2026-03-30 18:08:27 +08:00
|
|
|
|
const auth = require('../../../utils/auth');
|
2026-04-02 18:02:17 +08:00
|
|
|
|
const { formatTime } = require('../../../utils/format');
|
|
|
|
|
|
|
|
|
|
|
|
const PAGE_SIZE = 10;
|
2026-03-30 18:08:27 +08:00
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
nickName: '',
|
|
|
|
|
|
certificateCount: '-',
|
2026-04-02 18:02:17 +08:00
|
|
|
|
headerBg: 'https://yuedong-wechatapplet.oss-cn-shanghai.aliyuncs.com/static/event_miniapp/book.png',
|
|
|
|
|
|
tabLineImg: 'https://yuedong-wechatapplet.oss-cn-shanghai.aliyuncs.com/static/event_miniapp/point-b.png',
|
|
|
|
|
|
|
|
|
|
|
|
activeTab: 1, // 1-个人证书 2-团队证书
|
|
|
|
|
|
records: [],
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
noMore: false,
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
refresherTriggered: false
|
2026-03-30 18:08:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
|
const accessToken = wx.getStorageSync('accessToken') || '';
|
|
|
|
|
|
if (!accessToken) {
|
|
|
|
|
|
wx.redirectTo({ url: '/subpackages/mine/login/login' });
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-04-02 18:02:17 +08:00
|
|
|
|
this.resetAndLoad();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
this.resetAndLoad()
|
|
|
|
|
|
.finally(() => wx.stopPullDownRefresh());
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onRefresh() {
|
|
|
|
|
|
if (this.data.refresherTriggered) return;
|
|
|
|
|
|
this.setData({ refresherTriggered: true });
|
|
|
|
|
|
this.resetAndLoad()
|
|
|
|
|
|
.finally(() => this.setData({ refresherTriggered: false }));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 返回 */
|
|
|
|
|
|
onBack() {
|
|
|
|
|
|
wx.navigateBack({ delta: 1 });
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 切换Tab */
|
|
|
|
|
|
onSwitchTab(e) {
|
|
|
|
|
|
const tab = Number(e.currentTarget.dataset.tab);
|
|
|
|
|
|
if (tab === this.data.activeTab) return;
|
|
|
|
|
|
this.setData({ activeTab: tab });
|
|
|
|
|
|
this.resetAndLoad();
|
2026-03-30 18:08:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
loadProfile() {
|
|
|
|
|
|
if (this.data.loading) return;
|
|
|
|
|
|
|
|
|
|
|
|
auth
|
|
|
|
|
|
.fetchMyProfile()
|
|
|
|
|
|
.then((profile) => {
|
2026-04-10 16:10:33 +08:00
|
|
|
|
console.log('profile', profile);
|
2026-03-30 18:08:27 +08:00
|
|
|
|
const p = profile || {};
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
nickName: p.nickName || '',
|
|
|
|
|
|
certificateCount: p.certificateCount != null ? p.certificateCount : '-'
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
2026-05-09 16:19:37 +08:00
|
|
|
|
.catch(() => {});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-04-02 18:02:17 +08:00
|
|
|
|
|
|
|
|
|
|
/** 重置并加载 */
|
|
|
|
|
|
resetAndLoad() {
|
|
|
|
|
|
this.setData({ records: [], pageNo: 1, noMore: false });
|
2026-05-09 16:19:37 +08:00
|
|
|
|
this.loadProfile();
|
2026-04-02 18:02:17 +08:00
|
|
|
|
return this.loadRecords();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-04-10 01:07:07 +08:00
|
|
|
|
/** 上拉加载更多 */
|
|
|
|
|
|
onReachBottom() {
|
2026-04-02 18:02:17 +08:00
|
|
|
|
if (this.data.loading || this.data.noMore) return;
|
|
|
|
|
|
this.loadRecords();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 加载证书列表 */
|
|
|
|
|
|
loadRecords() {
|
|
|
|
|
|
if (this.data.loading) return Promise.resolve();
|
|
|
|
|
|
this.setData({ loading: true });
|
|
|
|
|
|
|
|
|
|
|
|
const { pageNo, activeTab } = this.data;
|
|
|
|
|
|
|
|
|
|
|
|
return auth
|
|
|
|
|
|
.fetchMyCertificates({ pageNo, pageSize: PAGE_SIZE, type: activeTab })
|
|
|
|
|
|
.then((result) => {
|
|
|
|
|
|
const res = result || {};
|
|
|
|
|
|
const rows = Array.isArray(res.rows) ? res.rows : (Array.isArray(res.list) ? res.list : []);
|
|
|
|
|
|
const total = typeof res.total === 'number' ? res.total : (typeof res.count === 'number' ? res.count : rows.length);
|
|
|
|
|
|
|
|
|
|
|
|
const formatted = rows.map((item, idx) => ({
|
|
|
|
|
|
...item,
|
|
|
|
|
|
id: item.id != null ? item.id : `${activeTab}-${pageNo}-${idx}`,
|
2026-04-08 00:40:29 +08:00
|
|
|
|
// 赛事名称
|
|
|
|
|
|
eventName: item.eventName || '',
|
|
|
|
|
|
// 项目-组别展示,优先用 projectGroupDisplay,否则拼接 projectName + groupName
|
|
|
|
|
|
projectGroupDisplay:
|
|
|
|
|
|
item.projectGroupDisplay ||
|
|
|
|
|
|
[item.projectName, item.groupName].filter(Boolean).join(' - ') ||
|
|
|
|
|
|
'-',
|
|
|
|
|
|
// 证书链接
|
|
|
|
|
|
certificateUrl: item.certificateUrl || '',
|
|
|
|
|
|
// 证书名称(用于查看证书时的标题)
|
|
|
|
|
|
certificateName: item.certificateName || item.eventName || '证书',
|
|
|
|
|
|
// 颁发时间
|
|
|
|
|
|
timeStr: item.issuedTime
|
|
|
|
|
|
? formatTime(item.issuedTime)
|
|
|
|
|
|
: item.createdTime
|
|
|
|
|
|
? formatTime(item.createdTime)
|
|
|
|
|
|
: ''
|
2026-04-02 18:02:17 +08:00
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
const newRecords = this.data.records.concat(formatted);
|
|
|
|
|
|
const currentTotal = pageNo * PAGE_SIZE;
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
records: newRecords,
|
|
|
|
|
|
pageNo: pageNo + 1,
|
2026-05-09 16:19:37 +08:00
|
|
|
|
noMore: currentTotal >= total
|
2026-04-02 18:02:17 +08:00
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
wx.showToast({ title: '加载失败', icon: 'none' });
|
|
|
|
|
|
})
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
this.setData({ loading: false });
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 查看证书 */
|
|
|
|
|
|
onViewCert(e) {
|
|
|
|
|
|
const url = e.currentTarget.dataset.url;
|
|
|
|
|
|
const name = e.currentTarget.dataset.name || '证书';
|
|
|
|
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
|
|
wx.showToast({ title: '暂无证书链接', icon: 'none' });
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lower = String(url).toLowerCase();
|
|
|
|
|
|
const isImage = lower.endsWith('.png') || lower.endsWith('.jpg') || lower.endsWith('.jpeg') || lower.includes('image');
|
|
|
|
|
|
const isPdf = lower.endsWith('.pdf');
|
|
|
|
|
|
|
|
|
|
|
|
if (isImage) {
|
|
|
|
|
|
wx.previewImage({ urls: [url], current: url });
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isPdf) {
|
|
|
|
|
|
wx.showLoading({ title: '打开中...' });
|
|
|
|
|
|
wx.downloadFile({
|
|
|
|
|
|
url,
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
wx.openDocument({
|
|
|
|
|
|
filePath: res.tempFilePath,
|
|
|
|
|
|
showMenu: true,
|
|
|
|
|
|
success: () => {},
|
|
|
|
|
|
fail: () => wx.showToast({ title: '打开失败', icon: 'none' }),
|
|
|
|
|
|
complete: () => wx.hideLoading()
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: () => {
|
2026-04-13 23:56:07 +08:00
|
|
|
|
// wx.hideLoading();
|
2026-04-02 18:02:17 +08:00
|
|
|
|
wx.showToast({ title: '下载失败', icon: 'none' });
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wx.setClipboardData({
|
|
|
|
|
|
data: url,
|
|
|
|
|
|
success: () => wx.showToast({ title: `${name}链接已复制`, icon: 'none' })
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-03-30 18:08:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
|