audit-model-class.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div :class="$style.wrapHeight">
  3. <div :class="$style.rowHeight">
  4. <!-- 左侧 -->
  5. <audit-model-tree ref="auditModelTree" @treeSelect="treeSelect" @depChanged="depChanged">
  6. <div :class="$style.treeWrap">
  7. <!-- 我的模型 和分类管理并列 -->
  8. <div :class="$style.treeTitle">我的模型</div>
  9. </div>
  10. </audit-model-tree>
  11. <div :class="$style.rightcard">
  12. <a-card>
  13. <sd-data-table-ex
  14. :key="key"
  15. ref="dataTable"
  16. :editnode="editnode"
  17. form-id="iamModelOwnCategory"
  18. page-id="audit/datacube/iamModelOwnCategory"
  19. :columns="columns1"
  20. :actions="actions"
  21. :search-fields="['categoryName', 'categoryId']"
  22. :filter-expressions="expressions"
  23. :show-selection="(item) => item.editAndDeleteAuth !== 0"
  24. :custom-delete-fun="deleteRows"
  25. @recordSaved="onRecordSaved"
  26. >
  27. <template slot="categoryName" slot-scope="text, record">
  28. <a
  29. v-if="record.editAndDeleteAuth !== 0"
  30. @click="
  31. () => {
  32. $refs.dataTable.showDetailModal(record.id, 'audit/datacube/iamModelOwnCategory')
  33. }
  34. "
  35. >{{ text }}</a
  36. >
  37. <span v-else>{{ text }}</span>
  38. </template>
  39. <!-- 详情表单 -->
  40. <template v-slot:form="{ model }" v-sd-watermark="waterMark" @saved="onSaved">
  41. <!-- 一般字段直接写name即可 -->
  42. <!-- { validator: validator }, -->
  43. <!-- <a-form-model-item
  44. prop="categoryId"
  45. label="分类编号"
  46. :rules="[
  47. {
  48. required: true,
  49. trigger: ['change', 'blur'],
  50. },
  51. // 只能是数字
  52. {
  53. pattern: /^[0-9]*$/,
  54. message: '只能输入数字',
  55. trigger: ['change', 'blur'],
  56. },
  57. ]"
  58. >
  59. <a-input v-model.trim="model.categoryId" />
  60. </a-form-model-item> -->
  61. <sd-form-item name="categoryName" />
  62. <sd-form-item name="categoryDesc">
  63. <a-textarea v-model="model.categoryDesc" :rows="3" />
  64. </sd-form-item>
  65. <sd-form-item name="sortNum" :input-props="{ defaultValue: 0 }" />
  66. <sd-form-item
  67. :hidden="true"
  68. name="parentId"
  69. :input-props="{ defaultValue: parentId, disabled: true }"
  70. />
  71. <!-- creatorAccount -->
  72. <!-- <sd-form-item
  73. :hidden="true"
  74. name="creatorAccount"
  75. :input-props="{ defaultValue: getUserInfo().account, disabled: true }"
  76. /> -->
  77. </template>
  78. </sd-data-table-ex>
  79. </a-card>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import components from './_import-components/audit-model-class-import'
  86. import TableColumnTypes from '@/common/services/table-column-types'
  87. import auditModelService from './audit-model-service'
  88. import auditModelTree from './audit-model-tree.vue'
  89. import { Modal, message } from 'ant-design-vue'
  90. import debounce from 'lodash.debounce'
  91. import axios from '@/common/services/axios-instance'
  92. import { getUserInfo } from '@/common/store-mixin'
  93. export default {
  94. name: 'AuditModelClass',
  95. metaInfo: {
  96. title: '分类管理',
  97. },
  98. components: {
  99. ...components,
  100. auditModelTree,
  101. },
  102. data() {
  103. return {
  104. editnode: true, // 列表是否可以新建
  105. key: 0,
  106. expressions: [
  107. // <!-- 创建人 -->
  108. {
  109. dataType: 'str',
  110. name: 'creatorAccount',
  111. op: 'eq',
  112. stringValue: getUserInfo().account,
  113. },
  114. //
  115. ],
  116. columns1: [
  117. {
  118. dataIndex: 'id',
  119. sdHidden: true,
  120. },
  121. {
  122. dataIndex: 'parentId',
  123. sdHidden: true,
  124. },
  125. {
  126. title: '排序号',
  127. dataIndex: 'sortNum',
  128. defaultSortOrder: 'ascend',
  129. width: '100px',
  130. },
  131. {
  132. title: '分类编号',
  133. dataIndex: 'id',
  134. },
  135. {
  136. title: '分类名称',
  137. dataIndex: 'categoryName',
  138. scopedSlots: { customRender: 'categoryName' },
  139. },
  140. {
  141. title: '创建时间',
  142. dataIndex: 'creationTime',
  143. sorter: true,
  144. sdRender: TableColumnTypes.date,
  145. },
  146. ],
  147. actions: [
  148. {
  149. label: '新建',
  150. type: 'primary',
  151. callback: this.create,
  152. permission: null,
  153. },
  154. {
  155. label: '删除',
  156. id: 'delete',
  157. permission: null,
  158. type: 'delete',
  159. callback: this.deleteRows,
  160. },
  161. ],
  162. isEnd: null,
  163. isroot: true,
  164. parentId: null,
  165. auditOrgId: null,
  166. }
  167. },
  168. methods: {
  169. // 新建分类
  170. create() {
  171. if (this.parentId === null) {
  172. return message.error('请选择分类')
  173. }
  174. if (this.isEnd !== '1' && this.isEnd !== 1) {
  175. this.$refs.dataTable.showDetailModal(null, 'audit/datacube/iamModelOwnCategory')
  176. // this.$refs.dataTable.$refs.detail.setFieldValue('parentId', this.parentId)
  177. } else {
  178. message.error('末级分类下不可再新建分类')
  179. }
  180. },
  181. // 删除分类
  182. deleteCategory(ids, resolve) {
  183. auditModelService
  184. .deleteCategory(ids)
  185. .then(() => {
  186. this.onRecordsDeleted()
  187. this.refresh()
  188. })
  189. .finally(resolve)
  190. },
  191. // 校验分类
  192. deleteRows() {
  193. const ids = this.$refs.dataTable.getSelectedRowKeys()
  194. // 判断是否有下级
  195. auditModelService.deleteCheckCategory(ids).then((res) => {
  196. if (!res) {
  197. return new Promise((resolve) => {
  198. Modal.confirm({
  199. title: '您确定删除这项内容吗?',
  200. content: '该层级下存在子分类或模型数据,是否全部删除?',
  201. cancelText: '取消',
  202. okText: '删除',
  203. okType: 'danger',
  204. onOk: () => {
  205. this.deleteCategory(ids, resolve)
  206. },
  207. onCancel: () => {
  208. resolve()
  209. },
  210. })
  211. })
  212. } else {
  213. this.deleteCategory(ids, null)
  214. }
  215. })
  216. },
  217. refresh() {
  218. this.$refs.dataTable.refresh()
  219. },
  220. // 分类树操作
  221. // 新建保存回调刷新树
  222. onRecordSaved() {
  223. this.$refs.auditModelTree.refreshNode(this.parentId)
  224. },
  225. // 删除回调
  226. onRecordsDeleted() {
  227. message.success('删除成功')
  228. this.$refs.auditModelTree.refreshNode(this.parentId)
  229. },
  230. // 分类树触发事件
  231. treeSelect(selectedKeys, info) {
  232. if (selectedKeys.length === 0) {
  233. // 未选中节点
  234. // 清空数据
  235. this.parentId = null
  236. this.expressions = this.expressions.filter((item) => item.name !== 'parentId')
  237. return
  238. }
  239. const dataRef = info.node.dataRef
  240. if (dataRef.isroot) {
  241. this.parentId = 0
  242. this.expressions.forEach((item, i) => {
  243. if (item.name === 'parentId') {
  244. // 删除当前元素
  245. this.expressions.splice(i, 1)
  246. }
  247. })
  248. } else {
  249. this.parentId = dataRef.id
  250. this.expressions = this.expressions.filter((item) => item.name !== 'parentId')
  251. this.expressions.push({
  252. dataType: 'str',
  253. name: 'parentId',
  254. op: 'eq',
  255. stringValue: this.parentId,
  256. })
  257. }
  258. this.key += 1
  259. // 是否是末尾节点
  260. },
  261. depChanged(selectedKeys, info) {},
  262. // 分类编码校验
  263. validator(rule, value, callback) {
  264. let id = -1
  265. if (this.$refs.dataTable.recordId) {
  266. id = this.$refs.dataTable.recordId
  267. }
  268. value = encodeURIComponent(value)
  269. const url =
  270. `api/xcoa-mobile/v1/iammodelowncate/check-category-code?catalogCode=${value}&parentId=${this.parentId}&id=` +
  271. id
  272. debounce(() => {
  273. axios.get(url).then((res) => {
  274. if (res.data) {
  275. callback()
  276. } else {
  277. callback('已存在分类编码,不可以重复')
  278. }
  279. })
  280. }, 500)()
  281. },
  282. },
  283. }
  284. </script>
  285. <style module lang="scss">
  286. @use '@/common/design' as *;
  287. .tree-wrap {
  288. display: flex;
  289. align-items: flex-end;
  290. // 分散布局 水平居中
  291. justify-content: space-between;
  292. padding-bottom: 10px;
  293. margin-top: 10px;
  294. border-bottom: 1px solid $black;
  295. }
  296. .wrap-height {
  297. height: 100%;
  298. .row-height {
  299. display: flex;
  300. flex: auto;
  301. height: 100%;
  302. .rightcard {
  303. flex: 1;
  304. width: calc(100% - 20%);
  305. height: 100%;
  306. }
  307. }
  308. }
  309. </style>