修复bug
This commit is contained in:
@@ -37,7 +37,7 @@ export default function request(url, data = {}, method = 'GET') {
|
|||||||
title: '登录过期,请重新登录',
|
title: '登录过期,请重新登录',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
uni.clearStorageSync('token')
|
clearAccountStorage()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pageSubPack/loginSub/pwd-login'
|
url: '/pageSubPack/loginSub/pwd-login'
|
||||||
@@ -114,6 +114,23 @@ export const upload = (filePath, url, fileName) => {
|
|||||||
* @param {Object|null|undefined} params - 原始请求参数
|
* @param {Object|null|undefined} params - 原始请求参数
|
||||||
* @returns {Object} 过滤后的干净参数对象,只保留有效值
|
* @returns {Object} 过滤后的干净参数对象,只保留有效值
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 清除账号相关缓存(退出登录/切换账号/登录过期时调用)
|
||||||
|
* 只清除账号绑定的 key,保留设备级和应用级 key(如 push_cid、hasShowGuide、rememberPwd 等)
|
||||||
|
*/
|
||||||
|
export function clearAccountStorage() {
|
||||||
|
const keys = [
|
||||||
|
'token',
|
||||||
|
'userId',
|
||||||
|
'userPermission',
|
||||||
|
'currentVillage',
|
||||||
|
'currentVillageId',
|
||||||
|
'home_banner_cache',
|
||||||
|
'tempChangePwdParams'
|
||||||
|
]
|
||||||
|
keys.forEach(key => uni.removeStorageSync(key))
|
||||||
|
}
|
||||||
|
|
||||||
export function filterParams(params) {
|
export function filterParams(params) {
|
||||||
if (!params) return {}
|
if (!params) return {}
|
||||||
return Object.keys(params).reduce((acc, key) => {
|
return Object.keys(params).reduce((acc, key) => {
|
||||||
|
|||||||
@@ -99,6 +99,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onUnmounted } from 'vue'
|
import { ref, computed, onUnmounted } from 'vue'
|
||||||
import { getLoginBySms, getSendCode } from '../../api/api.js'
|
import { getLoginBySms, getSendCode } from '../../api/api.js'
|
||||||
|
import { clearAccountStorage } from '../../api/request.js'
|
||||||
import PrivacyPopup from '@/components/privacy-popup/privacy-popup.vue'
|
import PrivacyPopup from '@/components/privacy-popup/privacy-popup.vue'
|
||||||
import { usePermStore } from '@/stores/usePermStore'
|
import { usePermStore } from '@/stores/usePermStore'
|
||||||
|
|
||||||
@@ -249,6 +250,8 @@ const handleLogin = () => {
|
|||||||
cid: push_cid
|
cid: push_cid
|
||||||
}
|
}
|
||||||
permStore.clearPerm()
|
permStore.clearPerm()
|
||||||
|
// 清除上个账号的所有缓存,防止新账号显示旧数据
|
||||||
|
clearAccountStorage()
|
||||||
getLoginBySms(params)
|
getLoginBySms(params)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -259,8 +262,6 @@ const handleLogin = () => {
|
|||||||
if (res.data.user.userId) {
|
if (res.data.user.userId) {
|
||||||
uni.setStorageSync('userId', res.data.user.userId)
|
uni.setStorageSync('userId', res.data.user.userId)
|
||||||
}
|
}
|
||||||
// 清掉上次账号的小区缓存,防止新账号显示旧小区
|
|
||||||
uni.removeStorageSync('currentVillage')
|
|
||||||
// 存当前绑定的小区ID,0 表示未绑定
|
// 存当前绑定的小区ID,0 表示未绑定
|
||||||
const currentVillageId = res.data.currentVillageId || 0
|
const currentVillageId = res.data.currentVillageId || 0
|
||||||
uni.setStorageSync('currentVillageId', currentVillageId)
|
uni.setStorageSync('currentVillageId', currentVillageId)
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { getLoginPassword } from '../../api/api.js'
|
import { getLoginPassword } from '../../api/api.js'
|
||||||
|
import { clearAccountStorage } from '../../api/request.js'
|
||||||
import PrivacyPopup from '@/components/privacy-popup/privacy-popup.vue'
|
import PrivacyPopup from '@/components/privacy-popup/privacy-popup.vue'
|
||||||
import { usePermStore } from '@/stores/usePermStore'
|
import { usePermStore } from '@/stores/usePermStore'
|
||||||
|
|
||||||
@@ -204,13 +205,13 @@ const handleLogin = () => {
|
|||||||
cid: push_cid
|
cid: push_cid
|
||||||
}
|
}
|
||||||
permStore.clearPerm()
|
permStore.clearPerm()
|
||||||
|
// 清除上个账号的所有缓存,防止新账号显示旧数据
|
||||||
|
clearAccountStorage()
|
||||||
getLoginPassword(params)
|
getLoginPassword(params)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log('33333',res)
|
// console.log('33333',res)
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
uni.setStorageSync('token', res.data.token)
|
uni.setStorageSync('token', res.data.token)
|
||||||
// 清掉上次账号的小区缓存,防止新账号显示旧小区
|
|
||||||
uni.removeStorageSync('currentVillage')
|
|
||||||
// 存用户ID
|
// 存用户ID
|
||||||
// if(res.data) {
|
// if(res.data) {
|
||||||
// // 存当前绑定的小区ID,0 表示未绑定
|
// // 存当前绑定的小区ID,0 表示未绑定
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref } from 'vue'
|
||||||
import {onLoad} from '@dcloudio/uni-app'
|
import {onLoad} from '@dcloudio/uni-app'
|
||||||
import { getVillageList,switchVillage} from '../../api/api.js'
|
import { getVillageList,switchVillage} from '../../api/api.js'
|
||||||
|
|
||||||
@@ -64,7 +64,18 @@
|
|||||||
const res = await getVillageList({ villageName })
|
const res = await getVillageList({ villageName })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
displayedCommunities.value = res.data
|
displayedCommunities.value = res.data
|
||||||
// 自动选中传入的小区
|
|
||||||
|
// 如果当前选中项不在新的列表中(搜索过滤掉了),则清空选中状态
|
||||||
|
if (selectedItem.value) {
|
||||||
|
const stillExists = displayedCommunities.value.find(
|
||||||
|
item => String(item.id) === String(selectedItem.value.id)
|
||||||
|
)
|
||||||
|
if (!stillExists) {
|
||||||
|
selectedItem.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动选中传入的默认小区(仅在默认小区存在于列表时)
|
||||||
if (defaultVillageId.value) {
|
if (defaultVillageId.value) {
|
||||||
const found = displayedCommunities.value.find(
|
const found = displayedCommunities.value.find(
|
||||||
item => String(item.id) === String(defaultVillageId.value)
|
item => String(item.id) === String(defaultVillageId.value)
|
||||||
@@ -82,11 +93,13 @@
|
|||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 接收传入的参数
|
// 接收传入的参数,并初始加载小区列表
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
if (options?.villageId) {
|
if (options?.villageId) {
|
||||||
defaultVillageId.value = options.villageId
|
defaultVillageId.value = options.villageId
|
||||||
}
|
}
|
||||||
|
// 在 onLoad 中调用初始加载,确保 defaultVillageId 已设置
|
||||||
|
fetchVillageList()
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理搜索输入(防抖)
|
// 处理搜索输入(防抖)
|
||||||
@@ -147,11 +160,6 @@
|
|||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 初始化
|
|
||||||
onMounted(() => {
|
|
||||||
fetchVillageList()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { onShow } from '@dcloudio/uni-app'
|
import { onShow } from '@dcloudio/uni-app'
|
||||||
import { logout, getSettingInfo } from '../../api/api.js'
|
import { logout, getSettingInfo } from '../../api/api.js'
|
||||||
|
import { clearAccountStorage } from '../../api/request.js'
|
||||||
import { usePermStore } from '@/stores/usePermStore'
|
import { usePermStore } from '@/stores/usePermStore'
|
||||||
|
|
||||||
const permStore = usePermStore()
|
const permStore = usePermStore()
|
||||||
@@ -121,9 +122,10 @@ const confirmLogout = () => {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
permStore.clearPerm()
|
permStore.clearPerm()
|
||||||
uni.clearStorageSync()
|
clearAccountStorage()
|
||||||
uni.showToast({ title: '退出登录成功', icon: 'success' })
|
uni.showToast({ title: '退出登录成功', icon: 'success' })
|
||||||
uni.redirectTo({ url: '/pageSubPack/loginSub/pwd-login' })
|
// 使用 reLaunch 销毁所有页面(包括 tab 页),确保新账号登录后页面重新初始化
|
||||||
|
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' })
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: res.msg || '退出失败', icon: 'none' })
|
uni.showToast({ title: res.msg || '退出失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,7 +423,11 @@ onShow(() => {
|
|||||||
// 从其他页面返回 / 从后台恢复:只刷新可能变化的数据
|
// 从其他页面返回 / 从后台恢复:只刷新可能变化的数据
|
||||||
getbannarData()
|
getbannarData()
|
||||||
getMyOrderNum()
|
getMyOrderNum()
|
||||||
// 小区和巡检数据不频繁变化,从后台恢复时用缓存/旧数据,减少请求
|
// 换账号登录后 currentVillage 缓存已被清除,需要重新获取小区
|
||||||
|
if (!uni.getStorageSync('currentVillage')) {
|
||||||
|
currentVillageData()
|
||||||
|
getInspectionData()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user