文件
OmniCard/mpuniapp/pages/owner/profile/index.uvue
wikiboss 62e0ae4435 feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 18:01:47 +08:00

950 行
24 KiB
Plaintext

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="profile-page" :class="pageRtlClass">
<scroll-view class="profile-scroll" :scroll-y="true">
<view class="profile-content">
<view class="bento-card identity-card">
<view class="identity-top" @click="onEditProfileClick">
<view class="avatar-ring" @click.stop="onAvatarClick">
<image
v-if="state.account.avatar !== ''"
class="avatar-img"
:src="state.account.avatar"
mode="aspectFill"
/>
<view v-else class="avatar-empty">
<text class="avatar-add-icon">+</text>
</view>
</view>
<view class="identity-copy">
<text class="identity-name">{{ accountName }}</text>
<text v-if="state.account.company !== ''" class="identity-company">{{ displayOrgField(state.account.company) }}</text>
<text v-if="state.account.department !== ''" class="identity-dept">{{ displayOrgField(state.account.department) }}</text>
<text class="identity-edit-text">{{ t('editProfile') }}</text>
</view>
</view>
<view class="metrics-row">
<view class="metrics-pod" @click="openPage('/pages/owner/card/index')">
<text class="metrics-number">{{ state.metrics.cardsCount }}</text>
<text class="metrics-label">{{ t('metricsCards') }}</text>
</view>
<view class="metrics-pod" @click="openPage('/pages/owner/radar')">
<text class="metrics-number">{{ state.metrics.visitorsCount }}</text>
<text class="metrics-label">{{ t('metricsVisitors') }}</text>
</view>
<view class="metrics-pod" @click="openPage('/pages/owner/leads')">
<text class="metrics-number">{{ state.metrics.leadsCount }}</text>
<text class="metrics-label">{{ t('metricsLeads') }}</text>
</view>
</view>
<view class="quota-section" @click="onQuotaClick">
<view class="quota-meta-row">
<text class="quota-section-title">{{ t('quotaCards') }}</text>
<text class="quota-numbers">{{ quotaLine }}</text>
</view>
<view v-if="quotaLoaded" class="quota-track">
<view
class="quota-fill"
:class="{ 'quota-fill-danger': quotaExceeded }"
:style="{ width: quotaPercent + '%' }"
></view>
</view>
<text v-if="quotaExceeded" class="quota-alert-text">{{ t('quotaUpgrade') }}</text>
</view>
</view>
<view v-if="state.errorMessage !== ''" class="error-notice" @click="reloadAccount">
<text class="error-notice-text">{{ state.errorMessage }}</text>
</view>
<text class="section-title">{{ t('cardStudioSection') }}</text>
<view class="bento-card bento-list-group">
<view class="bento-row-item" @click="openPage('/pages/owner/card/index')">
<view class="row-text-group">
<text class="row-title">{{ t('myCards') }}</text>
<text class="row-desc">{{ t('myCardsSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onEditProfileClick">
<view class="row-text-group">
<text class="row-title">{{ t('cardEdit') }}</text>
<text class="row-desc">{{ t('cardEditSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onOpenCases">
<view class="row-text-group">
<text class="row-title">{{ t('productCases') }}</text>
<text class="row-desc">{{ t('productCasesSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onOpenArticles">
<view class="row-text-group">
<text class="row-title">{{ t('articleDynamics') }}</text>
<text class="row-desc">{{ t('articleDynamicsSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onOpenPoster">
<view class="row-text-group">
<text class="row-title">{{ t('sharePoster') }}</text>
<text class="row-desc">{{ t('sharePosterSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="openPage('/pages/owner/hall/index')">
<view class="row-text-group">
<text class="row-title">{{ t('exchangeHall') }}</text>
<text class="row-desc">{{ t('exchangeHallSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
</view>
<text class="section-title">{{ t('workspaceSection') }}</text>
<view class="bento-card bento-list-group">
<view class="bento-row-item" @click="openPage('/pages/owner/nfc/scan')">
<view class="row-text-group">
<text class="row-title">{{ t('nfcScan') }}</text>
<text class="row-desc">{{ t('nfcScanSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="openPage('/pages/owner/nfc/mode')">
<view class="row-text-group">
<text class="row-title">{{ t('nfcMode') }}</text>
<text class="row-desc">{{ t('nfcModeSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="openPage('/pages/owner/nfc/security')">
<view class="row-text-group">
<text class="row-title">{{ t('nfcSecurity') }}</text>
<text class="row-desc">{{ t('nfcSecuritySub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="openPage('/pages/owner/team/overview')">
<view class="row-text-group">
<text class="row-title">{{ t('teamBriefing') }}</text>
<text class="row-desc">{{ t('teamBriefingSub') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
</view>
<text class="section-title">{{ t('languageSection') }}</text>
<view class="bento-card bento-list-group">
<view class="bento-row-item no-hover">
<view class="row-text-group">
<text class="row-title">{{ t('radarPushTitle') }}</text>
<text class="row-desc">{{ t('radarPushDesc') }}</text>
</view>
<switch
:checked="state.notifications.radarPush"
color="#0088FF"
@change="onRadarPushChange"
/>
</view>
<view class="row-divider"></view>
<view class="bento-row-item no-hover">
<view class="row-text-group">
<text class="row-title">{{ t('leadNoticeTitle') }}</text>
<text class="row-desc">{{ t('leadNoticeDesc') }}</text>
</view>
<switch
:checked="state.notifications.leadNotice"
color="#0088FF"
@change="onLeadNoticeChange"
/>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onOpenLanguageSheet">
<view class="row-text-group">
<text class="row-title">{{ t('languageLabel') }}</text>
</view>
<text class="row-value">{{ currentLanguageLabel }}</text>
<text class="row-arrow">›</text>
</view>
<view class="row-divider"></view>
<view class="bento-row-item" @click="onAboutAppClick">
<view class="row-text-group">
<text class="row-title">{{ t('aboutApp') }}</text>
</view>
<text class="row-arrow">›</text>
</view>
</view>
<view class="signout-btn" @click="onLogout">
<text class="signout-text">{{ t('logout') }}</text>
</view>
<view class="bottom-safe-space"></view>
</view>
</scroll-view>
<view v-if="showLanguageSheet" class="drawer-mask" @click="onCloseLanguageSheet">
<view class="drawer-sheet" @click.stop="">
<view class="drawer-handle"></view>
<view class="drawer-header">
<text class="drawer-title">{{ t('languageLabel') }}</text>
<view class="drawer-close-btn" @click="onCloseLanguageSheet">
<text class="drawer-close-icon">×</text>
</view>
</view>
<view
v-for="opt in languageOptions"
:key="opt.code"
class="drawer-option-row"
:class="{ 'drawer-option-active': state.locale === opt.code }"
@click="onSelectLanguage(opt.code)"
>
<text class="option-name" :class="{ 'option-name-active': state.locale === opt.code }">{{ opt.label }}</text>
<view v-if="state.locale === opt.code" class="option-check"></view>
</view>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { reactive, ref, computed } from 'vue';
import { OmniLocale, isRtl } from '../../../common/locale.uts';
import { clearAuthToken, getTenantId } from '../../../common/request.uts';
import { fetchCardQuota, fetchOwnerLeadPage, fetchOwnerRadarPage } from '../../../common/api.uts';
import {
ProfileState,
loadProfileSettings,
saveProfileSettings,
toggleRadarPush,
toggleLeadNotice,
setPreferredLocale,
calculateQuotaPercent,
resolveProfileText,
previewAccountAvatar,
removeAccountAvatar,
displayOrgField,
loadOwnerProfileAccount,
getDefaultMetrics,
} from './useProfile.uts';
const state = reactive<ProfileState>(loadProfileSettings());
state.metrics = getDefaultMetrics();
const showLanguageSheet = ref<boolean>(false);
const quotaLine = ref<string>('--');
const quotaExceeded = ref<boolean>(false);
const quotaPercent = ref<number>(0);
const quotaLoaded = ref<boolean>(false);
const pageRtlClass = computed((): string => {
return isRtl(state.locale) ? 'page-rtl' : '';
});
const accountName = computed((): string => {
return state.account.name;
});
function t(key: string): string {
return resolveProfileText(key);
}
type LangOpt = {
code: OmniLocale;
label: string;
};
const languageOptions: LangOpt[] = [
{ code: 'zh-CN', label: '中文 (简体)' },
{ code: 'en-US', label: 'English (US)' },
{ code: 'ar-SA', label: 'العربية' },
{ code: 'es-ES', label: 'Español' },
{ code: 'de-DE', label: 'Deutsch' },
{ code: 'fr-FR', label: 'Français' },
{ code: 'ja-JP', label: '日本語' },
];
const currentLanguageLabel = computed((): string => {
const target = languageOptions.find((o: LangOpt): boolean => o.code === state.locale);
return target != null ? target.label : '中文 (简体)';
});
function openPage(url: string): void {
const tabPages = [
'/pages/owner/workplace/index',
'/pages/owner/card/index',
'/pages/owner/radar',
'/pages/owner/leads',
'/pages/owner/profile/index',
];
if (tabPages.some((t: string): boolean => url.startsWith(t))) {
uni.switchTab({
url: url,
fail: (_err: unknown) => {
uni.navigateTo({ url: url });
},
});
return;
}
uni.navigateTo({
url: url,
fail: (_err: unknown) => {
uni.showToast({
title: t('loading'),
icon: 'none',
});
},
});
}
function onEditProfileClick(): void {
const id = state.account.cardId;
if (id === '') {
openPage('/pages/owner/card/edit');
return;
}
openPage('/pages/owner/card/edit?id=' + id);
}
function onOpenCases(): void {
const id = state.account.cardId;
if (id === '') {
openPage('/pages/owner/card/index');
return;
}
openPage('/pages/owner/card/cases?cardId=' + id);
}
function onOpenArticles(): void {
const id = state.account.cardId;
if (id === '') {
openPage('/pages/owner/card/index');
return;
}
openPage('/pages/owner/card/articles?cardId=' + id);
}
function onOpenPoster(): void {
const key = state.account.cardSlug !== '' ? state.account.cardSlug : state.account.cardId;
if (key === '') {
openPage('/pages/owner/card/qrcode');
return;
}
openPage('/pages/owner/card/qrcode?id=' + key);
}
function onAvatarClick(): void {
const itemList = state.account.avatar !== ''
? [t('avatarActionChoose'), t('avatarActionPreview'), t('avatarActionRemove')]
: [t('avatarActionChoose')];
uni.showActionSheet({
itemList: itemList,
success: (res: { tapIndex?: number }) => {
const idx = res.tapIndex != null ? res.tapIndex : -1;
if (idx === 0) {
onAvatarChoose();
} else if (idx === 1 && state.account.avatar !== '') {
previewAccountAvatar(state);
} else if (idx === 2 && state.account.avatar !== '') {
removeAccountAvatar(state);
saveProfileSettings(state);
uni.showToast({
title: t('saved'),
icon: 'none',
});
}
},
});
}
function onAvatarChoose(): void {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res: { tempFilePaths?: string[] }) => {
if (res.tempFilePaths != null && res.tempFilePaths.length > 0) {
state.account.avatar = res.tempFilePaths[0];
saveProfileSettings(state);
uni.showToast({
title: t('saved'),
icon: 'none',
});
}
},
});
}
async function loadQuota(): Promise<void> {
try {
const tenantId = getTenantId();
const quota = tenantId !== '' ? await fetchCardQuota(tenantId) : await fetchCardQuota();
quotaLine.value = String(quota.used) + ' / ' + String(quota.limit);
quotaExceeded.value = quota.exceeded === true;
quotaPercent.value = calculateQuotaPercent(quota.used, quota.limit);
quotaLoaded.value = true;
state.metrics.cardsCount = quota.used;
} catch (_e) {
quotaLine.value = '--';
quotaExceeded.value = false;
quotaPercent.value = 0;
quotaLoaded.value = false;
}
}
async function loadVisitorCount(): Promise<void> {
try {
const page = await fetchOwnerRadarPage({ page: 1, size: 1 });
const total = page.pagination != null ? page.pagination.total : 0;
state.metrics.visitorsCount = total;
} catch (_e) {
state.metrics.visitorsCount = 0;
}
}
async function loadLeadCount(): Promise<void> {
try {
const page = await fetchOwnerLeadPage({ page: 1, size: 1 });
const total = page.pagination != null ? page.pagination.total : 0;
state.metrics.leadsCount = total;
} catch (_e) {
state.metrics.leadsCount = 0;
}
}
function reloadAccount(): void {
void loadOwnerProfileAccount(state);
void loadQuota();
void loadVisitorCount();
void loadLeadCount();
}
function onQuotaClick(): void {
const usage = t('quotaCards') + ' ' + quotaLine.value;
const content = quotaExceeded.value ? t('quotaUpgrade') + '\n' + usage : usage;
uni.showModal({
title: t('quotaCards'),
content: content,
showCancel: false,
confirmText: t('confirm'),
});
}
function onAboutAppClick(): void {
uni.showModal({
title: t('aboutApp'),
content: t('aboutBody'),
showCancel: false,
confirmText: t('confirm'),
});
}
function onRadarPushChange(e: UniSwitchChangeEvent): void {
toggleRadarPush(state, e.detail.value);
}
function onLeadNoticeChange(e: UniSwitchChangeEvent): void {
toggleLeadNotice(state, e.detail.value);
}
function onOpenLanguageSheet(): void {
showLanguageSheet.value = true;
}
function onCloseLanguageSheet(): void {
showLanguageSheet.value = false;
}
function onSelectLanguage(code: OmniLocale): void {
setPreferredLocale(state, code);
saveProfileSettings(state);
onCloseLanguageSheet();
uni.showToast({
title: t('saved'),
icon: 'none',
});
}
function onLogout(): void {
uni.showModal({
title: resolveProfileText('confirmLogoutTitle'),
content: resolveProfileText('confirmLogoutContent'),
success: (res: { confirm?: boolean }) => {
if (res.confirm === true) {
clearAuthToken();
uni.showToast({
title: resolveProfileText('logout'),
icon: 'none',
});
// #ifdef H5
if (typeof window !== 'undefined') {
window.location.hash = '#/pages/common/login';
return;
}
// #endif
uni.reLaunch({
url: '/pages/common/login',
});
}
},
});
}
onShow(() => {
const loaded = loadProfileSettings();
state.account = loaded.account;
state.notifications = loaded.notifications;
state.locale = loaded.locale;
void loadOwnerProfileAccount(state);
void loadQuota();
void loadVisitorCount();
void loadLeadCount();
});
</script>
<style scoped>
.profile-page {
width: 100vw;
max-width: 480px;
height: 100vh;
margin: 0 auto;
overflow: hidden;
display: flex;
flex-direction: column;
background-color: #F5F8FC;
box-sizing: border-box;
}
.profile-scroll {
flex: 1;
width: 100%;
height: 0;
min-height: 0;
}
.profile-content {
width: 100%;
box-sizing: border-box;
padding-block-start: calc(12px + env(safe-area-inset-top, 0px));
padding-inline: 16px;
padding-block-end: 8px;
display: flex;
flex-direction: column;
}
.bento-card {
background-color: #FFFFFF;
border-radius: 20px;
border: 1px solid #EBF1F7;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(11, 99, 229, 0.03);
box-sizing: border-box;
margin-block-end: 8px;
}
.identity-card {
padding: 16px;
}
.identity-top {
min-height: 44px;
display: flex;
flex-direction: row;
align-items: center;
}
.avatar-ring {
width: 56px;
height: 56px;
margin-inline-end: 12px;
flex-shrink: 0;
}
.avatar-img,
.avatar-empty {
width: 56px;
height: 56px;
border-radius: 28px;
background-color: #EBF5FF;
}
.avatar-empty {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #0088FF;
}
.avatar-add-icon {
font-size: 24px;
line-height: 1;
color: #0088FF;
}
.identity-copy {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.identity-name {
font-size: 20px;
font-weight: 700;
line-height: 1.25;
color: #101828;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.identity-company {
margin-block-start: 2px;
font-size: 14px;
line-height: 1.4;
color: #101828;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.identity-dept {
margin-block-start: 2px;
font-size: 12px;
line-height: 1.4;
color: #64748B;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.identity-edit-text {
margin-block-start: 4px;
min-height: 44px;
display: flex;
align-items: center;
font-size: 14px;
font-weight: 600;
color: #0088FF;
}
.metrics-row {
display: flex;
flex-direction: row;
margin-block-start: 16px;
padding-block-start: 12px;
border-top: 1px solid #EBF1F7;
}
.metrics-pod {
flex: 1;
min-width: 0;
min-height: 44px;
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
.metrics-number {
font-size: 20px;
font-weight: 700;
line-height: 1.25;
color: #101828;
}
.metrics-label {
margin-block-start: 2px;
font-size: 12px;
line-height: 1.4;
color: #64748B;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.quota-section {
min-height: 44px;
margin-block-start: 12px;
padding-block-start: 12px;
display: flex;
flex-direction: column;
justify-content: center;
border-top: 1px solid #EBF1F7;
}
.quota-meta-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.quota-section-title {
font-size: 14px;
font-weight: 600;
color: #101828;
}
.quota-numbers {
font-size: 14px;
font-weight: 600;
color: #0088FF;
}
.quota-track {
height: 6px;
margin-block-start: 8px;
border-radius: 9999px;
background-color: #EBF1F7;
overflow: hidden;
}
.quota-fill {
height: 100%;
border-radius: 9999px;
background: linear-gradient(90deg, #00A3FF 0%, #0B63E5 100%);
}
.quota-fill-danger {
background: linear-gradient(90deg, #F79009 0%, #F04438 100%);
}
.quota-alert-text {
margin-block-start: 6px;
font-size: 12px;
line-height: 1.4;
color: #F04438;
}
.section-title {
margin-block: 12px 8px;
padding-inline: 4px;
font-size: 13px;
font-weight: 600;
line-height: 1.4;
color: #64748B;
}
.bento-list-group {
padding-block: 4px;
display: flex;
flex-direction: column;
}
.bento-row-item {
min-height: 48px;
padding: 10px 16px;
display: flex;
flex-direction: row;
align-items: center;
}
.bento-row-item:active {
background-color: #F7F8FA;
}
.no-hover:active {
background-color: #FFFFFF;
}
.row-text-group {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.row-title {
font-size: 16px;
font-weight: 600;
line-height: 1.3;
color: #101828;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row-desc {
margin-block-start: 2px;
font-size: 12px;
line-height: 1.4;
color: #64748B;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row-value {
flex-shrink: 0;
max-width: 42%;
margin-inline-end: 4px;
font-size: 14px;
line-height: 1.4;
color: #64748B;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row-arrow {
flex-shrink: 0;
font-size: 18px;
line-height: 1;
color: #94A3B8;
}
.row-divider {
height: 1px;
margin-inline: 16px;
background-color: #EBF1F7;
}
.signout-btn {
min-height: 48px;
margin-block-start: 16px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 14px;
background-color: #FFFFFF;
border: 1px solid #EBF1F7;
}
.signout-btn:active {
background-color: #FEF3F2;
}
.signout-text {
font-size: 16px;
font-weight: 600;
color: #F04438;
}
.error-notice {
margin-block-end: 8px;
padding: 12px;
border-radius: 12px;
background-color: #FEF3F2;
}
.error-notice-text {
font-size: 14px;
line-height: 1.5;
color: #B42318;
}
.bottom-safe-space {
height: calc(16px + var(--window-bottom, 0px) + env(safe-area-inset-bottom, 0px));
}
.drawer-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(16, 24, 40, 0.4);
z-index: 999;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.drawer-sheet {
background-color: #FFFFFF;
border-top-left-radius: 24px;
border-top-right-radius: 24px;
padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
box-shadow: 0 12px 36px rgba(16, 24, 40, 0.08);
}
.drawer-handle {
width: 36px;
height: 4px;
margin: 0 auto 12px auto;
border-radius: 9999px;
background-color: #EBF1F7;
}
.drawer-header {
min-height: 44px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.drawer-title {
font-size: 18px;
font-weight: 700;
color: #101828;
}
.drawer-close-btn {
width: 44px;
height: 44px;
display: flex;
align-items: center;
justify-content: center;
}
.drawer-close-icon {
font-size: 22px;
line-height: 1;
color: #64748B;
}
.drawer-option-row {
min-height: 48px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #EBF1F7;
}
.drawer-option-active .option-name {
color: #0088FF;
font-weight: 700;
}
.option-name {
font-size: 16px;
color: #101828;
}
.option-name-active {
color: #0088FF;
font-weight: 700;
}
.option-check {
width: 8px;
height: 8px;
border-radius: 4px;
background-color: #0088FF;
}
.page-rtl .identity-top,
.page-rtl .metrics-row,
.page-rtl .quota-meta-row,
.page-rtl .bento-row-item,
.page-rtl .drawer-header,
.page-rtl .drawer-option-row {
flex-direction: row-reverse;
}
</style>