MrShi
6 天以前 97158794d69fd2beee1bf27577aa7cadea8d847d
admin/src/views/login.vue
@@ -1,7 +1,7 @@
<template>
  <div class="wrap">
    <div class="introduce">
      <h2>近快后台管理系统</h2>
      <h2>志邦点将后台管理系统</h2>
      <h3></h3>
    </div>
    <div class="login">
@@ -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,37 @@
  },
  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')
      }
      dd.requestAuthCode({
        corpId: corpId,
        clientId: 'dingulzemj5bynjciapg',
        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>