page.js
Former-commit-id: 4e0f06e444ca643ecca5f10ca4faf1931f877a7c [formerly 4e0f06e444ca643ecca5f10ca4faf1931f877a7c [formerly 4e0f06e444ca643ecca5f10ca4faf1931f877a7c [formerly 4e0f06e444ca643ecca5f10ca4faf1931f877a7c [formerly 77feef32db1f491b87cc700bd59e18d4b8c10258 [formerly 2d2d82f6b0eddee2c76d199c3e0c0b6f2ab7b708]]]]] Former-commit-id: 790a48b1edc623424a3bce4c819693f79ba49d1f Former-commit-id: 5a4b94d48f109beef3ca71911912b1c279c8c9a1 Former-commit-id: 621a97129f0f99f8460a7e7c3cb6c187d9eab6cd [formerly 70d7aaa367e319b3fc8e08ffcd4d42495c96f811] Former-commit-id: bd3cbdaa3d8670f75242bc40231ec734c79190cf Former-commit-id: 191790b1402ac56e404d21876fba4c8d7eabccd3 Former-commit-id: 0bc40d5849db8c55f63470ed2ec00a62dfe8b1e2 Former-commit-id: 9e2a855d978994db8257f6386817474584ade274 Former-commit-id: 718ec62c33f2cb9093ed39f78ce0e5d8076bb1d0
This commit is contained in:
@@ -1,10 +1,4 @@
|
|||||||
import get from 'lodash.get'
|
|
||||||
import set from 'lodash.set'
|
|
||||||
import utilLib from '@/libs/util.js'
|
|
||||||
import dbLib from '@/libs/db.js'
|
|
||||||
|
|
||||||
// 模块
|
// 模块
|
||||||
|
|
||||||
import db from './modules/db'
|
import db from './modules/db'
|
||||||
import releases from './modules/releases'
|
import releases from './modules/releases'
|
||||||
import user from './modules/user'
|
import user from './modules/user'
|
||||||
@@ -31,69 +25,5 @@ export default {
|
|||||||
ua,
|
ua,
|
||||||
gray,
|
gray,
|
||||||
page
|
page
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
/**
|
|
||||||
* @class 通用工具
|
|
||||||
* @description 将 state 中某一项存储到数据库 如果已经有的话就更新数据 需要 uuid
|
|
||||||
* @param {Object} state vuex state
|
|
||||||
* @param {String} key key name
|
|
||||||
*/
|
|
||||||
utilVuex2DbByUuid (state, key) {
|
|
||||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
|
||||||
const row = dbLib.get(dbKey).find({uuid: utilLib.cookies.get('uuid')})
|
|
||||||
const value = get(state, key, '')
|
|
||||||
if (row.value()) {
|
|
||||||
row.assign({ value }).write()
|
|
||||||
} else {
|
|
||||||
dbLib.get(dbKey).push({
|
|
||||||
uuid: utilLib.cookies.get('uuid'),
|
|
||||||
value
|
|
||||||
}).write()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @class 通用工具
|
|
||||||
* @description 从数据库取值到 vuex 需要 uuid
|
|
||||||
* @param {Object} state vuex state
|
|
||||||
* @param {Object} param key 键名, defaultValue 取值失败默认值, handleFunction 处理函数
|
|
||||||
*/
|
|
||||||
utilDb2VuexByUuid (state, { key, defaultValue, handleFunction }) {
|
|
||||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
|
||||||
const row = dbLib.get(dbKey).find({uuid: utilLib.cookies.get('uuid')}).value()
|
|
||||||
const handle = handleFunction || (res => res)
|
|
||||||
set(state, key, row ? handle(row.value) : defaultValue)
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @class 通用工具
|
|
||||||
* @description 将 state 中某一项存储到数据库 如果已经有的话就更新数据 不需要 uuid 所有用户共享
|
|
||||||
* @param {Object} state vuex state
|
|
||||||
* @param {String} key key name
|
|
||||||
*/
|
|
||||||
utilVuex2Db (state, key) {
|
|
||||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
|
||||||
const row = dbLib.get(dbKey).find({pub: 'pub'})
|
|
||||||
const value = get(state, key, '')
|
|
||||||
if (row.value()) {
|
|
||||||
row.assign({ value }).write()
|
|
||||||
} else {
|
|
||||||
dbLib.get(dbKey).push({
|
|
||||||
pub: 'pub',
|
|
||||||
value
|
|
||||||
}).write()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @class 通用工具
|
|
||||||
* @description 从数据库取值到 vuex 不需要 uuid 所有用户共享
|
|
||||||
* @param {Object} state vuex state
|
|
||||||
* @param {Object} param key 键名, defaultValue 取值失败时的默认值, handleFunction 处理函数
|
|
||||||
*/
|
|
||||||
utilDb2Vuex (state, { key, defaultValue, handleFunction }) {
|
|
||||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
|
||||||
const row = dbLib.get(dbKey).find({pub: 'pub'}).value()
|
|
||||||
const handle = handleFunction || (res => res)
|
|
||||||
set(state, key, row ? handle(row.value) : defaultValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const pageOpenedDefult = {
|
const openedDefult = {
|
||||||
name: 'index',
|
name: 'index',
|
||||||
meta: {
|
meta: {
|
||||||
title: '首页',
|
title: '首页',
|
||||||
@@ -13,7 +13,7 @@ export default {
|
|||||||
pool: [],
|
pool: [],
|
||||||
// 当前显示的多页面列表
|
// 当前显示的多页面列表
|
||||||
opened: [
|
opened: [
|
||||||
pageOpenedDefult
|
openedDefult
|
||||||
],
|
],
|
||||||
// 当前页面
|
// 当前页面
|
||||||
current: ''
|
current: ''
|
||||||
@@ -88,43 +88,45 @@ export default {
|
|||||||
page.params = params || page.params
|
page.params = params || page.params
|
||||||
page.query = query || page.query
|
page.query = query || page.query
|
||||||
state.opened.splice(index, 1, page)
|
state.opened.splice(index, 1, page)
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
* @description 从数据库载入分页列表
|
* @description 从数据库载入分页列表
|
||||||
* @param {Object} state vuex state
|
* @param {Object} state vuex state
|
||||||
*/
|
*/
|
||||||
openedLoad (state) {
|
async openedLoad (state) {
|
||||||
this.commit('d2admin/utilDb2VuexByUuid', {
|
// store 赋值
|
||||||
key: 'opened',
|
const value = await this.dispatch('d2admin/db/getByUser', {
|
||||||
defaultValue: [
|
dbName: 'sys',
|
||||||
pageOpenedDefult
|
path: 'page.opened',
|
||||||
],
|
defaultValue: []
|
||||||
handleFunction (res) {
|
|
||||||
// 在处理函数中进行数据优化 过滤掉现在已经失效的页签或者已经改变了信息的页签
|
|
||||||
// 以 name 字段为准
|
|
||||||
// 如果页面过多的话可能需要优化算法
|
|
||||||
// 有效列表 1, 1, 0, 1 => 有效, 有效, 失效, 有效
|
|
||||||
const valid = []
|
|
||||||
// 处理数据
|
|
||||||
return res.map(opened => {
|
|
||||||
// 忽略首页
|
|
||||||
if (opened.name === 'index') {
|
|
||||||
valid.push(1)
|
|
||||||
return opened
|
|
||||||
}
|
|
||||||
// 尝试在所有的支持多标签页的页面里找到 name 匹配的页面
|
|
||||||
const find = state.page.pool.find(item => item.name === opened.name)
|
|
||||||
// 记录有效或无效信息
|
|
||||||
valid.push(find ? 1 : 0)
|
|
||||||
// 返回合并后的数据 新的覆盖旧的
|
|
||||||
// 新的数据中一般不会携带 params 和 query, 所以旧的参数会留存
|
|
||||||
return Object.assign({}, opened, find)
|
|
||||||
}).filter((opened, index) => valid[index] === 1)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
// 在处理函数中进行数据优化 过滤掉现在已经失效的页签或者已经改变了信息的页签
|
||||||
|
// 以 name 字段为准
|
||||||
|
// 如果页面过多的话可能需要优化算法
|
||||||
|
// 有效列表 1, 1, 0, 1 => 有效, 有效, 失效, 有效
|
||||||
|
const valid = []
|
||||||
|
// 处理数据
|
||||||
|
state.opened = value.map(opened => {
|
||||||
|
// 忽略首页
|
||||||
|
if (opened.name === 'index') {
|
||||||
|
valid.push(1)
|
||||||
|
return opened
|
||||||
|
}
|
||||||
|
// 尝试在所有的支持多标签页的页面里找到 name 匹配的页面
|
||||||
|
const find = state.pool.find(item => item.name === opened.name)
|
||||||
|
// 记录有效或无效信息
|
||||||
|
valid.push(find ? 1 : 0)
|
||||||
|
// 返回合并后的数据 新的覆盖旧的
|
||||||
|
// 新的数据中一般不会携带 params 和 query, 所以旧的参数会留存
|
||||||
|
return Object.assign({}, opened, find)
|
||||||
|
}).filter((opened, index) => valid[index] === 1)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
@@ -139,8 +141,12 @@ export default {
|
|||||||
newTag.query = query || newTag.query
|
newTag.query = query || newTag.query
|
||||||
// 添加进当前显示的页面数组
|
// 添加进当前显示的页面数组
|
||||||
state.opened.push(newTag)
|
state.opened.push(newTag)
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
@@ -172,8 +178,12 @@ export default {
|
|||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
state.opened.splice(index, 1)
|
state.opened.splice(index, 1)
|
||||||
}
|
}
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
// 最后需要判断是否需要跳到首页
|
// 最后需要判断是否需要跳到首页
|
||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
const { name = '', params = {}, query = {} } = newPage
|
const { name = '', params = {}, query = {} } = newPage
|
||||||
@@ -208,8 +218,12 @@ export default {
|
|||||||
name: pageAim
|
name: pageAim
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
@@ -232,8 +246,12 @@ export default {
|
|||||||
name: pageAim
|
name: pageAim
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
@@ -261,8 +279,12 @@ export default {
|
|||||||
name: pageAim
|
name: pageAim
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @class opened
|
* @class opened
|
||||||
@@ -272,8 +294,12 @@ export default {
|
|||||||
*/
|
*/
|
||||||
closeAll (state, vm) {
|
closeAll (state, vm) {
|
||||||
state.opened.splice(1)
|
state.opened.splice(1)
|
||||||
// 更新设置到数据库
|
// 持久化
|
||||||
this.commit('d2admin/utilVuex2DbByUuid', 'opened')
|
this.commit('d2admin/db/setByUser', {
|
||||||
|
dbName: 'sys',
|
||||||
|
path: 'page.opened',
|
||||||
|
value: state.opened
|
||||||
|
})
|
||||||
// 关闭所有的标签页后需要判断一次现在是不是在首页
|
// 关闭所有的标签页后需要判断一次现在是不是在首页
|
||||||
if (vm.$route.name !== 'index') {
|
if (vm.$route.name !== 'index') {
|
||||||
vm.$router.push({
|
vm.$router.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user