diff --git a/.env b/.env index 25fd33e0..b702f2e9 100644 --- a/.env +++ b/.env @@ -4,7 +4,7 @@ VUE_APP_TITLE=D2Admin # 网络请求公用地址 -VUE_APP_API=/api/ +VUE_APP_API=/background/v1/ # 仓库地址 VUE_APP_REPO=https://github.com/d2-projects/d2-admin diff --git a/.env.development b/.env.development index c126ecf1..0674e47e 100644 --- a/.env.development +++ b/.env.development @@ -2,3 +2,6 @@ # 页面 title 前缀 VUE_APP_TITLE=D2Admin Dev + +# 后台接口地址(代理目标) +VUE_APP_BASE_URL=http://127.0.0.1:8787/background/ diff --git a/docs/login-page-migration.md b/docs/login-page-migration.md index 289359d6..2fd2744a 100644 --- a/docs/login-page-migration.md +++ b/docs/login-page-migration.md @@ -2,7 +2,7 @@ > **搬迁源**:`D:\code\company\SCTMES_MES_V5\vue-app` > **搬迁目标**:`d:\code\mes\mes-ui` -> **状态**:⏳ 待审阅,审阅通过后执行搬迁 +> **状态**:✅ 已完成(2026-05-26) --- @@ -86,7 +86,7 @@ ### 2.5 i18n 语言包 -**i18n key 前缀**:`page.system_settings.system_monitoring.system.login` +**i18n key 前缀**:`page.system_administration.system_monitoring.login` | 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 "login": { "time_is_most_precious": "时间是一切财富中最宝贵的财富", "username": "用户名", "password": "密码", "login": "登录", - "quick_select_user": "快速选择用户", "please_enter_username": "请输入用户名", "please_enter_password": "请输入密码", - "please_enter_code": "请输入验证码", "dev_version": "开发版本", "test_version": "测试版本", "form_validation_failed": "表单校验失败,请检查" diff --git a/public/image/logo/sc_logo.png b/public/image/logo/sc_logo.png new file mode 100644 index 00000000..5f11f255 Binary files /dev/null and b/public/image/logo/sc_logo.png differ diff --git a/src/api/_service.js b/src/api/_service.js index b7f6a7af..dc0fa44f 100644 --- a/src/api/_service.js +++ b/src/api/_service.js @@ -125,13 +125,15 @@ function createRequest (service) { const token = util.cookies.get('token') const configDefault = { headers: { - Authorization: token, 'Content-Type': get(config, 'headers.Content-Type', 'application/json') }, timeout: 5000, baseURL: process.env.VUE_APP_API, data: {} } + if (token) { + configDefault.headers.Authorization = 'Bearer ' + token + } const option = merge(configDefault, config) // 处理 get 请求的参数 // 请根据实际需要修改 @@ -141,7 +143,7 @@ function createRequest (service) { } // 当需要以 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) } return service(option) diff --git a/src/api/auth.js b/src/api/auth.js new file mode 100644 index 00000000..d8b010fd --- /dev/null +++ b/src/api/auth.js @@ -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' + } + }) +} diff --git a/src/locales/en.json b/src/locales/en.json index 4afea1b4..64cb5f71 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -43,6 +43,19 @@ "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" + } } } } diff --git a/src/locales/zh-chs.json b/src/locales/zh-chs.json index fc1dc7fa..d38ccd70 100644 --- a/src/locales/zh-chs.json +++ b/src/locales/zh-chs.json @@ -43,6 +43,19 @@ "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": "表单校验失败,请检查" + } } } } diff --git a/src/store/modules/d2admin/modules/account.js b/src/store/modules/d2admin/modules/account.js index 21908a14..8380d123 100644 --- a/src/store/modules/d2admin/modules/account.js +++ b/src/store/modules/d2admin/modules/account.js @@ -1,7 +1,8 @@ -import { Message, MessageBox } from 'element-ui' import util from '@/libs/util.js' +import { loginAdminUser, logoutAdminUser } from '@/api/auth' + +import { MessageBox, Loading } from 'element-ui' import router from '@/router' -import { SYS_USER_LOGIN } from '@/api/sys.user.js' export default { namespaced: true, @@ -17,16 +18,24 @@ export default { username = '', password = '' } = {}) { - const res = await SYS_USER_LOGIN({ username, password }) - // 设置 cookie 一定要存 uuid 和 token 两个 cookie - // 整个系统依赖这两个数据进行校验和存储 - // uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复 - // token 代表用户当前登录状态 建议在网络请求中携带 token - // 如有必要 token 需要定时更新,默认保存一天 - util.cookies.set('uuid', res.uuid) - util.cookies.set('token', res.token) + // 新的写法 + const res = await loginAdminUser({ username, password }) + // 设置用户数据 + const cookieSetting = { expires: 365 } + util.cookies.set('uuid', res.userInfo.username, cookieSetting) + util.cookies.set('token', res.token, cookieSetting) + util.cookies.set('block', 'false') + + // 存储用户数据到本地 + localStorage.setItem('user_id', res.userInfo.user_id) + // 设置 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') }, @@ -35,34 +44,59 @@ export default { * @param {Object} context * @param {Object} payload confirm {Boolean} 是否需要确认 */ - logout ({ commit, dispatch }, { confirm = false } = {}) { - /** - * @description 注销 - */ - async function logout () { - // 删除cookie - util.cookies.remove('token') - // 清空 vuex 用户信息 - await dispatch('d2admin/user/set', {}, { root: true }) - util.cookies.remove('uuid') - // 跳转路由 - 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() + logout ({ dispatch }, { confirm = false } = {}) { + // 加载遮罩 + let loading = null + // 实际注销操作 + 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 + util.cookies.remove('token') + util.cookies.remove('uuid') + + // 刷新页面 + loading && loading.close() + router.push({ name: 'login' }) }) .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 用户登录后从持久化数据加载一系列的设置 @@ -83,6 +117,8 @@ export default { await dispatch('d2admin/size/load', null, { root: true }) // 持久化数据加载颜色设置 await dispatch('d2admin/color/load', null, { root: true }) + // DB -> store 持久化数据读取菜单源数据 + await dispatch('d2admin/menu/sourceDataLoad', null, { root: true }) } } } diff --git a/src/store/modules/d2admin/modules/menu.js b/src/store/modules/d2admin/modules/menu.js index 327a3d16..520e2d60 100644 --- a/src/store/modules/d2admin/modules/menu.js +++ b/src/store/modules/d2admin/modules/menu.js @@ -11,7 +11,9 @@ export default { // 侧边栏收缩 asideCollapse: setting.menu.asideCollapse, // 侧边栏折叠动画 - asideTransition: setting.menu.asideTransition + asideTransition: setting.menu.asideTransition, + // 菜单源数据 + sourceData: [] }, actions: { /** @@ -90,6 +92,19 @@ export default { }, { root: true }) state.asideCollapse = menu.asideCollapse !== undefined ? menu.asideCollapse : setting.menu.asideCollapse 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: { diff --git a/vue.config.js b/vue.config.js index 71c89998..99b57895 100644 --- a/vue.config.js +++ b/vue.config.js @@ -80,6 +80,15 @@ module.exports = { lintOnSave: true, devServer: { 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' }, css: {