Skip to content

Commit 629e824

Browse files
committed
feat: 🚀 优化代码逻辑 && 更新微信群二维码
1 parent 62f8548 commit 629e824

File tree

19 files changed

+180
-157
lines changed

19 files changed

+180
-157
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Geeker-Admin
191191

192192
| 微信群二维码 |
193193
| :------------------------------------------------------------: |
194-
| <img src="https://i.imgtg.com/2023/03/03/V95jD.png" width=170> |
194+
| <img src="https://i.imgtg.com/2023/03/10/Y3Fkr.png" width=170> |
195195

196196
### 捐赠 🍵
197197

src/App.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@ import { ElConfigProvider } from "element-plus";
1313
import zhCn from "element-plus/es/locale/lang/zh-cn";
1414
import en from "element-plus/es/locale/lang/en";
1515
16-
// 初始化主题配置
16+
const globalStore = GlobalStore();
1717
const { initTheme } = useTheme();
1818
initTheme();
1919
20-
const globalStore = GlobalStore();
21-
// 配置element按钮文字中间是否有空格
22-
const config = reactive({
23-
autoInsertSpace: false
24-
});
20+
// element config
21+
const config = reactive({ autoInsertSpace: false });
2522
26-
// element 语言配置
23+
// element language
2724
const i18nLocale = computed(() => {
28-
if (globalStore.language && globalStore.language == "zh") return zhCn;
25+
if (globalStore.language == "zh") return zhCn;
2926
if (globalStore.language == "en") return en;
3027
return getBrowserLang() == "zh" ? zhCn : en;
3128
});
3229
33-
// 配置全局组件大小
30+
// element assemblySize
3431
const assemblySize = computed(() => globalStore.assemblySize);
3532
</script>

