From 1caf37bd7945c11dbeeb9e21af1b760718f77059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E5=B9=B3=E8=89=BA?= <52643018@qq.com> Date: Wed, 15 Sep 2021 10:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E7=99=BB=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 4 +- pages/address/add/add.vue | 3 +- pages/address/list/list.vue | 5 +- pages/recharge/balance/balance.vue | 20 ++-- pages/user/register/register.vue | 162 +++++++++++++++++++++++------ 5 files changed, 148 insertions(+), 46 deletions(-) diff --git a/main.js b/main.js index f354e77..998f9db 100644 --- a/main.js +++ b/main.js @@ -29,9 +29,7 @@ Vue.prototype.$cookieStorage = cookieStorage; Vue.prototype.$config = config; Vue.prototype.$store = store; App.mpType = 'app' -Vue.prototype.getToken = function(){ - return "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczYTViNTA1NDNlYmNmMjFkNmZiMGJlNzc0NmJmMDE4MDc3MTRkY2Y1MjBiMjM3MGQyZDAyYzQxMTlmMDU4ZTkwMTUxNDQwOTk4MjJhODFhIn0.eyJhdWQiOiIzIiwianRpIjoiNzNhNWI1MDU0M2ViY2YyMWQ2ZmIwYmU3NzQ2YmYwMTgwNzcxNGRjZjUyMGIyMzcwZDJkMDJjNDExOWYwNThlOTAxNTE0NDA5OTgyMmE4MWEiLCJpYXQiOjE2MzExNjk1MDIsIm5iZiI6MTYzMTE2OTUwMiwiZXhwIjoxNjYyNzA1NTAyLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.p0YoIC_bhOxIOugYxDQTOFIK9t2ORiHQq9H6JWzdByBJKWkFDBisKaXZJvzn1HdU5cjNQnHaBfWpG1Ed15cQlB2LdpXxxc38iaaGW2J6WhlLhVkehloii-TtlZTOeqNrpAHbSe5DRrmm_L07Llm9wr1T1A6pP3MhzdHiZ9d6748j3_cJjK4CJUl3WfYRTaozLFlI00OCW4zzGfgivSighjSFyhqMoHnQ2iSoeWdcJnYpXzXQdc5AXvXOt6eIIa7o2F6Ma1tUseTYVijEVfngdfd21JI1eH6tHrSqUItkQHAart9o74dJn9micI3WrN5yEBXgzemqWkQGV4QzFHLyd3wk-XvP1s2GhCeWlJZOQADzgzhLoxzFUbgM5xULWHp3yfpePGISlM4ZpBwTHcqQt1i_UkNX_zCxa3RYQbZFDfWW0-UPbvHw40t5BY6X7nTPMhPjPGnnPq18jyYBrWBbC9vBWs2o2IHAe5VlkHtmy_v5fymFJLfFzS784Nxp2qPJFWxI7IfrpNckHxohhs5LoieQivw2MyU2shFOUjgwe0xQgyg6UBg5PwNknGTTmzYdavCM4BiQ7moqOuoI15ccIEmc_uMiuLVEfDPlzejP9PQv6mj6IlkJ8HSu4KZU-LxKmtLnGeEwMjVAZBIhsOwzMkaMF1nZ70pgv2YYwBQyVVs" -} + const app = new Vue({ ...App, store diff --git a/pages/address/add/add.vue b/pages/address/add/add.vue index b1a96c3..1058de2 100644 --- a/pages/address/add/add.vue +++ b/pages/address/add/add.vue @@ -375,11 +375,10 @@ export default { // 获取收货地址详情 queryAddress(id) { var token = this.$cookieStorage.get('user_token'); - console.log(this.getToken) this.$http.get({ api: 'api/address/' + id, header: { - Authorization: token || this.getToken() + Authorization: token } }).then(res => { if (res.statusCode == 200) { diff --git a/pages/address/list/list.vue b/pages/address/list/list.vue index cf828d6..970ba18 100644 --- a/pages/address/list/list.vue +++ b/pages/address/list/list.vue @@ -91,11 +91,12 @@ export default { // 删除收货地址 deleteAddress(item){ console.log("item", item) + var token = this.$cookieStorage.get('user_token'); this.$http.ajax({ api: '/api/address/'+ item.id, method: 'DELETE', header: { - Authorization: this.getToken() + Authorization: token } }).then(res => { console.log("删除地址", res); @@ -153,7 +154,7 @@ export default { this.$http.get({ api: 'api/address', header: { - Authorization: token || this.getToken() + Authorization: token } }).then(res => { if (res.statusCode == 200) { diff --git a/pages/recharge/balance/balance.vue b/pages/recharge/balance/balance.vue index ce325dc..85f6fb6 100644 --- a/pages/recharge/balance/balance.vue +++ b/pages/recharge/balance/balance.vue @@ -68,7 +68,7 @@ show: false, page: 0, more: true, - token: this.getToken(), + token: '', num: "", showText: '正在加载下一页数据', config: '' @@ -85,15 +85,15 @@ // var status = e.type ? e.type : 0; // var page = this.tabList[status].page; - // pageLogin(getUrl(), token => { - // this.setData({ - // 'token': token - // }); - // this.queryBalanceList(token, status, page); - // this.queryUserSum(token); - // }); - this.queryBalanceList(); - this.queryUserSum(this.token); + pageLogin(getUrl(), token => { + this.setData({ + 'token': token + }); + this.queryBalanceList(); + this.queryUserSum(token); + }); + // this.queryBalanceList(token, status, page); + // this.queryUserSum(this.token); }, methods: { dateChange(event){ diff --git a/pages/user/register/register.vue b/pages/user/register/register.vue index ae1a80a..2f9f924 100644 --- a/pages/user/register/register.vue +++ b/pages/user/register/register.vue @@ -6,7 +6,7 @@ - + @@ -43,9 +43,10 @@ } if (token) { - wx.switchTab({ - url: '/pages/user/personal/personal' - }); + // uni.switchTab({ + // url: '/pages/user/personal/personal' + // }); + this.$url('/pages/user/my/center', {type: 'launch'}) } else { // #ifdef MP-WEIXIN this.wxLogin(); @@ -87,6 +88,7 @@ // } // }); }, + // 小程序静默登录 wxLogin(){ uni.showLoading({ title: '正在自动登录', @@ -102,18 +104,8 @@ } }, }); - - // uni.getUserProfile({ - // desc: '我们将获取到的信息用于展示', - // lang: 'zh_CN', - // complete: result => { - // console.log(result); - // if(result.errMsg == 'getUserProfile:ok'){ - // console.log("获取成功!"); - // } - // } - // }) }, + // 通过code自动登录 autoLogin(code) { this.$http.post({ api: 'api/oauth/miniprogram/login', @@ -136,32 +128,33 @@ if (res.data.access_token) { console.log('已经返回给我了token'); - wx.hideLoading(); + uni.hideLoading(); var access_token = res.data.token_type + ' ' + res.data.access_token; var expires_in = res.data.expires_in || 315360000; this.$cookieStorage.set("user_token", access_token, expires_in); if (this.url) { - wx.redirectTo({ + uni.redirectTo({ url: "/" + this.url, - fail: () => { - wx.switchTab({ - url: "/" + this.url - }); - } + // fail: () => { + // uni.switchTab({ + // url: "/" + this.url + // }); + // } }) } else { - wx.switchTab({ - url: '/pages/user/personal/personal' - }); + // uni.switchTab({ + // url: '/pages/user/personal/personal' + // }); + this.$url('/pages/user/my/center', {type: 'launch'}) } } else { - wx.hideLoading(); + uni.hideLoading(); } }).catch(rej => { - wx.hideLoading(); - wx.showModal({ + uni.hideLoading(); + uni.showModal({ content: '请求失败,请重试', showCancel: false, success: res => { @@ -172,8 +165,119 @@ }); }); }, + // 获取用户手机号 + getPhoneNumber(e) { + if (e.detail.encryptedData) { + uni.login({ + success: res => { + if (res.code) { + this.setData({ + code: res.code + }); + this.phone(e); + } else { + uni.showModal({ + content: " 获取code失败", + showCancel: false + }); + } + } + }); + return; + } else { + this.toPhoneLogin(); + } + }, + // 通过手机号登录注册 + phone(e) { + uni.showLoading({ + title: '正在登录', + mask: true + }); + this.$http.post({ + api: 'api/oauth/miniprogram/mobile', + data: { + open_type: 'miniprogram', + code: this.code, + encryptedData: e.detail.encryptedData, + iv: e.detail.iv, + open_id: this.open_id, + shop_id: this.$cookieStorage.get('shop_id') || '', + agent_code: this.$cookieStorage.get('coupon_agent_code') || this.$cookieStorage.get('agent_code') || '', + clerk_id: this.$cookieStorage.get('clerk_id') || '', + agent_code_time: this.$cookieStorage.get('agent_code_time') || '', + shop_id_time: this.$cookieStorage.get('shop_id_time') || '' + } + }).then(res => { + if (res.statusCode == 200) { + res = res.data; + + if (res.data.access_token) { + var access_token = res.data.token_type + ' ' + res.data.access_token; + var expires_in = res.data.expires_in || 315360000; // debugger; + + this.$cookieStorage.set("user_token", access_token, expires_in); // this.$cookieStorage.set("user_token",access_token,expires_in); + // uni.setStorageSync("user_token",access_token); + + if (this.url) { + // var path = ['pages/entity/store/store', 'pages/index/index/index', + // 'pages/index/classification/classification', 'pages/store/tabCart/tabCart', 'pages/user/personal/personal', + // 'pages/travels/index/index', 'pages/user/collar/collar' + // ]; + // var pathIndex = path.indexOf(this.url); + + // if (pathIndex == -1) { + // uni.redirectTo({ + // url: "/" + this.url + // }); + // } else { + // uni.switchTab({ + // url: "/" + this.url + // }); + // } + this.$url("/" + this.url, {type: 'redirect'}); + } else { + // uni.switchTab({ + // url: '/pages/user/personal/personal' + // }); + this.$url('/pages/user/my/center', {type: 'launch'}) + } + } else { + uni.showModal({ + content: res.message || '请求失败,请重试', + showCancel: false + }); + } + } else { + uni.showModal({ + content: '请求失败,请重试', + showCancel: false + }); + } + + uni.hideLoading(); + }).catch(rej => { + uni.hideLoading(); + uni.showModal({ + content: '请求失败,请重试', + showCancel: false + }); + }); + }, + // 跳转到手机号验证码登录 toPhoneLogin(){ - this.$url('/pages/user/loginType/loginType'); + if (this.url) { + // uni.navigateTo({ + // url: '/pages/user/loginType/loginType?url=' + encodeURIComponent(this.url) + '&open_id=' + this.open_id + // }); + this.$url('/pages/user/loginType/loginType?url=' + encodeURIComponent(this.url) + '&open_id=' + this.open_id); + } else { + // wx.navigateTo({ + // url: '/pages/user/loginType/loginType?open_id=' + this.open_id + // }); + this.$url('/pages/user/loginType/loginType?open_id=' + this.open_id); + } + }, setData: function(obj) { let that = this;