移除系统配置获取金额
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
import { getSystemConfig } from '@/config/api/system.js'
|
||||
|
||||
/** 系统配置项 key(与后台一致) */
|
||||
export const DANA_TOTAL_CONFIG_KEY = 'overseas_payment_dana_total'
|
||||
export const DANA_SINGLE_CONFIG_KEY = 'overseas_payment_dana_single'
|
||||
|
||||
/** 本地缓存 key */
|
||||
export const DANA_TOTAL_STORAGE_KEY = 'danaPaymentTotal'
|
||||
export const DANA_SINGLE_STORAGE_KEY = 'danaPaymentSingle'
|
||||
|
||||
/** 写入缓存的金额结构(与业务侧约定一致) */
|
||||
const wrapStorageNumber = (n) => ({ type: 'number', data: n })
|
||||
|
||||
/**
|
||||
* 从本地缓存读取 DANA 金额;兼容 { type, data }、JSON 字符串、纯数字。
|
||||
*/
|
||||
export function parseDanaStorageNumber(raw) {
|
||||
if (raw === null || raw === undefined || raw === '') return null
|
||||
let value = raw
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim()
|
||||
if (trimmed.startsWith('{')) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed)
|
||||
if (parsed && typeof parsed === 'object' && 'data' in parsed) {
|
||||
value = parsed.data
|
||||
} else {
|
||||
value = parsed
|
||||
}
|
||||
} catch {
|
||||
value = raw
|
||||
}
|
||||
}
|
||||
} else if (typeof raw === 'object' && raw !== null && 'data' in raw) {
|
||||
value = raw.data
|
||||
}
|
||||
const num = Number(value)
|
||||
return Number.isFinite(num) ? num : null
|
||||
}
|
||||
|
||||
const parseConfigNumber = (rawValue) => {
|
||||
if (rawValue === null || rawValue === undefined) return null
|
||||
const cleaned = String(rawValue).replace(/[^0-9.]/g, '')
|
||||
if (!cleaned) return null
|
||||
const num = Number(cleaned)
|
||||
return Number.isFinite(num) ? num : null
|
||||
}
|
||||
|
||||
const extractConfigValue = (res, configKey) => {
|
||||
if (!res || res.code !== 200) return null
|
||||
const row = (res.rows || []).find((item) => item && item.configKey === configKey)
|
||||
if (row && row.configValue !== undefined) return row.configValue
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取 DANA 预扣款 / 单次扣款配置并写入本地缓存。
|
||||
* 用于首页及「直达」设备详情、订单详情、支付页等场景,避免仅依赖首页拉取。
|
||||
*/
|
||||
export async function fetchAndCacheDanaPaymentConfig() {
|
||||
const [totalRes, singleRes] = await Promise.all([
|
||||
getSystemConfig({ configKey: DANA_TOTAL_CONFIG_KEY }),
|
||||
getSystemConfig({ configKey: DANA_SINGLE_CONFIG_KEY })
|
||||
])
|
||||
|
||||
const totalRaw = extractConfigValue(totalRes, DANA_TOTAL_CONFIG_KEY)
|
||||
const singleRaw = extractConfigValue(singleRes, DANA_SINGLE_CONFIG_KEY)
|
||||
const totalValue = parseConfigNumber(totalRaw)
|
||||
const singleValue = parseConfigNumber(singleRaw)
|
||||
|
||||
if (totalValue !== null) {
|
||||
uni.setStorageSync(DANA_TOTAL_STORAGE_KEY, wrapStorageNumber(totalValue))
|
||||
}
|
||||
if (singleValue !== null) {
|
||||
uni.setStorageSync(DANA_SINGLE_STORAGE_KEY, wrapStorageNumber(singleValue))
|
||||
}
|
||||
|
||||
return { totalValue, singleValue }
|
||||
}
|
||||
Reference in New Issue
Block a user