From f40021e8f80886c7ee7efa81ab441cc7a9f449be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AD=A3=E6=98=93?= Date: Sat, 14 Sep 2024 17:34:29 +0800 Subject: [PATCH] =?UTF-8?q?PDA=E5=8F=AF=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/login.js | 8 +- config.js | 2 +- pages/login.vue | 17 ++-- store/modules/user.js | 189 +++++++++++++++++++++++------------------- 4 files changed, 119 insertions(+), 97 deletions(-) diff --git a/api/login.js b/api/login.js index 6ce7e7c..0ef8f2c 100644 --- a/api/login.js +++ b/api/login.js @@ -1,17 +1,19 @@ import request from '@/utils/request' // 登录方法 -export function login(username, password, code, uuid) { +export function login(username, password, code, uuid, clientId) { const data = { username, password, code, - uuid + uuid, + clientId } return request({ 'url': '/login', headers: { - isToken: false + isToken: false, + userName: username }, 'method': 'post', 'data': data diff --git a/config.js b/config.js index a2ebed8..f6f720a 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,6 @@ // 应用全局配置 module.exports = { - baseUrl: 'http://192.168.0.58', + baseUrl: 'http://192.168.0.58:7000', // baseUrl: 'http://localhost:8080', // 应用信息 appInfo: { diff --git a/pages/login.vue b/pages/login.vue index 65a7770..6e8057a 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -49,7 +49,7 @@ export default { globalConfig: getApp().globalData.config, loginForm: { username: 'admin', - password: 'admin123', + password: 'doantech123', code: '', uuid: '' } @@ -75,13 +75,14 @@ export default { }, // 获取图形验证码 getCode() { - getCodeImg().then((res) => { - this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; - if (this.captchaEnabled) { - this.codeUrl = 'data:image/gif;base64,' + res.img; - this.loginForm.uuid = res.uuid; - } - }); + this.captchaEnabled = false + // getCodeImg().then((res) => { + // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; + // if (this.captchaEnabled) { + // this.codeUrl = 'data:image/gif;base64,' + res.img; + // this.loginForm.uuid = res.uuid; + // } + // }); }, // 登录方法 async handleLogin() { diff --git a/store/modules/user.js b/store/modules/user.js index c1ec441..168d9e2 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -1,98 +1,117 @@ import config from '@/config' import storage from '@/utils/storage' import constant from '@/utils/constant' -import { login, logout, getInfo } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { + login, + logout, + getInfo +} from '@/api/login' +import { + getToken, + setToken, + removeToken +} from '@/utils/auth' const baseUrl = config.baseUrl const user = { - state: { - token: getToken(), - name: storage.get(constant.name), - avatar: storage.get(constant.avatar), - roles: storage.get(constant.roles), - permissions: storage.get(constant.permissions) - }, + state: { + token: getToken(), + name: storage.get(constant.name), + avatar: storage.get(constant.avatar), + roles: storage.get(constant.roles), + permissions: storage.get(constant.permissions) + }, - mutations: { - SET_TOKEN: (state, token) => { - state.token = token - }, - SET_NAME: (state, name) => { - state.name = name - storage.set(constant.name, name) - }, - SET_AVATAR: (state, avatar) => { - state.avatar = avatar - storage.set(constant.avatar, avatar) - }, - SET_ROLES: (state, roles) => { - state.roles = roles - storage.set(constant.roles, roles) - }, - SET_PERMISSIONS: (state, permissions) => { - state.permissions = permissions - storage.set(constant.permissions, permissions) - } - }, + mutations: { + SET_TOKEN: (state, token) => { + state.token = token + }, + SET_NAME: (state, name) => { + state.name = name + storage.set(constant.name, name) + }, + SET_AVATAR: (state, avatar) => { + state.avatar = avatar + storage.set(constant.avatar, avatar) + }, + SET_ROLES: (state, roles) => { + state.roles = roles + storage.set(constant.roles, roles) + }, + SET_PERMISSIONS: (state, permissions) => { + state.permissions = permissions + storage.set(constant.permissions, permissions) + } + }, - actions: { - // 登录 - Login({ commit }, userInfo) { - const username = userInfo.username.trim() - const password = userInfo.password - const code = userInfo.code - const uuid = userInfo.uuid - return new Promise((resolve, reject) => { - login(username, password, code, uuid).then(res => { - setToken(res.token) - commit('SET_TOKEN', res.token) - resolve() - }).catch(error => { - reject(error) - }) - }) - }, + actions: { + // 登录 + Login({ + commit + }, userInfo) { + const username = userInfo.username.trim() + const password = userInfo.password + const code = userInfo.code + const uuid = userInfo.uuid + return new Promise((resolve, reject) => { + login(username, password, code, uuid).then(res => { + console.log(res) + setToken(res.data) + commit('SET_TOKEN', res.data) + resolve() + }).catch(error => { + reject(error) + }) + }) + }, - // 获取用户信息 - GetInfo({ commit, state }) { - return new Promise((resolve, reject) => { - getInfo().then(res => { - const user = res.user - const avatar = (user == null || user.avatar == "" || user.avatar == null) ? require("@/static/images/profile.jpg") : baseUrl + user.avatar - const username = (user == null || user.userName == "" || user.userName == null) ? "" : user.userName - if (res.roles && res.roles.length > 0) { - commit('SET_ROLES', res.roles) - commit('SET_PERMISSIONS', res.permissions) - } else { - commit('SET_ROLES', ['ROLE_DEFAULT']) - } - commit('SET_NAME', username) - commit('SET_AVATAR', avatar) - resolve(res) - }).catch(error => { - reject(error) - }) - }) - }, + // 获取用户信息 + GetInfo({ + commit, + state + }) { + return new Promise((resolve, reject) => { + getInfo().then(res => { + const user = res.user + const avatar = (user == null || user.avatar == "" || user.avatar == null) ? + require("@/static/images/profile.jpg") : baseUrl + user.avatar + const username = (user == null || user.userName == "" || user.userName == + null) ? "" : user.userName + if (res.roles && res.roles.length > 0) { + commit('SET_ROLES', res.roles) + commit('SET_PERMISSIONS', res.permissions) + } else { + commit('SET_ROLES', ['ROLE_DEFAULT']) + } + commit('SET_NAME', username) + commit('SET_AVATAR', avatar) + resolve(res) + }).catch(error => { + reject(error) + }) + }) + }, - // 退出系统 - LogOut({ commit, state }) { - return new Promise((resolve, reject) => { - logout(state.token).then(() => { - commit('SET_TOKEN', '') - commit('SET_ROLES', []) - commit('SET_PERMISSIONS', []) - removeToken() - storage.clean() - resolve() - }).catch(error => { - reject(error) - }) - }) - } - } + // 退出系统 + LogOut({ + commit, + state + }) { + return new Promise((resolve, reject) => { + logout(state.token).then(() => { + commit('SET_TOKEN', '') + commit('SET_ROLES', []) + commit('SET_PERMISSIONS', []) + removeToken() + storage.clean() + resolve() + }).catch(error => { + reject(error) + }) + }) + } + } } -export default user +export default user \ No newline at end of file