iam-audit-modal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div>
  3. <a-modal
  4. ref="auditModal"
  5. :body-style="bodyStyle"
  6. :title="title"
  7. :destroy-on-close="true"
  8. :visible="visible"
  9. :width="modalWidth"
  10. @ok="handleOk"
  11. @cancel="handleCancel"
  12. >
  13. <!-- 列表 -->
  14. <sd-data-table-ex
  15. v-if="selectType === 'table'"
  16. ref="auditModalTable"
  17. data-url="api/xcoa-mobile/v1/iam-choose/getList"
  18. page-id=""
  19. form-id=""
  20. :pagination="{ pageSize: 5 }"
  21. :process-req="processReq"
  22. :filter-expressions="expressions"
  23. :check-type="checkType"
  24. :columns="columns"
  25. :search-fields="searchFields"
  26. show-selection
  27. @onChange="onChange"
  28. >
  29. </sd-data-table-ex>
  30. <!-- 树组件 -->
  31. <div v-if="selectType === 'tree'" :class="$style.treeDiv">
  32. <iam-audit-modaltree
  33. :single="single"
  34. :show-primary="false"
  35. :checkable="true"
  36. :top-node-text="topNodeText"
  37. :treeparams="treeparams"
  38. :default-expanded-keys="['0']"
  39. @treeSelect="treeSelect"
  40. @checkedKeys="checkedKeys"
  41. ></iam-audit-modaltree>
  42. </div>
  43. </a-modal>
  44. </div>
  45. </template>
  46. <script>
  47. import iamAuditModaltree from './iam-audit-modaltree.vue'
  48. import components from './_import-components/iam-audit-modal-import'
  49. function checkIn(list, node) {
  50. let indexNum = -1
  51. list.forEach((item, index) => {
  52. if (item.id === node) {
  53. indexNum = index
  54. }
  55. })
  56. return indexNum
  57. }
  58. export default {
  59. name: 'IamAuditModal',
  60. metaInfo: {
  61. title: 'AuditModal',
  62. },
  63. components: {
  64. ...components,
  65. iamAuditModaltree,
  66. },
  67. props: {
  68. // 弹出窗显示参数
  69. visible: {
  70. type: Boolean,
  71. default: false,
  72. },
  73. // 弹出窗模式 /table表格/tree树
  74. selectType: {
  75. type: String,
  76. default: 'table',
  77. },
  78. // 列表列内容
  79. columns: {
  80. type: Array,
  81. default: () => {
  82. return []
  83. },
  84. },
  85. // 弹出窗标题
  86. title: {
  87. type: String,
  88. default: '请选择',
  89. },
  90. // 弹出窗宽度
  91. modalWidth: {
  92. type: String,
  93. default: '50%',
  94. },
  95. // 树是否显示单选
  96. single: {
  97. type: Boolean,
  98. default: false,
  99. },
  100. // 配置文档ID
  101. treeparams: {
  102. type: Object,
  103. default: () => {
  104. return {
  105. configId: 0,
  106. }
  107. },
  108. },
  109. // 根节点名称
  110. topNodeText: {
  111. type: String,
  112. default: '根节点',
  113. },
  114. /**
  115. * 选择列表单选或者复选 add by zzb 20220224
  116. */
  117. checkType: {
  118. type: String,
  119. default: 'checkbox',
  120. },
  121. },
  122. data() {
  123. return {
  124. searchFields: ['title'],
  125. checkednode: [],
  126. bodyStyle: {
  127. padding: 0,
  128. },
  129. pageSize: 10, // 分页数量
  130. startPosition: 0, // 分页起始数
  131. expressions: [
  132. {
  133. dataType: 'str',
  134. name: 'parentId',
  135. op: 'eq',
  136. stringValue: 0,
  137. },
  138. ],
  139. }
  140. },
  141. mounted() {
  142. if (this.selectType !== 'tree') {
  143. this.bodyStyle.padding = 24
  144. }
  145. },
  146. methods: {
  147. handleOk(e) {
  148. this.$parent.visible = !this.$parent.visible
  149. if (this.selectType === 'table') {
  150. // 列表选择事件,返回选择的数据
  151. this.$emit(
  152. 'listSelected',
  153. this.$refs.auditModalTable.getSelectedRowKeys(),
  154. this.$refs.auditModalTable.getSelectedRows()
  155. )
  156. } else {
  157. // 发布事件,用于父组件获取选择的节点
  158. this.$emit('getCheckNode', this.checkednode)
  159. }
  160. },
  161. handleCancel(e) {
  162. this.$parent.visible = !this.$parent.visible
  163. this.$emit('handleCancel')
  164. },
  165. treeSelect(allCheckNode, checkNode) {
  166. // 判断当前点击节点是否为选中状态
  167. const indexNum = checkIn(this.checkednode, checkNode.node.dataRef.id)
  168. if (indexNum === -1) {
  169. this.checkednode.push(checkNode.node.dataRef)
  170. } else {
  171. this.checkednode.splice(indexNum, 1)
  172. }
  173. },
  174. checkedKeys(checkNode, allCheckNode) {
  175. this.checkednode = []
  176. allCheckNode.forEach((item) => {
  177. this.checkednode.push(item.data.props)
  178. })
  179. },
  180. // 设置请求内容
  181. processReq(req) {
  182. // 获取查询内容
  183. const searchExp = req.data.expressions.find((item) => {
  184. return item.dataType === 'exps'
  185. })
  186. const searchText = searchExp?.expressionsValue[0]?.stringValue.replaceAll(/%/g, '')
  187. req.data = {
  188. configId: this.treeparams.configId,
  189. parentId: this.parentId,
  190. key: searchText ?? '',
  191. maxResults: this.pageSize,
  192. startPosition: this.startPosition,
  193. }
  194. return req
  195. },
  196. // 翻页操作
  197. onChange(pagination, filters, sorter) {
  198. this.pageSize = pagination.pageSize
  199. this.startPosition = (pagination.current - 1) * pagination.pageSize
  200. },
  201. },
  202. }
  203. </script>
  204. <style module lang="scss">
  205. @use '@/common/design' as *;
  206. .tree-div {
  207. height: 350px;
  208. overflow: auto;
  209. width: 100%;
  210. :global(.ant-card) {
  211. width: 100%;
  212. }
  213. }
  214. </style>