Mr.Shi
2023-08-11 b15a83329e33a954f41c9558b58aa1a64332c46b
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
  <div class="box">
    <div class="box_content" v-show="show" @click="LOGIN">
      <img src="@/assets/icon/loginError.png" alt="" />
      <span>登录失败,请点击重新登录</span>
    </div>
  </div>
</template>
 
<script setup lang="ts">
  import { onMounted, getCurrentInstance, ref } from 'vue'
  import { ddLogin, getUserInfo, testLogin, getDingdingCorpId } from "@/apis"
  import { Toast } from "vant"
  import { useStore } from "vuex"
  import { useRouter } from "vue-router"
  const { proxy }: any = getCurrentInstance()
 
  const store = useStore()
 
  const router = useRouter()
 
  let show = ref<boolean>(false)
 
  const LOGIN = async () => {
    show.value = false
    // 判断如果是从钉钉进入,执行登录操作
    // if (proxy.$dd.env.platform == 'notInDingTalk') {
      // process.env.VUE_APP_COMPANYID
    if (proxy.$dd.env.platform !== 'notInDingTalk') {
      if (store.state.companyId !== 'noLogin') {
        getDingdingCorpId(store.state.companyId)
          .then(dataCode => {
            if (dataCode.code === 200) {
              proxy.$dd.runtime.permission.requestAuthCode({
                corpId: dataCode.data,
                onSuccess: async (result: any) => {
                  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)
                      await router.go(-1)
                    } else {
                      Toast.fail(info.message)
                      show.value = true
                    }
                  } else {
                    Toast.fail(res.message)
                    show.value = true
                  }
                },
                onFail: (err: any) => {
                  show.value = true
                  console.log(err)
                  Toast.fail('钉钉登录失败')
                }
              })
            }
          })
      }
    } else {
      // let res = await testLogin({
      //     username: 'manager',
      //     password: '1',
      //     companyId: '1',
      //     uuid: '0000',
      //     code: '0000'
      // })
 
      // let res = await testLogin({
      //     username: '15395136032',
      //     password: '123456',
      //     companyId: '4',
      //     uuid: '0000',
      //     code: '0000'
      // })
 
      // let res = await testLogin({  // 英子姐
      //   username: '18055151023',
      //   password: '123456',
      //   companyId: '1',
      //   uuid: '0000',
      //   code: '0000'
      // })
      // let res = await testLogin({  // 大栓
      //   username: '18019924213',
      //   password: '123456',
      //   companyId: '1',
      //   uuid: '0000',
      //   code: '0000'
      // })
      let res = await testLogin({ // 文武
        username: '18656077929',
        password: '123456',
        companyId: '8',
        uuid: '0000',
        code: '0000'
      })
      // let res = await testLogin({ // 胡克东
      //   username: '17751132561',
      //   password: '123456',
      //   companyId: '1',
      //   uuid: '0000',
      //   code: '0000'
      // })
 
      // let res = await testLogin({
      //     username: '15056231084',
      //     password: '123456',
      //     companyId: '1',
      //     uuid: '0000',
      //     code: '0000'
      // })
      if (res.code === 200) {
        window.localStorage.setItem('token', res.data)
        let info: any = await getUserInfo()
        if (info.code === 200) {
          await store.commit('setEntrance', 'H5')
          await store.commit('setUserInfo', info.data)
          await store.dispatch('getMenuList', 2)
          await router.go(-1)
        } else {
          show.value = true
          Toast.fail(res.message)
        }
      } else {
        show.value = true
        Toast.fail(res.message)
      }
    }
  }
 
  onMounted(async () => {
    LOGIN()
  })
</script>
 
<style lang="scss" scoped>
.box {
  width: 100%;
  position: absolute;
  height: 100%;
  background: white;
  .box_content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    img {
      width: 200px;
      height: 200px;
    }
    span {
      font-size: 28px;
      margin-top: 20px;
    }
  }
}
</style>