Просмотр исходного кода

app 打开微信小程序 -- 补识别是否安装微信软件

shizhongqi 4 лет назад
Родитель
Сommit
5cc5ba52a8
2 измененных файлов с 68 добавлено и 59 удалено
  1. 34 30
      ghsApp/src/admin/item/components/ItemStock.vue
  2. 34 29
      hdApp/src/admin/home/workbench.vue

+ 34 - 30
ghsApp/src/admin/item/components/ItemStock.vue

@@ -66,38 +66,42 @@ export default {
 			// #endif
 
 			// #ifdef APP-PLUS
-			//this.$msg('请在小程序上打开分享')
-			var sweixin
+			if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
+        uni.login({
+					provider: 'weixin',
+					success: function (loginRes) {
+						var sweixin
 
-			plus.share.getServices(function(s){
-				for (var i = 0; i < s.length; i++) {
-					var t = s[i];
-					if (t.id == 'weixin') {
-							sweixin = t;
-					}
-				}
-			}, function(e){
-				console.log("获取微信失败:" + e.message);
-			});
-
-			if (!(sweixin && sweixin.nativeClient)) {
-				this.$msg('请安装微信');
-				return false;
-			}
+						plus.share.getServices(function(s){
+							for (var i = 0; i < s.length; i++) {
+								var t = s[i];
+								if (t.id == 'weixin') {
+									sweixin = t;
+								}
+							}
 
-			uni.login({
-				provider: 'weixin',
-				success: function (loginRes) {
-					sweixin.launchMiniProgram({
-						id: 'gh_73b8b357d19a',
-						path: 'admin/item/list',
-						type: 0
-					});
-				},
-				fail: function (res) {
-					console.log(res)
-				}
-			});
+							if (sweixin && sweixin.nativeClient) {
+								sweixin.launchMiniProgram({
+									id: 'gh_73b8b357d19a',
+									path: 'admin/item/list',
+									type: 0
+								});
+							} else {
+								this.$msg('请安装微信');
+								return false;
+							}
+						}, function(e){
+							console.log("获取微信失败:" + e.message);
+						});
+					},
+					fail: function (res) {
+						console.log(res);
+					}
+				});
+    	}else{
+        this.$msg("微信应用未安装");
+				return false
+    	}
 			// #endif
 		},
 		addEvent() {

+ 34 - 29
hdApp/src/admin/home/workbench.vue

@@ -154,37 +154,42 @@ export default {
       // #endif
 
       // #ifdef APP-PLUS
-      var sweixin
+      if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
+        uni.login({
+          provider: 'weixin',
+          success: function (loginRes) {
+            var sweixin
 
-			plus.share.getServices(function(s){
-				for (var i = 0; i < s.length; i++) {
-					var t = s[i];
-					if (t.id == 'weixin') {
-							sweixin = t;
-					}
-				}
-			}, function(e){
-				console.log("获取微信失败:" + e.message);
-			});
+            plus.share.getServices(function(s){
+              for (var i = 0; i < s.length; i++) {
+                var t = s[i];
+                if (t.id == 'weixin') {
+                    sweixin = t;
+                }
+              }
 
-			if (!(sweixin && sweixin.nativeClient)) {
-				this.$msg('请安装微信');
-				return false;
-			}
-
-			uni.login({
-				provider: 'weixin',
-				success: function (loginRes) {
-          sweixin.launchMiniProgram({
-            id: 'gh_73b8b357d19a',
-            path: '/pagesPurchase/order',
-            type: 0
-          });
-				},
-        fail: function (res) {
-					console.log(res)
-				}
-			});
+              if (sweixin && sweixin.nativeClient) {
+                sweixin.launchMiniProgram({
+                  id: 'gh_73b8b357d19a',
+                  path: '/pagesPurchase/order',
+                  type: 0
+                });
+              } else {
+                this.$msg('请安装微信');
+                return false;
+              }
+            }, function(e){
+              console.log("获取微信失败:" + e.message);
+            });
+          },
+          fail: function (res) {
+            console.log(res)
+          }
+        });
+      } else {
+        this.$msg("微信应用未安装")
+				return false
+      }
 			// #endif
     },
     goPage (item) {