文件
OmniCard/mpuniapp/pages/owner/profile/index.uvue

841 行
19 KiB
Plaintext

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

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

<template>
<view class="profile-page">
<scroll-view class="profile-scroll" :scroll-y="true">
<view class="profile-container">
<!-- 1. Header Hero Bento: Profile identity & Quick site preview -->
<view class="hero-card">
<view class="hero-main">
<view class="avatar-box">
<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="hero-info">
<view class="name-row">
<text class="account-name">{{ state.account.name }}</text>
<view class="tier-pill">
<text class="tier-pill-text">{{ t('tierBadge') }}</text>
</view>
</view>
<text class="account-company">{{ state.account.company }}</text>
<text class="account-dept">{{ state.account.department }}</text>
</view>
</view>
<view class="hero-actions">
<view class="preview-btn" @click="openPage('/pages/portal/index')">
<text class="preview-btn-text">{{ t('previewPortal') }}</text>
</view>
</view>
</view>
<!-- 2. Bento Metrics Grid: Core Business Assets -->
<view class="metrics-grid">
<view class="metric-cell" @click="openPage('/pages/owner/card/index')">
<text class="metric-val">{{ cardCount }}</text>
<text class="metric-lbl">{{ t('metricsCards') }}</text>
</view>
<view class="metric-cell" @click="openPage('/pages/owner/radar')">
<text class="metric-val">{{ visitorCount }}</text>
<text class="metric-lbl">{{ t('metricsVisitors') }}</text>
</view>
<view class="metric-cell" @click="openPage('/pages/owner/leads')">
<text class="metric-val">{{ leadCount }}</text>
<text class="metric-lbl">{{ t('metricsLeads') }}</text>
</view>
</view>
<!-- 3. Plan & Quota Bento Card -->
<view class="section-card quota-card">
<view class="card-header-row">
<text class="section-title">{{ t('quotaSection') }}</text>
<view class="plan-status-badge">
<view class="status-dot"></view>
<text class="plan-status-text">{{ t('planActive') }}</text>
</view>
</view>
<view class="quota-body">
<view class="quota-meta-row">
<text class="quota-tier-name">{{ t('tierPro') }}</text>
<text class="quota-usage-num">{{ quotaLine }}</text>
</view>
<!-- Visual Progress Bar -->
<view class="progress-track">
<view
class="progress-fill"
:class="{ 'progress-fill-warning': quotaExceeded }"
:style="{ width: quotaPercent + '%' }"
></view>
</view>
<view class="quota-footer-row">
<text v-if="quotaExceeded" class="quota-warn-text">{{ t('quotaUpgrade') }}</text>
<text v-else class="quota-sub-desc">{{ t('quotaCards') }}</text>
<view class="quota-action-link" @click="openBillingPage">
<text class="quota-action-text">{{ t('upgradeQuota') }}</text>
</view>
</view>
</view>
</view>
<!-- 4. Operational Workspace: Hardware & Team Briefing -->
<view class="section-card">
<text class="section-title">{{ t('workspaceSection') }}</text>
<view class="setting-cell" @click="openPage('/pages/owner/nfc/scan')">
<view class="cell-left">
<text class="cell-label">{{ t('nfcScan') }}</text>
</view>
<view class="cell-right">
<text class="cell-arrow">›</text>
</view>
</view>
<view class="row-divider"></view>
<view class="setting-cell" @click="openPage('/pages/owner/nfc/mode')">
<view class="cell-left">
<text class="cell-label">{{ t('nfcMode') }}</text>
</view>
<view class="cell-right">
<text class="cell-arrow">›</text>
</view>
</view>
<view class="row-divider"></view>
<view class="setting-cell" @click="openPage('/pages/owner/nfc/security')">
<view class="cell-left">
<text class="cell-label">{{ t('nfcSecurity') }}</text>
</view>
<view class="cell-right">
<text class="cell-arrow">›</text>
</view>
</view>
<view class="row-divider"></view>
<view class="setting-cell" @click="openPage('/pages/owner/team/overview')">
<view class="cell-left">
<text class="cell-label">{{ t('teamBriefing') }}</text>
</view>
<view class="cell-right">
<text class="cell-arrow">›</text>
</view>
</view>
</view>
<!-- 5. Notifications Settings -->
<view class="section-card">
<text class="section-title">{{ t('notificationsSection') }}</text>
<!-- Radar push notification -->
<view class="setting-cell setting-cell-switch">
<view class="cell-text-wrap">
<text class="cell-label">{{ t('radarPushTitle') }}</text>
<text class="cell-desc">{{ t('radarPushDesc') }}</text>
</view>
<view class="switch-touch-area">
<switch
:checked="state.notifications.radarPush"
color="#0B5CFF"
@change="onRadarPushChange"
/>
</view>
</view>
<view class="row-divider"></view>
<!-- Lead notice notification -->
<view class="setting-cell setting-cell-switch">
<view class="cell-text-wrap">
<text class="cell-label">{{ t('leadNoticeTitle') }}</text>
<text class="cell-desc">{{ t('leadNoticeDesc') }}</text>
</view>
<view class="switch-touch-area">
<switch
:checked="state.notifications.leadNotice"
color="#0B5CFF"
@change="onLeadNoticeChange"
/>
</view>
</view>
</view>
<!-- 6. Preferred Display Language -->
<view class="section-card">
<text class="section-title">{{ t('languageSection') }}</text>
<text class="section-desc">{{ t('languageLabel') }}</text>
<view class="language-options">
<view
v-for="item in languageList"
:key="item.code"
class="language-chip"
:class="{ 'language-chip-active': item.code === state.locale }"
@click="onSelectLocale(item.code)"
>
<text
class="language-chip-text"
:class="{ 'language-chip-text-active': item.code === state.locale }"
>
{{ item.label }}
</text>
</view>
</view>
</view>
<!-- 7. Logout Action (Minimal, safe text button) -->
<view class="logout-wrap">
<view class="logout-btn" @click="onLogout">
<text class="logout-text">{{ t('logout') }}</text>
</view>
</view>
<!-- Error feedback banner -->
<view v-if="state.errorMessage !== ''" class="error-banner">
<text class="error-banner-text">{{ state.errorMessage }}</text>
</view>
<view class="bottom-spacer"></view>
</view>
</scroll-view>
</view>
</template>
<script setup lang="uts">
import {
ProfileState,
loadProfileSettings,
saveProfileSettings,
toggleRadarPush,
toggleLeadNotice,
setPreferredLocale,
resolveProfileText,
previewAccountAvatar,
removeAccountAvatar,
calculateQuotaPercent,
} from './useProfile.uts';
import { OmniLocale } from '../../../common/locale.uts';
import { fetchCardQuota } from '../../../common/api.uts';
import { getTenantId, clearAuthToken } from '../../../common/request.uts';
type LangOption = {
code: OmniLocale;
label: string;
};
const state = reactive<ProfileState>(loadProfileSettings());
const quotaLine = ref('--');
const quotaExceeded = ref(false);
const quotaPercent = ref(20);
const cardCount = ref('1');
const visitorCount = ref('12');
const leadCount = ref('5');
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];
saveProfileSettings(state);
}
},
});
}
function onAvatarDelete(): void {
removeAccountAvatar(state);
saveProfileSettings(state);
}
const languageList: LangOption[] = [
{ code: 'zh-CN', label: '简体中文' },
{ code: 'en-US', label: 'English' },
{ 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: '日本語' },
];
function t(key: string): string {
return resolveProfileText(key);
}
function onRadarPushChange(e: UniSwitchChangeEvent): void {
toggleRadarPush(state, e.detail.value);
}
function onLeadNoticeChange(e: UniSwitchChangeEvent): void {
toggleLeadNotice(state, e.detail.value);
}
function onSelectLocale(code: OmniLocale): void {
setPreferredLocale(state, code);
saveProfileSettings(state);
}
function openPage(url: string): void {
uni.navigateTo({
url,
});
}
function openBillingPage(): void {
uni.showToast({
title: resolveProfileText('tierPro'),
icon: 'none',
});
}
async function loadQuota(): Promise<void> {
try {
const tenantId = getTenantId();
const quota = await fetchCardQuota(tenantId !== '' ? tenantId : 1);
quotaLine.value = `${quota.used} / ${quota.limit}`;
quotaExceeded.value = quota.exceeded === true;
quotaPercent.value = calculateQuotaPercent(quota.used, quota.limit);
cardCount.value = `${quota.used}`;
} catch (_e) {
quotaLine.value = '1 / 5';
quotaExceeded.value = false;
quotaPercent.value = 20;
}
}
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;
loadQuota();
});
</script>
<style scoped>
.profile-page {
display: flex;
flex-direction: column;
height: 100%;
background-color: #F7F8FA;
}
.profile-scroll {
flex: 1;
}
.profile-container {
padding: 16px 16px 32px 16px;
display: flex;
flex-direction: column;
}
/* 1. Hero Identity Bento */
.hero-card {
background-color: #FFFFFF;
border: 1px solid #E3E7ED;
border-radius: 16px;
padding: 16px;
margin-bottom: 12px;
display: flex;
flex-direction: column;
}
.hero-main {
display: flex;
flex-direction: row;
align-items: center;
}
.avatar-box {
position: relative;
width: 56px;
height: 56px;
margin-right: 14px;
}
.account-avatar {
width: 56px;
height: 56px;
border-radius: 28px;
background-color: #E3E7ED;
}
.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;
}
.hero-info {
display: flex;
flex-direction: column;
flex: 1;
}
.name-row {
display: flex;
flex-direction: row;
align-items: center;
}
.account-name {
font-size: 17px;
font-weight: 600;
color: #101828;
line-height: 1.4;
margin-right: 8px;
}
.tier-pill {
padding: 1px 6px;
border-radius: 6px;
background-color: #EAF1FF;
border: 1px solid #0B5CFF;
}
.tier-pill-text {
font-size: 10px;
font-weight: 700;
color: #0B5CFF;
letter-spacing: 0.5px;
}
.account-company {
font-size: 13px;
color: #667085;
margin-top: 3px;
}
.account-dept {
font-size: 12px;
color: #667085;
margin-top: 1px;
}
.hero-actions {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #E3E7ED;
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.preview-btn {
height: 32px;
padding: 0 12px;
border-radius: 8px;
background-color: #F7F8FA;
border: 1px solid #E3E7ED;
display: flex;
align-items: center;
justify-content: center;
}
.preview-btn-text {
font-size: 12px;
font-weight: 500;
color: #101828;
}
/* 2. Metrics Bento Grid */
.metrics-grid {
display: flex;
flex-direction: row;
gap: 8px;
margin-bottom: 12px;
}
.metric-cell {
flex: 1;
background-color: #FFFFFF;
border: 1px solid #E3E7ED;
border-radius: 12px;
padding: 12px 8px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.metric-val {
font-size: 18px;
font-weight: 700;
color: #101828;
line-height: 1.2;
}
.metric-lbl {
font-size: 11px;
color: #667085;
margin-top: 4px;
}
/* 3. Common Section Cards */
.section-card {
background-color: #FFFFFF;
border: 1px solid #E3E7ED;
border-radius: 16px;
padding: 16px;
margin-bottom: 12px;
}
.card-header-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.section-title {
font-size: 15px;
font-weight: 600;
color: #101828;
}
.section-desc {
font-size: 13px;
color: #667085;
margin-top: 2px;
margin-bottom: 12px;
}
.plan-status-badge {
display: flex;
flex-direction: row;
align-items: center;
padding: 2px 8px;
border-radius: 10px;
background-color: #F7F8FA;
border: 1px solid #E3E7ED;
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 3px;
background-color: #12B76A;
margin-right: 4px;
}
.plan-status-text {
font-size: 11px;
font-weight: 500;
color: #667085;
}
/* Quota Details */
.quota-body {
display: flex;
flex-direction: column;
}
.quota-meta-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.quota-tier-name {
font-size: 13px;
font-weight: 600;
color: #101828;
}
.quota-usage-num {
font-size: 13px;
font-weight: 500;
color: #0B5CFF;
}
.progress-track {
height: 6px;
border-radius: 3px;
background-color: #F7F8FA;
border: 1px solid #E3E7ED;
overflow: hidden;
margin-bottom: 8px;
}
.progress-fill {
height: 100%;
border-radius: 3px;
background-color: #0B5CFF;
}
.progress-fill-warning {
background-color: #F04438;
}
.quota-footer-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.quota-sub-desc {
font-size: 12px;
color: #667085;
}
.quota-warn-text {
font-size: 12px;
color: #F04438;
font-weight: 500;
}
.quota-action-link {
min-height: 28px;
display: flex;
align-items: center;
}
.quota-action-text {
font-size: 12px;
font-weight: 600;
color: #0B5CFF;
}
/* Operational Cells */
.setting-cell {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
min-height: 48px;
padding-top: 6px;
padding-bottom: 6px;
}
.setting-cell:active {
opacity: 0.75;
}
.cell-left {
display: flex;
flex-direction: column;
flex: 1;
}
.cell-text-wrap {
display: flex;
flex-direction: column;
flex: 1;
padding-right: 12px;
}
.cell-label {
font-size: 14px;
font-weight: 500;
color: #101828;
}
.cell-desc {
font-size: 12px;
color: #667085;
line-height: 1.4;
margin-top: 2px;
}
.cell-right {
display: flex;
align-items: center;
justify-content: center;
min-width: 24px;
}
.cell-arrow {
font-size: 18px;
color: #667085;
font-weight: 400;
line-height: 1;
}
.setting-cell-switch {
min-height: 52px;
}
.switch-touch-area {
min-width: 44px;
min-height: 44px;
display: flex;
align-items: center;
justify-content: center;
}
.row-divider {
height: 1px;
background-color: #E3E7ED;
margin-top: 4px;
margin-bottom: 4px;
}
/* Language Chips */
.language-options {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 8px;
margin-top: 4px;
}
.language-chip {
min-height: 44px;
padding: 0 16px;
border-radius: 12px;
border: 1px solid #E3E7ED;
background-color: #F7F8FA;
display: flex;
align-items: center;
justify-content: center;
}
.language-chip-active {
border-color: #0B5CFF;
background-color: #0B5CFF;
}
.language-chip-text {
font-size: 13px;
font-weight: 500;
color: #101828;
}
.language-chip-text-active {
color: #FFFFFF;
}
/* Logout wrap */
.logout-wrap {
display: flex;
align-items: center;
justify-content: center;
margin-top: 8px;
margin-bottom: 16px;
}
.logout-btn {
min-height: 44px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: center;
}
.logout-text {
font-size: 14px;
font-weight: 500;
color: #667085;
}
.error-banner {
padding: 12px 16px;
background-color: #F7F8FA;
border: 1px solid #E3E7ED;
border-radius: 12px;
margin-bottom: 16px;
}
.error-banner-text {
font-size: 13px;
color: #667085;
}
.bottom-spacer {
height: calc(32px + var(--window-bottom, 0px) + env(safe-area-inset-bottom, 0px));
}
</style>