diff --git a/common/js/globalData.js b/common/js/globalData.js index b134ea7..96de592 100644 --- a/common/js/globalData.js +++ b/common/js/globalData.js @@ -1,5 +1,5 @@ export default { - deptId: 1, + deptId: 101, initPageNum: 1, initPageSize: 5 } \ No newline at end of file diff --git a/common/js/request.js b/common/js/request.js index 78c996b..ad87764 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -6,6 +6,8 @@ export default { uni.addInterceptor('request', { invoke(args) { // request 触发前拼接 url + // args.url = 'https://www.opsoul.com' + args.url; + // args.url = 'http://192.168.2.3:80' + args.url; args.url = 'http://127.0.0.1:80' + args.url; // console.log("停止触发"); // return false; @@ -60,52 +62,56 @@ export default { }) }, async login() { - // 从缓存中获取登录信息 - let userInfo = uni.getStorageSync('userProfile'); - if (userInfo) { - return true; - } - - // 获取微信登录凭证 - const wxLoginRes = await wx.login(); - console.log(wxLoginRes) - const wxAuthRes = await uni.request({ - url: '/wx/auth', - header: { - code: wxLoginRes.code - } - }) - console.log(wxAuthRes) - // TODO:调用小程序服务端确认是否是授权登录过的用户 - let loginRes = { - logined: false, - userInfo: {} - }; - // 未登录过的获取微信用户信息 - if (!loginRes || !loginRes.logined) { - userInfo = await wx.getUserProfile({ - desc: '用于小程序登录' - }); - // 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回 - loginRes = { - logined: true, - userInfo: { - userId: 1, - wxLoginCode: wxLoginRes.code, - openId: wxAuthRes[1].data.data.openid - } - }; - } - userInfo = loginRes.userInfo; - if (!userInfo) { - uni.showToast({ - icon: 'error', - title: '用户信息获取失败,请退出小程序重试' - }) - return false; - } - // 页面存储用户登录有效信息,以便其他页面调用 - uni.setStorageSync('userProfile', userInfo); + // 从缓存中获取登录信息 + let userInfo = uni.getStorageSync('userProfile'); + if (userInfo) { + return true; + } + + // TODO:调用小程序服务端确认是否是授权登录过的用户 + let loginRes = { + logined: false, + userInfo: {} + }; + // 未登录过的获取微信用户信息 + if (!loginRes.logined) { + userInfo = await wx.getUserProfile({ + desc: '用于小程序登录' + }); + // 获取微信登录凭证 + const wxLoginRes = await wx.login(); + console.log(wxLoginRes) + // 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回 + loginRes = { + logined: true, + userInfo: { + ...userInfo, + userId: 1, + wxLoginCode: wxLoginRes.code + } + }; + + const wxAuthRes = await uni.request({ + url: '/wx/auth', + header: { + code: wxLoginRes.code + } + }) + console.log(wxAuthRes) + loginRes.userInfo.openId = wxAuthRes[1].data.data.openid; + loginRes.userInfo.customerId = 2; + } + userInfo = loginRes.userInfo; + + if (!userInfo) { + uni.showToast({ + icon: 'error', + title: '微信用户信息获取失败,请退出小程序重试' + }) + return false; + } + // 页面存储用户登录有效信息,以便其他页面调用 + uni.setStorageSync('userProfile', userInfo); return true; }, wxLogin() { @@ -113,7 +119,6 @@ export default { }, getCurUserInfo() { let userProfile = uni.getStorageSync('userProfile'); - console.log("curUser:" + userProfile) return userProfile; }, getProductCategories(params = {}) { @@ -152,5 +157,50 @@ export default { } }) return res[1].data; - }, + }, + async getAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/list', + method: 'POST', + data: params + }) + return res[1].data; + }, + async addAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/insert', + method: 'POST', + data: params + }) + return res[1].data; + }, + async editAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/update', + method: 'POST', + data: params + }) + return res[1].data; + }, + async delAddressList(customerAddressId) { + let res = await uni.request({ + url: '/customer/address/delete', + method: 'POST', + data: { + customerAddressId: customerAddressId + }, + header: { + 'content-type': 'application/x-www-form-urlencoded' + } + }) + return res[1].data; + }, + async areaListByStep(params = { parentCode: null }) { + let res = await uni.request({ + url: '/system/area/list', + method: 'POST', + data: params + }) + return res[1].data; + } } diff --git a/pages/my/edit-address.vue b/pages/my/edit-address.vue index 9c70a0a..e0a9160 100644 --- a/pages/my/edit-address.vue +++ b/pages/my/edit-address.vue @@ -10,30 +10,31 @@