fix login

main
chenshuichuan 2 years ago
parent 000dd462ab
commit d2bc99a1de

@ -1,15 +1,18 @@
import request from '@/utils/request'
// 登录方法
export function login(username, password, code, uuid) {
export function login(username, password, code, uuid, tenantName, captchaVerification,rememberMe) {
const data = {
username,
password,
code,
uuid
uuid,
tenantName,
captchaVerification,
rememberMe
}
return request({
url: '/login',
url: '/admin-api/system/auth/login',
headers: {
isToken: false
},
@ -33,7 +36,7 @@ export function register(data) {
// 获取用户详细信息
export function getInfo() {
return request({
url: '/getInfo',
url: '/admin-api/system/auth/get-permission-info',
method: 'get'
})
}
@ -41,7 +44,7 @@ export function getInfo() {
// 退出方法
export function logout() {
return request({
url: '/logout',
url: '/admin-api/system/auth/logout',
method: 'post'
})
}
@ -49,7 +52,7 @@ export function logout() {
// 获取验证码
export function getCodeImg() {
return request({
url: '/captchaImage',
url: '/admin-api/system/captcha/isEnable',
headers: {
isToken: false
},

@ -2,7 +2,7 @@
const config = {
// baseUrl: 'https://vue.ruoyi.vip/prod-api',
// baseUrl: 'http://localhost/prod-api',
baseUrl: 'http://localhost:8080',
baseUrl: 'http://127.0.0.1:48080',
//cloud后台网关地址
// baseUrl: 'http://192.168.10.3:8080',
// 应用信息

@ -14,7 +14,7 @@
{
"path": "pages/index",
"style": {
"navigationBarTitleText": "若依移动端框架",
"navigationBarTitleText": "生管系统",
"navigationStyle": "custom"
}
},
@ -250,14 +250,20 @@
"pagePath": "pages/index",
"iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home_.png",
"text": "首页"
"text": "计划"
},
{
"pagePath": "pages/work",
"iconPath": "static/images/tabbar/work.png",
"selectedIconPath": "static/images/tabbar/work_.png",
"text": "作台"
"text": "工"
},
{
"pagePath": "pages/work",
"iconPath": "static/images/tabbar/work.png",
"selectedIconPath": "static/images/tabbar/work_.png",
"text": "投料"
},
{
"pagePath": "pages/template",
"iconPath": "static/images/tabbar/work.png",

@ -3,18 +3,18 @@
<view class="logo-content align-center justify-center flex">
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
</image>
<text class="title">若依移动端登录</text>
<text class="title">生产运营管理系统</text>
</view>
<view class="login-form-content">
<view class="input-item flex align-center">
<view class="iconfont icon-user icon"></view>
<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
</view>
<view class="input-item flex align-center">
<view class="input-item flex align-center">
<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 class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
<view v-if="captchaEnabled" class="input-item flex align-center" style="width: 60%;margin: 0px;">
<view class="iconfont icon-code icon"></view>
<input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
<view class="login-code">
@ -25,11 +25,10 @@
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
</view>
</view>
<view class="xieyi text-center">
<text class="text-grey1">登录即代表同意</text>
<text @click="handleUserAgrement" class="text-blue">用户协议</text>
<text @click="handlePrivacy" class="text-blue">隐私协议</text>
<text class="text-blue">用户协议</text>
<text class="text-blue">隐私协议</text>
</view>
</view>
</template>
@ -45,29 +44,19 @@ import { wxLogin } from '@/api/oauth';
import { setToken } from '@/utils/auth';
const userStore = useUserStore()
const codeUrl = ref("");
const captchaEnabled = ref(true); //
const useWxLogin = ref(false); // 使
const captchaEnabled = ref(false); //
const globalConfig = ref(config);
const loginForm = ref({
tenantName: '内蒙必硕',
username: "admin",
password: "admin123",
code: "",
captchaVerification: '',
rememberMe: '',
code: '',
uuid: ''
});
if (useWxLogin.value) {
getWxCode().then(res => {
console.log(res);
wxLogin('miniapp',res).then(res => {
if(res.token != null){
setToken(res.token);
loginSuccess()
}
});
})
}
//
function getCode() {
getCodeImg().then(res => {
@ -77,8 +66,8 @@ function getCode() {
loginForm.value.uuid = res.uuid
}
})
};
}
// getCode();
async function handleLogin() {
if (loginForm.value.username === "") {
modal.msgError("请输入您的账号")
@ -113,22 +102,7 @@ function loginSuccess(result) {
})
}
//
function handlePrivacy() {
let site = globalConfig.value.appInfo.agreements[0];
uni.navigateTo({
url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
});
};
//
function handleUserAgrement() {
let site = globalConfig.value.appInfo.agreements[1]
uni.navigateTo({
url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
});
};
getCode();
</script>
<style lang="scss">

@ -8,15 +8,20 @@ export interface LoginForm {
password: string;
code: string;
uuid: string;
tenantName: string;
captchaVerification: string;
rememberMe: string;
}
const useUserStore = defineStore("user", {
state: () => ({
token: getToken(),
userId: '',
name: "",
avatar: "",
roles: Array(),
permissions: [],
menus: [],
}),
actions: {
// 登录
@ -25,11 +30,15 @@ const useUserStore = defineStore("user", {
const password = userInfo.password;
const code = userInfo.code;
const uuid = userInfo.uuid;
const tenantName = userInfo.tenantName
const captchaVerification = userInfo.captchaVerification
const rememberMe = userInfo.rememberMe
return new Promise((resolve, reject) => {
login(username, password, code, uuid)
login(username, password, code, uuid,tenantName, captchaVerification,rememberMe)
.then((res: any) => {
setToken(res.token);
this.token = res.token;
setToken(res.data.accessToken);
this.token = res.data.accessToken;
resolve(null);
})
.catch((error) => {
@ -42,20 +51,19 @@ const useUserStore = defineStore("user", {
return new Promise((resolve, reject) => {
getInfo()
.then((res: any) => {
const user = res.user;
const avatar =
user.avatar == "" || user.avatar == null
? defAva
: import.meta.env.VITE_APP_BASE_API + user.avatar;
const user = res.data.user;
// const avatar =
// user.avatar == "" || user.avatar == null ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar;
const avatar = user.avatar == "" || user.avatar == null ? defAva : user.avatar;
if (res.roles && res.roles.length > 0) {
// 验证返回的roles是否是一个非空数组
this.roles = res.roles;
this.permissions = res.permissions;
this.roles = res.data.roles;
this.permissions = res.data.permissions;
} else {
this.roles = ["ROLE_DEFAULT"];
}
this.name = user.userName;
this.name = user.nickname;
this.userId = user.id;
this.avatar = avatar;
resolve(res);
})

@ -12,6 +12,7 @@ const request = <T>(config: RequestConfig): Promise<ResponseData<T>> => {
// 是否需要设置 token
const isToken = (config.headers || {}).isToken === false
config.header = config.header || {}
config.header['tenantId'] = '1'
if (getToken() && !isToken) {
config.header['Authorization'] = 'Bearer ' + getToken()
}

Loading…
Cancel
Save