guhongwei 2 jaren geleden
bovenliggende
commit
34703823d7
3 gewijzigde bestanden met toevoegingen van 348 en 126 verwijderingen
  1. 7 3
      common/css/font-icon.css
  2. 59 3
      pages/home/index.vue
  3. 282 120
      pages/login/index.vue

+ 7 - 3
common/css/font-icon.css

@@ -2,9 +2,9 @@
   font-family: "iconfont"; /* Project id 3674157 */
   /* Color fonts */
   src: 
-       url('https://at.alicdn.com/t/c/font_3674157_7xeq9ctlqo6.woff2?t=1664670177625') format('woff2'),
-       url('https://at.alicdn.com/t/c/font_3674157_7xeq9ctlqo6.woff?t=1664670177625') format('woff'),
-       url('https://at.alicdn.com/t/c/font_3674157_7xeq9ctlqo6.ttf?t=1664670177625') format('truetype');
+       url('https://at.alicdn.com/t/c/font_3674157_xhwjdjw85v.woff2?t=1665362884500') format('woff2'),
+       url('https://at.alicdn.com/t/c/font_3674157_xhwjdjw85v.woff?t=1665362884500') format('woff'),
+       url('https://at.alicdn.com/t/c/font_3674157_xhwjdjw85v.ttf?t=1665362884500') format('truetype');
 }
 
 .iconfont {
@@ -15,6 +15,10 @@
   -moz-osx-font-smoothing: grayscale;
 }
 
+.icon-weixin:before {
+  content: "\e73b";
+}
+
 .icon-duihao:before {
   content: "\e684";
 }

+ 59 - 3
pages/home/index.vue

@@ -20,7 +20,7 @@
 						</view>
 					</view>
 				</view>
-				<!-- 	<view class="zero four">
+				<view class="zero four">
 					<view class="recomList" v-for="(item,index) in recomList" :key="index">
 						<view class="list" v-for="(tag,indexs) in item.list" :key="indexs">
 							<view class="title">
@@ -32,7 +32,7 @@
 							</view>
 						</view>
 					</view>
-				</view> -->
+				</view>
 				<view class="zero five">
 					<view class="list" v-for="(item,index) in marketList" :key="index" @tap="toBuy(item)">
 						<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
@@ -44,7 +44,7 @@
 								<text>¥</text><text>{{item.sell_money||'暂无'}}</text>
 							</view>
 							<view class="btn">
-								<button type="default" size="mini">购买</button>
+								<!-- <button type="default" size="mini">购买</button> -->
 							</view>
 						</view>
 					</view>
@@ -73,6 +73,62 @@
 				btnList: [ //功能按钮
 				],
 				recomList: [ //推荐好物
+					{
+						list: [ //商品
+							{
+								title: '新品上架',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+							{
+								title: '',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+						]
+					},
+					{
+						list: [ //商品
+							{
+								title: '发现好货',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+							{
+								title: '热销爆款',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+						]
+					},
+					{
+						list: [ //商品
+							{
+								title: '天恩精选',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+							{
+								title: '居家常备',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+						]
+					},
+					{
+						list: [ //商品
+							{
+								title: '人气单品',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+							{
+								title: '夏季畅销',
+								url: require('@/static/test.png'),
+								name: '商品名称'
+							},
+						]
+					}
 				],
 				marketList: [ //商品列表
 				],

+ 282 - 120
pages/login/index.vue

@@ -1,20 +1,38 @@
 <template>
 	<mobile-frame>
 		<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-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 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>
 					<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>
 				</uni-forms>
 			</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>
 	</mobile-frame>
 </template>
@@ -25,14 +43,16 @@
 			return {
 				// 平台信息
 				platform: {},
+				//openid
 				openid: '',
-				logoUrl: this.$config.logoUrl,
+				// 隐私协议
+				agree: false,
 				form: {},
 				rules: {
 					phone: {
 						rules: [{
 								required: true,
-								errorMessage: '请输入号',
+								errorMessage: '请输入手机号',
 							},
 							{
 								minLength: 11,
@@ -41,21 +61,36 @@
 							}
 						]
 					},
-					password: {
+					code: {
 						rules: [{
 							required: true,
-							errorMessage: '请输入码',
+							errorMessage: '请输入验证码',
 						}, ]
 					},
-				}
+				},
+				// 微信登陆
+				// 无账号
+				is_user: false,
+				openType: '',
 			};
 		},
 		onShow: function() {
 			const that = this;
 			that.search();
-
 		},
 		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() {
 				const that = this;
 				uni.getStorage({
@@ -79,7 +114,9 @@
 								config: 'pointApp'
 							})
 							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) {
@@ -90,133 +127,227 @@
 					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 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') {
-					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({
-						key: 'token',
 						data: res.data,
+						key: 'token',
 						success: function() {
 							uni.navigateBack({
 								delta: 1
 							})
 						}
-					});
+					})
 				} else {
 					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>
 
 <style lang="scss">
 	.main {
-
-
-		.two {
+		.one {
 			padding: 2vw;
 
 			.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>