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