xuhaolan 3 years ago
parent
commit
742962cf31
4 changed files with 90 additions and 29 deletions
  1. 6 6
      pages.json
  2. 45 16
      pages/redirect/redirect.vue
  3. 1 1
      store/index.js
  4. 38 6
      utils/wxAuthorized.js

+ 6 - 6
pages.json

@@ -472,12 +472,12 @@
 				"selectedIconPath": "static/tabBar/tab-cate-current.png",
 				"text": "分类"
 			},
-			{
-				"pagePath": "pages/story/story",
-				"iconPath": "static/tabBar/tab-store.png",
-				"selectedIconPath": "static/tabBar/tab-store-current.png",
-				"text": "品牌故事"
-			},
+			// {
+			// 	"pagePath": "pages/story/story",
+			// 	"iconPath": "static/tabBar/tab-store.png",
+			// 	"selectedIconPath": "static/tabBar/tab-store-current.png",
+			// 	"text": "品牌故事"
+			// },
 			{
 				"pagePath": "pages/cart/cart",
 				"iconPath": "static/tabBar/tab-cart.png",

+ 45 - 16
pages/redirect/redirect.vue

@@ -13,7 +13,7 @@ import { wechatMpAuth } from '@/api/wx';
 // #endif
 export default {
 	computed: {
-		...mapState('user',['urlFile'])
+		...mapState(['urlFile'])
 	},
 	onLoad(option) {
 		let obj = this;
@@ -32,10 +32,8 @@ export default {
 			let obj = this;
 			let url = window.location.href;
 			let code = url.match(/code=([0-9]|[a-z]|[A-Z])*/g)[0].replace('code=', '');
-			let spread = uni.getStorageSync('spread')||'';
 			wechatAuth({
 				code: code,
-				spread:spread,
 			}).then(({ data }) => {
 				obj.wchatAuth(data);
 			}).catch((e) => {
@@ -95,19 +93,50 @@ export default {
 				if (ur=='pages/product/product') {
 					ur = '/pages/index/index'
 				}
-				uni.switchTab({
-					url: ur,
-					fail(e) {
-						uni.navigateTo({
-							url: ur,
-							fail(e) {
-								uni.navigateTo({
-									url: '/pages/index/index',
-								});
-							}
-						});
-					}
-				});
+				if (e.data.phone) {
+					uni.switchTab({
+						url: ur,
+						fail(e) {
+							console.log(e);
+							uni.navigateTo({
+								url: ur,
+								fail(e) {
+									console.log(e);
+									uni.switchTab({
+										url: '/pages/index/index'
+									});
+								}
+							});
+						}
+					});
+				} else {
+					uni.showModal({
+						title: '提示',
+						content: '请先绑定手机号',
+						showCancel: false,
+						success: res => {
+							uni.navigateTo({
+								url: '/pages/set/phone'
+							});
+						},
+						fail(e) {
+							console.log(e);
+						}
+					});
+				}
+				// uni.switchTab({
+				// 	url: ur,
+				// 	fail(e) {
+				// 		uni.navigateTo({
+				// 			url: ur,
+				// 			fail(e) {
+				// 				uni.navigateTo({
+				// 					url: '/pages/index/index',
+				// 				});
+				// 			}
+				// 		});
+				// 	}
+				// });
 			}).catch((e) => {
 				uni.showModal({
 					title: '错误',

+ 1 - 1
store/index.js

@@ -6,7 +6,7 @@ Vue.use(Vuex)
 const store = new Vuex.Store({
 	namespaced: true,
 	state: {
-		baseURL:'http://shop.zhengyjk1994.com',//请求地址配置 
+		baseURL:'http://www.plhl918.com/',//请求地址配置 
 		// baseURL:'http://po.frp.liuniu946.com',//请求地址配置
 		urlFile:'/index',//项目部署所在文件夹
 		userInfo: {}, //登录信息

+ 38 - 6
utils/wxAuthorized.js

@@ -20,9 +20,12 @@ let router = '';
 /**
  * @param {string} 当前页面地址信息
  */
-export function loginWinxin() {
+export async function loginWinxin() {
 	console.log('1');
 	let pages, page, path;
+	if (!router) {
+		router = await setRouter();
+	}
 	try {
 		pages = getCurrentPages();
 		// 获取跳转前页面
@@ -37,7 +40,6 @@ export function loginWinxin() {
 	if (path != 'pages/redirect/redirect') {
 		log.addLog('开始注册微信')
 		weixindata().then(() => {
-			console.log('2');
 			// 调用
 			try {
 				weixinSq();
@@ -53,8 +55,15 @@ function weixinSq() {
 	// 微信授权后跳转页面
 	try {
 		// 判断是否真实路由模式
+
+		// const type = router.mode === "history"?'':'/#'
+		// let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile +type+ '/pages/redirect/redirect');
+		// let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/#/pages/redirect/redirect');
+
 		const type = router.mode === "history"?'':'/#'
+		console.log(type)
 		let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile +type+ '/pages/redirect/redirect');
+
 		// 打开微信授权页面
 		let url =
 			'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
@@ -72,12 +81,16 @@ function weixinSq() {
 };
 
 // 微信注册
-export function weixindata(config) {
+export async function weixindata(config) {
 	let url;
 	try {
+		// 判断是否存在router
+		if (!router) {
+			router = await setRouter();
+		}
 		if (router.mode === "history") {
 			// 在ios中时候注册为微信刚进入时候的页面
-			if (window.entryUrl === '') {
+			if (!window.entryUrl) {
 				window.entryUrl = location.href.split('#')[0]
 			}
 			url = isAndroid() ? location.href.split('#')[0] : window.entryUrl;
@@ -115,7 +128,9 @@ export function weixindata(config) {
 						weixinObj.ready((e) => {
 							log.addLog("注册完毕", data)
 							console.log('注册完毕');
-							ok(data)
+							store.commit('setWeiChatObj', weixinObj)
+							ok(weixinObj)
+							// ok(data)
 						})
 					} catch (e) {
 						console.log(e)
@@ -216,7 +231,24 @@ function shareFun(config) {
 
 // 保存路由对象
 export function setRouter(route) {
-	router = route
+	return new Promise((ok, err) => {
+		router = getApp().$router;
+		console.log(router,'开始数据');
+		if (!router) {
+			const set = setInterval(() => {
+				router = getApp().$router;
+				console.log(router,'返回数据');
+				if (router) {
+					console.log(router,'结束');
+					clearInterval(set)
+					ok(router)
+				}
+			}, 100);
+		}else{
+			console.log(router,'成功');
+			ok(router)
+		}
+	})
 }
 
 export default {