fix: 优化工作人员重复信息提示
This commit is contained in:
@@ -6,12 +6,14 @@ import { Message } from '@arco-design/web-vue';
|
||||
import { onBeforeUnmount, ref } from 'vue';
|
||||
import { avatarApi } from '@/api/avatar';
|
||||
import { DEFAULT_USER_AVATAR } from '@/constants/avatar';
|
||||
import { createAvatarUploadCache } from './avatar-upload-cache';
|
||||
|
||||
export function useResourceAvatar() {
|
||||
const url = ref(DEFAULT_USER_AVATAR);
|
||||
const file = ref<File>();
|
||||
const cleared = ref(false);
|
||||
const canClear = ref(false);
|
||||
const uploadCache = createAvatarUploadCache(avatarApi.upload);
|
||||
let objectURL = '';
|
||||
|
||||
function revoke() {
|
||||
@@ -22,6 +24,7 @@ export function useResourceAvatar() {
|
||||
/** 加载现有受保护头像,记录没有头像时继续使用默认图。 */
|
||||
async function load(resource: string, identity: string) {
|
||||
revoke();
|
||||
uploadCache.reset();
|
||||
url.value = DEFAULT_USER_AVATAR;
|
||||
canClear.value = false;
|
||||
file.value = undefined;
|
||||
@@ -45,6 +48,7 @@ export function useResourceAvatar() {
|
||||
return;
|
||||
}
|
||||
revoke();
|
||||
uploadCache.reset();
|
||||
objectURL = URL.createObjectURL(next);
|
||||
url.value = objectURL;
|
||||
file.value = next;
|
||||
@@ -55,6 +59,7 @@ export function useResourceAvatar() {
|
||||
/** 标记清除头像,真正写入空值发生在保存资料时。 */
|
||||
function clear() {
|
||||
revoke();
|
||||
uploadCache.reset();
|
||||
url.value = DEFAULT_USER_AVATAR;
|
||||
file.value = undefined;
|
||||
cleared.value = true;
|
||||
@@ -63,7 +68,7 @@ export function useResourceAvatar() {
|
||||
|
||||
/** 将头像变化写入资源更新载荷。 */
|
||||
async function applyToPayload(payload: Record<string, unknown>) {
|
||||
if (file.value) payload.avatar = (await avatarApi.upload(file.value)).uri;
|
||||
if (file.value) payload.avatar = await uploadCache.resolve(file.value);
|
||||
else if (cleared.value) payload.avatar = '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user