refactor: ♻️ 完善CURD代码注释等

This commit is contained in:
cshaptx4869
2024-04-26 21:43:16 +08:00
parent 52bc2e32b5
commit 2b6a210855
9 changed files with 118 additions and 52 deletions

View File

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

View File

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

View File

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