feat(miniapp): migrate C-group pages to TypeScript, update contracts
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
interface RiskItem {
|
||||
title: string
|
||||
description: string
|
||||
}
|
||||
|
||||
interface AntiFraudPageData {
|
||||
risks: RiskItem[]
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
risks: [
|
||||
{ title: '投资博彩诱导', description: '刚认识便引导投资、博彩或下载陌生应用' },
|
||||
{ title: '借款资金周转', description: '以生病、工程或临时周转为由反复借款' },
|
||||
{ title: '索取隐私资料', description: '催促脱离平台并索要验证码、银行卡或证件信息' },
|
||||
{ title: '冒充平台人员', description: '以认证、保证金或解冻账户为由要求转账' },
|
||||
],
|
||||
},
|
||||
|
||||
report() {
|
||||
wx.navigateTo({ url: '/pages/report/report?type=fraud' })
|
||||
},
|
||||
|
||||
requestHelp() {
|
||||
wx.showModal({
|
||||
title: '安全求助',
|
||||
content: '如有财产损失或人身危险,请立即拨打 110;非紧急问题可前往平台帮助中心。',
|
||||
confirmText: '拨打 110',
|
||||
cancelText: '帮助中心',
|
||||
success(result: WechatMiniprogram.ShowModalSuccessCallbackResult) {
|
||||
if (result.confirm) wx.makePhoneCall({ phoneNumber: '110' })
|
||||
else if (result.cancel) wx.navigateTo({ url: '/pages/help-center/help-center' })
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,103 @@
|
||||
import api from '../../utils/api'
|
||||
|
||||
interface ContentCategory {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface ContentArticle {
|
||||
id: string
|
||||
title: string
|
||||
summary?: string
|
||||
categoryId?: string
|
||||
categoryName?: string
|
||||
coverFileId?: string
|
||||
viewCount?: number
|
||||
publishAt?: string
|
||||
createdAt?: string
|
||||
publishAtText?: string
|
||||
}
|
||||
|
||||
interface ContentPageData {
|
||||
categories: ContentCategory[]
|
||||
activeCategoryId: string
|
||||
articles: ContentArticle[]
|
||||
loading: boolean
|
||||
loadError: boolean
|
||||
}
|
||||
|
||||
const formatDate = (value: string | undefined): string => {
|
||||
if (!value) return ''
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return ''
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${month}-${day}`
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
categories: [{ id: '', name: '推荐' }],
|
||||
activeCategoryId: '',
|
||||
articles: [],
|
||||
loading: true,
|
||||
loadError: false,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadPage()
|
||||
},
|
||||
|
||||
async loadPage() {
|
||||
this.setData({ loading: true, loadError: false })
|
||||
try {
|
||||
const [categories, articles] = await Promise.all([
|
||||
api.get<ContentCategory[]>('/content/categories'),
|
||||
api.get<ContentArticle[]>('/content/articles'),
|
||||
])
|
||||
this.setData({
|
||||
categories: [{ id: '', name: '推荐' }, ...(categories || [])],
|
||||
articles: this.normalizeArticles(articles || [], categories || []),
|
||||
loading: false,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('加载婚恋课堂失败', error)
|
||||
this.setData({ loading: false, loadError: true })
|
||||
}
|
||||
},
|
||||
|
||||
normalizeArticles(articles: ContentArticle[], categories: ContentCategory[]): ContentArticle[] {
|
||||
const categoryNames = new Map<string, string>()
|
||||
categories.forEach((item) => categoryNames.set(item.id, item.name))
|
||||
return articles.map((item) => ({
|
||||
...item,
|
||||
categoryName: categoryNames.get(item.categoryId || '') || '婚恋课堂',
|
||||
publishAtText: formatDate(item.publishAt || item.createdAt),
|
||||
}))
|
||||
},
|
||||
|
||||
async select(e: WechatMiniprogram.TouchEvent) {
|
||||
const categoryId = (e.currentTarget.dataset.id as string) || ''
|
||||
if (categoryId === this.data.activeCategoryId) return
|
||||
this.setData({ activeCategoryId: categoryId, loading: true, loadError: false })
|
||||
try {
|
||||
const articles = await api.get<ContentArticle[]>('/content/articles', categoryId ? { categoryId } : undefined)
|
||||
this.setData({
|
||||
articles: this.normalizeArticles(articles || [], this.data.categories),
|
||||
loading: false,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('加载课堂分类失败', error)
|
||||
this.setData({ loading: false, loadError: true })
|
||||
}
|
||||
},
|
||||
|
||||
open(e: WechatMiniprogram.TouchEvent) {
|
||||
const id = e.currentTarget.dataset.id as string
|
||||
if (id) wx.navigateTo({ url: `/pages/content-detail/content-detail?id=${id}` })
|
||||
},
|
||||
|
||||
onRetry() {
|
||||
this.loadPage()
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,87 @@
|
||||
import api from '../../utils/api'
|
||||
|
||||
interface ServiceLocation {
|
||||
id: string
|
||||
name: string
|
||||
shortName?: string
|
||||
address?: string
|
||||
contactPhone?: string
|
||||
contactPhoneDisplay?: string
|
||||
openingHoursText?: string
|
||||
services?: string[]
|
||||
latitude?: number | string
|
||||
longitude?: number | string
|
||||
}
|
||||
|
||||
interface ServiceStationPageData {
|
||||
serviceLocation: ServiceLocation | null
|
||||
loading: boolean
|
||||
loadError: boolean
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
serviceLocation: null,
|
||||
loading: true,
|
||||
loadError: false,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadStation()
|
||||
},
|
||||
|
||||
async loadStation() {
|
||||
this.setData({ loading: true, loadError: false })
|
||||
try {
|
||||
const home = await api.get<{ serviceLocation?: ServiceLocation }>('/home')
|
||||
this.setData({ serviceLocation: home.serviceLocation || null, loading: false })
|
||||
} catch (error) {
|
||||
console.error('加载服务站失败', error)
|
||||
this.setData({ loading: false, loadError: true })
|
||||
}
|
||||
},
|
||||
|
||||
call() {
|
||||
const station = this.data.serviceLocation
|
||||
if (!station) return
|
||||
const phoneNumber = station.contactPhone || station.contactPhoneDisplay || ''
|
||||
const digitCount = phoneNumber.replace(/\D/g, '').length
|
||||
if (!phoneNumber || phoneNumber.includes('*') || digitCount < 5) {
|
||||
wx.showToast({ title: '联系电话请以预约确认为准', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.makePhoneCall({ phoneNumber })
|
||||
},
|
||||
|
||||
openMap() {
|
||||
const station = this.data.serviceLocation
|
||||
if (!station) return
|
||||
const latitude = Number(station.latitude)
|
||||
const longitude = Number(station.longitude)
|
||||
if (Number.isFinite(latitude) && Number.isFinite(longitude) && latitude && longitude) {
|
||||
wx.openLocation({
|
||||
latitude,
|
||||
longitude,
|
||||
name: station.name,
|
||||
address: station.address || '',
|
||||
})
|
||||
return
|
||||
}
|
||||
if (station.address) {
|
||||
wx.setClipboardData({ data: station.address })
|
||||
return
|
||||
}
|
||||
wx.showToast({ title: '暂未提供地图位置', icon: 'none' })
|
||||
},
|
||||
|
||||
book() {
|
||||
const station = this.data.serviceLocation
|
||||
const id = station ? station.id : ''
|
||||
const query = id ? `?serviceLocationId=${encodeURIComponent(id)}` : ''
|
||||
wx.navigateTo({ url: `/pages/service-appointment/service-appointment${query}` })
|
||||
},
|
||||
|
||||
onRetry() {
|
||||
this.loadStation()
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user