feat(portal): 优化微官网首页名片主客态自适应与主CTA动态切换

这个提交包含在:
wikiboss
2026-09-21 15:05:10 +08:00
父节点 43d4ec42bf
当前提交 3243979169
共有 4 个文件被更改,包括 837 次插入 和 232 次删除

查看文件

@@ -11,6 +11,7 @@ import {
} from '../../../common/types.uts';
import { fetchOwnerCardPage } from '../../../common/api.uts';
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
import { setOwnerCardIds } from '../../portal/usePortal.uts';
export type CardHomeItem = {
id?: string | number;
@@ -86,7 +87,7 @@ function isZhLocale(): boolean {
*/
export function resolveCardHomeText(key: CardHomeCopyKey): string {
const locale = getCurrentLocale();
if (key === 'poster' || key === 'share') {
if (key === 'share') {
return getOmniText(locale, 'card.share');
}
if (key === 'preview') {
@@ -103,6 +104,9 @@ export function resolveCardHomeText(key: CardHomeCopyKey): string {
}
const zh = isZhLocale();
if (key === 'poster') {
return zh ? '分享海报' : 'Share poster';
}
if (key === 'title') {
return zh ? '我的名片' : 'My cards';
}
@@ -113,7 +117,7 @@ export function resolveCardHomeText(key: CardHomeCopyKey): string {
return zh ? '搜索姓名、职位或公司' : 'Search name, title or company';
}
if (key === 'refresh') {
return zh ? '分享名片' : 'Share card';
return zh ? '刷新' : 'Refresh';
}
if (key === 'statusDraft') {
return zh ? '草稿' : 'Draft';
@@ -204,8 +208,19 @@ export async function loadCards(
const data = await fetchPage(sanitizeCardQuery(query));
const rawList = data.list != null ? data.list : [];
const list: CardHomeItem[] = [];
const ownerIds: string[] = [];
for (let i = 0; i < rawList.length; i++) {
list.push(toCardHomeItem(rawList[i]));
const item = toCardHomeItem(rawList[i]);
list.push(item);
if (item.id != null) {
ownerIds.push(String(item.id));
}
if (item.slug != null && item.slug !== '') {
ownerIds.push(item.slug);
}
}
if (ownerIds.length > 0) {
setOwnerCardIds(ownerIds);
}
const pagination =
data.pagination != null
@@ -323,12 +338,12 @@ export function openCardQrcode(card: CardHomeItem): void {
export function buildPortalPreviewUrl(card: CardHomeItem): string {
if (card.slug != null && card.slug !== '') {
return `/pages/portal/index?slug=${card.slug}`;
return `/pages/portal/index?slug=${card.slug}&mode=owner`;
}
if (card.id != null) {
return `/pages/portal/index?id=${card.id}`;
return `/pages/portal/index?id=${card.id}&mode=owner`;
}
return '/pages/portal/index';
return '/pages/portal/index?mode=owner';
}
export function openCardPreview(card: CardHomeItem): void {

文件差异内容过多而无法显示 加载差异

查看文件

@@ -418,3 +418,126 @@ export function filterVisibleBentoBlocks(blocks?: BentoBlockPublic[]): BentoBloc
.filter((b) => b.type !== 'hero')
.sort((a, b) => a.sortOrder - b.sortOrder);
}
export type PortalCollectCopyKey = 'label' | 'saved';
/**
* 收藏大厅文案:只解析 locale,不改 load / save / 上报
*/
export function resolvePortalCollectText(
key: PortalCollectCopyKey,
locale?: OmniLocale
): string {
const loc = locale != null ? locale : getCurrentLocale();
if (key === 'saved') {
return getOmniText(loc, 'portal.collected');
}
return getOmniText(loc, 'portal.collect');
}
export const OWNER_CARD_IDS_STORAGE_KEY = 'omni_owner_card_ids';
/**
* 读取本地名片主人 ID 集合缓存
*/
export function getOwnerCardIds(): string[] {
try {
const raw = uni.getStorageSync(OWNER_CARD_IDS_STORAGE_KEY);
if (raw == null) {
return [];
}
if (Array.isArray(raw)) {
const list: string[] = [];
for (let i = 0; i < raw.length; i++) {
list.push(String(raw[i]));
}
return list;
}
if (typeof raw === 'string') {
const str = (raw as string).trim();
if (str.startsWith('[')) {
const parsed = JSON.parse(str);
if (Array.isArray(parsed)) {
const list: string[] = [];
for (let i = 0; i < parsed.length; i++) {
list.push(String(parsed[i]));
}
return list;
}
}
}
} catch (_e) {}
return [];
}
/**
* 缓存名片主人名下的全部卡片 ID 与 Slug
*/
export function setOwnerCardIds(ids: string[]): void {
try {
uni.setStorageSync(OWNER_CARD_IDS_STORAGE_KEY, ids);
} catch (_e) {}
}
export type CheckIsOwnerParams = {
hasToken: boolean;
queryId?: string;
queryMode?: string;
cardId?: string | number;
cardSlug?: string;
ownerCardIds?: string[];
};
/**
* 精准判定当前浏览者是否为该名片主人
* 1. 显式参数带 mode=owner -> true
* 2. 具备登录 Token 且:
* - queryId 为空或 'default'(TabBar 默认进入) -> true
* - 或 cardId / cardSlug 存在于名片主卡片 ID 缓存集合中 -> true
* 3. 其余外部访客场景 -> false
*/
export function checkIsCardOwner(params: CheckIsOwnerParams): boolean {
if (params.queryMode === 'owner') {
return true;
}
if (!params.hasToken) {
return false;
}
const qId = params.queryId != null ? params.queryId.trim().toLowerCase() : '';
if (qId === '' || qId === 'default') {
return true;
}
const currentId = params.cardId != null ? String(params.cardId).trim() : '';
const currentSlug = params.cardSlug != null ? String(params.cardSlug).trim() : '';
const list = params.ownerCardIds != null ? params.ownerCardIds : getOwnerCardIds();
for (let i = 0; i < list.length; i++) {
const item = String(list[i]).trim();
if (item !== '' && (item === currentId || item === currentSlug)) {
return true;
}
}
return false;
}
/**
* 动态解析主 CTA 按钮文案 (主人态: 分享名片 / 访客态: 保存到通讯录)
*/
export function resolvePortalCtaText(isOwner: boolean, locale?: OmniLocale): string {
const loc = locale != null ? locale : getCurrentLocale();
if (isOwner) {
return getOmniText(loc, 'card.share');
}
return getOmniText(loc, 'card.save_contact');
}
/**
* 动态解析微官网顶栏辅助操作文案 (主人态: 编辑 / 访客态: 交换名片)
*/
export function resolvePortalHeaderLinkText(isOwner: boolean, locale?: OmniLocale): string {
const loc = locale != null ? locale : getCurrentLocale();
if (isOwner) {
return getOmniText(loc, 'common.edit');
}
return getOmniText(loc, 'card.exchange');
}