dict-value-operate-modal.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!--
  2. * 字典 value 弹窗
  3. *
  4. * @Author: DCCloud
  5. * @Date: 2022-06-08 21:50:41
  6. -->
  7. <template>
  8. <a-modal :open="visible" :title="form.dictValueId ? '编辑' : '添加'" ok-text="确认" cancel-text="取消" @ok="onSubmit"
  9. @cancel="onClose">
  10. <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
  11. <a-form-item label="编码" name="valueCode">
  12. <a-input v-model:value="form.valueCode" placeholder="请输入编码" />
  13. </a-form-item>
  14. <a-form-item label="名称" name="valueName">
  15. <a-input v-model:value="form.valueName" placeholder="请输入名称" />
  16. </a-form-item>
  17. <a-form-item label="主题" name="dictStyle">
  18. <a-select v-model:value="form.dictStyle" placeholder="请选择主题" :options="useBsDict.getDictList('SYS_DICT_TAG_COLOR')" />
  19. </a-form-item>
  20. <a-form-item label="排序" name="sort">
  21. <a-input-number v-model:value="form.sort" :min="0" :max="1000" />
  22. </a-form-item>
  23. <a-form-item label="备注" name="remark">
  24. <textarea v-model="form.remark" style="width: 100%; height: 100px; outline: none"></textarea>
  25. </a-form-item>
  26. </a-form>
  27. </a-modal>
  28. </template>
  29. <script setup>
  30. import { ref, reactive } from 'vue';
  31. import { message } from 'ant-design-vue';
  32. import { SmartLoading } from '/@/components/framework/smart-loading';
  33. import { dictApi } from '/@/api/support/dict-api';
  34. import { smartSentry } from '/@/lib/smart-sentry';
  35. import useBsDict from "/@/utils/dict.js"
  36. // emit
  37. const emit = defineEmits(['reloadList']);
  38. // 组件
  39. const formRef = ref();
  40. const formDefault = {
  41. dictValueId: undefined,
  42. dictKeyId: undefined,
  43. sort: 1,
  44. valueCode: '',
  45. valueName: '',
  46. remark: '',
  47. dictStyle: "default"
  48. };
  49. let form = reactive({ ...formDefault });
  50. const rules = {
  51. valueCode: [{ required: true, message: '请输入编码' }],
  52. valueName: [{ required: true, message: '请输入名称' }],
  53. sort: [{ required: true, message: '请输入排序' }],
  54. };
  55. // 是否展示
  56. const visible = ref(false);
  57. function showModal(rowData, dictKeyId) {
  58. Object.assign(form, formDefault);
  59. if (rowData) {
  60. Object.assign(form, rowData);
  61. }
  62. form.dictKeyId = dictKeyId;
  63. visible.value = true;
  64. }
  65. function onClose() {
  66. Object.assign(form, formDefault);
  67. visible.value = false;
  68. }
  69. function onSubmit() {
  70. formRef.value
  71. .validate()
  72. .then(async () => {
  73. SmartLoading.show();
  74. try {
  75. if (form.dictValueId) {
  76. await dictApi.valueEdit(form);
  77. } else {
  78. await dictApi.valueAdd(form);
  79. }
  80. message.success(`${form.dictKeyId ? '修改' : '添加'}成功`);
  81. emit('reloadList');
  82. onClose();
  83. } catch (error) {
  84. smartSentry.captureError(error);
  85. } finally {
  86. SmartLoading.hide();
  87. }
  88. })
  89. .catch((error) => {
  90. console.log('error', error);
  91. message.error('参数验证错误,请仔细填写表单数据!');
  92. });
  93. }
  94. defineExpose({
  95. showModal,
  96. });
  97. </script>