index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="实体关系名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入实体关系名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['knowledge:entityRelation:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. plain
  32. icon="el-icon-plus"
  33. size="mini"
  34. @click="handleAddByClass"
  35. v-hasPermi="['knowledge:entityRelation:add']"
  36. >根据类新增</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="success"
  41. plain
  42. icon="el-icon-edit"
  43. size="mini"
  44. :disabled="single"
  45. @click="handleUpdate"
  46. v-hasPermi="['knowledge:entityRelation:edit']"
  47. >修改</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="danger"
  52. plain
  53. icon="el-icon-delete"
  54. size="mini"
  55. :disabled="multiple"
  56. @click="handleDelete"
  57. v-hasPermi="['knowledge:entityRelation:remove']"
  58. >删除</el-button>
  59. </el-col>
  60. <!-- <el-col :span="1.5">
  61. <el-button
  62. type="warning"
  63. plain
  64. icon="el-icon-download"
  65. size="mini"
  66. @click="handleExport"
  67. v-hasPermi="['knowledge:entityRelation:export']"
  68. >导出</el-button>
  69. </el-col> -->
  70. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  71. </el-row>
  72. <el-table v-loading="loading" :data="entityRelationList" @selection-change="handleSelectionChange">
  73. <el-table-column type="selection" width="55" align="center" />
  74. <el-table-column label="实体关系名称" align="center" prop="name" />
  75. <el-table-column label="起点实体" align="center" prop="startNode.name" />
  76. <el-table-column label="终点实体" align="center" prop="endNode.name" />
  77. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  78. <template slot-scope="scope">
  79. <el-button
  80. size="mini"
  81. type="text"
  82. icon="el-icon-edit"
  83. @click="handleUpdate(scope.row)"
  84. v-hasPermi="['knowledge:entityRelation:edit']"
  85. >修改</el-button>
  86. <el-button
  87. size="mini"
  88. type="text"
  89. icon="el-icon-delete"
  90. @click="handleDelete(scope.row)"
  91. v-hasPermi="['knowledge:entityRelation:remove']"
  92. >删除</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination
  97. v-show="total>0"
  98. :total="total"
  99. :page.sync="queryParams.pageNum"
  100. :limit.sync="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. <!-- 添加或修改实体关系管理对话框 -->
  104. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  105. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  106. <el-form-item label="实体关系名称" prop="name">
  107. <el-input v-model="form.name" placeholder="请输入实体关系名称" />
  108. </el-form-item>
  109. <el-form-item label="起点实体" prop="startNode">
  110. <el-select v-model="form.startNode" placeholder="请选择起点实体" value-key="id" filterable >
  111. <el-option
  112. v-for="item in entityList"
  113. :key="item.id"
  114. :label="item.name"
  115. :value="item">
  116. </el-option>
  117. </el-select>
  118. </el-form-item>
  119. <el-form-item label="终点实体" prop="endNode">
  120. <el-select v-model="form.endNode" placeholder="请选择终点实体" value-key="id" filterable >
  121. <el-option
  122. v-for="item in entityList"
  123. :key="item.id"
  124. :label="item.name"
  125. :value="item">
  126. </el-option>
  127. </el-select>
  128. </el-form-item>
  129. </el-form>
  130. <div slot="footer" class="dialog-footer">
  131. <el-button type="primary" @click="submitForm">确 定</el-button>
  132. <el-button @click="cancel">取 消</el-button>
  133. </div>
  134. </el-dialog>
  135. <el-dialog :title="title" :visible.sync="openByClass" width="500px" append-to-body>
  136. <el-form ref="formClass" :model="formByClass" :rules="rulesByClass" label-width="100px">
  137. <el-form-item label="起点实体类" prop="subEntityClassId">
  138. <el-select v-model="formByClass.subEntityClassId" placeholder="请选择起点实体" value-key="id" filterable @change="getEntityClassRelationOption">
  139. <el-option
  140. v-for="item in entityClassOption"
  141. :key="item.id"
  142. :label="item.name"
  143. :value="item.id">
  144. </el-option>
  145. </el-select>
  146. </el-form-item>
  147. <el-form-item label="终点实体类" prop="objEntityClassId">
  148. <el-select v-model="formByClass.objEntityClassId" placeholder="请选择终点实体" value-key="id" filterable @change="getEntityClassRelationOption">
  149. <el-option
  150. v-for="item in entityClassOption"
  151. :key="item.id"
  152. :label="item.name"
  153. :value="item.id">
  154. </el-option>
  155. </el-select>
  156. </el-form-item>
  157. <el-form-item label="实体关系类" prop="entityClassRelId">
  158. <el-select v-model="formByClass.entityClassRelId" placeholder="请选实体关系类" value-key="id" filterable clearable >
  159. <el-option
  160. v-for="item in entityClassRelationOption"
  161. :key="item.id"
  162. :label="item.name"
  163. :value="item.id">
  164. </el-option>
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="起点实体" prop="subEntity">
  168. <el-input type="textarea" :rows="2" v-model="formByClass.subEntity" placeholder="请输入起点实体" />
  169. </el-form-item>
  170. <el-form-item label="终点实体" prop="objEntity">
  171. <el-input type="textarea" :rows="2" v-model="formByClass.objEntity" placeholder="请输入终点实体" />
  172. </el-form-item>
  173. </el-form>
  174. <div slot="footer" class="dialog-footer">
  175. <el-button type="primary" @click="submitFormByClass(1)">提交并继续添加</el-button>
  176. <el-button type="primary" @click="submitFormByClass(0)">提交并关闭</el-button>
  177. <el-button @click="cancelByClass">取 消</el-button>
  178. </div>
  179. </el-dialog>
  180. </div>
  181. </template>
  182. <script>
  183. import { listEntityRelation, getEntityRelation, delEntityRelation, addEntityRelation, updateEntityRelation } from "@/api/knowledge/entityRelation";
  184. import { findAll } from "@/api/knowledge/entity";
  185. import { getEntityClassOption } from "@/api/neo4j/class"
  186. import { getClassRelationOptionByClassId, addEntityAndRelation } from "@/api/neo4j/class_relation"
  187. import { bit2Info } from '@/utils/validate'
  188. export default {
  189. name: "EntityRelation",
  190. data() {
  191. return {
  192. // 遮罩层
  193. loading: true,
  194. // 选中数组
  195. ids: [],
  196. // 非单个禁用
  197. single: true,
  198. // 非多个禁用
  199. multiple: true,
  200. // 显示搜索条件
  201. showSearch: true,
  202. // 总条数
  203. total: 0,
  204. // 实体关系管理表格数据
  205. entityRelationList: [],
  206. // 弹出层标题
  207. title: "",
  208. // 是否显示弹出层
  209. open: false,
  210. // 查询参数
  211. queryParams: {
  212. pageNum: 1,
  213. pageSize: 10,
  214. name: null,
  215. },
  216. // 表单参数
  217. form: {},
  218. formByClass: {},
  219. // 表单校验
  220. rules: {
  221. name: [
  222. {required: true, message: '实体关系名称不能为空', trigger: 'blur'},
  223. ],
  224. startNode: [
  225. {required: true, message: '起点实体不能为空', trigger: 'blur'},
  226. ],
  227. endNode: [
  228. {required: true, message: '终点实体不能为空', trigger: 'blur'},
  229. ],
  230. },
  231. rulesByClass: {
  232. subEntityClassId: [
  233. {required: true, message: '起点实体类不能为空', trigger: 'blur'},
  234. ],
  235. objEntityClassId: [
  236. {required: true, message: '终点实体类不能为空', trigger: 'blur'},
  237. ],
  238. entityClassRelId: [
  239. {required: true, message: '实体关系类不能为空', trigger: 'blur'},
  240. ],
  241. subEntity: [
  242. {required: true, message: '起点实体不能为空', trigger: 'blur'},
  243. ],
  244. objEntity: [
  245. {required: true, message: '终点实体不能为空', trigger: 'blur'},
  246. ],
  247. },
  248. entityList: [],
  249. entityClassOption: [],
  250. entityClassRelationOption: [],
  251. openByClass: false,
  252. };
  253. },
  254. created() {
  255. this.getList();
  256. this.getOption();
  257. },
  258. activated(){
  259. this.getOption();
  260. },
  261. methods: {
  262. /** 查询实体关系管理列表 */
  263. bit2Info,
  264. getList() {
  265. this.loading = true;
  266. listEntityRelation(this.queryParams).then(response => {
  267. this.entityRelationList = response.content;
  268. this.total = response.totalElements;
  269. this.loading = false;
  270. });
  271. },
  272. // 取消按钮
  273. cancel() {
  274. this.open = false;
  275. this.reset();
  276. },
  277. // 表单重置
  278. reset() {
  279. this.form = {
  280. name: null,
  281. content: null,
  282. startNode: null,
  283. endNode: null,
  284. };
  285. this.resetForm("form");
  286. },
  287. /** 搜索按钮操作 */
  288. handleQuery() {
  289. this.queryParams.pageNum = 1;
  290. this.getList();
  291. },
  292. /** 重置按钮操作 */
  293. resetQuery() {
  294. this.resetForm("queryForm");
  295. this.handleQuery();
  296. },
  297. // 多选框选中数据
  298. handleSelectionChange(selection) {
  299. this.ids = selection.map(item => item.id)
  300. this.single = selection.length!==1
  301. this.multiple = !selection.length
  302. },
  303. /** 新增按钮操作 */
  304. handleAdd() {
  305. this.reset();
  306. this.open = true;
  307. this.title = "添加实体关系管理";
  308. },
  309. /** 修改按钮操作 */
  310. handleUpdate(row) {
  311. this.reset();
  312. const relId = row.id || this.ids
  313. getEntityRelation(relId).then(response => {
  314. this.form = response.data;
  315. this.open = true;
  316. this.title = "修改实体关系管理";
  317. });
  318. },
  319. /** 提交按钮 */
  320. submitForm() {
  321. this.$refs["form"].validate(valid => {
  322. if (valid) {
  323. if (this.form.id != null) {
  324. updateEntityRelation(this.form).then(response => {
  325. this.$modal.msgSuccess("修改成功");
  326. this.open = false;
  327. this.getList();
  328. });
  329. } else {
  330. addEntityRelation(this.form).then(response => {
  331. this.$modal.msgSuccess("新增成功");
  332. this.open = false;
  333. this.getList();
  334. });
  335. }
  336. }
  337. });
  338. },
  339. /** 删除按钮操作 */
  340. handleDelete(row) {
  341. const relIds = row.id || this.ids;
  342. this.$modal.confirm('是否确认删除实体关系管理编号为"' + relIds + '"的数据项?').then(function() {
  343. return delEntityRelation(relIds);
  344. }).then(() => {
  345. this.getList();
  346. this.$modal.msgSuccess("删除成功");
  347. }).catch(() => {});
  348. },
  349. /** 导出按钮操作 */
  350. handleExport() {
  351. this.download('knowledge/entityRelation/export', {
  352. ...this.queryParams
  353. }, `entityRelation_${new Date().getTime()}.xlsx`)
  354. },
  355. getOption(){
  356. findAll().then(resp => {
  357. this.entityList = resp
  358. })
  359. getEntityClassOption().then(resp => {
  360. this.entityClassOption = resp.data
  361. })
  362. },
  363. getEntityClassRelationOption(){
  364. delete this.formByClass.entityClassRelId;
  365. if(this.formByClass.subEntityClassId && this.formByClass.objEntityClassId) {
  366. getClassRelationOptionByClassId(this.formByClass.subEntityClassId, this.formByClass.objEntityClassId).then(resp => {
  367. this.entityClassRelationOption = resp.data;
  368. })
  369. } else {
  370. this.entityClassRelationOption = []
  371. }
  372. },
  373. handleAddByClass(){
  374. this.resetClass();
  375. this.openByClass = true;
  376. this.title = "添加实体及实体关系";
  377. },
  378. resetClass(){
  379. this.formByClass = {
  380. // name: null,
  381. // content: null,
  382. // startNode: null,
  383. // endNode: null,
  384. };
  385. this.resetForm("formClass");
  386. },
  387. cancelByClass(){
  388. this.openByClass = false;
  389. this.resetClass();
  390. },
  391. submitFormByClass(type){
  392. this.$refs["formClass"].validate(valid => {
  393. if (valid) {
  394. addEntityAndRelation(this.formByClass).then(reps => {
  395. this.$modal.msgSuccess("提交成功");
  396. if(type) {
  397. this.handleAddByClass()
  398. } else {
  399. this.openByClass = false;
  400. this.getList();
  401. }
  402. })
  403. }
  404. })
  405. },
  406. }
  407. };
  408. </script>