DictItemList.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <a-card :bordered="false">
  3. <!-- 抽屉 -->
  4. <a-drawer
  5. title="字典列表"
  6. :width="screenWidth"
  7. :visible="visible"
  8. @close="onClose"
  9. >
  10. <!-- 抽屉内容的border -->
  11. <div>
  12. <div class="table-page-search-wrapper">
  13. <a-form>
  14. <a-row :gutter="10">
  15. <a-col :md="2" :sm="24">
  16. <a-button style="margin-bottom: 10px" type="primary" @click="handleAdd">新增</a-button>
  17. </a-col>
  18. </a-row>
  19. </a-form>
  20. </div>
  21. <div>
  22. <a-table
  23. ref="table"
  24. row-key="id"
  25. size="middle"
  26. :columns="columns"
  27. :data-source="dataSource"
  28. :loading="loading"
  29. @change="handleTableChange"
  30. >
  31. <span slot="action" slot-scope="text, record">
  32. <a @click="handleEdit(record)">编辑</a>
  33. <a-divider type="vertical" />
  34. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.dictId)">
  35. <a>删除</a>
  36. </a-popconfirm>
  37. </span>
  38. </a-table>
  39. </div>
  40. </div>
  41. </a-drawer>
  42. <dict-item-modal ref="modalForm" @ok="modalFormOk" /> <!-- 字典数据 -->
  43. </a-card>
  44. </template>
  45. <script>
  46. import DictItemModal from './DictItemModal'
  47. import { listMixin } from '@/mixin/listMixin'
  48. import { getDicAction } from '@/api/request'
  49. export default {
  50. name: 'DictItemList',
  51. components: { DictItemModal },
  52. mixins: [listMixin],
  53. data() {
  54. return {
  55. columns: [
  56. {
  57. title: '名称',
  58. align: 'center',
  59. dataIndex: 'dictLabel'
  60. },
  61. {
  62. title: '数据值',
  63. align: 'center',
  64. dataIndex: 'dictValue'
  65. },
  66. {
  67. title: '操作',
  68. dataIndex: 'action',
  69. align: 'center',
  70. scopedSlots: { customRender: 'action' }
  71. }
  72. ],
  73. title: '操作',
  74. visible: false,
  75. screenWidth: 800,
  76. model: {},
  77. dictId: '',
  78. labelCol: {
  79. xs: { span: 5 },
  80. sm: { span: 5 }
  81. },
  82. wrapperCol: {
  83. xs: { span: 12 },
  84. sm: { span: 12 }
  85. },
  86. form: this.$form.createForm(this),
  87. validatorRules: {
  88. itemText: { rules: [{ required: true, message: '请输入名称!' }] },
  89. itemValue: { rules: [{ required: true, message: '请输入数据值!' }] }
  90. },
  91. url: {
  92. delete: '/system/dict/data/'
  93. }
  94. }
  95. },
  96. created() {
  97. // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
  98. this.resetScreenSize()
  99. },
  100. methods: {
  101. edit(record) {
  102. if (record.dictId) {
  103. this.dictId = record.dictId
  104. }
  105. this.model = Object.assign({}, record)
  106. this.visible = true
  107. // 当其它模块调用该模块时,调用此方法加载字典数据
  108. this.loadDataTree()
  109. },
  110. // 添加字典数据
  111. handleAdd() {
  112. this.$refs.modalForm.add(this.dictId)
  113. this.$refs.modalForm.title = '新增'
  114. },
  115. handleEdit(record){
  116. this.$refs.modalForm.edit(this.dictId,record)
  117. this.$refs.modalForm.title = '编辑'
  118. },
  119. onClose() {
  120. this.visible = false
  121. this.form.resetFields()
  122. this.dataSource = []
  123. },
  124. // 抽屉的宽度随着屏幕大小来改变
  125. resetScreenSize() {
  126. const screenWidth = document.body.clientWidth
  127. if (screenWidth < 600) {
  128. this.screenWidth = screenWidth
  129. } else {
  130. this.screenWidth = 600
  131. }
  132. },
  133. loadDataTree() {
  134. this.loading = true
  135. getDicAction('/system/dict/data/type/', this.model.dictType).then((res) => {
  136. if (res.code === 200) {
  137. this.dataSource = res.rows || res.data
  138. } else {
  139. this.$message.warning(res.msg)
  140. }
  141. }).finally(() => {
  142. this.loading = false
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="less" scoped>
  149. </style>