index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="container">
  3. <div class="head-title">
  4. <span> 字典 </span>
  5. <div class="form-row">
  6. <a-input v-model="formData.type_key" style="margin: 0 0.6rem" placeholder="请输入type_key" />
  7. <a-input v-model="formData.type_label" style="margin: 0 0.6rem" placeholder="请输入type_label" />
  8. <a-button type="primary" style="margin: 0 0.6rem" @click="intData">
  9. <template #icon>
  10. <icon-search />
  11. </template>
  12. 查询
  13. </a-button>
  14. <!-- <a-button style="margin: 0 0.6rem 0 0" @click="intData">重置</a-button> -->
  15. <a-button type="primary" @click="dictShowModel(1, null)">添加字典</a-button>
  16. </div>
  17. </div>
  18. <a-table :data="dataSource" :columns="columns" :scroll="{ x: 'auto' }">
  19. <template #operation="{ record }">
  20. <a class="a-link" href="javascript:;" style="margin: 0 1rem;" @click="dictShowModel(2, record)">修改</a>
  21. <a-popconfirm :content="`是否确认删除字典编号为 ${record.id} 的数据项?`" @ok="deleteChange(record.id)" type="warning">
  22. <a class="a-link" href="javascript:;" style="color: red;">删除</a>
  23. </a-popconfirm>
  24. </template>
  25. </a-table>
  26. <!-- 弹框 -->
  27. <a-modal :title="typeCurrent == 1 ? '添加字典' : '修改字典'" v-model:visible="visible" @onCancel="resetForm" centered
  28. :maskClosable="false" :footer="null">
  29. <a-form ref="formRef" :rules="rules" :model="formState" @submit="handleSubmit">
  30. <a-form-item label="字典名称" field="label">
  31. <a-input v-model="formState.label" />
  32. </a-form-item>
  33. <a-form-item label="key" field="value">
  34. <a-input v-model="formState.value" />
  35. </a-form-item>
  36. <a-form-item label="字典类型" field="typeLabel">
  37. <a-input v-model="formState.typeLabel" />
  38. </a-form-item>
  39. <a-form-item label="数据键值" field="typeKey">
  40. <a-input v-model="formState.typeKey" />
  41. </a-form-item>
  42. <a-form-item label="备注" field="remark">
  43. <a-textarea v-model="formState.remark" />
  44. </a-form-item>
  45. <a-form-item>
  46. <a-button type="primary" html-type="submit" style="margin-right: 10px;">确定</a-button>
  47. <a-button @click="$refs.formRef.resetFields(); visible = false;">取消</a-button>
  48. </a-form-item>
  49. </a-form>
  50. </a-modal>
  51. </div>
  52. </template>
  53. <script setup>
  54. import { onMounted, ref, reactive } from "vue";
  55. import { dictionaryList, dictionaryAdd, dictionaryDelete, dictionaryUpdate } from '@/api/path/dict';
  56. const visible = ref(false);
  57. const typeCurrent = ref(null);
  58. const formRef = ref();
  59. const dicId = ref(null);
  60. const formData = ref({
  61. type_key: '',
  62. type_label: ''
  63. });
  64. const columns = ref([
  65. { title: '字典编号', dataIndex: 'id', align: 'center', width: 120 },
  66. { title: '字典名称', dataIndex: 'label', align: 'center', width: 120 },
  67. { title: '字典类型', dataIndex: 'type_label', align: 'center', width: 120 },
  68. {
  69. title: '备注',
  70. dataIndex: 'remark',
  71. align: 'center',
  72. width: 180
  73. },
  74. { title: '创建时间', dataIndex: 'created_at', align: 'center', width: 200 },
  75. {
  76. title: '操作',
  77. dataIndex: 'id',
  78. slotName: 'operation',
  79. align: 'center',
  80. width: 220,
  81. fixed: "right",
  82. }
  83. ])
  84. const rules = {
  85. label: [{ required: true, trigger: 'change', }],
  86. value: [
  87. {
  88. required: true,
  89. trigger: 'change',
  90. },
  91. ],
  92. typeKey: [
  93. {
  94. required: true,
  95. trigger: 'change',
  96. },
  97. ],
  98. typeLabel: [
  99. {
  100. required: true,
  101. trigger: 'change',
  102. },
  103. ],
  104. remark: [
  105. {
  106. required: true,
  107. trigger: 'change',
  108. },
  109. ],
  110. };
  111. const formState = reactive({
  112. label: '',
  113. value: '',
  114. typeKey: '',
  115. typeLabel: '',
  116. remark: '',
  117. });
  118. const pageData = ref({
  119. total: 0,
  120. pageSize: 10,
  121. current: 1,
  122. })
  123. const dataSource = ref([]);
  124. // 列表
  125. const intData = async () => {
  126. const param = {
  127. current: pageData.value.current,
  128. size: pageData.value.pageSize,
  129. ...formData.value
  130. }
  131. const { data } = await dictionaryList(param)
  132. dataSource.value = data.records;
  133. pageData.value.total = data.total;
  134. }
  135. // 提交
  136. const handleSubmit = ({ values, errors }) => {
  137. const submitData = {
  138. label: formState.label,
  139. value: formState.value,
  140. typeKey: formState.typeKey,
  141. typeLabel: formState.typeLabel,
  142. remark: formState.remark,
  143. id: typeCurrent == 1 ? undefined : dicId.value
  144. }
  145. if (typeCurrent == 1) {
  146. dictionaryAdd(submitData).then(res => {
  147. intData();
  148. visible.value = false;
  149. })
  150. } else {
  151. dictionaryUpdate(submitData).then(res => {
  152. intData();
  153. visible.value = false;
  154. })
  155. }
  156. }
  157. // 删除
  158. const deleteChange = (e) => {
  159. dictionaryDelete({ id: e }).then(res => {
  160. console.log(res, '///////////');
  161. })
  162. }
  163. // 弹框
  164. const dictShowModel = (type, data) => {
  165. typeCurrent.value = type;
  166. visible.value = true;
  167. if (type == 2) {
  168. console.log(data.id);
  169. dicId.value = data.id;
  170. formState.label = data.label;
  171. formState.value = data.value;
  172. formState.typeKey = data.type_key;
  173. formState.typeLabel = data.type_label;
  174. formState.remark = data.remark;
  175. }
  176. }
  177. // 取消
  178. const resetForm = () => {
  179. visible.value = false;
  180. }
  181. onMounted(() => {
  182. intData();
  183. })
  184. </script>
  185. <style scoped lang="less">
  186. .container {
  187. .head-title {
  188. display: flex;
  189. justify-content: space-between;
  190. }
  191. .form-row {
  192. display: flex;
  193. }
  194. }
  195. </style>