|
@@ -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"],
|
|
jsApiList: ["launchMiniprogram"],
|
|
|
success: function (res) {
|
|
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授权信息
|
|
// 获取微信API授权信息
|
|
|
export const getWxconfig = () => {
|
|
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];
|
|
let url = window.location.href.split("#")[0];
|
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
|
formData.append('url', url);
|
|
formData.append('url', url);
|
|
@@ -217,11 +248,6 @@ export const getWxconfig = () => {
|
|
|
wecomTicket(formData).then(response => {
|
|
wecomTicket(formData).then(response => {
|
|
|
if (response.StatusCode == 200) {
|
|
if (response.StatusCode == 200) {
|
|
|
let qiyeData = response.Data;
|
|
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({
|
|
wx.agentConfig({
|
|
|
debug: true,
|
|
debug: true,
|
|
|
corpid: qiyeData.appid,
|
|
corpid: qiyeData.appid,
|
|
@@ -229,10 +255,8 @@ export const getWxconfig = () => {
|
|
|
timestamp: qiyeData.timestamp,
|
|
timestamp: qiyeData.timestamp,
|
|
|
nonceStr: qiyeData.noncestr,
|
|
nonceStr: qiyeData.noncestr,
|
|
|
signature: qiyeData.signature,
|
|
signature: qiyeData.signature,
|
|
|
- jsApiList: [...jsApiList],
|
|
|
|
|
|
|
+ jsApiList: ["hideMenuItems"],
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
- console.log('获取签名成功');
|
|
|
|
|
- isAgentConfigSuccess = true; // 标记配置成功
|
|
|
|
|
wx.hideMenuItems({
|
|
wx.hideMenuItems({
|
|
|
menuList: [
|
|
menuList: [
|
|
|
"menuItem:share:wechat",
|
|
"menuItem:share:wechat",
|
|
@@ -240,22 +264,18 @@ export const getWxconfig = () => {
|
|
|
"menuItem:share:email", // 通过邮件转发
|
|
"menuItem:share:email", // 通过邮件转发
|
|
|
"menuItem:copyUrl",
|
|
"menuItem:copyUrl",
|
|
|
"menuItem:share:wechat_friend",
|
|
"menuItem:share:wechat_friend",
|
|
|
- "menuItem:share:timeline"
|
|
|
|
|
|
|
+ "menuItem:share:timeline",
|
|
|
|
|
+ "menuItem:share:appMessage",
|
|
|
|
|
+ "menuItem:openWithSafari"
|
|
|
],
|
|
],
|
|
|
success: () => {
|
|
success: () => {
|
|
|
- console.log('菜单隐藏成功');
|
|
|
|
|
|
|
+ // console.log('菜单隐藏成功');
|
|
|
},
|
|
},
|
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
|
- console.log('菜单隐藏失败:', err);
|
|
|
|
|
|
|
+ // console.log('菜单隐藏失败:', err);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- },
|
|
|
|
|
- fail: function (res) {
|
|
|
|
|
- // console.log("获取签名失败", res);
|
|
|
|
|
- if (res.errMsg.indexOf('function not exist') > -1) {
|
|
|
|
|
- alert('版本过低请升级');
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|