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'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 登录方法
|
// 登录方法
|
||||||
export function login(username, password, code, uuid) {
|
export function login(username, password, captchaVerification) {
|
||||||
const data = {
|
const data = {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
code,
|
captchaVerification
|
||||||
uuid
|
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
url: '/system/auth/login',
|
url: '/system/auth/login',
|
||||||
headers: {
|
headers: {
|
||||||
isToken: false
|
isToken: false
|
||||||
},
|
},
|
||||||
'method': 'post',
|
'method': 'POST',
|
||||||
'data': data
|
'data': data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -22,7 +21,7 @@ export function login(username, password, code, uuid) {
|
|||||||
export function getInfo() {
|
export function getInfo() {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/auth/get-permission-info',
|
url: '/system/auth/get-permission-info',
|
||||||
'method': 'get'
|
'method': 'GET'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,18 +29,32 @@ export function getInfo() {
|
|||||||
export function logout() {
|
export function logout() {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/auth/logout',
|
url: '/system/auth/logout',
|
||||||
'method': 'post'
|
'method': 'POST'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取验证码
|
// 获取验证码
|
||||||
export function getCodeImg() {
|
export function getCaptcha(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/captcha/get-image',
|
url: '/captcha/get',
|
||||||
headers: {
|
headers: {
|
||||||
isToken: false
|
isToken: false,
|
||||||
|
isTenant: false
|
||||||
},
|
},
|
||||||
method: 'get',
|
method: 'POST',
|
||||||
timeout: 20000
|
'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({
|
return request({
|
||||||
url: '/system/user/profile/update-password',
|
url: '/system/user/profile/update-password',
|
||||||
method: 'put',
|
method: 'PUT',
|
||||||
params: data
|
params: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
|||||||
export function getUserProfile() {
|
export function getUserProfile() {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/user/profile/get',
|
url: '/system/user/profile/get',
|
||||||
method: 'get'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export function getUserProfile() {
|
|||||||
export function updateUserProfile(data) {
|
export function updateUserProfile(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/user/profile/update',
|
url: '/system/user/profile/update',
|
||||||
method: 'put',
|
method: 'PUT',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ export function updateUserProfile(data) {
|
|||||||
export function uploadAvatar(data) {
|
export function uploadAvatar(data) {
|
||||||
return upload({
|
return upload({
|
||||||
url: '/system/user/profile/update-avatar',
|
url: '/system/user/profile/update-avatar',
|
||||||
method: 'put',
|
method: 'PUT',
|
||||||
name: data.name,
|
name: data.name,
|
||||||
filePath: data.filePath
|
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 = {
|
module.exports = {
|
||||||
// baseUrl: 'http://localhost:8080',
|
// baseUrl: 'http://localhost:8080',
|
||||||
baseUrl: 'http://localhost:48080/admin-api',
|
baseUrl: 'http://localhost:48080',
|
||||||
// 应用信息
|
// 应用信息
|
||||||
appInfo: {
|
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>
|
<view class="iconfont icon-password icon"></view>
|
||||||
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
||||||
</view>
|
</view>
|
||||||
<view class="input-item flex align-center" v-if="captchaEnabled">
|
<Verify @success="pwdLogin" :mode="'pop'" :captchaType="'blockPuzzle'"
|
||||||
<view class="iconfont icon-code icon"></view>
|
:imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
|
||||||
<input v-model="loginForm.code" class="input" placeholder="请输入验证码" maxlength="5" />
|
|
||||||
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
|
|
||||||
</view>
|
|
||||||
<view class="action-btn">
|
<view class="action-btn">
|
||||||
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
||||||
</view>
|
</view>
|
||||||
@ -33,25 +30,24 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from '@/api/login'
|
import Verify from "@/components/verifition/Verify"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
name: 'Login',
|
||||||
|
components: {
|
||||||
|
Verify
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
codeUrl: "",
|
|
||||||
captchaEnabled: true,
|
captchaEnabled: true,
|
||||||
globalConfig: getApp().globalData.config,
|
globalConfig: getApp().globalData.config,
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: "admin",
|
username: "admin",
|
||||||
password: "admin123",
|
password: "admin123",
|
||||||
code: "",
|
captchaVerification: ""
|
||||||
uuid: ''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.getCode()
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
// 隐私协议
|
// 隐私协议
|
||||||
handlePrivacy() {
|
handlePrivacy() {
|
||||||
@ -63,39 +59,24 @@
|
|||||||
let site = this.globalConfig.appInfo.agreements[1]
|
let site = this.globalConfig.appInfo.agreements[1]
|
||||||
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
|
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 === "") {
|
if (this.loginForm.username === "") {
|
||||||
this.$modal.msgError("请输入您的账号")
|
this.$modal.msgError("请输入您的账号")
|
||||||
} else if (this.loginForm.password === "") {
|
} else if (this.loginForm.password === "") {
|
||||||
this.$modal.msgError("请输入您的密码")
|
this.$modal.msgError("请输入您的密码")
|
||||||
} else if (this.loginForm.code === "" && this.captchaEnabled) {
|
|
||||||
this.$modal.msgError("请输入验证码")
|
|
||||||
} else {
|
} else {
|
||||||
this.$modal.loading("登录中,请耐心等待...")
|
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.$store.dispatch('Login', this.loginForm).then(() => {
|
||||||
this.$modal.closeLoading()
|
this.$modal.closeLoading()
|
||||||
this.loginSuccess()
|
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) {
|
Login({ commit }, userInfo) {
|
||||||
const username = userInfo.username.trim()
|
const username = userInfo.username.trim()
|
||||||
const password = userInfo.password
|
const password = userInfo.password
|
||||||
const code = userInfo.code
|
const captchaVerification = userInfo.captchaVerification
|
||||||
const uuid = userInfo.uuid
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login(username, password, code, uuid).then(res => {
|
login(username, password, captchaVerification).then(res => {
|
||||||
res = res.data;
|
res = res.data;
|
||||||
// 设置 token
|
// 设置 token
|
||||||
setToken(res)
|
setToken(res)
|
||||||
@ -83,7 +82,6 @@ const user = {
|
|||||||
LogOut({ commit, state }) {
|
LogOut({ commit, state }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logout(state.token).then(() => {
|
logout(state.token).then(() => {
|
||||||
commit('SET_TOKEN', '')
|
|
||||||
commit('SET_ROLES', [])
|
commit('SET_ROLES', [])
|
||||||
commit('SET_PERMISSIONS', [])
|
commit('SET_PERMISSIONS', [])
|
||||||
removeToken()
|
removeToken()
|
||||||
|
@ -5,7 +5,7 @@ import errorCode from '@/utils/errorCode'
|
|||||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
import { toast, showConfirm, tansParams } from '@/utils/common'
|
||||||
|
|
||||||
let timeout = 10000
|
let timeout = 10000
|
||||||
const baseUrl = config.baseUrl
|
const baseUrl = config.baseUrl + '/admin-api';
|
||||||
|
|
||||||
const request = config => {
|
const request = config => {
|
||||||
// 是否需要设置 token
|
// 是否需要设置 token
|
||||||
|
Loading…
Reference in New Issue
Block a user