refactor: 重构存储与接口适配,统一金额单位与会话管理
- 新增配置、存储、金额转换工具服务 - 按userId隔离本地缓存,替换旧设备级存储 - 统一移动端金额单位为万元,新增转换适配逻辑 - 重构认证与请求逻辑,支持真实后端会话 - 调整搜索、帮助、融资模块的模拟开关与数据适配 - 更新文档说明开发状态与配置规则
This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
import { API_BASE_URL, wait, requestJson } from '@/services/api.uts'
|
||||
import { setUserStorage } from '@/services/storage.uts'
|
||||
import { API_DEMO_ENABLED, API_BASE_URL, wait, requestJson } from '@/services/api.uts'
|
||||
import { demoProducts, parseProduct, FinanceProduct } from './finance.uts'
|
||||
import { assessmentApiPayload } from '@/services/assessment.uts'
|
||||
export { API_BASE_URL } from '@/services/api.uts'
|
||||
|
||||
export async function submitAssessment(payload: UTSJSONObject): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
const apiPayload = assessmentApiPayload(payload)
|
||||
if (API_DEMO_ENABLED) {
|
||||
await wait(650)
|
||||
uni.setStorageSync('latestAssessment', payload)
|
||||
setUserStorage('latestAssessment', apiPayload)
|
||||
return 'ASSESSMENT-DEMO-001'
|
||||
}
|
||||
const result = await requestJson('/assessments', 'POST', payload)
|
||||
const result = await requestJson('/assessments', 'POST', apiPayload)
|
||||
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) {
|
||||
if (API_DEMO_ENABLED) {
|
||||
await wait(320)
|
||||
return demoProducts.slice()
|
||||
}
|
||||
@@ -25,7 +28,7 @@ export async function fetchMatches(): Promise<FinanceProduct[]> {
|
||||
}
|
||||
|
||||
export async function fetchProduct(id: string): Promise<FinanceProduct | null> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
if (API_DEMO_ENABLED) {
|
||||
await wait(180)
|
||||
const products = demoProducts.filter((item: FinanceProduct): boolean => item.id == id)
|
||||
return products.length > 0 ? products[0] : null
|
||||
@@ -35,7 +38,7 @@ export async function fetchProduct(id: string): Promise<FinanceProduct | null> {
|
||||
}
|
||||
|
||||
export async function sendAssistantMessage(message: string): Promise<string> {
|
||||
if (API_BASE_URL.length == 0) {
|
||||
if (API_DEMO_ENABLED) {
|
||||
await wait(600)
|
||||
return '结合您的评估结果,建议优先选择年化利率较低、可随借随还的产品,并重点确认提前还款规则。'
|
||||
}
|
||||
@@ -44,4 +47,3 @@ export async function sendAssistantMessage(message: string): Promise<string> {
|
||||
if (reply == null || reply.length == 0) throw new Error('助手暂时没有返回内容')
|
||||
return reply
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user