Merge pull request #72 from cshaptx4869/patch-35

refactor: ♻️ 完善CURD代码注释等
This commit is contained in:
Ray Hao
2024-04-26 22:02:36 +08:00
committed by GitHub
9 changed files with 146 additions and 78 deletions

View File

@@ -33,6 +33,8 @@ export default defineMock([
"sys:menu:edit", "sys:menu:edit",
"sys:dict:add", "sys:dict:add",
"sys:role:add", "sys:role:add",
"sys:user:query",
"sys:user:export",
], ],
}, },
msg: "一切ok", msg: "一切ok",

View File

@@ -192,11 +192,17 @@ interface IOperatData {
} }
const props = defineProps<{ const props = defineProps<{
contentConfig: { contentConfig: {
// 页面名称(参与组成权限标识,如sys:user:xxx)
pageName: string; pageName: string;
// 列表的网络请求函数(需返回promise)
indexAction: (data: any) => Promise<any>; indexAction: (data: any) => Promise<any>;
// 删除的网络请求函数(需返回promise)
deleteAction: (data: any) => Promise<any>; deleteAction: (data: any) => Promise<any>;
// 主键名(默认为id)
pk?: string; pk?: string;
// 表格工具栏(默认支持refresh,add,delete,export,也可自定义)
toolbar: any[]; toolbar: any[];
// table组件列属性(额外的属性templet,operat)
cols: any[]; cols: any[];
}; };
}>(); }>();
@@ -205,7 +211,7 @@ const emit = defineEmits<{
addClick: []; addClick: [];
exportClick: []; exportClick: [];
toolbarClick: [name: string]; toolbarClick: [name: string];
editClick: [id: number]; editClick: [row: any];
operatClick: [data: IOperatData]; operatClick: [data: IOperatData];
}>(); }>();
// 暴露的属性和方法 // 暴露的属性和方法
@@ -222,7 +228,7 @@ const total = ref(0);
// 列表数据 // 列表数据
const pageData = ref([]); const pageData = ref([]);
// 每页条数 // 每页条数
const pageSize = 1; const pageSize = 10;
// 搜索参数 // 搜索参数
const queryParams = reactive<any>({ const queryParams = reactive<any>({
pageNum: 1, pageNum: 1,
@@ -240,9 +246,9 @@ function fetchPageData(formData: any = {}, isRestart = false) {
} }
props.contentConfig props.contentConfig
.indexAction({ ...queryParams, ...formData }) .indexAction({ ...queryParams, ...formData })
.then((res: any) => { .then(({ data }) => {
total.value = res.total; total.value = data.total;
pageData.value = res.list; pageData.value = data.list;
}) })
.finally(() => { .finally(() => {
loading.value = false; loading.value = false;

View File

@@ -67,27 +67,42 @@ import { ref, reactive } from "vue";
import { useThrottleFn } from "@vueuse/core"; import { useThrottleFn } from "@vueuse/core";
import type { FormRules, ElForm } from "element-plus"; import type { FormRules, ElForm } from "element-plus";
// 定义接收的属性/自定义事件 // 定义接收的属性
const props = defineProps<{ const props = defineProps<{
modalConfig: { modalConfig: {
// dialog组件属性
dialog: any; dialog: any;
// 页面名称
pageName?: string; pageName?: string;
// 提交的网络请求函数(需返回promise)
formAction: (data: any) => Promise<any>; formAction: (data: any) => Promise<any>;
// 表单项
formItems: Array<{ formItems: Array<{
// 组件类型(如input,select,radio等)
type: string; type: string;
// 标签文本
label: string; label: string;
// 键名
prop: string; prop: string;
// 组件属性
attrs?: any; attrs?: any;
// 初始值
initialValue?: any; initialValue?: any;
// 可选项(适用于select,radio组件)
options?: { label: string; value: any }[]; options?: { label: string; value: any }[];
// 插槽名(适用于组件类型为custom)
slotName?: string; slotName?: string;
}>; }>;
// 表单验证规则
formRules: FormRules; formRules: FormRules;
}; };
}>(); }>();
// 自定义事件
const emit = defineEmits<{ const emit = defineEmits<{
submitClick: []; submitClick: [];
}>(); }>();
// 暴露的属性和方法
defineExpose({ setModalVisible });
const dialogVisible = ref(false); const dialogVisible = ref(false);
const formRef = ref<InstanceType<typeof ElForm>>(); const formRef = ref<InstanceType<typeof ElForm>>();
@@ -121,8 +136,6 @@ function closeDialog() {
formRef.value?.resetFields(); formRef.value?.resetFields();
formRef.value?.clearValidate(); formRef.value?.clearValidate();
} }
// 暴露的属性和方法
defineExpose({ setModalVisible });
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@@ -42,21 +42,30 @@
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
import type { ElForm } from "element-plus"; import type { ElForm } from "element-plus";
// 定义接收的属性/自定义事件 // 定义接收的属性
interface IProps { interface IProps {
searchConfig: { searchConfig: {
// 页面名称(参与组成权限标识,如sys:user:xxx)
pageName: string; pageName: string;
// 表单项
formItems: Array<{ formItems: Array<{
// 组件类型(如input,select等)
type: string; type: string;
// 标签文本
label: string; label: string;
// 键名
prop: string; prop: string;
// 组件属性
attrs?: any; attrs?: any;
// 初始值
initialValue?: any; initialValue?: any;
// 可选项(适用于select组件)
options?: { label: string; value: any }[]; options?: { label: string; value: any }[];
}>; }>;
}; };
} }
const props = defineProps<IProps>(); const props = defineProps<IProps>();
// 自定义事件
const emit = defineEmits<{ const emit = defineEmits<{
queryClick: [queryParams: any]; queryClick: [queryParams: any];
resetClick: [queryParams: any]; resetClick: [queryParams: any];
@@ -65,7 +74,7 @@ const emit = defineEmits<{
defineExpose({ getQueryParams }); defineExpose({ getQueryParams });
const queryFormRef = ref<InstanceType<typeof ElForm>>(); const queryFormRef = ref<InstanceType<typeof ElForm>>();
// 定义form的数据 // 搜索表单数据
const queryParams = reactive<any>({}); const queryParams = reactive<any>({});
for (const item of props.searchConfig.formItems) { for (const item of props.searchConfig.formItems) {
queryParams[item.prop] = item.initialValue ?? ""; queryParams[item.prop] = item.initialValue ?? "";

View File

@@ -14,7 +14,6 @@ declare module "vue" {
DeptTree: (typeof import("./../views/system/user/components/dept-tree.vue"))["default"]; DeptTree: (typeof import("./../views/system/user/components/dept-tree.vue"))["default"];
Dictionary: (typeof import("./../components/Dictionary/index.vue"))["default"]; Dictionary: (typeof import("./../components/Dictionary/index.vue"))["default"];
DictItem: (typeof import("./../views/system/dict/components/dict-item.vue"))["default"]; DictItem: (typeof import("./../views/system/dict/components/dict-item.vue"))["default"];
ElAlert: (typeof import("element-plus/es"))["ElAlert"];
ElBreadcrumb: (typeof import("element-plus/es"))["ElBreadcrumb"]; ElBreadcrumb: (typeof import("element-plus/es"))["ElBreadcrumb"];
ElBreadcrumbItem: (typeof import("element-plus/es"))["ElBreadcrumbItem"]; ElBreadcrumbItem: (typeof import("element-plus/es"))["ElBreadcrumbItem"];
ElButton: (typeof import("element-plus/es"))["ElButton"]; ElButton: (typeof import("element-plus/es"))["ElButton"];
@@ -32,15 +31,11 @@ declare module "vue" {
ElForm: (typeof import("element-plus/es"))["ElForm"]; ElForm: (typeof import("element-plus/es"))["ElForm"];
ElFormItem: (typeof import("element-plus/es"))["ElFormItem"]; ElFormItem: (typeof import("element-plus/es"))["ElFormItem"];
ElIcon: (typeof import("element-plus/es"))["ElIcon"]; ElIcon: (typeof import("element-plus/es"))["ElIcon"];
ElImage: (typeof import("element-plus/es"))["ElImage"];
ElInput: (typeof import("element-plus/es"))["ElInput"]; ElInput: (typeof import("element-plus/es"))["ElInput"];
ElInputNumber: (typeof import("element-plus/es"))["ElInputNumber"];
ElLink: (typeof import("element-plus/es"))["ElLink"];
ElMenu: (typeof import("element-plus/es"))["ElMenu"]; ElMenu: (typeof import("element-plus/es"))["ElMenu"];
ElMenuItem: (typeof import("element-plus/es"))["ElMenuItem"]; ElMenuItem: (typeof import("element-plus/es"))["ElMenuItem"];
ElOption: (typeof import("element-plus/es"))["ElOption"]; ElOption: (typeof import("element-plus/es"))["ElOption"];
ElPagination: (typeof import("element-plus/es"))["ElPagination"]; ElPagination: (typeof import("element-plus/es"))["ElPagination"];
ElPopover: (typeof import("element-plus/es"))["ElPopover"];
ElRadio: (typeof import("element-plus/es"))["ElRadio"]; ElRadio: (typeof import("element-plus/es"))["ElRadio"];
ElRadioGroup: (typeof import("element-plus/es"))["ElRadioGroup"]; ElRadioGroup: (typeof import("element-plus/es"))["ElRadioGroup"];
ElRow: (typeof import("element-plus/es"))["ElRow"]; ElRow: (typeof import("element-plus/es"))["ElRow"];
@@ -51,10 +46,7 @@ declare module "vue" {
ElSwitch: (typeof import("element-plus/es"))["ElSwitch"]; ElSwitch: (typeof import("element-plus/es"))["ElSwitch"];
ElTable: (typeof import("element-plus/es"))["ElTable"]; ElTable: (typeof import("element-plus/es"))["ElTable"];
ElTableColumn: (typeof import("element-plus/es"))["ElTableColumn"]; ElTableColumn: (typeof import("element-plus/es"))["ElTableColumn"];
ElTabPane: (typeof import("element-plus/es"))["ElTabPane"];
ElTabs: (typeof import("element-plus/es"))["ElTabs"];
ElTag: (typeof import("element-plus/es"))["ElTag"]; ElTag: (typeof import("element-plus/es"))["ElTag"];
ElText: (typeof import("element-plus/es"))["ElText"];
ElTooltip: (typeof import("element-plus/es"))["ElTooltip"]; ElTooltip: (typeof import("element-plus/es"))["ElTooltip"];
ElTree: (typeof import("element-plus/es"))["ElTree"]; ElTree: (typeof import("element-plus/es"))["ElTree"];
ElTreeSelect: (typeof import("element-plus/es"))["ElTreeSelect"]; ElTreeSelect: (typeof import("element-plus/es"))["ElTreeSelect"];
@@ -64,20 +56,14 @@ declare module "vue" {
GithubCorner: (typeof import("./../components/GithubCorner/index.vue"))["default"]; GithubCorner: (typeof import("./../components/GithubCorner/index.vue"))["default"];
Hamburger: (typeof import("./../components/Hamburger/index.vue"))["default"]; Hamburger: (typeof import("./../components/Hamburger/index.vue"))["default"];
IconSelect: (typeof import("./../components/IconSelect/index.vue"))["default"]; IconSelect: (typeof import("./../components/IconSelect/index.vue"))["default"];
IEpCaretBottom: (typeof import("~icons/ep/caret-bottom"))["default"];
IEpCaretTop: (typeof import("~icons/ep/caret-top"))["default"];
IEpClose: (typeof import("~icons/ep/close"))["default"]; IEpClose: (typeof import("~icons/ep/close"))["default"];
IEpCollection: (typeof import("~icons/ep/collection"))["default"];
IEpDelete: (typeof import("~icons/ep/delete"))["default"]; IEpDelete: (typeof import("~icons/ep/delete"))["default"];
IEpDownload: (typeof import("~icons/ep/download"))["default"]; IEpDownload: (typeof import("~icons/ep/download"))["default"];
IEpEdit: (typeof import("~icons/ep/edit"))["default"]; IEpEdit: (typeof import("~icons/ep/edit"))["default"];
IEpPlus: (typeof import("~icons/ep/plus"))["default"]; IEpPlus: (typeof import("~icons/ep/plus"))["default"];
IEpPosition: (typeof import("~icons/ep/position"))["default"];
IEpQuestionFilled: (typeof import("~icons/ep/question-filled"))["default"];
IEpRefresh: (typeof import("~icons/ep/refresh"))["default"]; IEpRefresh: (typeof import("~icons/ep/refresh"))["default"];
IEpRefreshLeft: (typeof import("~icons/ep/refresh-left"))["default"]; IEpRefreshLeft: (typeof import("~icons/ep/refresh-left"))["default"];
IEpSearch: (typeof import("~icons/ep/search"))["default"]; IEpSearch: (typeof import("~icons/ep/search"))["default"];
IEpSetting: (typeof import("~icons/ep/setting"))["default"];
IEpTop: (typeof import("~icons/ep/top"))["default"]; IEpTop: (typeof import("~icons/ep/top"))["default"];
IEpUploadFilled: (typeof import("~icons/ep/upload-filled"))["default"]; IEpUploadFilled: (typeof import("~icons/ep/upload-filled"))["default"];
LangSelect: (typeof import("./../components/LangSelect/index.vue"))["default"]; LangSelect: (typeof import("./../components/LangSelect/index.vue"))["default"];
@@ -86,10 +72,12 @@ declare module "vue" {
NavBar: (typeof import("./../layout/components/NavBar/index.vue"))["default"]; NavBar: (typeof import("./../layout/components/NavBar/index.vue"))["default"];
NavbarLeft: (typeof import("./../layout/components/NavBar/components/NavbarLeft.vue"))["default"]; NavbarLeft: (typeof import("./../layout/components/NavBar/components/NavbarLeft.vue"))["default"];
NavbarRight: (typeof import("./../layout/components/NavBar/components/NavbarRight.vue"))["default"]; NavbarRight: (typeof import("./../layout/components/NavBar/components/NavbarRight.vue"))["default"];
PageContent: (typeof import("./../components/PageContent/index.vue"))["default"];
PageModal: (typeof import("./../components/PageModal/index.vue"))["default"];
PageSearch: (typeof import("./../components/PageSearch/index.vue"))["default"];
Pagination: (typeof import("./../components/Pagination/index.vue"))["default"]; Pagination: (typeof import("./../components/Pagination/index.vue"))["default"];
PieChart: (typeof import("./../views/dashboard/components/PieChart.vue"))["default"]; PieChart: (typeof import("./../views/dashboard/components/PieChart.vue"))["default"];
RadarChart: (typeof import("./../views/dashboard/components/RadarChart.vue"))["default"]; RadarChart: (typeof import("./../views/dashboard/components/RadarChart.vue"))["default"];
RightPanel: (typeof import("./../components/RightPanel/index.vue"))["default"];
RouterLink: (typeof import("vue-router"))["RouterLink"]; RouterLink: (typeof import("vue-router"))["RouterLink"];
RouterView: (typeof import("vue-router"))["RouterView"]; RouterView: (typeof import("vue-router"))["RouterView"];
Settings: (typeof import("./../layout/components/Settings/index.vue"))["default"]; Settings: (typeof import("./../layout/components/Settings/index.vue"))["default"];

View File

@@ -8,7 +8,11 @@ const modalConfig = {
formAction: function (data: any) { formAction: function (data: any) {
console.log("add", data); console.log("add", data);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve("新增成功"); resolve({
code: "00000",
data: null,
msg: "新增成功",
});
}); });
}, },
formItems: [ formItems: [

View File

@@ -5,7 +5,8 @@ const contentConfig = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
resolve({ resolve({
total: 2, code: "00000",
data: {
list: [ list: [
{ {
id: 2, id: 2,
@@ -36,6 +37,9 @@ const contentConfig = {
createTime: "2021-06-05", createTime: "2021-06-05",
}, },
], ],
total: 2,
},
msg: "一切ok",
}); });
}, 800); }, 800);
}); });
@@ -43,7 +47,11 @@ const contentConfig = {
deleteAction: function (id: string) { deleteAction: function (id: string) {
console.log("delete", id); console.log("delete", id);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve("删除成功"); resolve({
code: "00000",
data: null,
msg: "删除成功",
});
}); });
}, },
pk: "id", pk: "id",

View File

@@ -8,7 +8,11 @@ const modalConfig = {
formAction: function (data: any) { formAction: function (data: any) {
console.log("edit", data); console.log("edit", data);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve("编辑成功"); resolve({
code: "00000",
data: null,
msg: "修改成功",
});
}); });
}, },
formItems: [ formItems: [

View File

@@ -64,13 +64,14 @@ function handleResetClick() {
} }
// 新增 // 新增
function handleAddClick() { function handleAddClick() {
console.log("add");
//显示添加表单 //显示添加表单
addModalRef.value?.setModalVisible(); addModalRef.value?.setModalVisible();
} }
// 导出 // 导出
function handleExportClick() { function handleExportClick() {
console.log("export", searchRef.value?.getQueryParams()); console.log("export");
// 可以根据检索条件去导出数据
console.log(searchRef.value?.getQueryParams());
} }
// 其他工具栏 // 其他工具栏
function handleToolbarClick(name: string) { function handleToolbarClick(name: string) {
@@ -78,9 +79,10 @@ function handleToolbarClick(name: string) {
} }
// 编辑 // 编辑
const editModalRef = ref<InstanceType<typeof PageModal>>(); const editModalRef = ref<InstanceType<typeof PageModal>>();
function handleEditClick() { function handleEditClick(row: any) {
//显示编辑表单或者根据id获取数据进行填充 //显示编辑表单 根据id获取数据进行填充
editModalRef.value?.setModalVisible({ const idMap: Record<string, any> = {
2: {
id: 2, id: 2,
username: "admin", username: "admin",
nickname: "系统管理员", nickname: "系统管理员",
@@ -92,16 +94,48 @@ function handleEditClick() {
status: 1, status: 1,
deptId: 1, deptId: 1,
roleIds: [2], roleIds: [2],
}); },
3: {
id: 3,
username: "test",
nickname: "测试小用户",
mobile: "17621210366",
gender: 1,
avatar:
"https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
email: "youlaitech@163.com",
status: 1,
deptId: 3,
roleIds: [3],
},
};
editModalRef.value?.setModalVisible(idMap[row.id]);
} }
// 其他操作列 // 其他操作列
function handleOperatClick(data: any) { function handleOperatClick(data: any) {
console.log(data.name, data.row); console.log(data);
// 重置密码
if (data.name === "reset_pwd") {
ElMessageBox.prompt(
"请输入用户「" + data.row.username + "」的新密码",
"重置密码",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
}
).then(({ value }) => {
if (!value) {
ElMessage.warning("请输入新密码");
return false;
}
// 发送网络请求
ElMessage.success("密码重置成功,新密码是:" + value);
});
}
} }
// 表单提交 // 表单提交
function handleSubmitClick() { function handleSubmitClick() {
//刷新别表数据 //刷新别表数据
console.log("submit");
contentRef.value?.fetchPageData({}, true); contentRef.value?.fetchPageData({}, true);
} }
</script> </script>