refactor: 重构项目分包结构与资源管理
1. 调整页面路由,将业务页面迁移到对应分包,主包仅保留首页 2. 拆分公共服务模块,将账户、融资相关逻辑移入对应分包 3. 统一资源路径,将专属静态资源放入各分包static目录,更新导航栏图标资源 4. 修复启动引导逻辑,实现仅首次冷启动显示引导页 5. 更新README文档,补充分包配置与开发规范说明
This commit is contained in:
+2
-78
@@ -1,5 +1,4 @@
|
||||
/** Mobile API adapter with deterministic local mocks. */
|
||||
import { demoProducts, parseProduct, FinanceProduct } from '@/services/finance.uts'
|
||||
/** Shared request, configuration and session infrastructure. */
|
||||
export const API_BASE_URL = ''
|
||||
const REQUEST_TIMEOUT = 10000
|
||||
const SESSION_KEY = 'aiFinanceSession'
|
||||
@@ -54,79 +53,4 @@ const requestJson = (path: string, method: RequestMethod, payload: UTSJSONObject
|
||||
})
|
||||
}
|
||||
|
||||
export async function requestSmsCode(phone: string): Promise<boolean> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(350)
|
||||
return phone.length == 11
|
||||
}
|
||||
await requestJson('/auth/sms-code', 'POST', { phone })
|
||||
return true
|
||||
}
|
||||
|
||||
export async function loginWithSms(phone: string, code: string): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(300)
|
||||
if (code.length != 6) throw new Error('验证码应为 6 位数字')
|
||||
return 'demo-sms-token'
|
||||
}
|
||||
const result = await requestJson('/auth/sms-login', 'POST', { phone, code })
|
||||
const token = result['token'] as string | null
|
||||
if (token == null || token.length == 0) throw new Error('登录响应缺少 token')
|
||||
return token
|
||||
}
|
||||
|
||||
export async function loginWithPassword(phone: string, password: string): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(300)
|
||||
return 'demo-password-token'
|
||||
}
|
||||
const result = await requestJson('/auth/password-login', 'POST', { phone, password })
|
||||
const token = result['token'] as string | null
|
||||
if (token == null || token.length == 0) throw new Error('登录响应缺少 token')
|
||||
return token
|
||||
}
|
||||
|
||||
export async function submitAssessment(payload: UTSJSONObject): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(650)
|
||||
uni.setStorageSync('latestAssessment', payload)
|
||||
return 'ASSESSMENT-DEMO-001'
|
||||
}
|
||||
const result = await requestJson('/assessments', 'POST', payload)
|
||||
const id = result['id'] as string | null
|
||||
if (id == null || id.length == 0) throw new Error('评估提交成功但未返回编号')
|
||||
return id
|
||||
}
|
||||
|
||||
export async function fetchMatches(): Promise<FinanceProduct[]> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(320)
|
||||
return demoProducts.slice()
|
||||
}
|
||||
const result = await requestJson('/matches', 'GET', new UTSJSONObject())
|
||||
const items = result['items'] as UTSJSONObject[] | null
|
||||
return items == null ? [] : items.map((item: UTSJSONObject): FinanceProduct => parseProduct(item))
|
||||
}
|
||||
|
||||
export async function fetchProduct(id: string): Promise<FinanceProduct | null> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(180)
|
||||
const products = demoProducts.filter((item: FinanceProduct): boolean => item.id == id)
|
||||
return products.length > 0 ? products[0] : null
|
||||
}
|
||||
const result = await requestJson('/products/' + encodeURIComponent(id), 'GET', new UTSJSONObject())
|
||||
return parseProduct(result)
|
||||
}
|
||||
|
||||
export async function sendAssistantMessage(message: string): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
await wait(600)
|
||||
return '结合您的评估结果,建议优先选择年化利率较低、可随借随还的产品,并重点确认提前还款规则。'
|
||||
}
|
||||
const result = await requestJson('/assistant/messages', 'POST', { message })
|
||||
const reply = result['reply'] as string | null
|
||||
if (reply == null || reply.length == 0) throw new Error('助手暂时没有返回内容')
|
||||
return reply
|
||||
}
|
||||
|
||||
export { apiMessage }
|
||||
export { apiMessage, requestJson, wait }
|
||||
|
||||
Reference in New Issue
Block a user