refactor(CURD): ♻️ 优化和修改使用示例
This commit is contained in:
@@ -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<UserForm> = {
|
||||
@@ -26,6 +24,10 @@ const modalConfig: IModalConfig<UserForm> = {
|
||||
attrs: {
|
||||
placeholder: "请输入用户名",
|
||||
},
|
||||
col: {
|
||||
xs: 24,
|
||||
sm: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "用户昵称",
|
||||
@@ -35,6 +37,10 @@ const modalConfig: IModalConfig<UserForm> = {
|
||||
attrs: {
|
||||
placeholder: "请输入用户昵称",
|
||||
},
|
||||
col: {
|
||||
xs: 24,
|
||||
sm: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "所属部门",
|
||||
@@ -48,14 +54,12 @@ const modalConfig: IModalConfig<UserForm> = {
|
||||
"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<UserForm> = {
|
||||
multiple: true,
|
||||
},
|
||||
options: [],
|
||||
async initFn(formItem) {
|
||||
this.options = await RoleAPI.getOptions();
|
||||
},
|
||||
initialValue: [],
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
@@ -103,29 +105,18 @@ const modalConfig: IModalConfig<UserForm> = {
|
||||
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);
|
||||
|
||||
@@ -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<UserForm> = {
|
||||
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<UserForm> = {
|
||||
"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<UserForm> = {
|
||||
multiple: true,
|
||||
},
|
||||
options: [],
|
||||
async initFn(formItem) {
|
||||
this.options = await RoleAPI.getOptions();
|
||||
},
|
||||
initialValue: [],
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
@@ -107,18 +100,8 @@ const modalConfig: IModalConfig<UserForm> = {
|
||||
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<UserForm> = {
|
||||
],
|
||||
};
|
||||
|
||||
export default modalConfig;
|
||||
export default reactive(modalConfig);
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
<template #mobile="scope">
|
||||
<el-text> {{ scope.row[scope.prop] }} </el-text>
|
||||
<el-text>{{ scope.row[scope.prop] }}</el-text>
|
||||
<copy-button
|
||||
v-if="scope.row[scope.prop]"
|
||||
:text="scope.row[scope.prop]"
|
||||
@@ -90,6 +90,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user