iam-audit-tree-table.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div :class="$style.wrapHeight">
  3. <div :class="$style.rowHeight">
  4. <iam-audit-listtree
  5. :key="key"
  6. :checkable="checkable"
  7. :draggable="draggable"
  8. :is-search="isSearch"
  9. :show-line="showLine"
  10. :selected-keys="defaultSelectedKeys"
  11. :top-node-text="topNodeText"
  12. :treeparams="treeparams"
  13. :default-expanded-keys="defaultSelectedKeys"
  14. :is-select-dep="isSelectDep"
  15. :dep-options="depOptions"
  16. @treeSelect="treeSelect"
  17. @depChanged="depChanged"
  18. ></iam-audit-listtree>
  19. <div :class="$style.rightcard">
  20. <a-card :class="$style.acard">
  21. <sd-data-table-ex
  22. :key="key"
  23. ref="dataTable"
  24. data-url="api/xcoa-mobile/v1/iam-tree-list/getList"
  25. :process-req="processReq"
  26. :form-id="formId"
  27. :page-id="pageId"
  28. :columns="columns"
  29. :show-selection="(item) => item.editAndDeleteAuth !== 0"
  30. :actions="actions"
  31. :search-fields="searchFields"
  32. :filter-expressions="expressions"
  33. @onChange="onChange"
  34. @recordSaved="onRecordSaved"
  35. @recordsDeleted="onRecordsDeleted"
  36. >
  37. <!-- 点击列插槽 -->
  38. <template slot="customCell" slot-scope="text, record">
  39. <slot name="customCell" :text="text" :record="record"></slot>
  40. </template>
  41. <!-- 详情表单 -->
  42. <template v-slot:form="{ model }" @saved="onRecordSaved">
  43. <slot :model="model" :parentId="parentId"></slot>
  44. </template>
  45. </sd-data-table-ex>
  46. </a-card>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. Z
  52. <script>
  53. import iamAuditListtree from './iam-audit-listtree.vue'
  54. import components from './_import-components/iam-audit-tree-table-import'
  55. export default {
  56. name: 'IamAuditTreeTable',
  57. metaInfo: {
  58. title: 'TreeTable模板',
  59. },
  60. components: {
  61. ...components,
  62. iamAuditListtree,
  63. },
  64. props: {
  65. // table展示列
  66. columns: {
  67. type: Array,
  68. default: () => {
  69. return []
  70. },
  71. },
  72. // 按钮信息
  73. actions: {
  74. type: Array,
  75. default: () => {
  76. return []
  77. },
  78. },
  79. // 默认选中节点
  80. selectedKeys: {
  81. type: Array,
  82. default: function() {
  83. return []
  84. },
  85. },
  86. // 是否开启搜索
  87. isSearch: {
  88. type: Boolean,
  89. default: false,
  90. },
  91. // 是否显示复选框
  92. checkable: {
  93. type: Boolean,
  94. default: false,
  95. },
  96. // 是否可以拖拽
  97. draggable: {
  98. type: Boolean,
  99. default: false,
  100. },
  101. // 是否显示连线
  102. showLine: {
  103. type: Boolean,
  104. default: false,
  105. },
  106. // 根节点名称
  107. topNodeText: {
  108. type: String,
  109. default: '根节点',
  110. },
  111. // 地址树接口数据源
  112. treeparams: {
  113. type: Object,
  114. default: () => {
  115. return {}
  116. },
  117. },
  118. // 默认展开节点id
  119. defaultExpandedKeys: {
  120. type: Array,
  121. default: () => {
  122. return ['0']
  123. },
  124. },
  125. // 是否显示部门选择下拉框
  126. isSelectDep: {
  127. type: Boolean,
  128. default: false,
  129. },
  130. // 部门下拉框列表值
  131. depOptions: {
  132. type: Array,
  133. default: () => {
  134. return []
  135. },
  136. },
  137. // 部门下拉框默认值
  138. defaultDepValue: {
  139. type: Array,
  140. default: () => {
  141. return []
  142. },
  143. },
  144. // table搜索key
  145. searchFields: {
  146. type: Array,
  147. default: () => {
  148. return []
  149. },
  150. },
  151. // table formID
  152. formId: {
  153. type: String,
  154. default: '',
  155. },
  156. // table pageId
  157. pageId: {
  158. type: String,
  159. default: '',
  160. },
  161. },
  162. data() {
  163. return {
  164. key: 0,
  165. treeData: [],
  166. parentId: 0,
  167. parentName: '业务类型',
  168. parentObj: [{ id: '0', name: '业务类型' }],
  169. isDocType: '', // 是否公文类
  170. defaultSelectedKeys: ['0'],
  171. pageSize: 10, // 分页数量
  172. startPosition: 0, // 分页起始数
  173. expressions: [
  174. {
  175. dataType: 'str',
  176. name: 'parentId',
  177. op: 'eq',
  178. stringValue: 0,
  179. },
  180. ],
  181. }
  182. },
  183. mounted() {
  184. if (this.selectedKeys.length > 0) {
  185. this.defaultSelectedKeys = [this.defaultSelectedKeys]
  186. }
  187. },
  188. methods: {
  189. // 获取菜单树数据
  190. addTreeKey(data) {
  191. let result
  192. if (!data) {
  193. return
  194. }
  195. for (var i = 0; i < data.length; i++) {
  196. const item = data[i]
  197. item.key = item.id
  198. if (item.children && item.children.length > 0) {
  199. result = this.addTreeKey(item.children)
  200. } else {
  201. result = this.addTreeKey(item.children)
  202. }
  203. }
  204. return result
  205. },
  206. // 处理用户要选择的数据
  207. mapCategoryItems(items) {
  208. return (items || []).map((item) => {
  209. // 不能选择当前节点的下级节点
  210. let isLeaf = item.leaf
  211. if (item.id === String(this.$refs.dataTable.getDetailModal().getFieldValue('parentId'))) {
  212. isLeaf = true
  213. }
  214. const result = {
  215. id: item.id,
  216. name: item.text,
  217. checkable: true,
  218. isLeaf,
  219. }
  220. return result
  221. })
  222. },
  223. // 选择上级分类后给对应的域赋值
  224. fnTreePicker(value) {
  225. if (value.length > 0) {
  226. this.$refs.dataTable.getDetailModal().setFieldValue('parentId', value[0].id)
  227. this.$refs.dataTable.getDetailModal().setFieldValue('parentName', value[0].name)
  228. } else {
  229. this.$refs.dataTable.getDetailModal().setFieldValue('parentId', '')
  230. this.$refs.dataTable.getDetailModal().setFieldValue('parentName', '')
  231. }
  232. },
  233. treeSelect(selectedKeys, info) {
  234. this.parentId = info.node.dataRef.id // 父级id
  235. this.parentName = info.node.dataRef.text // 父级名称
  236. this.parentObj = [{ id: info.node.dataRef.id, name: info.node.dataRef.text }]
  237. // 是否公文类
  238. this.isDocType = info.node.dataRef.props.isDoc
  239. this.defaultSelectedKeys = selectedKeys
  240. this.expressions.forEach((item) => {
  241. if (item.name === 'parentId') {
  242. item.stringValue = Number(info.node.dataRef.id)
  243. }
  244. })
  245. this.expressions = [...this.expressions]
  246. this.defaultSelectedKeys = selectedKeys
  247. this.parentId = Number(info.node.dataRef.id)
  248. },
  249. // 部门下拉框选择事件
  250. depChanged(value, info) {
  251. // console.log(value) // 选中的值
  252. // console.log(info.data.props) // 选中的下拉json
  253. },
  254. // 新建保存回调刷新树
  255. onRecordSaved() {
  256. this.key = this.key + 1
  257. },
  258. // 删除回调
  259. onRecordsDeleted() {
  260. this.key = this.key + 1
  261. },
  262. // 设置请求内容
  263. processReq(req) {
  264. // 获取查询内容
  265. const searchExp = req.data.expressions.find((item) => {
  266. return item.dataType === 'exps'
  267. })
  268. const searchText = searchExp?.expressionsValue[0]?.stringValue.replaceAll(/%/g, '')
  269. req.data = {
  270. configId: this.treeparams.configId,
  271. parentId: this.parentId,
  272. key: searchText ?? '',
  273. maxResults: this.pageSize,
  274. startPosition: this.startPosition,
  275. }
  276. return req
  277. },
  278. // 翻页操作
  279. onChange(pagination, filters, sorter) {
  280. this.pageSize = pagination.pageSize
  281. this.startPosition = (pagination.current - 1) * pagination.pageSize
  282. },
  283. },
  284. }
  285. </script>
  286. <style module lang="scss">
  287. @use '@/common/design' as *;
  288. .wrap-height {
  289. height: 100%;
  290. .row-height {
  291. display: flex;
  292. flex: auto;
  293. height: 100%;
  294. .rightcard {
  295. flex: 1;
  296. width: calc(100% - 20%);
  297. height: 100%;
  298. .acard {
  299. min-height: 100%;
  300. }
  301. }
  302. }
  303. }
  304. </style>