MrShi
4 天以前 05aec1e9986fbe3e907259bb1a1396f129bd0fa1
admin/src/views/login.vue
@@ -22,8 +22,8 @@
<script>
import { mapMutations } from 'vuex'
import { getCaptcha, loginByPassword } from '@/api/system/common'
import { getCaptcha, loginByPassword, loginByDingTalk } from '@/api/system/common'
import * as dd from 'dingtalk-jsapi';
export default {
  name: 'Login',
  data () {
@@ -31,6 +31,7 @@
      loading: false,
      username: '',
      password: '',
      unionId: '',
      // 验证码
      captcha: {
        loading: false,
@@ -57,7 +58,8 @@
        username: this.username.trim(),
        password: this.password,
        code: this.captcha.value.trim(),
        uuid: this.captcha.uuid
        uuid: this.captcha.uuid,
        unionId: this.unionId
      },true)
        .then(() => {
          window.location.href = process.env.VUE_APP_CONTEXT_PATH
@@ -113,6 +115,38 @@
  },
  created () {
    this.refreshCaptcha()
    var that = this
    let href = window.location.href;
    let corpId = ''
    if (dd.env.platform !== 'notInDingTalk') {
      // 先判断地址上有没有corpId
      if (href.indexOf('?corpid=') !== -1) {
        // alert('从地址拿corpid')
        corpId = href.substring(href.lastIndexOf('?corpid=') + 8, href.lastIndexOf('#'))
        window.localStorage.setItem('corpId', corpId)
      // 判断浏览器缓存是否有corpId
      } else if (window.localStorage.getItem('corpId')) {
        corpId = window.localStorage.getItem('corpId')
        // alert('从缓存拿corpid')
      }
      // dingulzemj5bynjciapg
      dd.requestAuthCode({
        corpId: corpId,
        clientId: 'dingy7xdyzffnegiaszo',
        onSuccess: function(result) {
          loginByDingTalk({
            code: result.code,
            corpId: corpId
          }).then(res => {
            if (res.loginStatus) {
              window.location.href = process.env.VUE_APP_CONTEXT_PATH
              return
            }
            that.unionId = res.unionId
          })
        }
      });
    }
  }
}
</script>