src/api/interface/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export namespace User {
7070
createTime: string;
7171
status: number;
7272
avatar: string;
73+
photo: any[];
7374
children?: ResUserList[];
7475
}
7576
export interface ResStatus {

src/components/ImportExcel/index.vue

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</el-form-item>
77
<el-form-item label="文件上传 :">
88
<el-upload
9-
action="string"
9+
action="#"
1010
class="upload"
1111
:drag="true"
1212
:limit="excelLimit"
@@ -17,12 +17,16 @@
1717
:on-exceed="handleExceed"
1818
:on-success="excelUploadSuccess"
1919
:on-error="excelUploadError"
20-
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
20+
:accept="parameter.fileType!.join(',')"
2121
>
22-
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
23-
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
22+
<slot name="empty">
23+
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
24+
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
25+
</slot>
2426
<template #tip>
25-
<div class="el-upload__tip">请上传 .xls , .xlsx 标准格式文件</div>
27+
<slot name="tip">
28+
<div class="el-upload__tip">请上传 .xls , .xlsx 标准格式文件,文件最大为 {{ parameter.fileSize }}M</div>
29+
</slot>
2630
</template>
2731
</el-upload>
2832
</el-form-item>
@@ -37,13 +41,15 @@
3741
import { ref } from "vue";
3842
import { useDownload } from "@/hooks/useDownload";
3943
import { Download } from "@element-plus/icons-vue";
40-
import { ElNotification } from "element-plus";
44+
import { ElNotification, UploadRequestOptions, UploadRawFile } from "element-plus";
4145
4246
export interface ExcelParameterProps {
4347
title: string; // 标题
44-
tempApi: (params: any) => Promise<any>; // 下载模板的Api
45-
importApi: (params: any) => Promise<any>; // 批量导入的Api
46-
getTableList?: () => Promise<any>; // 获取表格数据的Api
48+
fileSize?: number; // 上传文件的大小
49+
fileType?: File.ExcelMimeType[]; // 上传文件的类型
50+
tempApi?: (params: any) => Promise<any>; // 下载模板的Api
51+
importApi?: (params: any) => Promise<any>; // 批量导入的Api
52+
getTableList?: () => void; // 获取表格数据的Api
4753
}
4854
4955
// 是否覆盖数据
@@ -53,11 +59,15 @@ const excelLimit = ref(1);
5359
// dialog状态
5460
const dialogVisible = ref(false);
5561
// 父组件传过来的参数
56-
const parameter = ref<Partial<ExcelParameterProps>>({});
62+
const parameter = ref<ExcelParameterProps>({
63+
title: "",
64+
fileSize: 5,
65+
fileType: ["application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
66+
});
5767
5868
// 接收父组件参数
59-
const acceptParams = (params?: any): void => {
60-
parameter.value = params;
69+
const acceptParams = (params: ExcelParameterProps) => {
70+
parameter.value = { ...parameter.value, ...params };
6171
dialogVisible.value = true;
6272
};
6373
@@ -68,40 +78,41 @@ const downloadTemp = () => {
6878
};
6979
7080
// 文件上传
71-
const uploadExcel = async (param: any) => {
81+
const uploadExcel = async (param: UploadRequestOptions) => {
7282
let excelFormData = new FormData();
7383
excelFormData.append("file", param.file);
7484
excelFormData.append("isCover", isCover.value as unknown as Blob);
7585
await parameter.value.importApi!(excelFormData);
76-
parameter.value.getTableList && parameter.value.getTableList();
86+
parameter.value.getTableList!();
7787
dialogVisible.value = false;
7888
};
7989
8090
/**
8191
* @description 文件上传之前判断
8292
* @param file 上传的文件
8393
* */
84-
const beforeExcelUpload = (file: any) => {
85-
const isExcel =
86-
file.type === "application/vnd.ms-excel" || file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
87-
const fileSize = file.size / 1024 / 1024 < 5;
94+
const beforeExcelUpload = (file: UploadRawFile) => {
95+
const isExcel = parameter.value.fileType!.includes(file.type as File.ExcelMimeType);
96+
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!;
8897
if (!isExcel)
8998
ElNotification({
9099
title: "温馨提示",
91100
message: "上传文件只能是 xls / xlsx 格式!",
92101
type: "warning"
93102
});
94103
if (!fileSize)
95-
ElNotification({
96-
title: "温馨提示",
97-
message: "上传文件大小不能超过 5MB!",
98-
type: "warning"
99-
});
104+
setTimeout(() => {
105+
ElNotification({
106+
title: "温馨提示",
107+
message: `上传文件大小不能超过 ${parameter.value.fileSize}MB!`,
108+
type: "warning"
109+
});
110+
}, 0);
100111
return isExcel && fileSize;
101112
};
102113
103114
// 文件数超出提示
104-
const handleExceed = (): void => {
115+
const handleExceed = () => {
105116
ElNotification({
106117
title: "温馨提示",
107118
message: "最多只能上传一个文件!",
@@ -110,7 +121,7 @@ const handleExceed = (): void => {
110121
};
111122
112123
// 上传错误提示
113-
const excelUploadError = (): void => {
124+
const excelUploadError = () => {
114125
ElNotification({
115126
title: "温馨提示",
116127
message: `批量添加${parameter.value.title}失败,请您重新上传!`,
@@ -119,7 +130,7 @@ const excelUploadError = (): void => {
119130
};
120131
121132
// 上传成功提示
122-
const excelUploadSuccess = (): void => {
133+
const excelUploadSuccess = () => {
123134
ElNotification({
124135
title: "温馨提示",
125136
message: `批量添加${parameter.value.title}成功!`,

src/components/ProTable/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const colSetting = tableColumns.value!.filter(
206206
);
207207
const openColSetting = () => colRef.value.openColSetting();
208208
209-
// 🙅‍♀️ 不需要打印可以把以下方法删除(目前数据处理比较复杂 201-238
209+
// 🙅‍♀️ 不需要打印可以把以下方法删除(目前数据处理比较复杂 209-246
210210
// 处理打印数据(把后台返回的值根据 enum 做转换)
211211
const printData = computed(() => {
212212
const printDataList = JSON.parse(JSON.stringify(selectedList.value.length ? selectedList.value : tableData.value));

src/components/SelectFilter/index.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</template>
3030

3131
<script setup lang="ts" name="selectFilter">
32-
import { ref, onBeforeMount } from "vue";
32+
import { ref, watch } from "vue";
3333
3434
interface OptionsProps {
3535
value: string | number;
@@ -56,12 +56,16 @@ const props = withDefaults(defineProps<SelectFilterProps>(), {
5656
5757
// 重新接收默认值
5858
const selected = ref<{ [key: string]: any }>({});
59-
onBeforeMount(() => {
60-
props.data.forEach(item => {
61-
if (item.multiple) selected.value[item.key] = props.defaultValues[item.key] ?? [""];
62-
else selected.value[item.key] = props.defaultValues[item.key] ?? "";
63-
});
64-
});
59+
watch(
60+
() => props.defaultValues,
61+
() => {
62+
props.data.forEach(item => {
63+
if (item.multiple) selected.value[item.key] = props.defaultValues[item.key] ?? [""];
64+
else selected.value[item.key] = props.defaultValues[item.key] ?? "";
65+
});
66+
},
67+
{ deep: true, immediate: true }
68+
);
6569
6670
interface FilterEmits {
6771
(e: "change", value: any): void;

src/components/SwitchDark/index.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
<template>
2-
<el-switch v-model="themeConfig.isDark" @change="onAddDarkChange" inline-prompt :active-icon="Sunny" :inactive-icon="Moon" />
2+
<el-switch v-model="themeConfig.isDark" @change="switchDark" inline-prompt :active-icon="Sunny" :inactive-icon="Moon" />
33
</template>
44

55
<script setup lang="ts" name="SwitchDark">
66
import { computed } from "vue";
77
import { GlobalStore } from "@/stores";
88
import { Sunny, Moon } from "@element-plus/icons-vue";
99
import { useTheme } from "@/hooks/useTheme";
10-
const globalStore = GlobalStore();
1110
1211
const { switchDark } = useTheme();
1312
13+
const globalStore = GlobalStore();
1414
const themeConfig = computed(() => globalStore.themeConfig);
15-
16-
const onAddDarkChange = () => {
17-
switchDark();
18-
};
1915
</script>

src/components/TreeFilter/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ const defaultProps = {
5757
label: props.label
5858
};
5959
60-
const filterText = ref<string>("");
6160
const treeRef = ref<InstanceType<typeof ElTree>>();
6261
const treeData = ref<{ [key: string]: any }[]>([]);
6362
const treeAllData = ref<{ [key: string]: any }[]>([]);
64-
const selected = ref();
6563
64+
const selected = ref();
6665
const setSelected = () => {
6766
if (props.multiple) selected.value = Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue];
6867
else selected.value = typeof props.defaultValue === "string" ? props.defaultValue : "";
@@ -77,6 +76,7 @@ onBeforeMount(async () => {
7776
}
7877
});
7978
79+
// 使用 nextTick 防止打包后赋值不生效
8080
watch(
8181
() => props.defaultValue,
8282
() => nextTick(() => setSelected()),
@@ -94,6 +94,7 @@ watch(
9494
{ deep: true, immediate: true }
9595
);
9696
97+
const filterText = ref("");
9798
watch(filterText, val => {
9899
treeRef.value!.filter(val);
99100
});

src/components/Upload/Img.vue

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,13 @@ import { generateUUID } from "@/utils/util";
5454
import { ElNotification, formContextKey, formItemContextKey } from "element-plus";
5555
import type { UploadProps, UploadRequestOptions } from "element-plus";
5656
57-
type FileTypes =
58-
| "image/apng"
59-
| "image/bmp"
60-
| "image/gif"
61-
| "image/jpeg"
62-
| "image/pjpeg"
63-
| "image/png"
64-
| "image/svg+xml"
65-
| "image/tiff"
66-
| "image/webp"
67-
| "image/x-icon";
68-
6957
interface UploadFileProps {
7058
imageUrl: string; // 图片地址 ==> 必传
7159
api?: (params: any) => Promise<any>; // 上传图片的 api 方法,一般项目上传都是同一个 api 方法,在组件里直接引入即可 ==> 非必传
7260
drag?: boolean; // 是否支持拖拽上传 ==> 非必传(默认为 true)
7361
disabled?: boolean; // 是否禁用上传组件 ==> 非必传(默认为 false)
7462
fileSize?: number; // 图片大小限制 ==> 非必传(默认为 5M)
75-
fileType?: FileTypes[]; // 图片类型限制 ==> 非必传(默认为 ["image/jpeg", "image/png", "image/gif"])
63+
fileType?: File.ImageMimeType[]; // 图片类型限制 ==> 非必传(默认为 ["image/jpeg", "image/png", "image/gif"])
7664
height?: string; // 组件高度 ==> 非必传(默认为 150px)
7765
width?: string; // 组件宽度 ==> 非必传(默认为 150px)
7866
borderRadius?: string; // 组件边框圆角 ==> 非必传(默认为 8px)
@@ -106,11 +94,10 @@ const self_disabled = computed(() => {
10694
10795
/**
10896
* @description 图片上传
109-
* @param options 上传的文件
97+
* @param options upload 所有配置项
11098
* */
11199
interface UploadEmits {
112100
(e: "update:imageUrl", value: string): void;
113-
(e: "check-validate"): void;
114101
}
115102
const emit = defineEmits<UploadEmits>();
116103
const handleHttpUpload = async (options: UploadRequestOptions) => {
@@ -122,7 +109,6 @@ const handleHttpUpload = async (options: UploadRequestOptions) => {
122109
emit("update:imageUrl", data.fileUrl);
123110
// 调用 el-form 内部的校验方法(可自动校验)
124111
formItemContext?.prop && formContext?.validateField([formItemContext.prop as string]);
125-
emit("check-validate");
126112
} catch (error) {
127113
options.onError(error as any);
128114
}
@@ -145,27 +131,31 @@ const editImg = () => {
145131
146132
/**
147133
* @description 文件上传之前判断
148-
* @param rawFile 上传的文件
134+
* @param rawFile 选择的文件
149135
* */
150136
const beforeUpload: UploadProps["beforeUpload"] = rawFile => {
151137
const imgSize = rawFile.size / 1024 / 1024 < props.fileSize;
152-
const imgType = props.fileType;
153-
if (!imgType.includes(rawFile.type as FileTypes))
138+
const imgType = props.fileType.includes(rawFile.type as File.ImageMimeType);
139+
if (!imgType)
154140
ElNotification({
155141
title: "温馨提示",
156142
message: "上传图片不符合所需的格式!",
157143
type: "warning"
158144
});
159145
if (!imgSize)
160-
ElNotification({
161-
title: "温馨提示",
162-
message: `上传图片大小不能超过 ${props.fileSize}M!`,
163-
type: "warning"
164-
});
165-
return imgType.includes(rawFile.type as FileTypes) && imgSize;
146+
setTimeout(() => {
147+
ElNotification({
148+
title: "温馨提示",
149+
message: `上传图片大小不能超过 ${props.fileSize}M!`,
150+
type: "warning"
151+
});
152+
}, 0);
153+
return imgType && imgSize;
166154
};
167155
168-
// 图片上传成功提示
156+
/**
157+
* @description 图片上传成功
158+
* */
169159
const uploadSuccess = () => {
170160
ElNotification({
171161
title: "温馨提示",
@@ -174,7 +164,9 @@ const uploadSuccess = () => {
174164
});
175165
};
176166
177-
// 图片上传错误提示
167+
/**
168+
* @description 图片上传错误
169+
* */
178170
const uploadError = () => {
179171
ElNotification({
180172
title: "温馨提示",

0 commit comments

Comments
 (0)