28 lines
928 B
TypeScript
28 lines
928 B
TypeScript
import type { ProjectListItem } from '@lehuo/contracts';
|
|
import { MiniProgramApiError } from '../../services/api-client';
|
|
import { fetchPublicProjects } from '../../services/participation';
|
|
|
|
Page({
|
|
data: { loading: true, message: '', items: [] as ProjectListItem[] },
|
|
onLoad() {
|
|
void this.load();
|
|
},
|
|
async load() {
|
|
this.setData({ loading: true, message: '' });
|
|
try {
|
|
const result = await fetchPublicProjects();
|
|
this.setData({ items: result.items });
|
|
} catch (error) {
|
|
this.setData({
|
|
message: error instanceof MiniProgramApiError ? error.message : '项目加载失败,请稍后重试',
|
|
});
|
|
} finally {
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
open(event: WechatMiniprogram.BaseEvent) {
|
|
const publicId = event.currentTarget.dataset['id'] as string;
|
|
void wx.navigateTo({ url: `/pages/project-detail/project-detail?publicId=${publicId}` });
|
|
},
|
|
});
|