liujd 6 лет назад
Родитель
Сommit
20d983ef31

+ 2 - 2
mobile-code/src/App.vue

@@ -1,7 +1,7 @@
 <script>
 import { mapMutations, mapActions, mapGetters } from 'vuex'
 import { setTimeout } from 'timers'
-import { getCheckLogin, getUser } from '@/utils/auth'
+import { getCheckLogin, getUser, wxLoginFn } from '@/utils/auth'
 export default {
 	// 全端,数据共享,还可以解决页面初始化模板访问不到值得问题
 	// 有坑 分包里的页面访问不到
@@ -10,7 +10,7 @@ export default {
 	onLaunch() {
 		// this.getAllOptions()
 		// #ifdef MP-WEIXIN
-		// wxLoginFn()
+		wxLoginFn()
 		// #endif
 		// 开发
 		uni.setStorageSync('token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjFfMTI1MzY2MzAifQ.eyJpc3MiOiJodHRwOlwvXC9tLmhoYi5jb20iLCJhdWQiOiJodHRwOlwvXC9tLmhoYi5jb20iLCJqdGkiOiIxXzEyNTM2NjMwIiwiaWF0IjoxNTc0NDIzMDc4LCJuYmYiOjE1NzQ0MjMwNzgsImV4cCI6MTU3NDQyNjY3OCwidXNlcklkIjoxMjUzNjYzMH0.v_T9NuFRpzuI7GtwuuuNlVg6EylImaCUwqo2A6NRTE4')

+ 22 - 0
mobile-code/src/api/mini/index.js

@@ -0,0 +1,22 @@
+import https from '@/plugins/luch-request_0.0.7/request'
+
+/** *
+ * 静默获取用户信息 mini
+ */
+export const postWxCode = data => {
+	return https.get('/auth/mini-info', data)
+}
+
+/** *
+ * 点击授权获取用户信息 mini
+ */
+export const getWxInfo = data => {
+	return https.post('/user/mini-full-info', data)
+}
+
+/** *
+ * 点击授权获取手机号 mini
+ */
+export const getWxPhone = data => {
+	return https.post('/user/mini-mobile', data)
+}

+ 1 - 1
mobile-code/src/manifest.json

@@ -10,7 +10,7 @@
         "request":200000
     },
     "mp-weixin" : {
-        "appid" : "wx3a163add860e0a86",
+        "appid" : "wxe4675bab299a52f7",
         "setting" : {
             "urlCheck" : false
         },

+ 1 - 1
mobile-code/src/pages/common/redirect.vue

@@ -10,7 +10,7 @@ export default {
 		}
 	},
 	computed: {
-		...mapGetters({ userInfo: 'getSelfInfo' })
+		// ...mapGetters({ userInfo: 'getSelfInfo' })
 	},
 	onLoad(options) {
 		uni.showLoading({

+ 2 - 2
mobile-code/src/pages/common/webview.vue

@@ -4,7 +4,7 @@
 
 <script>
 import { mapGetters } from 'vuex'
-import { getSelfInfo } from '@/utils/auth'
+// import { getSelfInfo } from '@/utils/auth'
 
 export default {
 	data() {
@@ -14,7 +14,7 @@ export default {
 		}
 	},
 	computed: {
-		...mapGetters({ userInfo: 'getSelfInfo' })
+		// ...mapGetters({ userInfo: 'getSelfInfo' })
 	},
 	onLoad(option) {
 	},

+ 5 - 5
mobile-code/src/pages/home/category.vue

@@ -9,16 +9,16 @@
 			<scroll-view scroll-y class="right-box" :style="{height:height+'px'}" v-if="currentTab==index">
 				<!--内容部分 start -->
 				<div class="page-view" v-if="!$util.isEmpty(list.data)">
-					<div class="goods-list" v-for="(item, index) in list.data" :key="index" @click="$util.pageTo(`/pages/goods/detail?id=${item.id}`)">
+					<div class="goods-list" v-for="(items, subIndex) in list.data" :key="items.id" @click="$util.pageTo(`/pages/goods/detail?id=${items.id}`)">
 						<div class="img-blo">
-							<app-img :src="item.smallImgList[0]" alt="商品图" mode="aspectFit" :height="200" />
+							<app-img :src="items.smallImgList[0]" alt="商品图" mode="aspectFit" :height="200" />
 						</div>
 						<div class="goods-det">
 							<div class="goods-det-top">
-								<div class="goods-name">{{ item.goodsName }}</div>
-								<div class="goods-sales">已售{{ item.sold }}</div>
+								<div class="goods-name">{{ items.goodsName }}</div>
+								<div class="goods-sales">已售{{ items.sold }}</div>
 							</div>
-							<div class="goods-price">¥{{ item.price }}</div>
+							<div class="goods-price">¥{{ items.price }}</div>
 						</div>
 					</div>
 				</div>

+ 37 - 5
mobile-code/src/pages/home/components/login-popup.vue

@@ -2,17 +2,26 @@
 	<bottom-popup class="popup-wrap" :show="show" @close="hidePopup">
 		<app-close @close="hidePopup" />
 		<div class="popup-content">
+			<!-- #ifdef MP-WEIXIN -->
 			<div class="step-wrap">
 				<app-step :index="stepIndex" />
 			</div>
+			<!-- #endif -->
 			<!-- 获取手机号 -->
 			<template v-if="stepIndex == 0">
 				<div class="popup-attr-wrap">
-					<img :src="`${constant.imgUrl}/retail/user/attr-default.png`" alt />
+					<img :src="`${constant.imgUrl}/retail/user/attr-default.png`" mode="widthFix" alt />
 				</div>
+				<!-- #ifdef H5 -->
 				<div class="creat-account-btn">
-					<button class="button-com red big">点击创建头像</button>
+					<button class="button-com red big" @click="registerFn">点击授权登录</button>
 				</div>
+				<!-- #endif -->
+				<!-- #ifdef MP-WEIXIN -->
+				<div class="creat-account-btn">
+					<button class="button-com red big mini-btn" open-type="getUserInfo" @getuserinfo="getWxAvatar" :plain="true">点击创建头像</button>
+				</div>
+				<!-- #endif -->
 			</template>
 			<!-- 注册完成 -->
 			<template v-if="stepIndex == 1">
@@ -23,7 +32,7 @@
 					<div class="phone-num font-bold">13285979347</div>
 				</div>
 				<div class="creat-account-btn">
-					<button class="button-com red big">点击创建头像</button>
+					<button class="button-com red big mini-btn" open-type="getPhoneNumber" @getphonenumber="getWxMobile" :plain="true">点击创建头像</button>
 				</div>
 			</template>
 			<!-- 关注公众号 -->
@@ -33,7 +42,7 @@
 					<div class="flex-center-between">
 						<div class="wx-public-left">
 							<div class="wx-public-img">
-								<img :src="`${constant.imgUrl}/retail/user/attr-default.png`" alt />
+								<img :src="`${constant.imgUrl}/retail/user/attr-default.png`" mode="widthFix" alt />
 							</div>
 							<div class="wx-public-det">
 								<div class="wx-public-tit">国兰华尚</div>
@@ -52,6 +61,9 @@
 import AppStep from '@/components/app-step'
 import BottomPopup from '@/components/plugin/bottom-popup'
 import AppClose from '@/components/module/app-close'
+// api
+import { getCheckLogin, getUser } from '@/utils/auth'
+import { getWxPhone } from '@/api/mini'
 export default {
 	name: 'login-popup-module',
 	components: {
@@ -62,11 +74,15 @@ export default {
 	props: {
 		stepIndex: {
 			type: Number,
-			default: 0
+			default: 1
 		},
 		show: {
 			type: Boolean,
 			default: false
+		},
+		info: {
+			type: Object,
+			default: () => {}
 		}
 	},
 	data() {
@@ -77,6 +93,19 @@ export default {
 	methods: {
 		hidePopup() {
 			this.$emit('hide')
+		},
+		registerFn() {
+			getCheckLogin()
+		},
+		getWxMobile(e) {
+			console.log(e)
+			if (e.detail.errMsg === 'getPhoneNumber:ok') {
+				getWxPhone({ iv: e.detail.iv, encryptData: e.detail.encryptedData }).then(res => {
+					console.log('用户信息', res)
+				})
+			} else {
+				this.$msg('获取信息失败!')
+			}
 		}
 	}
 }
@@ -85,6 +114,9 @@ export default {
 <style lang='scss' scoped>
 	// 弹窗
 	.popup-wrap {
+		.mini-btn {
+			border: none !important;
+		}
 		/deep/.tui-popup-class {
 			border-top-left-radius: 20px;
 			border-top-right-radius: 20px;

+ 1 - 1
mobile-code/src/pages/home/shop.vue

@@ -10,7 +10,7 @@
 				<tui-list-cell :lineLeft="false" :lineRight="false" class="tui-list">
 					<div class="list-wrap">
 						<div class="list-label">营业时间</div>
-						<div class="list-val">{{ shop.openTime }}</div>
+						<div class="list-val">{{ shop.openTime || '暂无' }}</div>
 					</div>
 				</tui-list-cell>
 				<tui-list-cell @click="phoneCall" :lineLeft="false" :lineRight="false" class="tui-list">

+ 47 - 15
mobile-code/src/pages/home/user.vue

@@ -7,7 +7,12 @@
 					<img :src="`${constant.imgUrl}/retail/user/attr-default.png`" alt mode="widthFix" />
 				</div>
 				<div class="button-wrap">
+					<!-- #ifdef H5 -->
 					<button class="button-com" @click="showPopup">申请会员</button>
+					<!-- #endif -->
+					<!-- #ifdef MP-WEIXIN -->
+					<button class="button-com mini-btn" open-type="getUserInfo" @getuserinfo="getWxAvatar">申请会员</button>
+					<!-- #endif -->
 				</div>
 			</template>
 			<!-- 已登录 -->
@@ -19,12 +24,12 @@
 							<div class="user-level">
 								<!-- <div class="user-level-icon">
 									<img src="" alt />
-								</div> -->
+								</div>-->
 								<div>成长值 {{ shopUser.userAsset.growth }}/{{ shopUser.userAsset.nextLevelGrowth }}</div>
 							</div>
 						</div>
 						<div class="user-blo-right login-attr-wrap">
-							<img :src="shopUser.smallAvatarUrl | default_avatar" alt="头像" />
+							<img :src="shopUser.smallAvatarUrl | default_avatar" alt="头像" mode="widthFix" />
 						</div>
 					</div>
 					<div class="user-wrap-bottom">
@@ -34,26 +39,28 @@
 				</div>
 			</template>
 		</div>
-		<div class="surplus-wrap">
-			<div class="surplus-left">
-				<div>我的余额(¥)</div>
-				<div class="my-surplus">{{ shopUser.userAsset.balance || 0.00 }}</div>
-			</div>
-			<div class="surplus-right">
-				<button class="button-com" @click="$util.pageTo({
+		<template v-if="!$util.isEmpty(shopUser)">
+			<div class="surplus-wrap">
+				<div class="surplus-left">
+					<div>我的余额(¥)</div>
+					<div class="my-surplus">{{ shopUser.userAsset.balance || 0.00 }}</div>
+				</div>
+				<div class="surplus-right">
+					<button class="button-com" @click="$util.pageTo({
 					url: '/pages/pay/index',
 					query: {
 						pageStatus: 'recharge'
 					}
 				})">充值</button>
-				<button class="button-com red" @click="$util.pageTo({
+					<button class="button-com red" @click="$util.pageTo({
 					url: '/pages/pay/index',
 					query: {
 						pageStatus: 'payment'
 					}
 				})">付款</button>
+				</div>
 			</div>
-		</div>
+		</template>
 		<div class="list-content">
 			<tui-list-view class="tui-list-view">
 				<tui-list-cell class="tui-list" :arrow="true" @click="$util.pageTo('/pages/order/list')">
@@ -95,7 +102,7 @@
 			</tui-list-view>
 		</div>
 		<!-- 登录弹窗 -->
-		<login-popup :show="popupShow" @hide="hidePopup" />
+		<login-popup :show="popupShow" :info="wxInfo" @hide="hidePopup" />
 		<!-- 登录弹窗 -->
 		<app-trademark />
 		<!-- <app-footer :activeIndex="3" /> -->
@@ -110,7 +117,8 @@ import TuiListCell from '@/components/plugin/list-cell'
 import LoginPopup from '@/pages/home/components/login-popup'
 import AppTrademark from '@/components/module/app-trademark'
 // api
-import { getShopUser } from '@/utils/auth'
+import { getShopUser, getCheckLogin } from '@/utils/auth'
+import { getWxInfo, getWxPhone } from '@/api/mini'
 export default {
 	name: 'user',
 	components: {
@@ -124,7 +132,8 @@ export default {
 		return {
 			constant: this.$constant,
 			popupShow: false,
-			stepIndex: 0
+			stepIndex: 0,
+			wxInfo: {}
 		}
 	},
 	computed: {
@@ -138,7 +147,8 @@ export default {
 			getShopUser()
 		},
 		showPopup() {
-			this.popupShow = true
+			// this.popupShow = true
+			getCheckLogin()
 		},
 		hidePopup() {
 			this.popupShow = false
@@ -150,6 +160,24 @@ export default {
 			// #endif
 			// #ifndef H5
 			// #endif
+		},
+		// 获取微信信息
+		getWxAvatar() {
+			uni.getUserInfo({
+				provider: 'weixin',
+				success: res => {
+					console.log('res', res)
+					this.popupShow = true
+					getWxInfo({ iv: res.iv, encryptData: res.encryptedData }).then(subRes => {
+						console.log('用户信息', subRes)
+						this.wxInfo = subRes
+						this.popupShow = true
+					})
+				},
+				fail: () => {
+					// this.loading = false
+				}
+			})
 		}
 	}
 }
@@ -211,6 +239,10 @@ export default {
 		}
 		.button-wrap {
 			@include disFlex(center, center);
+
+			.mini-btn {
+				border: none !important;
+			}
 		}
 	}
 	.surplus-wrap {

+ 7 - 6
mobile-code/src/store/modules/user.js

@@ -12,12 +12,13 @@ const getters = {
 	// 员工用户信息
 	getSelfInfo: (state) => {
 		getState(state, 'selfInfo', 'selfInfo')
-		if (state.selfInfo) return state.selfInfo
-		let data = {}
-		getSelfInfo().then(res => {
-			data = res
-		})
-		return data
+		// if (state.selfInfo) return state.selfInfo
+		// let data = {}
+		// getSelfInfo().then(res => {
+		// 	data = res
+		// })
+		// return data
+		return state.selfInfo
 	},
 	// 用户信息
 	getUser: (state) => {

+ 28 - 51
mobile-code/src/utils/auth.js

@@ -12,7 +12,7 @@ import {
 	getShopUserApi
 	// checkLogin,
 } from '@/api/common'
-// import { postWxCode } from '@/api/login'
+import { postWxCode } from '@/api/mini'
 
 import util from './util'
 /**
@@ -104,58 +104,35 @@ export async function getSelfInfo(update) {
  * 微信登陆
  * @parmas update为true时会重新触发请求,重置vuex的数据
  */
-// let wxLoginFrist = true
 export async function wxLoginFn(update) {
-// 	// let params = {
-// 	// 	appid: 'wxad348eb41eda2363',
-// 	// 	redirect_uri: encodeURI('https://www.meijiabang.com'),
-// 	// 	response_type: 'code',
-// 	// 	scope: 'snsapi_base'
-// 	// }
-// 	// let oauthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
-// 	// console.log(oauthUrl)
-// 	// window.location.href = oauthUrl
-// 	// uni.redirectTo({
-// 	// 	url: `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
-// 	// })
-// 	// share.methods.getWeiXinOptin()
-// 	return false
-// 	let dataInfo = null
-// 	let loginInfo = store.state.login.loginInfo
-// 	if (!util.isEmpty(loginInfo) && !update) {
-// 		return loginInfo
-// 	}
+	let dataInfo = null
+	let loginInfo = store.state.login.loginInfo
+	if (!util.isEmpty(loginInfo) && !update) {
+		return loginInfo
+	}
+
+	let getObj = await new Promise(resolve => {
+		uni.login({
+			provider: 'weixin',
+			success: res => {
+				uni.setStorageSync('code', res.code)
+				console.log(res.code, 'res.code')
+				resolve(res)
+			}
+		})
+	})
+
+	await postWxCode({ code: getObj.code }).then(subRes => {
+		const { openid, session_key, unionid } = subRes.data
+		dataInfo = subRes.data
+		store.commit('setLoginInfo', {
+			openid,
+			session_key,
+			unionid
+		  })
+	})
 
-	// 	// #ifdef H5
-	// 	jweixin.ready(function() {
-
-	// 	})
-	// 	// #endif
-	// 	// // #ifdef MP-WEIXIN
-	// 	// wxLoginFrist = false
-	// 	let getObj = await new Promise(resolve => {
-	// 		uni.login({
-	// 			provider: 'weixin',
-	// 			success: res => {
-	// 				uni.setStorageSync('code', res.code)
-	// 				console.log(res.code, 'res.code')
-	// 				resolve(res)
-	// 			}
-	// 		})
-	// 	})
-	// 	// // #endif
-
-	// 	await postWxCode({ code: getObj.code }).then(subRes => {
-	// 		const { openid, session_key, unionid } = subRes.data
-	// 		dataInfo = subRes.data
-	// 		store.commit('setLoginInfo', {
-	// 			openid,
-	// 			session_key,
-	// 			unionid
-	// 		  })
-	// 	})
-
-// 	return dataInfo
+	return dataInfo
 }
 
 /**