970c84e7 by 杨炀

Merge commit 'd60f1935'

2 parents 2e2f984e d60f1935
1 <script> 1 <script>
2 import * as loginServer from '@/common/login.js'; 2 import {
3 import * as api from '@/common/api.js'; 3 showLogin,
4 h5Login
5 } from '@/common/login.js';
4 import config from '@/config.js'; 6 import config from '@/config.js';
5 7
8 let firstload = false
6 export default { 9 export default {
7 onLaunch: function() { 10 onLaunch: function() {
8 console.log('App Launch'); 11 console.log('App Launch');
12 firstload = true
13
9 this.globalData.baseUrl_api = config.baseUrl_api; 14 this.globalData.baseUrl_api = config.baseUrl_api;
15
16 let userName = uni.getStorageSync('userName')
17 if (userName) {
18 h5Login(userName)
19 .then(() => {
20 this.globalData.isLogin = true;
21 let firstLoadCallback = getApp().firstLoadCallback;
22 if (firstLoadCallback) {
23 firstLoadCallback();
24 }
25 })
26 .catch(() => {
27 showLogin()
28 })
29
30 } else {
31 this.globalData.isLogin = false;
32 showLogin()
33 }
10 }, 34 },
11 onShow: function() { 35 onShow: function() {
12 console.log('App Show'); 36 console.log('App Show');
13 uni.getStorage({
14 key: 'token',
15 success: () => {
16 this.globalData.isLogin = true;
17 let firstLoadCallback = getApp().firstLoadCallback;
18 if (firstLoadCallback) {
19 firstLoadCallback();
20 }
21 },
22 fail: () => {
23 this.globalData.isLogin = false;
24 }
25 })
26 }, 37 },
27 onHide: function() { 38 onHide: function() {
28 console.log('App Hide'); 39 console.log('App Hide');
......
...@@ -187,11 +187,70 @@ function h5Login(userName) { ...@@ -187,11 +187,70 @@ function h5Login(userName) {
187 params: { 187 params: {
188 username: userName 188 username: userName
189 } 189 }
190 }).then((res) => { 190 }).then((res) => {
191 uni.setStorageSync('token', 'Bearer ' + res.data.token); 191 uni.setStorageSync('token', 'Bearer ' + res.data.token);
192 }) 192 })
193 } 193 }
194 194
195 function showLogin(callback) {
196 uni.clearStorageSync()
197
198 uni.showModal({
199 title: '请输入工号,进行身份验证',
200 showCancel: false,
201 editable: true,
202 placeholderText: '工号',
203 complete: (res) => {
204 if (res.cancel) {
205 setTimeout(() => {
206 showLogin(callback)
207 })
208 return
209 }
210 if (!res.content) {
211 uni.showToast({
212 title: '工号不能为空',
213 icon: 'none',
214 duration: 3000
215 })
216
217 setTimeout(() => {
218 showLogin(callback)
219 })
220 return
221 }
222 if (res.confirm) {
223 h5Login(res.content)
224 .then(() => {
225 uni.showToast({
226 title: '验证成功',
227 icon: 'none',
228 duration: 1000
229 })
230
231 uni.setStorageSync('userName', res.content)
232
233 if (callback) {
234 callback()
235 }
236 })
237 .catch(() => {
238 showLogin(callback)
239 })
240 }
241 }
242 })
243 }
244
245 function h5LoginAuto() {
246 let userName = uni.getStorageSync('userName')
247 if (userName) {
248 return h5Login(userName)
249 } else {
250 showLogin()
251 }
252 }
253
195 function initData() { 254 function initData() {
196 console.log('initData') 255 console.log('initData')
197 256
...@@ -241,5 +300,7 @@ export { ...@@ -241,5 +300,7 @@ export {
241 getWxUserPhone, 300 getWxUserPhone,
242 checkUserAuth, 301 checkUserAuth,
243 h5Login, 302 h5Login,
303 showLogin,
304 h5LoginAuto,
244 initData 305 initData
245 } 306 }
...\ No newline at end of file ...\ No newline at end of file
......
1 import config from '@/config.js' 1 import config from '@/config.js'
2 import { 2 import {
3 pcLogin, 3 pcLogin,
4 getNowOpenId, 4 getNowOpenId,
5 initData 5 initData,
6 showLogin,
7 h5LoginAuto
6 } from './login' 8 } from './login'
7 9
8 const excludeUrls = ['/system/wx/getUserInfo'] 10 const excludeUrls = ['/system/wx/getUserInfo']
...@@ -34,7 +36,7 @@ function getHeaders() { ...@@ -34,7 +36,7 @@ function getHeaders() {
34 36
35 let request = function(req) { 37 let request = function(req) {
36 req.method = req.method.toUpperCase() 38 req.method = req.method.toUpperCase()
37 if (!['GET', 'POST','PUT', 'DELETE'].includes(req.method)) { 39 if (!['GET', 'POST', 'PUT', 'DELETE'].includes(req.method)) {
38 uni.showToast({ 40 uni.showToast({
39 title: `暂不支持的请求方式: ${req.method}`, 41 title: `暂不支持的请求方式: ${req.method}`,
40 icon: 'none' 42 icon: 'none'
...@@ -63,26 +65,17 @@ let request = function(req) { ...@@ -63,26 +65,17 @@ let request = function(req) {
63 } else { 65 } else {
64 //登录超时 66 //登录超时
65 if (data.code == 60002 || data.code == 60001) { 67 if (data.code == 60002 || data.code == 60001) {
66 if (req.url != '/system/wx/getUserInfo') { 68 showLogin()
67 reLogin(); 69 } else if (data.code == 401) {
68 } 70 h5LoginAuto()
69 } 71 .then(() => {
70 else if (data.code == 401 && req.url != '/system/wx/getUserInfo') { 72 uni.hideLoading();
71 pcLogin() 73 uni.redirectTo({
72 .then(()=>{ 74 url: getCurrentPages()[getCurrentPages()
73 return getNowOpenId() 75 .length - 1].$page.fullPath
74 }) 76 })
75 .then(()=>{ 77 })
76 return initData() 78 } else {
77 })
78 .then(()=>{
79 uni.hideLoading();
80 uni.redirectTo({
81 url:getCurrentPages()[getCurrentPages().length-1].$page.fullPath
82 })
83 })
84 }
85 else {
86 if (!excludeUrls.includes(req.url)) { 79 if (!excludeUrls.includes(req.url)) {
87 uni.showToast({ 80 uni.showToast({
88 title: data.msg, 81 title: data.msg,
...@@ -142,4 +135,4 @@ function pcLoginByOpenId(appId, openId) { ...@@ -142,4 +135,4 @@ function pcLoginByOpenId(appId, openId) {
142 } 135 }
143 136
144 137
145 export default request; 138 export default request;
...\ No newline at end of file ...\ No newline at end of file
......
1 <template>
2 <uni-popup class="popYanZhengBox" ref="popYanZheng" type="center">
3 <view class="popup-content">
4 <view class="t">温馨提示</view>
5 <view class="p">该微信未绑定系统内手机号,绑定手机号后正常使用。</view>
6 <button class="start" type="default" @click="login">绑定手机号</button>
7 </view>
8 </uni-popup>
9 </template>
10
11 <script setup>
12 import {
13 onMounted,
14 ref
15 } from "vue";
16 import {
17 h5Login
18 } from '@/common/login.js';
19
20 const app = getApp();
21
22 const popYanZheng = ref(null);
23
24
25 onMounted(() => {
26 if (!app.globalData.isLogin) {
27 popYanZheng.value.open()
28 }
29 })
30
31 function login() {
32 h5Login('12000013583')
33 .then(() => {
34 popYanZheng.value.close()
35 })
36 }
37 </script>
38
39 <style>
40
41 </style>
...\ No newline at end of file ...\ No newline at end of file
1 // prod 1 // prod
2 // const baseUrl_api = 'https://research.wtwuxicenter.com/'; 2 // const baseUrl_api = 'https://research.wtwuxicenter.com/';
3 3
4 4
5 // staging 5 // staging
6 const baseUrl_api = "http://192.168.1.118:8080"; 6 const baseUrl_api = "http://192.168.1.118:8080";
7 7
8 export default { 8 export default {
9 baseUrl_api: baseUrl_api 9 baseUrl_api
10 }; 10 };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,8 +18,6 @@ import login from '@/components/login' ...@@ -18,8 +18,6 @@ import login from '@/components/login'
18 18
19 export function createApp() { 19 export function createApp() {
20 const app = createSSRApp(App) 20 const app = createSSRApp(App)
21 app.component('showLogin', login)
22
23 return { 21 return {
24 app 22 app
25 } 23 }
......
1 <template> 1 <template>
2 <view class="page"> 2 <view class="page">
3 <show-login></show-login>
4 <view class="uni-margin-wrap"> 3 <view class="uni-margin-wrap">
5 <!-- <view class="logobox"> 4 <!-- <view class="logobox">
6 <image class="logo" :src="venue.venueLogo"></image> 5 <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!