no message
Former-commit-id: 13cddc6e80583fea2d48d618c9ff9de4d8e7dfea
This commit is contained in:
@@ -10,6 +10,7 @@ import ua from './modules/ua'
|
||||
import gray from './modules/gray'
|
||||
import page from './modules/page'
|
||||
import transition from './modules/transition'
|
||||
import search from './modules/search'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
@@ -25,6 +26,7 @@ export default {
|
||||
ua,
|
||||
gray,
|
||||
page,
|
||||
transition
|
||||
transition,
|
||||
search
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
import util from '@/libs/util.js'
|
||||
import { AccountLogin } from '@/api/sys/login'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
actions: {
|
||||
/**
|
||||
* @description 登陆
|
||||
* @description 登录
|
||||
* @param {Object} param context
|
||||
* @param {Object} param vm {Object} vue 实例
|
||||
* @param {Object} param username {String} 用户账号
|
||||
* @param {Object} param password {String} 密码
|
||||
* @param {Object} param route {Object} 登录成功后定向的路由对象
|
||||
*/
|
||||
login ({ commit }, { vm, username, password }) {
|
||||
login ({
|
||||
commit
|
||||
}, {
|
||||
vm,
|
||||
username,
|
||||
password,
|
||||
route = {
|
||||
name: 'index'
|
||||
}
|
||||
}) {
|
||||
// 开始请求登录接口
|
||||
vm.$axios({
|
||||
method: 'post',
|
||||
url: '/login',
|
||||
data: {
|
||||
username,
|
||||
password
|
||||
}
|
||||
AccountLogin({
|
||||
username,
|
||||
password
|
||||
})
|
||||
.then(res => {
|
||||
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
||||
@@ -26,27 +33,29 @@ export default {
|
||||
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
||||
// token 代表用户当前登录状态 建议在网络请求中携带 token
|
||||
// 如有必要 token 需要定时更新,默认保存一天
|
||||
util.cookies.set('uuid', res.data.uuid)
|
||||
util.cookies.set('token', res.data.token)
|
||||
util.cookies.set('uuid', res.uuid)
|
||||
util.cookies.set('token', res.token)
|
||||
// 设置 vuex 用户信息
|
||||
commit('d2admin/user/set', {
|
||||
name: res.data.name
|
||||
name: res.name
|
||||
}, { root: true })
|
||||
// 用户登陆后从持久化数据加载一系列的设置
|
||||
// 用户登录后从持久化数据加载一系列的设置
|
||||
commit('load')
|
||||
// 跳转路由
|
||||
vm.$router.push({
|
||||
name: 'index'
|
||||
})
|
||||
// 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
|
||||
const path = util.cookies.get('redirect')
|
||||
// 根据是否存有重定向页面判断如何重定向
|
||||
vm.$router.replace(path ? { path } : route)
|
||||
// 删除 cookie 中保存的重定向页面
|
||||
util.cookies.remove('redirect')
|
||||
})
|
||||
.catch(err => {
|
||||
console.group('登陆结果')
|
||||
console.group('登录结果')
|
||||
console.log('err: ', err)
|
||||
console.groupEnd()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 注销用户并返回登陆页面
|
||||
* @description 注销用户并返回登录页面
|
||||
* @param {Object} param context
|
||||
* @param {Object} param vm {Object} vue 实例
|
||||
* @param {Object} param confirm {Boolean} 是否需要确认
|
||||
@@ -87,7 +96,7 @@ export default {
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* @description 用户登陆后从持久化数据加载一系列的设置
|
||||
* @description 用户登录后从持久化数据加载一系列的设置
|
||||
* @param {Object} state vuex state
|
||||
*/
|
||||
load (state) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import { httpGet } from '@/api/sys/http'
|
||||
import semver from 'semver'
|
||||
import util from '@/libs/util.js'
|
||||
import setting from '@/setting.js'
|
||||
@@ -19,7 +19,7 @@ export default {
|
||||
* @param {Object} param context
|
||||
*/
|
||||
checkUpdate ({ state, commit }) {
|
||||
axios.get(setting.releases.api)
|
||||
httpGet(setting.releases.api)
|
||||
.then(res => {
|
||||
let versionGet = res.tag_name
|
||||
const update = semver.lt(state.version, versionGet)
|
||||
@@ -43,7 +43,7 @@ export default {
|
||||
versionShow (state) {
|
||||
util.log.capsule('D2Admin', `v${state.version}`)
|
||||
console.log('Github https://github.com/d2-projects/d2-admin')
|
||||
console.log('Doc http://d2admin.fairyever.com/zh/')
|
||||
console.log('Doc https://d2-projects.github.io/d2-admin-doc/zh/')
|
||||
},
|
||||
/**
|
||||
* @description 设置是否有新的 D2Admin 版本
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import setting from '@/setting.js'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
// 搜索面板激活状态
|
||||
active: false,
|
||||
// 快捷键
|
||||
hotkey: {
|
||||
open: setting.hotkey.search.open,
|
||||
close: setting.hotkey.search.close
|
||||
},
|
||||
// 所有可以搜索的页面
|
||||
pool: []
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* @description 切换激活状态
|
||||
* @param {Object} state vuex state
|
||||
*/
|
||||
toggle (state) {
|
||||
state.active = !state.active
|
||||
},
|
||||
/**
|
||||
* @description 设置激活模式
|
||||
* @param {Object} state vuex state
|
||||
* @param {Boolean} active active
|
||||
*/
|
||||
set (state, active) {
|
||||
state.active = active
|
||||
},
|
||||
/**
|
||||
* @description 初始化
|
||||
* @param {Object} state vuex state
|
||||
* @param {Array} menu menu
|
||||
*/
|
||||
init (state, menu) {
|
||||
const pool = []
|
||||
const push = function (menu, titlePrefix = []) {
|
||||
menu.forEach(m => {
|
||||
if (m.children) {
|
||||
push(m.children, [ ...titlePrefix, m.title ])
|
||||
} else {
|
||||
pool.push({
|
||||
...m,
|
||||
fullTitle: [ ...titlePrefix, m.title ].join(' / ')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
push(menu)
|
||||
state.pool = pool
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user