refactor: 重构存储与接口适配,统一金额单位与会话管理
- 新增配置、存储、金额转换工具服务 - 按userId隔离本地缓存,替换旧设备级存储 - 统一移动端金额单位为万元,新增转换适配逻辑 - 重构认证与请求逻辑,支持真实后端会话 - 调整搜索、帮助、融资模块的模拟开关与数据适配 - 更新文档说明开发状态与配置规则
This commit is contained in:
+33
-11
@@ -1,3 +1,6 @@
|
||||
import { getUserStorage, setUserStorage } from '@/services/storage.uts'
|
||||
import { wanAmountValid, yuanToWan, wanToYuan } from './money.uts'
|
||||
|
||||
export type AssessmentForm = {
|
||||
name: string, idCard: string, phone: string, city: string, maritalStatus: string,
|
||||
occupation: string, company: string, monthlyIncome: string, socialSecurity: string,
|
||||
@@ -17,22 +20,41 @@ export function draftText(saved: UTSJSONObject, key: string): string {
|
||||
return typeof value == 'string' ? value as string : ''
|
||||
}
|
||||
export function activeAssessmentType(): string {
|
||||
const type = uni.getStorageSync('assessmentActiveType')
|
||||
const type = getUserStorage('assessmentActiveType')
|
||||
if (type == 'enterprise' || type == 'personal') return type as string
|
||||
const legacy = uni.getStorageSync('assessmentDraft')
|
||||
const legacy = getUserStorage('assessmentDraft')
|
||||
if (legacy != null && typeof legacy == 'object' && draftText(legacy as UTSJSONObject, 'type') == 'enterprise') return 'enterprise'
|
||||
return 'personal'
|
||||
}
|
||||
export function loadAssessmentDraft(type: string): UTSJSONObject | null {
|
||||
const scoped = uni.getStorageSync('assessmentDraft:' + type)
|
||||
if (scoped != null && typeof scoped == 'object') return scoped as UTSJSONObject
|
||||
const legacy = uni.getStorageSync('assessmentDraft')
|
||||
const scoped = getUserStorage('assessmentDraft:' + type)
|
||||
if (scoped != null && typeof scoped == 'object') return normalizeAssessmentDraft(scoped as UTSJSONObject)
|
||||
const legacy = getUserStorage('assessmentDraft')
|
||||
if (legacy != null && typeof legacy == 'object') {
|
||||
const saved = legacy as UTSJSONObject
|
||||
if (draftText(saved, 'type') == type) return saved
|
||||
if (draftText(saved, 'type') == type) return normalizeAssessmentDraft(saved)
|
||||
}
|
||||
return null
|
||||
}
|
||||
export function normalizeAssessmentDraft(saved: UTSJSONObject): UTSJSONObject {
|
||||
if (saved['moneyUnit'] == 'wan') return saved
|
||||
const result: UTSJSONObject = { ...saved, moneyUnit: 'wan', draftVersion: 2 }
|
||||
// 老草稿只有年营收以万元保存,其余金额均为元;只转换一次。
|
||||
const keys = ['monthlyIncome', 'totalDebtBalance', 'monthlyLoanPayment', 'creditCardTotalLimit', 'creditCardUsedLimit']
|
||||
if (saved['moneyUnit'] == 'yuan') keys.push('annualRevenue')
|
||||
keys.forEach((key) => { result[key] = yuanToWan(draftText(saved, key)) })
|
||||
return result
|
||||
}
|
||||
export function assessmentApiPayload(saved: UTSJSONObject): UTSJSONObject {
|
||||
const normalized = normalizeAssessmentDraft(saved)
|
||||
const result: UTSJSONObject = { ...normalized, moneyUnit: 'yuan' }
|
||||
const keys = ['annualRevenue', 'monthlyIncome', 'totalDebtBalance', 'monthlyLoanPayment', 'creditCardTotalLimit', 'creditCardUsedLimit']
|
||||
keys.forEach((key) => {
|
||||
const value = draftText(normalized, key)
|
||||
result[key] = value.length > 0 ? wanToYuan(value) : ''
|
||||
})
|
||||
return result
|
||||
}
|
||||
export function formFromDraft(saved: UTSJSONObject): AssessmentForm {
|
||||
return {
|
||||
name: draftText(saved, 'name'), idCard: draftText(saved, 'idCard'), phone: draftText(saved, 'phone'), city: draftText(saved, 'city'), maritalStatus: draftText(saved, 'maritalStatus'),
|
||||
@@ -59,7 +81,7 @@ export function assetValidationMessage(form: AssessmentForm): string {
|
||||
const amounts = [form.totalDebtBalance, form.monthlyLoanPayment, form.creditCardTotalLimit, form.creditCardUsedLimit]
|
||||
const amountLabels = ['欠款总余额', '贷款月还款金额', '总额度', '已使用总额度']
|
||||
for (let i = 0; i < amounts.length; i++) {
|
||||
if (amounts[i].length > 0 && !/^[0-9]{1,12}([.][0-9]{1,2})?$/.test(amounts[i])) return amountLabels[i] + '请输入有效金额,最多两位小数'
|
||||
if (amounts[i].length > 0 && !wanAmountValid(amounts[i])) return amountLabels[i] + '范围为 0–99999.999999 万元,最多六位小数'
|
||||
}
|
||||
return ''
|
||||
}
|
||||
@@ -77,7 +99,7 @@ export function saveAssessmentDraft(type: string, step: number, form: Assessment
|
||||
const files: UTSJSONObject[] = documents.map((item): UTSJSONObject => ({ name: item.name, path: item.path }))
|
||||
const grants: string[] = authorizations.filter((item) => item.selected).map((item) => item.key)
|
||||
const payload: UTSJSONObject = {
|
||||
type, step, name: form.name, idCard: form.idCard, phone: form.phone, city: form.city, maritalStatus: form.maritalStatus,
|
||||
type, step, moneyUnit: 'wan', draftVersion: 2, name: form.name, idCard: form.idCard, phone: form.phone, city: form.city, maritalStatus: form.maritalStatus,
|
||||
occupation: form.occupation, company: form.company, monthlyIncome: form.monthlyIncome, socialSecurity: form.socialSecurity, housingFund: form.housingFund,
|
||||
house: form.house, car: form.car, savings: form.savings, creditCard: form.creditCard, otherAssets: form.otherAssets,
|
||||
creditLoanCount: form.creditLoanCount, totalDebtBalance: form.totalDebtBalance, monthlyLoanPayment: form.monthlyLoanPayment,
|
||||
@@ -85,10 +107,10 @@ export function saveAssessmentDraft(type: string, step: number, form: Assessment
|
||||
enterpriseName: form.enterpriseName, businessCode: form.businessCode, annualRevenue: form.annualRevenue, operatingYears: form.operatingYears,
|
||||
documents: files, authorizations: grants, documentConsent, dataConsent
|
||||
}
|
||||
uni.setStorageSync('assessmentActiveType', type)
|
||||
uni.setStorageSync('assessmentDraft:' + type, payload)
|
||||
setUserStorage('assessmentActiveType', type)
|
||||
setUserStorage('assessmentDraft:' + type, payload)
|
||||
// 保留现有提交与档案入口读取的活动草稿。
|
||||
uni.setStorageSync('assessmentDraft', payload)
|
||||
setUserStorage('assessmentDraft', payload)
|
||||
}
|
||||
export function showAgreementNotice(title: string): void {
|
||||
uni.showModal({ title, content: '完整协议将在相关服务开放时提供。当前勾选仅保存您的选择,不会发起实名认证、查询外部数据或上传资料。', showCancel: false, confirmText: '我知道了' })
|
||||
|
||||
Reference in New Issue
Block a user