Commit dab046f4 by 李伟康

feat(api): 新增权益模块功能并优化API请求

- 修改getEmployeeList方法中sceneList参数从[1]改为[0]
- 新增getMerchantCarBrandList函数用于获取门店主营车品牌
- 新增getCarBrandsListApi函数用于获取车型数据
- 重构qs.uts中的stringify方法,支持更完整的查询字符串序列化选项
- 在sign.uts中更新签名逻辑,添加arrayFormat和allowDots配置
- 移除http.uts中的多余空行
- 新增权益相关API函数:getEquityMaterialId、getEquityMaterialConfig等
- 添加getSoureData函数处理素材数据获取逻辑
- 实现图片转base64功能
- 更新equity页面路由配置
- 重构equity/detail页面,使用store状态管理替代props传递
- 添加权益首页逻辑,实现素材数据获取和展示
- 添加车型品牌列表获取功能
- 修改开发服务器端口从9900到8080
1 parent a0bca4af
...@@ -6,9 +6,31 @@ import http from "@/api/request/http.uts"; ...@@ -6,9 +6,31 @@ import http from "@/api/request/http.uts";
/** 获取交付人员列表 */ /** 获取交付人员列表 */
export function getEmployeeList(data: UTSJSONObject): Promise<any> { export function getEmployeeList(data: UTSJSONObject): Promise<any> {
return http.post({ return http.post({
"method": "dj.api.smartcarlife.employee.getByMerchantId", 'method': 'dj.api.smartcarlife.employee.getByMerchantId',
"projectName": "boutique", 'projectName': 'boutique',
"sceneList": [1], 'sceneList': [0],
...data ...data
} as UTSJSONObject); } as UTSJSONObject)
}
/** 获取门店主营车品牌 */
export function getMerchantCarBrandList(merchantIdList: Array<string | number>): Promise<any> {
return http.post({
method: 'merchants.api.open.merchant.info',
projectName: 'merchants',
merchantIdList: merchantIdList,
merchantInfoSwitch: {
brandFlag: true
}
} as UTSJSONObject, false, 'merchant')
}
/**
* 车型
*/
export function getCarBrandsListApi(data: UTSJSONObject): Promise<any> {
return http.post({
method: 'scrm.api.carlife.common.getCarSeriesList',
...data
} as UTSJSONObject, false, 'scrm')
} }
...@@ -180,7 +180,6 @@ class Request { ...@@ -180,7 +180,6 @@ class Request {
} }
} }
const formData = formPairs.join("&"); const formData = formPairs.join("&");
const hostUrl = HOST[finalHostType] as string; const hostUrl = HOST[finalHostType] as string;
uni.request({ uni.request({
url: `${hostUrl}${path}router?method=${requestData.method}`, url: `${hostUrl}${path}router?method=${requestData.method}`,
......
...@@ -3,34 +3,118 @@ ...@@ -3,34 +3,118 @@
* 仅支持简单对象序列化,不处理复杂嵌套 * 仅支持简单对象序列化,不处理复杂嵌套
*/ */
function encodeValue(val: any): string { interface StringifyOptions {
if (val == null) { prefix?: string
return ''; encoder?: Function
filter?: Function | Array<string>
sort?: Function
strictNullHandling?: boolean
skipNulls?: boolean
encodeValuesOnly?: boolean
generateArrayPrefix?: Function
allowDots?: boolean
serializeDate?: Function
formatter?: Function
}
function stringifyRecursive(
obj: any,
options: StringifyOptions = {}
): string {
const prefix = options.prefix ?? ''
const encoder = options.encoder || encodeURIComponent
const filter = options.filter
const sort = options.sort
const strictNullHandling = options.strictNullHandling ?? false
const skipNulls = options.skipNulls ?? false
const encodeValuesOnly = options.encodeValuesOnly ?? false
const generateArrayPrefix = options.generateArrayPrefix || ((p: string, k: string) => `${p}[${k}]`)
const allowDots = options.allowDots ?? false
const formatter = options.formatter || ((str: string) => str)
const serializeDate = options.serializeDate || ((date: Date) => date.toISOString())
let processedObj: any = obj
if (typeof filter === 'function') {
processedObj = filter(prefix, obj)
} else if (obj instanceof Date) {
processedObj = serializeDate(obj)
} else if (obj === null) {
if (strictNullHandling) {
return encoder && !encodeValuesOnly ? encoder(prefix) : prefix
}
processedObj = ''
}
if (typeof processedObj === 'string' ||
typeof processedObj === 'number' ||
typeof processedObj === 'boolean') {
if (encoder) {
const keyValue = encodeValuesOnly ? prefix : encoder(prefix)
return `${formatter(keyValue)}=${formatter(encoder(processedObj))}`
}
return `${formatter(prefix)}=${formatter(String(processedObj))}`
}
const values: Array<string> = []
if (typeof processedObj === 'undefined') {
return ''
}
let objKeys: Array<string> = []
if (Array.isArray(filter)) {
objKeys = filter as Array<string>
} else {
const keys = Object.keys(processedObj)
objKeys = sort ? keys.sort(sort) : keys
}
for (let i = 0; i < objKeys.length; i++) {
const key = objKeys[i]
if (skipNulls && processedObj[key] === null) {
continue
}
if (Array.isArray(processedObj)) {
const result = stringifyRecursive(
processedObj[key],
{
...options,
prefix: prefix ? generateArrayPrefix(prefix, key) : key
}
)
if (result) {
values.push(result)
}
} else {
const result = stringifyRecursive(
processedObj[key],
{
...options,
prefix: prefix ? prefix + (allowDots ? '.' + key : '[' + key + ']') : key
}
)
if (result) {
values.push(result)
}
} }
const str = `${val}`; }
const encoded = encodeURIComponent(str);
return encoded != null ? encoded : ''; return values.join('&')
} }
/** /**
* 将对象序列化为 query string * 将对象序列化为 query string
* @param obj 要序列化的对象 * @param obj 要序列化的对象
* @param encodeValuesOnly 是否只编码值(key 不编码) * @param options 配置选项
* @returns 序列化后的字符串,如 "key1=val1&key2=val2" * @returns 序列化后的字符串,如 "key1=val1&key2=val2"
*/ */
export function stringify(obj: UTSJSONObject, encodeValuesOnly: boolean = true): string { export function stringify(
const pairs: string[] = []; obj: UTSJSONObject,
options: StringifyOptions = {}
for (const key in obj) { ): string {
const val = obj[key]; return stringifyRecursive(obj, options)
if (val == null) {
continue;
}
const keyStr = encodeValuesOnly ? key : encodeURIComponent(key);
const valStr = encodeValue(val);
pairs.push(`${keyStr}=${valStr}`);
}
return pairs.join('&');
} }
\ No newline at end of file \ No newline at end of file
...@@ -16,8 +16,12 @@ import { stringify as qsStringify } from "./qs.uts"; ...@@ -16,8 +16,12 @@ import { stringify as qsStringify } from "./qs.uts";
export function sign(params: UTSJSONObject, secret: string, noSignAttr: string[] = []): UTSJSONObject { export function sign(params: UTSJSONObject, secret: string, noSignAttr: string[] = []): UTSJSONObject {
// 1. 用 qs.stringify 序列化(encodeValuesOnly: true) // 1. 用 qs.stringify 序列化(encodeValuesOnly: true)
const objStr = qsStringify(params, true); const objStr = qsStringify(params,{
arrayFormat: 'indices',
allowDots: true,
encodeValuesOnly: true
});
console.log(objStr,'===')
// 2. split('&') 拆开 // 2. split('&') 拆开
const objVal = objStr.split('&'); const objVal = objStr.split('&');
......
...@@ -78,3 +78,194 @@ export function getBoutiqueMockData(immediate: boolean = false): Promise<UTSJSON ...@@ -78,3 +78,194 @@ export function getBoutiqueMockData(immediate: boolean = false): Promise<UTSJSON
return fallback return fallback
}) })
} }
/**
* 获取后台延保素材ID
*/
export function getEquityMaterialId(data: UTSJSONObject): Promise<any> {
return http.post({
method: 'dj.api.smartcarlife.reception.home.page.material.view',
projectName: 'boutique',
...data
} as UTSJSONObject)
}
/**
* 获取后台延保素材配置
*/
export function getEquityMaterialConfig(data: UTSJSONObject): Promise<any> {
return http.post({
method: 'dj.api.car.boutique.reception.home.page.entrance.material.detail',
projectName: 'boutique',
...data
} as UTSJSONObject)
}
/**
* 权益配置
*/
export function findReceptionpriproConfigList(data: UTSJSONObject): Promise<any> {
return http.post({
method: 'dj.api.smartcarlife.recepiton.customer.findReceptionpriproConfigList',
projectName: 'boutique',
...data
} as UTSJSONObject)
}
/**获取素材配置 */
export async function getSoureData(
shopMerchantId: string | number,
sceneType: string | number,
params: UTSJSONObject = {}
): Promise<any> {
try {
const res = await getEquityMaterialId({
merchantId: shopMerchantId,
...params
})
if (res && res.id) {
console.log(res.id, 'res.idres.idres.idres.id')
let data = await getEquityMaterialConfig({
id: res.id
})
if (data) {
let { toolList, materialInfoList } = data
let storageName = `source_${sceneType}_${shopMerchantId}`
if (params.brandId && params.subBrandId) {
storageName += `_${params.brandId}_${params.subBrandId}`
}
const insurance = materialInfoList.find(e => e.componentName == 'insurance')
const hasEquity = toolList.find(e => e.id == insurance?.id)
if (insurance && hasEquity) {
let configList
try {
configList = await findReceptionpriproConfigList({})
storage.set('findReceptionpriproConfigList', configList)
} catch (error) {
configList = storage.get('findReceptionpriproConfigList')
}
const toolOtherList = configList.map(i => {
return {
id: hasEquity.id + 100 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
} as UTSJSONObject
})
toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
return {
id: hasEquity.id + 100 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList,
hide: true,
detailTitle: i.productName,
thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp'
} as UTSJSONObject
})
materialInfoList = materialInfoList.concat(moduleOtherList)
}
data.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
data.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
uni.setStorageSync(storageName, {
moduleList: data.moduleList,
toolList: data.toolList,
id: res.id
})
return Promise.resolve(data)
} else {
throw new Error('获取数据失败')
}
} else {
throw new Error('未找到素材 ID')
}
} catch (error) {
uni.hideLoading()
if (error) {
uni.showToast({
title: `${error}`,
icon: 'none',
duration: 2000
})
}
return Promise.reject(error)
}
}
/**批量图片转 base64 */
async function imgTransformBase64(imgList: Array<any> = [], keyList: string[]): Promise<Array<any>> {
return await Promise.all(
imgList.map(async e => {
await Promise.all(
Object.keys(e).map(async key => {
if (keyList.includes(key)) {
const isArray = Array.isArray(e[key])
if (isArray) {
await Promise.all(
e[key].map(async i => {
await Promise.all(
Object.keys(i).map(async k => {
if (k == 'detailUrl' && i[k]) {
i[k] = await getBase64(i[k])
}
})
)
})
)
} else {
if (typeof e[key] === 'string' && e[key]) {
e[key] = await getBase64(e[key])
}
if (e[key] && typeof e[key] === 'object') {
await Promise.all(
Object.keys(e[key]).map(async k => {
if (e[key][k]) {
e[key][k] = await getBase64(e[key][k])
}
})
)
}
}
}
})
)
return e
})
)
}
/**转 base64 */
async function getBase64(url: string): Promise<string> {
return new Promise((resolve, reject) => {
uni.request({
url,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data as ArrayBuffer)}`
resolve(base64)
},
fail: err => {
resolve(url)
}
})
})
}
...@@ -57,6 +57,12 @@ ...@@ -57,6 +57,12 @@
"navigationStyle": "custom", "navigationStyle": "custom",
"navigationBarTitleText": "个人考勤" "navigationBarTitleText": "个人考勤"
} }
},
{
"path":"pages/equity/detail/index",
"style": {
"navigationStyle": "custom"
}
} }
], ],
"easycom": { "easycom": {
......
...@@ -7,13 +7,19 @@ ...@@ -7,13 +7,19 @@
<template #home> <template #home>
<view class="home-content"> <view class="home-content">
<view class="header"> <view class="header">
<text class="title">会员权益场景</text> <text class="title">
<text class="subtitle">Member Equity</text> 会员权益场景
</text>
<text class="subtitle">
Member Equity
</text>
</view> </view>
<view class="action-area"> <view class="action-area">
<view class="start-btn" @click="handleStart"> <view class="start-btn" @click="handleStart">
<text class="btn-text">开始接待</text> <text class="btn-text">
开始接待
</text>
</view> </view>
</view> </view>
</view> </view>
...@@ -21,7 +27,6 @@ ...@@ -21,7 +27,6 @@
<template #detail> <template #detail>
<view class="detail-content"> <view class="detail-content">
<text class="detail-title">详情页</text>
</view> </view>
</template> </template>
</home-frame> </home-frame>
...@@ -32,25 +37,108 @@ ...@@ -32,25 +37,108 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref, ComponentPublicInstance } from 'vue' import { ref, ComponentPublicInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app' import { onLoad, onShow } from '@dcloudio/uni-app'
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import HomeFrame from '@/components/HomeFrame/index.uvue' import { store } from "@/store/index.uts";
import HomeFrame from '@/components/HomeFrame/index.uvue'
import { getMerchantCarBrandList, getEmployeeList , getCarBrandsListApi } from '@/api/common-api.uts'
import { getSoureData } from '@/api/system-api.uts'
const homeRef = ref(null) const homeRef = ref(null)
const detailRef = ref(null)
const loadComplete = ref<boolean>(false)
const moduleList = ref<Array<any>>([])
const toolList = ref<Array<any>>([])
const mediaId = ref<string | number>('')
function handleStart(): void { function setViewInfo(data: any): void {
uni.showToast({ const { moduleList: dataModuleList, toolList: dataToolList, id: dataId } = data as UTSJSONObject
title: '开始接待', moduleList.value = dataModuleList
icon: 'success' toolList.value = dataToolList
mediaId.value = dataId
loadComplete.value = true
store.state.user = {
...store.state.user,
...data
}
}
function handleStart(): void {
const currentModuleList = moduleList.value
if (!currentModuleList.length) {
return uni.showToast({
title: '该场景尚未配置素材,请联系总部人员',
icon: 'none'
}) })
} }
const firstId = currentModuleList[0].id
uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` })
}
function get_Vehicle_Sales_Data(): void {
const userInfo = storage.get('userInfo'),
storageCarBrandList = storage.get('carBrandList'),
storageEmployeeList = storage.get('employeeList'),
{shopMerchantId} = userInfo
getMerchantCarBrandList([shopMerchantId]).then(({data}) => {
let list = data[0].carBrandList,
carBrandList = [],
brandIdList = [],
subBrandIdList = []
list?.map(e => {
e.childs.map(i => {
i.brandName = e.name
i.brandId = e.id
carBrandList.push(i)
subBrandIdList.push(i.id)
})
brandIdList.push(e.id)
})
getSoure(brandIdList, subBrandIdList)
store.dispatch('setCarBrandsList', carBrandList)
storage.set('carBrandList', carBrandList)
if (carBrandList.length) {
let index = 0
getCarBrandsList(carBrandList, index)
}
})
}
async function getSoure(brandIdList: string[], subBrandIdList: string[]): Promise<void> {
const userInfo = storage.get('userInfo')
const { shopMerchantId, sceneType } = userInfo as UTSJSONObject
const storageKey = `source_${sceneType}_${shopMerchantId}`
const data = uni.getStorageSync(storageKey)
if (data) {
setViewInfo(data)
}
onLoad((options: OnLoadOptions) => { try {
const requestData = await getSoureData(shopMerchantId, sceneType, {
brandIdList: brandIdList,
subBrandIdList: subBrandIdList
})
if (requestData) {
setViewInfo(requestData)
} else {
loadComplete.value = true
}
} catch (error) {
console.error('获取数据失败:', error)
loadComplete.value = true
}
}
onLoad((options: OnLoadOptions) => {
get_Vehicle_Sales_Data()
uni.hideLoading() uni.hideLoading()
}) })
onShow(() => { onShow(() => {
const userInfo = storage.get('userInfo') const userInfo = storage.get('userInfo')
if (userInfo == null) { if (userInfo == null) {
storage.remove('userInfo') storage.remove('userInfo')
...@@ -73,7 +161,33 @@ onShow(() => { ...@@ -73,7 +161,33 @@ onShow(() => {
if (homeRef.value != null) { if (homeRef.value != null) {
(homeRef.value as ComponentPublicInstance).$callMethod('updateApp') (homeRef.value as ComponentPublicInstance).$callMethod('updateApp')
} }
}) })
/**按序加载车型 */
async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index]
if (!item) return
const storageKey = `${item.id}_${item.brandId}_carlist`
const carList = uni.getStorageSync(storageKey)
if (index < carBrandList.length - 1) {
const nextIndex = index + 1
if (!carList) {
const list = await getCarBrandsListApi({
brandId: item.brandId,
childBrandId: item.id
})
if (list) {
uni.setStorageSync(storageKey, list)
}
getCarBrandsList(carBrandList, nextIndex)
} else {
getCarBrandsList(carBrandList, nextIndex)
}
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
......
...@@ -23,7 +23,7 @@ export default defineConfig({ ...@@ -23,7 +23,7 @@ export default defineConfig({
}, },
server: { server: {
port: 9900, port: 8080,
proxy proxy
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!