bug
jiangping
2023-12-06 1f4e7d0f73a73e7350cf5a1df279d5f30904c5d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
  <router-view/>
</template>
 
<script setup lang="ts">
import * as echarts from 'echarts'
import { getCurrentInstance, provide, onMounted } from "vue";
import { useStore } from "vuex";
import { useRoute } from 'vue-router';
import { ddLogin, getUserInfo, testLogin, getDingdingCorpId } from "@/apis";
import { Toast } from "vant";
 
const { proxy }: any = getCurrentInstance()
 
provide('ec', echarts)
const route = useRoute()
const store = useStore()
 
const LOGIN = async () => {
  
  let timer: any = null
  timer = setInterval(() => {
    if (store.state.companyId) {
      clearInterval(timer)
      timer = null
      if (proxy.$dd.env.platform !== 'notInDingTalk') {
        if (store.state.companyId !== 'noLogin') {
          // Toast.fail(store.state.companyId)
          getDingdingCorpId(store.state.companyId)
            .then(dataCode => {
              if (dataCode.code === 200) {
                proxy.$dd.runtime.permission.requestAuthCode({
                  corpId: dataCode.data,
                  onSuccess: async (result: any) => {
                    // process.env.VUE_APP_CORPID
                    // process.env.VUE_APP_COMPANYID
                    let res: any = await ddLogin({ code: result.code, companyId: store.state.companyId })
                    if (res.code === 200) {
                      let info: any = await getUserInfo()
                      if (info.code === 200) {
                        await store.commit('setEntrance', 'DD')
                        await store.commit('setUserInfo', info.data)
                        await store.dispatch('getMenuList', 2)
                      } else {
                        Toast.fail(info.message)
                      }
                    } else {
                      Toast.fail(res.message)
                    }
                    proxy.$reslove()
                  },
                  onFail: (err: any) => {
                    Toast.fail('钉钉登录失败')
                  }
                })
              }
            })
        } else {
          proxy.$reslove()
        }
      } else {
        proxy.$reslove()
      }
    }
  }, 1000)
}
 
if (proxy.$dd.env.platform !== 'notInDingTalk') {
  proxy.$dd.ready(function() {
    // 页面被唤醒的事件监听(webview)
    document.addEventListener('resume', function(e) {
      e.preventDefault();
    }, false);
    // 网络连接断开的事件监听
    document.addEventListener('offline', function(e) {
      e.preventDefault();
    }, false);
  })
}
 
onMounted(() => {
  store.dispatch('mobilePhoneModel')
  LOGIN()
})
</script>
 
<style lang="scss">
  html, body, #app {
    width: 100%;
    height: 100%;
    margin: 0;
  }
</style>