Merge pull request #160 from cshaptx4869/patch-103
refactor(CURD): ♻️ 优化和修改使用示例
This commit is contained in:
@@ -245,7 +245,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<!-- 格式化为百分比 -->
|
<!-- 格式化为百分比 -->
|
||||||
<template v-else-if="col.templet === 'percent'">
|
<template v-else-if="col.templet === 'percent'">
|
||||||
<template v-if="col.prop"> {{ scope.row[col.prop] }}% </template>
|
<template v-if="col.prop">{{ scope.row[col.prop] }}%</template>
|
||||||
</template>
|
</template>
|
||||||
<!-- 显示图标 -->
|
<!-- 显示图标 -->
|
||||||
<template v-else-if="col.templet === 'icon'">
|
<template v-else-if="col.templet === 'icon'">
|
||||||
@@ -448,7 +448,8 @@
|
|||||||
>
|
>
|
||||||
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
||||||
<div class="el-upload__text">
|
<div class="el-upload__text">
|
||||||
将文件拖到此处,或<em>点击上传</em>
|
<span>将文件拖到此处,或</span>
|
||||||
|
<em>点击上传</em>
|
||||||
</div>
|
</div>
|
||||||
<template #tip>
|
<template #tip>
|
||||||
<div class="el-upload__tip">
|
<div class="el-upload__tip">
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ prepareFuncs.forEach((func) => func());
|
|||||||
|
|
||||||
// 获取表单数据
|
// 获取表单数据
|
||||||
function getFormData(key?: string) {
|
function getFormData(key?: string) {
|
||||||
return key === undefined ? formData : formData[key] ?? undefined;
|
return key === undefined ? formData : (formData[key] ?? undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置表单值
|
// 设置表单值
|
||||||
|
|||||||
@@ -133,7 +133,7 @@
|
|||||||
<template #footer>
|
<template #footer>
|
||||||
<div>
|
<div>
|
||||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
||||||
<el-button @click="handleCloseModal">取 消</el-button>
|
<el-button @click="handleClose">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
<template #footer>
|
<template #footer>
|
||||||
<div style="padding-right: var(--el-dialog-padding-primary)">
|
<div style="padding-right: var(--el-dialog-padding-primary)">
|
||||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
||||||
<el-button @click="handleCloseModal">取 消</el-button>
|
<el-button @click="handleClose">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@@ -399,15 +399,19 @@ const handleSubmit = useThrottleFn(() => {
|
|||||||
}
|
}
|
||||||
ElMessage.success(msg);
|
ElMessage.success(msg);
|
||||||
emit("submitClick");
|
emit("submitClick");
|
||||||
handleCloseModal();
|
handleClose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
|
// 隐藏弹窗
|
||||||
|
function handleClose() {
|
||||||
|
modalVisible.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
// 关闭弹窗
|
// 关闭弹窗
|
||||||
function handleCloseModal() {
|
function handleCloseModal() {
|
||||||
modalVisible.value = false;
|
|
||||||
formRef.value?.resetFields();
|
formRef.value?.resetFields();
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
formRef.value?.clearValidate();
|
formRef.value?.clearValidate();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import DeptAPI from "@/api/dept";
|
import UserAPI, { type UserForm } from "@/api/user";
|
||||||
import RoleAPI from "@/api/role";
|
|
||||||
import UserAPI, { UserForm } from "@/api/user";
|
|
||||||
import type { IModalConfig } from "@/components/CURD/types";
|
import type { IModalConfig } from "@/components/CURD/types";
|
||||||
|
|
||||||
const modalConfig: IModalConfig<UserForm> = {
|
const modalConfig: IModalConfig<UserForm> = {
|
||||||
@@ -26,6 +24,10 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
attrs: {
|
attrs: {
|
||||||
placeholder: "请输入用户名",
|
placeholder: "请输入用户名",
|
||||||
},
|
},
|
||||||
|
col: {
|
||||||
|
xs: 24,
|
||||||
|
sm: 12,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "用户昵称",
|
label: "用户昵称",
|
||||||
@@ -35,6 +37,10 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
attrs: {
|
attrs: {
|
||||||
placeholder: "请输入用户昵称",
|
placeholder: "请输入用户昵称",
|
||||||
},
|
},
|
||||||
|
col: {
|
||||||
|
xs: 24,
|
||||||
|
sm: 12,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "所属部门",
|
label: "所属部门",
|
||||||
@@ -48,14 +54,12 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
"check-strictly": true,
|
"check-strictly": true,
|
||||||
"render-after-expand": false,
|
"render-after-expand": false,
|
||||||
},
|
},
|
||||||
async initFn(formItem) {
|
|
||||||
formItem.attrs.data = await DeptAPI.getOptions();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "custom",
|
type: "custom",
|
||||||
label: "性别",
|
label: "性别",
|
||||||
prop: "gender",
|
prop: "gender",
|
||||||
|
initialValue: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "角色",
|
label: "角色",
|
||||||
@@ -67,9 +71,7 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
multiple: true,
|
multiple: true,
|
||||||
},
|
},
|
||||||
options: [],
|
options: [],
|
||||||
async initFn(formItem) {
|
initialValue: [],
|
||||||
this.options = await RoleAPI.getOptions();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
@@ -103,29 +105,18 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// label: "状态",
|
|
||||||
// prop: "status",
|
|
||||||
// type: "radio",
|
|
||||||
// options: [
|
|
||||||
// { label: "正常", value: 1 },
|
|
||||||
// { label: "禁用", value: 0 },
|
|
||||||
// ],
|
|
||||||
// initialValue: 1,
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
label: "状态",
|
label: "状态",
|
||||||
prop: "status",
|
prop: "status",
|
||||||
type: "switch",
|
type: "radio",
|
||||||
attrs: {
|
options: [
|
||||||
activeText: "正常",
|
{ label: "正常", value: 1 },
|
||||||
inactiveText: "禁用",
|
{ label: "禁用", value: 0 },
|
||||||
activeValue: 1,
|
],
|
||||||
inactiveValue: 0,
|
|
||||||
},
|
|
||||||
initialValue: 1,
|
initialValue: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default modalConfig;
|
// 如果有异步数据会修改配置的,推荐用reactive包裹,而纯静态配置的可以直接导出
|
||||||
|
export default reactive(modalConfig);
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import DeptAPI from "@/api/dept";
|
import UserAPI, { type UserForm } from "@/api/user";
|
||||||
import RoleAPI from "@/api/role";
|
|
||||||
import UserAPI from "@/api/user";
|
|
||||||
import type { UserForm } from "@/api/user";
|
|
||||||
import type { IModalConfig } from "@/components/CURD/types";
|
import type { IModalConfig } from "@/components/CURD/types";
|
||||||
import { DeviceEnum } from "@/enums/DeviceEnum";
|
import { DeviceEnum } from "@/enums/DeviceEnum";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
@@ -11,7 +8,7 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
component: "drawer",
|
component: "drawer",
|
||||||
drawer: {
|
drawer: {
|
||||||
title: "修改用户",
|
title: "修改用户",
|
||||||
size: useAppStore().device === DeviceEnum.MOBILE ? "90%" : 600,
|
size: useAppStore().device === DeviceEnum.MOBILE ? "80%" : 500,
|
||||||
},
|
},
|
||||||
pk: "id",
|
pk: "id",
|
||||||
formAction: function (data) {
|
formAction: function (data) {
|
||||||
@@ -52,14 +49,12 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
"check-strictly": true,
|
"check-strictly": true,
|
||||||
"render-after-expand": false,
|
"render-after-expand": false,
|
||||||
},
|
},
|
||||||
async initFn(formItem) {
|
|
||||||
formItem.attrs.data = await DeptAPI.getOptions();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "custom",
|
type: "custom",
|
||||||
label: "性别",
|
label: "性别",
|
||||||
prop: "gender",
|
prop: "gender",
|
||||||
|
initialValue: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "角色",
|
label: "角色",
|
||||||
@@ -71,9 +66,7 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
multiple: true,
|
multiple: true,
|
||||||
},
|
},
|
||||||
options: [],
|
options: [],
|
||||||
async initFn(formItem) {
|
initialValue: [],
|
||||||
this.options = await RoleAPI.getOptions();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
@@ -107,18 +100,8 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// label: "状态",
|
|
||||||
// prop: "status",
|
|
||||||
// type: "radio",
|
|
||||||
// options: [
|
|
||||||
// { label: "正常", value: 1 },
|
|
||||||
// { label: "禁用", value: 0 },
|
|
||||||
// ],
|
|
||||||
// initialValue: 1,
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
label: "状态123",
|
label: "状态",
|
||||||
prop: "status",
|
prop: "status",
|
||||||
type: "switch",
|
type: "switch",
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -131,4 +114,4 @@ const modalConfig: IModalConfig<UserForm> = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default modalConfig;
|
export default reactive(modalConfig);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
<template #mobile="scope">
|
<template #mobile="scope">
|
||||||
<el-text> {{ scope.row[scope.prop] }} </el-text>
|
<el-text>{{ scope.row[scope.prop] }}</el-text>
|
||||||
<copy-button
|
<copy-button
|
||||||
v-if="scope.row[scope.prop]"
|
v-if="scope.row[scope.prop]"
|
||||||
:text="scope.row[scope.prop]"
|
:text="scope.row[scope.prop]"
|
||||||
@@ -90,6 +90,8 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import UserAPI from "@/api/user";
|
import UserAPI from "@/api/user";
|
||||||
|
import DeptAPI from "@/api/dept";
|
||||||
|
import RoleAPI from "@/api/role";
|
||||||
import type { IObject, IOperatData } from "@/components/CURD/types";
|
import type { IObject, IOperatData } from "@/components/CURD/types";
|
||||||
import usePage from "@/components/CURD/usePage";
|
import usePage from "@/components/CURD/usePage";
|
||||||
import addModalConfig from "./config/add";
|
import addModalConfig from "./config/add";
|
||||||
@@ -105,18 +107,32 @@ const {
|
|||||||
editModalRef,
|
editModalRef,
|
||||||
handleQueryClick,
|
handleQueryClick,
|
||||||
handleResetClick,
|
handleResetClick,
|
||||||
handleAddClick,
|
// handleAddClick,
|
||||||
// handleEditClick,
|
// handleEditClick,
|
||||||
handleSubmitClick,
|
handleSubmitClick,
|
||||||
handleExportClick,
|
handleExportClick,
|
||||||
handleSearchClick,
|
handleSearchClick,
|
||||||
handleFilterChange,
|
handleFilterChange,
|
||||||
} = usePage();
|
} = 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) {
|
async function handleEditClick(row: IObject) {
|
||||||
|
editModalRef.value?.setModalVisible();
|
||||||
|
// 加载部门下拉数据源
|
||||||
|
editModalConfig.formItems[2]!.attrs!.data = await DeptAPI.getOptions();
|
||||||
|
// 加载角色下拉数据源
|
||||||
|
editModalConfig.formItems[4]!.options = await RoleAPI.getOptions();
|
||||||
// 根据id获取数据进行填充
|
// 根据id获取数据进行填充
|
||||||
const data = await UserAPI.getFormData(row.id);
|
const data = await UserAPI.getFormData(row.id);
|
||||||
editModalRef.value?.setModalVisible(data);
|
editModalRef.value?.setFormData(data);
|
||||||
}
|
}
|
||||||
// 其他工具栏
|
// 其他工具栏
|
||||||
function handleToolbarClick(name: string) {
|
function handleToolbarClick(name: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user