Gate record features and storage entry points with invitation guidance; enforce record access in the backend. Add homepage greetings, right-swipe profile dismissal, and move the smoking switch to settings. Simplify API base configuration and remove the unused legacy tab bar component.
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
const { withRecordAccess } = require('../../utils/record-access');
|
|
const { tryLoginRenewal } = require('../../utils/subscribe');
|
|
const { withDataCache } = require('../../utils/page-cache');
|
|
const { getLayout } = require('../../utils/layout');
|
|
// pages/pet/achievements.js
|
|
const { api } = require('../../utils/request');
|
|
|
|
Page(withRecordAccess(withDataCache({
|
|
onLoginSubscribeTap: function() { return tryLoginRenewal(); },
|
|
onResize: function() { this.setData(getLayout()); },
|
|
data: { loading: true, loadError: false,
|
|
achievements: [],
|
|
unlockedCount: 0,
|
|
totalCount: 0,
|
|
progressPercent: 0
|
|
},
|
|
|
|
onLoad: function() {
|
|
this.setData(getLayout());
|
|
this.loadAchievements();
|
|
},
|
|
|
|
onShow: function() {
|
|
this.loadAchievements();
|
|
},
|
|
|
|
loadAchievements: async function() {
|
|
if (this._pageLoading) return;
|
|
this._pageLoading = true;
|
|
this.setData({loading: !this._hasCachedData, loadError:false});
|
|
try {
|
|
const res = await api.petAchievements();
|
|
let list = res.achievements || [];
|
|
// 排序:已解锁的按解锁时间倒序(最新获得的排最前),未解锁的排后面
|
|
list = list.sort(function(a, b) {
|
|
var aUnlocked = a.unlocked ? 1 : 0;
|
|
var bUnlocked = b.unlocked ? 1 : 0;
|
|
if (aUnlocked !== bUnlocked) {
|
|
return bUnlocked - aUnlocked;
|
|
}
|
|
if (aUnlocked && bUnlocked) {
|
|
var ta = (a.unlocked_at || '').replace(/-/g, '').replace(/[: ]/g, '');
|
|
var tb = (b.unlocked_at || '').replace(/-/g, '').replace(/[: ]/g, '');
|
|
return tb.localeCompare(ta);
|
|
}
|
|
return 0;
|
|
});
|
|
const unlocked = list.filter(a => a.unlocked);
|
|
const total = list.length;
|
|
var pageData = {
|
|
achievements: list,
|
|
unlockedCount: unlocked.length,
|
|
totalCount: total,
|
|
progressPercent: total > 0 ? Math.round(unlocked.length / total * 100) : 0
|
|
};
|
|
this.setData(pageData);
|
|
} catch (e) {
|
|
this.setData({loadError:true});
|
|
console.error(e);
|
|
}
|
|
finally { this._pageLoading = false; this.setData({loading:false}); }
|
|
},
|
|
|
|
goBack: function() {
|
|
wx.navigateBack();
|
|
}
|
|
}, {"loadAchievements": ["petAchievements"]})));
|