fix login

main
chenshuichuan 2 years ago
parent 000dd462ab
commit d2bc99a1de

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

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

@ -14,7 +14,7 @@
{ {
"path": "pages/index", "path": "pages/index",
"style": { "style": {
"navigationBarTitleText": "若依移动端框架", "navigationBarTitleText": "生管系统",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
@ -250,13 +250,19 @@
"pagePath": "pages/index", "pagePath": "pages/index",
"iconPath": "static/images/tabbar/home.png", "iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home_.png", "selectedIconPath": "static/images/tabbar/home_.png",
"text": "首页" "text": "计划"
}, },
{ {
"pagePath": "pages/work", "pagePath": "pages/work",
"iconPath": "static/images/tabbar/work.png", "iconPath": "static/images/tabbar/work.png",
"selectedIconPath": "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", "pagePath": "pages/template",

@ -3,7 +3,7 @@
<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">
@ -14,7 +14,7 @@
<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" 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> <view class="iconfont icon-code icon"></view>
<input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" /> <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
<view class="login-code"> <view class="login-code">
@ -25,11 +25,10 @@
<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>
</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 class="text-blue">用户协议</text>
<text @click="handlePrivacy" class="text-blue">隐私协议</text> <text class="text-blue">隐私协议</text>
</view> </view>
</view> </view>
</template> </template>
@ -45,29 +44,19 @@ import { wxLogin } from '@/api/oauth';
import { setToken } from '@/utils/auth'; import { setToken } from '@/utils/auth';
const userStore = useUserStore() const userStore = useUserStore()
const codeUrl = ref(""); const codeUrl = ref("");
const captchaEnabled = ref(true); // const captchaEnabled = ref(false); //
const useWxLogin = ref(false); // 使
const globalConfig = ref(config); const globalConfig = ref(config);
const loginForm = ref({ const loginForm = ref({
tenantName: '内蒙必硕',
username: "admin", username: "admin",
password: "admin123", password: "admin123",
code: "", captchaVerification: '',
rememberMe: '',
code: '',
uuid: '' 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() { function getCode() {
getCodeImg().then(res => { getCodeImg().then(res => {
@ -77,8 +66,8 @@ function getCode() {
loginForm.value.uuid = res.uuid loginForm.value.uuid = res.uuid
} }
}) })
}; }
// getCode();
async function handleLogin() { async function handleLogin() {
if (loginForm.value.username === "") { if (loginForm.value.username === "") {
modal.msgError("请输入您的账号") 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> </script>
<style lang="scss"> <style lang="scss">

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

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

Loading…
Cancel
Save