guhongwei il y a 2 ans
Parent
commit
e086ff33e9
2 fichiers modifiés avec 219 ajouts et 53 suppressions
  1. 214 42
      pages/login/index.vue
  2. 5 11
      pagesHome/shop/index.vue

+ 214 - 42
pages/login/index.vue

@@ -2,24 +2,42 @@
 	<mobile-frame>
 		<view class="main">
 			<view class="one" v-if="platform.uniPlatform=='app'">
-				<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>
-					<uni-forms-item label="验证码" name="code">
-						<view class="yzm">
-							<view class="l">
-								<uni-easyinput type="text" v-model="form.code" placeholder="请输入手机验证码" />
-							</view>
-							<view class="r">
-								<button type="default" size="mini" @tap.stop="sendCount">{{time_count==0?'验证码':time_count}}</button>
+				<view class="one_2">
+					<uni-data-checkbox mode="tag" v-model="loginType" :localdata="loginTypeList" @change="logintypeChange"></uni-data-checkbox>
+				</view>
+				<view class="one_3" v-if="loginType==0">
+					<uni-forms ref="codeForm" :rules="codeRules" :model="codeForm" label-width="auto">
+						<uni-forms-item label="手机号" name="phone">
+							<uni-easyinput type="number" v-model="codeForm.phone" placeholder="请输入手机号" />
+						</uni-forms-item>
+						<uni-forms-item label="验证码" name="code">
+							<view class="yzm">
+								<view class="l">
+									<uni-easyinput type="text" v-model="codeForm.code" placeholder="请输入手机验证码" />
+								</view>
+								<view class="r">
+									<button type="default" size="mini" @tap.stop="appsendCount">{{time_count==0?'验证码':time_count}}</button>
+								</view>
 							</view>
+						</uni-forms-item>
+						<view class="btn">
+							<button type="default" size="mini" @click="codeSubmit('codeForm')">提交登录</button>
+						</view>
+					</uni-forms>
+				</view>
+				<view class="one_4" v-else-if="loginType==1">
+					<uni-forms ref="accountForm" :rules="accountRules" :model="accountForm" label-width="auto">
+						<uni-forms-item label="手机号" name="phone">
+							<uni-easyinput type="number" v-model="accountForm.phone" placeholder="请输入手机号" />
+						</uni-forms-item>
+						<uni-forms-item label="登录密码" name="password">
+							<uni-easyinput type="number" v-model="accountForm.password" placeholder="请输入登录密码" />
+						</uni-forms-item>
+						<view class="btn">
+							<button type="default" size="mini" @click="accountSubmit('accountForm')">提交登录</button>
 						</view>
-					</uni-forms-item>
-					<view class="btn">
-						<button type="default" size="mini" @click="toSubmit('form')">提交登录</button>
-					</view>
-				</uni-forms>
+					</uni-forms>
+				</view>
 			</view>
 			<view class="two" v-else-if="platform.uniPlatform=='mp-weixin'">
 				<view class="icon">
