Commit c9317ec9 by 胡悦

feat: 增强请求处理和文件夹组件功能

- 在 Request 类中添加 restoreLogin 和 redirectToLogin 方法,优化 401 错误处理流程,支持自动恢复登录。
- 更新 ToolBox 组件,支持文件夹展开和收起功能,优化素材展示逻辑,提升用户体验。
- 在 HomeFrame 组件中集成新的树形数据结构,支持更灵活的素材管理和展示。
- 修复多个组件中的样式和逻辑问题,确保一致性和可维护性。
1 parent 98b8895d
......@@ -181,6 +181,7 @@ class Request {
}
let { sessionId } = uni.$storage.get()
if (sessionId) header.Authorization = sessionId
const _this = this
return new Promise((resolve, reject) => {
uni.getNetworkType({
success (res) {
......@@ -201,7 +202,6 @@ class Request {
dataType: 'json',
responseType: 'text',
success (response) {
console.log('response', response)
try {
let { data, statusCode } = response
if (!data || statusCode != 200) {
......@@ -218,84 +218,92 @@ class Request {
}
let { code, msg } = data
if (code == 401) {
// 检查是否有 30 天免登标识
const noSignInUuid = uni.$storage.get('noSignInUuid')
// 调用 restore 接口尝试恢复登录
const currentSessionId = uni.$storage.get('sessionId')
if (noSignInUuid && currentSessionId) {
// 尝试调用 restoreLoginInfo 恢复登录
uni.request({
url: `${shukeDomain}/linkwe-gateway/auth/accountLoginSp/restore`,
data: { token: currentSessionId },
method: 'POST',
header: { 'content-type': 'application/json' },
success: function(restoreRes) {
const restoreData = restoreRes.data
if (restoreData && restoreData.code === 0) {
// 恢复成功,更新 sessionId 和 userInfo
const newToken = restoreData.data?.token || restoreData.data?.sessionId || restoreData.data?.access_token
const userInfo = restoreData.data?.loginUser || restoreData.data?.user || {}
if (newToken) {
uni.$storage.set('sessionId', newToken)
}
if (userInfo && Object.keys(userInfo).length > 0) {
uni.$storage.set('userInfo', userInfo)
}
// 重新发起原请求
resolve(_this.shukeRequest(url, params, method, returnAll))
} else {
// restoreLoginInfo 返回 code 不为 0,清除缓存跳转登录
failHandler()
}
},
fail: function() {
// restoreLoginInfo 失败,清除缓存跳转登录
failHandler()
}
})
function failHandler() {
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.$storage.set('noSignInUuid', '')
uni.hideLoading()
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`restoreLoginInfo 失败,跳转登录页:currentPage:${currentPage.route}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: `/pages/common/login?username=${noSignInUuid}`
})
}
reject('登录已过期,请重新登录')
}
return
if (currentSessionId) {
_this.restoreLogin(resolve, reject, url, params, method, returnAll, currentSessionId)
} else {
// 没有 30 天免登标识,直接清除缓存跳转登录
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.hideLoading()
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`HTTP Triggered Logout: params:${JSON.stringify(params)}->code:${code} msg:${msg} currentPage:${currentPage.route}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
})
}
// 没有 sessionId,直接跳转登录
_this.redirectToLogin(reject)
}
} else resolve(data.data)
return
} else {
resolve(data.data)
}
} catch (error) {
console.log(error)
uni.$logger.error(`${params.method}处理异常:${error.msg}`)
reject(error)
}
},
fail (error) {
uni.hideLoading()
uni.$logger.error(`HTTP Request Fail: ${JSON.stringify(params)}->${error.message}`)
uni.showToast({
title: typeof error == 'string' ? error : error.errMsg ? error.errMsg : JSON.stringify(error) || '系统异常',
icon: 'error'
})
reject(error)
}
})
}
})
})
}
/**
* 调用 restore 接口恢复登录
*/
restoreLogin (resolve, reject, url, params, method, returnAll, currentSessionId) {
uni.request({
url: `${shukeDomain}/linkwe-gateway/auth/accountLoginSp/restore`,
data: { token: currentSessionId },
method: 'POST',
header: { 'content-type': 'application/json' },
success: (restoreRes) => {
console.log(restoreRes, 'restoreRes')
const restoreData = restoreRes.data
if (restoreData && restoreData.code == '200') {
// 恢复成功,更新 sessionId 和 userInfo
const newToken = restoreData.data?.sessionId || restoreData.data?.token || restoreData.data?.access_token
const userInfo = restoreData.data?.loginUser || restoreData.data?.user || {}
if (newToken) {
uni.$storage.set('sessionId', newToken)
}
if (userInfo && Object.keys(userInfo).length > 0) {
uni.$storage.set('userInfo', userInfo)
}
// 重新发起原请求
resolve(this.shukeRequest(url, params, method, returnAll))
} else {
// restore 返回失败,跳转登录
this.redirectToLogin(reject)
}
},
fail: () => {
// restore 接口调用失败,跳转登录
this.redirectToLogin(reject)
}
})
}
/**
* 跳转到登录页
*/
redirectToLogin (reject) {
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.$storage.set('noSignInUuid', '')
uni.hideLoading()
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`跳转登录页:currentPage:${currentPage.route}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
})
}
reject('登录已过期,请重新登录')
}
}
export default new Request()
......@@ -72,7 +72,7 @@ export default {
<style scoped lang="scss">
.selector-container {
padding: 0 toRpx(40) toRpx(80);
padding: toRpx(40) toRpx(40) toRpx(80);
width: 100%;
box-sizing: border-box;
......
<template>
<uni-popup ref="popup" type="center" border-radius="20px" @maskClick="false">
<uni-popup ref="popup" type="center" border-radius="20px" :mask-click="false">
<view class="change-password-box">
<!-- 关闭按钮 -->
<view class="close" @click="close">
......@@ -186,8 +186,12 @@ export default {
this.close()
} else {
// 旧密码错误等其他情况
if (res.code === 401 || (res.message && res.message.includes('旧密码'))) {
this.error.oldPassword = '旧密码错误'
if (res.code === 500 || (res.msg && res.msg.includes('旧密码'))) {
if (res.msg && res.msg.includes('新密码')) {
this.error.newPassword = res.msg
} else {
this.error.oldPassword = res.msg
}
} else {
uni.showToast({
title: '操作失败',
......
......@@ -27,6 +27,12 @@
<view class="left-footer">
<view
class="btn"
@click="openScenePopup"
>
<view class="sprite-icon icon-scene-change"></view>
</view>
<view
class="btn"
@click="handleSetting"
>
<view class="sprite-icon icon-setting"></view>
......@@ -102,6 +108,40 @@ export default {
// this.leaveTrack()
// }, 5000)
// },
async openScenePopup () {
try {
uni.showLoading({
mask: true
})
// 清空门店信息
uni.$storage.rm('storeInfo')
// 调用 getStoreList 获取门店列表
const storeListRes = await uni.$api.loginApi.getStoreList()
if (!storeListRes || !storeListRes.data) {
throw '获取门店列表失败'
}
const stores = storeListRes.data.stores
if (!stores || stores.length === 0) {
throw '暂无门店信息,请联系管理员'
}
uni.hideLoading()
// 跳转至门店列表页面
uni.reLaunch({
url: `/pages/common/selectStore?stores=${encodeURIComponent(JSON.stringify(stores))}`
})
} catch (error) {
uni.hideLoading()
uni.showToast({
title: error?.message || error,
icon: 'none'
})
}
},
clickHome () {
if (this.tabs[this.tabIndex].isTrack)
this.changeIndex(0, this.tabs[0])
......
<template>
<uni-popup ref="popup" border-radius="20px">
<uni-popup ref="popup" border-radius="20px" :mask-click="false">
<view class="setting-box">
<view class="close flex" @click="close">
<uni-icons type="closeempty" :size="18" color="#1A1A1A"></uni-icons>
......@@ -11,7 +11,7 @@
<view class="check-box" @click="handleCheck">检查更新</view>
</view>
<view class="btn-box">
<view class="btn flex" @click="changeAccount">切换账号</view>
<!-- <view class="btn flex" @click="changeAccount">切换账号</view> -->
<view class="btn flex" @click="openChangePassword">修改密码</view>
<view class="btn flex logout" @click="logout">退出</view>
</view>
......@@ -104,6 +104,10 @@ export default {
mask: true
})
// 清空门店信息和用户信息
uni.$storage.rm('storeInfo')
uni.$storage.rm('userInfo')
// 调用 getStoreList 获取门店列表
const storeListRes = await uni.$api.loginApi.getStoreList()
if (!storeListRes || !storeListRes.data) {
......@@ -162,7 +166,7 @@ export default {
},
jump(type) {
let url = type == 'icp' ? 'https://beian.miit.gov.cn/' :
'https://img01.glsx.com.cn/weapp/resource/saas/app/privacy.html'
'https://img01.glsx.com.cn/weapp/resource/miniprogram/market-assistant/html/agreement.html'
uni.navigateTo({
url: `/pages/common/webview?url=${url}`
})
......
<template>
<view class="store-addr">
<view class="icon-addr sprite-icon icon-addr"></view>
<view class="addr-text">{{ userInfo.shopMerchantName }}</view>
<view class="addr-text">{{ storeInfo.storeName }}</view>
</view>
</template>
......@@ -9,11 +9,11 @@
export default {
data() {
return {
userInfo: {}
storeInfo: {}
}
},
mounted() {
this.userInfo = uni.$storage.get('userInfo') || {}
this.storeInfo = uni.$storage.get('storeInfo') || {}
}
}
</script>
......
......@@ -2,30 +2,27 @@
<view class="tool-box" :style="toolStyle">
<view :class="['btn', { hideIcon: !show }]" @click="open">
<view class="icon sprite-icon icon-tool-file"></view>
{{ folderName }}
</view>
文件夹
</view>
<view :class="['list', { showList: !show }]">
<view class="title" @click="close">{{ folderName }}</view>
<view class="list-body" :class="{ 'multi-column': data.length > 8 }">
<template v-for="(i, index) in data">
<view :class="['item', { active: i[idKey] == id }]" :key="index" @click="jump(i)" :style="{'--i': index}">
<template v-if="i.shortTitleUrl">
<!-- <image class="icon" :src="i.shortTitleUrl" mode="scaleToFill" /> -->
<view class="icon">
<view class="sprite-icon icon-tool-pay"></view>
</view>
<view class="list-body" :class="{ 'multi-column': flatList.length > 8 }">
<template v-for="(item, index) in flatList">
<view :key="index" :class="['item', { active: item.id == id, 'folder-item': item.isFolder }]" @click.stop="handleItemClick(item)" :style="{'--i': index}">
<template v-if="item.isFolder">
<view class="folder">{{ item.folderName }}</view>
</template>
<template v-else>
<view class="icon">
<view class="sprite-icon icon-tool-file"></view>
<view class="sprite-icon icon-tool-pay"></view>
</view>
<view class="material-name">{{ item.materialName }}</view>
</template>
{{ i.shortTitle }}
</view>
</template>
</view>
<template v-if="showPayBtn">
<view class="item" @click="toPay" :style="{'--i': data.length}">
<view class="item" @click="toPay" :style="{'--i': flatList.length}">
<view class="icon">
<view class="sprite-icon icon-tool-pay"></view>
</view>
......@@ -33,7 +30,7 @@
</view>
</template>
<template v-if="type != 'preview'">
<view class="item" @click="finish" :style="{'--i': data.length + (showPayBtn ? 1 : 0)}">
<view class="item" @click="finish" :style="{'--i': flatList.length + (showPayBtn ? 1 : 0)}">
<view class="icon">
<view class="sprite-icon icon-tool-finish"></view>
</view>
......@@ -60,11 +57,15 @@ export default {
folderName: {
type: String,
default: '文件夹'
}
},
},
data () {
return {
show: true
show: true,
touchStartX: 0,
touchStartY: 0,
flatList: [],
expandedFolderCode: ''
}
},
computed: {
......@@ -79,8 +80,99 @@ export default {
this.show = true
}
},
data: {
immediate: true,
handler (newval) {
this.syncExpandedFolder(newval)
this.flatList = this.flattenTreeData(newval)
}
},
id: {
immediate: true,
handler () {
this.syncExpandedFolder(this.data)
this.flatList = this.flattenTreeData(this.data)
}
},
},
methods: {
syncExpandedFolder(treeData) {
if (!Array.isArray(treeData) || !treeData.length) {
this.expandedFolderCode = ''
return
}
const matchedFolder = treeData.find(folder =>
Array.isArray(folder.children) && folder.children.some(child => child && child[this.idKey] == this.id)
)
if (matchedFolder?.folderCode) {
this.expandedFolderCode = matchedFolder.folderCode
return
}
if (!treeData.some(folder => folder.folderCode === this.expandedFolderCode)) {
this.expandedFolderCode = treeData[0]?.folderCode || ''
}
},
flattenTreeData(treeData) {
const result = []
if (!Array.isArray(treeData)) return result
treeData.forEach(folder => {
// 添加文件夹标题项
result.push({
isFolder: true,
folderCode: folder.folderCode,
folderName: folder.folderName
})
// 添加子项素材
if (this.expandedFolderCode === folder.folderCode && Array.isArray(folder.children)) {
folder.children.forEach(child => {
result.push({
...child,
isFolder: false
})
})
}
})
return result
},
handleItemClick(item) {
if (item.isFolder) {
// 手风琴效果:仅展开当前分类;若再次点击已展开分类则收起
this.expandedFolderCode = this.expandedFolderCode === item.folderCode ? '' : item.folderCode
this.flatList = this.flattenTreeData(this.data)
if (!this.expandedFolderCode) return
// 展开后默认定位到该分类第一个素材
const folder = this.data.find(f => f.folderCode === this.expandedFolderCode)
if (folder && Array.isArray(folder.children) && folder.children.length > 0) {
this.$emit('choose', folder.children[0])
}
} else {
// 点击素材,直接切换
this.$emit('choose', item)
}
},
// handleTouchStart(e) {
// this.touchStartX = e.touches[0].pageX
// this.touchStartY = e.touches[0].pageY
// },
// handleTouchMove(e) {
// // 阻止默认行为,防止滚动冲突
// if (Math.abs(e.touches[0].pageX - this.touchStartX) > Math.abs(e.touches[0].pageY - this.touchStartY)) {
// e.preventDefault()
// }
// },
// handleTouchEnd(e) {
// console.log(e, 'touchend ')
// const diffX = e.changedTouches[0].pageX - this.touchStartX
// const diffY = e.changedTouches[0].pageY - this.touchStartY
// // 判断是否为水平滑动
// if (Math.abs(diffX) < 50 || Math.abs(diffY) > 30) return
// // 左滑或右滑切换文件夹
// const direction = diffX > 0 ? 'prev' : 'next'
// this.$emit('swipe', direction)
// },
hide () {
this.show = true
},
......@@ -221,7 +313,7 @@ export default {
/* 超过 8 个时换列展示 */
&.multi-column {
flex-wrap: wrap;
// flex-wrap: wrap;
justify-content: flex-start;
width: toRpx(240);
......@@ -246,7 +338,6 @@ export default {
font-size: toRpx(22);
color: #555;
width: 100%;
padding-top: toRpx(20);
padding-bottom: toRpx(12);
position: relative;
......@@ -273,6 +364,34 @@ export default {
color: #2c66f7;
font-weight: 500;
}
/* 文件夹项样式 */
&.folder-item {
justify-content: flex-start;
padding: toRpx(8) 0;
.folder {
height: toRpx(50);
line-height: toRpx(50);
background-color: #eaedf3;
border: toRpx(1) solid #e2e2e2;
border-radius: toRpx(8);
text-align: center;
width: 100%;
font-size: toRpx(24);
font-weight: 600;
color: #666;
}
}
.material-name {
font-size: toRpx(22);
text-align: center;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
......
......@@ -208,7 +208,7 @@ export default {
}
}, 200),
jumpUrl () {
let url = 'https://img01.glsx.com.cn/weapp/resource/saas/app/privacy.html'
let url = 'https://img01.glsx.com.cn/weapp/resource/miniprogram/market-assistant/html/privacy.html'
uni.navigateTo({
url: `/pages/common/webview?url=${url}`
})
......
......@@ -22,7 +22,7 @@
</view>
<view class="tips flex">
<view :class="['tips-text', { deal: pageData.orderFinishFlag }]">
{{ pageData.orderFinishFlag ? '成交' : '未成交' }}
{{ pageData.orderFinishFlag ? '成交' : '战败' }}
</view>
<view class="score-box" v-if="pageData.score != null">
{{ pageData.score }}
......
......@@ -128,6 +128,12 @@ export default {
const userInfo = res.data.loginUser || {};
uni.$storage.set('userInfo', userInfo);
// 存储门店信息到缓存
uni.$storage.set('storeInfo', {
storeCode: selectedStore.storeCode,
storeName: selectedStore.storeName
});
// 如果勾选了 30 天免登,调用 saveLoginInfo 保存登录信息
if (this.loginForm.noSignIn) {
// 存储 noSignInUuid,用于 401 时恢复登录
......
......@@ -18,6 +18,7 @@
:id.sync="id"
:media="moduleList"
:folders="folderList"
:trees="treeData"
:type.sync="type"
:toolList="toolList"
:aitoCarModelIds="aitoCarModelIds"
......@@ -44,6 +45,7 @@ export default {
homeList: [],
moduleList: [],
folderList: [],
treeData: [],
toolList: [],
id: '',
type: '',
......@@ -124,22 +126,55 @@ export default {
)
const results = await Promise.all(folderPromises)
// 找到第一个有数据的文件夹
const validResult = results.find(res => Array.isArray(res?.data) && res.data.length > 0)
if (!validResult) return this.resetLists()
this.processMaterials(validResult.data)
// 构建 treeData,供后续页面/组件直接透传使用
this.treeData = Object.freeze(
this.folderList
.map((folder, index) => {
const materials = Array.isArray(results[index]?.data) ? results[index].data : []
return {
folderCode: folder.folderCode,
folderName: folder.folderName,
children: materials
}
})
.filter(folder => Array.isArray(folder.children) && folder.children.length > 0)
)
// 使用 treeData 扁平化后的素材作为 moduleList 数据源
const flatMaterials = this.treeData.flatMap(folder => (Array.isArray(folder.children) ? folder.children : []))
if (!flatMaterials.length) return this.resetLists()
this.moduleList = Object.freeze(flatMaterials.map(item => ({
...item,
treeData: this.treeData,
thumbnail: item.materialUrl,
title: item.materialName,
class: 'landscape',
style: 'width: calc(100vw * (1282 / 2346));height: calc(100vmin * (1173 / 768) * (304 / 2346));',
showAlt: false,
componentName: 'media-component',
materialName: item.materialName,
receptionSourceDetailList: {
detailUrl: item.materialUrl
}
})))
this.toolList = Object.freeze(flatMaterials.map(item => ({
...item,
treeData: this.treeData,
shortTitle: item.materialName,
title: item.materialName,
shortTitleUrl: item.materialUrl
})))
},
resetLists() {
this.moduleList = []
this.treeData = []
this.toolList = []
},
processMaterials(materials) {
processMaterials(materials, treeData = []) {
this.moduleList = Object.freeze(materials.map(item => ({
...item,
treeData,
thumbnail: item.materialUrl,
title: item.materialName,
class: 'landscape',
......@@ -154,6 +189,7 @@ export default {
this.toolList = Object.freeze(materials.map(item => ({
...item,
treeData,
shortTitle: item.materialName,
title: item.materialName,
shortTitleUrl: item.materialUrl
......
......@@ -46,4 +46,5 @@ export const STORAGE_OBJECTKEY = {
boutique_YQorderSetting: 'boutique_YQorderSetting',
sessionId:'sessionId',
typeItem: 'typeItem',
storeInfo: 'storeInfo'
}
......@@ -12,9 +12,11 @@ class RecordService {
this.recorder = null
this.tempRecord = null
this._startAudioPromise = null
// init 是 async,但构造函数不能 await;用 Promise 让外部在 start 前等待初始化完成
this._initPromise = null
this.timeoutService = null
// 初始化
this.init()
this._initPromise = this.init()
}
static getInstance() {
......@@ -107,14 +109,11 @@ class RecordService {
async initDto() {
const userInfo = storageApi.getUserInfo() || {}
const {
user: { userId, userName, deptId }
} = userInfo
const { userId, userName } = userInfo
const machineCode = await utils.getOAID()
const dto = new RecordDto({
userId,
userName,
merchantId: deptId,
machineCode
})
this.tempRecord = dto
......@@ -176,6 +175,8 @@ class RecordService {
// --- 录音控制 ---
async startAudio(isInitData = true) {
// 确保 init 完成后再启动计时/录音
await this._initPromise
if (this._startAudioPromise) return this._startAudioPromise
this._startAudioPromise = (async () => {
try {
......@@ -243,6 +244,7 @@ class RecordService {
this.audioManager = null
this.recorder = null
this.tempRecord = null
this.timeoutService = null
}
destroy() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!