商家订单列表返回位置&&数据字典定时刷新
This commit is contained in:
parent
83332b2d4e
commit
1830014a67
@ -4,11 +4,14 @@ import { get } from '@/api/http'
|
||||
export let dictCache = {}
|
||||
|
||||
const SESSION_KEY = 'dict_cache'
|
||||
const SESSION_TIME_KEY = 'dict_cache_time'
|
||||
const REFRESH_INTERVAL = 5 * 60 * 1000
|
||||
|
||||
export const useDatadicStore = defineStore('datadic', {
|
||||
state: () => ({
|
||||
dicts: {},
|
||||
loaded: false
|
||||
loaded: false,
|
||||
loading: false
|
||||
}),
|
||||
getters: {
|
||||
getByCode: (state) => (code) => {
|
||||
@ -21,31 +24,42 @@ export const useDatadicStore = defineStore('datadic', {
|
||||
},
|
||||
actions: {
|
||||
async init() {
|
||||
// 优先从 sessionStorage 读取缓存
|
||||
const cached = sessionStorage.getItem(SESSION_KEY)
|
||||
const cacheTime = Number(sessionStorage.getItem(SESSION_TIME_KEY) || 0)
|
||||
const now = Date.now()
|
||||
let shouldRefresh = true
|
||||
|
||||
if (cached) {
|
||||
try {
|
||||
dictCache = JSON.parse(cached)
|
||||
this.dicts = dictCache
|
||||
this.loaded = true
|
||||
return
|
||||
shouldRefresh = now - cacheTime > REFRESH_INTERVAL
|
||||
} catch (e) {
|
||||
sessionStorage.removeItem(SESSION_KEY)
|
||||
sessionStorage.removeItem(SESSION_TIME_KEY)
|
||||
}
|
||||
}
|
||||
if (this.loaded) return
|
||||
|
||||
if (this.loading || (this.loaded && !shouldRefresh)) return
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await get('/v1/client/CDatadicsClient')
|
||||
if (res.status === 200 && res.data) {
|
||||
dictCache = {}
|
||||
res.data.forEach(item => {
|
||||
dictCache[item.code] = item
|
||||
})
|
||||
this.dicts = dictCache
|
||||
this.loaded = true
|
||||
sessionStorage.setItem(SESSION_KEY, JSON.stringify(dictCache))
|
||||
sessionStorage.setItem(SESSION_TIME_KEY, String(Date.now()))
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('数据字典加载失败', e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3457,6 +3457,8 @@
|
||||
margin-top: 4vw;
|
||||
|
||||
.item {
|
||||
margin-bottom: 4vw;
|
||||
|
||||
.top_line {
|
||||
.bs;
|
||||
.box;
|
||||
|
||||
@ -177,12 +177,47 @@ export default {
|
||||
selectedDateRange: [new Date(), new Date()]
|
||||
}
|
||||
},
|
||||
beforeRouteLeave(to) {
|
||||
if (to.name === 'MerchantTradeDetail') {
|
||||
sessionStorage.setItem('MerchantTrade_scroll', window.scrollY || 0)
|
||||
sessionStorage.setItem('MerchantTrade_fromDetail', '1')
|
||||
}
|
||||
this._pauseScroll = true
|
||||
},
|
||||
mounted() {
|
||||
const isReturningFromDetail = sessionStorage.getItem('MerchantTrade_fromDetail') === '1'
|
||||
sessionStorage.removeItem('MerchantTrade_fromDetail')
|
||||
if (!isReturningFromDetail) {
|
||||
sessionStorage.setItem('MerchantTrade_scroll', '0')
|
||||
}
|
||||
|
||||
this._pauseScroll = false
|
||||
window.addEventListener('scroll', this.saveScroll)
|
||||
},
|
||||
unmounted() {
|
||||
window.removeEventListener('scroll', this.saveScroll)
|
||||
},
|
||||
methods: {
|
||||
parseData(res) {
|
||||
return res.data || []
|
||||
},
|
||||
onLoad(list) {
|
||||
// console.log('list loaded:', list);
|
||||
saveScroll() {
|
||||
if (this._pauseScroll) return
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
|
||||
sessionStorage.setItem('MerchantTrade_scroll', scrollTop)
|
||||
},
|
||||
onLoad() {
|
||||
const scrollTop = sessionStorage.getItem('MerchantTrade_scroll')
|
||||
if (scrollTop && scrollTop !== '0' && !this._scrollRestored) {
|
||||
this._scrollRestored = true
|
||||
window.removeEventListener('scroll', this.saveScroll)
|
||||
this.$nextTick(() => {
|
||||
window.scrollTo(0, Number(scrollTop))
|
||||
})
|
||||
setTimeout(() => {
|
||||
window.addEventListener('scroll', this.saveScroll)
|
||||
}, 100)
|
||||
}
|
||||
},
|
||||
onconfirm(value) {
|
||||
this.date = this.currentDate;
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
<BasePage>
|
||||
<div class="merchanttradedetail">
|
||||
<div class="state" :class="getStateClass(data.state)" v-if="type !== 'user'">
|
||||
<img :src="data.state >= 3 ? '/img/checked.png' : '/img/loading.png'" alt="">
|
||||
<img v-if="data.state >= 3" src="/img/checked.png" alt="">
|
||||
<b>{{ data.statename }}</b>
|
||||
</div>
|
||||
|
||||
<div class="state box-tb box-align-center" v-else>
|
||||
<img :src="data.state >= 3 ? '/img/checked.png' : '/img/loading.png'" alt="">
|
||||
<img v-if="data.state >= 3" src="/img/checked.png" alt="">
|
||||
<b style="margin:2.4vw 0 0;">交易完成</b>
|
||||
</div>
|
||||
|
||||
|
||||
@ -216,6 +216,7 @@
|
||||
|
||||
<script>
|
||||
import ManagerPopup from "@/components/ManagerPopup.vue"
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
export default {
|
||||
name: 'My',
|
||||
@ -308,7 +309,9 @@ export default {
|
||||
this.$showConfirmDialog({
|
||||
title: "确认退出?",
|
||||
}).then(() => {
|
||||
this.$ls.remove('member_token');
|
||||
useUserStore().clearUser();
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
location.replace('#/Login');
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
@ -392,7 +395,9 @@ export default {
|
||||
confirmButtonText: '确定',
|
||||
}).then(() => {
|
||||
this.saving = false;
|
||||
this.$ls.remove('member_token');
|
||||
useUserStore().clearUser();
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
location.replace('#/Login');
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
</b>
|
||||
|
||||
<button class="r" style="color: #a73436;" @click="$navigate('/Transfer?type=point')">
|
||||
转出
|
||||
转余额
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user