createRelationClassModal.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <a-modal
  3. title="新建一个关系类"
  4. :visible="show"
  5. :maskClosable="false"
  6. @ok="handleOk"
  7. @cancel="handleClose"
  8. >
  9. <h4 class="title">{{entClsName}}</h4>
  10. <div style="margin-bottom: 20px;">
  11. <a-radio-group @change="onChangeOrigin" v-model="Originvalue" disabled>
  12. <a-radio :value="3">作为起点</a-radio>
  13. <a-radio :value="4">作为终点</a-radio>
  14. </a-radio-group>
  15. </div>
  16. <h4 class="title">选择或新建关系</h4>
  17. <a-row :gutter="10" >
  18. <a-col :span="4">
  19. <h4 class="title" style="margin-top:.6em;">背景颜色</h4>
  20. </a-col>
  21. <a-col :span="15">
  22. <a-form :form="form">
  23. <a-form-item>
  24. <a-color-picker @fromChild="getColor" v-decorator="formRules.backGroundColor" />
  25. </a-form-item>
  26. </a-form>
  27. </a-col>
  28. </a-row>
  29. <div style="margin-bottom: 20px;">
  30. <a-radio-group @change="onChange" v-model="value">
  31. <a-radio :value="1">复制已有关系</a-radio>
  32. <a-radio :value="2">新建关系</a-radio>
  33. </a-radio-group>
  34. </div>
  35. <div v-if="value==1" style="margin-bottom: 20px;">
  36. <a-row :gutter="10">
  37. <a-col :span="12">
  38. <a-button @click="getRelationCls">
  39. {{selectedRelCls ? selectedRelCls : '选择一个关系类名称'}}
  40. </a-button>
  41. </a-col>
  42. <a-col :span="12">
  43. <!-- <a-select
  44. showSearch
  45. placeholder="选择一个关系类"
  46. style="width:200px;"
  47. @change="handleSelectRelationClass"
  48. >
  49. <a-select-option
  50. v-for="item in filterRelationList"
  51. :value="item.relClsID"
  52. :key="item.relClsID"
  53. >
  54. <a-popover placement="left">
  55. <template slot="content">
  56. <div>起点:{{item.startName}}</div>
  57. <div>关系类:{{item.relClsName}}</div>
  58. <div>终点:{{item.endName}}</div>
  59. <div v-for="(p,i) in attrList" :key="i">属性:{{p.attrClsName}}</div>
  60. </template>
  61. <span
  62. @mouseenter="enter(item)"
  63. @mouseleave="leave()"
  64. >
  65. {{item.startName}}->{{item.relClsName}}->{{item.endName}}</span>
  66. </a-popover>
  67. </a-select-option>
  68. </a-select> -->
  69. </a-col>
  70. </a-row>
  71. </div>
  72. <div v-if="value==2">
  73. <a-form :form="form">
  74. <a-form-item>
  75. <a-input v-decorator="formRules.entityClass" placeholder="请输入关系类名" />
  76. </a-form-item>
  77. </a-form>
  78. </div>
  79. <h4 class="title">{{Originvalue===3 ? '选择终点关系类' : '选择起点关系类'}}</h4>
  80. <div style="max-height: 420px; overflow: auto;">
  81. <!--<class-tree @nodeSelected="entityClassNodeSelected" :editable="false"></class-tree>-->
  82. <z-tree :editable="false" @nodeSelected="entityClassNodeSelected"></z-tree>
  83. </div>
  84. </a-modal>
  85. </template>
  86. <script>
  87. import AColorPicker from '@/components/knowledge/colorPicker';
  88. import ClassTree from "@/views/knowledge/graphClass/entityClassTree.vue";
  89. import zTree from "@/views/knowledge/graphClass/entityClassZtree.vue";
  90. import { getRelationAttr, getAllRelationClassListByName, addRelationClass } from "@/api/graph/relationClass"
  91. const formRules = {
  92. // 所有验证规则
  93. entityClass: [
  94. // 用作标识,我们统一写成和表单提交字段一样
  95. "entityClass", // 表单提交的字段
  96. {
  97. rules: [{ required: true, message: "此选项必填", whitespace: true }]
  98. }
  99. ]
  100. // relationClass: [
  101. // relationClass, // 表单提交的字段
  102. // {
  103. // rules: [{required: false, message: '此选项必填', whitespace: true}]
  104. // }
  105. // ]
  106. };
  107. export default {
  108. components: {
  109. AColorPicker,
  110. zTree,
  111. ClassTree,
  112. VNodes: {
  113. functional: true,
  114. render: (h, ctx) => ctx.props.vnodes
  115. }
  116. },
  117. name: "create-relation-class-modal",
  118. props: ["pramsId", "entClsName", "entClsType"],
  119. data() {
  120. return {
  121. color:'',
  122. show: true,
  123. form: this.$form.createForm(this),
  124. formRules,
  125. value: 1,
  126. Originvalue: 3,
  127. filterRelationList: [], // 已有关系列表
  128. EntityClassNode: {}, // 实体类节点信息
  129. selectRelationValue: "",
  130. timer: null, // 延时器
  131. attrMap: {},
  132. attrList: [], // 属性list
  133. selectedRelCls: ''
  134. };
  135. },
  136. created() {
  137. // 判断是起点还是终点
  138. if (this.entClsType === "START") {
  139. this.Originvalue = 3; // 起点
  140. } else {
  141. this.Originvalue = 4; // 终点
  142. }
  143. },
  144. destroyed() {
  145. },
  146. methods: {
  147. getColor (color) {
  148. this.color = color;
  149. },
  150. enter(item) {
  151. const vm = this
  152. if (vm.attrMap.hasOwnProperty(item.relClsID)) { // 判断map中是否存在
  153. vm.attrList = vm.attrMap[item.relClsID];
  154. clearTimeout(vm.timer);
  155. } else {
  156. vm.timer = setTimeout(() => {
  157. getRelationAttr(item.relClsID).then(res => {
  158. vm.attrMap[item.relClsID] = res; // 缓存
  159. vm.attrList = res;
  160. });
  161. }, 10);
  162. }
  163. },
  164. leave() {
  165. clearTimeout(this.timer);
  166. },
  167. /**
  168. * // 传出来的实体类节点信息
  169. * @param node
  170. */
  171. entityClassNodeSelected(node) {
  172. this.EntityClassNode = node;
  173. },
  174. /**
  175. * 选中的已有关系
  176. * @param value
  177. */
  178. handleChange(name) {
  179. getAllRelationClassListByName(name,false).then(data => {
  180. //参数为空,获取所有的列表
  181. this.filterRelationList = data.records;
  182. });
  183. },
  184. handleSelectRelationClass(id) {
  185. this.selectRelationValue = id;
  186. },
  187. getRelationCls() {
  188. this.$open('getRelationClsListModal', {}, function (data) {
  189. if (data) {
  190. this.relClsName = data
  191. this.selectedRelCls = data
  192. getAllRelationClassListByName(data,false).then(data => {
  193. //参数为空,获取所有的列表
  194. this.filterRelationList = data.rows;
  195. });
  196. }
  197. })
  198. },
  199. onChange(e) {
  200. },
  201. // 选择起点或终点
  202. onChangeOrigin(e) {
  203. },
  204. async getFormData() {
  205. var result = await this.$formValidateFields("form"); //form的字符串
  206. // 在这里对form返回数据进行处理
  207. return result;
  208. },
  209. async handleOk(e) {
  210. let result = await this.getFormData(); // this是当前组件的this, 'form'此表单的名称,一定要是字符串
  211. const endID = this.EntityClassNode && this.EntityClassNode.entClsID;
  212. const relClsID = this.selectRelationValue;
  213. let entClsType = "START";
  214. if (!endID) {
  215. this.$message.error("请选择要建立关系的实体类");
  216. return;
  217. }
  218. const data = {
  219. startID: this.pramsId,
  220. endID: endID,
  221. backGroundColor:this.color,
  222. relClsMemo:this.relClsMemo,
  223. relClsName:this.relClsName,
  224. };
  225. if (this.Originvalue == 4) {
  226. // 传进来的实体类作为终点
  227. data["startID"] = endID;
  228. data["endID"] = this.pramsId;
  229. entClsType = "ENT";
  230. }
  231. if (this.value == 1) {
  232. // 已有关系属性
  233. data["relClsID"] = relClsID;
  234. }
  235. if (this.value == 2) {
  236. // 新建关系
  237. data["relClsName"] = result.entityClass;
  238. const uniqueMatchList = this.$checkSpecialChar(result.entityClass)
  239. if (uniqueMatchList.length > 0) {
  240. this.$message.error(`关系类名称不能包含特殊字符【${uniqueMatchList.join('、')}】!`)
  241. return false
  242. }
  243. }
  244. addRelationClass(data).then(resp => {
  245. let data = resp.data
  246. if (data !== false) {
  247. this.$trigger("relationClass:nodeCreated", data);
  248. this.$close({
  249. id: this.pramsId,
  250. entClsType: entClsType
  251. });
  252. }
  253. });
  254. },
  255. handleClose(e) {
  256. this.$close(false);
  257. }
  258. }
  259. };
  260. </script>
  261. <style scoped>
  262. .ant-row {
  263. margin-bottom: 2px;
  264. }
  265. </style>