|
@@ -1,20 +1,38 @@
|
|
<template>
|
|
<template>
|
|
<mobile-frame>
|
|
<mobile-frame>
|
|
<view class="main">
|
|
<view class="main">
|
|
- <view class="two">
|
|
|
|
|
|
+ <view class="one" v-if="platform.uniPlatform=='app'">
|
|
<uni-forms ref="form" :rules="rules" :model="form" label-width="auto">
|
|
<uni-forms ref="form" :rules="rules" :model="form" label-width="auto">
|
|
- <uni-forms-item label="账号" name="phone">
|
|
|
|
- <uni-easyinput type="text" v-model="form.phone" placeholder="请输入账号" />
|
|
|
|
|
|
+ <uni-forms-item label="手机号" name="phone">
|
|
|
|
+ <uni-easyinput type="text" v-model="form.phone" placeholder="请输入手机号" />
|
|
</uni-forms-item>
|
|
</uni-forms-item>
|
|
- <uni-forms-item label="密码" name="password">
|
|
|
|
- <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
|
|
|
|
|
|
+ <uni-forms-item label="验证码" name="code">
|
|
|
|
+ <uni-easyinput type="text" v-model="form.code" placeholder="请输入验证码" />
|
|
|
|
+ <button type="default" size="mini">验证码</button>
|
|
</uni-forms-item>
|
|
</uni-forms-item>
|
|
<view class="btn">
|
|
<view class="btn">
|
|
- <button type="default" size="mini" @click="toSubmit('form')">登录</button>
|
|
|
|
- <button type="default" size="mini" @click="wxLogin()">微信信任登录</button>
|
|
|
|
|
|
+ <button type="default" size="mini" @click="toSubmit('form')">提交登录</button>
|
|
</view>
|
|
</view>
|
|
</uni-forms>
|
|
</uni-forms>
|
|
</view>
|
|
</view>
|
|
|
|
+ <view class="two" v-else-if="platform.uniPlatform=='mp-weixin'">
|
|
|
|
+ <view class="icon">
|
|
|
|
+ <text class="iconfont icon-weixin"></text>
|
|
|
|
+ </view>
|
|
|
|
+ <view class="btn">
|
|
|
|
+ <button type="default" size="mini" @tap="wxLogin()" :open-type="openType" @getphonenumber="getUserPhone">微信信任登录</button>
|
|
|
|
+ </view>
|
|
|
|
+ </view>
|
|
|
|
+ <view class="thr">
|
|
|
|
+ <view class="thr_1">
|
|
|
|
+ <checkbox-group @change="changeAgree">
|
|
|
|
+ <label>
|
|
|
|
+ <checkbox :checked="agree" />
|
|
|
|
+ <text @tap="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
|
|
|
|
+ </label>
|
|
|
|
+ </checkbox-group>
|
|
|
|
+ </view>
|
|
|
|
+ </view>
|
|
</view>
|
|
</view>
|
|
</mobile-frame>
|
|
</mobile-frame>
|
|
</template>
|
|
</template>
|
|
@@ -25,14 +43,16 @@
|
|
return {
|
|
return {
|
|
// 平台信息
|
|
// 平台信息
|
|
platform: {},
|
|
platform: {},
|
|
|
|
+ //openid
|
|
openid: '',
|
|
openid: '',
|
|
- logoUrl: this.$config.logoUrl,
|
|
|
|
|
|
+ // 隐私协议
|
|
|
|
+ agree: false,
|
|
form: {},
|
|
form: {},
|
|
rules: {
|
|
rules: {
|
|
phone: {
|
|
phone: {
|
|
rules: [{
|
|
rules: [{
|
|
required: true,
|
|
required: true,
|
|
- errorMessage: '请输入账号',
|
|
|
|
|
|
+ errorMessage: '请输入手机号',
|
|
},
|
|
},
|
|
{
|
|
{
|
|
minLength: 11,
|
|
minLength: 11,
|
|
@@ -41,21 +61,36 @@
|
|
}
|
|
}
|
|
]
|
|
]
|
|
},
|
|
},
|
|
- password: {
|
|
|
|
|
|
+ code: {
|
|
rules: [{
|
|
rules: [{
|
|
required: true,
|
|
required: true,
|
|
- errorMessage: '请输入密码',
|
|
|
|
|
|
+ errorMessage: '请输入验证码',
|
|
}, ]
|
|
}, ]
|
|
},
|
|
},
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ // 微信登陆
|
|
|
|
+ // 无账号
|
|
|
|
+ is_user: false,
|
|
|
|
+ openType: '',
|
|
};
|
|
};
|
|
},
|
|
},
|
|
onShow: function() {
|
|
onShow: function() {
|
|
const that = this;
|
|
const that = this;
|
|
that.search();
|
|
that.search();
|
|
-
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
|
|
+ // 同意隐私协议
|
|
|
|
+ changeAgree() {
|
|
|
|
+ const that = this;
|
|
|
|
+ if (that.agree) that.$set(that, `agree`, false)
|
|
|
|
+ else that.$set(that, `agree`, true);
|
|
|
|
+ },
|
|
|
|
+ // 查看隐私协议
|
|
|
|
+ toAgree() {
|
|
|
|
+ uni.navigateTo({
|
|
|
|
+ url: `/pages/other/agree`
|
|
|
|
+ })
|
|
|
|
+ },
|
|
search() {
|
|
search() {
|
|
const that = this;
|
|
const that = this;
|
|
uni.getStorage({
|
|
uni.getStorage({
|
|
@@ -79,7 +114,9 @@
|
|
config: 'pointApp'
|
|
config: 'pointApp'
|
|
})
|
|
})
|
|
if (aee.errcode == '0') {
|
|
if (aee.errcode == '0') {
|
|
- that.$set(that, `openid`, aee.data.openid)
|
|
|
|
|
|
+ that.$set(that, `openid`, aee.data.openid);
|
|
|
|
+ // 微信登录
|
|
|
|
+ that.openidLogin(aee.data.openid);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fail: function(err) {
|
|
fail: function(err) {
|
|
@@ -90,133 +127,227 @@
|
|
console.log('to do');
|
|
console.log('to do');
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // 账号登录
|
|
|
|
- toSubmit(ref) {
|
|
|
|
- const that = this;
|
|
|
|
- that.$refs[ref].validate().then(async params => {
|
|
|
|
- const res = await that.$api(`/user/login`, 'POST', {
|
|
|
|
- ...params
|
|
|
|
- })
|
|
|
|
- if (res.errcode == '0') {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: '登录成功',
|
|
|
|
- icon: 'success'
|
|
|
|
- });
|
|
|
|
- uni.setStorage({
|
|
|
|
- key: 'token',
|
|
|
|
- data: res.data,
|
|
|
|
- success: function() {
|
|
|
|
- uni.navigateBack({
|
|
|
|
- delta: 1
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- if (res.errcode == '-5') {
|
|
|
|
- // 账号无,注册账号
|
|
|
|
- that.createUser(params);
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.errmsg,
|
|
|
|
- icon: 'none'
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }).catch(err => {
|
|
|
|
- console.log('表单错误信息:', err);
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- // 微信信任登录
|
|
|
|
- wxLogin() {
|
|
|
|
- const that = this;
|
|
|
|
- if (that.platform.uniPlatform == 'mp-weixin') {
|
|
|
|
- that.userLogin({
|
|
|
|
- openid: that.openid
|
|
|
|
- }, '2');
|
|
|
|
- } else if (that.platform.uniPlatform == 'app') {
|
|
|
|
- console.log('app');
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- // 账号登录,无账号,注册账号
|
|
|
|
- async createUser(params) {
|
|
|
|
|
|
+ // 微信登录
|
|
|
|
+ async openidLogin(e) {
|
|
const that = this;
|
|
const that = this;
|
|
- const openid = that.openid;
|
|
|
|
- if (that.platform.uniPlatform == 'mp-weixin') params.openid = openid;
|
|
|
|
- const res = await that.$api(`/user`, 'POST', {
|
|
|
|
- ...params
|
|
|
|
|
|
+ let res = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
|
+ openid: e
|
|
})
|
|
})
|
|
if (res.errcode == '0') {
|
|
if (res.errcode == '0') {
|
|
- that.userLogin(params, '1')
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.errmsg,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- // 微信登录,无账号,微信注册账号
|
|
|
|
- async createwxUser() {
|
|
|
|
- const that = this;
|
|
|
|
- const res = await that.$api(`/user`, 'POST', {
|
|
|
|
- openid: that.openid
|
|
|
|
- })
|
|
|
|
- if (res.errcode == '0') {
|
|
|
|
- that.userLogin({
|
|
|
|
- openid: that.openid
|
|
|
|
- }, '2')
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.errmsg,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- // 用户登录
|
|
|
|
- async userLogin(params, type) {
|
|
|
|
- const that = this;
|
|
|
|
- let res;
|
|
|
|
- if (type == '1') {
|
|
|
|
- res = await that.$api(`/user/login`, 'POST', {
|
|
|
|
- ...params
|
|
|
|
- })
|
|
|
|
- } else if (type == '2') {
|
|
|
|
- res = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
|
- openid: params.openid
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- if (res.errcode == '0') {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: '登录成功',
|
|
|
|
- icon: 'success'
|
|
|
|
- });
|
|
|
|
uni.setStorage({
|
|
uni.setStorage({
|
|
- key: 'token',
|
|
|
|
data: res.data,
|
|
data: res.data,
|
|
|
|
+ key: 'token',
|
|
success: function() {
|
|
success: function() {
|
|
uni.navigateBack({
|
|
uni.navigateBack({
|
|
delta: 1
|
|
delta: 1
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ })
|
|
} else {
|
|
} else {
|
|
if (res.errcode == '-5') {
|
|
if (res.errcode == '-5') {
|
|
- // 账号无,注册账号
|
|
|
|
- that.createwxUser(params);
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.errmsg,
|
|
|
|
- icon: 'none'
|
|
|
|
- });
|
|
|
|
|
|
+ console.log('无账号');
|
|
|
|
+ that.$set(that, `is_user`, false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ // 微信信任登录
|
|
|
|
+ async wxLogin() {
|
|
|
|
+ const that = this;
|
|
|
|
+ if (that.agree) {
|
|
|
|
+ uni.getUserProfile({
|
|
|
|
+ desc: '用于展示',
|
|
|
|
+ success: async function(res) {
|
|
|
|
+ console.log('1');
|
|
|
|
+ let parmas = {
|
|
|
|
+ openid: that.openid,
|
|
|
|
+ icon: [{
|
|
|
|
+ url: res.userInfo.avatarUrl
|
|
|
|
+ }],
|
|
|
|
+ name: res.userInfo.nickName
|
|
|
|
+ }
|
|
|
|
+ const arr = await that.$api(`/user`, 'POST', parmas);
|
|
|
|
+ if (res.errcode == '0') {
|
|
|
|
+ console.log('2');
|
|
|
|
+ const agg = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
|
+ openid: that.openid
|
|
|
|
+ })
|
|
|
|
+ if (agg.errcode == '0') {
|
|
|
|
+ console.log('3');
|
|
|
|
+ uni.setStorage({
|
|
|
|
+ data: res.data,
|
|
|
|
+ key: 'token',
|
|
|
|
+ success: function() {
|
|
|
|
+ uni.navigateBack({
|
|
|
|
+ delta: 1
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: agg.errmsg,
|
|
|
|
+ icon: 'none'
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: res.errmsg,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: function(err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: '请阅读并同意用户协议和隐私政策',
|
|
|
|
+ icon: 'none'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 获取手机号
|
|
|
|
+ getUserPhone(e) {
|
|
|
|
+ console.log('1');
|
|
|
|
+ const that = this;
|
|
|
|
+ },
|
|
}
|
|
}
|
|
|
|
+ // },
|
|
|
|
+ // // 微信信任登录
|
|
|
|
+ // wxLogin() {
|
|
|
|
+ // const that = this;
|
|
|
|
+ // let agree = that.agree;
|
|
|
|
+ // if (agree) {
|
|
|
|
+ // uni.getUserProfile({
|
|
|
|
+ // desc: '用户展示',
|
|
|
|
+ // success: function(res) {
|
|
|
|
+ // uni.login({
|
|
|
|
+ // success: function(resl) {
|
|
|
|
+
|
|
|
|
+ // },
|
|
|
|
+ // fail: function(errl) {
|
|
|
|
+ // console.log(errl);
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // },
|
|
|
|
+ // fail: function(err) {
|
|
|
|
+ // console.log(err);
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // // uni.login({
|
|
|
|
+ // // success: async function(event) {
|
|
|
|
+ // // const res = await that.$api(`/wechat/api/login/app`, 'GET', {
|
|
|
|
+ // // js_code: event.code,
|
|
|
|
+ // // config: 'pointApp'
|
|
|
|
+ // // })
|
|
|
|
+ // // if (res.errcode == '0') {
|
|
|
|
+ // // // 用openid登录
|
|
|
|
+ // // // that.openidLogin(res.data.openid);
|
|
|
|
+ // // let arr = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
|
+ // // openid: res.data.openid
|
|
|
|
+ // // })
|
|
|
|
+ // // if (arr.errcode == '0') {
|
|
|
|
+ // // console.log('登录成功');
|
|
|
|
+ // // } else {
|
|
|
|
+ // // if (arr.errcode == '-5') {
|
|
|
|
+ // // // 去注册
|
|
|
|
+ // // // that.registerWxuser(e);
|
|
|
|
+ // // that.$set(that, `errcode`, arr.errcode)
|
|
|
|
+ // // } else {
|
|
|
|
+ // // uni.showToast({
|
|
|
|
+ // // title: arr.errmsg,
|
|
|
|
+ // // icon: 'none'
|
|
|
|
+ // // })
|
|
|
|
+ // // }
|
|
|
|
+ // // }
|
|
|
|
+ // // } else {
|
|
|
|
+ // // console.log(res);
|
|
|
|
+ // // }
|
|
|
|
+ // // }
|
|
|
|
+ // // })
|
|
|
|
+ // // console.log(that.errcode);
|
|
|
|
+ // // console.log('1');
|
|
|
|
+ // // if (that.errcode == '-5') {
|
|
|
|
+ // // console.log('2');
|
|
|
|
+ // // uni.getUserProfile({
|
|
|
|
+ // // desc: '用户展示',
|
|
|
|
+ // // success: function(res) {
|
|
|
|
+ // // console.log(res);
|
|
|
|
+ // // console.log(e);
|
|
|
|
+ // // },
|
|
|
|
+ // // fail: function(err) {
|
|
|
|
+ // // console.log(err);
|
|
|
|
+ // // }
|
|
|
|
+ // // })
|
|
|
|
+ // // }
|
|
|
|
+
|
|
|
|
+ // } else {
|
|
|
|
+ // uni.showToast({
|
|
|
|
+ // title: '请阅读并同意用户协议和隐私政策',
|
|
|
|
+ // icon: 'none'
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // // openid登录
|
|
|
|
+ // async openidLogin(e) {
|
|
|
|
+ // const that = this;
|
|
|
|
+ // let res = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
|
+ // openid: e
|
|
|
|
+ // })
|
|
|
|
+ // if (res.errcode == '0') {
|
|
|
|
+ // console.log('登录成功');
|
|
|
|
+ // } else {
|
|
|
|
+ // if (res.errcode == '-5') {
|
|
|
|
+ // // 去注册
|
|
|
|
+ // that.registerWxuser(e);
|
|
|
|
+ // } else {
|
|
|
|
+ // uni.showToast({
|
|
|
|
+ // title: res.errmsg,
|
|
|
|
+ // icon: 'none'
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // // wx注册
|
|
|
|
+ // registerWxuser(e) {
|
|
|
|
+ // const that = this;
|
|
|
|
+ // console.log(e);
|
|
|
|
+ // uni.getUserProfile({
|
|
|
|
+ // desc: '用户展示',
|
|
|
|
+ // success: function(res) {
|
|
|
|
+ // console.log(res);
|
|
|
|
+ // console.log(e);
|
|
|
|
+ // },
|
|
|
|
+ // fail: function(err) {
|
|
|
|
+ // console.log(err);
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // },
|
|
|
|
+ // // 账号登录
|
|
|
|
+ // toSubmit(ref) {
|
|
|
|
+ // const that = this;
|
|
|
|
+ // that.$refs[ref].validate().then(async params => {
|
|
|
|
+ // let agree = that.agree;
|
|
|
|
+ // if (agree) {
|
|
|
|
+ // console.log(params);
|
|
|
|
+ // } else {
|
|
|
|
+ // uni.showToast({
|
|
|
|
+ // title: '请阅读并同意用户协议和隐私政策',
|
|
|
|
+ // icon: 'none'
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // }).catch(err => {
|
|
|
|
+ // console.log(err);
|
|
|
|
+ // })
|
|
|
|
+ // },
|
|
|
|
+
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
<style lang="scss">
|
|
.main {
|
|
.main {
|
|
-
|
|
|
|
-
|
|
|
|
- .two {
|
|
|
|
|
|
+ .one {
|
|
padding: 2vw;
|
|
padding: 2vw;
|
|
|
|
|
|
.btn {
|
|
.btn {
|
|
@@ -230,5 +361,36 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ .two {
|
|
|
|
+ text-align: center;
|
|
|
|
+ margin: 20vw 0;
|
|
|
|
+
|
|
|
|
+ .icon {
|
|
|
|
+ margin: 0 0 5vw 0;
|
|
|
|
+
|
|
|
|
+ text {
|
|
|
|
+ font-size: 60px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .btn {
|
|
|
|
+ button {
|
|
|
|
+ background-color: var(--f35BColor);
|
|
|
|
+ color: var(--fffColor);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .thr {
|
|
|
|
+ .thr_1 {
|
|
|
|
+ padding: 0 2vw;
|
|
|
|
+ font-size: 14px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ position: absolute;
|
|
|
|
+ width: 96vw;
|
|
|
|
+ bottom: 25vw;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|