石可 5 years ago
parent
commit
30d2e44aba
  1. 24
      pages/index/index.vue
  2. 119
      pages/login/index.vue

24
pages/index/index.vue

@ -59,6 +59,29 @@
return {
}
},
onLoad(){
this.href_str = JSON.stringify(location.href);
let options = this.strToObj();
console.log("options", options)
},
methods: {
strToObj(){
let val = this.href_str;
let obj = {};
if(!val) return obj;
if(val.indexOf('?') < 0) return obj;
let indexA = val.indexOf('?') + 1;
let str = val.substr(indexA, val.length);
let indexB = str.indexOf('#');
str = str.substr(0, indexB);
let arr = str.split('&');
arr.map(item => {
let a = item.split('=');
obj[a[0]] = a[1];
});
return obj;
}
}
}
</script>
@ -70,6 +93,7 @@
padding: 21rpx 32rpx;
display: flex;
justify-content: space-between;
box-sizing: border-box;
.search{
// width: 530rpx;
width: 100%;

119
pages/login/index.vue

@ -1,126 +1,23 @@
<template>
<view>
<view class="lf-row-center lf-flex-column box">
<!-- <image class="img" :src="userInfo.avatar" v-if="userInfo.avatar"></image> -->
<!-- <image class="img" src="../../static/logo.png" v-else></image> -->
<image class="img" src="../../static/logo.png" ></image>
<view class="lf-m-t-30 lf-font-32" v-if="type == 'phone'">{{ userInfo.nickname || '游客用户' }}</view>
<block v-if="type == 'userinfo'">
<button class="btn" @click="getUserProfile">
<text class="lf-iconfont lf-icon-weixin lf-font-60 lf-text-vertical"></text>
<text class="lf-m-l-20">微信快捷登录</text>
</button>
<!-- <view class="lf-m-t-40 lf-font-28" @click="$toBack()">暂不绑定继续操作</view> -->
<view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
</block>
<block v-else-if="type == 'phone'">
<button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
<text class="lf-iconfont lf-icon-weixin lf-font-60 lf-text-vertical"></text>
<text class="lf-m-l-20">绑定手机号</text>
</button>
<!-- <view class="lf-m-t-40 lf-font-28" @click="$url('/pages/login/accountLogin')">使用手机号登录</view> -->
<view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
</block>
</view>
<!-- 服务条款 -->
<view class="fixed-bottom lf-flex" v-show="agreement.title">
<checkbox-group @change="checkboxChange" style="display: inline-block;">
<checkbox class="lf-text-vertical" :checked="checked"></checkbox>
</checkbox-group>
<view class="lf-m-l-10 lf-font-24 lf-color-gray" style="display: inline-block;">
<text>请认真阅读并同意</text>
<text @click="enterAgree" class="text-orange">{{ agreement.title }}</text>
<text>在小程序下单购买即表示您已默认同意</text>
<text @click="enterAgree" class="text-orange">{{ agreement.title }}</text>
<text>的所有条款</text>
</view>
</view>
</view>
<view></view>
</template>
<script>
export default {
data(){
return {
checked: false, //
isLogin: false, //
userInfo: {},
type: 'userinfo', // phone | userinfo
agreement: {} //
}
},
onLoad(options){
this.type = options.type || this.type;
this.getAgree();
getApp().globalData.wxlogin().then(res => {
this.userInfo = res;
});
const callbackURL = encodeURIComponent('http://192.168.3.183:8080/#/pages/index/index');
const appId = 'wx98e64ab875b2553e';
const dataStr = '1';
const redirectURI = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${callbackURL}&response_type=code&scope=snsapi_userinfo&state=${dataStr}#wechat_redirect`;
location.replace(redirectURI);
},
methods: {
//
getAgree(){
this.$http(this.API.API_WXLOGIN_VIEW).then(res => {
this.agreement = res.data?.agreement;
})
},
//
enterAgree(){
this.$url('/pages/agreement/agreement?id='+ this.agreement.article_id);
},
//
checkboxChange(event){
this.checked = event.detail.value.length > 0;
},
//
getPhoneNumber(event){
console.log(event);
if(event.detail.errMsg == 'getPhoneNumber:ok'){
let encryptedData = event.detail.encryptedData;
let iv = event.detail.iv;
// let userInfo = uni.getStorageSync('userinfo') || {};
this.$http(this.API.API_WECHAT_SETPHONE, {
encryptedData,
iv,
// token: userInfo.token //
}).then(res => {
console.log("更新手机号", res);
this.$msg('更新成功', {icon: 'success'});
uni.setStorageSync('userinfo', res.data);
setTimeout(() => {
this.$toBack();
}, 1000);
})
}
},
//
getUserProfile(){
uni.getUserProfile({
desc: '您的信息将用于时空网显示',
lang: 'zh_CN',
complete: result => {
console.log(result)
if(result.errMsg == 'getUserProfile:ok'){
let encryptedData = result.encryptedData;
let iv = result.iv;
let signature = result.signature;
// let userInfo = uni.getStorageSync('userinfo') || {};
this.$http(this.API.API_WECHAT_SETPROFILE, {
encryptedData,
iv,
// token: userInfo.token //
}).then(res => {
console.log("更新用户信息", res);
this.$msg('更新成功', {icon: 'success'});
uni.setStorageSync('userinfo', res.data);
setTimeout(() => {
this.$toBack();
}, 1000);
})
}
}
});
}
}
}
</script>

Loading…
Cancel
Save