From d768a385e6e5a7de3e771c7be7ac65a74a9b3d5b Mon Sep 17 00:00:00 2001
From: autumnal_wind@yeah.net <autumnal_wind@yeah.net>
Date: 星期二, 28 五月 2024 16:28:08 +0800
Subject: [PATCH] feat: 数据字典改造
---
src/views/basis/sysParam/config/DetailForm.vue | 43 ++++++++++++++++++++++++++-----------------
1 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/src/views/basis/sysParam/config/DetailForm.vue b/src/views/basis/sysParam/config/DetailForm.vue
index a88a58e..ce7b418 100644
--- a/src/views/basis/sysParam/config/DetailForm.vue
+++ b/src/views/basis/sysParam/config/DetailForm.vue
@@ -1,6 +1,6 @@
<template>
<div class="p-2">
- <dialog :title="dialog.title" :model="dialog.visible" width="500px">
+ <Dialog :title="dialog.title" v-model="dialog.visible" width="600px" :draggable="draggable">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px" v-loading="formLoading">
<el-form-item label="参数名称" prop="configName">
<el-input v-model="formData.configName" placeholder="请输入参数名称"/>
@@ -21,35 +21,43 @@
</el-form-item>
</el-form>
<template #footer>
- <div class="dialog-footer">
- <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
- <el-button @click="dialog.visible = false">取 消</el-button>
- </div>
+ <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
+ <el-button @click="dialog.visible = false">取 消</el-button>
</template>
- </dialog>
+ </Dialog>
</div>
</template>
<script setup lang="ts">
// 模块导入
import {ConfigForm} from "@/api/system/config/types";
-import {addConfig, getConfig, updateConfig} from "@/api/system/config";
+import * as configApi from '@/api/system/config'
+import {useI18n} from "vue-i18n";
-
+defineOptions({ name: 'SysConfigForm' })
// 接收父组件传入属性
// const props = defineProps({})
// 当前组件属性
-const { proxy } = getCurrentInstance() as ComponentInternalInstance;
+const {proxy} = getCurrentInstance() as ComponentInternalInstance;
+// 国际化
+const { t } = useI18n()
+// 数据字典
+const {sys_yes_no} = toRefs<any>(proxy?.useDict("sys_yes_no"));
+// 对话框
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
+// 窗体是否可以拖动
+const draggable = ref(true)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const formLoading = ref(false)
// 表单的类型:create - 新增;update - 修改
const formType = ref('')
+// 表单引用
const formRef = ref<ElFormInstance>();
+// 表单数据
const formData = ref<ConfigForm>({
configId: undefined,
configName: '',
@@ -58,24 +66,25 @@
configType: "Y",
remark: ''
})
+// 表单校验规则
const formRules = reactive({
- configName: [{ required: true, message: "参数名称不能为空", trigger: "blur" }],
- configKey: [{ required: true, message: "参数键名不能为空", trigger: "blur" }],
- configValue: [{ required: true, message: "参数键值不能为空", trigger: "blur" }]
+ configName: [{required: true, message: "参数名称不能为空", trigger: "blur"}],
+ configKey: [{required: true, message: "参数键名不能为空", trigger: "blur"}],
+ configValue: [{required: true, message: "参数键值不能为空", trigger: "blur"}]
})
/** 当前组件方法 */
/** 窗体打开事件 */
const open = async (type: string, id?: number) => {
dialog.visible = true
- dialog.title = type
+ dialog.title = t('action.' + type)
formType.value = type
resetForm()
// 修改时,设置数据
if (id) {
formLoading.value = true
try {
- const res = await getConfig(id);
+ const res = await configApi.getConfig(id);
Object.assign(formData.value, res.data);
} finally {
formLoading.value = false
@@ -96,7 +105,7 @@
}
// 传回给父组件的属性与方法
// 提供 open 方法,用于打开弹窗
- defineExpose({open})
+defineExpose({open})
/** 触发父组件的事件 */
/** 定义 success 事件,用于操作成功后的回调 */
@@ -112,10 +121,10 @@
try {
const data = formData.value as unknown as ConfigForm
if (formType.value === 'create') {
- await addConfig(data)
+ await configApi.addConfig(data)
proxy?.$modal.msgSuccess("新增参数成功");
} else {
- await updateConfig(data)
+ await configApi.updateConfig(data)
proxy?.$modal.msgSuccess("修改参数成功");
}
dialog.visible = false
--
Gitblit v1.8.0