7 changed files with 1513 additions and 1250 deletions
-
6pages.json
-
579pages/user/loginType/loginType - 副本.vue
-
702pages/user/loginType/loginType.vue
-
4pages/user/my/center.vue
-
13pages/user/my/setting.vue
-
708pages/user/register/register - 副本.vue
-
751pages/user/register/register.vue
@ -0,0 +1,579 @@ |
|||
<template> |
|||
<view id="user-register"> |
|||
<view class="tips" :hidden="!message">{{message}}</view> |
|||
<view class="register_header"> |
|||
<image @tap="jumpHome" src="https://cdn.guojiang.club/app_guojiang_logo.png"></image> |
|||
</view> |
|||
<view class="register_input"> |
|||
<view class="tellphone"> |
|||
<input type="number" placeholder="手机号码" @input="changeCode" placeholder-class="input-placeholder"></input> |
|||
</view> |
|||
<view class="code"> |
|||
<view class="writecode"> |
|||
<input type="text" placeholder="验证码" @input="changeIdentifyCode" placeholder-class="input-placeholder"></input> |
|||
</view> |
|||
|
|||
<view class="getCode" @tap.stop="getCode">{{codes.codeText}}</view> |
|||
</view> |
|||
</view> |
|||
<view class="submit"> |
|||
<button type="default" class="check" @tap.stop="submitF" :disabled="showLoading" :loading="showLoading">快速登录</button> |
|||
</view> |
|||
<!-- #ifdef MP-WEIXIN --> |
|||
<view class="weixin" @tap="jumpBack">微信登录</view> |
|||
<!-- #endif --> |
|||
|
|||
<view class="select" @tap="chageAgreement"> |
|||
<!--<checkbox-group @change="changeChecked">--> |
|||
<!--<checkbox @tap="changeChecked" color="#fff" :checked="checked" />--> |
|||
<text> 注册/登录即代表同意《果酱使用协议》</text> |
|||
<!--</checkbox-group>--> |
|||
</view> |
|||
|
|||
<view class="mask" :hidden="!showAgreement"> |
|||
|
|||
</view> |
|||
<view class="greement-box" :hidden="!showAgreement"> |
|||
<view class="title mx-1px-bottom"> |
|||
用户协议 |
|||
</view> |
|||
<view class="content"> |
|||
<u-parse :content="agreement.user_agreement" /> |
|||
</view> |
|||
<view class="btn mx-1px-top" @tap="chageAgreement"> |
|||
确定 |
|||
</view> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
<script> |
|||
import { |
|||
pageLogin, |
|||
getUrl, |
|||
config, |
|||
is |
|||
} from '@/common/js/utils.js'; |
|||
import uParse from '@/components/gaoyia-parse/parse.vue'; |
|||
|
|||
export default { |
|||
components: { |
|||
uParse |
|||
}, |
|||
|
|||
data() { |
|||
return { |
|||
codes: { |
|||
total: 60, |
|||
access_token: null, |
|||
codeText: "获取验证码" |
|||
}, |
|||
tellphone: "", |
|||
identifyingcode: "", |
|||
sending: false, |
|||
checked: true, |
|||
orginUrl: "", |
|||
showLoading: false, |
|||
message: "", |
|||
open_id: '', |
|||
brand: config.BRAND.name, |
|||
author: config.PACKAGES.author, |
|||
code: '', |
|||
shop_id: '', |
|||
unionInFo: '', |
|||
openInFo: '', |
|||
config: '', |
|||
agreement: '', |
|||
showAgreement: false, |
|||
is_app_bind:'' |
|||
}; |
|||
}, |
|||
onLoad(e) { |
|||
// 第三方平台配置颜色 |
|||
var bgConfig = this.$cookieStorage.get('globalConfig') || ''; |
|||
this.setData({ |
|||
config: bgConfig |
|||
}); |
|||
// #ifdef APP-PLUS |
|||
if(e.url){ |
|||
this.orginUrl = JSON.parse(e.url); |
|||
} |
|||
if(e.open_id){ |
|||
this.open_id = e.open_id |
|||
} |
|||
this.is_app_bind =e.is_app_bind; |
|||
// #endif |
|||
// #ifdef H5 || MP-WEIXIN |
|||
this.orginUrl = decodeURIComponent(e.url); |
|||
console.log('this.orginUrl',this.orginUrl); |
|||
// #endif |
|||
if (e.shop_id) { |
|||
this.setData({ |
|||
shop_id: e.shop_id |
|||
}); |
|||
} |
|||
// #ifdef H5 || MP-WEIXIN |
|||
if (e.open_id) { |
|||
this.open_id = e.open_id; |
|||
} |
|||
// #endif |
|||
if(e.is_app_weixin){ |
|||
this.is_app_weixin = JSON.parse(e.is_app_weixin) |
|||
} |
|||
|
|||
this.getGreementInfo(); |
|||
}, |
|||
onShow() { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
|
|||
this.token = token; |
|||
|
|||
if (token) { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
}, |
|||
methods: { |
|||
changeChecked(e) { |
|||
this.setData({ |
|||
checked: !this.checked |
|||
}); |
|||
}, |
|||
|
|||
changeCode(e) { |
|||
this.setData({ |
|||
tellphone: e.detail.value |
|||
}); |
|||
}, |
|||
|
|||
changeIdentifyCode(e) { |
|||
this.setData({ |
|||
identifyingcode: e.detail.value |
|||
}); |
|||
}, |
|||
|
|||
random() { |
|||
return Math.random().toString(36).substr(2, 24); |
|||
}, |
|||
|
|||
chageAgreement() { |
|||
this.setData({ |
|||
showAgreement: !this.showAgreement |
|||
}); |
|||
}, |
|||
|
|||
jumpBack() { |
|||
wx.redirectTo({ |
|||
url: '/pages/user/register/register' |
|||
}); |
|||
}, |
|||
jumpHome() { |
|||
wx.switchTab({ |
|||
url: '/pages/index/index/index' |
|||
}); |
|||
}, |
|||
// 获取用户协议 |
|||
getGreementInfo() { |
|||
this.$http.get({ |
|||
api: 'api/user/agreement' |
|||
}).then(res => { |
|||
res = res.data; |
|||
|
|||
if (res.status) { |
|||
this.setData({ |
|||
agreement: res.data |
|||
}); |
|||
} |
|||
|
|||
}); |
|||
}, |
|||
|
|||
getCode() { |
|||
if (this.sending) return; |
|||
var randoms = this.random(); |
|||
this.setData({ |
|||
sending: true, |
|||
'codes.codeText': "短信发送中", |
|||
'codes.access_token': randoms |
|||
}); |
|||
|
|||
var fn; |
|||
fn = this.getLoginCode; |
|||
|
|||
fn(() => { |
|||
var total = this.codes.total; |
|||
|
|||
this.setData({ |
|||
'codes.codeText': total + "秒后再发送" |
|||
}); |
|||
var timer = setInterval(() => { |
|||
total--; |
|||
this.setData({ |
|||
'codes.codeText': total + "秒后再发送" |
|||
}); |
|||
|
|||
if (total < 1) { |
|||
this.setData({ |
|||
sending: false, |
|||
'codes.codeText': "获取验证码" |
|||
}); |
|||
clearInterval(timer); |
|||
} |
|||
}, 1000); |
|||
}, () => { |
|||
this.setData({ |
|||
sending: false, |
|||
'codes.codeText': "获取验证码" |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
getLoginCode(resolve, reject) { |
|||
var message = null; |
|||
|
|||
if (!is.has(this.tellphone)) { |
|||
message = "请输入您的手机号"; |
|||
} else if (!is.mobile(this.tellphone)) { |
|||
message = '手机号格式不正确,请重新输入'; |
|||
} |
|||
|
|||
if (message) { |
|||
this.setData({ |
|||
message: message |
|||
}); |
|||
reject(); |
|||
setTimeout(() => { |
|||
this.setData({ |
|||
message: "" |
|||
}); |
|||
}, 3000); |
|||
return; |
|||
} |
|||
|
|||
this.$http.post({ |
|||
api: "api/sms/verify-code", |
|||
data: { |
|||
mobile: this.tellphone, |
|||
access_token: this.codes.access_token |
|||
} |
|||
}).then(res => { |
|||
if (res.data.success) { |
|||
resolve(); |
|||
} else { |
|||
reject(); |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
submitF() { |
|||
var message = null; |
|||
|
|||
|
|||
if (!is.has(this.tellphone)) { |
|||
message = "请输入您的手机号"; |
|||
} else if (!is.mobile(this.tellphone)) { |
|||
message = '手机号格式不正确,请重新输入'; |
|||
} else if (!is.has(this.identifyingcode)) { |
|||
message = "请填写验证码"; |
|||
} else if (!is.has(this.checked)) { |
|||
message = "请同意此协议"; |
|||
} |
|||
|
|||
if (message) { |
|||
|
|||
this.message = message; |
|||
|
|||
setTimeout(() => { |
|||
this.message = ''; |
|||
}, 3000); |
|||
return; |
|||
} |
|||
|
|||
this.setData({ |
|||
showLoading: true |
|||
}); |
|||
if(this.is_app_bind){ |
|||
this.appbindPhone() |
|||
} else{ |
|||
|
|||
this.quickLogin(); |
|||
} |
|||
|
|||
}, |
|||
appbindPhone(){ |
|||
var that = this; |
|||
var data = { |
|||
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') || '', |
|||
open_type: 'wechat', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
grant_type: 'sms_token', |
|||
type: "direct" |
|||
} |
|||
this.$http.post({ |
|||
api:'api/oauth/sms', |
|||
data:data |
|||
}).then(res=>{ |
|||
res = res.data; |
|||
if(res.status){ |
|||
res.data.access_token = res.data.token_type + ' ' + res.data.access_token; |
|||
var expires_in = res.data.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", res.data.access_token, expires_in); |
|||
if (this.orginUrl != ''){ |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
}else{ |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
|
|||
} |
|||
|
|||
|
|||
}else{ |
|||
wx.showModal({ |
|||
content: res.message || "验证码不正确", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
}) |
|||
}, |
|||
|
|||
quickLogin() { |
|||
var that = this; |
|||
// #ifdef MP-WEIXIN |
|||
var data = { |
|||
grant_type: 'sms_token', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
open_type: 'miniprogram', |
|||
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') || '' |
|||
}; |
|||
// #endif |
|||
|
|||
|
|||
// #ifdef H5 |
|||
var data = { |
|||
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') || '', |
|||
open_type: 'wechat', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
grant_type: 'sms_token', |
|||
type: "direct" |
|||
} |
|||
// #endif |
|||
|
|||
// #ifdef APP-PLUS |
|||
var app_info = this.$cookieStorage.get('app_user_info'); |
|||
var nick_name; |
|||
var avatar; |
|||
if(app_info){ |
|||
nick_name = app_info.nickName; |
|||
avatar = app_info.avatarUrl; |
|||
} |
|||
|
|||
var data = { |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
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') || '', |
|||
grant_type: 'sms_token', |
|||
type: "direct", |
|||
nick_name:nick_name || '', |
|||
avatar:avatar || '' |
|||
} |
|||
// #endif |
|||
this.$http.post({ |
|||
// #ifdef MP-WEIXIN |
|||
api: "api/oauth/sms", |
|||
// #endif |
|||
|
|||
// #ifdef H5 |
|||
api: 'api/oauth/sms', |
|||
// #endif |
|||
// #ifdef APP-PLUS |
|||
api:'api/oauth/app/sms', |
|||
// #endif |
|||
data: data, |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
// #ifdef H5 || APP-PLUS |
|||
if (res.data.access_token) { |
|||
|
|||
res.data.access_token = res.data.token_type + ' ' + res.data.access_token; |
|||
var expires_in = res.data.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", res.data.access_token, expires_in); |
|||
|
|||
|
|||
// #ifdef APP-PLUS |
|||
if (this.orginUrl != '') |
|||
// #endif |
|||
// #ifdef H5 |
|||
if (this.orginUrl != 'undefined') |
|||
// #endif |
|||
{ |
|||
|
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} |
|||
else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} |
|||
|
|||
|
|||
// #endif |
|||
|
|||
// #ifdef MP-WEIXIN |
|||
|
|||
if (res.data.access_token) { |
|||
var result = res.data; |
|||
|
|||
if (result.access_token) { |
|||
result.access_token = result.token_type + ' ' + result.access_token; |
|||
var expires_in = result.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", result.access_token, expires_in); // wx.setStorageSync("user_token",result.access_token); |
|||
|
|||
|
|||
|
|||
if (this.orginUrl != 'undefined') { |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
if (this.orginUrl != 'undefined') { |
|||
|
|||
if (this.orginUrl.startsWith('pages/index/index/index')) { |
|||
if (this.orginUrl == "pages/index/index/index") { |
|||
getApp().globalData.giftLogin = false; |
|||
} else { |
|||
getApp().globalData.giftLogin = true; |
|||
} |
|||
|
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} else { |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// #endif |
|||
|
|||
|
|||
else { |
|||
wx.showModal({ |
|||
content: res.message || "验证码不正确", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: "请求失败", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
this.setData({ |
|||
showLoading: false |
|||
}); |
|||
}).catch(rej => { |
|||
wx.showModal({ |
|||
content: "请求失败", |
|||
showCancel: false |
|||
}); |
|||
this.setData({ |
|||
showLoading: false |
|||
}); |
|||
}); |
|||
}, |
|||
setData: function(obj) { |
|||
let that = this; |
|||
let keys = []; |
|||
let val, data; |
|||
Object.keys(obj).forEach(function(key) { |
|||
keys = key.split('.'); |
|||
val = obj[key]; |
|||
data = that.$data; |
|||
keys.forEach(function(key2, index) { |
|||
if (index + 1 == keys.length) { |
|||
that.$set(data, key2, val); |
|||
} else { |
|||
if (!data[key2]) { |
|||
that.$set(data, key2, {}); |
|||
} |
|||
} |
|||
|
|||
data = data[key2]; |
|||
}); |
|||
}); |
|||
} |
|||
}, |
|||
computed: {}, |
|||
watch: {} |
|||
}; |
|||
</script> |
|||
<style rel="stylesheet/less" lang="less"> |
|||
@import "loginType"; |
|||
</style> |
|||
@ -1,579 +1,175 @@ |
|||
<template> |
|||
<view id="user-register"> |
|||
<view class="tips" :hidden="!message">{{message}}</view> |
|||
<view class="register_header"> |
|||
<image @tap="jumpHome" src="https://cdn.guojiang.club/app_guojiang_logo.png"></image> |
|||
<view> |
|||
<lf-nav title="登录/注册" :showIcon="true" bgColor="#fff"></lf-nav> |
|||
<view class="head"> |
|||
<view class="head-content"> |
|||
<image class="logo"></image> |
|||
<view class="title">欢迎来到金城优选!</view> |
|||
</view> |
|||
</view> |
|||
<view class="register_input"> |
|||
<view class="tellphone"> |
|||
<input type="number" placeholder="手机号码" @input="changeCode" placeholder-class="input-placeholder"></input> |
|||
<view class="content"> |
|||
<view class="list"> |
|||
<view class="lf-flex"> |
|||
<view class="lf-font-28 lf-color-black" style="width: 140rpx;">手机号</view> |
|||
<input class="input" placeholder="请输入手机号码" v-model="phone" maxlength="11" /> |
|||
</view> |
|||
<view class="clear" v-if="phone.length" @click="phone = ''"> |
|||
<text class="lf-iconfont icon--"></text> |
|||
</view> |
|||
</view> |
|||
<view class="code"> |
|||
<view class="writecode"> |
|||
<input type="text" placeholder="验证码" @input="changeIdentifyCode" placeholder-class="input-placeholder"></input> |
|||
<view class="list"> |
|||
<view class="lf-flex"> |
|||
<view class="lf-font-28 lf-color-black" style="width: 140rpx;">验证码</view> |
|||
<input class="input input-code" placeholder="请输入验证码" maxlength="8" v-model="code" /> |
|||
</view> |
|||
<view class="code" :class="{'active-bg': is_code}" @click="getCode"> |
|||
<text>{{ is_code ? num +'秒后重新获取' : '获取验证码' }}</text> |
|||
</view> |
|||
|
|||
<view class="getCode" @tap.stop="getCode">{{codes.codeText}}</view> |
|||
</view> |
|||
</view> |
|||
<view class="submit"> |
|||
<button type="default" class="check" @tap.stop="submitF" :disabled="showLoading" :loading="showLoading">快速登录</button> |
|||
</view> |
|||
<!-- #ifdef MP-WEIXIN --> |
|||
<view class="weixin" @tap="jumpBack">微信登录</view> |
|||
<!-- #endif --> |
|||
|
|||
<view class="select" @tap="chageAgreement"> |
|||
<!--<checkbox-group @change="changeChecked">--> |
|||
<!--<checkbox @tap="changeChecked" color="#fff" :checked="checked" />--> |
|||
<text> 注册/登录即代表同意《果酱使用协议》</text> |
|||
<!--</checkbox-group>--> |
|||
</view> |
|||
|
|||
<view class="mask" :hidden="!showAgreement"> |
|||
|
|||
</view> |
|||
<view class="greement-box" :hidden="!showAgreement"> |
|||
<view class="title mx-1px-bottom"> |
|||
用户协议 |
|||
</view> |
|||
<view class="content"> |
|||
<u-parse :content="agreement.user_agreement" /> |
|||
</view> |
|||
<view class="btn mx-1px-top" @tap="chageAgreement"> |
|||
确定 |
|||
</view> |
|||
<button class="next-btn" hover-class="lf-opacity" @click="next">登录</button> |
|||
<view class="fixed-desc"> |
|||
<text>未注册的手机号码登录时将自动注册,并表示您已接受同意</text> |
|||
<text @click="$msg('敬请期待')">《用户协议》</text> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
<script> |
|||
import { |
|||
pageLogin, |
|||
getUrl, |
|||
config, |
|||
is |
|||
} from '@/common/js/utils.js'; |
|||
import uParse from '@/components/gaoyia-parse/parse.vue'; |
|||
|
|||
<script> |
|||
export default { |
|||
components: { |
|||
uParse |
|||
}, |
|||
|
|||
data() { |
|||
data(){ |
|||
return { |
|||
codes: { |
|||
total: 60, |
|||
access_token: null, |
|||
codeText: "获取验证码" |
|||
}, |
|||
tellphone: "", |
|||
identifyingcode: "", |
|||
sending: false, |
|||
checked: true, |
|||
orginUrl: "", |
|||
showLoading: false, |
|||
message: "", |
|||
open_id: '', |
|||
brand: config.BRAND.name, |
|||
author: config.PACKAGES.author, |
|||
phone: '', |
|||
code: '', |
|||
shop_id: '', |
|||
unionInFo: '', |
|||
openInFo: '', |
|||
config: '', |
|||
agreement: '', |
|||
showAgreement: false, |
|||
is_app_bind:'' |
|||
}; |
|||
}, |
|||
onLoad(e) { |
|||
// 第三方平台配置颜色 |
|||
var bgConfig = this.$cookieStorage.get('globalConfig') || ''; |
|||
this.setData({ |
|||
config: bgConfig |
|||
}); |
|||
// #ifdef APP-PLUS |
|||
if(e.url){ |
|||
this.orginUrl = JSON.parse(e.url); |
|||
} |
|||
if(e.open_id){ |
|||
this.open_id = e.open_id |
|||
} |
|||
this.is_app_bind =e.is_app_bind; |
|||
// #endif |
|||
// #ifdef H5 || MP-WEIXIN |
|||
this.orginUrl = decodeURIComponent(e.url); |
|||
console.log('this.orginUrl',this.orginUrl); |
|||
// #endif |
|||
if (e.shop_id) { |
|||
this.setData({ |
|||
shop_id: e.shop_id |
|||
}); |
|||
is_code: false, |
|||
timer: null, |
|||
num: 10 |
|||
} |
|||
// #ifdef H5 || MP-WEIXIN |
|||
if (e.open_id) { |
|||
this.open_id = e.open_id; |
|||
} |
|||
// #endif |
|||
if(e.is_app_weixin){ |
|||
this.is_app_weixin = JSON.parse(e.is_app_weixin) |
|||
} |
|||
|
|||
this.getGreementInfo(); |
|||
}, |
|||
onShow() { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
|
|||
this.token = token; |
|||
|
|||
if (token) { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
onLoad(){ |
|||
|
|||
}, |
|||
onUnload(){ |
|||
if(this.timer){ |
|||
clearInterval(this.timer); |
|||
this.timer = null; |
|||
} |
|||
}, |
|||
methods: { |
|||
changeChecked(e) { |
|||
this.setData({ |
|||
checked: !this.checked |
|||
}); |
|||
}, |
|||
|
|||
changeCode(e) { |
|||
this.setData({ |
|||
tellphone: e.detail.value |
|||
}); |
|||
}, |
|||
|
|||
changeIdentifyCode(e) { |
|||
this.setData({ |
|||
identifyingcode: e.detail.value |
|||
}); |
|||
}, |
|||
|
|||
random() { |
|||
return Math.random().toString(36).substr(2, 24); |
|||
}, |
|||
|
|||
chageAgreement() { |
|||
this.setData({ |
|||
showAgreement: !this.showAgreement |
|||
}); |
|||
}, |
|||
|
|||
jumpBack() { |
|||
wx.redirectTo({ |
|||
url: '/pages/user/register/register' |
|||
}); |
|||
}, |
|||
jumpHome() { |
|||
wx.switchTab({ |
|||
url: '/pages/index/index/index' |
|||
}); |
|||
}, |
|||
// 获取用户协议 |
|||
getGreementInfo() { |
|||
this.$http.get({ |
|||
api: 'api/user/agreement' |
|||
}).then(res => { |
|||
res = res.data; |
|||
|
|||
if (res.status) { |
|||
this.setData({ |
|||
agreement: res.data |
|||
}); |
|||
} |
|||
|
|||
}); |
|||
}, |
|||
|
|||
getCode() { |
|||
if (this.sending) return; |
|||
var randoms = this.random(); |
|||
this.setData({ |
|||
sending: true, |
|||
'codes.codeText': "短信发送中", |
|||
'codes.access_token': randoms |
|||
}); |
|||
|
|||
var fn; |
|||
fn = this.getLoginCode; |
|||
|
|||
fn(() => { |
|||
var total = this.codes.total; |
|||
|
|||
this.setData({ |
|||
'codes.codeText': total + "秒后再发送" |
|||
}); |
|||
var timer = setInterval(() => { |
|||
total--; |
|||
this.setData({ |
|||
'codes.codeText': total + "秒后再发送" |
|||
}); |
|||
|
|||
if (total < 1) { |
|||
this.setData({ |
|||
sending: false, |
|||
'codes.codeText': "获取验证码" |
|||
}); |
|||
clearInterval(timer); |
|||
} |
|||
}, 1000); |
|||
}, () => { |
|||
this.setData({ |
|||
sending: false, |
|||
'codes.codeText': "获取验证码" |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
getLoginCode(resolve, reject) { |
|||
var message = null; |
|||
|
|||
if (!is.has(this.tellphone)) { |
|||
message = "请输入您的手机号"; |
|||
} else if (!is.mobile(this.tellphone)) { |
|||
message = '手机号格式不正确,请重新输入'; |
|||
getCode(){ |
|||
if(this.is_code) return; |
|||
this.is_code = true; |
|||
if(this.timer){ |
|||
clearInterval(this.timer); |
|||
this.timer = null; |
|||
} |
|||
|
|||
if (message) { |
|||
this.setData({ |
|||
message: message |
|||
}); |
|||
reject(); |
|||
setTimeout(() => { |
|||
this.setData({ |
|||
message: "" |
|||
}); |
|||
}, 3000); |
|||
return; |
|||
} |
|||
|
|||
this.$http.post({ |
|||
api: "api/sms/verify-code", |
|||
data: { |
|||
mobile: this.tellphone, |
|||
access_token: this.codes.access_token |
|||
console.log("测试重复点击", Math.random()) |
|||
// TODO 在此发送网络请求 |
|||
this.timer = setInterval(() => { |
|||
this.num--; |
|||
if(this.num <= 0){ |
|||
clearInterval(this.timer); |
|||
this.timer = null; |
|||
this.num = 10; |
|||
this.is_code = false; |
|||
} |
|||
}).then(res => { |
|||
if (res.data.success) { |
|||
resolve(); |
|||
} else { |
|||
reject(); |
|||
} |
|||
}); |
|||
}, 1000); |
|||
}, |
|||
|
|||
submitF() { |
|||
var message = null; |
|||
|
|||
|
|||
if (!is.has(this.tellphone)) { |
|||
message = "请输入您的手机号"; |
|||
} else if (!is.mobile(this.tellphone)) { |
|||
message = '手机号格式不正确,请重新输入'; |
|||
} else if (!is.has(this.identifyingcode)) { |
|||
message = "请填写验证码"; |
|||
} else if (!is.has(this.checked)) { |
|||
message = "请同意此协议"; |
|||
} |
|||
|
|||
if (message) { |
|||
|
|||
this.message = message; |
|||
|
|||
setTimeout(() => { |
|||
this.message = ''; |
|||
}, 3000); |
|||
return; |
|||
} |
|||
|
|||
this.setData({ |
|||
showLoading: true |
|||
}); |
|||
if(this.is_app_bind){ |
|||
this.appbindPhone() |
|||
} else{ |
|||
|
|||
this.quickLogin(); |
|||
} |
|||
next(){ |
|||
|
|||
}, |
|||
appbindPhone(){ |
|||
var that = this; |
|||
var data = { |
|||
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') || '', |
|||
open_type: 'wechat', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
grant_type: 'sms_token', |
|||
type: "direct" |
|||
} |
|||
this.$http.post({ |
|||
api:'api/oauth/sms', |
|||
data:data |
|||
}).then(res=>{ |
|||
res = res.data; |
|||
if(res.status){ |
|||
res.data.access_token = res.data.token_type + ' ' + res.data.access_token; |
|||
var expires_in = res.data.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", res.data.access_token, expires_in); |
|||
if (this.orginUrl != ''){ |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
}else{ |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
|
|||
} |
|||
|
|||
|
|||
}else{ |
|||
wx.showModal({ |
|||
content: res.message || "验证码不正确", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
}) |
|||
}, |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
quickLogin() { |
|||
var that = this; |
|||
// #ifdef MP-WEIXIN |
|||
var data = { |
|||
grant_type: 'sms_token', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
open_type: 'miniprogram', |
|||
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') || '' |
|||
}; |
|||
// #endif |
|||
|
|||
<style lang="scss" scoped> |
|||
.head{ |
|||
height: 400rpx; |
|||
width: 750rpx; |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
justify-content: center; |
|||
.head-content{ |
|||
display: flex; |
|||
flex-direction: column; |
|||
|
|||
// #ifdef H5 |
|||
var data = { |
|||
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') || '', |
|||
open_type: 'wechat', |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
grant_type: 'sms_token', |
|||
type: "direct" |
|||
} |
|||
// #endif |
|||
|
|||
// #ifdef APP-PLUS |
|||
var app_info = this.$cookieStorage.get('app_user_info'); |
|||
var nick_name; |
|||
var avatar; |
|||
if(app_info){ |
|||
nick_name = app_info.nickName; |
|||
avatar = app_info.avatarUrl; |
|||
} |
|||
|
|||
var data = { |
|||
access_token: that.codes.access_token, |
|||
mobile: that.tellphone, |
|||
code: that.identifyingcode, |
|||
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') || '', |
|||
grant_type: 'sms_token', |
|||
type: "direct", |
|||
nick_name:nick_name || '', |
|||
avatar:avatar || '' |
|||
} |
|||
// #endif |
|||
this.$http.post({ |
|||
// #ifdef MP-WEIXIN |
|||
api: "api/oauth/sms", |
|||
// #endif |
|||
|
|||
// #ifdef H5 |
|||
api: 'api/oauth/sms', |
|||
// #endif |
|||
// #ifdef APP-PLUS |
|||
api:'api/oauth/app/sms', |
|||
// #endif |
|||
data: data, |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
// #ifdef H5 || APP-PLUS |
|||
if (res.data.access_token) { |
|||
|
|||
res.data.access_token = res.data.token_type + ' ' + res.data.access_token; |
|||
var expires_in = res.data.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", res.data.access_token, expires_in); |
|||
|
|||
|
|||
// #ifdef APP-PLUS |
|||
if (this.orginUrl != '') |
|||
// #endif |
|||
// #ifdef H5 |
|||
if (this.orginUrl != 'undefined') |
|||
// #endif |
|||
{ |
|||
|
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} |
|||
else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} |
|||
|
|||
|
|||
// #endif |
|||
|
|||
// #ifdef MP-WEIXIN |
|||
|
|||
if (res.data.access_token) { |
|||
var result = res.data; |
|||
|
|||
if (result.access_token) { |
|||
result.access_token = result.token_type + ' ' + result.access_token; |
|||
var expires_in = result.expires_in || 315360000; |
|||
this.$cookieStorage.set("user_token", result.access_token, expires_in); // wx.setStorageSync("user_token",result.access_token); |
|||
|
|||
|
|||
|
|||
if (this.orginUrl != 'undefined') { |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl, |
|||
fail:rej=>{ |
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
}); |
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
if (this.orginUrl != 'undefined') { |
|||
|
|||
if (this.orginUrl.startsWith('pages/index/index/index')) { |
|||
if (this.orginUrl == "pages/index/index/index") { |
|||
getApp().globalData.giftLogin = false; |
|||
} else { |
|||
getApp().globalData.giftLogin = true; |
|||
} |
|||
|
|||
wx.switchTab({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} else { |
|||
wx.redirectTo({ |
|||
url: "/" + this.orginUrl |
|||
}); |
|||
} |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// #endif |
|||
|
|||
|
|||
else { |
|||
wx.showModal({ |
|||
content: res.message || "验证码不正确", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: "请求失败", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
this.setData({ |
|||
showLoading: false |
|||
}); |
|||
}).catch(rej => { |
|||
wx.showModal({ |
|||
content: "请求失败", |
|||
showCancel: false |
|||
}); |
|||
this.setData({ |
|||
showLoading: false |
|||
}); |
|||
}); |
|||
}, |
|||
setData: function(obj) { |
|||
let that = this; |
|||
let keys = []; |
|||
let val, data; |
|||
Object.keys(obj).forEach(function(key) { |
|||
keys = key.split('.'); |
|||
val = obj[key]; |
|||
data = that.$data; |
|||
keys.forEach(function(key2, index) { |
|||
if (index + 1 == keys.length) { |
|||
that.$set(data, key2, val); |
|||
} else { |
|||
if (!data[key2]) { |
|||
that.$set(data, key2, {}); |
|||
} |
|||
} |
|||
|
|||
data = data[key2]; |
|||
}); |
|||
}); |
|||
align-items: center; |
|||
.logo{ |
|||
width: 182rpx; |
|||
height: 182rpx; |
|||
border-radius: 50%; |
|||
background-color: #EEEEEE; |
|||
} |
|||
}, |
|||
computed: {}, |
|||
watch: {} |
|||
}; |
|||
</script> |
|||
<style rel="stylesheet/less" lang="less"> |
|||
@import "loginType"; |
|||
.title{ |
|||
font-size: 32rpx; |
|||
color: #222222; |
|||
font-weight: bold; |
|||
font-family: '楷体'; |
|||
margin-top: 20rpx; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.content{ |
|||
padding: 0 32rpx; |
|||
} |
|||
.next-btn{ |
|||
width: 550rpx; |
|||
height: 100rpx; |
|||
background: #15716E; |
|||
border-radius: 50rpx; |
|||
line-height: 100rpx; |
|||
color: #FFFFFF; |
|||
margin-top: 100rpx; |
|||
} |
|||
.list{ |
|||
height: 120rpx; |
|||
width: 100%; |
|||
border-bottom: 1rpx solid #e5e5e5; |
|||
display: flex; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
.input{ |
|||
width: 430rpx; |
|||
height: 80rpx; |
|||
font-size: 28rpx; |
|||
} |
|||
.input-code{ |
|||
width: 340rpx; |
|||
} |
|||
.clear{ |
|||
padding: 20rpx; |
|||
} |
|||
.code{ |
|||
min-width: 180rpx; |
|||
max-width: 220rpx; |
|||
height: 64rpx; |
|||
padding: 0 4rpx; |
|||
font-size: 24rpx; |
|||
color: #15716E; |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
border-radius: 32rpx; |
|||
border: 2rpx solid #15716E; |
|||
} |
|||
.active-bg{ |
|||
background: #efefef; |
|||
} |
|||
} |
|||
|
|||
.fixed-desc{ |
|||
position: fixed; |
|||
bottom: 50rpx; |
|||
left: calc(50% - 343rpx); |
|||
width: 686rpx; |
|||
padding-bottom: constant(safe-area-inset-bottom); |
|||
padding-bottom: env(safe-area-inset-bottom); |
|||
font-size: 28rpx; |
|||
color: #777777; |
|||
&>text:nth-child(2){ |
|||
color: #FF9D9D; |
|||
} |
|||
} |
|||
</style> |
|||
@ -0,0 +1,708 @@ |
|||
<template> |
|||
<view id="login-type"> |
|||
<view class="phone__warning"> |
|||
<image src="https://cdn.guojiang.club/app_guojiang_logo.png"></image> |
|||
<!--<i class="iconfont icon-anquanjinggao"></i>--> |
|||
</view> |
|||
<!-- #ifdef MP-WEIXIN --> |
|||
<button class="wechat-phoneBtn phone__btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"> |
|||
<i class="iconfont icon-hudong"></i> |
|||
<view class="btn__text">微信登录</view> |
|||
</button> |
|||
<!-- #endif --> |
|||
<!-- #ifdef APP-PLUS --> |
|||
<button class="wechat-phoneBtn phone__btn" @click="appLogin"> |
|||
<i class="iconfont icon-hudong"></i> |
|||
<view class="btn__text">微信登录</view> |
|||
</button> |
|||
<!-- #endif --> |
|||
<!-- #ifdef MP-WEIXIN--> |
|||
<view class="phone_login" @tap="jumpLogin"> |
|||
手机号登录 |
|||
</view> |
|||
<!-- #endif --> |
|||
|
|||
<!-- #ifdef APP-PLUS --> |
|||
<view class="phone_login" @tap="jumploginType"> |
|||
手机号登录 |
|||
</view> |
|||
<!-- #endif --> |
|||
<view class="select" @tap="chageAgreement"> |
|||
<text> 注册/登录即代表同意《果酱使用协议》</text> |
|||
</view> |
|||
|
|||
<view class="mask" :hidden="!showAgreement"> |
|||
|
|||
</view> |
|||
<view class="greement-box" :hidden="!showAgreement"> |
|||
<view class="title mx-1px-bottom"> |
|||
用户协议 |
|||
</view> |
|||
<view class="content"> |
|||
<!-- <u-parse :content="agreement.user_agreement" /> --> |
|||
</view> |
|||
<view class="btn mx-1px-top" @tap="chageAgreement"> |
|||
确定 |
|||
</view> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
<script> |
|||
import { |
|||
pageLogin, |
|||
getUrl, |
|||
config, |
|||
wechat, |
|||
GetUrl |
|||
} from '@/common/js/utils.js'; |
|||
import uParse from '@/components/gaoyia-parse/parse.vue'; |
|||
|
|||
export default { |
|||
|
|||
components: { |
|||
uParse |
|||
}, |
|||
|
|||
data() { |
|||
return { |
|||
code: '', |
|||
url: '', |
|||
logo: '', |
|||
author: config.PACKAGES.author, |
|||
config: '', |
|||
showAgreement: false, |
|||
agreement: '', |
|||
open_id: '', |
|||
h5_url: '' |
|||
}; |
|||
}, |
|||
|
|||
onShow() { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
// this.setData({ |
|||
// token: token |
|||
// }); |
|||
this.token = token; |
|||
|
|||
var initInfo = this.$cookieStorage.get('init'); |
|||
|
|||
if (initInfo && initInfo.shop_show_logo) { |
|||
this.setData({ |
|||
logo: initInfo.shop_show_logo |
|||
}); |
|||
} |
|||
|
|||
if (token) { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} else { |
|||
// #ifdef MP-WEIXIN |
|||
this.wxLogin(); |
|||
// #endif |
|||
} |
|||
}, |
|||
|
|||
onLoad(e) { |
|||
// 第三方平台配置颜色 |
|||
var bgConfig = this.$cookieStorage.get('globalConfig') || ''; |
|||
this.setData({ |
|||
config: bgConfig |
|||
}); |
|||
|
|||
if (e.url) { |
|||
// #ifdef APP-PLUS |
|||
console.log(e.url) |
|||
this.url = e.url |
|||
// #endif |
|||
// #ifdef MP-WEIXIN || H5 |
|||
this.url = decodeURIComponent(e.url); |
|||
console.log('this.url',this.url) |
|||
// #endif |
|||
} |
|||
|
|||
if (e.shop_id) { |
|||
this.$cookieStorage.set('shop_id', e.shop_id); |
|||
} |
|||
|
|||
this.getGreementInfo(); |
|||
|
|||
// #ifdef APP-PLUS |
|||
var appid = plus.runtime.appid; |
|||
// #endif |
|||
|
|||
// #ifdef H5 |
|||
var env = { |
|||
isIPad: /ipad/i.test(window.navigator.userAgent), |
|||
isIphone: /iphone|ipad|ipod/i.test(window.navigator.userAgent), |
|||
isWechat: /MicroMessenger/i.test(window.navigator.userAgent) |
|||
} |
|||
if(env.isWechat){ |
|||
if(e.openid){ |
|||
this.$cookieStorage.set('openid',e.openid) |
|||
} |
|||
var openid = this.$cookieStorage.get('openid') || e.openid; |
|||
if(openid){ |
|||
this.postNewQuickLogin(openid); |
|||
} else{ |
|||
let origin = window.location.origin; |
|||
var url = origin+'/pages/user/register/register'; |
|||
window.location.href = this.$config.GLOBAL.baseUrl+'oauth/wxOauth?redirect_url='+encodeURIComponent(url); |
|||
} |
|||
} else{ |
|||
let url = this.url; |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?url='+url |
|||
}) |
|||
} |
|||
|
|||
// #endif |
|||
|
|||
}, |
|||
methods: { |
|||
jumploginType(){ |
|||
var url = this.url; |
|||
if(url){ |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?url='+encodeURIComponent(JSON.stringify(this.url))+'&is_app_bind=app' |
|||
}) |
|||
} else{ |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?is_app_bind=app' |
|||
}) |
|||
|
|||
} |
|||
|
|||
}, |
|||
//h5调用微信登陆接口 |
|||
postNewQuickLogin(open_id){ |
|||
wx.showLoading({ |
|||
title: '正在登录', |
|||
mask: true |
|||
}); |
|||
this.$http.post({ |
|||
api:'api/oauth/newQuickLogin', |
|||
data:{ |
|||
open_id:open_id |
|||
} |
|||
}).then(res=>{ |
|||
res = res.data; |
|||
if(res.status){ |
|||
if(res.data.access_token){ |
|||
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(res.data.has_bind_mobile == 0){ |
|||
wx.reLaunch({ |
|||
url:'/pages/user/bindingphone/bindingphone' |
|||
}) |
|||
} else{ |
|||
var url = this.url; |
|||
if(url){ |
|||
wx.redirectTo({ |
|||
url:'/'+ url, |
|||
fail:res=>{ |
|||
wx.switchTab({ |
|||
url:'/'+ url |
|||
}) |
|||
} |
|||
}) |
|||
} else{ |
|||
wx.switchTab({ |
|||
url:'/pages/user/personal/personal' |
|||
}) |
|||
} |
|||
|
|||
} |
|||
} else{ |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
|
|||
} |
|||
|
|||
} else{ |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading() |
|||
}).catch(rej=>{ |
|||
wx.showModal({ |
|||
content: rej.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
wx.hideLoading() |
|||
|
|||
}) |
|||
|
|||
}, |
|||
// app调用登录接口 |
|||
appLogin() { |
|||
var that = this; |
|||
uni.getProvider({ |
|||
service: 'oauth', |
|||
success: function(res) { |
|||
uni.login({ |
|||
provider: "weixin", |
|||
success: function(loginRes) { |
|||
uni.getUserInfo({ |
|||
provider: 'weixin', |
|||
success: function (infoRes) { |
|||
var app_info = { |
|||
nickName:infoRes.userInfo.nickName, |
|||
avatarUrl:infoRes.userInfo.avatarUrl |
|||
} |
|||
that.$cookieStorage.set('app_user_info',app_info) |
|||
} |
|||
}); |
|||
console.log('loginRes',loginRes); |
|||
that.postUnionidLogin(loginRes) |
|||
} |
|||
}) |
|||
|
|||
} |
|||
}) |
|||
|
|||
}, |
|||
// app登录请求的接口 |
|||
postUnionidLogin(data) { |
|||
var newobj = { |
|||
openid: data.authResult.openid, |
|||
unionid: data.authResult.unionid |
|||
} |
|||
this.$http.post({ |
|||
api: 'api/oauth/app/unionid/login', |
|||
data: { |
|||
openid: data.authResult.openid, |
|||
unionid: data.authResult.unionid |
|||
} |
|||
}).then(res => { |
|||
res = res.data; |
|||
if (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; |
|||
this.$cookieStorage.set("user_token", access_token, expires_in); |
|||
if (this.url) { |
|||
wx.redirectTo({ |
|||
url: "/" + this.url, |
|||
fail: res => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
|
|||
} |
|||
} else { |
|||
var open_id = res.data.open_id; |
|||
wx.showToast({ |
|||
title: '需先绑定手机号', |
|||
duration: 3000, |
|||
success: res => { |
|||
var mobileurl = '/pages/user/loginType/loginType?url=' + encodeURIComponent(JSON.stringify(this.url))+ '&open_id=' +encodeURIComponent(JSON.stringify(open_id)) +'&is_app_weixin=appweixin' |
|||
wx.redirectTo({ |
|||
url: mobileurl |
|||
}) |
|||
} |
|||
}) |
|||
|
|||
|
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
|
|||
} |
|||
}) |
|||
}, |
|||
chageAgreement() { |
|||
this.setData({ |
|||
showAgreement: !this.showAgreement |
|||
}); |
|||
}, |
|||
|
|||
// 获取用户协议 |
|||
getGreementInfo() { |
|||
this.$http.get({ |
|||
api: 'api/user/agreement' |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
|
|||
if (res.status) { |
|||
this.setData({ |
|||
agreement: res.data |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
wxLogin() { |
|||
|
|||
//H5判断是否是微信环境 |
|||
//#ifdef H5 |
|||
/* if (!wechat.isWechat()) { |
|||
this.jumpLogin(); |
|||
return; |
|||
} else { |
|||
var url = this.$route.query.url; |
|||
|
|||
var obj_url = GetUrl(url); |
|||
|
|||
if (obj_url == undefined || obj_url.openid == undefined) { |
|||
this.officialAccountLogin(); |
|||
} else { |
|||
this.open_id = obj_url.openid; |
|||
this.url = url; |
|||
this.quickLoginByOpenId(url) |
|||
} |
|||
*/ |
|||
// } |
|||
//#endif |
|||
|
|||
// #ifdef APP-PLUS |
|||
this.jumpLogin(); |
|||
return; |
|||
// #endif |
|||
|
|||
//#ifdef MP-WEIXIN |
|||
wx.showLoading({ |
|||
title: '正在自动登录', |
|||
mask: true |
|||
}); |
|||
wx.login({ |
|||
success: res => { |
|||
if (res.code) { |
|||
this.autoLogin(res.code); |
|||
} else { |
|||
wx.showToast({ |
|||
title: '获取code失败', |
|||
image: '../../../static/error.png' |
|||
}); |
|||
} |
|||
}, |
|||
}); |
|||
// #endif |
|||
|
|||
}, |
|||
|
|||
quickLoginByOpenId(url) { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
if (wechat.isWechat() && !token) { |
|||
this.$http.post({ |
|||
api: 'api/oauth/official-account/quick-login', |
|||
data: { |
|||
open_id: this.open_id |
|||
} |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
if (res.status) { |
|||
if (res.data.open_id != '') { |
|||
|
|||
var url_ = '/pages/user/loginType/loginType?url=' + decodeURIComponent(this.url) + '&open_id=' + this.open_id; |
|||
wx.redirectTo({ |
|||
url: url_ |
|||
}); |
|||
return; |
|||
} |
|||
|
|||
if (res.data.access_token) { |
|||
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({ |
|||
url: "/" + this.url, |
|||
fail: rej => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading(); |
|||
|
|||
}, err => { |
|||
wx.hideLoading(); |
|||
|
|||
}); |
|||
} |
|||
}, |
|||
|
|||
officialAccountLogin() { |
|||
|
|||
var url = this.url ? encodeURIComponent(this.url) : 'pages/user/personal/personal' |
|||
|
|||
var redirect_url = config.GLOBAL.mobile_url + 'pages/user/register/register?url=' + url; |
|||
|
|||
console.log(redirect_url); |
|||
|
|||
this.$http.get({ |
|||
api: 'api/oauth/official-account/get-redirect-url', |
|||
data: { |
|||
redirect_url: redirect_url |
|||
} |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
if (res.status) { |
|||
if (res.data.url) { |
|||
window.location.href = res.data.url; |
|||
} |
|||
|
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: '请求失败', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: '请求失败', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading(); |
|||
|
|||
}, err => { |
|||
wx.hideLoading(); |
|||
|
|||
}); |
|||
|
|||
}, |
|||
|
|||
jumpLogin() { |
|||
if (this.url) { |
|||
wx.navigateTo({ |
|||
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 |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
getPhoneNumber(e) { |
|||
if (e.detail.encryptedData) { |
|||
wx.login({ |
|||
success: res => { |
|||
if (res.code) { |
|||
this.setData({ |
|||
code: res.code |
|||
}); |
|||
this.phone(e); |
|||
} else { |
|||
wx.showModal({ |
|||
content: " 获取code失败", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
return; |
|||
} else { |
|||
this.jumpLogin(); |
|||
} |
|||
}, |
|||
|
|||
phone(e) { |
|||
wx.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); |
|||
// wx.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) { |
|||
wx.redirectTo({ |
|||
url: "/" + this.url |
|||
}); |
|||
} else { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
|
|||
wx.hideLoading(); |
|||
}).catch(rej => { |
|||
wx.hideLoading(); |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
autoLogin(code) { |
|||
this.$http.post({ |
|||
api: 'api/oauth/miniprogram/login', |
|||
data: { |
|||
code: code, |
|||
open_type: 'miniprogram', |
|||
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 => { |
|||
res = res.data; |
|||
if (res.data && res.data.open_id) { |
|||
this.setData({ |
|||
open_id: res.data.open_id |
|||
}); |
|||
} // 如果接口返回token就直接登录,如果没有则弹出授权 |
|||
|
|||
if (res.data.access_token) { |
|||
console.log('已经返回给我了token'); |
|||
wx.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({ |
|||
url: "/" + this.url, |
|||
fail: () => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}) |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.hideLoading(); |
|||
} |
|||
}).catch(rej => { |
|||
wx.hideLoading(); |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false, |
|||
success: res => { |
|||
if (res.confirm || !res.cancel && !res.confirm) { |
|||
this.wxLogin(); |
|||
} |
|||
} |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
setData: function(obj) { |
|||
let that = this; |
|||
let keys = []; |
|||
let val, data; |
|||
Object.keys(obj).forEach(function(key) { |
|||
keys = key.split('.'); |
|||
val = obj[key]; |
|||
data = that.$data; |
|||
keys.forEach(function(key2, index) { |
|||
if (index + 1 == keys.length) { |
|||
that.$set(data, key2, val); |
|||
} else { |
|||
if (!data[key2]) { |
|||
that.$set(data, key2, {}); |
|||
} |
|||
} |
|||
|
|||
data = data[key2]; |
|||
}); |
|||
}); |
|||
} |
|||
}, |
|||
computed: {}, |
|||
watch: {} |
|||
}; |
|||
</script> |
|||
|
|||
<style rel="stylesheet/less" lang="less"> |
|||
@import "register"; |
|||
</style> |
|||
@ -1,708 +1,75 @@ |
|||
<template> |
|||
<view id="login-type"> |
|||
<view class="phone__warning"> |
|||
<image src="https://cdn.guojiang.club/app_guojiang_logo.png"></image> |
|||
<!--<i class="iconfont icon-anquanjinggao"></i>--> |
|||
<view> |
|||
<lf-nav title="登录/注册" :showIcon="true" bgColor="#fff"></lf-nav> |
|||
<view class="illustration"> |
|||
<image class="img" src="../../../static/images/empty.png" mode="aspectFill"></image> |
|||
</view> |
|||
<!-- #ifdef MP-WEIXIN --> |
|||
<button class="wechat-phoneBtn phone__btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"> |
|||
<i class="iconfont icon-hudong"></i> |
|||
<view class="btn__text">微信登录</view> |
|||
</button> |
|||
<!-- #endif --> |
|||
<!-- #ifdef APP-PLUS --> |
|||
<button class="wechat-phoneBtn phone__btn" @click="appLogin"> |
|||
<i class="iconfont icon-hudong"></i> |
|||
<view class="btn__text">微信登录</view> |
|||
</button> |
|||
<!-- #endif --> |
|||
<!-- #ifdef MP-WEIXIN--> |
|||
<view class="phone_login" @tap="jumpLogin"> |
|||
手机号登录 |
|||
</view> |
|||
<!-- #endif --> |
|||
|
|||
<!-- #ifdef APP-PLUS --> |
|||
<view class="phone_login" @tap="jumploginType"> |
|||
手机号登录 |
|||
</view> |
|||
<!-- #endif --> |
|||
<view class="select" @tap="chageAgreement"> |
|||
<text> 注册/登录即代表同意《果酱使用协议》</text> |
|||
</view> |
|||
|
|||
<view class="mask" :hidden="!showAgreement"> |
|||
|
|||
</view> |
|||
<view class="greement-box" :hidden="!showAgreement"> |
|||
<view class="title mx-1px-bottom"> |
|||
用户协议 |
|||
</view> |
|||
<view class="content"> |
|||
<!-- <u-parse :content="agreement.user_agreement" /> --> |
|||
</view> |
|||
<view class="btn mx-1px-top" @tap="chageAgreement"> |
|||
确定 |
|||
</view> |
|||
<view class="fixed-btn"> |
|||
<button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button> |
|||
<button class="btn2" hover-class="lf-opacity" @click="getUserInfo">微信授权登录</button> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
<script> |
|||
import { |
|||
pageLogin, |
|||
getUrl, |
|||
config, |
|||
wechat, |
|||
GetUrl |
|||
} from '@/common/js/utils.js'; |
|||
import uParse from '@/components/gaoyia-parse/parse.vue'; |
|||
|
|||
<script> |
|||
export default { |
|||
|
|||
components: { |
|||
uParse |
|||
}, |
|||
|
|||
data() { |
|||
return { |
|||
code: '', |
|||
url: '', |
|||
logo: '', |
|||
author: config.PACKAGES.author, |
|||
config: '', |
|||
showAgreement: false, |
|||
agreement: '', |
|||
open_id: '', |
|||
h5_url: '' |
|||
}; |
|||
}, |
|||
|
|||
onShow() { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
// this.setData({ |
|||
// token: token |
|||
// }); |
|||
this.token = token; |
|||
|
|||
var initInfo = this.$cookieStorage.get('init'); |
|||
|
|||
if (initInfo && initInfo.shop_show_logo) { |
|||
this.setData({ |
|||
logo: initInfo.shop_show_logo |
|||
}); |
|||
} |
|||
|
|||
if (token) { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} else { |
|||
// #ifdef MP-WEIXIN |
|||
this.wxLogin(); |
|||
// #endif |
|||
} |
|||
}, |
|||
|
|||
onLoad(e) { |
|||
// 第三方平台配置颜色 |
|||
var bgConfig = this.$cookieStorage.get('globalConfig') || ''; |
|||
this.setData({ |
|||
config: bgConfig |
|||
}); |
|||
|
|||
if (e.url) { |
|||
// #ifdef APP-PLUS |
|||
console.log(e.url) |
|||
this.url = e.url |
|||
// #endif |
|||
// #ifdef MP-WEIXIN || H5 |
|||
this.url = decodeURIComponent(e.url); |
|||
console.log('this.url',this.url) |
|||
// #endif |
|||
} |
|||
|
|||
if (e.shop_id) { |
|||
this.$cookieStorage.set('shop_id', e.shop_id); |
|||
} |
|||
|
|||
this.getGreementInfo(); |
|||
|
|||
// #ifdef APP-PLUS |
|||
var appid = plus.runtime.appid; |
|||
// #endif |
|||
|
|||
// #ifdef H5 |
|||
var env = { |
|||
isIPad: /ipad/i.test(window.navigator.userAgent), |
|||
isIphone: /iphone|ipad|ipod/i.test(window.navigator.userAgent), |
|||
isWechat: /MicroMessenger/i.test(window.navigator.userAgent) |
|||
} |
|||
if(env.isWechat){ |
|||
if(e.openid){ |
|||
this.$cookieStorage.set('openid',e.openid) |
|||
} |
|||
var openid = this.$cookieStorage.get('openid') || e.openid; |
|||
if(openid){ |
|||
this.postNewQuickLogin(openid); |
|||
} else{ |
|||
let origin = window.location.origin; |
|||
var url = origin+'/pages/user/register/register'; |
|||
window.location.href = this.$config.GLOBAL.baseUrl+'oauth/wxOauth?redirect_url='+encodeURIComponent(url); |
|||
} |
|||
} else{ |
|||
let url = this.url; |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?url='+url |
|||
}) |
|||
} |
|||
|
|||
// #endif |
|||
|
|||
}, |
|||
methods: { |
|||
jumploginType(){ |
|||
var url = this.url; |
|||
if(url){ |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?url='+encodeURIComponent(JSON.stringify(this.url))+'&is_app_bind=app' |
|||
}) |
|||
} else{ |
|||
wx.navigateTo({ |
|||
url:'/pages/user/loginType/loginType?is_app_bind=app' |
|||
}) |
|||
|
|||
} |
|||
|
|||
}, |
|||
//h5调用微信登陆接口 |
|||
postNewQuickLogin(open_id){ |
|||
wx.showLoading({ |
|||
title: '正在登录', |
|||
mask: true |
|||
}); |
|||
this.$http.post({ |
|||
api:'api/oauth/newQuickLogin', |
|||
data:{ |
|||
open_id:open_id |
|||
} |
|||
}).then(res=>{ |
|||
res = res.data; |
|||
if(res.status){ |
|||
if(res.data.access_token){ |
|||
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(res.data.has_bind_mobile == 0){ |
|||
wx.reLaunch({ |
|||
url:'/pages/user/bindingphone/bindingphone' |
|||
}) |
|||
} else{ |
|||
var url = this.url; |
|||
if(url){ |
|||
wx.redirectTo({ |
|||
url:'/'+ url, |
|||
fail:res=>{ |
|||
wx.switchTab({ |
|||
url:'/'+ url |
|||
}) |
|||
} |
|||
}) |
|||
} else{ |
|||
wx.switchTab({ |
|||
url:'/pages/user/personal/personal' |
|||
}) |
|||
} |
|||
|
|||
} |
|||
} else{ |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
|
|||
getUserInfo(){ |
|||
uni.getUserProfile({ |
|||
desc: '我们将获取到的信息用于展示', |
|||
lang: 'zh_CN', |
|||
complete: result => { |
|||
console.log(result); |
|||
if(result.errMsg == 'getUserProfile:ok'){ |
|||
console.log("获取成功!"); |
|||
} |
|||
|
|||
} else{ |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading() |
|||
}).catch(rej=>{ |
|||
wx.showModal({ |
|||
content: rej.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
wx.hideLoading() |
|||
|
|||
}) |
|||
|
|||
}, |
|||
// app调用登录接口 |
|||
appLogin() { |
|||
var that = this; |
|||
uni.getProvider({ |
|||
service: 'oauth', |
|||
success: function(res) { |
|||
uni.login({ |
|||
provider: "weixin", |
|||
success: function(loginRes) { |
|||
uni.getUserInfo({ |
|||
provider: 'weixin', |
|||
success: function (infoRes) { |
|||
var app_info = { |
|||
nickName:infoRes.userInfo.nickName, |
|||
avatarUrl:infoRes.userInfo.avatarUrl |
|||
} |
|||
that.$cookieStorage.set('app_user_info',app_info) |
|||
} |
|||
}); |
|||
console.log('loginRes',loginRes); |
|||
that.postUnionidLogin(loginRes) |
|||
} |
|||
}) |
|||
|
|||
} |
|||
}) |
|||
|
|||
}, |
|||
// app登录请求的接口 |
|||
postUnionidLogin(data) { |
|||
var newobj = { |
|||
openid: data.authResult.openid, |
|||
unionid: data.authResult.unionid |
|||
} |
|||
this.$http.post({ |
|||
api: 'api/oauth/app/unionid/login', |
|||
data: { |
|||
openid: data.authResult.openid, |
|||
unionid: data.authResult.unionid |
|||
} |
|||
}).then(res => { |
|||
res = res.data; |
|||
if (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; |
|||
this.$cookieStorage.set("user_token", access_token, expires_in); |
|||
if (this.url) { |
|||
wx.redirectTo({ |
|||
url: "/" + this.url, |
|||
fail: res => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
|
|||
} |
|||
} else { |
|||
var open_id = res.data.open_id; |
|||
wx.showToast({ |
|||
title: '需先绑定手机号', |
|||
duration: 3000, |
|||
success: res => { |
|||
var mobileurl = '/pages/user/loginType/loginType?url=' + encodeURIComponent(JSON.stringify(this.url))+ '&open_id=' +encodeURIComponent(JSON.stringify(open_id)) +'&is_app_weixin=appweixin' |
|||
wx.redirectTo({ |
|||
url: mobileurl |
|||
}) |
|||
} |
|||
}) |
|||
|
|||
|
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
|
|||
} |
|||
}) |
|||
}, |
|||
chageAgreement() { |
|||
this.setData({ |
|||
showAgreement: !this.showAgreement |
|||
}); |
|||
}, |
|||
|
|||
// 获取用户协议 |
|||
getGreementInfo() { |
|||
this.$http.get({ |
|||
api: 'api/user/agreement' |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
|
|||
if (res.status) { |
|||
this.setData({ |
|||
agreement: res.data |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
wxLogin() { |
|||
|
|||
//H5判断是否是微信环境 |
|||
//#ifdef H5 |
|||
/* if (!wechat.isWechat()) { |
|||
this.jumpLogin(); |
|||
return; |
|||
} else { |
|||
var url = this.$route.query.url; |
|||
|
|||
var obj_url = GetUrl(url); |
|||
|
|||
if (obj_url == undefined || obj_url.openid == undefined) { |
|||
this.officialAccountLogin(); |
|||
} else { |
|||
this.open_id = obj_url.openid; |
|||
this.url = url; |
|||
this.quickLoginByOpenId(url) |
|||
} |
|||
*/ |
|||
// } |
|||
//#endif |
|||
|
|||
// #ifdef APP-PLUS |
|||
this.jumpLogin(); |
|||
return; |
|||
// #endif |
|||
|
|||
//#ifdef MP-WEIXIN |
|||
wx.showLoading({ |
|||
title: '正在自动登录', |
|||
mask: true |
|||
}); |
|||
wx.login({ |
|||
success: res => { |
|||
if (res.code) { |
|||
this.autoLogin(res.code); |
|||
} else { |
|||
wx.showToast({ |
|||
title: '获取code失败', |
|||
image: '../../../static/error.png' |
|||
}); |
|||
} |
|||
}, |
|||
}); |
|||
// #endif |
|||
|
|||
}, |
|||
|
|||
quickLoginByOpenId(url) { |
|||
var token = this.$cookieStorage.get('user_token'); |
|||
if (wechat.isWechat() && !token) { |
|||
this.$http.post({ |
|||
api: 'api/oauth/official-account/quick-login', |
|||
data: { |
|||
open_id: this.open_id |
|||
} |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
if (res.status) { |
|||
if (res.data.open_id != '') { |
|||
|
|||
var url_ = '/pages/user/loginType/loginType?url=' + decodeURIComponent(this.url) + '&open_id=' + this.open_id; |
|||
wx.redirectTo({ |
|||
url: url_ |
|||
}); |
|||
return; |
|||
} |
|||
|
|||
if (res.data.access_token) { |
|||
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({ |
|||
url: "/" + this.url, |
|||
fail: rej => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading(); |
|||
|
|||
}, err => { |
|||
wx.hideLoading(); |
|||
|
|||
}); |
|||
} |
|||
}, |
|||
|
|||
officialAccountLogin() { |
|||
|
|||
var url = this.url ? encodeURIComponent(this.url) : 'pages/user/personal/personal' |
|||
|
|||
var redirect_url = config.GLOBAL.mobile_url + 'pages/user/register/register?url=' + url; |
|||
|
|||
console.log(redirect_url); |
|||
|
|||
this.$http.get({ |
|||
api: 'api/oauth/official-account/get-redirect-url', |
|||
data: { |
|||
redirect_url: redirect_url |
|||
} |
|||
}).then(res => { |
|||
if (res.statusCode == 200) { |
|||
res = res.data; |
|||
if (res.status) { |
|||
if (res.data.url) { |
|||
window.location.href = res.data.url; |
|||
} |
|||
|
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: '请求失败', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
title: '', |
|||
content: '请求失败', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
wx.hideLoading(); |
|||
|
|||
}, err => { |
|||
wx.hideLoading(); |
|||
|
|||
}); |
|||
|
|||
}, |
|||
|
|||
jumpLogin() { |
|||
if (this.url) { |
|||
wx.navigateTo({ |
|||
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 |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
getPhoneNumber(e) { |
|||
if (e.detail.encryptedData) { |
|||
wx.login({ |
|||
success: res => { |
|||
if (res.code) { |
|||
this.setData({ |
|||
code: res.code |
|||
}); |
|||
this.phone(e); |
|||
} else { |
|||
wx.showModal({ |
|||
content: " 获取code失败", |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
return; |
|||
} else { |
|||
this.jumpLogin(); |
|||
} |
|||
}, |
|||
|
|||
phone(e) { |
|||
wx.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); |
|||
// wx.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) { |
|||
wx.redirectTo({ |
|||
url: "/" + this.url |
|||
}); |
|||
} else { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: res.message || '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
} else { |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
} |
|||
|
|||
wx.hideLoading(); |
|||
}).catch(rej => { |
|||
wx.hideLoading(); |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
autoLogin(code) { |
|||
this.$http.post({ |
|||
api: 'api/oauth/miniprogram/login', |
|||
data: { |
|||
code: code, |
|||
open_type: 'miniprogram', |
|||
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 => { |
|||
res = res.data; |
|||
if (res.data && res.data.open_id) { |
|||
this.setData({ |
|||
open_id: res.data.open_id |
|||
}); |
|||
} // 如果接口返回token就直接登录,如果没有则弹出授权 |
|||
|
|||
if (res.data.access_token) { |
|||
console.log('已经返回给我了token'); |
|||
wx.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({ |
|||
url: "/" + this.url, |
|||
fail: () => { |
|||
wx.switchTab({ |
|||
url: "/" + this.url |
|||
}); |
|||
} |
|||
}) |
|||
|
|||
} else { |
|||
wx.switchTab({ |
|||
url: '/pages/user/personal/personal' |
|||
}); |
|||
} |
|||
} else { |
|||
wx.hideLoading(); |
|||
} |
|||
}).catch(rej => { |
|||
wx.hideLoading(); |
|||
wx.showModal({ |
|||
content: '请求失败,请重试', |
|||
showCancel: false, |
|||
success: res => { |
|||
if (res.confirm || !res.cancel && !res.confirm) { |
|||
this.wxLogin(); |
|||
} |
|||
} |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
setData: function(obj) { |
|||
let that = this; |
|||
let keys = []; |
|||
let val, data; |
|||
Object.keys(obj).forEach(function(key) { |
|||
keys = key.split('.'); |
|||
val = obj[key]; |
|||
data = that.$data; |
|||
keys.forEach(function(key2, index) { |
|||
if (index + 1 == keys.length) { |
|||
that.$set(data, key2, val); |
|||
} else { |
|||
if (!data[key2]) { |
|||
that.$set(data, key2, {}); |
|||
} |
|||
} |
|||
|
|||
data = data[key2]; |
|||
}); |
|||
}); |
|||
toPhoneLogin(){ |
|||
this.$url('/pages/user/loginType/loginType'); |
|||
} |
|||
}, |
|||
computed: {}, |
|||
watch: {} |
|||
}; |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style rel="stylesheet/less" lang="less"> |
|||
@import "register"; |
|||
<style lang="scss" scoped> |
|||
.illustration{ |
|||
width: 750rpx; |
|||
height: 750rpx; |
|||
position: fixed; |
|||
top: 44%; |
|||
left: 0; |
|||
margin-top: -375rpx; |
|||
.img{ |
|||
width: 100%; |
|||
height: 100%; |
|||
} |
|||
} |
|||
.fixed-btn{ |
|||
width: 630rpx; |
|||
height: max-content; |
|||
position: fixed; |
|||
left: calc(50% - 315rpx); |
|||
top: calc(46% + 375rpx); |
|||
display: flex; |
|||
justify-content: space-between; |
|||
.btn1, .btn2{ |
|||
width: 300rpx; |
|||
height: 100rpx; |
|||
border-radius: 60rpx; |
|||
border: 1rpx solid #15716E; |
|||
box-sizing: border-box; |
|||
line-height: 100rpx; |
|||
font-size: 32rpx; |
|||
} |
|||
.btn1{ |
|||
background-color: #F3F8F8; |
|||
color: #15716E; |
|||
} |
|||
.btn2{ |
|||
background-color: #15716E; |
|||
color: #FFFFFF; |
|||
} |
|||
} |
|||
</style> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue