970c84e7 by 杨炀

Merge commit 'd60f1935'

2 parents 2e2f984e d60f1935
<script>
import * as loginServer from '@/common/login.js';
import * as api from '@/common/api.js';
import {
showLogin,
h5Login
} from '@/common/login.js';
import config from '@/config.js';
let firstload = false
export default {
onLaunch: function() {
console.log('App Launch');
firstload = true
this.globalData.baseUrl_api = config.baseUrl_api;
let userName = uni.getStorageSync('userName')
if (userName) {
h5Login(userName)
.then(() => {
this.globalData.isLogin = true;
let firstLoadCallback = getApp().firstLoadCallback;
if (firstLoadCallback) {
firstLoadCallback();
}
})
.catch(() => {
showLogin()
})
} else {
this.globalData.isLogin = false;
showLogin()
}
},
onShow: function() {
console.log('App Show');
uni.getStorage({
key: 'token',
success: () => {
this.globalData.isLogin = true;
let firstLoadCallback = getApp().firstLoadCallback;
if (firstLoadCallback) {
firstLoadCallback();
}
},
fail: () => {
this.globalData.isLogin = false;
}
})
},
onHide: function() {
console.log('App Hide');
......
......@@ -187,11 +187,70 @@ function h5Login(userName) {
params: {
username: userName
}
}).then((res) => {
}).then((res) => {
uni.setStorageSync('token', 'Bearer ' + res.data.token);
})
}
function showLogin(callback) {
uni.clearStorageSync()
uni.showModal({
title: '请输入工号,进行身份验证',
showCancel: false,
editable: true,
placeholderText: '工号',
complete: (res) => {
if (res.cancel) {
setTimeout(() => {
showLogin(callback)
})
return
}
if (!res.content) {
uni.showToast({
title: '工号不能为空',
icon: 'none',
duration: 3000
})
setTimeout(() => {
showLogin(callback)
})
return
}
if (res.confirm) {
h5Login(res.content)
.then(() => {
uni.showToast({
title: '验证成功',
icon: 'none',
duration: 1000
})
uni.setStorageSync('userName', res.content)
if (callback) {
callback()
}
})
.catch(() => {
showLogin(callback)
})
}
}
})
}
function h5LoginAuto() {
let userName = uni.getStorageSync('userName')
if (userName) {
return h5Login(userName)
} else {
showLogin()
}
}
function initData() {
console.log('initData')
......@@ -241,5 +300,7 @@ export {
getWxUserPhone,
checkUserAuth,
h5Login,
showLogin,
h5LoginAuto,
initData
}
\ No newline at end of file
......
import config from '@/config.js'
import {
pcLogin,
getNowOpenId,
initData
pcLogin,
getNowOpenId,
initData,
showLogin,
h5LoginAuto
} from './login'
const excludeUrls = ['/system/wx/getUserInfo']
......@@ -34,7 +36,7 @@ function getHeaders() {
let request = function(req) {
req.method = req.method.toUpperCase()
if (!['GET', 'POST','PUT', 'DELETE'].includes(req.method)) {
if (!['GET', 'POST', 'PUT', 'DELETE'].includes(req.method)) {
uni.showToast({
title: `暂不支持的请求方式: ${req.method}`,
icon: 'none'
......@@ -63,26 +65,17 @@ let request = function(req) {
} else {
//登录超时
if (data.code == 60002 || data.code == 60001) {
if (req.url != '/system/wx/getUserInfo') {
reLogin();
}
}
else if (data.code == 401 && req.url != '/system/wx/getUserInfo') {
pcLogin()
.then(()=>{
return getNowOpenId()
})
.then(()=>{
return initData()
})
.then(()=>{
uni.hideLoading();
uni.redirectTo({
url:getCurrentPages()[getCurrentPages().length-1].$page.fullPath
})
})
}
else {
showLogin()
} else if (data.code == 401) {
h5LoginAuto()
.then(() => {
uni.hideLoading();
uni.redirectTo({
url: getCurrentPages()[getCurrentPages()
.length - 1].$page.fullPath
})
})
} else {
if (!excludeUrls.includes(req.url)) {
uni.showToast({
title: data.msg,
......@@ -142,4 +135,4 @@ function pcLoginByOpenId(appId, openId) {
}
export default request;
export default request;
\ No newline at end of file
......
<template>
<uni-popup class="popYanZhengBox" ref="popYanZheng" type="center">
<view class="popup-content">
<view class="t">温馨提示</view>
<view class="p">该微信未绑定系统内手机号,绑定手机号后正常使用。</view>
<button class="start" type="default" @click="login">绑定手机号</button>
</view>
</uni-popup>
</template>
<script setup>
import {
onMounted,
ref
} from "vue";
import {
h5Login
} from '@/common/login.js';
const app = getApp();
const popYanZheng = ref(null);
onMounted(() => {
if (!app.globalData.isLogin) {
popYanZheng.value.open()
}
})
function login() {
h5Login('12000013583')
.then(() => {
popYanZheng.value.close()
})
}
</script>
<style>
</style>
\ No newline at end of file
// prod
// const baseUrl_api = 'https://research.wtwuxicenter.com/';
// const baseUrl_api = 'https://research.wtwuxicenter.com/';
// staging
const baseUrl_api = "http://192.168.1.118:8080";
export default {
baseUrl_api: baseUrl_api
baseUrl_api
};
\ No newline at end of file
......
......@@ -18,8 +18,6 @@ import login from '@/components/login'
export function createApp() {
const app = createSSRApp(App)
app.component('showLogin', login)
return {
app
}
......
<template>
<view class="page">
<show-login></show-login>
<view class="uni-margin-wrap">
<!-- <view class="logobox">
<image class="logo" :src="venue.venueLogo"></image>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!