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
......@@ -5,10 +5,32 @@ import http from "@/api/request/http.uts";
/** 获取交付人员列表 */
export function getEmployeeList(data: UTSJSONObject): Promise<any> {
return http.post({
"method": "dj.api.smartcarlife.employee.getByMerchantId",
"projectName": "boutique",
"sceneList": [1],
...data
} as UTSJSONObject);
return http.post({
'method': 'dj.api.smartcarlife.employee.getByMerchantId',
'projectName': 'boutique',
'sceneList': [0],
...data
} 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 {
}
}
const formData = formPairs.join("&");
const hostUrl = HOST[finalHostType] as string;
uni.request({
url: `${hostUrl}${path}router?method=${requestData.method}`,
......
......@@ -3,34 +3,118 @@
* 仅支持简单对象序列化,不处理复杂嵌套
*/
function encodeValue(val: any): string {
if (val == null) {
return '';
}
const str = `${val}`;
const encoded = encodeURIComponent(str);
return encoded != null ? encoded : '';
interface StringifyOptions {
prefix?: string
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)
}
}
}
return values.join('&')
}
/**
* 将对象序列化为 query string
* @param obj 要序列化的对象
* @param encodeValuesOnly 是否只编码值(key 不编码)
* @param options 配置选项
* @returns 序列化后的字符串,如 "key1=val1&key2=val2"
*/
export function stringify(obj: UTSJSONObject, encodeValuesOnly: boolean = true): string {
const pairs: string[] = [];
for (const key in obj) {
const val = obj[key];
if (val == null) {
continue;
}
const keyStr = encodeValuesOnly ? key : encodeURIComponent(key);
const valStr = encodeValue(val);
pairs.push(`${keyStr}=${valStr}`);
}
return pairs.join('&');
}
export function stringify(
obj: UTSJSONObject,
options: StringifyOptions = {}
): string {
return stringifyRecursive(obj, options)
}
\ No newline at end of file
......@@ -16,8 +16,12 @@ import { stringify as qsStringify } from "./qs.uts";
export function sign(params: UTSJSONObject, secret: string, noSignAttr: string[] = []): UTSJSONObject {
// 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('&') 拆开
const objVal = objStr.split('&');
......
......@@ -78,3 +78,194 @@ export function getBoutiqueMockData(immediate: boolean = false): Promise<UTSJSON
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 @@
"navigationStyle": "custom",
"navigationBarTitleText": "个人考勤"
}
},
{
"path":"pages/equity/detail/index",
"style": {
"navigationStyle": "custom"
}
}
],
"easycom": {
......
<template>
<!-- #ifdef APP -->
<layout-root>
<!-- #endif -->
<view class="page-container">
<home-frame ref="homeRef" :showFooter="true">
<template #home>
<view class="home-content">
<view class="header">
<text class="title">会员权益场景</text>
<text class="subtitle">Member Equity</text>
</view>
<view class="action-area">
<view class="start-btn" @click="handleStart">
<text class="btn-text">开始接待</text>
<!-- #endif -->
<view class="page-container">
<home-frame ref="homeRef" :showFooter="true">
<template #home>
<view class="home-content">
<view class="header">
<text class="title">
会员权益场景
</text>
<text class="subtitle">
Member Equity
</text>
</view>
<view class="action-area">
<view class="start-btn" @click="handleStart">
<text class="btn-text">
开始接待
</text>
</view>
</view>
</view>
</view>
</template>
<template #detail>
<view class="detail-content">
<text class="detail-title">详情页</text>
</view>
</template>
</home-frame>
</view>
<!-- #ifdef APP -->
</template>
<template #detail>
<view class="detail-content">
</view>
</template>
</home-frame>
</view>
<!-- #ifdef APP -->
</layout-root>
<!-- #endif -->
</template>
<script setup lang="uts">
import { ref, ComponentPublicInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { storage } from '@/utils/storage.uts'
import HomeFrame from '@/components/HomeFrame/index.uvue'
const homeRef = ref(null)
function handleStart(): void {
uni.showToast({
title: '开始接待',
icon: 'success'
})
}
import { ref, ComponentPublicInstance } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { storage } from '@/utils/storage.uts'
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 detailRef = ref(null)
const loadComplete = ref<boolean>(false)
const moduleList = ref<Array<any>>([])
const toolList = ref<Array<any>>([])
const mediaId = ref<string | number>('')
onLoad((options: OnLoadOptions) => {
uni.hideLoading()
})
onShow(() => {
const userInfo = storage.get('userInfo')
if (userInfo == null) {
storage.remove('userInfo')
storage.remove('sessionId')
uni.reLaunch({ url: '/pages/common/login' })
return
function setViewInfo(data: any): void {
const { moduleList: dataModuleList, toolList: dataToolList, id: dataId } = data as UTSJSONObject
moduleList.value = dataModuleList
toolList.value = dataToolList
mediaId.value = dataId
loadComplete.value = true
store.state.user = {
...store.state.user,
...data
}
}
const userInfoObj = userInfo as UTSJSONObject
const shopMerchantId = userInfoObj['shopMerchantId'] as string | null
const shopMerchantName = userInfoObj['shopMerchantName'] as string | null
if (shopMerchantId == null || shopMerchantId == '' || shopMerchantName == null || shopMerchantName == '') {
storage.remove('userInfo')
storage.remove('sessionId')
uni.reLaunch({ url: '/pages/common/login' })
return
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` })
}
if (homeRef.value != null) {
(homeRef.value as ComponentPublicInstance).$callMethod('updateApp')
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)
}
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()
})
onShow(() => {
const userInfo = storage.get('userInfo')
if (userInfo == null) {
storage.remove('userInfo')
storage.remove('sessionId')
uni.reLaunch({ url: '/pages/common/login' })
return
}
const userInfoObj = userInfo as UTSJSONObject
const shopMerchantId = userInfoObj['shopMerchantId'] as string | null
const shopMerchantName = userInfoObj['shopMerchantName'] as string | null
if (shopMerchantId == null || shopMerchantId == '' || shopMerchantName == null || shopMerchantName == '') {
storage.remove('userInfo')
storage.remove('sessionId')
uni.reLaunch({ url: '/pages/common/login' })
return
}
if (homeRef.value != null) {
(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>
<style scoped lang="scss">
......
......@@ -23,7 +23,7 @@ export default defineConfig({
},
server: {
port: 9900,
port: 8080,
proxy
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!