Commit 63a4e10e by 李伟康

素材增加配置服务

1 parent f14b531e
...@@ -6,32 +6,16 @@ const serverConfig = { ...@@ -6,32 +6,16 @@ const serverConfig = {
mockTimer: {}, mockTimer: {},
mockCache: null mockCache: null
}, },
bydServerConfig = {
mockRequestCount: null,
mockTimer: {},
mockCache: null
},
boutiqueServerConfig = { boutiqueServerConfig = {
mockRequestCount: null, mockRequestCount: null,
mockTimer: {}, mockTimer: {},
mockCache: null mockCache: null
}, },
jihuServerConfig = {
mockRequestCount: null,
mockTimer: {},
mockCache: null
},
configModule = 'app-tape', configModule = 'app-tape',
bydConfigModule = 'byd-pad-config',
boutiqueConfigModule = 'boutique-pad-config', boutiqueConfigModule = 'boutique-pad-config',
jihuConfigModule = 'jihu-pad-config',
configUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${configModule}&env=${env}`, configUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${configModule}&env=${env}`,
bydConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${bydConfigModule}&env=${env}`, boutiqueConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${boutiqueConfigModule}&env=${env}`
boutiqueConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${boutiqueConfigModule}&env=${env}`, /**获取APP配置 */
jihuConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${jihuConfigModule}&env=${env}`
/**获取mock数据 */
const getMockData = async (immediate = false) => { const getMockData = async (immediate = false) => {
const MOCKDATA = uni.$storage.get('mock_data') const MOCKDATA = uni.$storage.get('mock_data')
try { try {
...@@ -43,8 +27,6 @@ const getMockData = async (immediate = false) => { ...@@ -43,8 +27,6 @@ const getMockData = async (immediate = false) => {
serverConfig.mockRequestCount = Date.now() serverConfig.mockRequestCount = Date.now()
const data = await http.uni_request({ url: configUrl }) const data = await http.uni_request({ url: configUrl })
data.createTime = Date.now() data.createTime = Date.now()
data.moduleList = await imgToBase64(data.moduleList, 'thumbnail')
data.default_moduleList = await imgToBase64(data.default_moduleList, 'thumbnail')
serverConfig.mockCache = data serverConfig.mockCache = data
uni.$storage.set('mock_data', data) uni.$storage.set('mock_data', data)
return Promise.resolve(data) return Promise.resolve(data)
...@@ -68,98 +50,6 @@ const getMockData = async (immediate = false) => { ...@@ -68,98 +50,6 @@ const getMockData = async (immediate = false) => {
return Promise.reject(error) return Promise.reject(error)
} }
} }
const imgToBase64 = (list, urlKey, isArray = true) => {
return new Promise((resolve, reject) => {
let arr = [],
newList = JSON.parse(JSON.stringify(list))
if (isArray) {
list.map((e, index) => {
if (!e[urlKey]) return resolve(list)
if (!e[urlKey].startsWith('https')) return resolve(list)
uni.request({
url: urlKey ? e[urlKey] : e,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`
newList[index][urlKey] = base64
newList[index][`original_${urlKey}`] = e[urlKey]
arr.push(e)
if (arr.length === list.length) resolve(newList)
},
fail: err => {
reject(err)
}
})
})
} else {
Object.keys(list).map(key => {
if (!list[key].startsWith('https')) return resolve(list)
uni.request({
url: list[key],
method: 'GET',
responseType: 'arraybuffer',
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`
newList[key] = base64
arr.push(key)
if (arr.length === Object.keys(list).length) resolve(newList)
},
fail: err => {
reject(err)
}
})
})
}
})
}
const updateMockData = (dataList, keyList, storageName = 'mock_data') => {
const mockData = uni.$storage.get(storageName)
keyList.map(key => {
mockData[key] = dataList[key]
})
setTimeout(() => {
uni.$storage.set(storageName, mockData)
}, 1e3)
}
/**
*获取比亚迪配置
*/
const getBydMockData = async (immediate = false) => {
const MOCKDATA = uni.$storage.get('byd_mock_data')
try {
if (!immediate && MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
return Promise.resolve(MOCKDATA)
} else {
if (!bydServerConfig.mockRequestCount || immediate) {
bydServerConfig.mockCache = null
bydServerConfig.mockRequestCount = Date.now()
const data = await http.uni_request({ url: bydConfigUrl })
data.createTime = Date.now()
data.moduleList = await imgToBase64(data.moduleList, 'thumbnail')
bydServerConfig.mockCache = data
uni.$storage.set('byd_mock_data', data)
return Promise.resolve(data)
} else {
const key = Date.now()
return new Promise(resolve => {
bydServerConfig.mockTimer[key] = setInterval(() => {
if (bydServerConfig.mockCache) {
clearInterval(bydServerConfig.mockTimer[key])
bydServerConfig.mockRequestCount = null
resolve(bydServerConfig.mockCache)
}
}, 1e3)
})
}
}
} catch (error) {
console.log(error)
if (bydServerConfig.mockTimer[key]) clearInterval(bydServerConfig.mockTimer[key])
bydServerConfig.mockRequestCount = null
return Promise.reject(error)
}
}
/** /**
*获取后台素材配置 *获取后台素材配置
*/ */
...@@ -207,56 +97,128 @@ const getBoutiqueMockData = async (immediate = false) => { ...@@ -207,56 +97,128 @@ const getBoutiqueMockData = async (immediate = false) => {
return Promise.reject(error) return Promise.reject(error)
} }
} }
/**
*获取极狐配置
*/
const getJihuMockData = async (immediate = false) => {
const MOCKDATA = uni.$storage.get('jihu_mock_data')
try {
if (!immediate && MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
return Promise.resolve(MOCKDATA)
} else {
if (!jihuServerConfig.mockRequestCount || immediate) {
jihuServerConfig.mockCache = null
jihuServerConfig.mockRequestCount = Date.now()
const data = await http.uni_request({ url: jihuConfigUrl })
data.createTime = Date.now()
data.moduleList = await imgToBase64(data.moduleList, 'thumbnail')
jihuServerConfig.mockCache = data
uni.$storage.set('jihu_mock_data', data)
return Promise.resolve(data)
} else {
const key = Date.now()
return new Promise(resolve => {
jihuServerConfig.mockTimer[key] = setInterval(() => {
if (jihuServerConfig.mockCache) {
clearInterval(jihuServerConfig.mockTimer[key])
jihuServerConfig.mockRequestCount = null
resolve(jihuServerConfig.mockCache)
}
}, 1e3)
})
}
}
} catch (error) {
if (jihuServerConfig.mockTimer[key]) clearInterval(jihuServerConfig.mockTimer[key])
jihuServerConfig.mockRequestCount = null
return Promise.reject(error)
}
}
// 图片版本号 // 图片版本号
const getImageVersion = async () => { const getImageVersion = async () => {
const accountInfo = await getMockData() const accountInfo = await getMockData()
return accountInfo?.version || Date.now() return accountInfo?.version || Date.now()
} }
/**获取延保素材配置 */
const getSoureData = async (channelType = 1, shopMerchantId) => {
const appConfigUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=app-config-url&env=${env}`,
{ brandIds, merchantIds, caseCenterIds } = await http.uni_request({ url: appConfigUrl })
let targetUrl,
storageName = 'source_data_'
if (merchantIds.hasOwnProperty(shopMerchantId)) {
targetUrl = `${merchantIds[shopMerchantId]}&env=${env}`
storageName += `merchantId_${shopMerchantId}`
}
else {
targetUrl = `${brandIds[channelType]}&env=${env}`
storageName += `channelType_${channelType}`
}
let data = await http.uni_request({ url: targetUrl }),
{ moduleList, toolList } = data
/**全损无忧 */
if (caseCenterIds.includes(channelType)) {
let configList
try {
configList = await findReceptionpriproConfigList({})
uni.$storage.set('findReceptionpriproConfigList', configList)
} catch (error) {
configList = uni.$storage.get('findReceptionpriproConfigList')
}
const toolOtherList = configList.map(i => {
return {
id: 10 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
}
})
toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
return {
id: 10 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList
}
})
moduleList = moduleList.concat(moduleOtherList)
}
data.moduleList = await imgTransformBase64(moduleList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
data.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
uni.setStorageSync(storageName, {
moduleList, toolList
})
return Promise.resolve(data)
}
/**批量图片转base64 */
const imgTransformBase64 = async (imgList = [], keyList = []) => {
const list = await Promise.all(
imgList.map(async e => {
await Promise.all(
Object.keys(e).map(async key => {
if (keyList.includes(key)) {
let isArray = Array.isArray(e[key])
if (isArray) {
await Promise.all(
e[key].map(async i => {
await Promise.all(
Object.keys(i).map(async k => {
// i[`original_${k}`] = JSON.parse(JSON.stringify(i[k]))
i[k] = await getBase64(i[k])
})
)
})
)
} else {
if (typeof e[key] === 'string') {
// e[`original_${key}`] = JSON.parse(JSON.stringify(e[key]))
e[key] = await getBase64(e[key])
}
if (typeof e[key] === 'object') {
await Promise.all(
Object.keys(e[key]).map(async k => {
// e[key][`original_${k}`] = JSON.parse(JSON.stringify(e[key][k]))
e[key][k] = await getBase64(e[key][k])
})
)
}
}
}
})
)
return e
})
)
return list
}
/**转base64 */
const getBase64 = async (url) => {
return new Promise((resolve, reject) => {
uni.request({
url,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`
resolve(base64)
},
fail: err => {
reject(err)
}
})
})
}
module.exports = { module.exports = {
getImageVersion, getImageVersion,
getMockData, getMockData,
imgToBase64,
updateMockData,
getBydMockData,
getBoutiqueMockData, getBoutiqueMockData,
findReceptionpriproConfigList, findReceptionpriproConfigList,
getJihuMockData getSoureData
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"versionName" : "2.5.1", "versionName" : "2.5.1",
"versionCode" : "251", "versionCode" : "251",
"transformPx" : false, "transformPx" : false,
"sassImplementationName": "node-sass",
/* 5+App特有相关 */ /* 5+App特有相关 */
"app-plus" : { "app-plus" : {
"cache" : false, "cache" : false,
...@@ -16,6 +17,7 @@ ...@@ -16,6 +17,7 @@
"ignoreVersion" : true "ignoreVersion" : true
}, },
"screenOrientation" : "landscape", "screenOrientation" : "landscape",
"splashscreen" : { "splashscreen" : {
"alwaysShowBeforeRender" : true, "alwaysShowBeforeRender" : true,
"waiting" : true, "waiting" : true,
......
...@@ -89,6 +89,10 @@ export default { ...@@ -89,6 +89,10 @@ export default {
channelType () { channelType () {
const { channelType } = uni.$storage.get('userInfo') const { channelType } = uni.$storage.get('userInfo')
return channelType || 1 //默认问界 return channelType || 1 //默认问界
},
shopMerchantId () {
const { shopMerchantId } = uni.$storage.get('userInfo')
return shopMerchantId
} }
}, },
onBackPress (options) { onBackPress (options) {
...@@ -102,7 +106,7 @@ export default { ...@@ -102,7 +106,7 @@ export default {
return false return false
}, },
onLoad () { onLoad () {
this.setViewInfo() uni.$api.systemApi.getMockData(true) //获取APP配置信息
this.getSoure() this.getSoure()
this.get_Vehicle_Sales_Data() this.get_Vehicle_Sales_Data()
}, },
...@@ -159,124 +163,15 @@ export default { ...@@ -159,124 +163,15 @@ export default {
}) })
}, },
// 查询素材 // 查询素材
// 查询素材 async getSoure (loadStorage = true) {
async getSoure () { const { channelType, shopMerchantId } = this
/**比亚迪 */ if (loadStorage) {
if (this.channelType == 2) { let data = uni.getStorageSync(`source_data_merchantId_${shopMerchantId}`)
let { moduleList, toolList } = await uni.$api.systemApi.getBydMockData(true) if (!data) data = uni.getStorageSync(`source_data_channelType_${channelType}`)
let configList if (data) this.setViewInfo(data)
try {
configList = await uni.$api.systemApi.findReceptionpriproConfigList({})
uni.$storage.set('findReceptionpriproConfigList', configList)
} catch (error) {
configList = uni.$storage.get('findReceptionpriproConfigList')
}
const toolOtherList = configList.map(i => {
return {
id: 10 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
}
})
toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
return {
id: 10 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList
}
})
moduleList = moduleList.concat(moduleOtherList)
moduleList = await Promise.all(
moduleList.map(async e => ({
...e,
receptionSourceDetailList: e.receptionSourceDetailList ? await uni.$api.systemApi.imgToBase64(e.receptionSourceDetailList, 'detailUrl') : undefined,
screenList: e.screenList ? await uni.$api.systemApi.imgToBase64(e.screenList, 'url') : undefined
}))
)
toolList = await uni.$api.systemApi.imgToBase64(toolList, 'shortTitleUrl')
uni.$api.systemApi.updateMockData(
{
moduleList,
toolList
},
['moduleList', 'toolList'],
'byd_mock_data'
)
this.setViewInfo(moduleList, toolList)
}
/**极狐 */
else if (this.channelType == 4) this.getJihuMockData()
else {
let { moduleList, toolList, default_moduleList, default_toolList, boutiqueDefaultCarBrandId, aitoCarModelIds } = await uni.$api.systemApi.getMockData(true)
if (this.channelType == 3) {
let configList
try {
configList = await uni.$api.systemApi.findReceptionpriproConfigList({})
uni.$storage.set('findReceptionpriproConfigList', configList)
} catch (error) {
configList = uni.$storage.get('findReceptionpriproConfigList')
}
const toolOtherList = configList.map(i => {
return {
id: 10 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
}
})
default_toolList = default_toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
return {
id: 10 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList
}
})
default_moduleList = default_moduleList.concat(moduleOtherList)
/**其他品牌 */
default_toolList = await uni.$api.systemApi.imgToBase64(default_toolList, 'shortTitleUrl')
uni.$api.systemApi.updateMockData(
{
default_moduleList,
default_toolList
},
['default_moduleList', 'default_toolList']
)
this.setViewInfo(default_moduleList, default_toolList)
} else {
this.aitoCarModelIds = aitoCarModelIds
/**默认问界 */
moduleList = await Promise.all(
moduleList.map(async e => {
const receptionSourceDetailListType = Array.isArray(e.receptionSourceDetailList)
return {
...e,
receptionSourceDetailList: e.receptionSourceDetailList ? await uni.$api.systemApi.imgToBase64(e.receptionSourceDetailList, receptionSourceDetailListType ? 'detailUrl' : '', receptionSourceDetailListType) : undefined,
carTypeList: e.carTypeList ? await uni.$api.systemApi.imgToBase64(e.carTypeList, 'url') : undefined,
screenList: e.screenList ? await uni.$api.systemApi.imgToBase64(e.screenList, 'url') : undefined
}
})
)
toolList = await uni.$api.systemApi.imgToBase64(toolList, 'shortTitleUrl')
uni.$api.systemApi.updateMockData(
{
moduleList,
toolList
},
['moduleList', 'toolList']
)
this.$store.state.user.boutiqueDefaultCarBrandId = boutiqueDefaultCarBrandId
this.setViewInfo(moduleList, toolList)
}
} }
let requestData = await uni.$api.systemApi.getSoureData(channelType, shopMerchantId)
this.setViewInfo(requestData)
}, },
errorImg (index) { errorImg (index) {
this.moduleList[index].showAlt = true this.moduleList[index].showAlt = true
...@@ -288,7 +183,7 @@ export default { ...@@ -288,7 +183,7 @@ export default {
mask: true mask: true
}) })
this.$refs.home.startAudio() this.$refs.home.startAudio()
this.getSoure() this.getSoure(false)
this.clearHistory() this.clearHistory()
this.id = this.moduleList[0].id this.id = this.moduleList[0].id
this.type = 'edit' this.type = 'edit'
...@@ -403,54 +298,16 @@ export default { ...@@ -403,54 +298,16 @@ export default {
} }
}, },
/**素材内容 */ /**素材内容 */
setViewInfo (_moduleList, _toolList) { setViewInfo (data) {
if (_moduleList && _toolList) { let { moduleList, toolList, aitoCarModelIds } = data
this.moduleList = _moduleList if (this.channelType == 1) this.aitoCarModelIds = aitoCarModelIds
this.toolList = _toolList this.moduleList = moduleList
return this.toolList = toolList
} this.$store.state.user = {
if (this.channelType == 2) { ...this.$store.state.user,
const { moduleList, toolList } = uni.$storage.get('byd_mock_data') ...data
this.moduleList = moduleList
this.toolList = toolList
} else {
const { default_moduleList, default_toolList, moduleList, toolList } = uni.$storage.get('mock_data') || {}
this.moduleList = {
3: default_moduleList,
1: moduleList
}[this.channelType]
this.toolList = {
3: default_toolList,
1: toolList
}[this.channelType]
} }
}, },
async getJihuMockData () {
let { moduleList, toolList, boutiqueDefaultCarBrandId, defaultCarId } = await uni.$api.systemApi.getJihuMockData(true)
moduleList = await Promise.all(
moduleList.map(async e => {
const receptionSourceDetailListType = Array.isArray(e.receptionSourceDetailList)
return {
...e,
receptionSourceDetailList: e.receptionSourceDetailList ? await uni.$api.systemApi.imgToBase64(e.receptionSourceDetailList, receptionSourceDetailListType ? 'detailUrl' : '', receptionSourceDetailListType) : undefined,
carTypeList: e.carTypeList ? await uni.$api.systemApi.imgToBase64(e.carTypeList, 'url') : undefined,
screenList: e.screenList ? await uni.$api.systemApi.imgToBase64(e.screenList, 'url') : undefined
}
})
)
toolList = await uni.$api.systemApi.imgToBase64(toolList, 'shortTitleUrl')
uni.$api.systemApi.updateMockData(
{
moduleList,
toolList
},
['moduleList', 'toolList'],
'jihu_mock_data'
)
this.$store.state.user.boutiqueDefaultCarBrandId = boutiqueDefaultCarBrandId
this.$store.state.user.defaultCarId = defaultCarId
this.setViewInfo(moduleList, toolList)
}
} }
} }
</script> </script>
......
...@@ -25,9 +25,7 @@ export const STORAGE_OBJECTKEY = { ...@@ -25,9 +25,7 @@ export const STORAGE_OBJECTKEY = {
recordSuccessList: 'recordSuccessList', recordSuccessList: 'recordSuccessList',
historyList: 'historyList', historyList: 'historyList',
storageVersion: 'storageVersion', storageVersion: 'storageVersion',
byd_mock_data: 'byd_mock_data',
boutique_mock_data: 'boutique_mock_data', boutique_mock_data: 'boutique_mock_data',
findReceptionpriproConfigList: 'findReceptionpriproConfigList', findReceptionpriproConfigList: 'findReceptionpriproConfigList',
appInfoList: 'appInfoList', appInfoList: 'appInfoList',
jihu_mock_data: 'jihu_mock_data'
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!