feat: 完成全部接口替换为新后端接口

This commit is contained in:
R524809
2026-10-19 13:19:07 +08:00
parent 8de06ce66b
commit 997042789d
40 changed files with 1946 additions and 785 deletions
+15 -3
View File
@@ -123,7 +123,7 @@ page {
box-sizing: border-box;
}
.profile-hero__stat+.profile-hero__stat {
.profile-hero__stat + .profile-hero__stat {
margin-left: 32rpx;
}
@@ -164,7 +164,7 @@ page {
box-sizing: border-box;
}
.profile-grid__cell+.profile-grid__cell {
.profile-grid__cell + .profile-grid__cell {
margin-left: 32rpx;
}
@@ -461,4 +461,16 @@ page {
.profile-editor__action--disabled {
opacity: 0.6;
}
}
/* 仅在账户恢复需要用户主动确认时展示,正常静默登录不出现。 */
.profile-account-restart {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
padding: 24rpx;
margin-bottom: @section-gap-xs;
border-radius: @radius-xl;
background: @bg-white;
font-size: 26rpx;
}
+52 -30
View File
@@ -1,7 +1,7 @@
import { uploadAsset, memberStats } from '../../services/member-api';
import { getUser as getServerUser, startAccount } from '../../utils/auth';
import { disablePageShareMenu } from '../../base/pageMixin';
import { APP_VERSION } from '../../config/config';
import { getDownloadLogCount } from '../../utils/downloadLogs';
import { getFavoriteCount } from '../../utils/favorites';
import {
getCachedUser,
getUser,
@@ -22,6 +22,8 @@ Page({
draftNickName: '',
draftAvatarUrl: '/assets/imgs/doodle-head.png',
isSavingProfile: false,
serverAccountActionRequired: false,
isStartingAccount: false,
},
onLoad() {
@@ -35,17 +37,52 @@ Page({
},
onShow() {
void this.checkServerAccount();
this.syncUserInfoFromApp();
void this.refreshStats();
},
/** 正常登录始终静默;账户不存在时才展示用户主动重新开始的入口。 */
async checkServerAccount() {
try {
await getServerUser();
this.setData({ serverAccountActionRequired: false });
} catch (error) {
const reason = (error as { reason?: string }).reason;
this.setData({
serverAccountActionRequired:
reason === 'ACCOUNT_NOT_FOUND' ||
reason === 'ACCOUNT_RESTART_REQUIRED',
});
}
},
async onStartServerAccount() {
if (this.data.isStartingAccount) return;
this.setData({ isStartingAccount: true });
try {
await startAccount();
this.setData({ serverAccountActionRequired: false });
wx.showToast({ title: '账户已就绪', icon: 'success' });
} catch {
wx.showToast({ title: '账户暂不可用,请稍后重试', icon: 'none' });
} finally {
this.setData({ isStartingAccount: false });
}
},
async syncUserInfoFromApp() {
const app = getApp<IAppOption>();
const cachedUser = app.globalData.user || getCachedUser();
if (cachedUser) {
this.applyUserInfo(cachedUser);
}
if (cachedUser) this.applyUserInfo(cachedUser);
else
this.setData({
userName: '微信用户',
avatarUrl: this.DEFAULT_AVATAR_URL,
printCount: 0,
favoriteCount: 0,
});
try {
const latestUser = await getUser();
@@ -69,13 +106,11 @@ Page({
async refreshStats() {
try {
const [printCount, favoriteCount] = await Promise.all([
getDownloadLogCount(),
getFavoriteCount(),
]);
const stats = await memberStats();
const { downloadCount: printCount, favoriteCount } = stats;
this.setData({ printCount, favoriteCount });
} catch (e) {
console.error('refreshStats failed', e);
} catch {
this.setData({ printCount: 0, favoriteCount: 0 });
}
},
@@ -121,12 +156,12 @@ Page({
this.setData({ isSavingProfile: true });
try {
const avatarUrl = await this.persistAvatarIfNeeded(
const avatarAssetId = await this.persistAvatarIfNeeded(
this.data.draftAvatarUrl,
);
const user = await updateUserProfile({
nickName,
avatarUrl,
avatarAssetId,
});
this.applyUserInfo(user);
@@ -140,24 +175,11 @@ Page({
}
},
async persistAvatarIfNeeded(avatarUrl: string): Promise<string> {
if (!avatarUrl) return avatarUrl;
if (
avatarUrl.startsWith('cloud://') ||
avatarUrl.startsWith('http://') ||
avatarUrl.startsWith('https://')
) {
return avatarUrl;
}
async persistAvatarIfNeeded(avatarUrl: string): Promise<string | null> {
const user = await getUser();
const cloudPath = `user-avatars/${user._id}-${Date.now()}.png`;
const uploadRes = await wx.cloud.uploadFile({
cloudPath,
filePath: avatarUrl,
});
return uploadRes.fileID;
if (!avatarUrl || avatarUrl === this.DEFAULT_AVATAR_URL) return null;
if (avatarUrl === user.avatarUrl) return user.avatarAssetId || null;
return (await uploadAsset(avatarUrl, 'avatar')).id;
},
onGoToDownloads() {
+13
View File
@@ -38,6 +38,19 @@
</view>
</view>
<view
wx:if="{{serverAccountActionRequired}}"
class="profile-account-restart">
<text>账户需要重新开始使用</text>
<button
size="mini"
loading="{{isStartingAccount}}"
disabled="{{isStartingAccount}}"
bindtap="onStartServerAccount">
开始使用账户
</button>
</view>
<!-- 双格入口 -->
<view class="profile-grid">
<view class="profile-grid__cell" bindtap="onGoToFavorites">