This commit is contained in:
nyoung 2024-08-22 20:54:43 +08:00
parent 1220174322
commit c2648e42f3
6 changed files with 86 additions and 38 deletions

12
App.vue
View File

@ -2,14 +2,22 @@
import config from '@/config' import config from '@/config'
import request from './utils/request'; import request from './utils/request';
import { import {
getToken getToken,
setTenantId
} from '@/utils/auth' } from '@/utils/auth'
import {
getTenantIdByWebsite
} from '@/api/login.js'
export default { export default {
onLaunch: function() { onLaunch: function() {
/*#ifdef MP*/ /*#ifdef MP*/
return return
/*#endif*/ /*#endif*/
if (!getToken()) { if (!getToken()) {
return return
} }
@ -106,4 +114,4 @@
body { body {
height: 100%; height: 100%;
} }
</style> </style>

View File

@ -9,7 +9,7 @@ export function login(username, password, code, uuid) {
uuid uuid
} }
return request({ return request({
'url': '/login', 'url': '/rescue/login',
headers: { headers: {
isToken: false isToken: false
}, },
@ -21,7 +21,7 @@ export function login(username, password, code, uuid) {
// 获取用户详细信息 // 获取用户详细信息
export function getInfo() { export function getInfo() {
return request({ return request({
'url': '/getInfo', 'url': '/rescue/getInfo',
'method': 'get' 'method': 'get'
}) })
} }
@ -29,7 +29,7 @@ export function getInfo() {
// 退出方法 // 退出方法
export function logout() { export function logout() {
return request({ return request({
'url': '/logout', 'url': '/rescue/logout',
'method': 'post' 'method': 'post'
}) })
} }
@ -37,11 +37,36 @@ export function logout() {
// 获取验证码 // 获取验证码
export function getCodeImg() { export function getCodeImg() {
return request({ return request({
'url': '/captchaImage', 'url': '/rescue/captchaImage',
headers: { headers: {
isToken: false isToken: false,
}, },
method: 'get', method: 'get',
timeout: 20000 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
}
})
}

View File

@ -1,6 +1,6 @@
// 应用全局配置 // 应用全局配置
module.exports = { 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',
//baseUrl: 'http://47.95.206.185:8011/rescue', //baseUrl: 'http://47.95.206.185:8011/rescue',
imagesUrl: 'http://shequ.0315e.com/static/images/pages/', imagesUrl: 'http://shequ.0315e.com/static/images/pages/',
@ -26,4 +26,4 @@ module.exports = {
} }
] ]
} }
} }

View File

@ -80,12 +80,16 @@
<script> <script>
import request from '../../utils/request'; import request from '../../utils/request';
import { loginApp } from '@/api/login.js';
import { import {
setToken setToken,
setTenantId
} from '@/utils/auth.js' } from '@/utils/auth.js'
import { import {
getToken login,
} from '@/utils/auth' getInfo,
getTenantIdByWebsite
} from '@/api/login.js'
export default { export default {
data() { data() {
return { return {
@ -117,7 +121,8 @@
tel: '', tel: '',
yzm: '', yzm: '',
wrod: '', wrod: '',
activeid: 0 activeid: 0,
tenantCode: 'lighting'
} }
}, },
computed: { computed: {
@ -135,6 +140,14 @@
} }
}, },
}, },
created(){
getTenantIdByWebsite(this.tenantCode).then(res => {
const tenantId = res.data;
if (tenantId && tenantId >= 0) {
setTenantId(tenantId)
}
})
},
methods: { methods: {
setidentity(text) { setidentity(text) {
@ -268,18 +281,10 @@
password: this.wrod, password: this.wrod,
type: 0 type: 0
} }
request({ loginApp(data).then(res => {
url: '/loginApp', setToken(res.data.accessToken)
method: 'post', this.userinfo()
data: data
}).then((res) => {
console.log('密码请求', res);
if (res.code == 200) {
setToken(res.token)
this.userinfo()
}
}) })
} }
if (this.activeid == 1) { if (this.activeid == 1) {
const data = { const data = {
@ -293,12 +298,12 @@
data: data data: data
}).then((res) => { }).then((res) => {
console.log('验证码请求', res); console.log('验证码请求', res);
if (res.code == 200) { if (res.code == 0) {
uni.showToast({ uni.showToast({
title: '登录成功', title: '登录成功',
icon: 'none' icon: 'none'
}) })
setToken(res.token) setToken(res.data.accessToken)
this.userinfo() this.userinfo()
} }
@ -308,15 +313,12 @@
}, },
userinfo() { userinfo() {
if (this.sfindex == 'user') { if (this.sfindex == 'user') {
request({ getInfo().then((res) => {
url: '/getAppInfo',
method: 'get',
}).then((res) => {
let userJson = {} let userJson = {}
userJson.userId = res.user.userId userJson.userId = res.data.user.userId
uni.setStorageSync('userInfo', res.user) uni.setStorageSync('userInfo', res.data.user)
uni.setStorageSync('userId', res.user.userId) uni.setStorageSync('userId', res.data.user.userId)
uni.setStorageSync('role', res.role) uni.setStorageSync('role', res.data.role)
this.goselect() this.goselect()
}) })
} }

View File

@ -1,5 +1,5 @@
const TokenKey = 'App-Token' const TokenKey = 'App-Token'
const TenantIdKey = 'TENANT_ID'
export function getToken() { export function getToken() {
return uni.getStorageSync(TokenKey) return uni.getStorageSync(TokenKey)
} }
@ -11,3 +11,10 @@ export function setToken(token) {
export function removeToken() { export function removeToken() {
return uni.removeStorageSync(TokenKey) return uni.removeStorageSync(TokenKey)
} }
export function setTenantId(TenantId) {
return uni.setStorageSync(TenantIdKey, TenantId);
}
export function getTenantId(){
return uni.getStorageSync(TenantIdKey)
}

View File

@ -1,6 +1,6 @@
import store from '@/store' import store from '@/store'
import config from '@/config' import config from '@/config'
import { getToken } from '@/utils/auth' import { getToken,getTenantId } from '@/utils/auth'
import errorCode from '@/utils/errorCode' import errorCode from '@/utils/errorCode'
import { toast, showConfirm, tansParams } from '@/utils/common' import { toast, showConfirm, tansParams } from '@/utils/common'
@ -20,6 +20,12 @@ const request = config => {
url = url.slice(0, -1) url = url.slice(0, -1)
config.url = url 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) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
method: config.method || 'get', method: config.method || 'get',
@ -31,7 +37,7 @@ const request = config => {
}).then(response => { }).then(response => {
// debugger // debugger
let res = response let res = response
const code = res.data.code || 200 const code = res.data.code || 200
const msg = errorCode[code] || res.data.msg || errorCode['default'] const msg = errorCode[code] || res.data.msg || errorCode['default']
if (code === 401) { if (code === 401) {