登录
Showing
6 changed files
with
137 additions
and
256 deletions
| 1 | <script> | 1 | <script> |
| 2 | import * as loginServer from '@/common/login.js'; | 2 | import { |
| 3 | import * as api from '@/common/api.js'; | 3 | h5Login |
| 4 | import config from '@/config.js'; | 4 | } from '@/common/login.js'; |
| 5 | import * as api from '@/common/api.js'; | ||
| 6 | import config from '@/config.js'; | ||
| 5 | 7 | ||
| 6 | 8 | let loginUrl=['pages/index/login', 'pages/index/register'] | |
| 7 | let firstload = false | 9 | let firstload = false |
| 8 | export default { | 10 | export default { |
| 9 | onLaunch: function() { | 11 | onLaunch: function(options) { |
| 10 | console.log('App Launch'); | 12 | console.log('App Launch', options); |
| 11 | firstload = true | 13 | firstload = true |
| 12 | this.globalData.baseUrl = config.baseUrl; | ||
| 13 | this.globalData.baseUrl_api = config.baseUrl_api; | ||
| 14 | this.globalData.fileUrl = config.fileUrl; | ||
| 15 | |||
| 16 | new Promise((resolve, reject) => { | ||
| 17 | uni.checkSession({ | ||
| 18 | success: res => { | ||
| 19 | loginServer | ||
| 20 | .getCurrUser(true) | ||
| 21 | .catch(() => { | ||
| 22 | return loginServer.pcLogin(); | ||
| 23 | }) | ||
| 24 | .then(user => { | ||
| 25 | resolve(user); | ||
| 26 | }); | ||
| 27 | }, | ||
| 28 | fail: res => { | ||
| 29 | loginServer | ||
| 30 | .wxLogin() | ||
| 31 | .then(loginRes => { | ||
| 32 | return loginServer.pcLogin(loginRes.code); | ||
| 33 | }) | ||
| 34 | .then(user => { | ||
| 35 | resolve(user); | ||
| 36 | }); | ||
| 37 | } | ||
| 38 | }); | ||
| 39 | }) | ||
| 40 | .then(()=>{ | ||
| 41 | return loginServer.getNowOpenId() | ||
| 42 | }) | ||
| 43 | .then(() => { | ||
| 44 | return loginServer.initData() | ||
| 45 | // console.log(22222222) | ||
| 46 | // const currUser = uni.getStorageSync('currUser'); | ||
| 47 | // // console.log(currUser) | ||
| 48 | // return Promise.all([api.getVenue(), api.getOwnMemberInfo()]).then(res => { | ||
| 49 | // let ven = res[0].data; | ||
| 50 | // let men = res[1]?.data; | ||
| 51 | |||
| 52 | // if (ven.venuePic) { | ||
| 53 | // ven.venuePicArr = ven.venuePic.split(','); | ||
| 54 | // } | ||
| 55 | // if (ven.businessPeriod) { | ||
| 56 | // ven.startBus = ven.businessPeriod.split(',')[0]; | ||
| 57 | // ven.endBus = ven.businessPeriod.split(',')[1]; | ||
| 58 | // } | ||
| 59 | // ven.latitude = ven.lal.split(',')[0]; | ||
| 60 | // ven.longitude = ven.lal.split(',')[1]; | ||
| 61 | 14 | ||
| 62 | // this.globalData.venue = ven; | 15 | this.globalData.baseUrl_api = config.baseUrl_api; |
| 63 | // this.globalData.isVip = men?.isVip; | ||
| 64 | // // this.globalData.relateProjectId = men.info.relateProjectId; | ||
| 65 | // this.globalData.relateProjectIdList = men?.info?.relateProjectIdList; | ||
| 66 | // this.globalData.relateVenueProjectIdList = men?.info?.relateVenueProjectIdList; | ||
| 67 | 16 | ||
| 68 | // this.globalData.venueConfig = { | 17 | if(loginUrl.indexOf( options.path)==-1){ |
| 69 | // normalOverDay: ven.resSiteConfig?.normalOrderNum, | 18 | let userName = uni.getStorageSync('userName') |
| 70 | // normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0], | 19 | if (userName) { |
| 71 | // normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1] | 20 | h5Login(userName) |
| 72 | // }; | ||
| 73 | // if (men?.isVip) { | ||
| 74 | // this.globalData.venueConfig.memberOverDay = ven.resSiteConfig?.memberOrderNum; | ||
| 75 | // this.globalData.venueConfig.memberPeriodStart = ven.resSiteConfig?.memberOrderPeriod.split(',')[0]; | ||
| 76 | // this.globalData.venueConfig.memberPeriodEnd = ven.resSiteConfig?.memberOrderPeriod.split(',')[1]; | ||
| 77 | // } | ||
| 78 | // }); | ||
| 79 | }) | ||
| 80 | .then(() => { | 21 | .then(() => { |
| 81 | this.globalData.isLogin = true; | 22 | this.globalData.isLogin = true; |
| 82 | let firstLoadCallback = getApp().firstLoadCallback; | 23 | let firstLoadCallback = getApp().firstLoadCallback; |
| 83 | if (firstLoadCallback) { | 24 | if (firstLoadCallback) { |
| 84 | firstLoadCallback(); | 25 | firstLoadCallback(); |
| 85 | } | 26 | } |
| 86 | }); | 27 | }) |
| 87 | }, | ||
| 88 | onShow: function() { | ||
| 89 | console.log('App Show'); | ||
| 90 | // loginServer.getNowOpenId() | ||
| 91 | if (!firstload) { | ||
| 92 | loginServer.getCurrUser(true) | ||
| 93 | .catch(() => { | 28 | .catch(() => { |
| 94 | return loginServer.pcLogin().then(() => { | ||
| 95 | uni.redirectTo({ | 29 | uni.redirectTo({ |
| 96 | url: getCurrentPages()[getCurrentPages().length - 1].$page.fullPath | 30 | url: '/pages/index/login' |
| 97 | }) | 31 | }) |
| 98 | }); | ||
| 99 | }) | 32 | }) |
| 33 | } else { | ||
| 34 | this.globalData.isLogin = false; | ||
| 35 | uni.redirectTo({ | ||
| 36 | url: '/pages/index/login' | ||
| 37 | }) | ||
| 38 | } | ||
| 100 | } | 39 | } |
| 101 | }, | 40 | }, |
| 41 | onShow: function() { | ||
| 42 | console.log('App Show'); | ||
| 43 | }, | ||
| 102 | onHide: function() { | 44 | onHide: function() { |
| 103 | console.log('App Hide'); | 45 | console.log('App Hide'); |
| 104 | } | 46 | } |
| 105 | }; | 47 | }; |
| 106 | </script> | 48 | </script> |
| 107 | 49 | ||
| 108 | <style lang="scss"> | 50 | <style lang="scss"> | ... | ... |
| 1 | import request from './request' | 1 | import request from './request' |
| 2 | import * as api from '@/common/api.js'; | 2 | import * as api from '@/common/api.js' |
| 3 | 3 | ||
| 4 | let appId = '' | 4 | let appId = '' |
| 5 | // #ifdef MP | 5 | // #ifdef MP |
| 6 | const accountInfo = uni.getAccountInfoSync() | 6 | const accountInfo = uni.getAccountInfoSync() |
| 7 | const appId = accountInfo.miniProgram.appId; | 7 | appId = accountInfo.miniProgram.appId |
| 8 | // #endif | 8 | // #endif |
| 9 | 9 | ||
| 10 | function wxLogin() { | 10 | function wxLogin() { |
| ... | @@ -22,81 +22,59 @@ function wxLogin() { | ... | @@ -22,81 +22,59 @@ function wxLogin() { |
| 22 | }) | 22 | }) |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | function pcLogin(code) { | 25 | function pcLogin(data) { |
| 26 | if (code) { | 26 | return request({ |
| 27 | return pcLoginByCode(code) | 27 | url: '/login', |
| 28 | } else { | 28 | method: 'post', |
| 29 | const currUser = uni.getStorageSync('currUser') || {} | 29 | params: data |
| 30 | if (currUser.openId) { | 30 | }).then((res) => { |
| 31 | return pcLoginByOpenId(currUser.openId); | 31 | uni.setStorageSync('userName', data.username) |
| 32 | } else { | 32 | uni.setStorageSync('token', 'Bearer ' + res.data.token) |
| 33 | return wxLogin().then((loginRes) => { | ||
| 34 | return pcLoginByCode(loginRes.code) | ||
| 35 | }) | 33 | }) |
| 36 | } | ||
| 37 | } | ||
| 38 | } | 34 | } |
| 39 | 35 | ||
| 40 | function pcLoginByOpenId(openId) { | 36 | function h5Login(userName) { |
| 41 | return request({ | 37 | return request({ |
| 42 | url: "/system/wx/loginByOpenId", | 38 | url: `/h5Login`, |
| 43 | method: "POST", | 39 | method: 'post', |
| 44 | params: { | 40 | params: { |
| 45 | appId: appId, | 41 | username: userName |
| 46 | openId: openId | ||
| 47 | } | 42 | } |
| 48 | }).then((res) => { | 43 | }).then((res) => { |
| 49 | let user = res.data; | 44 | uni.setStorageSync('token', 'Bearer ' + res.data.token) |
| 50 | // console.log("openId " + openId, user) | ||
| 51 | |||
| 52 | uni.setStorageSync('token', 'Bearer ' + user.token); | ||
| 53 | uni.setStorageSync('currUser', user); | ||
| 54 | return user; | ||
| 55 | }).catch(() => { | ||
| 56 | uni.removeStorageSync('currUser') | ||
| 57 | }) | 45 | }) |
| 58 | } | 46 | } |
| 59 | 47 | ||
| 60 | function pcLoginByCode(code) { | 48 | function h5LoginAuto() { |
| 61 | return request({ | 49 | const userName = uni.getStorageSync('userName') |
| 62 | // url: "/weixin/api/login", | 50 | if (userName) { |
| 63 | url: "/system/wx/loginByJsCode", | 51 | return h5Login(userName) |
| 64 | method: "POST", | 52 | } else { |
| 65 | params: { | 53 | uni.redirectTo({ |
| 66 | appId: appId, | 54 | url: '/pages/index/login' |
| 67 | jsCode: code | ||
| 68 | } | ||
| 69 | }).then((res) => { | ||
| 70 | let user = res.data | ||
| 71 | // console.log("code: " + code, user) | ||
| 72 | // getNowOpenId() | ||
| 73 | uni.setStorageSync('token', 'Bearer ' + user.token); | ||
| 74 | uni.setStorageSync('currUser', user); | ||
| 75 | return user; | ||
| 76 | }).catch((err) => { | ||
| 77 | uni.removeStorageSync('currUser') | ||
| 78 | }) | 55 | }) |
| 56 | } | ||
| 79 | } | 57 | } |
| 80 | 58 | ||
| 81 | function getCurrUser(isAuto) { | 59 | function getCurrUser(isAuto) { |
| 82 | return request({ | 60 | return request({ |
| 83 | url: "/system/wx/getUserInfo", | 61 | url: '/system/wx/getUserInfo', |
| 84 | method: "GET", | 62 | method: 'GET', |
| 85 | opts: { | 63 | opts: { |
| 86 | isAuto: isAuto | 64 | isAuto: isAuto |
| 87 | } | 65 | } |
| 88 | }).then((res) => { | 66 | }).then((res) => { |
| 89 | let user = res.data; | 67 | const user = res.data |
| 90 | uni.setStorageSync('currUser', user); | 68 | uni.setStorageSync('currUser', user) |
| 91 | return user | 69 | return user |
| 92 | }) | 70 | }) |
| 93 | } | 71 | } |
| 94 | 72 | ||
| 95 | function getWxUser() { | 73 | function getWxUser() { |
| 96 | return new Promise((resolve, reject) => { | 74 | return new Promise((resolve, reject) => { |
| 97 | const currUser = uni.getStorageSync('currUser'); | 75 | const currUser = uni.getStorageSync('currUser') |
| 98 | // getNowOpenId() | 76 | // getNowOpenId() |
| 99 | const nowOpenId = uni.getStorageSync('nowOpenId'); | 77 | const nowOpenId = uni.getStorageSync('nowOpenId') |
| 100 | uni.getUserProfile({ | 78 | uni.getUserProfile({ |
| 101 | desc: '用于完善用户信息', | 79 | desc: '用于完善用户信息', |
| 102 | success: function(infoRes) { | 80 | success: function(infoRes) { |
| ... | @@ -104,7 +82,7 @@ function getWxUser() { | ... | @@ -104,7 +82,7 @@ function getWxUser() { |
| 104 | 82 | ||
| 105 | request({ | 83 | request({ |
| 106 | url: `/system/wx/updateWxUser?openId=${nowOpenId}`, | 84 | url: `/system/wx/updateWxUser?openId=${nowOpenId}`, |
| 107 | method: "POST", | 85 | method: 'POST', |
| 108 | params: { | 86 | params: { |
| 109 | appId: appId, | 87 | appId: appId, |
| 110 | openId: nowOpenId, | 88 | openId: nowOpenId, |
| ... | @@ -116,9 +94,9 @@ function getWxUser() { | ... | @@ -116,9 +94,9 @@ function getWxUser() { |
| 116 | signature: infoRes.signature | 94 | signature: infoRes.signature |
| 117 | } | 95 | } |
| 118 | }).then((res) => { | 96 | }).then((res) => { |
| 119 | let user = res.data; | 97 | const user = res.data |
| 120 | uni.setStorageSync('currUser', user); | 98 | uni.setStorageSync('currUser', user) |
| 121 | resolve(user); | 99 | resolve(user) |
| 122 | }).catch(() => { | 100 | }).catch(() => { |
| 123 | reject() | 101 | reject() |
| 124 | }) | 102 | }) |
| ... | @@ -126,19 +104,19 @@ function getWxUser() { | ... | @@ -126,19 +104,19 @@ function getWxUser() { |
| 126 | fail: (res) => { | 104 | fail: (res) => { |
| 127 | reject(res) | 105 | reject(res) |
| 128 | } | 106 | } |
| 129 | }); | 107 | }) |
| 130 | }); | 108 | }) |
| 131 | } | 109 | } |
| 132 | 110 | ||
| 133 | function getWxUserPhone(phoneRes) { | 111 | function getWxUserPhone(phoneRes) { |
| 134 | // console.log(phoneRes) | 112 | // console.log(phoneRes) |
| 135 | 113 | ||
| 136 | const currUser = uni.getStorageSync('currUser'); | 114 | const currUser = uni.getStorageSync('currUser') |
| 137 | // getNowOpenId() | 115 | // getNowOpenId() |
| 138 | const nowOpenId = uni.getStorageSync('nowOpenId'); | 116 | const nowOpenId = uni.getStorageSync('nowOpenId') |
| 139 | return request({ | 117 | return request({ |
| 140 | url: `/system/wx/updateMobile?openId=${nowOpenId}`, | 118 | url: `/system/wx/updateMobile?openId=${nowOpenId}`, |
| 141 | method: "POST", | 119 | method: 'POST', |
| 142 | params: { | 120 | params: { |
| 143 | appId: appId, | 121 | appId: appId, |
| 144 | userId: currUser.id, | 122 | userId: currUser.id, |
| ... | @@ -149,10 +127,10 @@ function getWxUserPhone(phoneRes) { | ... | @@ -149,10 +127,10 @@ function getWxUserPhone(phoneRes) { |
| 149 | signature: phoneRes.signature | 127 | signature: phoneRes.signature |
| 150 | } | 128 | } |
| 151 | }).then((res) => { | 129 | }).then((res) => { |
| 152 | let user = res.data; | 130 | const user = res.data |
| 153 | // uni.setStorageSync('token', 'Bearer '+ user.token); | 131 | // uni.setStorageSync('token', 'Bearer '+ user.token); |
| 154 | uni.setStorageSync('token', user.token); | 132 | uni.setStorageSync('token', user.token) |
| 155 | uni.setStorageSync('currUser', user); | 133 | uni.setStorageSync('currUser', user) |
| 156 | return user | 134 | return user |
| 157 | }) | 135 | }) |
| 158 | } | 136 | } |
| ... | @@ -166,7 +144,7 @@ function checkUserAuth(path) { | ... | @@ -166,7 +144,7 @@ function checkUserAuth(path) { |
| 166 | uni.navigateTo({ | 144 | uni.navigateTo({ |
| 167 | url: '/pages/index/start?path=' + encodeURIComponent(path) | 145 | url: '/pages/index/start?path=' + encodeURIComponent(path) |
| 168 | }) | 146 | }) |
| 169 | return false; | 147 | return false |
| 170 | } | 148 | } |
| 171 | } | 149 | } |
| 172 | 150 | ||
| ... | @@ -183,41 +161,48 @@ function getNowOpenId() { | ... | @@ -183,41 +161,48 @@ function getNowOpenId() { |
| 183 | function initData() { | 161 | function initData() { |
| 184 | console.log('initData') | 162 | console.log('initData') |
| 185 | 163 | ||
| 186 | const currUser = uni.getStorageSync('currUser'); | 164 | // const currUser = uni.getStorageSync('currUser') |
| 187 | // console.log(currUser) | 165 | // console.log(currUser) |
| 188 | return Promise.all([api.getVenue(), api.getOwnMemberInfo()]).then(res => { | 166 | return Promise.all([api.getVenue(), api.getOwnMemberInfo()]).then(res => { |
| 189 | let ven = res[0].data; | 167 | const ven = res[0].data |
| 190 | let men = res[1]?.data; | 168 | const men = res[1]?.data |
| 191 | 169 | ||
| 192 | const app = getApp(); | 170 | const app = getApp() |
| 193 | 171 | ||
| 194 | if (ven.venuePic) { | 172 | if (ven.venuePic) { |
| 195 | ven.venuePicArr = ven.venuePic.split(','); | 173 | ven.venuePicArr = ven.venuePic.split(',') |
| 196 | } | 174 | } |
| 197 | if (ven.businessPeriod) { | 175 | if (ven.businessPeriod) { |
| 198 | ven.startBus = ven.businessPeriod.split(',')[0]; | 176 | ven.startBus = ven.businessPeriod.split(',')[0] |
| 199 | ven.endBus = ven.businessPeriod.split(',')[1]; | 177 | ven.endBus = ven.businessPeriod.split(',')[1] |
| 200 | } | 178 | } |
| 201 | ven.latitude = ven.lal.split(',')[0]; | 179 | ven.latitude = ven.lal.split(',')[0] |
| 202 | ven.longitude = ven.lal.split(',')[1]; | 180 | ven.longitude = ven.lal.split(',')[1] |
| 203 | 181 | ||
| 204 | app.globalData.venue = ven; | 182 | app.globalData.venue = ven |
| 205 | app.globalData.isVip = men?.isVip; | 183 | app.globalData.isVip = men?.isVip |
| 206 | // app.globalData.relateProjectId = men.info.relateProjectId; | 184 | // app.globalData.relateProjectId = men.info.relateProjectId; |
| 207 | app.globalData.relateProjectIdList = men?.info?.relateProjectIdList; | 185 | app.globalData.relateProjectIdList = men?.info?.relateProjectIdList |
| 208 | app.globalData.relateVenueProjectIdList = men?.info?.relateVenueProjectIdList; | 186 | app.globalData.relateVenueProjectIdList = men?.info?.relateVenueProjectIdList |
| 209 | 187 | ||
| 210 | app.globalData.venueConfig = { | 188 | app.globalData.venueConfig = { |
| 211 | normalOverDay: ven.resSiteConfig?.normalOrderNum, | 189 | normalOverDay: ven.resSiteConfig?.normalOrderNum, |
| 212 | normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0], | 190 | normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0], |
| 213 | normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1] | 191 | normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1] |
| 214 | }; | 192 | } |
| 215 | if (men?.isVip) { | 193 | if (men?.isVip) { |
| 216 | app.globalData.venueConfig.memberOverDay = ven.resSiteConfig?.memberOrderNum; | 194 | app.globalData.venueConfig.memberOverDay = ven.resSiteConfig?.memberOrderNum |
| 217 | app.globalData.venueConfig.memberPeriodStart = ven.resSiteConfig?.memberOrderPeriod.split(',')[0]; | 195 | app.globalData.venueConfig.memberPeriodStart = ven.resSiteConfig?.memberOrderPeriod.split(',')[0] |
| 218 | app.globalData.venueConfig.memberPeriodEnd = ven.resSiteConfig?.memberOrderPeriod.split(',')[1]; | 196 | app.globalData.venueConfig.memberPeriodEnd = ven.resSiteConfig?.memberOrderPeriod.split(',')[1] |
| 219 | } | 197 | } |
| 220 | }); | 198 | }) |
| 199 | } | ||
| 200 | |||
| 201 | function getCodeImg() { | ||
| 202 | return request({ | ||
| 203 | url: '/captchaImage', | ||
| 204 | method: 'get' | ||
| 205 | }) | ||
| 221 | } | 206 | } |
| 222 | 207 | ||
| 223 | export { | 208 | export { |
| ... | @@ -228,5 +213,8 @@ export { | ... | @@ -228,5 +213,8 @@ export { |
| 228 | getWxUser, | 213 | getWxUser, |
| 229 | getWxUserPhone, | 214 | getWxUserPhone, |
| 230 | checkUserAuth, | 215 | checkUserAuth, |
| 231 | initData | 216 | initData, |
| 217 | getCodeImg, | ||
| 218 | h5Login, | ||
| 219 | h5LoginAuto | ||
| 232 | } | 220 | } | ... | ... |
| 1 | import config from '@/config.js' | 1 | import config from '@/config.js' |
| 2 | import { | 2 | import { |
| 3 | pcLogin, | 3 | h5LoginAuto |
| 4 | getNowOpenId, | ||
| 5 | initData | ||
| 6 | } from './login' | 4 | } from './login' |
| 7 | 5 | ||
| 8 | const excludeUrls = ['/system/wx/getUserInfo'] | 6 | const excludeUrls = ['pages/index/login', 'pages/index/register'] |
| 9 | 7 | ||
| 10 | // 获取Token | 8 | // 获取Token |
| 11 | function getToken() { | 9 | function getToken() { |
| 12 | try { | 10 | try { |
| 13 | const token = uni.getStorageSync('token'); | 11 | const token = uni.getStorageSync('token') |
| 14 | if (token) { | 12 | if (token) { |
| 15 | return token | 13 | return token |
| 16 | } else { | 14 | } else { |
| ... | @@ -23,22 +21,22 @@ function getToken() { | ... | @@ -23,22 +21,22 @@ function getToken() { |
| 23 | 21 | ||
| 24 | // 获取请求头 | 22 | // 获取请求头 |
| 25 | function getHeaders() { | 23 | function getHeaders() { |
| 26 | let token = getToken() | 24 | const token = getToken() |
| 27 | let header = { | 25 | const header = { |
| 28 | "Authorization": token, | 26 | 'Authorization': token, |
| 29 | "Content-Type": "application/json", //根据自己的数据类型 | 27 | 'Content-Type': 'application/json' // 根据自己的数据类型 |
| 30 | // "Content-Type":"application/x-www-form-urlencoded", | 28 | // "Content-Type":"application/x-www-form-urlencoded", |
| 31 | } | 29 | } |
| 32 | return header | 30 | return header |
| 33 | } | 31 | } |
| 34 | 32 | ||
| 35 | let request = function(req) { | 33 | const request = function(req) { |
| 36 | req.method = req.method.toUpperCase() | 34 | req.method = req.method.toUpperCase() |
| 37 | if (!['GET', 'POST','PUT', 'DELETE'].includes(req.method)) { | 35 | if (!['GET', 'POST', 'PUT', 'DELETE'].includes(req.method)) { |
| 38 | uni.showToast({ | 36 | uni.showToast({ |
| 39 | title: `暂不支持的请求方式: ${req.method}`, | 37 | title: `暂不支持的请求方式: ${req.method}`, |
| 40 | icon: 'none' | 38 | icon: 'none' |
| 41 | }); | 39 | }) |
| 42 | return | 40 | return |
| 43 | } | 41 | } |
| 44 | 42 | ||
| ... | @@ -53,36 +51,14 @@ let request = function(req) { | ... | @@ -53,36 +51,14 @@ let request = function(req) { |
| 53 | url: config.baseUrl_api + req.url, | 51 | url: config.baseUrl_api + req.url, |
| 54 | method: req.method, | 52 | method: req.method, |
| 55 | data: req.params, | 53 | data: req.params, |
| 56 | header: getHeaders(), | 54 | header: getHeaders() |
| 57 | }).then(res => { | 55 | }).then(res => { |
| 58 | switch (res.statusCode) { | 56 | switch (res.statusCode) { |
| 59 | case 200: | 57 | case 200: |
| 60 | const data = res.data || {}; | 58 | const data = res.data || {} |
| 61 | if (data.code == 200) { | 59 | if (data.code === 200) { |
| 62 | resolve(data) | 60 | resolve(data) |
| 63 | } else { | 61 | } else { |
| 64 | //登录超时 | ||
| 65 | if (data.code == 60002 || data.code == 60001) { | ||
| 66 | if (req.url != '/system/wx/getUserInfo') { | ||
| 67 | reLogin(); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | else if (data.code == 401 && req.url != '/system/wx/getUserInfo') { | ||
| 71 | pcLogin() | ||
| 72 | .then(()=>{ | ||
| 73 | return getNowOpenId() | ||
| 74 | }) | ||
| 75 | .then(()=>{ | ||
| 76 | return initData() | ||
| 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)) { | 62 | if (!excludeUrls.includes(req.url)) { |
| 87 | uni.showToast({ | 63 | uni.showToast({ |
| 88 | title: data.msg, | 64 | title: data.msg, |
| ... | @@ -90,7 +66,29 @@ let request = function(req) { | ... | @@ -90,7 +66,29 @@ let request = function(req) { |
| 90 | duration: 3000 | 66 | duration: 3000 |
| 91 | }) | 67 | }) |
| 92 | } | 68 | } |
| 69 | |||
| 70 | // 登录超时 | ||
| 71 | if (data.code === 60002 || data.code === 60001) { | ||
| 72 | uni.redirectTo({ | ||
| 73 | url: '/pages/index/login' | ||
| 74 | }) | ||
| 75 | } else if (data.code === 401) { | ||
| 76 | h5LoginAuto() | ||
| 77 | .then(() => { | ||
| 78 | uni.hideLoading() | ||
| 79 | uni.redirectTo({ | ||
| 80 | url: getCurrentPages()[getCurrentPages() | ||
| 81 | .length - 1].$page.fullPath | ||
| 82 | }) | ||
| 83 | }) | ||
| 84 | .catch(() => { | ||
| 85 | uni.showToast({ | ||
| 86 | title: '服务异常,请稍后重试', | ||
| 87 | icon: 'none' | ||
| 88 | }) | ||
| 89 | }) | ||
| 93 | } | 90 | } |
| 91 | |||
| 94 | reject(res) | 92 | reject(res) |
| 95 | } | 93 | } |
| 96 | break | 94 | break |
| ... | @@ -107,39 +105,4 @@ let request = function(req) { | ... | @@ -107,39 +105,4 @@ let request = function(req) { |
| 107 | }) | 105 | }) |
| 108 | } | 106 | } |
| 109 | 107 | ||
| 110 | function reLogin() { | 108 | export default request |
| 111 | const currUser = uni.getStorageSync('currUser') || {} | ||
| 112 | if (currUser.openId) { | ||
| 113 | const accountInfo = uni.getAccountInfoSync() | ||
| 114 | pcLoginByOpenId(accountInfo.miniProgram.appId, currUser.openId) | ||
| 115 | .then((res) => { | ||
| 116 | let user = res.data; | ||
| 117 | uni.setStorageSync('token', 'Bearer ' + user.token); | ||
| 118 | uni.setStorageSync('currUser', user); | ||
| 119 | |||
| 120 | uni.showToast({ | ||
| 121 | title: '一走神把您的操作遗漏了,请重试', | ||
| 122 | icon: 'none' | ||
| 123 | }) | ||
| 124 | }).catch(() => { | ||
| 125 | uni.showToast({ | ||
| 126 | title: '服务异常,请稍后重试', | ||
| 127 | icon: 'none' | ||
| 128 | }) | ||
| 129 | }) | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | function pcLoginByOpenId(appId, openId) { | ||
| 134 | return request({ | ||
| 135 | url: "/system/wx/loginByOpenId", | ||
| 136 | method: "POST", | ||
| 137 | params: { | ||
| 138 | appId: appId, | ||
| 139 | openId: openId | ||
| 140 | } | ||
| 141 | }) | ||
| 142 | } | ||
| 143 | |||
| 144 | |||
| 145 | export default request; | ... | ... |
| 1 | // prod | 1 | // prod |
| 2 | // const baseUrl = 'https://research.wtwuxicenter.com/'; | 2 | // const baseUrl_api = 'https://research.wtwuxicenter.com/'; |
| 3 | // const baseUrl_api=`${baseUrl}/prod-api`; | ||
| 4 | 3 | ||
| 5 | // uat | ||
| 6 | // const baseUrl = 'https://jxt.itechtop.cn'; | ||
| 7 | const baseUrl = 'https://jxt.wtwuxicenter.com'; | ||
| 8 | const baseUrl_api = `${baseUrl}/prod-api`; | ||
| 9 | 4 | ||
| 10 | // staging | 5 | // staging |
| 11 | // const baseUrl = 'https://5q5re1d432g2.ngrok2.xiaomiqiu123.top'; | 6 | const baseUrl_api = "http://192.168.1.96:8787"; |
| 12 | |||
| 13 | // const baseUrl = "http://192.168.1.118:8081"; | ||
| 14 | // const baseUrl_api = `${baseUrl}`; | ||
| 15 | |||
| 16 | const fileUrl = "http://r.itechtop.cn"; | ||
| 17 | 7 | ||
| 18 | export default { | 8 | export default { |
| 19 | baseUrl: baseUrl, | 9 | baseUrl_api |
| 20 | fileUrl: fileUrl, | ||
| 21 | baseUrl_api: baseUrl_api, | ||
| 22 | }; | 10 | }; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment