home.vue 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="w-full h-full" v-loading="isLoading">
  3. <el-container class="flex flex-row h-full">
  4. <el-header class="bg-sky-800 leading-10 flex flex-row justify-between">
  5. <Header></Header>
  6. </el-header>
  7. <el-main>
  8. <router-view v-slot="{ Component }">
  9. <transition name="router_animate">
  10. <component :is="Component" />
  11. </transition>
  12. </router-view>
  13. </el-main>
  14. </el-container>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import Header from '@/pages/header/header.vue';
  19. import { nextTick, onMounted, ref } from 'vue';
  20. import { storeToRefs } from 'pinia';
  21. import { useStore } from '@/store/index'
  22. import { post } from "@/utils/request";
  23. const { userInfo } = storeToRefs(useStore());
  24. declare var wx: any; // wx 小程序对象
  25. declare var window: Window & { WWOpenData: any }; // 如果是 window.WWOpenData
  26. declare var WWOpenData: any; // wx 小程序对象
  27. const isLoading = ref(true);
  28. const agentConfig = () => {
  29. var isCorpWX = true
  30. var ua = navigator.userAgent.toLowerCase();
  31. if (ua.indexOf("wxwork") > 0) {
  32. isCorpWX = false;
  33. }
  34. const curUrl = location.href.split("#")[0];
  35. post(`/wxcorp/getCorpWXConfig`, { url: curUrl, token: userInfo.value.id }).then(res => {
  36. wx.config({
  37. beta: true,
  38. debug: isCorpWX, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  39. appId: res.data.appid, // 必填,公众号的唯一标识
  40. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  41. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  42. signature: res.data.sign, // 必填,签名,见附录1
  43. jsApiList: ['chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'previewFile', 'getLocation', 'agentConfig', 'getLocalImgData']
  44. });
  45. wx.ready(() => {
  46. post(`/wxcorp/getCorpWXAgentConfig`, { url: curUrl, token: userInfo.value.id }).then(res => {
  47. wx.agentConfig({
  48. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  49. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  50. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  51. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  52. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  53. jsApiList: ['selectExternalContact', 'selectEnterpriseContact', 'openAppManage'], //必填,传入需要使用的接口名称
  54. success: function (result: any) {
  55. console.log(result, '请求微信成功')
  56. console.log(window, 'window')
  57. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  58. if (window.WWOpenData) {
  59. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  60. if (WWOpenData.initCanvas) {
  61. WWOpenData.initCanvas()
  62. console.log('我企业微信 canvas 应该执行了吧')
  63. }
  64. }
  65. },
  66. fail: function (res: any) {
  67. console.log('查看错误信息', res)
  68. if (res.errMsg.indexOf('function not exist') > -1) {
  69. alert('版本过低请升级')
  70. }
  71. },
  72. })
  73. })
  74. })
  75. })
  76. }
  77. onMounted(async () => {
  78. await nextTick();
  79. isLoading.value = false;
  80. if (userInfo.value.userNameNeedTranslate == 1) {
  81. agentConfig()
  82. }
  83. });
  84. </script>
  85. <style scoped lang="scss">
  86. .el-main {
  87. padding: 0;
  88. flex: 1;
  89. overflow: auto;
  90. background: $backColor;
  91. }
  92. </style>