mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
feat: uniapp 适配aj-captcha
This commit is contained in:
parent
af2b1eb25f
commit
baf5d87d32
@ -1,47 +1,60 @@
|
|||||||
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
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户详细信息
|
// 获取用户详细信息
|
||||||
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'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 退出方法
|
// 退出方法
|
||||||
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',
|
},
|
||||||
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({
|
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"
|
||||||
|
}
|
||||||
|
}
|
@ -1,182 +1,163 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="normal-login-container">
|
<view class="normal-login-container">
|
||||||
<view class="logo-content align-center justify-center flex">
|
<view class="logo-content align-center justify-center flex">
|
||||||
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
|
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
|
||||||
</image>
|
</image>
|
||||||
<text class="title">芋道移动端登录</text>
|
<text class="title">芋道移动端登录</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="login-form-content">
|
<view class="login-form-content">
|
||||||
<view class="input-item flex align-center">
|
<view class="input-item flex align-center">
|
||||||
<view class="iconfont icon-user icon"></view>
|
<view class="iconfont icon-user icon"></view>
|
||||||
<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
|
<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
|
||||||
</view>
|
</view>
|
||||||
<view class="input-item flex align-center">
|
<view class="input-item flex align-center">
|
||||||
<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" />
|
<view class="action-btn">
|
||||||
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
|
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
||||||
</view>
|
</view>
|
||||||
<view class="action-btn">
|
</view>
|
||||||
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<view class="xieyi text-center">
|
<view class="xieyi text-center">
|
||||||
<text class="text-grey1">登录即代表同意</text>
|
<text class="text-grey1">登录即代表同意</text>
|
||||||
<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
|
<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
|
||||||
<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
|
<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from '@/api/login'
|
import Verify from "@/components/verifition/Verify"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
name: 'Login',
|
||||||
return {
|
components: {
|
||||||
codeUrl: "",
|
Verify
|
||||||
captchaEnabled: true,
|
},
|
||||||
globalConfig: getApp().globalData.config,
|
data() {
|
||||||
loginForm: {
|
return {
|
||||||
username: "admin",
|
captchaEnabled: true,
|
||||||
password: "admin123",
|
globalConfig: getApp().globalData.config,
|
||||||
code: "",
|
loginForm: {
|
||||||
uuid: ''
|
username: "admin",
|
||||||
}
|
password: "admin123",
|
||||||
}
|
captchaVerification: ""
|
||||||
},
|
}
|
||||||
created() {
|
}
|
||||||
this.getCode()
|
},
|
||||||
},
|
methods: {
|
||||||
methods: {
|
// 隐私协议
|
||||||
// 隐私协议
|
handlePrivacy() {
|
||||||
handlePrivacy() {
|
let site = this.globalConfig.appInfo.agreements[0]
|
||||||
let site = this.globalConfig.appInfo.agreements[0]
|
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}`)
|
},
|
||||||
},
|
// 用户协议
|
||||||
// 用户协议
|
handleUserAgrement() {
|
||||||
handleUserAgrement() {
|
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}`)
|
},
|
||||||
},
|
// 登录方法
|
||||||
// 获取图形验证码
|
async handleLogin(params) {
|
||||||
getCode() {
|
if (this.loginForm.username === "") {
|
||||||
getCodeImg().then(res => {
|
this.$modal.msgError("请输入您的账号")
|
||||||
res = res.data;
|
} else if (this.loginForm.password === "") {
|
||||||
this.captchaEnable = res.enable;
|
this.$modal.msgError("请输入您的密码")
|
||||||
if (this.captchaEnable) {
|
} else {
|
||||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
this.$modal.loading("登录中,请耐心等待...")
|
||||||
this.loginForm.uuid = res.uuid;
|
// 显示验证码
|
||||||
}
|
this.$refs.verify.show()
|
||||||
})
|
}
|
||||||
},
|
},
|
||||||
// 登录方法
|
// 密码登录
|
||||||
async handleLogin() {
|
async pwdLogin(params) {
|
||||||
if (this.loginForm.username === "") {
|
this.loginForm.captchaVerification = params.captchaVerification
|
||||||
this.$modal.msgError("请输入您的账号")
|
this.$store.dispatch('Login', this.loginForm).then(() => {
|
||||||
} else if (this.loginForm.password === "") {
|
this.$modal.closeLoading()
|
||||||
this.$modal.msgError("请输入您的密码")
|
this.loginSuccess()
|
||||||
} else if (this.loginForm.code === "" && this.captchaEnabled) {
|
})
|
||||||
this.$modal.msgError("请输入验证码")
|
},
|
||||||
} else {
|
// 登录成功后,处理函数
|
||||||
this.$modal.loading("登录中,请耐心等待...")
|
loginSuccess(result) {
|
||||||
this.pwdLogin()
|
// 设置用户信息
|
||||||
}
|
this.$store.dispatch('GetInfo').then(res => {
|
||||||
},
|
this.$tab.reLaunch('/pages/index')
|
||||||
// 密码登录
|
})
|
||||||
async pwdLogin() {
|
}
|
||||||
this.$store.dispatch('Login', this.loginForm).then(() => {
|
}
|
||||||
this.$modal.closeLoading()
|
}
|
||||||
this.loginSuccess()
|
|
||||||
}).catch(() => {
|
|
||||||
if (this.captchaEnabled) {
|
|
||||||
this.getCode()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
// 登录成功后,处理函数
|
|
||||||
loginSuccess(result) {
|
|
||||||
// 设置用户信息
|
|
||||||
this.$store.dispatch('GetInfo').then(res => {
|
|
||||||
this.$tab.reLaunch('/pages/index')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
page {
|
page {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.normal-login-container {
|
.normal-login-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
.logo-content {
|
.logo-content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 21px;
|
font-size: 21px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-top: 15%;
|
padding-top: 15%;
|
||||||
|
|
||||||
image {
|
image {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-form-content {
|
.login-form-content {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 20px auto;
|
margin: 20px auto;
|
||||||
margin-top: 15%;
|
margin-top: 15%;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
|
||||||
.input-item {
|
.input-item {
|
||||||
margin: 20px auto;
|
margin: 20px auto;
|
||||||
background-color: #f5f6f7;
|
background-color: #f5f6f7;
|
||||||
height: 45px;
|
height: 45px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
font-size: 38rpx;
|
font-size: 38rpx;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-btn {
|
.login-btn {
|
||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
height: 45px;
|
height: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.xieyi {
|
.xieyi {
|
||||||
color: #333;
|
color: #333;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.easyinput {
|
.easyinput {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-code-img {
|
.login-code-img {
|
||||||
height: 45px;
|
height: 45px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
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