diff --git a/src/components/CURD/PageForm.vue b/src/components/CURD/PageForm.vue
index 524a6a4b..0979019e 100644
--- a/src/components/CURD/PageForm.vue
+++ b/src/components/CURD/PageForm.vue
@@ -149,7 +149,7 @@ prepareFuncs.forEach((func) => func());
// 获取表单数据
function getFormData(key?: string) {
- return key === undefined ? formData : formData[key] ?? undefined;
+ return key === undefined ? formData : (formData[key] ?? undefined);
}
// 设置表单值
diff --git a/src/components/CURD/PageModal.vue b/src/components/CURD/PageModal.vue
index 37854c11..214b28e1 100644
--- a/src/components/CURD/PageModal.vue
+++ b/src/components/CURD/PageModal.vue
@@ -133,7 +133,7 @@
确 定
- 取 消
+ 取 消
@@ -285,7 +285,7 @@
确 定
- 取 消
+ 取 消
@@ -399,15 +399,19 @@ const handleSubmit = useThrottleFn(() => {
}
ElMessage.success(msg);
emit("submitClick");
- handleCloseModal();
+ handleClose();
});
}
});
}, 3000);
+// 隐藏弹窗
+function handleClose() {
+ modalVisible.value = false;
+}
+
// 关闭弹窗
function handleCloseModal() {
- modalVisible.value = false;
formRef.value?.resetFields();
nextTick(() => {
formRef.value?.clearValidate();
diff --git a/src/views/demo/curd/config/add.ts b/src/views/demo/curd/config/add.ts
index 38bcf59d..6a33ebce 100644
--- a/src/views/demo/curd/config/add.ts
+++ b/src/views/demo/curd/config/add.ts
@@ -1,6 +1,4 @@
-import DeptAPI from "@/api/dept";
-import RoleAPI from "@/api/role";
-import UserAPI, { UserForm } from "@/api/user";
+import UserAPI, { type UserForm } from "@/api/user";
import type { IModalConfig } from "@/components/CURD/types";
const modalConfig: IModalConfig
= {
@@ -26,6 +24,10 @@ const modalConfig: IModalConfig = {
attrs: {
placeholder: "请输入用户名",
},
+ col: {
+ xs: 24,
+ sm: 12,
+ },
},
{
label: "用户昵称",
@@ -35,6 +37,10 @@ const modalConfig: IModalConfig = {
attrs: {
placeholder: "请输入用户昵称",
},
+ col: {
+ xs: 24,
+ sm: 12,
+ },
},
{
label: "所属部门",
@@ -48,14 +54,12 @@ const modalConfig: IModalConfig = {
"check-strictly": true,
"render-after-expand": false,
},
- async initFn(formItem) {
- formItem.attrs.data = await DeptAPI.getOptions();
- },
},
{
type: "custom",
label: "性别",
prop: "gender",
+ initialValue: 1,
},
{
label: "角色",
@@ -67,9 +71,7 @@ const modalConfig: IModalConfig = {
multiple: true,
},
options: [],
- async initFn(formItem) {
- this.options = await RoleAPI.getOptions();
- },
+ initialValue: [],
},
{
type: "input",
@@ -103,29 +105,18 @@ const modalConfig: IModalConfig = {
maxlength: 50,
},
},
- // {
- // label: "状态",
- // prop: "status",
- // type: "radio",
- // options: [
- // { label: "正常", value: 1 },
- // { label: "禁用", value: 0 },
- // ],
- // initialValue: 1,
- // },
{
label: "状态",
prop: "status",
- type: "switch",
- attrs: {
- activeText: "正常",
- inactiveText: "禁用",
- activeValue: 1,
- inactiveValue: 0,
- },
+ type: "radio",
+ options: [
+ { label: "正常", value: 1 },
+ { label: "禁用", value: 0 },
+ ],
initialValue: 1,
},
],
};
-export default modalConfig;
+// 如果有异步数据会修改配置的,推荐用reactive包裹,而纯静态配置的可以直接导出
+export default reactive(modalConfig);
diff --git a/src/views/demo/curd/config/edit.ts b/src/views/demo/curd/config/edit.ts
index bbcf2cb1..2a509644 100644
--- a/src/views/demo/curd/config/edit.ts
+++ b/src/views/demo/curd/config/edit.ts
@@ -1,7 +1,4 @@
-import DeptAPI from "@/api/dept";
-import RoleAPI from "@/api/role";
-import UserAPI from "@/api/user";
-import type { UserForm } from "@/api/user";
+import UserAPI, { type UserForm } from "@/api/user";
import type { IModalConfig } from "@/components/CURD/types";
import { DeviceEnum } from "@/enums/DeviceEnum";
import { useAppStore } from "@/store";
@@ -11,7 +8,7 @@ const modalConfig: IModalConfig = {
component: "drawer",
drawer: {
title: "修改用户",
- size: useAppStore().device === DeviceEnum.MOBILE ? "90%" : 600,
+ size: useAppStore().device === DeviceEnum.MOBILE ? "80%" : 500,
},
pk: "id",
formAction: function (data) {
@@ -52,14 +49,12 @@ const modalConfig: IModalConfig = {
"check-strictly": true,
"render-after-expand": false,
},
- async initFn(formItem) {
- formItem.attrs.data = await DeptAPI.getOptions();
- },
},
{
type: "custom",
label: "性别",
prop: "gender",
+ initialValue: 1,
},
{
label: "角色",
@@ -71,9 +66,7 @@ const modalConfig: IModalConfig = {
multiple: true,
},
options: [],
- async initFn(formItem) {
- this.options = await RoleAPI.getOptions();
- },
+ initialValue: [],
},
{
type: "input",
@@ -107,18 +100,8 @@ const modalConfig: IModalConfig = {
maxlength: 50,
},
},
- // {
- // label: "状态",
- // prop: "status",
- // type: "radio",
- // options: [
- // { label: "正常", value: 1 },
- // { label: "禁用", value: 0 },
- // ],
- // initialValue: 1,
- // },
{
- label: "状态123",
+ label: "状态",
prop: "status",
type: "switch",
attrs: {
@@ -131,4 +114,4 @@ const modalConfig: IModalConfig = {
],
};
-export default modalConfig;
+export default reactive(modalConfig);
diff --git a/src/views/demo/curd/index.vue b/src/views/demo/curd/index.vue
index c4a146ad..e648cbc4 100644
--- a/src/views/demo/curd/index.vue
+++ b/src/views/demo/curd/index.vue
@@ -41,7 +41,7 @@
- {{ scope.row[scope.prop] }}
+ {{ scope.row[scope.prop] }}
import UserAPI from "@/api/user";
+import DeptAPI from "@/api/dept";
+import RoleAPI from "@/api/role";
import type { IObject, IOperatData } from "@/components/CURD/types";
import usePage from "@/components/CURD/usePage";
import addModalConfig from "./config/add";
@@ -105,18 +107,32 @@ const {
editModalRef,
handleQueryClick,
handleResetClick,
- handleAddClick,
+ // handleAddClick,
// handleEditClick,
handleSubmitClick,
handleExportClick,
handleSearchClick,
handleFilterChange,
} = usePage();
+
+// 新增
+async function handleAddClick() {
+ addModalRef.value?.setModalVisible();
+ // 加载部门下拉数据源
+ addModalConfig.formItems[2]!.attrs!.data = await DeptAPI.getOptions();
+ // 加载角色下拉数据源
+ addModalConfig.formItems[4]!.options = await RoleAPI.getOptions();
+}
// 编辑
async function handleEditClick(row: IObject) {
+ editModalRef.value?.setModalVisible();
+ // 加载部门下拉数据源
+ editModalConfig.formItems[2]!.attrs!.data = await DeptAPI.getOptions();
+ // 加载角色下拉数据源
+ editModalConfig.formItems[4]!.options = await RoleAPI.getOptions();
// 根据id获取数据进行填充
const data = await UserAPI.getFormData(row.id);
- editModalRef.value?.setModalVisible(data);
+ editModalRef.value?.setFormData(data);
}
// 其他工具栏
function handleToolbarClick(name: string) {