cmy 5 years ago
parent
commit
f083bdd45b
2 changed files with 96 additions and 45 deletions
  1. 39 0
      libs/log.js
  2. 57 45
      utils/wxAuthorized.js

+ 39 - 0
libs/log.js

@@ -0,0 +1,39 @@
+
+const logLength=100;//缓存存储上限
+const name = 'log';//缓存名字
+export function addLog (data,content='') {
+	let log = uni.getStorageSync(name)||[];
+	log.unshift({
+		title:data,
+		content:content
+	});
+	uni.setStorageSync(name,log);
+	initLog(log);
+}
+
+
+export function delLog () {
+	return uni.setStorageSync(name,'');
+}
+
+export function getLog () {
+	return uni.getStorageSync(name);
+}
+
+export function initLog (log) {
+	if(log.length>logLength){
+		const newarr = log.slice(log.length-logLength);
+		uni.setStorageSync(name,newarr);
+	}
+}
+export function showLog (log) {
+	
+	let str = '';
+	uni.getStorageSync(name).forEach((e) => {
+		str+=e.title+':'+JSON.stringify(e.content)
+	})
+	uni.showModal({
+		title:"日志",
+		content:str
+	})
+}

+ 57 - 45
utils/wxAuthorized.js

@@ -2,6 +2,8 @@ import {
 	wechatConfig,
 	wechatConfig,
 	share
 	share
 } from '@/api/wx';
 } from '@/api/wx';
+// 加载日志
+import * as log from '@/libs/log.js'
 import {
 import {
 	isAndroid
 	isAndroid
 } from './platform.js'
 } from './platform.js'
@@ -33,12 +35,12 @@ export function loginWinxin() {
 	}
 	}
 	// 判断是否在登录页
 	// 判断是否在登录页
 	if (path != 'pages/redirect/redirect') {
 	if (path != 'pages/redirect/redirect') {
-		weixinObj.ready(() => {
+		log.addLog('开始注册微信')
+		weixindata().then(() => {
 			console.log('2');
 			console.log('2');
 			// 调用
 			// 调用
 			try {
 			try {
-				console.log(shareData);
-				weixinSq(shareData, path);
+				weixinSq();
 			} catch (e) {
 			} catch (e) {
 				console.log(e);
 				console.log(e);
 				//TODO handle the exception
 				//TODO handle the exception
@@ -47,7 +49,7 @@ export function loginWinxin() {
 	}
 	}
 };
 };
 // 微信授权登录
 // 微信授权登录
-function weixinSq(data, path) {
+function weixinSq() {
 	// 微信授权后跳转页面
 	// 微信授权后跳转页面
 	try {
 	try {
 		let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/pages/redirect/redirect');
 		let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/pages/redirect/redirect');
@@ -79,52 +81,62 @@ export function weixindata(config) {
 	if (router.mode === "hash") {
 	if (router.mode === "hash") {
 		url = location.href.split('#')[0];
 		url = location.href.split('#')[0];
 	}
 	}
-	//注册微信信息
-	wechatConfig({
-			url
-		})
-		.then(({
-			data
-		}) => {
-			// 保存appId
-			appId = data.appId
-			// 微信信息配置
-			weixinObj.config({
-				debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-				appId: data.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
-				timestamp: data.timestamp, // 必填,生成签名的时间戳
-				nonceStr: data.nonceStr, // 必填,生成签名的随机串
-				signature: data.signature, // 必填,签名,见附录1
-				jsApiList: data.jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
-			});
-			weixinObj.ready((e) => {
-				// 判断有无自定义数据
-				if (config) {
-					shareLoad(config)
-				} else {
-					// 判断是否已经缓存了默认数据
-					if (shareData) {
-						shareLoad()
-					} else {
-						// 请求获取默认数据
-						share({}).then(({
-							data
-						}) => {
-							shareData = data.data
-							shareLoad()
-						});
-					}
-				}
+	log.addLog('注册开始',url)
+	return new Promise((ok, error) => {
+		//注册微信信息
+		wechatConfig({
+				url
 			})
 			})
+			.then(({
+				data
+			}) => {
+				// 保存appId
+				appId = data.appId
+				// 微信信息配置
+				weixinObj.config({
+					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+					appId: data.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
+					timestamp: data.timestamp, // 必填,生成签名的时间戳
+					nonceStr: data.nonceStr, // 必填,生成签名的随机串
+					signature: data.signature, // 必填,签名,见附录1
+					jsApiList: data.jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
+				});
+				weixinObj.ready((e) => {
+					ok(data)
+				})
 
 
-		})
-		.catch(e => {
-			console.log(e);
-		});
+			})
+			.catch(e => {
+				error(e);
+				console.log(e);
+			});
+	})
 }
 }
 
 
-// 加载分享数据
+// 判断分享调用方法
 function shareLoad(config) {
 function shareLoad(config) {
+	weixindata().then((e) => {
+		// 判断有无自定义数据
+		if (config) {
+			shareFun(config)
+		} else {
+			// 判断是否已经缓存了默认数据
+			if (shareData) {
+				shareFun()
+			} else {
+				// 请求获取默认数据
+				share({}).then(({
+					data
+				}) => {
+					shareData = data.data
+					shareFun()
+				});
+			}
+		}
+	})
+}
+// 配置分享数据
+function shareFun(config) {
 	let mess;
 	let mess;
 	if (config) {
 	if (config) {
 		mess = {
 		mess = {