account
Former-commit-id: 1f42a274955daf53cf70bd00781efa8c9a30aecd [formerly 1f42a274955daf53cf70bd00781efa8c9a30aecd [formerly 1f42a274955daf53cf70bd00781efa8c9a30aecd [formerly 1f42a274955daf53cf70bd00781efa8c9a30aecd [formerly 91e8a0baee40147d462bc980d9bebf36d6bceb44 [formerly af707f999d1a6d9844532a7e39998fd582ef66a1]]]]] Former-commit-id: 8b155f33da09f8a27b1b1e2fa7cbf05e63464ce9 Former-commit-id: 8407ff43bd64f93bdb42d23bdaa3a1ce5463b28a Former-commit-id: 37877392735a64d5923e5b792086bff14ff8073e [formerly 57fa25c15aa9de84e0f8d8ae3b70aae6fc3f1789] Former-commit-id: 620a5ea3e8fa2745b505b844dbacf9674f01e4dc Former-commit-id: ea6030ce9cba3cc0ab705466f3f0fd5c20d6e02e Former-commit-id: 82a7fbcc85c93771fd881d19ea333ce1c39a5238 Former-commit-id: 4f84af65b78b05ca8a6129947daee72f75721f0c Former-commit-id: d0cb9cc7318f6fb69595e188825e26bc8eb2d3bc
This commit is contained in:
@@ -19,7 +19,7 @@ export default {
|
|||||||
])
|
])
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('d2admin', [
|
...mapActions('d2admin/account', [
|
||||||
'logout'
|
'logout'
|
||||||
]),
|
]),
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ new Vue({
|
|||||||
// 展示系统信息
|
// 展示系统信息
|
||||||
util.showInfo()
|
util.showInfo()
|
||||||
// 用户登陆后从数据库加载一系列的设置
|
// 用户登陆后从数据库加载一系列的设置
|
||||||
this.$store.commit('d2admin/loginSuccessLoad')
|
this.$store.commit('d2admin/account/load')
|
||||||
// 初始化全屏监听
|
// 初始化全屏监听
|
||||||
this.fullscreenListenerInit()
|
this.fullscreenListenerInit()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export default {
|
|||||||
particlesJS('login', config)
|
particlesJS('login', config)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('d2admin', [
|
...mapActions('d2admin/account', [
|
||||||
'login'
|
'login'
|
||||||
]),
|
]),
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2eb4adc620a4ffb94292cc6c574b7290fccf8356
|
4ece1c4e7a74f137bfa094cbb973d62c91bde205
|
||||||
115
src/store/modules/d2admin/modules/account.js
Normal file
115
src/store/modules/d2admin/modules/account.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import util from '@/libs/util.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
actions: {
|
||||||
|
/**
|
||||||
|
* 登陆
|
||||||
|
* @param {Object} param context
|
||||||
|
* @param {Object} param vm {Object} vue 实例
|
||||||
|
* @param {Object} param username {String} 用户账号
|
||||||
|
* @param {Object} param password {String} 密码
|
||||||
|
*/
|
||||||
|
login ({ commit }, { vm, username, password }) {
|
||||||
|
// 开始请求登录接口
|
||||||
|
vm.$axios({
|
||||||
|
method: 'post',
|
||||||
|
url: '/login',
|
||||||
|
data: {
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
||||||
|
// 整个系统依赖这两个数据进行校验和存储
|
||||||
|
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
||||||
|
// token 代表用户当前登录状态 建议在网络请求中携带 token
|
||||||
|
// 如有必要 token 需要定时更新,默认保存一天
|
||||||
|
util.cookies.set('uuid', res.data.uuid)
|
||||||
|
util.cookies.set('token', res.data.token)
|
||||||
|
// 设置 vuex 用户信息
|
||||||
|
commit('d2admin/user/set', {
|
||||||
|
name: res.data.name
|
||||||
|
}, {
|
||||||
|
root: true
|
||||||
|
})
|
||||||
|
// 用户登陆后从数据库加载一系列的设置
|
||||||
|
commit('d2admin/account/load', null, {
|
||||||
|
root: true
|
||||||
|
})
|
||||||
|
// 跳转路由
|
||||||
|
vm.$router.push({
|
||||||
|
name: 'index'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.group('登陆结果')
|
||||||
|
console.log('err: ', err)
|
||||||
|
console.groupEnd()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 注销用户并返回登陆页面
|
||||||
|
* @param {Object} param context
|
||||||
|
* @param {Object} param vm {Object} vue 实例
|
||||||
|
* @param {Object} param confirm {Boolean} 是否需要确认
|
||||||
|
*/
|
||||||
|
logout ({ commit }, { vm, confirm }) {
|
||||||
|
/**
|
||||||
|
* @description 注销
|
||||||
|
*/
|
||||||
|
function logout () {
|
||||||
|
// 删除cookie
|
||||||
|
util.cookies.remove('token')
|
||||||
|
util.cookies.remove('uuid')
|
||||||
|
// 跳转路由
|
||||||
|
vm.$router.push({
|
||||||
|
name: 'login'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 判断是否需要确认
|
||||||
|
if (confirm) {
|
||||||
|
commit('d2admin/grayModeSet', true, {
|
||||||
|
root: true
|
||||||
|
})
|
||||||
|
vm.$confirm('注销当前账户吗? 打开的标签页和用户设置将会被保存。', '确认操作', {
|
||||||
|
confirmButtonText: '确定注销',
|
||||||
|
cancelButtonText: '放弃',
|
||||||
|
type: 'warning'
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
commit('d2admin/grayModeSet', false, {
|
||||||
|
root: true
|
||||||
|
})
|
||||||
|
logout()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
commit('d2admin/grayModeSet', false, {
|
||||||
|
root: true
|
||||||
|
})
|
||||||
|
vm.$message('放弃注销用户')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
logout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
/**
|
||||||
|
* @class ...
|
||||||
|
* @description 用户登陆后从数据库加载一系列的设置
|
||||||
|
* @param {Object} state vuex state
|
||||||
|
*/
|
||||||
|
load (state) {
|
||||||
|
// DB -> store 加载用户名
|
||||||
|
this.commit('d2admin/user/load')
|
||||||
|
// DB -> store 加载主题
|
||||||
|
this.commit('d2admin/theme/load')
|
||||||
|
// DB -> store 数据库加载上次退出时的多页列表
|
||||||
|
this.commit('d2admin/pageOpenedListLoad')
|
||||||
|
// DB -> store 数据库加载这个用户之前设置的侧边栏折叠状态
|
||||||
|
this.commit('d2admin/menu/asideCollapseLoad')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,10 +39,10 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* @description 添加一个日志
|
* @description 添加一个日志
|
||||||
* @param {Object} state vuex state
|
* @param {Object} state vuex state
|
||||||
* @param {Object} param type {String}: 类型
|
* @param {Object} param type {String} 类型
|
||||||
* @param {Object} param err {Error}: 错误对象
|
* @param {Object} param err {Error} 错误对象
|
||||||
* @param {Object} param vm {Object}: vue 实例
|
* @param {Object} param vm {Object} vue 实例
|
||||||
* @param {Object} param info {String}: 信息
|
* @param {Object} param info {String} 信息
|
||||||
*/
|
*/
|
||||||
add ({ state, rootState }, { type, err, vm, info }) {
|
add ({ state, rootState }, { type, err, vm, info }) {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import util from '@/libs/util.js'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 检查路径是否存在 不存在的话初始化
|
* @description 检查路径是否存在 不存在的话初始化
|
||||||
* @param {Object} param dbName {String}: 数据库名称
|
* @param {Object} param dbName {String} 数据库名称
|
||||||
* @param {Object} param path {String}: 路径
|
* @param {Object} param path {String} 路径
|
||||||
* @param {Object} param defaultValue {*}: 初始化默认值
|
* @param {Object} param defaultValue {*} 初始化默认值
|
||||||
*/
|
*/
|
||||||
function pathInit ({
|
function pathInit ({
|
||||||
dbName = 'sys',
|
dbName = 'sys',
|
||||||
@@ -23,8 +23,8 @@ function pathInit ({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 检查路径下是否有当前用户的档案
|
* @description 检查路径下是否有当前用户的档案
|
||||||
* @param {Object} param dbName {String}: 数据库名称
|
* @param {Object} param dbName {String} 数据库名称
|
||||||
* @param {Object} param path {String}: 路径
|
* @param {Object} param path {String} 路径
|
||||||
*/
|
*/
|
||||||
function isRowExistByUser ({
|
function isRowExistByUser ({
|
||||||
dbName = 'sys',
|
dbName = 'sys',
|
||||||
@@ -51,9 +51,9 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* @description 将数据存储到指定位置 [用户存储区域]
|
* @description 将数据存储到指定位置 [用户存储区域]
|
||||||
* @param {Object} state vuex state
|
* @param {Object} state vuex state
|
||||||
* @param {Object} param dbName {String}: 数据库名称
|
* @param {Object} param dbName {String} 数据库名称
|
||||||
* @param {Object} param path {String}: 存储路径
|
* @param {Object} param path {String} 存储路径
|
||||||
* @param {Object} param value {*}: 需要存储的值
|
* @param {Object} param value {*} 需要存储的值
|
||||||
*/
|
*/
|
||||||
dbValueSetByUser (state, {
|
dbValueSetByUser (state, {
|
||||||
dbName = 'sys',
|
dbName = 'sys',
|
||||||
@@ -81,9 +81,9 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* @description 从系统存储中获取数据 [用户存储区域]
|
* @description 从系统存储中获取数据 [用户存储区域]
|
||||||
* @param {Object} state vuex state
|
* @param {Object} state vuex state
|
||||||
* @param {Object} param dbName {String}: 数据库名称
|
* @param {Object} param dbName {String} 数据库名称
|
||||||
* @param {Object} param path {String}: 存储路径
|
* @param {Object} param path {String} 存储路径
|
||||||
* @param {Object} param defaultValue {*}: 取值失败的默认值
|
* @param {Object} param defaultValue {*} 取值失败的默认值
|
||||||
*/
|
*/
|
||||||
dbValueGetByUser (context, {
|
dbValueGetByUser (context, {
|
||||||
dbName = 'sys',
|
dbName = 'sys',
|
||||||
|
|||||||
Reference in New Issue
Block a user