Commit 1e375067 by liimin

fixed

1 parent bd950fbb
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-26 18:02:49
* @Last Modified by: limin
* @Last Modified time: 2019-09-10 18:09:16
* @Last Modified time: 2019-09-16 14:45:51
*/
import MD5 from 'js-md5'
const secret = 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b'
......@@ -10,14 +10,20 @@ const sign = (params, noSignAttr = []) => {
delete params.sign
const keys = Object.keys(params).sort()
var str = []
var obj = null
for (const key in params) {
if (typeof params[key] === 'object') params[key] = JSON.stringify(params[key])
obj = params[key]
if (obj === null) {
obj = ''
} else if (typeof obj === 'object') {
obj = JSON.stringify(obj)
}
params[key] = obj
}
keys.forEach(e => {
!noSignAttr.includes(e) && str.push(e + params[e])
})
params.sign = MD5(secret + str.join('') + secret)
// console.log(params)
return params
}
export default sign
......@@ -218,6 +218,13 @@
color: $theme-aside-item-color-active;
}
}
&:nth-child(1).is-active {
color: $theme-aside-item-color-active;
background: $theme-aside-item-background-color;
i {
color: $theme-aside-item-color-active;
}
}
}
}
.el-submenu {
......
<template>
<div class="personal">
<div class="personal-panel">
<div class="personal-desc" v-if="user">
<div
class="personal-desc"
v-if="user"
>
<div class="avatar-container">
<el-avatar
:size="'large'"
......@@ -13,7 +16,7 @@
</div>
<div class="registe-info">
<span class="registe-info">
<d2-el-icon name="time"/>
<d2-el-icon name="time" />
有效期:{{user.validTime || '未知' }}
</span>
</div>
......@@ -25,26 +28,46 @@
</div>-->
<div class="main-operation">
<span class="main-operation-item">
<el-button size="small" icon="el-icon-user" @click="openPersonalDialog"> 个人信息</el-button>
<el-button
size="small"
icon="el-icon-user"
@click="personalVisible = true"
> 个人信息</el-button>
</span>
<span class="main-operation-item">
<el-button size="small" icon="el-icon-key" @click="openPasswordDialog"> 修改密码</el-button>
<el-button
size="small"
icon="el-icon-key"
@click="passwordVisible = true"
> 修改密码</el-button>
</span>
</div>
<div class="other-operation" @click="clear">
<div
class="other-operation"
@click="clear"
>
<div class="other-operation-item">
<d2-el-icon name="delete"/>
<d2-el-icon name="delete" />
清空本地缓存
</div>
</div>
<div class="personal-footer" @click="logOut">
<div
class="personal-footer"
@click="logOut"
>
<el-button type="text">
<d2-el-icon name="switch-button"/> 退出
<d2-el-icon name="switch-button" /> 退出
</el-button>
</div>
</div>
<personal-dialog :visible="personalVisible" :user="info" />
<password-dialog :visible="passwordVisible" :user="info" />
<personal-dialog
:visible="personalVisible"
:user="info"
/>
<password-dialog
:visible="passwordVisible"
:user="info"
/>
</div>
</template>
......@@ -97,6 +120,7 @@ export default {
// await this.$store.commit('d2admin/gray/set', false)
// await this.$store.dispatch('d2admin/user/set', {})
await this.logout()
await this.$store.commit('d2admin/page/setCurrent', '')
this.$router.push('/login')
// })
// .catch(() => {
......@@ -119,6 +143,7 @@ export default {
)
.then(async() => {
await this.$store.commit('d2admin/gray/set', false)
// await this.$store.commit('d2admin/page/setCurrent', '')
localStorage.clear()
window.location.reload()
})
......@@ -150,13 +175,6 @@ export default {
reject(new Error('错误'))
})
})
},
// 打开个人信息弹出框
openPersonalDialog: function() {
this.personalVisible = true
},
openPasswordDialog: function() {
this.passwordVisible = true
}
}
}
......@@ -236,7 +254,7 @@ export default {
margin-right: 1px;
font-size: 14px;
text-align: center;
padding:2px 0;
padding: 2px 0;
border-color: rgba(180, 190, 190, 0.2);
border-top-width: 1px;
border-top-style: solid;
......
import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
import util from '@/libs/util'
const isDev = process.env.NODE_ENV === 'development'
const adapter = new LocalStorage(`${process.env.VUE_APP_STORAGE_PREFIX}-${process.env.VUE_APP_VERSION}`, {
serialize: (data) => escape(JSON.stringify(data)),
deserialize: (data) => JSON.parse(unescape(data))
serialize: (data) => isDev ? JSON.stringify(data) : escape(JSON.stringify(data)),
deserialize: (data) => isDev ? JSON.parse(data) : JSON.parse(unescape(data))
})
const db = low(adapter)
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-27 19:16:26
* @Last Modified by: limin
* @Last Modified time: 2019-09-15 19:42:01
* @Last Modified time: 2019-09-16 14:13:22
*/
const permision = {}
/**
......
......@@ -39,7 +39,7 @@ new Vue({
// this.$store.commit('d2admin/search/init', menuHeader)
// },
mounted() {
// Vue.config.devtools = true
Vue.config.devtools = true
// 展示系统信息
this.$store.commit('d2admin/releases/versionShow')
// 用户登录后从数据库加载一系列的设置
......
......@@ -44,20 +44,17 @@ function errorLog(error) {
// 创建一个 axios 实例
const service = axios.create({
baseURL: process.env.VUE_APP_API,
timeout: 5000 // 请求超时时间
timeout: 5000, // 请求超时时间
transformRequest: [function(data) {
return qs.stringify(data)
}]
})
// 请求拦截器
service.interceptors.request.use(
config => {
config.transformRequest = [function(data) {
return qs.stringify(data)
}]
return new Promise(async resolve => {
const {
url,
params
} = config
const { url, params } = config
await store.commit('d2admin/loading/set', true)
const uuid = util.cookies.get('uuid')
// 如果请求链接不在排除列表 (排除列表: 登录 基础数据) 并且cookie 过期(判断是否长时间未操作)
......@@ -96,7 +93,7 @@ service.interceptors.response.use(
return data
default:
// 不是正确的 code
errorCreate(`code:${code} ${dataAxios.message}`)
errorCreate(`${dataAxios.message}`)
break
}
},
......
......@@ -23,6 +23,13 @@ const router = new VueRouter({
routes
})
const setCurrent = path => {
return new Promise(async resolve => {
path !== '/login' && await store.dispatch('d2admin/page/currentSet', path)
resolve()
})
}
/**
* 路由拦截
* 权限验证
......@@ -33,6 +40,8 @@ router.beforeEach(async(to, from, next) => {
await store.dispatch('d2admin/page/isLoaded')
// 确认已经加载组件尺寸设置 https://github.com/d2-projects/d2-admin/issues/198
await store.dispatch('d2admin/size/isLoaded')
// 设置当前页 下次登录 默认打开此页面
await setCurrent(to.fullPath)
// 进度条
NProgress.start()
// 关闭搜索面板
......
......@@ -18,7 +18,7 @@ const frameIn = [{
* 首页
*/
export const home = {
path: 'index',
path: '/index',
name: 'index',
icon: 'monitor',
meta: {
......
......@@ -29,6 +29,7 @@ export default {
: _.cloneDeep(data.authes)
await dispatch('d2admin/auth/set', authes, { root: true })
// // 设置 vuex 用户信息
delete data.authes
await dispatch('d2admin/user/set', data, { root: true })
// // 强制初始化基础数据
dispatch('d2admin/base/init', null, { root: true })
......
import router from '@/router'
// import setting from '@/setting.js'
import { home, localRoutes } from '@/router/routes'
const INDEX_PATH = '/index'
home.fullPath = INDEX_PATH
// 判定是否需要缓存
const isKeepAlive = data => _.get(data, 'meta.cache', false)
const setIcon = meta => (meta.icon = localRoutes[meta.authId].icon)
export default {
namespaced: true,
state: {
......@@ -12,7 +14,7 @@ export default {
pool: [],
// 当前显示的多页面列表
opened: [home],
// 已经加载多标签页数据 https://github.com/d2-projects/d2-admin/issues/201
// 已经加载多标签页数据
openedLoaded: false,
// 当前页面
current: '',
......@@ -21,7 +23,7 @@ export default {
},
actions: {
/**
* @description 确认已经加载多标签页数据 https://github.com/d2-projects/d2-admin/issues/201
* @description 确认已经加载多标签页数据
* @param {Object} context
*/
isLoaded({ state }) {
......@@ -42,7 +44,7 @@ export default {
openedLoad({ state, commit, dispatch }) {
return new Promise(async resolve => {
// store 赋值
const value = await dispatch(
let value = await dispatch(
'd2admin/db/get',
{
dbName: 'sys',
......@@ -52,6 +54,13 @@ export default {
},
{ root: true }
)
if (value[0].fullPath !== INDEX_PATH) {
const index = value.some(page => page.fullPath === INDEX_PATH)
if (index) {
value = value.filter(page => page.fullPath !== INDEX_PATH)
}
value.unshift(home)
}
// 在处理函数中进行数据优化 过滤掉现在已经失效的页签或者已经改变了信息的页签
// 以 fullPath 字段为准
// 如果页面过多的话可能需要优化算法
......@@ -64,7 +73,7 @@ export default {
state.opened = value
.map(opened => {
// 忽略首页
if (opened.fullPath === '/index') {
if (opened.fullPath === INDEX_PATH) {
valid.push(1)
setIcon(opened.meta)
return opened
......@@ -199,7 +208,7 @@ export default {
})
}
}
commit('currentSet', fullPath)
// dispatch('currentSet', fullPath)
// end
resolve()
})
......@@ -331,15 +340,14 @@ export default {
* @description 关闭所有 tag
* @param {Object} context
*/
closeAll({ state, dispatch }) {
closeAll({ state, dispatch, commit }) {
return new Promise(async resolve => {
// 删除打开的页面 并在缓存设置中删除
await dispatch('_splice', { index: 1 })
await dispatch('closeOpened')
// dispatch('currentSet', _index)
// 持久化
await dispatch('opend2db')
const _index = '/index'
state.current = _index
router.replace(_index)
// await dispatch('opend2db')
router.replace(INDEX_PATH)
// end
resolve()
})
......@@ -349,7 +357,7 @@ export default {
* @description 私有公共方法
* @param {Object} context
*/
async _do({ state, dispatch }, { pageSelect, call }) {
async _do({ state, dispatch, commit }, { pageSelect, call }) {
return new Promise(async resolve => {
const pageAim = pageSelect || state.current
let currentIndex = 0
......@@ -360,7 +368,7 @@ export default {
})
await call(currentIndex)
// 设置当前的页面
state.current = pageAim
// dispatch('currentSet', pageAim)
if (router.app.$route.fullPath !== pageAim) {
router.push(pageAim)
}
......@@ -387,8 +395,66 @@ export default {
state.opened = _clone
resolve()
})
},
/**
* @class current
* @description 设置当前激活的页面 fullPath
* @param {Object} state state
* @param {String} fullPath new fullPath
*/
currentSet({ state, dispatch, commit }, fullPath) {
return new Promise(async resolve => {
await commit('setCurrent', fullPath)
// 设置数据
dispatch(
'd2admin/db/set',
{
dbName: 'sys',
path: 'page.current',
value: state.current,
user: true
},
{ root: true }
)
resolve()
})
},
/**
* @class current
* @description 设置当前激活的页面 fullPath
* @param {Object} state state
* @param {String} fullPath new fullPath
*/
async currentGet({ state, dispatch }, fullPath) {
return new Promise(async resolve => {
const _current = state.current || await dispatch(
'd2admin/db/get',
{
dbName: 'sys',
path: 'page.current',
defaultValue: INDEX_PATH,
user: true
},
{ root: true }
)
resolve(_current)
})
},
/**
* @class closeOpened
* @description 关闭所有 打开的页面
* @param {Object} context
*/
closeOpened({ state, dispatch, commit }) {
return new Promise(async resolve => {
// 删除打开的页面 并在缓存设置中删除
await dispatch('_splice', { index: 1 })
// 持久化
await dispatch('opend2db')
// end
resolve()
})
}
},
mutations: {
/**
......@@ -433,15 +499,6 @@ export default {
state.keepAlive = []
},
/**
* @class current
* @description 设置当前激活的页面 fullPath
* @param {Object} state state
* @param {String} fullPath new fullPath
*/
currentSet(state, fullPath) {
state.current = fullPath
},
/**
* @class pool
* @description 保存 pool (候选池)
* @param {Object} state state
......@@ -464,6 +521,12 @@ export default {
}
push(routes)
state.pool = pool
},
setCurrent(state, path) {
return new Promise(resolve => {
state.current = path
resolve()
})
}
}
}
......@@ -54,19 +54,19 @@
</el-form-item>
<el-form-item label="发送结点序列" prop="sendSequence">
<el-input v-model="editForm.sendSequence" maxlength="8"
:show-word-limit="true" placeholder="请输入发送结点序列" clearable></el-input>
:show-word-limit="true" placeholder="请输入发送结点序列" oninput ="value=value.replace(/[^\d^\.]+/g,'')" clearable></el-input>
</el-form-item>
<el-form-item label="发送节点端口" prop="sendPort">
<el-input v-model="editForm.sendPort" maxlength="8"
:show-word-limit="true" placeholder="请输入发送节点端口" clearable></el-input>
:show-word-limit="true" placeholder="请输入发送节点端口" oninput ="value=value.replace(/[^\d]/g,'')" clearable></el-input>
</el-form-item>
<el-form-item label="网关地址" prop="gatewayUrl">
<el-input v-model="editForm.gatewayUrl" maxlength="16"
:show-word-limit="true" placeholder="请输入网关地址" clearable></el-input>
:show-word-limit="true" placeholder="请输入网关地址" oninput ="value=value.replace(/[^\d^\.]+/g,'')" clearable></el-input>
</el-form-item>
<el-form-item label="网关端口" prop="gatewayPort">
<el-input v-model="editForm.gatewayPort" maxlength="8"
:show-word-limit="true" placeholder="请输入网关端口" clearable></el-input>
:show-word-limit="true" placeholder="请输入网关端口" oninput ="value=value.replace(/[^\d]/g,'')" clearable></el-input>
</el-form-item>
</el-form>
<div slot="footer">
......@@ -116,7 +116,8 @@ export default {
{ required: true, message: '请输入发送节点端口', trigger: 'blur' }
],
gatewayUrl: [
{ required: true, message: '请输入网关地址', trigger: 'blur' }
{ required: true, message: '请输入网关地址', trigger: 'blur' },
{ pattern: /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/, message: '请输入合法的网关地址', trigger: 'blur' }
],
gatewayPort: [
{ required: true, message: '请输入网关端口', trigger: 'blur' }
......
......@@ -126,7 +126,11 @@ export default {
clearInterval(this.timeInterval)
},
methods: {
...mapActions('d2admin/account', ['login']),
...mapActions({
login: 'd2admin/account/login',
current: 'd2admin/page/currentGet'
}),
// ...mapActions('d2admin/account', ['login']),
refreshTime() {
this.time = dayjs().format('HH:mm:ss')
},
......@@ -145,7 +149,10 @@ export default {
// 具体需要传递的数据请自行修改代码
this.login(_p)
.then(() => this.$store.dispatch('d2admin/auth/init'))
.then(_ => this.$router.replace(this.$route.query.redirect || '/'))
.then(async _ => {
const _current = await this.current()
this.$router.replace(this.$route.query.redirect || _current)
})
}
})
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!