@@ -77,16 +95,31 @@
 	export default {
 		data() {
 			return {
+				point_title: this.$config.point_title,
 				// 平台信息
 				platform: {},
 				//openid
 				openid: '',
 				// 隐私协议
 				agree: false,
-				form: {},
-				rules: {
+				// app-start
+				loginType: 0,
+				// 短信登录
+				loginTypeList: [ //
+					{
+						"value": 0,
+						"text": "短信登录"
+					}, {
+						"value": 1,
+						"text": "密码登录"
+					},
+				],
+				// 验证码登录
+				codeForm: {},
+				codeRules: {
 					phone: {
-						rules: [{
+						rules: [ //
+							{
 								required: true,
 								errorMessage: '请输入手机号',
 							},
@@ -98,12 +131,40 @@
 						]
 					},
 					code: {
-						rules: [{
-							required: true,
-							errorMessage: '请输入验证码',
-						}, ]
+						rules: [ //
+							{
+								required: true,
+								errorMessage: '请输入短信验证码',
+							}
+						]
+					}
+				},
+				// 密码登录
+				accountForm: {},
+				accountRules: {
+					phone: {
+						rules: [ //
+							{
+								required: true,
+								errorMessage: '请输入手机号',
+							},
+							{
+								minLength: 11,
+								maxLength: 11,
+								errorMessage: '账号长度在{maxLength}个字符',
+							}
+						]
 					},
+					password: {
+						rules: [ //
+							{
+								required: true,
+								errorMessage: '请输入登录密码',
+							}
+						]
+					}
 				},
+				// app-end
 				// 微信登陆
 				// 无账号
 				is_user: false,
@@ -283,17 +344,27 @@
 			},
 			// 短信验证
 			// 获取验证码
-			sendCount() {
+			async sendCount() {
 				const that = this;
+				let user = this.user;
 				let form = that.form && that.form.phone ? that.form : that.phoneForm;
 				if (form && form.phone) {
-					let time_count = 60;
-					uni.showToast({
-						title: '发送成功',
-						icon: 'none'
-					});
-					that.$set(that, `time_count`, time_count);
-					that.timeDown();
+					let res = await that.$api(`/user/toBindPhone`, 'POST', {
+						id: user._id,
+						phone: form.phone
+					})
+					if (res.errcode == '0') {
+						uni.showToast({
+							title: '发送成功'
+						})
+						that.$set(that, `time_count`, 60);
+						that.timeDown();
+					} else {
+						uni.showToast({
+							title: res.errmsg,
+							icon: 'none'
+						})
+					}
 				} else {
 					uni.showToast({
 						title: '输入错误,请重新输入!',
@@ -321,12 +392,30 @@
 					if (form.type == '0') {
 						if (form && form.phone) that.updatePhone(form.phone);
 					} else if (form.type == '1') {
-						let code = '1234';
-						if (form.code == code) {
-							if (form && form.phone) that.updatePhone(form.phone);
+						const res = await that.$api(`/user/checkBindPhone`, 'POST', {
+							id: user._id,
+							code: form.code,
+							phone: form.phone
+						});
+						if (res.errcode == '0') {
+							const arr = await that.$api(`/user/${user._id}`, 'POST', {
+								phone: form.phone
+							});
+							if (arr.errcode == '0') {
+								uni.showToast({
+									title: '绑定手机号成功',
+									icon: 'none'
+								})
+								that.wxLogins();
+							} else {
+								uni.showToast({
+									title: arr.errmsg,
+									icon: 'none'
+								})
+							}
 						} else {
 							uni.showToast({
-								title: '短信验证失败,请重新输入!',
+								title: res.errmsg,
 								icon: 'none'
 							})
 						}
@@ -355,24 +444,101 @@
 					that.wxLogins();
 				}
 			},
+			// 账号登录-start
+			// 选择登录类型
+			logintypeChange(e) {
+				const that = this;
+				that.$set(that, `loginType`, e.detail.value)
+			},
+			// 验证码登录
+			async appsendCount() {
+				const that = this;
+				let form = that.codeForm;
+				if (form && form.phone) {
+					let res = await that.$api(`/user/toLoginByCode`, 'POST', {
+						phone: form.phone
+					})
+					console.log(res);
+					if (res.errcode == '0') {
+						uni.showToast({
+							title: '发送成功'
+						})
+						that.$set(that, `time_count`, 60);
+						that.timeDown();
+					} else {
+						uni.showToast({
+							title: res.errmsg,
+							icon: 'none'
+						})
+					}
+				} else {
+					uni.showToast({
+						title: '输入错误,请重新输入!',
+						icon: 'none'
+					})
+				}
+			},
+			codeSubmit(ref) {
+				const that = this;
+				let agree = that.agree;
+				that.$refs[ref].validate().then(async params => {
+					if (agree) {
+						const res = await that.$api(`/user/checkLoginCode`, 'POST', params);
+						if (res.errcode == '0') {
+							uni.setStorage({
+								key: 'token',
+								data: res.data,
+								success: function() {
+									uni.navigateBack({
+										delta: 1
+									})
+								}
+							});
+						} else {
+							uni.showToast({
+								title: res.errmsg,
+								icon: 'none'
+							})
+						}
+					} else {
+						uni.showToast({
+							title: '请阅读并同意用户协议和隐私政策',
+							icon: 'none'
+						})
+					}
+
+				}).catch(err => {
+					console.log(err);
+				})
+			},
 			// 账号登录
-			toSubmit(ref) {
+			accountSubmit(ref) {
 				const that = this;
 				let agree = that.agree;
 				that.$refs[ref].validate().then(async params => {
-					let code = '1234';
-					if (params.code == code) {
-						if (agree) {
-							console.log(params);
+					if (agree) {
+						const res = await that.$api(`/user/login`, 'POST', {
+							...params
+						})
+						if (res.errcode == '0') {
+							uni.setStorage({
+								key: 'token',
+								data: res.data,
+								success: function() {
+									uni.navigateBack({
+										delta: 1
+									})
+								}
+							});
 						} else {
 							uni.showToast({
-								title: '请阅读并同意用户协议和隐私政策',
+								title: res.errmsg,
 								icon: 'none'
 							})
 						}
 					} else {
 						uni.showToast({
-							title: '验证码错误',
+							title: '请阅读并同意用户协议和隐私政策',
 							icon: 'none'
 						})
 					}
@@ -380,6 +546,7 @@
 					console.log(err);
 				})
 			},
+			// 账号登录-end
 			// 同意隐私协议
 			changeAgree() {
 				const that = this;
@@ -401,6 +568,11 @@
 		.one {
 			padding: 2vw;
 
+			.one_2 {
+				margin: 4vw 22vw;
+				text-align: center;
+			}
+
 			.btn {
 				text-align: center;
 				margin: 0 0 2vw 0;

+ 5 - 11
pagesHome/shop/index.vue

@@ -205,20 +205,15 @@
 			};
 		},
 		onLoad: async function(e) {
+			console.log(e);
 			const that = this;
-			that.$set(that, `id`, e.id || '');
+			that.$set(that, `id`, e.id || '6333d71d32c5f69745f9bd32');
 			await that.watchLogin();
 			await that.search();
 			await that.searchOther();
 		},
 		onShow: function() {},
 		methods: {
-			qrR(res) {
-				this.src = res
-			},
-			saveQrcode() {
-				this.$refs.qrcode._saveCode()
-			},
 			// 监听用户是否登录
 			watchLogin() {
 				const that = this;
@@ -250,7 +245,7 @@
 					// 查询全部商品
 					that.searchAll();
 					// 创建二维码
-					that.createQrcode(that.info);
+					that.createQrcode();
 				}
 			},
 			// 查询店铺商品
@@ -286,10 +281,9 @@
 				}
 			},
 			// 创建二维码
-			createQrcode(e) {
-				// console.log(e);
+			createQrcode() {
 				const that = this;
-				const url = `${that.$config.serverUrl}/shopinfo?id=${e._id}`;
+				const url = `${that.$config.serverUrl}/shopinfo?id=${that.id}`;
 				var qrcode = new QRCode(`myQrcode`, {
 					text: url,
 					width: 110,