feat: 统一后台与用户端图片与文件上传交互,支持点击放大预览、删除与多图批量多选上传

这个提交包含在:
wikiboss
2026-09-21 01:28:01 +08:00
父节点 56392d8f9e
当前提交 955c73e7ef
共有 47 个文件被更改,包括 2605 次插入 和 77 次删除

查看文件

@@ -13,11 +13,29 @@
<text class="section-title">{{ t('accountSection') }}</text>
<view class="account-header">
<image
class="account-avatar"
:src="state.account.avatar"
mode="aspectFill"
/>
<view class="avatar-container">
<image
v-if="state.account.avatar !== ''"
class="account-avatar"
:src="state.account.avatar"
mode="aspectFill"
@click="onAvatarClick"
/>
<view
v-else
class="account-avatar-placeholder"
@click="onAvatarChoose"
>
<text class="avatar-placeholder-plus">+</text>
</view>
<view
v-if="state.account.avatar !== ''"
class="avatar-del-badge"
@click="onAvatarDelete"
>
<text class="avatar-del-icon">×</text>
</view>
</view>
<view class="account-info">
<text class="account-name">{{ state.account.name }}</text>
<text class="account-meta">{{ state.account.company }}</text>
@@ -117,6 +135,8 @@ import {
toggleLeadNotice,
setPreferredLocale,
resolveProfileText,
previewAccountAvatar,
removeAccountAvatar,
} from './useProfile.uts';
import { OmniLocale } from '../../../common/locale.uts';
@@ -127,6 +147,30 @@ type LangOption = {
const state = reactive<ProfileState>(loadProfileSettings());
function onAvatarClick(): void {
if (state.account.avatar !== '') {
previewAccountAvatar(state);
} else {
onAvatarChoose();
}
}
function onAvatarChoose(): void {
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: (res: { tempFilePaths: string[] }) => {
if (res.tempFilePaths && res.tempFilePaths.length > 0) {
state.account.avatar = res.tempFilePaths[0];
}
},
});
}
function onAvatarDelete(): void {
removeAccountAvatar(state);
}
const languageList: LangOption[] = [
{ code: 'zh-CN', label: '简体中文' },
{ code: 'en-US', label: 'English' },
@@ -230,12 +274,55 @@ onMounted(() => {
align-items: center;
}
.avatar-container {
position: relative;
width: 56px;
height: 56px;
margin-right: 16px;
}
.account-avatar {
width: 56px;
height: 56px;
border-radius: 28px;
background-color: #E3E7ED;
margin-right: 16px;
}
.account-avatar-placeholder {
width: 56px;
height: 56px;
border-radius: 28px;
border: 1px dashed #C9CDD4;
background-color: #F7F8FA;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-placeholder-plus {
font-size: 24px;
color: #667085;
line-height: 1;
}
.avatar-del-badge {
position: absolute;
top: 0px;
right: 0px;
width: 18px;
height: 18px;
border-radius: 9px;
background-color: rgba(240, 68, 56, 0.9);
display: flex;
align-items: center;
justify-content: center;
}
.avatar-del-icon {
color: #FFFFFF;
font-size: 13px;
font-weight: 700;
line-height: 1;
}
.account-info {

查看文件

@@ -310,6 +310,31 @@ export function setPreferredLocale(
return targetLocale;
}
/**
* 预览个人头像
*/
export function previewAccountAvatar(state: ProfileState): void {
if (state.account.avatar !== '') {
// #ifndef UNI-APP-X-TEST
try {
if (typeof uni !== 'undefined' && typeof uni.previewImage === 'function') {
uni.previewImage({
urls: [state.account.avatar],
current: state.account.avatar,
});
}
} catch (_e) {}
// #endif
}
}
/**
* 移除个人头像
*/
export function removeAccountAvatar(state: ProfileState): void {
state.account.avatar = '';
}
/**
* 瑞士国际主义多语言文案解析器,无 emoji
*/