feat: 新增登录注销功能,调整接口与配置
1. 新增项目logo文件 2. 调整API基础地址与开发代理配置 3. 添加多语言登录相关文案 4. 新增登录注销API接口 5. 重构请求与账号登录注销逻辑 6. 更新文档与菜单store状态
This commit is contained in:
2
.env
2
.env
@@ -4,7 +4,7 @@
|
|||||||
VUE_APP_TITLE=D2Admin
|
VUE_APP_TITLE=D2Admin
|
||||||
|
|
||||||
# 网络请求公用地址
|
# 网络请求公用地址
|
||||||
VUE_APP_API=/api/
|
VUE_APP_API=/background/v1/
|
||||||
|
|
||||||
# 仓库地址
|
# 仓库地址
|
||||||
VUE_APP_REPO=https://github.com/d2-projects/d2-admin
|
VUE_APP_REPO=https://github.com/d2-projects/d2-admin
|
||||||
|
|||||||
@@ -2,3 +2,6 @@
|
|||||||
|
|
||||||
# 页面 title 前缀
|
# 页面 title 前缀
|
||||||
VUE_APP_TITLE=D2Admin Dev
|
VUE_APP_TITLE=D2Admin Dev
|
||||||
|
|
||||||
|
# 后台接口地址(代理目标)
|
||||||
|
VUE_APP_BASE_URL=http://127.0.0.1:8787/background/
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> **搬迁源**:`D:\code\company\SCTMES_MES_V5\vue-app`
|
> **搬迁源**:`D:\code\company\SCTMES_MES_V5\vue-app`
|
||||||
> **搬迁目标**:`d:\code\mes\mes-ui`
|
> **搬迁目标**:`d:\code\mes\mes-ui`
|
||||||
> **状态**:⏳ 待审阅,审阅通过后执行搬迁
|
> **状态**:✅ 已完成(2026-05-26)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
### 2.5 i18n 语言包
|
### 2.5 i18n 语言包
|
||||||
|
|
||||||
**i18n key 前缀**:`page.system_settings.system_monitoring.system.login`
|
**i18n key 前缀**:`page.system_administration.system_monitoring.login`
|
||||||
|
|
||||||
| key | 中文 | 英文 |
|
| key | 中文 | 英文 |
|
||||||
|-----|------|------|
|
|-----|------|------|
|
||||||
@@ -104,17 +104,15 @@
|
|||||||
|
|
||||||
**搬迁操作**:
|
**搬迁操作**:
|
||||||
|
|
||||||
1. 在 `src/locales/zh-chs.json` 的 `page.system.system_monitoring` 下新增:
|
1. 在 `src/locales/zh-chs.json` 的 `page.system_administration.system_monitoring` 下新增:
|
||||||
```json
|
```json
|
||||||
"login": {
|
"login": {
|
||||||
"time_is_most_precious": "时间是一切财富中最宝贵的财富",
|
"time_is_most_precious": "时间是一切财富中最宝贵的财富",
|
||||||
"username": "用户名",
|
"username": "用户名",
|
||||||
"password": "密码",
|
"password": "密码",
|
||||||
"login": "登录",
|
"login": "登录",
|
||||||
"quick_select_user": "快速选择用户",
|
|
||||||
"please_enter_username": "请输入用户名",
|
"please_enter_username": "请输入用户名",
|
||||||
"please_enter_password": "请输入密码",
|
"please_enter_password": "请输入密码",
|
||||||
"please_enter_code": "请输入验证码",
|
|
||||||
"dev_version": "开发版本",
|
"dev_version": "开发版本",
|
||||||
"test_version": "测试版本",
|
"test_version": "测试版本",
|
||||||
"form_validation_failed": "表单校验失败,请检查"
|
"form_validation_failed": "表单校验失败,请检查"
|
||||||
|
|||||||
BIN
public/image/logo/sc_logo.png
Normal file
BIN
public/image/logo/sc_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.3 KiB |
@@ -125,13 +125,15 @@ function createRequest (service) {
|
|||||||
const token = util.cookies.get('token')
|
const token = util.cookies.get('token')
|
||||||
const configDefault = {
|
const configDefault = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: token,
|
|
||||||
'Content-Type': get(config, 'headers.Content-Type', 'application/json')
|
'Content-Type': get(config, 'headers.Content-Type', 'application/json')
|
||||||
},
|
},
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
baseURL: process.env.VUE_APP_API,
|
baseURL: process.env.VUE_APP_API,
|
||||||
data: {}
|
data: {}
|
||||||
}
|
}
|
||||||
|
if (token) {
|
||||||
|
configDefault.headers.Authorization = 'Bearer ' + token
|
||||||
|
}
|
||||||
const option = merge(configDefault, config)
|
const option = merge(configDefault, config)
|
||||||
// 处理 get 请求的参数
|
// 处理 get 请求的参数
|
||||||
// 请根据实际需要修改
|
// 请根据实际需要修改
|
||||||
@@ -141,7 +143,7 @@ function createRequest (service) {
|
|||||||
}
|
}
|
||||||
// 当需要以 form 形式发送时 处理发送的数据
|
// 当需要以 form 形式发送时 处理发送的数据
|
||||||
// 请根据实际需要修改
|
// 请根据实际需要修改
|
||||||
if (!isEmpty(option.data) && option.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
|
if (!isEmpty(option.data) && option.headers['Content-Type'] === 'application/x-www-form-urlen·coded') {
|
||||||
option.data = stringify(option.data)
|
option.data = stringify(option.data)
|
||||||
}
|
}
|
||||||
return service(option)
|
return service(option)
|
||||||
|
|||||||
33
src/api/auth.js
Normal file
33
src/api/auth.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { request } from '@/api/_service'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号登录
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {string} data.username
|
||||||
|
* @param {string} data.password
|
||||||
|
*/
|
||||||
|
export function loginAdminUser (data) {
|
||||||
|
return request({
|
||||||
|
url: 'login',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
method: 'login',
|
||||||
|
platform: 'background',
|
||||||
|
...data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注销当前已登录的账号
|
||||||
|
*/
|
||||||
|
export function logoutAdminUser () {
|
||||||
|
return request({
|
||||||
|
url: 'logout',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
method: 'logout',
|
||||||
|
platform: 'background'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -43,6 +43,19 @@
|
|||||||
"please_enter": "Please enter {name}"
|
"please_enter": "Please enter {name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"system": {
|
||||||
|
"login": {
|
||||||
|
"time_is_most_precious": "Time is the most precious of all wealth",
|
||||||
|
"username": "Username",
|
||||||
|
"password": "Password",
|
||||||
|
"login": "Login",
|
||||||
|
"please_enter_username": "Please enter username",
|
||||||
|
"please_enter_password": "Please enter password",
|
||||||
|
"dev_version": "Development Version",
|
||||||
|
"test_version": "Test Version",
|
||||||
|
"form_validation_failed": "Form validation failed, please check"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,19 @@
|
|||||||
"please_enter": "请输入{name}"
|
"please_enter": "请输入{name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"system": {
|
||||||
|
"login": {
|
||||||
|
"time_is_most_precious": "时间是一切财富中最宝贵的财富",
|
||||||
|
"username": "用户名",
|
||||||
|
"password": "密码",
|
||||||
|
"login": "登录",
|
||||||
|
"please_enter_username": "请输入用户名",
|
||||||
|
"please_enter_password": "请输入密码",
|
||||||
|
"dev_version": "开发版本",
|
||||||
|
"test_version": "测试版本",
|
||||||
|
"form_validation_failed": "表单校验失败,请检查"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Message, MessageBox } from 'element-ui'
|
|
||||||
import util from '@/libs/util.js'
|
import util from '@/libs/util.js'
|
||||||
|
import { loginAdminUser, logoutAdminUser } from '@/api/auth'
|
||||||
|
|
||||||
|
import { MessageBox, Loading } from 'element-ui'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import { SYS_USER_LOGIN } from '@/api/sys.user.js'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@@ -17,16 +18,24 @@ export default {
|
|||||||
username = '',
|
username = '',
|
||||||
password = ''
|
password = ''
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const res = await SYS_USER_LOGIN({ username, password })
|
// 新的写法
|
||||||
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
const res = await loginAdminUser({ username, password })
|
||||||
// 整个系统依赖这两个数据进行校验和存储
|
// 设置用户数据
|
||||||
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
const cookieSetting = { expires: 365 }
|
||||||
// token 代表用户当前登录状态 建议在网络请求中携带 token
|
util.cookies.set('uuid', res.userInfo.username, cookieSetting)
|
||||||
// 如有必要 token 需要定时更新,默认保存一天
|
util.cookies.set('token', res.token, cookieSetting)
|
||||||
util.cookies.set('uuid', res.uuid)
|
util.cookies.set('block', 'false')
|
||||||
util.cookies.set('token', res.token)
|
|
||||||
|
// 存储用户数据到本地
|
||||||
|
localStorage.setItem('user_id', res.userInfo.user_id)
|
||||||
|
|
||||||
// 设置 vuex 用户信息
|
// 设置 vuex 用户信息
|
||||||
await dispatch('d2admin/user/set', { name: res.name }, { root: true })
|
await dispatch('d2admin/user/set', {
|
||||||
|
name: res.userInfo.username,
|
||||||
|
admin: res.userInfo,
|
||||||
|
token: res.token
|
||||||
|
}, { root: true })
|
||||||
|
|
||||||
// 用户登录后从持久化数据加载一系列的设置
|
// 用户登录后从持久化数据加载一系列的设置
|
||||||
await dispatch('load')
|
await dispatch('load')
|
||||||
},
|
},
|
||||||
@@ -35,34 +44,59 @@ export default {
|
|||||||
* @param {Object} context
|
* @param {Object} context
|
||||||
* @param {Object} payload confirm {Boolean} 是否需要确认
|
* @param {Object} payload confirm {Boolean} 是否需要确认
|
||||||
*/
|
*/
|
||||||
logout ({ commit, dispatch }, { confirm = false } = {}) {
|
logout ({ dispatch }, { confirm = false } = {}) {
|
||||||
/**
|
// 加载遮罩
|
||||||
* @description 注销
|
let loading = null
|
||||||
*/
|
// 实际注销操作
|
||||||
async function logout () {
|
function doLogout () {
|
||||||
|
logoutAdminUser()
|
||||||
|
.finally(() => {
|
||||||
|
// 删除sourceData
|
||||||
|
util.cookies.set('block', 'true')
|
||||||
|
dispatch('d2admin/db/set', {
|
||||||
|
dbName: 'database',
|
||||||
|
path: '$menu.sourceData',
|
||||||
|
value: [],
|
||||||
|
user: true
|
||||||
|
}, { root: true })
|
||||||
|
|
||||||
|
// 删除info
|
||||||
|
dispatch('d2admin/user/set', {}, { root: true })
|
||||||
|
|
||||||
// 删除cookie
|
// 删除cookie
|
||||||
util.cookies.remove('token')
|
util.cookies.remove('token')
|
||||||
// 清空 vuex 用户信息
|
|
||||||
await dispatch('d2admin/user/set', {}, { root: true })
|
|
||||||
util.cookies.remove('uuid')
|
util.cookies.remove('uuid')
|
||||||
// 跳转路由
|
|
||||||
|
// 刷新页面
|
||||||
|
loading && loading.close()
|
||||||
router.push({ name: 'login' })
|
router.push({ name: 'login' })
|
||||||
}
|
|
||||||
// 判断是否需要确认
|
|
||||||
if (confirm) {
|
|
||||||
commit('d2admin/gray/set', true, { root: true })
|
|
||||||
MessageBox.confirm('确定要注销当前用户吗', '注销用户', { type: 'warning' })
|
|
||||||
.then(() => {
|
|
||||||
commit('d2admin/gray/set', false, { root: true })
|
|
||||||
logout()
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
commit('d2admin/gray/set', false, { root: true })
|
|
||||||
Message({ message: '取消注销操作' })
|
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
logout()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
doLogout()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.confirm('确定要执行注销操作吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
closeOnClickModal: false
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
loading = Loading.service({
|
||||||
|
lock: true,
|
||||||
|
text: 'Loading',
|
||||||
|
spinner: 'el-icon-loading',
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)'
|
||||||
|
})
|
||||||
|
doLogout()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description 用户登录后从持久化数据加载一系列的设置
|
* @description 用户登录后从持久化数据加载一系列的设置
|
||||||
@@ -83,6 +117,8 @@ export default {
|
|||||||
await dispatch('d2admin/size/load', null, { root: true })
|
await dispatch('d2admin/size/load', null, { root: true })
|
||||||
// 持久化数据加载颜色设置
|
// 持久化数据加载颜色设置
|
||||||
await dispatch('d2admin/color/load', null, { root: true })
|
await dispatch('d2admin/color/load', null, { root: true })
|
||||||
|
// DB -> store 持久化数据读取菜单源数据
|
||||||
|
await dispatch('d2admin/menu/sourceDataLoad', null, { root: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ export default {
|
|||||||
// 侧边栏收缩
|
// 侧边栏收缩
|
||||||
asideCollapse: setting.menu.asideCollapse,
|
asideCollapse: setting.menu.asideCollapse,
|
||||||
// 侧边栏折叠动画
|
// 侧边栏折叠动画
|
||||||
asideTransition: setting.menu.asideTransition
|
asideTransition: setting.menu.asideTransition,
|
||||||
|
// 菜单源数据
|
||||||
|
sourceData: []
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +92,19 @@ export default {
|
|||||||
}, { root: true })
|
}, { root: true })
|
||||||
state.asideCollapse = menu.asideCollapse !== undefined ? menu.asideCollapse : setting.menu.asideCollapse
|
state.asideCollapse = menu.asideCollapse !== undefined ? menu.asideCollapse : setting.menu.asideCollapse
|
||||||
state.asideTransition = menu.asideTransition !== undefined ? menu.asideTransition : setting.menu.asideTransition
|
state.asideTransition = menu.asideTransition !== undefined ? menu.asideTransition : setting.menu.asideTransition
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 持久化数据加载菜单源数据
|
||||||
|
* @param {Object} context
|
||||||
|
*/
|
||||||
|
async sourceDataLoad ({ state, dispatch }) {
|
||||||
|
const sourceData = await dispatch('d2admin/db/get', {
|
||||||
|
dbName: 'database',
|
||||||
|
path: '$menu.sourceData',
|
||||||
|
defaultValue: [],
|
||||||
|
user: true
|
||||||
|
}, { root: true })
|
||||||
|
state.sourceData = sourceData
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|||||||
@@ -80,6 +80,15 @@ module.exports = {
|
|||||||
lintOnSave: true,
|
lintOnSave: true,
|
||||||
devServer: {
|
devServer: {
|
||||||
publicPath: process.env.VUE_APP_PUBLIC_PATH || '/',
|
publicPath: process.env.VUE_APP_PUBLIC_PATH || '/',
|
||||||
|
proxy: {
|
||||||
|
'/background': {
|
||||||
|
target: process.env.VUE_APP_BASE_URL,
|
||||||
|
changeOrigin: true,
|
||||||
|
pathRewrite: {
|
||||||
|
'^/background': ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
disableHostCheck: process.env.NODE_ENV === 'development'
|
disableHostCheck: process.env.NODE_ENV === 'development'
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
|
|||||||
Reference in New Issue
Block a user