perf: 用户管理优化头像上传

This commit is contained in:
xiaojunnuo
2024-10-27 00:52:26 +08:00
parent d10d42e206
commit 661293c189
4 changed files with 51 additions and 9 deletions
@@ -185,7 +185,8 @@ function install(app: App, options: any = {}) {
defaultType: "form",
form: {
keepName: true,
action: "http://www.docmirror.cn:7070/api/upload/form/upload",
type: "form",
action: "/basic/file/upload",
name: "file",
withCredentials: false,
uploadRequest: async ({ action, file, onProgress }: any) => {
@@ -205,12 +206,8 @@ function install(app: App, options: any = {}) {
}
});
},
successHandle(ret: any) {
// 上传完成后的结果处理, 此处应返回格式为{url:xxx}
return {
url: "http://www.docmirror.cn:7070" + ret,
key: ret.replace("/api/upload/form/download?key=", "")
};
successHandle(res: any) {
return res;
}
}
});
@@ -1,5 +1,6 @@
import * as api from "./api";
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
import { useUserStore } from "/@/store/modules/user";
export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
@@ -17,6 +18,8 @@ export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOpti
return await api.AddObj(form);
};
const userStore = useUserStore();
return {
crudOptions: {
request: {
@@ -114,6 +117,35 @@ export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOpti
style: {
height: "30px",
width: "auto"
},
buildUrl(key: string) {
return `/api/basic/file/download?&key=` + key;
}
}
},
form: {
component: {
vModel: "modelValue",
valueType: "key",
cropper: {
aspectRatio: 1,
autoCropArea: 1,
viewMode: 0
},
onReady: null,
uploader: {
type: "form",
action: "/basic/file/upload",
name: "file",
headers: {
Authorization: "Bearer " + userStore.getToken
},
successHandle(res: any) {
return res;
}
},
buildUrl(key: string) {
return `/api/basic/file/download?&key=` + key;
}
}
}