Przeglądaj źródła

:alien: Updating code due to external API changes.

冷冷 6 lat temu
rodzic
commit
28ee8c5b76

+ 14 - 1
src/api/login.js

@@ -29,10 +29,23 @@ export const loginByUsername = (username, password, code, randomStr) => {
     })
 }
 
+export const loginByMobile = (mobile, code) => {
+    var grant_type = 'mobile'
+    return request({
+        url: '/auth/mobile/token/sms',
+        headers: {
+            'TENANT_ID': '1',
+            'Authorization': 'Basic cGlnOnBpZw=='
+        },
+        method: 'post',
+        params: { mobile: 'SMS@' + mobile,code: code, grant_type }
+    })
+}
+
 export const loginBySocial = (state, code) => {
     var grant_type = 'mobile'
     return request({
-        url: '/auth/mobile/token',
+        url: '/auth/mobile/token/social',
         headers: {
             'TENANT_ID': '1',
             'Authorization': 'Basic cGlnOnBpZw=='

+ 34 - 21
src/page/login/codelogin.vue

@@ -8,7 +8,7 @@
     <el-form-item prop="phone">
       <el-input size="small"
                 @keyup.enter.native="handleLogin"
-                v-model="loginForm.phone"
+                v-model="loginForm.mobile"
                 auto-complete="off"
                 placeholder="请输入手机号码">
         <i slot="prefix"
@@ -42,11 +42,11 @@
 
 <script>
 const MSGINIT = "发送验证码",
-  // MSGERROR = "验证码发送失败",
   MSGSCUCCESS = "${time}秒后重发",
   MSGTIME = 60;
 import { isvalidatemobile } from "@/util/validate";
 import { mapGetters } from "vuex";
+import request from '@/router/axios'
 export default {
   name: "codelogin",
   data () {
@@ -69,12 +69,12 @@ export default {
       msgTime: MSGTIME,
       msgKey: false,
       loginForm: {
-        phone: "17547400800",
-        code: ""
+          mobile: '',
+          code: ''
       },
       loginRules: {
-        phone: [{ required: true, trigger: "blur", validator: validatePhone }],
-        code: [{ required: true, trigger: "blur", validator: validateCode }]
+          mobile: [{ required: true, trigger: 'blur', validator: validatePhone }],
+          code: [{ required: true, trigger: 'blur', validator: validateCode }]
       }
     };
   },
@@ -85,21 +85,34 @@ export default {
   },
   props: [],
   methods: {
-    handleSend () {
-      if (this.msgKey) return;
-      this.msgText = MSGSCUCCESS.replace("${time}", this.msgTime);
-      this.msgKey = true;
-      const time = setInterval(() => {
-        this.msgTime--;
-        this.msgText = MSGSCUCCESS.replace("${time}", this.msgTime);
-        if (this.msgTime == 0) {
-          this.msgTime = MSGTIME;
-          this.msgText = MSGINIT;
-          this.msgKey = false;
-          clearInterval(time);
-        }
-      }, 1000);
-    },
+    handleSend() {
+          if (this.msgKey) return
+
+          request({
+              url: '/admin/mobile/' + this.loginForm.mobile,
+              method: 'get'
+          }).then(response => {
+              console.log(response.data.data)
+              if (response.data.data) {
+                  this.$message.success('验证码发送成功')
+              } else {
+                  this.$message.error(response.data.msg)
+              }
+          })
+
+          this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
+          this.msgKey = true
+          const time = setInterval(() => {
+              this.msgTime--
+              this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
+              if (this.msgTime == 0) {
+                  this.msgTime = MSGTIME
+                  this.msgText = MSGINIT
+                  this.msgKey = false
+                  clearInterval(time)
+              }
+          }, 1000)
+      },
     handleLogin () {
       this.$refs.loginForm.validate(valid => {
         if (valid) {

+ 1 - 1
src/page/login/thirdlogin.vue

@@ -32,7 +32,7 @@ export default {
       redirect_uri = encodeURIComponent(window.location.origin + '/#/authredirect')
       if (thirdpart === 'wechat') {
         appid = 'wxd1678d3f83b1d83a'
-        url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=' + appid + '&response_type=code&scope=snsapi_login#wechat_redirect'
+        url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=WX&response_type=code&scope=snsapi_login#wechat_redirect'
       } else if (thirdpart === 'tencent') {
         client_id = '101322838'
         url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=' + appid + '&client_id=' + client_id + '&redirect_uri=' + redirect_uri

+ 22 - 0
src/page/login/userlogin.vue

@@ -75,6 +75,10 @@ export default {
   data () {
 
     return {
+      socialForm: {
+          code: '',
+          state: ''
+      },
       loginForm: {
         username: "admin",
         password: "123456",
@@ -104,6 +108,24 @@ export default {
       passwordType: "password"
     };
   },
+  watch: {
+        $route() {
+            const params = this.$route.query
+            this.socialForm.state = params.state
+            this.socialForm.code = params.code
+            if (!validatenull(this.socialForm.state)) {
+                const loading = this.$loading({
+                    lock: true,
+                    text: `登录中,请稍后。。。`,
+                    spinner: 'el-icon-loading'
+                })
+                setTimeout(() => {
+                    loading.close()
+                }, 2000)
+                this.handleSocialLogin()
+            }
+        }
+    },
   created () {
     this.refreshCode();
   },

+ 1 - 1
src/router/axios.js

@@ -47,7 +47,7 @@ axios.interceptors.request.use(config => {
 axios.interceptors.response.use(res => {
     NProgress.done();
     const status = Number(res.status);
-    const message = res.data.message || errorCode[status] || errorCode['default'];
+    const message = res.data.data || errorCode[status] || errorCode['default'];
 
     if (status === 401){
         store.dispatch('FedLogOut').then(() => {

+ 11 - 9
src/store/modules/user.js

@@ -1,6 +1,6 @@
 import { setToken, removeToken } from '@/util/auth'
 import { setStore, getStore } from '@/util/store'
-import { logout, loginByUsername, loginBySocial, getUserInfo } from '@/api/login'
+import { logout, loginByUsername,loginByMobile, loginBySocial, getUserInfo } from '@/api/login'
 import { encryption } from '@/util/util'
 import webiste from '@/const/website';
 import { GetMenu } from '@/api/menu'
@@ -61,14 +61,16 @@ const user = {
         },
         //根据手机号登录
         LoginByPhone({ commit }, userInfo) {
-            return new Promise((resolve) => {
-                loginByUsername(userInfo.phone, userInfo.code).then(res => {
-                    const data = res.data;
-                    commit('SET_TOKEN', data);
-                    commit('DEL_ALL_TAG');
-                    commit('CLEAR_LOCK');
-                    setToken(data);
-                    resolve();
+            return new Promise((resolve, reject) => {
+                loginByMobile(userInfo.mobile, userInfo.code).then(response => {
+                    const data = response.data
+                    setToken(data.access_token)
+                    commit('SET_ACCESS_TOKEN', data.access_token)
+                    commit('SET_REFRESH_TOKEN', data.refresh_token)
+                    commit('CLEAR_LOCK')
+                    resolve()
+                }).catch(error => {
+                    reject(error)
                 })
             })
         },