armg 3 päivää sitten
vanhempi
commit
396877e91d
4 muutettua tiedostoa jossa 101 lisäystä ja 94 poistoa
  1. 4 1
      src/layout/index.vue
  2. 95 75
      src/utils/index.ts
  3. 1 17
      src/views/AIDesign/index.vue
  4. 1 1
      src/views/AIDesign/result.vue

+ 4 - 1
src/layout/index.vue

@@ -7,6 +7,7 @@
 </template>
 <script lang="ts">
 import { Component, Vue, Watch } from "vue-property-decorator";
+import { getWxconfig } from '@/utils/index';
 import axios from "axios";
 declare let wx: any;
 @Component({
@@ -15,7 +16,9 @@ declare let wx: any;
 })
 export default class extends Vue {
   @Watch("$route")
-  routechange(to: any, from: any) { }
+  routechange(to: any, from: any) {
+    // getWxconfig()
+  }
   created() { }
   //判断是否微信环境
   is_weixn() {

+ 95 - 75
src/utils/index.ts

@@ -144,72 +144,103 @@ export const toLBHome = () => {
   }
 }
 
-// 全局变量:标记agentConfig是否已成功初始化
-let isAgentConfigSuccess = false;
 
-/* 跳转小程序(需先调用getWxconfig初始化)
- * @param {string} appid 目标小程序appid
- * @returns {Promise} 跳转成功/失败的Promise
- */
-export const toXiaoChengxu = async (appid) => {
-  try {
-    if (!appid) {
-      throw new Error("小程序appid不能为空");
-    }
-    // 1. 确保agentConfig已成功初始化(如果未初始化,会自动执行)
-    await getWxconfig();
-    // 2. 检查launchMiniprogram接口是否可用
-    await new Promise((resolve, reject) => {
-      wx.checkJsApi({
+// export const toXiaoChengxu = (appid) => {
+//   let url = window.location.href.split("#")[0];
+//   wx.ready(function () {
+//     wx.checkJsApi({
+//       jsApiList: ["agentConfig", "launchMiniprogram"], // 需要检测的JS接口列表
+//       success: function (res) {
+//         const formData = new FormData();
+//         formData.append('url', url);
+//         formData.append('agent', '1');
+//         wecomTicket(formData).then(response => {
+//           if (response.StatusCode == 200) {
+//             let yingyongData = response.Data;
+//             wx.agentConfig({
+//               corpid: yingyongData.appid, // 必填,企业微信的corpid,必须与当前登录的企业一致
+//               agentid: yingyongData.agentID, // 必填,企业微信的应用id (e.g. 1000247)
+//               timestamp: yingyongData.timestamp, // 必填,生成签名的时间戳
+//               nonceStr: yingyongData.noncestr, // 必填,生成签名的随机串
+//               signature: yingyongData.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
+//               jsApiList: ["launchMiniprogram"], //必填,传入需要使用的接口名称
+//               success: function (res) {
+//                 wx.invoke(
+//                   "launchMiniprogram",
+//                   {
+//                     appid: appid, // 需跳转的小程序appid
+//                     path: "" // 所需跳转的小程序内页面路径及参数。非必填
+//                   },
+//                   function (res) {
+//                     if (res.err_msg == "launchMiniprogram:ok") {
+//                       // 正常
+//                       console.log("正常");
+//                     } else {
+//                       // 错误处理
+//                     }
+//                   }
+//                 );
+//               },
+//               fail: function (res) {
+//                 if (res.errMsg.indexOf("function not exist") > -1) {
+//                   alert("版本过低请升级");
+//                 }
+//               }
+//             });
+//           }
+//         });
+//       }
+//     });
+//   });
+// }
+
+
+export const toXiaoChengxu = (appid) => {
+  let url = window.location.href.split("#")[0];
+  const formData = new FormData();
+  formData.append('url', url);
+  formData.append('agent', '1');
+  wecomTicket(formData).then(response => {
+    if (response.StatusCode == 200) {
+      let qiyeData = response.Data;
+      wx.agentConfig({
+        debug: true,
+        corpid: qiyeData.appid,
+        agentid: qiyeData.agentID,
+        timestamp: qiyeData.timestamp,
+        nonceStr: qiyeData.noncestr,
+        signature: qiyeData.signature,
         jsApiList: ["launchMiniprogram"],
         success: function (res) {
-          console.log("checkJsApi结果:", res);
-          // 检查接口是否真的可用
-          if (res.checkResult.launchMiniprogram !== true) {
-            reject(new Error("当前环境不支持launchMiniprogram接口,请确认企业微信版本和应用权限"));
-          } else {
-            resolve();
-          }
-        },
-        fail: function (err) {
-          reject(new Error(`checkJsApi失败:${JSON.stringify(err)}`));
-        }
-      });
-    });
-
-    // 3. 调用跳转接口
-    await new Promise((resolve, reject) => {
-      wx.invoke(
-        "launchMiniprogram",
-        {
-          appid: appid, // 目标小程序appid
-          path: "" // 小程序内路径(非必填)
+          wx.invoke(
+            "launchMiniprogram",
+            {
+              appid: appid, // 需跳转的小程序appid
+              path: "" // 所需跳转的小程序内页面路径及参数。非必填
+            },
+            function (res) {
+              if (res.err_msg == "launchMiniprogram:ok") {
+                // 正常
+                console.log("正常");
+              } else {
+                // 错误处理
+              }
+            }
+          );
         },
-        function (res) {
-          // console.log("launchMiniprogram调用结果:", res);
-          if (res.err_msg === "launchMiniprogram:ok") {
-            // console.log("小程序跳转成功");
-            resolve(res);
-          } else {
-            reject(new Error(`跳转失败:${res.err_msg}`));
+        fail: function (res) {
+          if (res.errMsg.indexOf("function not exist") > -1) {
+            alert("版本过低请升级");
           }
         }
-      );
-    });
-
-  } catch (error) {
-    console.error("小程序跳转流程异常:", error.message);
-    alert(`跳转失败:${error.message}`);
-    throw error; // 抛出错误,方便上层处理
-  }
-};
+      });
+    }
+  });
+}
 
 // 获取微信API授权信息
 export const getWxconfig = () => {
-  if (isAgentConfigSuccess) {
-    return;
-  }
-  const jsApiList = ['downloadFile', 'saveImageToPhotosAlbum', 'closeWindow', 'hideMenuItems', 'launchMiniprogram'];
+  // const jsApiList = ['ready', 'downloadFile', 'saveImageToPhotosAlbum', 'closeWindow', 'hideMenuItems'];
   let url = window.location.href.split("#")[0];
   const formData = new FormData();
   formData.append('url', url);
@@ -217,11 +248,6 @@ export const getWxconfig = () => {
   wecomTicket(formData).then(response => {
     if (response.StatusCode == 200) {
       let qiyeData = response.Data;
-      // console.log("corpid=", qiyeData.appid)
-      // console.log("agentid=", qiyeData.agentID)
-      // console.log("timestamp=", qiyeData.timestamp)
-      // console.log("nonceStr=", qiyeData.noncestr)
-      // console.log("signature=", qiyeData.signature)
       wx.agentConfig({
         debug: true,
         corpid: qiyeData.appid,
@@ -229,10 +255,8 @@ export const getWxconfig = () => {
         timestamp: qiyeData.timestamp,
         nonceStr: qiyeData.noncestr,
         signature: qiyeData.signature,
-        jsApiList: [...jsApiList],
+        jsApiList: ["hideMenuItems"],
         success: function (res) {
-          console.log('获取签名成功');
-          isAgentConfigSuccess = true; // 标记配置成功
           wx.hideMenuItems({
             menuList: [
               "menuItem:share:wechat",
@@ -240,22 +264,18 @@ export const getWxconfig = () => {
               "menuItem:share:email",         // 通过邮件转发
               "menuItem:copyUrl",
               "menuItem:share:wechat_friend",
-              "menuItem:share:timeline"
+              "menuItem:share:timeline",
+              "menuItem:share:appMessage",
+              "menuItem:openWithSafari"
             ],
             success: () => {
-              console.log('菜单隐藏成功');
+              // console.log('菜单隐藏成功');
             },
             fail: (err) => {
-              console.log('菜单隐藏失败:', err);
+              // console.log('菜单隐藏失败:', err);
             }
           });
-        },
-        fail: function (res) {
-          // console.log("获取签名失败", res);
-          if (res.errMsg.indexOf('function not exist') > -1) {
-            alert('版本过低请升级');
-          }
-        },
+        }
       });
     }
   });

+ 1 - 17
src/views/AIDesign/index.vue

@@ -93,26 +93,10 @@ declare let wx: any;
 @Component
 export default class extends Vue {
   private currentTab = 'outside';
-  // created() {
-  //   getWxconfig();
-  //   // 经销商随身邦,好邦手进去,默认在内墙空间;服务商进去,默认外墙空间
-  //   const agentFrom = window.localStorage.getItem('agentFrom');
-  //   window.localStorage.setItem('agentFromAI', agentFrom);
-  //   // 导购直接从AI设计首页进来的修改agentFrom=dg
-  //   const agent = this.$route.query.agent || null;
-  //   if (agent && agent === 'dg') {
-  //     window.localStorage.setItem('agentFromAI', agent);
-  //   }
-  //   if (agentFrom === 'ssb' || agentFrom === 'hbs') {
-  //     this.currentTab = 'inside';
-  //   } else {
-  //     this.currentTab = 'outside';
-  //   }
-  // }
   // 入口新判断
   created() {
-    this.loginMode = window.localStorage.getItem("loginMode") || 'codeLogin';
     getWxconfig();
+    this.loginMode = window.localStorage.getItem("loginMode") || 'codeLogin';
     const agentFrom = window.localStorage.getItem('agentFrom');
     // 经销商随身邦,好邦手进去,默认在内墙空间;服务商进去,默认外墙空间
     if (agentFrom === 'ssb' || agentFrom === 'hbs') {

+ 1 - 1
src/views/AIDesign/result.vue

@@ -151,11 +151,11 @@ export default class extends Vue {
   private serviceCodeArray = [];
   private allRes = null;
   created() {
+    getWxconfig();
     if (window.localStorage.getItem('agentFromAI') === 'stoneLikePaint') {
       this.getServiceCode();
     }
     checkAndSaveUserWecomType();
-    getWxconfig();
   }
 
   activated() {