feat: add account deletion, announcements and subscription renewal

Support personal records and persistent smoking visibility. Add upload quota preflight, file cleanup, privacy entry, image caching and revision-based page refresh across the backend, admin and mini program.
This commit is contained in:
2026-11-03 22:06:47 +08:00
parent 4c9708b562
commit 8be6d9b1ab
98 changed files with 1679 additions and 372 deletions
+29 -3
View File
@@ -14,8 +14,10 @@ App({
onLaunch: function() {
this.removeLegacyDataCaches();
this._authListeners = [];
require('./utils/subscribe').resetLoginRenewal();
// 冷启动始终换取新 token,所有业务请求共享这一次登录。
this.silentLogin().catch(function() {});
if (wx.getStorageSync('accountDeleted')) this.setAuthState('error','账号已注销。再次进入将创建新账号,原数据不会恢复。');
else this.silentLogin().catch(function() {});
this.checkNetwork();
wx.onNetworkStatusChange((res) => {
this.globalData.isConnected = res.isConnected;
@@ -23,6 +25,16 @@ App({
});
},
finishAccountDeletion: function() {
require('./utils/data-cache').clear();
require('./utils/announcement-session').clear();
require('./utils/subscribe').resetLoginRenewal();
this._authGeneration=(this._authGeneration||0)+1;this._authPromise=null;
wx.clearStorageSync();
wx.setStorageSync('accountDeleted',true);
this.globalData.token=null;this.globalData.userId=null;
this.setAuthState('error','账号已注销。再次进入将创建新账号,原数据不会恢复。');
},
onRelationChanged: function() {
if (this._relationRedirect) return;
wx.removeStorageSync('petHasPet');
@@ -35,13 +47,19 @@ App({
this._relationSync = true;
const before = String(wx.getStorageSync('coupleId') || '');
try {
await api.checkAuth();
const auth = await api.checkAuth({cache:false, silent:true});
const changed = require('./utils/data-cache').applyRemoteRevision(auth.data_revision);
if (before !== String(wx.getStorageSync('coupleId') || '')) {
this.onRelationChanged();
} else if (changed && typeof getCurrentPages === 'function') {
const pages = getCurrentPages();
const page = pages[pages.length - 1];
if (page && page.onDataChanged) page.onDataChanged();
}
} catch(e) {} finally { this._relationSync = false; }
};
sync();
if (this.globalData.authState === 'ready') require('./utils/subscribe').prepareLoginRenewal();
if (!this._relationTimer) this._relationTimer = setInterval(sync, 30000);
},
onHide: function() { if(this._relationTimer) clearInterval(this._relationTimer); this._relationTimer=null; },
@@ -65,6 +83,7 @@ App({
},
// 多个旧 token 请求同时返回 401 时,只刷新一次;较晚返回的旧请求复用新 token。
refreshAuth: function(failedToken) {
if(wx.getStorageSync('accountDeleted')) return Promise.reject({error:'账号已注销',accountDeleted:true});
if (this._authPromise) return this._authPromise;
if (this.globalData.authState === 'ready' && wx.getStorageSync('token') !== failedToken) return Promise.resolve();
return this.silentLogin();
@@ -109,20 +128,24 @@ App({
silentLogin: function() {
if (this._authPromise) return this._authPromise;
const generation=this._authGeneration||0;
this.setAuthState('loading');
this._authPromise = this.performLogin().then((res) => {
this.setAuthState('ready');
require('./utils/subscribe').prepareLoginRenewal();
return res;
}).catch((error) => {
if(generation!==(this._authGeneration||0))throw error;
wx.removeStorageSync('token');
this.globalData.token = null;
var failure = { error: (error && error.error) || '登录失败,请检查网络后重试', authFailed: true };
this.setAuthState('error', failure.error);
throw failure;
}).finally(() => { this._authPromise = null; });
}).finally(() => { if(generation===(this._authGeneration||0))this._authPromise = null; });
return this._authPromise;
},
performLogin: async function() {
const generation=this._authGeneration||0;
var loginRes = await new Promise(function(resolve, reject) {
var done = false;
var timer = setTimeout(function() {
@@ -136,7 +159,9 @@ App({
if (!loginRes.code) throw { error: '未能获取微信登录凭证,请重试' };
// 定位授权不阻塞登录,城市信息由页面后续的定位接口更新。
var res = await api.wechatLogin(loginRes.code, '');
if (generation!==(this._authGeneration||0)) throw {error:'账号状态已变更,请重新进入'};
if (!res || !res.token || !res.user_id) throw { error: '登录响应不完整,请重试' };
wx.removeStorageSync('accountDeleted');
wx.setStorageSync('token', res.token);
wx.setStorageSync('userId', res.user_id);
wx.setStorageSync('coupleId', res.couple_id || '');
@@ -144,6 +169,7 @@ App({
wx.setStorageSync('nickname', res.nickname || '');
wx.setStorageSync('region', res.region || '');
wx.setStorageSync('hasLoggedIn', true);
require('./utils/data-cache').applyRemoteRevision(res.data_revision);
this.globalData.token = res.token;
this.globalData.userId = res.user_id;
return res;