DictItemList.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. :pagination="false"
  29. :loading="loading"
  30. @change="handleTableChange"
  31. >
  32. <span slot="action" slot-scope="text, record">
  33. <a @click="handleEdit(record)">编辑</a>
  34. <a-divider type="vertical" />
  35. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.dictCode)">
  36. <a>删除</a>
  37. </a-popconfirm>
  38. </span>
  39. </a-table>
  40. </div>
  41. </div>
  42. </a-drawer>
  43. <dict-item-modal ref="modalForm" @ok="modalFormOk" /> <!-- 字典数据 -->
  44. </a-card>
  45. </template>
  46. <script>
  47. import DictItemModal from './DictItemModal'
  48. import { listMixin } from '@/mixin/listMixin'
  49. export default {
  50. name: 'DictItemList',
  51. components: { DictItemModal },
  52. mixins: [listMixin],
  53. data() {
  54. return {
  55. createMixin: true,
  56. columns: [
  57. {
  58. title: '名称',
  59. align: 'center',
  60. dataIndex: 'dictLabel'
  61. },
  62. {
  63. title: '数据值',
  64. align: 'center',
  65. dataIndex: 'dictValue'
  66. },
  67. {
  68. title: '操作',
  69. dataIndex: 'action',
  70. align: 'center',
  71. scopedSlots: { customRender: 'action' }
  72. }
  73. ],
  74. isDict: true,
  75. title: '操作',
  76. visible: false,
  77. screenWidth: 800,
  78. model: {},
  79. dictId: '',
  80. labelCol: {
  81. xs: { span: 5 },
  82. sm: { span: 5 }
  83. },
  84. wrapperCol: {
  85. xs: { span: 12 },
  86. sm: { span: 12 }
  87. },
  88. form: this.$form.createForm(this),
  89. validatorRules: {
  90. itemText: { rules: [{ required: true, message: '请输入名称!' }] },
  91. itemValue: { rules: [{ required: true, message: '请输入数据值!' }] }
  92. },
  93. url: {
  94. list: '/system/dict/data/type/',
  95. delete: '/system/dict/data/'
  96. }
  97. }
  98. },
  99. created() {
  100. // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
  101. this.resetScreenSize()
  102. },
  103. methods: {
  104. edit(record) {
  105. if (record.dictId) {
  106. this.dictId = record.dictId
  107. }
  108. this.model = Object.assign({}, record)
  109. this.visible = true
  110. // 当其它模块调用该模块时,调用此方法加载字典数据
  111. this.loadData()
  112. },
  113. // 添加字典数据
  114. handleAdd() {
  115. this.$refs.modalForm.add(this.dictId, this.model)
  116. this.$refs.modalForm.title = '新增'
  117. },
  118. handleEdit(record) {
  119. this.$refs.modalForm.edit(this.dictId, record)
  120. this.$refs.modalForm.title = '编辑'
  121. },
  122. onClose() {
  123. this.visible = false
  124. this.form.resetFields()
  125. this.dataSource = []
  126. },
  127. // 抽屉的宽度随着屏幕大小来改变
  128. resetScreenSize() {
  129. const screenWidth = document.body.clientWidth
  130. if (screenWidth < 600) {
  131. this.screenWidth = screenWidth
  132. } else {
  133. this.screenWidth = 600
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="less" scoped>
  140. </style>