RulesDatail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div class="container">
  3. <el-form ref="form" :model="form">
  4. <ele-pro-table
  5. style="height: 100%"
  6. ref="table"
  7. :columns="columns"
  8. :datasource="form.datasource"
  9. :page-size="20"
  10. @columns-change="handleColumnChange"
  11. :cache-key="cacheKeyUrl"
  12. height="calc(100% - 100px)"
  13. :needPage="false"
  14. >
  15. <!-- 表头工具栏 -->
  16. <template v-slot:toolbar>
  17. <el-button
  18. size="small"
  19. type="primary"
  20. icon="el-icon-plus"
  21. class="ele-btn-icon"
  22. @click="addHandler"
  23. v-if="$hasPermission('main:team:save')"
  24. >
  25. 添加脱敏规则
  26. </el-button>
  27. </template>
  28. <!-- 操作列 -->
  29. <template v-slot:action="{ row, $index }">
  30. <el-popconfirm
  31. class="ele-action"
  32. title="确定要删除此信息吗?"
  33. @confirm="handleDelInfo($index)"
  34. >
  35. <template v-slot:reference>
  36. <el-link type="danger" :underline="false" icon="el-icon-delete">
  37. 删除
  38. </el-link>
  39. </template>
  40. </el-popconfirm>
  41. </template>
  42. <template v-slot:fieldName="{ row, $index }">
  43. <el-form-item
  44. :prop="'datasource.' + $index + '.fieldName'"
  45. :rules="{
  46. required: true,
  47. message: '请输入脱敏字段key',
  48. trigger: ['blur']
  49. }"
  50. >
  51. <el-input v-model="row.fieldName" clearable></el-input>
  52. </el-form-item>
  53. </template>
  54. <template v-slot:fieldAlias="{ row, $index }">
  55. <el-form-item
  56. :prop="'datasource.' + $index + '.fieldAlias'"
  57. :rules="{
  58. required: true,
  59. message: '请输入脱敏字段名称',
  60. trigger: ['blur']
  61. }"
  62. >
  63. <el-input v-model="row.fieldAlias" clearable></el-input>
  64. </el-form-item>
  65. </template>
  66. <template v-slot:typeId="{ row, $index }">
  67. <el-form-item
  68. :prop="'datasource.' + $index + '.typeId'"
  69. :rules="{
  70. required: true,
  71. message: '请选择',
  72. trigger: ['blur', 'change']
  73. }"
  74. >
  75. <el-select
  76. v-if="typeList.length"
  77. v-model="row.typeId"
  78. collapse-tags
  79. filterable
  80. placeholder="请选择"
  81. style="width: 100%"
  82. clearable
  83. size="medium"
  84. >
  85. <el-option
  86. v-for="item in typeList"
  87. :key="item.id"
  88. :label="item.dataName"
  89. :value="item.id"
  90. >
  91. </el-option>
  92. </el-select>
  93. </el-form-item>
  94. </template>
  95. <template v-slot:roleAuthorityList="{ row, $index }">
  96. <el-form-item :prop="'datasource.' + $index + '.roleAuthorityList'">
  97. <el-select
  98. v-if="roleList.length"
  99. v-model="row.roleAuthorityList"
  100. multiple
  101. filterable
  102. placeholder="请选择"
  103. style="width: 100%"
  104. clearable
  105. size="medium"
  106. >
  107. <el-option
  108. v-for="item in roleList"
  109. :key="item.id"
  110. :label="item.name"
  111. :value="item.id"
  112. >
  113. </el-option>
  114. </el-select>
  115. </el-form-item>
  116. </template>
  117. <template v-slot:userAuthorityList="{ row, $index }">
  118. <el-form-item :prop="'datasource.' + $index + '.userAuthorityList'">
  119. <el-select
  120. :ref="'userRef' + $index"
  121. v-if="userList.length"
  122. v-model="row.userAuthorityList"
  123. multiple
  124. filterable
  125. placeholder="请选择"
  126. style="width: 100%"
  127. clearable
  128. size="medium"
  129. @focus.prevent="openUserPage(row, $index)"
  130. >
  131. <el-option
  132. v-for="item in userList"
  133. :key="item.id"
  134. :label="item.name"
  135. :value="item.id"
  136. >
  137. </el-option>
  138. </el-select>
  139. </el-form-item>
  140. </template>
  141. <template v-slot:status="{ row, $index }">
  142. <el-form-item :prop="'datasource.' + $index + '.status'">
  143. <el-switch
  144. v-model="row.status"
  145. :active-text="row.status == 1 ? '启用' : '停用'"
  146. :active-value="1"
  147. :inactive-value="0"
  148. >
  149. </el-switch>
  150. </el-form-item>
  151. </template>
  152. <template v-slot:headerRequired="{ column }">
  153. <span class="is-required">{{ column.label }}</span>
  154. </template>
  155. </ele-pro-table>
  156. </el-form>
  157. <UserPage
  158. @success="userSelect"
  159. ref="UserPage"
  160. :visible.sync="userVisible"
  161. ></UserPage>
  162. </div>
  163. </template>
  164. <script>
  165. import tabMixins from '@/mixins/tableColumnsMixin';
  166. import UserPage from './UserPage.vue';
  167. import { getRolesListAPI } from '@/api/system/role';
  168. import { getUserPage } from '@/api/system/organization';
  169. import { pageDatadesensitizetype } from '@/api/system/dataDesensitization';
  170. export default {
  171. mixins: [tabMixins],
  172. components: { UserPage },
  173. props: {
  174. detailList: {
  175. type: Array,
  176. default: () => []
  177. }
  178. },
  179. watch: {
  180. detailList: {
  181. handler(newValue) {
  182. this.form.datasource = newValue;
  183. }
  184. }
  185. },
  186. data() {
  187. return {
  188. cacheKeyUrl: 'mainData-system-dataDesensitization',
  189. form: {
  190. datasource: []
  191. },
  192. roleList: [],
  193. userList: [],
  194. typeList: [],
  195. index: null,
  196. userVisible: false
  197. };
  198. },
  199. computed: {
  200. columns() {
  201. let arr = [
  202. {
  203. width: 55,
  204. label: '序号',
  205. type: 'index',
  206. columnKey: 'index',
  207. align: 'center',
  208. fixed: 'left'
  209. },
  210. {
  211. prop: 'fieldAlias',
  212. slot: 'fieldAlias',
  213. label: '脱敏字段名称',
  214. width: 120,
  215. align: 'center',
  216. showOverflowTooltip: true,
  217. headerSlot: 'headerRequired'
  218. },
  219. {
  220. prop: 'fieldName',
  221. slot: 'fieldName',
  222. label: '脱敏字段key',
  223. width: 120,
  224. align: 'center',
  225. showOverflowTooltip: true,
  226. headerSlot: 'headerRequired'
  227. },
  228. {
  229. prop: 'typeId',
  230. slot: 'typeId',
  231. label: '脱敏规则类型',
  232. align: 'center',
  233. width: 150,
  234. showOverflowTooltip: true,
  235. headerSlot: 'headerRequired'
  236. },
  237. {
  238. prop: 'roleAuthorityList',
  239. slot: 'roleAuthorityList',
  240. label: '可查看角色',
  241. align: 'center',
  242. showOverflowTooltip: true
  243. },
  244. {
  245. prop: 'userAuthorityList',
  246. slot: 'userAuthorityList',
  247. label: '可查看账号',
  248. align: 'center',
  249. showOverflowTooltip: true
  250. },
  251. {
  252. prop: 'status',
  253. slot: 'status',
  254. width: 120,
  255. label: '启用状态',
  256. slot: 'status',
  257. align: 'center',
  258. showOverflowTooltip: true
  259. },
  260. {
  261. columnKey: 'action',
  262. label: '操作',
  263. width: 80,
  264. align: 'center',
  265. resizable: false,
  266. slot: 'action',
  267. showOverflowTooltip: true,
  268. fixed: 'right'
  269. }
  270. ];
  271. return arr;
  272. }
  273. },
  274. methods: {
  275. async getRolesList() {
  276. const res = await getRolesListAPI();
  277. this.roleList = res;
  278. },
  279. async getUserList() {
  280. let { list } = await getUserPage({ pageNum: 1, size: -1 });
  281. this.userList = list;
  282. },
  283. async getTypeList() {
  284. let res = await pageDatadesensitizetype({
  285. pageNum: 1,
  286. size: -1
  287. });
  288. this.typeList = res.list;
  289. },
  290. addHandler() {
  291. this.form.datasource.push({
  292. fieldName: '',
  293. fieldAlias: '',
  294. typeId: '',
  295. roleAuthorityList: [],
  296. userAuthorityList: [],
  297. status: 1
  298. });
  299. },
  300. openUserPage(row, index) {
  301. console.log(row);
  302. this.index = index;
  303. console.log(this.$refs);
  304. let ref = 'userRef' + index;
  305. this.$refs[ref].blur();
  306. this.$refs.UserPage.open('1', row.userAuthorityList);
  307. // this.userVisible = true;
  308. },
  309. visibleType() {
  310. this.$nextTick(() => {
  311. this.$refs.userRef.blur();
  312. });
  313. },
  314. userSelect(e) {
  315. let ids = e.data.map((item) => item.id);
  316. console.log(this.index);
  317. this.$set(this.form.datasource[this.index], 'userAuthorityList', ids);
  318. console.log(e);
  319. },
  320. handleDelInfo(index) {
  321. this.form.datasource.splice(index, 1);
  322. },
  323. getTableValidate() {
  324. return new Promise((resolve, reject) => {
  325. // if (this.form.datasource.length == 0) return this.$message.warning('请添加至少一条交付物信息')
  326. this.$refs.form.validate((valid) => {
  327. if (!valid) {
  328. this.$message.warning('有必填项未填,请检查');
  329. reject('有必填项未填,请检查');
  330. } else {
  331. resolve(this.form.datasource);
  332. }
  333. });
  334. });
  335. }
  336. },
  337. created() {
  338. if (this.detailList.length) {
  339. this.form.datasource = detailList;
  340. }
  341. this.getRolesList();
  342. this.getUserList();
  343. this.getTypeList();
  344. }
  345. };
  346. </script>
  347. <style lang="scss" scoped>
  348. .container {
  349. width: 100%;
  350. height: 100%;
  351. }
  352. table th .is-required:before {
  353. content: '*';
  354. color: red;
  355. margin-right: 4px;
  356. }
  357. </style>