初始化配置完善

This commit is contained in:
赵正易
2024-03-12 10:02:38 +08:00
parent 87129a1651
commit 504e33d447
4 changed files with 328 additions and 292 deletions

View File

@@ -1,17 +1,16 @@
// 应用全局配置
module.exports = {
//baseUrl: 'https://vue.ruoyi.vip/prod-api',
baseUrl: 'http://localhost:8888',
baseUrl: '/api',
// 应用信息
appInfo: {
// 应用名称
name: "ruoyi-app",
name: "DOAN",
// 应用版本
version: "1.1.0",
version: "1.0.0",
// 应用logo
logo: "/static/logo.png",
// 官方网站
site_url: "http://ruoyi.vip",
site_url: "",
// 政策协议
agreements: [{
title: "隐私政策",

View File

@@ -58,7 +58,16 @@
"template" : "static/index.html",
"devServer" : {
"port" : 9090,
"https" : false
"https" : false,
"disableHostCheck":true,
"proxy":{
"/api":{
"target":"http://localhost:8888",
"pathRewrite":{
"^/api": ""
}
}
}
},
"title" : "RuoYi-App",
"router" : {

View File

@@ -1,8 +1,7 @@
<template>
<view class="normal-login-container">
<view class="logo-content align-center justify-center flex">
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
</image>
<image style="width: 100rpx; height: 100rpx" :src="globalConfig.appInfo.logo" mode="widthFix"></image>
<text class="title">若依移动端登录</text>
</view>
<view class="login-form-content">
@@ -14,7 +13,7 @@
<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" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
<view class="input-item flex align-center" style="width: 60%; margin: 0px" v-if="captchaEnabled">
<view class="iconfont icon-code icon"></view>
<input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
<view class="login-code">
@@ -34,90 +33,103 @@
<text @click="handlePrivacy" class="text-blue">隐私协议</text>
</view>
</view>
</view>
</template>
<script>
import { getCodeImg } from '@/api/login'
import { getCodeImg } from '@/api/login';
export default {
data() {
return {
codeUrl: "",
captchaEnabled: true,
codeUrl: '',
captchaEnabled: false,
// 用户注册开关
register: false,
globalConfig: getApp().globalData.config,
loginForm: {
username: "admin",
password: "admin123",
code: "",
username: 'admin',
password: '123456',
code: '',
uuid: ''
}
}
};
},
created() {
this.getCode()
this.getCode();
},
methods: {
// 用户注册
handleUserRegister() {
this.$tab.redirectTo(`/pages/register`)
this.$tab.redirectTo(`/pages/register`);
},
// 隐私协议
handlePrivacy() {
let site = this.globalConfig.appInfo.agreements[0]
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
let site = this.globalConfig.appInfo.agreements[0];
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
},
// 用户协议
handleUserAgrement() {
let site = this.globalConfig.appInfo.agreements[1]
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
let site = this.globalConfig.appInfo.agreements[1];
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
},
// 获取图形验证码
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
getCodeImg().then((res) => {
if (res.code !== 200) {
uni.showToast({
title: '获取验证码失败!',
icon: 'error'
});
return;
}
})
const result = res.data;
if (result.captchaOff === 'off') {
this.captchaEnabled = false;
return;
}else{
this.captchaEnabled = true;
}
this.codeUrl = 'data:image/gif;base64,' + result.img;
this.loginForm.uuid = result.uuid;
});
},
// 登录方法
async handleLogin() {
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("请输入验证码")
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.$modal.loading('登录中,请耐心等待...');
this.pwdLogin();
}
},
// 密码登录
async pwdLogin() {
this.$store.dispatch('Login', this.loginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
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')
})
}
this.$store.dispatch('GetInfo').then((res) => {
this.$tab.reLaunch('/pages/index');
});
}
}
};
</script>
<style lang="scss">
@@ -168,7 +180,6 @@
text-align: left;
padding-left: 15px;
}
}
.login-btn {
@@ -198,5 +209,4 @@
}
}
}
</style>

View File

@@ -1,8 +1,16 @@
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
@@ -39,15 +47,17 @@ const user = {
actions: {
// 登录
Login({ commit }, userInfo) {
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)
setToken(res.data)
commit('SET_TOKEN', res.data)
resolve()
}).catch(error => {
reject(error)
@@ -56,12 +66,17 @@ const user = {
},
// 获取用户信息
GetInfo({ commit, state }) {
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
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)
@@ -78,7 +93,10 @@ const user = {
},
// 退出系统
LogOut({ commit, state }) {
LogOut({
commit,
state
}) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
commit('SET_TOKEN', '')