add home state

This commit is contained in:
RainSun 2020-03-15 11:27:56 +08:00
parent e52f7221d2
commit f195c4d280
3 changed files with 74 additions and 3 deletions

View File

@ -13,6 +13,8 @@ export default new Vuex.Store({
row_pwd: '', row_pwd: '',
// 配置信息 // 配置信息
settings: '', settings: '',
// 主页状态
home_state: '',
}, },
mutations: { mutations: {
// 设置用户信息 // 设置用户信息
@ -31,6 +33,10 @@ export default new Vuex.Store({
SET_SETTINGS(state, settings) { SET_SETTINGS(state, settings) {
state.settings = settings; state.settings = settings;
}, },
// 设置主页状态
SET_HOMESTATE(state, home_state) {
state.home_state = home_state
},
}, },
actions: { actions: {
// 设置用户信息 // 设置用户信息
@ -61,6 +67,13 @@ export default new Vuex.Store({
commit('SET_SETTINGS', arg[0]); commit('SET_SETTINGS', arg[0]);
localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state)); localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
}, },
// 设置主页状态
setHomeState({
commit
}, arg) {
commit('SET_HOMESTATE', arg[0]);
localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
},
}, },
modules: {} modules: {}
}) })

View File

@ -294,6 +294,14 @@ export function lang() {
CHS:{ CHS:{
title: '更新日志', title: '更新日志',
timeline: [ timeline: [
{
label: '切换页面之后保存主页状态',
tag:'bug修复',
content: [
'正常情况下不保存主页状态进行页面跳转的时候会导致每次回到主页都是默认回顶的状态,已修复',
'2020-03-15'
]
},
{ {
label: '设置中的重置功能优化', label: '设置中的重置功能优化',
tag:'功能更新', tag:'功能更新',
@ -403,6 +411,14 @@ export function lang() {
EN:{ EN:{
title: 'Update Log', title: 'Update Log',
timeline: [ timeline: [
{
label: 'Save homepage status after switching pages',
tag:'Bug fix',
content: [
'Normally, when you do nt save the homepage state, the page jump will result in the default backing state every time you return to the homepage.',
'2020-03-15'
]
},
{ {
label: 'Optimization of reset function in settings', label: 'Optimization of reset function in settings',
tag:'Feature update', tag:'Feature update',

View File

@ -135,14 +135,16 @@ export default {
lang: '', lang: '',
// vcnsole // vcnsole
lastClickTime: 0, lastClickTime: 0,
count: 0 count: 0,
//
scrollHeight: 0,
}; };
}, },
computed: { computed: {
...mapState(['user_infos', 'row_data', 'row_pwd', 'settings']) ...mapState(['user_infos', 'row_data', 'row_pwd', 'settings', 'home_state'])
}, },
methods: { methods: {
...mapActions(['setUserInfo', 'setRowData', 'setRowPwd', 'setSettings']), ...mapActions(['setUserInfo', 'setRowData', 'setRowPwd', 'setSettings', 'setHomeState']),
// md-app // md-app
changeFixed(clientHeight) { changeFixed(clientHeight) {
@ -188,6 +190,19 @@ export default {
this.show_list = data_list; this.show_list = data_list;
// title // title
this.separateTitle(data_list); this.separateTitle(data_list);
//
if(this.home_state) {
this.search_start = this.home_state.search_start
this.search_content = this.home_state.search_content
this.$nextTick(()=>{
this.$refs.list_placeholder.parentNode.parentNode.scrollTo({
top: this.home_state.scrollHeight
});
console.log('原状态恢复完成')
this.setHomeState(['', this])
console.log('主页状态缓存删除完成')
})
}
} else { } else {
// //
this.show_list = []; this.show_list = [];
@ -261,6 +276,8 @@ export default {
// //
turnToUnlock(type) { turnToUnlock(type) {
this.setHomeState(['', this])
console.log('主页状态缓存删除完成')
console.log(type); console.log(type);
this.setRowPwd(['', this]); this.setRowPwd(['', this]);
if (type == '密码超时') this.$router.push({ name: 'Unlock', params: { msg: this.lang.unlock_msg.expired } }); if (type == '密码超时') this.$router.push({ name: 'Unlock', params: { msg: this.lang.unlock_msg.expired } });
@ -285,15 +302,33 @@ export default {
this.turnToUnlock('点击新增未解锁拦截'); this.turnToUnlock('点击新增未解锁拦截');
return; return;
} }
let home_state = {
search_start : this.search_start,
search_content: this.search_content,
scrollHeight: this.scrollHeight
}
this.setHomeState([home_state, this])
this.$router.push('/add'); this.$router.push('/add');
}, },
turnToDetail(content) { turnToDetail(content) {
let home_state = {
search_start : this.search_start,
search_content: this.search_content,
scrollHeight: this.scrollHeight
}
this.setHomeState([home_state, this])
this.$router.push({ name: 'Detail', params: { code_content: content } }); this.$router.push({ name: 'Detail', params: { code_content: content } });
}, },
// //
turnToPage(url) { turnToPage(url) {
let home_state = {
search_start : this.search_start,
search_content: this.search_content,
scrollHeight: this.scrollHeight
}
this.setHomeState([home_state, this])
this.$router.push(url); this.$router.push(url);
}, },
@ -394,6 +429,11 @@ export default {
this.toggleClass(vconDom, 'vconsole-show'); this.toggleClass(vconDom, 'vconsole-show');
this.count = 0; this.count = 0;
} }
},
//
scroll(e) {
this.scrollHeight = this.$refs.list_placeholder.parentNode.parentNode.scrollTop
} }
}, },
created() { created() {
@ -409,6 +449,7 @@ export default {
this.clientHeight = `${document.documentElement.clientHeight}`; this.clientHeight = `${document.documentElement.clientHeight}`;
setHtmlFontSize(); setHtmlFontSize();
}.bind(this); }.bind(this);
this.$refs.list_placeholder.parentNode.parentNode.addEventListener('scroll', this.scroll)
}, },
watch: { watch: {
// `clientHeight` // `clientHeight`
@ -423,6 +464,7 @@ export default {
} else { } else {
this.show_list = JSON.parse(JSON.stringify(this.cache_list)); this.show_list = JSON.parse(JSON.stringify(this.cache_list));
this.cache_list = []; this.cache_list = [];
this.search_content = ''
console.log('搜索阵列关闭,缓存清空完成'); console.log('搜索阵列关闭,缓存清空完成');
} }
}, },