GraphImport.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div>
  3. <div class="menu-title">
  4. 知识图谱导入
  5. </div>
  6. <div class="menu-content">
  7. <el-tabs v-model="activeName" @tab-click="handleClick">
  8. <el-tab-pane label="本体导入" name="first">
  9. <el-row :gutter="5" style="margin: 20px 0">
  10. <el-col :span="7">
  11. <div>
  12. <label>请选择本体:</label>
  13. <el-select v-model="ontologyId" placeholder="请选择本体">
  14. <el-option v-for="item in ontologyList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  15. </el-select>
  16. </div>
  17. </el-col>
  18. <el-col :span="10">
  19. <div>
  20. <label>请选择文件:</label>
  21. <el-input v-model="fileName" readonly style="width: 300px;margin-right: 20px" disabled></el-input>
  22. <el-upload
  23. ref="upload" style="display: inline-block"
  24. :auto-upload="false"
  25. action="#" accept=".xls, .xlsx"
  26. :on-change="handleFileChange"
  27. :limit="2"
  28. :show-file-list="false">
  29. <el-button type="primary">上传文件</el-button>
  30. </el-upload>
  31. </div>
  32. </el-col>
  33. <el-col :span="2">
  34. <el-button type="primary" style="float:right;" @click="queryData" :loading="btLoading">执行</el-button>
  35. </el-col>
  36. </el-row>
  37. <div><a :href="path+'template.xlsx'" download="template.xlsx" style="text-decoration:underline;color: #0D6DFF">下载模板</a></div>
  38. <div class="result" style="width: 100%;margin-top: 20px;color: #5c5c5c;" v-if="showFlag && activeName == 'first'">成功导入</div>
  39. <div style="margin-top: 20px;height:20px;border: 1px solid rgba(0, 0, 0, 0.1);padding: 20px" v-if="showFlag && activeName == 'first'">
  40. <el-descriptions title="" :column="3" >
  41. <el-descriptions-item label="概念数量">{{resultCmd.gncount.toString().replace(/(\d)(?=(?:\d{3})+$)/g,'$1,')}}</el-descriptions-item>
  42. <el-descriptions-item label="对象属性数量">{{resultCmd.gxscount.toString().replace(/(\d)(?=(?:\d{3})+$)/g,'$1,')}}</el-descriptions-item>
  43. <el-descriptions-item label="值属性数量">{{resultCmd.zsxcount.toString().replace(/(\d)(?=(?:\d{3})+$)/g,'$1,')}}</el-descriptions-item>
  44. </el-descriptions>
  45. </div>
  46. </el-tab-pane>
  47. <el-tab-pane label="图谱数据导入" name="second">
  48. <el-row :gutter="5" style="margin: 20px 0">
  49. <el-col :span="7">
  50. <div>
  51. <label>请选择图谱:</label>
  52. <el-select v-model="spaceName" placeholder="请选择图谱" style="width: calc(100% - 204px)">
  53. <el-option v-for="item in spaceList" :label="item.comment" :value="item.name"></el-option>
  54. </el-select>
  55. <!--<el-button type="primary" style="margin-left: 20px;" @click="addCmd">新建图谱</el-button>-->
  56. </div>
  57. </el-col>
  58. <el-col :span="10">
  59. <div >
  60. <label>请选择文件:</label>
  61. <el-input v-model="fileName" readonly style="margin-right: 20px;width: calc(100% - 204px)" disabled></el-input>
  62. <el-upload
  63. ref="upload" style="display: inline-block"
  64. :auto-upload="false"
  65. action="#" accept=".zip"
  66. :on-change="handleFileChange"
  67. :limit="2"
  68. :show-file-list="false">
  69. <el-button type="primary">上传文件</el-button>
  70. </el-upload>
  71. </div>
  72. <div style="color: red;margin-top: 10px">* zip文件必须包含vertex.json、edge.json</div>
  73. </el-col>
  74. <el-col :span="2">
  75. <el-button type="primary" style="float:right;" @click="startSpace">执行</el-button>
  76. </el-col>
  77. </el-row>
  78. <div><a :href="path+'图谱数据.zip'" download="图谱数据.zip" style="text-decoration:underline;color: #0D6DFF">下载模板</a></div>
  79. <div class="result" style="width: 100%;margin-top: 20px;color: #5c5c5c;" v-if="showFlag && activeName == 'second'">{{message}}</div>
  80. <div style="margin-top: 20px;" v-if="showFlag && activeName == 'second'">
  81. <el-table :data="resultCmd1" border style="width: 100%" >
  82. <el-table-column prop="title" label="标题"></el-table-column>
  83. <el-table-column prop="gf_name" label="文件名"></el-table-column>
  84. <el-table-column prop="flag" label="状态">
  85. <template slot-scope="scope">
  86. <label :style="{color:scope.row.flag?'#67c23a':'#f56c6c'}">{{scope.row.flag?"成功":"失败"}}</label>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </div>
  91. </el-tab-pane>
  92. </el-tabs>
  93. </div>
  94. <el-dialog title="新建图谱" :visible.sync="cmdDialogVisible" width="40%">
  95. <el-steps :active="active" finish-status="success" style="margin-bottom: 20px">
  96. <el-step title="新建图谱"></el-step>
  97. <el-step title="选择本体"></el-step>
  98. </el-steps>
  99. <el-form ref="cmd" label-width="120px" :model="cmd" v-if="active == 0">
  100. <el-form-item label="图谱名称:">
  101. <el-input v-model="cmd.name" style="width: 100%" ></el-input>
  102. </el-form-item>
  103. <el-form-item label="图谱描述:">
  104. <el-input v-model="cmd.comment" style="width: 100%" ></el-input>
  105. </el-form-item>
  106. </el-form>
  107. <span slot="footer" class="dialog-footer" v-if="active == 0">
  108. <el-button type="primary" @click="createSpace">下一步</el-button>
  109. </span>
  110. <el-form ref="cmd" label-width="130px" :model="cmd" v-if="active == 1">
  111. <el-form-item label="选择本体:">
  112. <el-select v-model="cmd.ontologyId" placeholder="请选择本体" style="width: 100%">
  113. <el-option v-for="item in ontologyList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  114. </el-select>
  115. </el-form-item>
  116. </el-form>
  117. <span slot="footer" class="dialog-footer" v-if="active == 1">
  118. <el-button @click="cmdDialogVisible = false">取 消</el-button>
  119. <el-button type="primary" @click="submitModify" :loading="loading">确 定</el-button>
  120. </span>
  121. </el-dialog>
  122. </div>
  123. </template>
  124. <script>
  125. import request,{getFileUrl} from '@/utils/request';
  126. var _this;
  127. export default {
  128. name: "codeWarehouse",
  129. data() {
  130. return {
  131. activeName: 'first',
  132. ontologyId:"",
  133. fileName:"",
  134. file:"",
  135. ontologyList:[],
  136. resultCmd:{
  137. gncount:"",
  138. gxscount:"",
  139. zsxcount:""
  140. },
  141. resultCmd1:{},
  142. showFlag:false,
  143. cmd:{},
  144. cmdDialogVisible:false,
  145. spaceList:[],
  146. active:0,
  147. spaceName:"",
  148. loading:false,
  149. path:getFileUrl(),
  150. message:"",
  151. btLoading:false
  152. }
  153. },
  154. mounted() {
  155. _this = this;
  156. _this.queryOntology();
  157. _this.querySpaceList();
  158. },
  159. methods: {
  160. handleClick(tab, event) {
  161. _this.fileName = "";
  162. _this.file = "";
  163. _this.resultCmd = {};
  164. _this.showFlag = false;
  165. _this.btLoading = false;
  166. },
  167. handleFileChange(file) {
  168. this.$refs.upload.clearFiles();
  169. _this.fileName = file.raw.name;
  170. _this.file = file.raw;
  171. },
  172. queryOntology() {
  173. request({
  174. url: `/ontology/query_list`,
  175. method: 'post',
  176. data: {EQI_sourceType: 1}
  177. }).then(res => {
  178. _this.ontologyList = res.data;
  179. });
  180. },
  181. querySpaceList() {
  182. request({
  183. url: '/nebula_operate/showspace',
  184. method: 'get'
  185. }).then(res => {
  186. _this.spaceList = res.data;
  187. });
  188. },
  189. queryData() {
  190. _this.resultCmd = {};
  191. _this.showFlag = false;
  192. if(!_this.ontologyId){
  193. _this.$message.warning("请选择本体");
  194. return false;
  195. }
  196. if(!_this.file){
  197. _this.$message.warning("请选择文件");
  198. return false;
  199. }
  200. _this.btLoading = true;
  201. _this.$message.info("数据在执行中。。");
  202. let formData = new FormData();
  203. formData.append("file", _this.file);
  204. formData.append("ontologyId", _this.ontologyId);
  205. request({
  206. url: '/nebula_model/importmodel/'+_this.ontologyId,
  207. method: 'post',
  208. data: formData
  209. }).then(res => {
  210. _this.resultCmd = res.data;
  211. _this.showFlag = true;
  212. _this.btLoading = false;
  213. });
  214. },
  215. addCmd(){
  216. _this.active = 0;
  217. _this.cmd = {
  218. ontologyId:"",
  219. name:"",
  220. comment:""
  221. }
  222. _this.loading = false;
  223. _this.cmdDialogVisible = true;
  224. },
  225. createSpace(){
  226. if(!_this.cmd.name){
  227. _this.$message.warning("请输入图谱名称");
  228. return false;
  229. }
  230. if(!_this.cmd.comment){
  231. _this.$message.warning("请输入图谱描述");
  232. return false;
  233. }
  234. _this.active = 1;
  235. },
  236. submitModify(){
  237. if(!_this.cmd.ontologyId){
  238. _this.$message.warning("请选择本体");
  239. return false;
  240. }
  241. _this.loading = true;
  242. this.$message({
  243. message: '正在初始化图空间,请等待...',
  244. type:"info",
  245. duration:20000
  246. });
  247. request({
  248. url: '/nebula_operate/createspace',
  249. method: 'post',
  250. data: {name:_this.cmd.name,comment:_this.cmd.comment}
  251. }).then(res => {
  252. var timer = setTimeout(function(){
  253. request({
  254. url: '/nebula_model/initgraphdatabase/'+_this.cmd.ontologyId+'/'+_this.cmd.name,
  255. method: 'get',
  256. data: {}
  257. }).then(res => {
  258. _this.$message.success("新建图谱成功");
  259. clearTimeout(timer);
  260. _this.loading = false;
  261. _this.cmdDialogVisible = false;
  262. _this.querySpaceList();
  263. });
  264. },20000)
  265. });
  266. },
  267. startSpace(){
  268. _this.resultCmd = {};
  269. _this.showFlag = false;
  270. if(!_this.spaceName){
  271. _this.$message.warning("请选择图谱");
  272. return false;
  273. }
  274. if(!_this.file){
  275. _this.$message.warning("请选择文件");
  276. return false;
  277. }
  278. request({
  279. url: '/graph-task/query_list/'+_this.spaceName,
  280. method: 'get',
  281. data: {}
  282. }).then(res => {
  283. if(res.data.length <= 0){
  284. let formData = new FormData();
  285. formData.append("file", _this.file);
  286. request({
  287. url: '/nebula_graph_import/uploadfile/'+_this.spaceName,
  288. method: 'put',
  289. data: formData
  290. }).then(res => {
  291. _this.resultCmd1 = res.data;
  292. var flag = true;
  293. res.data.forEach(item => {
  294. if(!item.flag){
  295. _this.message = "导入失败";
  296. flag = false;
  297. }
  298. })
  299. if(flag){
  300. _this.message = "导入成功";
  301. }
  302. _this.showFlag = true;
  303. });
  304. }else{
  305. _this.$message.warning("该图谱在执行中。。");
  306. }
  307. });
  308. }
  309. }
  310. }
  311. </script>
  312. <style lang="scss">
  313. .upload-btn {
  314. display: inline-block;
  315. margin-left: 20px;
  316. }
  317. </style>