keep-alive

This commit is contained in:
2023-06-29 16:02:24 +08:00
parent b28add0fc1
commit 5aa63a973b
6 changed files with 36 additions and 5 deletions

View File

@@ -3,7 +3,9 @@
<v-toast v-show="showToast"></v-toast>
<v-alert v-show="showAlert"></v-alert>
<v-loading v-show="loading"></v-loading>
<router-view/>
<keep-alive :include="keepAlive" >
<router-view/>
</keep-alive>
</div>
</template>
@@ -24,7 +26,7 @@ export default {
}
},
computed: {
...mapGetters(['showToast', 'showAlert', 'loading'])
...mapGetters(['showToast', 'showAlert', 'loading', 'keepAlive'])
}
}
</script>

View File

@@ -50,6 +50,10 @@ export default {
},
toPage2 (e) {
let url = e.path
let name = url.substr(1)
if (name === 'semifinishedinstore') {
this.$store.dispatch('setKeepAlive', [name])
}
this.$router.push(url)
},
Quit () {

View File

@@ -25,7 +25,7 @@
<button class="button button--primary">快速查询</button>
<button class="button button--primary">确定</button>
<button class="button button--primary">清除</button>
<button class="button button--primary">关闭</button>
<button class="button button--primary" @click="colseUp">关闭</button>
</div>
</div>
</div>
@@ -73,6 +73,9 @@ export default {
async _getMaterial () {
let res = await getMaterial(this.val1)
this.options1 = [...res.data]
},
colseUp () {
this.$router.push('/semifinishedinstore')
}
}
}

View File

@@ -31,7 +31,7 @@
<div class="search-item">
<div class="search-label">物料</div>
<div class="filter_input_wraper pointer" @click="searchMater">
<input type="text" class="filter-input" disabled>
<input type="text" class="filter-input" disabled v-model="val1">
</div>
</div>
<div class="search-item">
@@ -98,6 +98,7 @@
<script>
import {getBcpStor, getBillType} from '@config/getData2.js'
export default {
name: 'semifinishedinstore',
data () {
return {
options1: [],
@@ -105,9 +106,19 @@ export default {
options2: [],
value2: '',
options3: [],
value3: ''
value3: '',
val1: ''
}
},
beforeRouteLeave (to, from, next) {
if (to.path === '/home' || to.path === '/login') {
this.$store.dispatch('setKeepAlive', [])
}
next()
},
activated () {
// this.val2 = this.$store.getters.materObj.material_name
},
created () {
this._getBcpStor()
this._getBillType()

View File

@@ -2,18 +2,23 @@ import * as types from '../types'
import { getStore, setStore } from '@config/utils.js'
const state = {
keepAlive: [], // 缓存页面
deviceUuid: getStore('deviceUuid') || '',
deviceCode: getStore('deviceCode') || '',
isProductonplan: getStore('isProductonplan') || ''
}
const getters = {
keepAlive: state => state.keepAlive,
deviceUuid: state => state.deviceUuid,
deviceCode: state => state.deviceCode,
isProductonplan: state => state.isProductonplan
}
const actions = {
setKeepAlive ({commit}, res) {
commit(types.SET_KEEP_ALIVE, res)
},
setDevice ({commit}, res) {
setStore('deviceUuid', res.deviceUuid)
setStore('deviceCode', res.deviceCode)
@@ -26,6 +31,9 @@ const actions = {
}
const mutations = {
[types.SET_KEEP_ALIVE] (state, res) {
state.keepAlive = res
},
[types.DATA_DEVICE] (state, res) {
state.deviceUuid = res.deviceUuid
state.deviceCode = res.deviceCode

View File

@@ -13,6 +13,9 @@ export const SAVE_USER_INFO = 'SAVE_USER_INFO'
export const DEL_USER_INFO = 'DEL_USER_INFO'
export const SAVE_TOKEN = 'SAVE_TOKEN'
// 缓存页面
export const SET_KEEP_ALIVE = 'SET_KEEP_ALIVE'
// 数据
export const DATA_DEVICE = 'DATA_DEVICE'
export const DATA_IS_PROPLAN = 'DATA_IS_PROPLAN'