zhongxiaoyu 3 лет назад
Родитель
Сommit
02a054ddc4
2 измененных файлов с 31 добавлено и 18 удалено
  1. 1 0
      package.json
  2. 30 18
      src/views/dashboard/index.vue

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
     "normalize.css": "7.0.0",
     "nprogress": "0.2.0",
     "path-to-regexp": "2.4.0",
+    "qs": "^6.10.3",
     "vue": "2.6.10",
     "vue-router": "3.0.6",
     "vue2-org-tree": "^1.3.5",

+ 30 - 18
src/views/dashboard/index.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-10-14 17:17:53
- * @LastEditTime: 2022-03-28 10:14:55
+ * @LastEditTime: 2022-03-28 14:18:00
  * @LastEditors: your name
  * @Description: In User Settings Edit
  * @FilePath: \Foshan4A\src\views\dashboard\index.vue
@@ -42,7 +42,7 @@
                 v-for="(p, i) in item.params"
                 :key="i"
                 :command="{ item, index: i}"
-              >{{ Object.entries(p).map(arr => arr[1].comment).join(' ') }}</el-dropdown-item>
+              >{{ Object.entries(p).filter(arr => arr[1].repeat).map(arr => arr[1].comment).join(' ') }}</el-dropdown-item>
             </el-dropdown-menu>
           </el-dropdown>
         </template>
@@ -127,6 +127,7 @@ import Analysis from './components/analysis.vue'
 import Journal from './components/journal.vue'
 import { GetOthSystem } from '@/api/apiHome'
 import axios from 'axios'
+import qs from 'qs'
 export default {
   name: 'Dashboard',
   components: { Analysis, Journal },
@@ -236,6 +237,9 @@ export default {
                       value,
                       comment
                     })
+                    map[key].forEach((element, index, arr) => {
+                      element.repeat = arr.length
+                    })
                   } else {
                     map[key] = [
                       {
@@ -356,10 +360,11 @@ export default {
     },
     toApp(item, index = 0) {
       if (item.appUrl) {
+        let method
         const originParams = item.params.length ? item.params[index] : {}
         const headers = {}
         const url = []
-        const params = []
+        const params = {}
         Object.entries(originParams).forEach(arr => {
           const value = ['loginName', 'userName', 'token'].includes(arr[1].value)
             ? sessionStorage.getItem(arr[1].value) ?? ''
@@ -372,27 +377,34 @@ export default {
               url.push(`${arr[0]}=${value}`)
               break
             case 'body':
-              params.push(`${arr[0]}=${value}`)
+              params[arr[0]] = value
               break
             default:
               break
           }
         })
-        const form = document.createElement('form')
-        form.action = item.appUrl + (url.length ? '?' + url.join('&') : '')
-        form.target = '_blank'
-        form.method = parseInt(item.requestType) === 1 ? 'get' : 'post'
-        form.style.display = 'none'
-        for (let i = 0; i < params.length; i++) {
-          const input = document.createElement('input')
-          const map = params[i].split('=')
-          input.name = map[0]
-          input.value = map[1]
-          form.appendChild(input)
+        if (parseInt(item.requestType) === 1) {
+          method = 'get'
+        } else {
+          method = 'post'
+          headers['Content-Type'] =
+            item.bodyType === 'application/json'
+              ? 'application/json;charset=UTF-8'
+              : 'application/x-www-form-urlencoded'
         }
-        document.body.appendChild(form)
-        form.submit()
-        document.body.removeChild(form)
+        axios({
+          url: item.appUrl + (url.length ? '?' + url.join('&') : ''),
+          method,
+          headers,
+          data: item.bodyType === 'application/json' ? params : qs.stringify(params)
+        })
+          .then(res => {
+            const data = res.data.data
+            data && window.open(res.data.data)
+          })
+          .catch(err => {
+            console.log(err)
+          })
       }
       // if (item.appUrl) {
       //   window.open(item.appUrl)