refactor: 优化代码规范和可读性

This commit is contained in:
Ray.Hao committed 2026-05-25 22:22:42 +08:00
1 parent e3e5b87f89
commit 2a538d7da7
56 files changed
+324 -294

No files matched your search

+3 -12
View File
@@ -30,8 +30,8 @@
@filter-change="handleFilterChange"
>
<template #status="scope">
<el-tag :type="scope.row[scope.prop] == 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
<el-tag :type="scope.row[scope.prop] === 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] === 1 ? "启用" : "禁用" }}
</el-tag>
</template>
<template #gender="scope">
@@ -187,13 +187,11 @@ const contentConfig: IContentConfig<UserQueryParams, UserItem> = reactive({
},
exportAction: UserAPI.export,
importTemplate: UserAPI.downloadTemplate,
importsAction(data: any) {
console.log("importsAction", data);
importsAction() {
return Promise.resolve();
},
async exportsAction(params: any) {
const data = await UserAPI.getPage(params);
console.log("exportsAction", data.list);
return data.list;
},
pk: "id",
@@ -299,9 +297,6 @@ const addModalConfig: IModalConfig<UserForm> = reactive({
labelWidth: 100,
},
formAction: UserAPI.create,
beforeSubmit(data: any) {
console.log("提交之前处理", data);
},
formItems: [
{
label: "用户名",
@@ -415,9 +410,6 @@ const editModalConfig: IModalConfig<UserForm> = reactive({
size: useAppStore().device === DeviceEnum.MOBILE ? "80%" : 500,
},
pk: "id",
beforeSubmit(data: any) {
console.log("beforeSubmit", data);
},
formAction(data: any) {
return UserAPI.update(data.id as string, data);
},
@@ -539,7 +531,6 @@ const {
// 其他工具
function handleToolbarClick(name: string) {
console.log(name);
if (name === "custom1") {
ElMessage.success("点击了自定义1按钮");
}
-3
View File
@@ -14,9 +14,6 @@ const modalConfig: IModalConfig<UserForm> = {
labelWidth: 100,
},
formAction: UserAPI.create,
beforeSubmit(data) {
console.log("提交之前处理", data);
},
formItems: [
{
label: "用户名",
+1 -3
View File
@@ -24,15 +24,13 @@ const contentConfig: IContentConfig<UserQueryParams, UserItem> = {
},
exportAction: UserAPI.export,
importTemplate: UserAPI.downloadTemplate,
importsAction(data) {
importsAction() {
// 模拟导入数据
console.log("importsAction", data);
return Promise.resolve();
},
async exportsAction(params) {
// 模拟获取到的是全量数据
const data = await UserAPI.getPage(params);
console.log("exportsAction", data.list);
return data.list;
},
pk: "id",
-3
View File
@@ -13,9 +13,6 @@ const modalConfig: IModalConfig<UserForm> = {
size: useAppStore().device === DeviceEnum.MOBILE ? "80%" : 500,
},
pk: "id",
beforeSubmit(data) {
console.log("beforeSubmit", data);
},
formAction(data) {
return UserAPI.update(data.id as string, data);
},
-2
View File
@@ -30,7 +30,6 @@ const contentConfig: IContentConfig<DemoQueryParams, DemoItem> = {
toolbar: [],
indexAction(params) {
// 模拟发起网络请求获取列表数据
console.log("indexAction:", params);
const list = [
{
id: 1,
@@ -74,7 +73,6 @@ const contentConfig: IContentConfig<DemoQueryParams, DemoItem> = {
},
modifyAction(data) {
// 模拟发起网络请求修改字段
// console.log("modifyAction:", data);
ElMessage.success(JSON.stringify(data));
return Promise.resolve(null);
},
-3
View File
@@ -12,9 +12,6 @@ const modalConfig: IModalConfig = {
size: useAppStore().device === DeviceEnum.MOBILE ? "80%" : 500,
},
form: { labelPosition: "right", labelWidth: "auto" },
beforeSubmit(data) {
console.log("beforeSubmit", data);
},
formAction(data) {
// return UserAPI.update(data.id as string, data);
// 模拟发起网络请求修改字段
+2 -5
View File
@@ -15,8 +15,7 @@ const searchConfig: ISearchConfig = {
prop: "testInput",
attrs: { placeholder: "请输入", clearable: true },
events: {
change: (e) => {
console.log("输入框的值: ", e);
change: () => {
// 级联操作示例,需要使用reactive提前定义数组
// selectOptions.push({ label: e, value: e });
},
@@ -35,9 +34,7 @@ const searchConfig: ISearchConfig = {
attrs: { placeholder: "全部", clearable: true },
options: stateArr as any,
events: {
change(e) {
console.log("选中的值: ", e);
},
change() {},
},
},
{
+5 -7
View File
@@ -33,8 +33,8 @@
@filter-change="handleFilterChange"
>
<template #status="scope">
<el-tag :type="scope.row[scope.prop] == 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
<el-tag :type="scope.row[scope.prop] === 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] === 1 ? "启用" : "禁用" }}
</el-tag>
</template>
<template #gender="scope">
@@ -91,8 +91,8 @@
@operate-click="handleOperateClick2"
>
<template #status="scope">
<el-tag :type="scope.row[scope.prop] == 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
<el-tag :type="scope.row[scope.prop] === 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] === 1 ? "启用" : "禁用" }}
</el-tag>
</template>
</page-content>
@@ -145,7 +145,6 @@ const {
// 其他工具
function handleToolbarClick(name: string) {
console.log(name);
if (name === "custom1") {
ElMessage.success("点击了自定义1按钮");
}
@@ -203,8 +202,7 @@ const addModalRef2 = ref();
const openSecondModal = () => {
handleAddClick(addModalRef2 as Ref<PageModalInstance>);
};
const secondSubmit = (formData: any) => {
console.log("secondSubmit", formData);
const secondSubmit = () => {
ElMessage.success("二级弹窗提交成功");
};
-1
View File
@@ -11,7 +11,6 @@ defineOptions({
});
const route = useRoute();
console.log(route);
const value = ref("");
</script>
@@ -17,7 +17,4 @@ import MultiLevel2 from "../level2.vue";
defineOptions({ name: "MultiLevel31" });
const value = ref("");
onMounted(() => {
console.log("Multilevel31 onMounted");
});
</script>
@@ -17,7 +17,4 @@ import MultiLevel2 from "../level2.vue";
defineOptions({ name: "MultiLevel32" });
const value = ref("");
onMounted(() => {
console.log("Multilevel32 onMounted");
});
</script>
@@ -6,8 +6,4 @@
defineOptions({ name: "MultiLevel2" });
const value = ref("");
onMounted(() => {
console.log("MultiLevel2 mounted");
});
</script>
-4
View File
@@ -3,8 +3,4 @@
</template>
<script setup lang="ts">
defineOptions({ name: "MultiLevel1" });
onMounted(() => {
console.log("MultiLevel1 mounted");
});
</script>
+1 -1
View File
@@ -104,7 +104,7 @@ const isCanvasBlank = (canvas: HTMLCanvasElement) => {
const blank = document.createElement("canvas"); //系统获取一个空canvas对象
blank.width = canvas.width;
blank.height = canvas.height;
return canvas.toDataURL() == blank.toDataURL(); //比较值相等则为空
return canvas.toDataURL() === blank.toDataURL(); //比较值相等则为空
};
// 保存为图片
+5 -3
View File
@@ -11,8 +11,8 @@
</el-link>
<table-select :text="text" :select-config="selectConfig" @confirm-click="handleConfirm">
<template #status="scope">
<el-tag :type="scope.row[scope.prop] == 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
<el-tag :type="scope.row[scope.prop] === 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] === 1 ? "启用" : "禁用" }}
</el-tag>
</template>
<template #gender="scope">
@@ -46,7 +46,9 @@ function handleConfirm(data: IUser[]) {
const text = computed(() => {
// 获取字典数据
const dictData = dictStore.getDictItems("gender");
const genderLabel = dictData.find((item: any) => item.value == selectedUser.value?.gender)?.label;
const genderLabel = dictData.find(
(item) => String(item.value) === String(selectedUser.value?.gender)
)?.label;
return selectedUser.value
? `${selectedUser.value.username} - ${genderLabel} - ${selectedUser.value.deptName}`
: "";
+10 -7
View File
@@ -348,8 +348,7 @@ const gridOptions = reactive<VxeGridProps<RowMeta>>({
},
ajax: {
// 接收 Promise
query: ({ page: { currentPage, pageSize }, form, filters, sort, sorts }) => {
console.log({ currentPage, pageSize, form, filters, sort, sorts });
query: ({ page: { currentPage, pageSize } }) => {
return new Promise<{ total: number; result: RowMeta[] }>((resolve) => {
setTimeout(() => {
const list = [
@@ -465,9 +464,7 @@ const gridOptions = reactive<VxeGridProps<RowMeta>>({
});
const gridEvents: VxeGridListeners<RowMeta> = {
// 只对 form-config 配置时有效,表单重置时会触发该事件
formReset() {
console.log("Form Reset");
},
formReset() {},
};
// #endregion
@@ -593,7 +590,10 @@ const curd = {
},
/** 确定并保存 */
onSubmitForm: () => {
console.log("提交表单");
VXETable.modal.message({
content: "提交成功",
status: "success",
});
},
onDelete: (row?: RowMeta) => {
let ids = [];
@@ -614,7 +614,10 @@ const curd = {
VXETable.modal.confirm("确定要删除吗?").then((type) => {
if (type === "confirm") {
// 执行删除操作
console.log("删除的ID", ids);
VXETable.modal.message({
content: `已删除 ${ids.length} 条数据`,
status: "success",
});
}
});
},