mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
feat: uniapp 适配aj-captcha
This commit is contained in:
parent
af2b1eb25f
commit
baf5d87d32
@ -1,19 +1,18 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 登录方法
|
||||
export function login(username, password, code, uuid) {
|
||||
export function login(username, password, captchaVerification) {
|
||||
const data = {
|
||||
username,
|
||||
password,
|
||||
code,
|
||||
uuid
|
||||
captchaVerification
|
||||
}
|
||||
return request({
|
||||
url: '/system/auth/login',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
'method': 'post',
|
||||
'method': 'POST',
|
||||
'data': data
|
||||
})
|
||||
}
|
||||
@ -22,7 +21,7 @@ export function login(username, password, code, uuid) {
|
||||
export function getInfo() {
|
||||
return request({
|
||||
url: '/system/auth/get-permission-info',
|
||||
'method': 'get'
|
||||
'method': 'GET'
|
||||
})
|
||||
}
|
||||
|
||||
@ -30,18 +29,32 @@ export function getInfo() {
|
||||
export function logout() {
|
||||
return request({
|
||||
url: '/system/auth/logout',
|
||||
'method': 'post'
|
||||
'method': 'POST'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
export function getCodeImg() {
|
||||
export function getCaptcha(data) {
|
||||
return request({
|
||||
url: '/system/captcha/get-image',
|
||||
url: '/captcha/get',
|
||||
headers: {
|
||||
isToken: false
|
||||
isToken: false,
|
||||
isTenant: false
|
||||
},
|
||||
method: 'get',
|
||||
timeout: 20000
|
||||
method: 'POST',
|
||||
'data': data
|
||||
})
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
export function checkCaptcha(data) {
|
||||
return request({
|
||||
url: '/captcha/check',
|
||||
headers: {
|
||||
isToken: false,
|
||||
isTenant: false
|
||||
},
|
||||
method: 'POST',
|
||||
'data': data
|
||||
})
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
||||
}
|
||||
return request({
|
||||
url: '/system/user/profile/update-password',
|
||||
method: 'put',
|
||||
method: 'PUT',
|
||||
params: data
|
||||
})
|
||||
}
|
||||
@ -18,7 +18,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
||||
export function getUserProfile() {
|
||||
return request({
|
||||
url: '/system/user/profile/get',
|
||||
method: 'get'
|
||||
method: 'GET'
|
||||
})
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ export function getUserProfile() {
|
||||
export function updateUserProfile(data) {
|
||||
return request({
|
||||
url: '/system/user/profile/update',
|
||||
method: 'put',
|
||||
method: 'PUT',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
@ -35,7 +35,7 @@ export function updateUserProfile(data) {
|
||||
export function uploadAvatar(data) {
|
||||
return upload({
|
||||
url: '/system/user/profile/update-avatar',
|
||||
method: 'put',
|
||||
method: 'PUT',
|
||||
name: data.name,
|
||||
filePath: data.filePath
|
||||
})
|
||||
|
482
yudao-ui-admin-uniapp/components/verifition/Verify.vue
Normal file
482
yudao-ui-admin-uniapp/components/verifition/Verify.vue
Normal file
File diff suppressed because one or more lines are too long
11
yudao-ui-admin-uniapp/components/verifition/utils/ase.js
Normal file
11
yudao-ui-admin-uniapp/components/verifition/utils/ase.js
Normal file
@ -0,0 +1,11 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
/**
|
||||
* @word 要加密的内容
|
||||
* @keyWord String 服务器随机返回的关键字
|
||||
* */
|
||||
export function aesEncrypt(word,keyWord="XwKsGlMcdPMEhR1B"){
|
||||
var key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
var srcs = CryptoJS.enc.Utf8.parse(word);
|
||||
var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
|
||||
return encrypted.toString();
|
||||
}
|
17
yudao-ui-admin-uniapp/components/verifition/utils/request.js
Normal file
17
yudao-ui-admin-uniapp/components/verifition/utils/request.js
Normal file
@ -0,0 +1,17 @@
|
||||
import config from '@/config'
|
||||
const baseUrl = config.baseUrl
|
||||
export const myRequest = (option={})=>{
|
||||
return new Promise((reslove,reject)=>{
|
||||
uni.request({
|
||||
url: baseUrl + option.url,
|
||||
data :option.data,
|
||||
method:option.method || "GET",
|
||||
success: (result) => {
|
||||
reslove(result)
|
||||
},
|
||||
fail:(error)=>{
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
||||
// 应用全局配置
|
||||
module.exports = {
|
||||
// baseUrl: 'http://localhost:8080',
|
||||
baseUrl: 'http://localhost:48080/admin-api',
|
||||
baseUrl: 'http://localhost:48080',
|
||||
// 应用信息
|
||||
appInfo: {
|
||||
// 应用名称
|
||||
|
5
yudao-ui-admin-uniapp/package.json
Normal file
5
yudao-ui-admin-uniapp/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"crypto-js": "^4.0.0"
|
||||
}
|
||||
}
|
@ -14,11 +14,8 @@
|
||||
<view class="iconfont icon-password icon"></view>
|
||||
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
||||
</view>
|
||||
<view class="input-item flex align-center" v-if="captchaEnabled">
|
||||
<view class="iconfont icon-code icon"></view>
|
||||
<input v-model="loginForm.code" class="input" placeholder="请输入验证码" maxlength="5" />
|
||||
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
|
||||
</view>
|
||||
<Verify @success="pwdLogin" :mode="'pop'" :captchaType="'blockPuzzle'"
|
||||
:imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
|
||||
<view class="action-btn">
|
||||
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
||||
</view>
|
||||
@ -33,25 +30,24 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getCodeImg } from '@/api/login'
|
||||
import Verify from "@/components/verifition/Verify"
|
||||
|
||||
export default {
|
||||
name: 'Login',
|
||||
components: {
|
||||
Verify
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
codeUrl: "",
|
||||
captchaEnabled: true,
|
||||
globalConfig: getApp().globalData.config,
|
||||
loginForm: {
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
code: "",
|
||||
uuid: ''
|
||||
captchaVerification: ""
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getCode()
|
||||
},
|
||||
methods: {
|
||||
// 隐私协议
|
||||
handlePrivacy() {
|
||||
@ -63,39 +59,24 @@
|
||||
let site = this.globalConfig.appInfo.agreements[1]
|
||||
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
|
||||
},
|
||||
// 获取图形验证码
|
||||
getCode() {
|
||||
getCodeImg().then(res => {
|
||||
res = res.data;
|
||||
this.captchaEnable = res.enable;
|
||||
if (this.captchaEnable) {
|
||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
||||
this.loginForm.uuid = res.uuid;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 登录方法
|
||||
async handleLogin() {
|
||||
async handleLogin(params) {
|
||||
if (this.loginForm.username === "") {
|
||||
this.$modal.msgError("请输入您的账号")
|
||||
} else if (this.loginForm.password === "") {
|
||||
this.$modal.msgError("请输入您的密码")
|
||||
} else if (this.loginForm.code === "" && this.captchaEnabled) {
|
||||
this.$modal.msgError("请输入验证码")
|
||||
} else {
|
||||
this.$modal.loading("登录中,请耐心等待...")
|
||||
this.pwdLogin()
|
||||
// 显示验证码
|
||||
this.$refs.verify.show()
|
||||
}
|
||||
},
|
||||
// 密码登录
|
||||
async pwdLogin() {
|
||||
async pwdLogin(params) {
|
||||
this.loginForm.captchaVerification = params.captchaVerification
|
||||
this.$store.dispatch('Login', this.loginForm).then(() => {
|
||||
this.$modal.closeLoading()
|
||||
this.loginSuccess()
|
||||
}).catch(() => {
|
||||
if (this.captchaEnabled) {
|
||||
this.getCode()
|
||||
}
|
||||
})
|
||||
},
|
||||
// 登录成功后,处理函数
|
||||
|
BIN
yudao-ui-admin-uniapp/static/images/default.jpg
Normal file
BIN
yudao-ui-admin-uniapp/static/images/default.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -42,10 +42,9 @@ const user = {
|
||||
Login({ commit }, userInfo) {
|
||||
const username = userInfo.username.trim()
|
||||
const password = userInfo.password
|
||||
const code = userInfo.code
|
||||
const uuid = userInfo.uuid
|
||||
const captchaVerification = userInfo.captchaVerification
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, password, code, uuid).then(res => {
|
||||
login(username, password, captchaVerification).then(res => {
|
||||
res = res.data;
|
||||
// 设置 token
|
||||
setToken(res)
|
||||
@ -83,7 +82,6 @@ const user = {
|
||||
LogOut({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout(state.token).then(() => {
|
||||
commit('SET_TOKEN', '')
|
||||
commit('SET_ROLES', [])
|
||||
commit('SET_PERMISSIONS', [])
|
||||
removeToken()
|
||||
|
@ -5,7 +5,7 @@ import errorCode from '@/utils/errorCode'
|
||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
||||
|
||||
let timeout = 10000
|
||||
const baseUrl = config.baseUrl
|
||||
const baseUrl = config.baseUrl + '/admin-api';
|
||||
|
||||
const request = config => {
|
||||
// 是否需要设置 token
|
||||
|
Loading…
Reference in New Issue
Block a user