Merge commit '023f830b'
Showing
6 changed files
with
138 additions
and
245 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 | ||
| 8 | let loginUrl=['pages/index/login', 'pages/index/register'] | ||
| 9 | let firstload = false | ||
| 10 | export default { | ||
| 11 | onLaunch: function(options) { | ||
| 12 | console.log('App Launch', options); | ||
| 13 | firstload = true | ||
| 6 | 14 | ||
| 7 | let firstload = false | 15 | this.globalData.baseUrl_api = config.baseUrl_api; |
| 8 | export default { | 16 | |
| 9 | onLaunch: function() { | 17 | if(loginUrl.indexOf( options.path)==-1){ |
| 10 | console.log('App Launch'); | 18 | let userName = uni.getStorageSync('userName') |
| 11 | firstload = true | 19 | if (userName) { |
| 12 | this.globalData.baseUrl = config.baseUrl; | 20 | h5Login(userName) |
| 13 | this.globalData.baseUrl_api = config.baseUrl_api; | 21 | .then(() => { |
| 14 | this.globalData.fileUrl = config.fileUrl; | 22 | this.globalData.isLogin = true; |
| 15 | 23 | let firstLoadCallback = getApp().firstLoadCallback; | |
| 16 | new Promise((resolve, reject) => { | 24 | if (firstLoadCallback) { |
| 17 | uni.checkSession({ | 25 | firstLoadCallback(); |
| 18 | success: res => { | 26 | } |
| 19 | loginServer | 27 | }) |
| 20 | .getCurrUser(true) | 28 | .catch(() => { |
| 21 | .catch(() => { | 29 | uni.redirectTo({ |
| 22 | return loginServer.pcLogin(); | 30 | url: '/pages/index/login' |
| 23 | }) | 31 | }) |
| 24 | .then(user => { | 32 | }) |
| 25 | resolve(user); | 33 | } else { |
| 26 | }); | 34 | this.globalData.isLogin = false; |
| 27 | }, | 35 | uni.redirectTo({ |
| 28 | fail: res => { | 36 | url: '/pages/index/login' |
| 29 | loginServer | 37 | }) |
| 30 | .wxLogin() | 38 | } |
| 31 | .then(loginRes => { | 39 | } |
| 32 | return loginServer.pcLogin(loginRes.code); | 40 | }, |
| 33 | }) | 41 | onShow: function() { |
| 34 | .then(user => { | 42 | console.log('App Show'); |
| 35 | resolve(user); | 43 | }, |
| 36 | }); | 44 | onHide: function() { |
| 37 | } | 45 | console.log('App Hide'); |
| 38 | }); | 46 | } |
| 39 | }) | 47 | }; |
| 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 | |||
| 62 | // this.globalData.venue = ven; | ||
| 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 | |||
| 68 | // this.globalData.venueConfig = { | ||
| 69 | // normalOverDay: ven.resSiteConfig?.normalOrderNum, | ||
| 70 | // normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0], | ||
| 71 | // normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1] | ||
| 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(() => { | ||
| 81 | this.globalData.isLogin = true; | ||
| 82 | let firstLoadCallback = getApp().firstLoadCallback; | ||
| 83 | if (firstLoadCallback) { | ||
| 84 | firstLoadCallback(); | ||
| 85 | } | ||
| 86 | }); | ||
| 87 | }, | ||
| 88 | onShow: function() { | ||
| 89 | console.log('App Show'); | ||
| 90 | // loginServer.getNowOpenId() | ||
| 91 | if (!firstload) { | ||
| 92 | loginServer.getCurrUser(true) | ||
| 93 | .catch(() => { | ||
| 94 | return loginServer.pcLogin().then(() => { | ||
| 95 | uni.redirectTo({ | ||
| 96 | url: getCurrentPages()[getCurrentPages().length - 1].$page.fullPath | ||
| 97 | }) | ||
| 98 | }); | ||
| 99 | }) | ||
| 100 | } | ||
| 101 | }, | ||
| 102 | onHide: function() { | ||
| 103 | console.log('App Hide'); | ||
| 104 | } | ||
| 105 | }; | ||
| 106 | </script> | 48 | </script> |
| 107 | 49 | ||
| 108 | <style lang="scss"> | 50 | <style lang="scss"> | ... | ... |
This diff is collapsed.
Click to expand it.
| 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 { |
| 17 | return '' | 15 | return '' |
| 18 | } | 16 | } |
| 19 | } catch (e) { | 17 | } catch (e) { |
| 20 | console.log(e) | 18 | console.log(e) |
| 21 | } | 19 | } |
| 22 | } | 20 | } |
| 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 | ||
| 45 | // if (req.method == 'POST' && !req.hideLoding) { | 43 | // if (req.method == 'POST' && !req.hideLoding) { |
| 46 | // uni.showLoading({ | 44 | // uni.showLoading({ |
| 47 | // title: '提交中...' | 45 | // title: '提交中...' |
| 48 | // }) | 46 | // }) |
| 49 | // } | 47 | // } |
| 50 | 48 | ||
| 51 | return new Promise((resolve, reject) => { | 49 | return new Promise((resolve, reject) => { |
| 52 | uni.request({ | 50 | uni.request({ |
| 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 | //登录超时 | 62 | if (!excludeUrls.includes(req.url)) { |
| 65 | if (data.code == 60002 || data.code == 60001) { | 63 | uni.showToast({ |
| 66 | if (req.url != '/system/wx/getUserInfo') { | 64 | title: data.msg, |
| 67 | reLogin(); | 65 | icon: 'none', |
| 68 | } | 66 | duration: 3000 |
| 69 | } | 67 | }) |
| 70 | else if (data.code == 401 && req.url != '/system/wx/getUserInfo') { | 68 | } |
| 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)) { | ||
| 87 | uni.showToast({ | ||
| 88 | title: data.msg, | ||
| 89 | icon: 'none', | ||
| 90 | duration: 3000 | ||
| 91 | }) | ||
| 92 | } | ||
| 93 | } | ||
| 94 | reject(res) | ||
| 95 | } | ||
| 96 | break | ||
| 97 | default: | ||
| 98 | reject(res) | ||
| 99 | } | ||
| 100 | }).catch(res => { | ||
| 101 | reject(res) | ||
| 102 | }).finally(() => { | ||
| 103 | // if (req.method == 'POST' && !req.hideLoding) { | ||
| 104 | // uni.hideLoading() | ||
| 105 | // } | ||
| 106 | }) | ||
| 107 | }) | ||
| 108 | } | ||
| 109 | |||
| 110 | function reLogin() { | ||
| 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 | 69 | ||
| 120 | uni.showToast({ | 70 | // 登录超时 |
| 121 | title: '一走神把您的操作遗漏了,请重试', | 71 | if (data.code === 60002 || data.code === 60001) { |
| 122 | icon: 'none' | 72 | uni.redirectTo({ |
| 123 | }) | 73 | url: '/pages/index/login' |
| 124 | }).catch(() => { | 74 | }) |
| 125 | uni.showToast({ | 75 | } else if (data.code === 401) { |
| 126 | title: '服务异常,请稍后重试', | 76 | h5LoginAuto() |
| 127 | icon: 'none' | 77 | .then(() => { |
| 128 | }) | 78 | uni.hideLoading() |
| 129 | }) | 79 | uni.redirectTo({ |
| 130 | } | 80 | url: getCurrentPages()[getCurrentPages() |
| 81 | .length - 1].$page.fullPath | ||
| 82 | }) | ||
| 83 | }) | ||
| 84 | .catch(() => { | ||
| 85 | uni.showToast({ | ||
| 86 | title: '服务异常,请稍后重试', | ||
| 87 | icon: 'none' | ||
| 88 | }) | ||
| 89 | }) | ||
| 90 | } | ||
| 91 | |||
| 92 | reject(res) | ||
| 93 | } | ||
| 94 | break | ||
| 95 | default: | ||
| 96 | reject(res) | ||
| 97 | } | ||
| 98 | }).catch(res => { | ||
| 99 | reject(res) | ||
| 100 | }).finally(() => { | ||
| 101 | // if (req.method == 'POST' && !req.hideLoding) { | ||
| 102 | // uni.hideLoading() | ||
| 103 | // } | ||
| 104 | }) | ||
| 105 | }) | ||
| 131 | } | 106 | } |
| 132 | 107 | ||
| 133 | function pcLoginByOpenId(appId, openId) { | 108 | export default request |
| 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.
| ... | @@ -85,7 +85,7 @@ | ... | @@ -85,7 +85,7 @@ |
| 85 | 85 | ||
| 86 | const app = getApp(); | 86 | const app = getApp(); |
| 87 | const projectList = ref([]); | 87 | const projectList = ref([]); |
| 88 | const priceTable = ref([]); | 88 | const priceTable = ref([]); |
| 89 | const czList = ref([]); | 89 | const czList = ref([]); |
| 90 | const isActive = ref(0); | 90 | const isActive = ref(0); |
| 91 | const popup = ref(null); | 91 | const popup = ref(null); | ... | ... |
-
Please register or sign in to post a comment