Ver Fonte

:recycle: 重构代码。 三方登录绑定、登录逻辑修改。完善支付模块

冷冷 há 6 anos atrás
pai
commit
2e93ec094f

+ 1 - 1
src/const/crud/admin/sys-file.js

@@ -38,7 +38,7 @@ export const tableOption = {
     },
 	  {
       label: '文件名',
-      prop: 'name',
+      prop: 'fileName',
       overHidden:true,
       search: true
     },

+ 10 - 46
src/page/login/authredirect.vue

@@ -4,6 +4,7 @@
 
 <script>
 import request from '@/router/axios'
+import { getQueryString } from '@/util/util'
 import { mapGetters } from 'vuex'
 
 export default {
@@ -12,58 +13,21 @@ export default {
     ...mapGetters(['tagWel'])
   },
   created() {
-    const params = this.$route.query
-    let code = params.code
-    const url = window.location.href
+    const url = window.location.href.replace('#/authredirect', '')
+    const code = getQueryString(url, 'code')
+    let state = getQueryString(url, 'state')
+    const type = state.split('-')[1]
+    state = state.split('-')[0]
     // 登录请求
-    if (url.indexOf('LOGIN') > 0) {
-      // QQ 微信强大 可以解析
-      if (url.indexOf('WX') > 0 || url.indexOf('QQ') > 0) {
-        const state = params.state.split('-')[0]
-        const code = params.code
-        window.opener.location.href = `${window.location.origin}/#/login?state=${state}&code=${code}&time=` + new Date().getTime()
-      } else if (url.indexOf('OSC') > 0) {
-        const start = url.indexOf('=') + 1
-        const end = url.indexOf('&state')
-        code = url.substring(start, end)
-        window.opener.location.href = `${window.location.origin}/#/login?state=OSC&code=${code}&time=` + new Date().getTime()
-      } else if (url.indexOf('GITEE') > 0) {
-        const start = url.indexOf('=') + 1
-        const end = url.indexOf('&state')
-        code = url.substring(start, end)
-        window.opener.location.href = `${window.location.origin}/#/login?state=GITEE&code=${code}&time=` + new Date().getTime()
-      }
+    if (type === 'LOGIN') {
+      window.opener.location.href = `${window.location.origin}/#/login?state=${state}&code=${code}&time=` + new Date().getTime()
       window.close()
     } else {
-      if (url.indexOf('WX') > 0 || url.indexOf('QQ') > 0) {
-        const state = params.state.split('-')[0]
-        const code = params.code
-        request({
-          url: '/admin/social/bind',
-          method: 'post',
-          params: { state, code }
-        }).then(() => {
-          this.$alert('社交账号绑定成功', '成功', {
-            confirmButtonText: '确定',
-            callback: () => {
-              window.close()
-            }
-          })
-        })
-      } else if (url.indexOf('OSC') > 0) {
-        const state = 'OSC'
-        this.bind(state, url)
-      } else if (url.indexOf('GITEE') > 0) {
-        const state = 'GITEE'
-        this.bind(state, url)
-      }
+      this.bind(state, code)
     }
   },
   methods: {
-    bind: function(state, url) {
-      const start = url.indexOf('=') + 1
-      const end = url.indexOf('#')
-      const code = url.substring(start, end)
+    bind: function(state, code) {
       request({
         url: '/admin/social/bind',
         method: 'post',

+ 25 - 7
src/util/util.js

@@ -1,4 +1,4 @@
-import {validatenull} from './validate'
+import { validatenull } from './validate'
 import request from '@/router/axios'
 import * as CryptoJS from 'crypto-js'
 
@@ -150,16 +150,16 @@ export const listenfullscreen = (callback) => {
     callback()
   }
 
-  document.addEventListener('fullscreenchange', function () {
+  document.addEventListener('fullscreenchange', function() {
     listen()
   })
-  document.addEventListener('mozfullscreenchange', function () {
+  document.addEventListener('mozfullscreenchange', function() {
     listen()
   })
-  document.addEventListener('webkitfullscreenchange', function () {
+  document.addEventListener('webkitfullscreenchange', function() {
     listen()
   })
-  document.addEventListener('msfullscreenchange', function () {
+  document.addEventListener('msfullscreenchange', function() {
     listen()
   })
 }
@@ -321,7 +321,7 @@ export function handleImg(fileName, id) {
     const blob = response.data
     const img = document.getElementById(id)
     img.src = URL.createObjectURL(blob)
-    window.setTimeout(function () {
+    window.setTimeout(function() {
       window.URL.revokeObjectURL(blob)
     }, 0)
   })
@@ -339,9 +339,27 @@ export function handleDown(filename, bucket) {
     link.download = filename
     document.body.appendChild(link)
     link.click()
-    window.setTimeout(function () {
+    window.setTimeout(function() {
       URL.revokeObjectURL(blob)
       document.body.removeChild(link)
     }, 0)
   })
 }
+
+export function getQueryString(url, paraName) {
+  const arrObj = url.split('?')
+  if (arrObj.length > 1) {
+    const arrPara = arrObj[1].split('&')
+    let arr
+    for (let i = 0; i < arrPara.length; i++) {
+      arr = arrPara[i].split('=')
+      // eslint-disable-next-line eqeqeq
+      if (arr != null && arr[0] == paraName) {
+        return arr[1]
+      }
+    }
+    return ''
+  } else {
+    return ''
+  }
+}

+ 1 - 1
src/views/admin/user/info.vue

@@ -242,7 +242,7 @@ export default {
         url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=QQ-BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
       } else if (thirdpart === 'gitee') {
         client_id = '8fc54e0e76e7842cf767c3ae3b9fdc48c03cefed27aa565ff7b2a39d142d9892'
-        url = 'https://gitee.com/oauth/authorize?response_type=code&state=GITEE--BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
+        url = 'https://gitee.com/oauth/authorize?response_type=code&state=GITEE-BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
       } else if (thirdpart === 'osc') {
         client_id = 'neIIqlwGsjsfsA6uxNqD'
         url = 'https://www.oschina.net/action/oauth2/authorize?response_type=code&client_id=' + client_id + '&state=OSC-BIND&redirect_uri=' + redirect_uri

+ 1 - 0
src/views/pay/goods/index.vue

@@ -67,6 +67,7 @@ export default {
     getList(page, params) {
       this.tableLoading = true
       fetchList(Object.assign({
+        descs: 'create_time',
         current: page.currentPage,
         size: page.pageSize
       }, params)).then(response => {

+ 1 - 0
src/views/pay/notify/index.vue

@@ -76,6 +76,7 @@ export default {
     getList(page, params) {
       this.tableLoading = true
       fetchList(Object.assign({
+        descs: 'create_time',
         current: page.currentPage,
         size: page.pageSize
       }, params)).then(response => {

+ 1 - 0
src/views/pay/orders/index.vue

@@ -76,6 +76,7 @@ export default {
     getList(page, params) {
       this.tableLoading = true
       fetchList(Object.assign({
+        descs: 'create_time',
         current: page.currentPage,
         size: page.pageSize
       }, params)).then(response => {