95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
import { AUTH_READY_MESSAGE, MINI_PROGRAM_TITLE } from '../../constants/app-info';
|
||
import { MiniProgramApiError } from '../../services/api-client';
|
||
import { loginWithWechat, restoreCurrentSession } from '../../services/auth';
|
||
|
||
Page({
|
||
data: {
|
||
authStatus: 'loading',
|
||
message: '正在安全登录,请稍候…',
|
||
title: MINI_PROGRAM_TITLE,
|
||
canCollaborate: false,
|
||
serviceCategories: [
|
||
{ code: 'OLD_AGE', label: '关爱老人', symbol: '老', tone: 'orange' },
|
||
{ code: 'WOMEN_CHILDREN', label: '困境儿童', symbol: '童', tone: 'green' },
|
||
{ code: 'WOMEN_CHILDREN', label: '妇女帮扶', symbol: '女', tone: 'rose' },
|
||
{ code: 'DISABILITY', label: '残障救助', symbol: '助', tone: 'blue' },
|
||
],
|
||
},
|
||
|
||
onLoad() {
|
||
void this.authenticate();
|
||
},
|
||
|
||
async authenticate() {
|
||
this.setData({ authStatus: 'loading', message: '正在安全登录,请稍候…' });
|
||
try {
|
||
const session = await restoreCurrentSession();
|
||
const user = session?.user ?? (await loginWithWechat()).user;
|
||
this.setData({
|
||
authStatus: 'success',
|
||
message: AUTH_READY_MESSAGE,
|
||
canCollaborate: user.permissions.includes('assigned_cases:read'),
|
||
});
|
||
} catch (error) {
|
||
const message =
|
||
error instanceof MiniProgramApiError && error.requestId
|
||
? `${error.message}(编号:${error.requestId})`
|
||
: error instanceof Error
|
||
? error.message
|
||
: '登录失败,请稍后重试';
|
||
this.setData({ authStatus: 'error', message });
|
||
}
|
||
},
|
||
|
||
retryLogin() {
|
||
void this.authenticate();
|
||
},
|
||
|
||
applyForSelf() {
|
||
void wx.navigateTo({ url: '/pages/application-form/application-form?mode=SELF' });
|
||
},
|
||
|
||
applyForFamily() {
|
||
void wx.navigateTo({ url: '/pages/application-form/application-form?mode=FAMILY' });
|
||
},
|
||
|
||
applyForCategory(event: WechatMiniprogram.BaseEvent) {
|
||
const category = event.currentTarget.dataset['code'] as string;
|
||
void wx.navigateTo({
|
||
url: `/pages/application-form/application-form?mode=SELF&category=${category}`,
|
||
});
|
||
},
|
||
|
||
viewMyApplications() {
|
||
void wx.navigateTo({ url: '/pages/my-applications/my-applications' });
|
||
},
|
||
|
||
viewAssignedCases() {
|
||
void wx.navigateTo({ url: '/pages/assigned-cases/assigned-cases' });
|
||
},
|
||
|
||
viewProjects() {
|
||
void wx.navigateTo({ url: '/pages/projects/projects' });
|
||
},
|
||
|
||
viewActivities() {
|
||
void wx.navigateTo({ url: '/pages/activities/activities' });
|
||
},
|
||
|
||
viewVolunteerCenter() {
|
||
void wx.navigateTo({ url: '/pages/volunteer-center/volunteer-center' });
|
||
},
|
||
viewContent() {
|
||
void wx.navigateTo({ url: '/pages/content/content' });
|
||
},
|
||
viewOrganization() {
|
||
void wx.navigateTo({ url: '/pages/content/content?type=ORGANIZATION_INTRO' });
|
||
},
|
||
viewNotifications() {
|
||
void wx.navigateTo({ url: '/pages/notifications/notifications' });
|
||
},
|
||
apply() {
|
||
void wx.navigateTo({ url: '/pages/application-form/application-form?mode=SELF' });
|
||
},
|
||
});
|