Browse Source

对接登录功能

master
邓平艺 4 years ago
parent
commit
1caf37bd79
  1. 4
      main.js
  2. 3
      pages/address/add/add.vue
  3. 5
      pages/address/list/list.vue
  4. 20
      pages/recharge/balance/balance.vue
  5. 162
      pages/user/register/register.vue

4
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

3
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) {

5
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) {

20
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){

162
pages/user/register/register.vue

@ -6,7 +6,7 @@
</view>
<view class="fixed-btn">
<button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button>
<button class="btn2" hover-class="lf-opacity" @click="wxLogin">微信授权登录</button>
<button class="btn2" hover-class="lf-opacity" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信授权登录</button>
</view>
</view>
</template>
@ -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;

Loading…
Cancel
Save