登录
This commit is contained in:
parent
1220174322
commit
c2648e42f3
10
App.vue
10
App.vue
@ -2,14 +2,22 @@
|
||||
import config from '@/config'
|
||||
import request from './utils/request';
|
||||
import {
|
||||
getToken
|
||||
getToken,
|
||||
setTenantId
|
||||
} from '@/utils/auth'
|
||||
import {
|
||||
getTenantIdByWebsite
|
||||
} from '@/api/login.js'
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
/*#ifdef MP*/
|
||||
return
|
||||
/*#endif*/
|
||||
|
||||
|
||||
|
||||
|
||||
if (!getToken()) {
|
||||
return
|
||||
}
|
||||
|
35
api/login.js
35
api/login.js
@ -9,7 +9,7 @@ export function login(username, password, code, uuid) {
|
||||
uuid
|
||||
}
|
||||
return request({
|
||||
'url': '/login',
|
||||
'url': '/rescue/login',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
@ -21,7 +21,7 @@ export function login(username, password, code, uuid) {
|
||||
// 获取用户详细信息
|
||||
export function getInfo() {
|
||||
return request({
|
||||
'url': '/getInfo',
|
||||
'url': '/rescue/getInfo',
|
||||
'method': 'get'
|
||||
})
|
||||
}
|
||||
@ -29,7 +29,7 @@ export function getInfo() {
|
||||
// 退出方法
|
||||
export function logout() {
|
||||
return request({
|
||||
'url': '/logout',
|
||||
'url': '/rescue/logout',
|
||||
'method': 'post'
|
||||
})
|
||||
}
|
||||
@ -37,11 +37,36 @@ export function logout() {
|
||||
// 获取验证码
|
||||
export function getCodeImg() {
|
||||
return request({
|
||||
'url': '/captchaImage',
|
||||
'url': '/rescue/captchaImage',
|
||||
headers: {
|
||||
isToken: false
|
||||
isToken: false,
|
||||
},
|
||||
method: 'get',
|
||||
timeout: 20000
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 获取验证码
|
||||
export function loginApp(data) {
|
||||
return request({
|
||||
'url': '/rescue/loginApp',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
method: 'post',
|
||||
timeout: 20000,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 使用租户域名(标识),获得租户编号
|
||||
export function getTenantIdByWebsite(website) {
|
||||
return request({
|
||||
url: '/system/tenant/get-by-website',
|
||||
method: 'get',
|
||||
params: {
|
||||
website
|
||||
}
|
||||
})
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// 应用全局配置
|
||||
module.exports = {
|
||||
baseUrl: 'http://192.168.1.8:48080/admin-api',
|
||||
baseUrl: 'http://localhost:48080/admin-api',
|
||||
// baseUrl: 'http://47.95.206.185:8011/rescue',
|
||||
//baseUrl: 'http://47.95.206.185:8011/rescue',
|
||||
imagesUrl: 'http://shequ.0315e.com/static/images/pages/',
|
||||
|
@ -80,12 +80,16 @@
|
||||
|
||||
<script>
|
||||
import request from '../../utils/request';
|
||||
import { loginApp } from '@/api/login.js';
|
||||
import {
|
||||
setToken
|
||||
setToken,
|
||||
setTenantId
|
||||
} from '@/utils/auth.js'
|
||||
import {
|
||||
getToken
|
||||
} from '@/utils/auth'
|
||||
login,
|
||||
getInfo,
|
||||
getTenantIdByWebsite
|
||||
} from '@/api/login.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -117,7 +121,8 @@
|
||||
tel: '',
|
||||
yzm: '',
|
||||
wrod: '',
|
||||
activeid: 0
|
||||
activeid: 0,
|
||||
tenantCode: 'lighting'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -135,6 +140,14 @@
|
||||
}
|
||||
},
|
||||
},
|
||||
created(){
|
||||
getTenantIdByWebsite(this.tenantCode).then(res => {
|
||||
const tenantId = res.data;
|
||||
if (tenantId && tenantId >= 0) {
|
||||
setTenantId(tenantId)
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
||||
setidentity(text) {
|
||||
@ -268,18 +281,10 @@
|
||||
password: this.wrod,
|
||||
type: 0
|
||||
}
|
||||
request({
|
||||
url: '/loginApp',
|
||||
method: 'post',
|
||||
data: data
|
||||
}).then((res) => {
|
||||
console.log('密码请求', res);
|
||||
if (res.code == 200) {
|
||||
setToken(res.token)
|
||||
loginApp(data).then(res => {
|
||||
setToken(res.data.accessToken)
|
||||
this.userinfo()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
if (this.activeid == 1) {
|
||||
const data = {
|
||||
@ -293,12 +298,12 @@
|
||||
data: data
|
||||
}).then((res) => {
|
||||
console.log('验证码请求', res);
|
||||
if (res.code == 200) {
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
})
|
||||
setToken(res.token)
|
||||
setToken(res.data.accessToken)
|
||||
this.userinfo()
|
||||
|
||||
}
|
||||
@ -308,15 +313,12 @@
|
||||
},
|
||||
userinfo() {
|
||||
if (this.sfindex == 'user') {
|
||||
request({
|
||||
url: '/getAppInfo',
|
||||
method: 'get',
|
||||
}).then((res) => {
|
||||
getInfo().then((res) => {
|
||||
let userJson = {}
|
||||
userJson.userId = res.user.userId
|
||||
uni.setStorageSync('userInfo', res.user)
|
||||
uni.setStorageSync('userId', res.user.userId)
|
||||
uni.setStorageSync('role', res.role)
|
||||
userJson.userId = res.data.user.userId
|
||||
uni.setStorageSync('userInfo', res.data.user)
|
||||
uni.setStorageSync('userId', res.data.user.userId)
|
||||
uni.setStorageSync('role', res.data.role)
|
||||
this.goselect()
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
const TokenKey = 'App-Token'
|
||||
|
||||
const TenantIdKey = 'TENANT_ID'
|
||||
export function getToken() {
|
||||
return uni.getStorageSync(TokenKey)
|
||||
}
|
||||
@ -11,3 +11,10 @@ export function setToken(token) {
|
||||
export function removeToken() {
|
||||
return uni.removeStorageSync(TokenKey)
|
||||
}
|
||||
|
||||
export function setTenantId(TenantId) {
|
||||
return uni.setStorageSync(TenantIdKey, TenantId);
|
||||
}
|
||||
export function getTenantId(){
|
||||
return uni.getStorageSync(TenantIdKey)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import store from '@/store'
|
||||
import config from '@/config'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import { getToken,getTenantId } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
||||
|
||||
@ -20,6 +20,12 @@ const request = config => {
|
||||
url = url.slice(0, -1)
|
||||
config.url = url
|
||||
}
|
||||
// 设置租户
|
||||
const isTanantId = (config.headers || {}).isTanantId === false
|
||||
config.header = config.header || {}
|
||||
if(getTenantId() && !isTanantId){
|
||||
config.header['Tenant-Id'] = getTenantId()
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
method: config.method || 'get',
|
||||
|
Loading…
Reference in New Issue
Block a user