Browse Source

Merge branch 'dev' of http://git.ycjcjy.com/SpaceOfCheng/admin into dev

wangfei 6 years ago
parent
commit
69975f8c9d
3 changed files with 29 additions and 14 deletions
  1. 12
    9
      src/pages/system/newOrder/newOrderList/index.vue
  2. 11
    5
      src/util/ajax.js
  3. 6
    0
      src/util/api.js

+ 12
- 9
src/pages/system/newOrder/newOrderList/index.vue View File

@@ -79,10 +79,10 @@
79 79
 
80 80
 <script>
81 81
 import { createNamespacedHelpers, mapState, mapActions } from 'vuex'
82
-
83 82
 import { getLodop } from '@/util/LodopFuncs'
84
-
85 83
 import { formatTimeBySeconds } from '@/util/util'
84
+import { replaceURLParams } from '@/util/ajax'
85
+
86 86
 // const WebSocket = require('ws')
87 87
 const { mapState: mapOrderState, mapActions: mapOrderActions } = createNamespacedHelpers('goodsorder')
88 88
 
@@ -257,9 +257,12 @@ export default {
257 257
     },
258 258
     initWebSocket () {
259 259
       // console.log(this.user)
260
+      const wsPath = this.$api.system.notify.newGoodsOrders.url
261
+      const wsRealPath = replaceURLParams(wsPath, { grps: caseid, id })
262
+
260 263
       let caseid = this.caseid
261 264
       let id = this.userInfo.UserId
262
-      const wsuri = `${window.location.origin.replace('http', 'ws')}/api-v2/common/MQ/websocket/${caseid}/${id}?token=${localStorage.getItem('JWT')}`
265
+      const wsuri = `${window.location.origin.replace('http', 'ws')}${wsRealPath}?token=${localStorage.getItem('JWT')}`
263 266
       // const wsuri = `ws://192.168.0.11/api/guest/MQ/websocket/${caseid}/${id}`
264 267
       try {
265 268
         this.websock = new WebSocket(wsuri)
@@ -275,14 +278,14 @@ export default {
275 278
     websocketonmessage (e) {
276 279
       // let oldList = this.list
277 280
       let newList = JSON.parse(e.data).data.refreshOnlineGoodsOrders
278
-      let newinfo = newList.filter(x => this.list.filter(item => item.OrdersId === x.OrdersId).length === 0)
279
-      this.updateList({ list: newList }).then(() => {
280
-        for (let i = 0; i < newinfo.length; i++) {
281
-          this.printPdf(`item_${newinfo[i].OrdersId}`)
281
+      // let newinfo = newList.filter(x => this.list.filter(item => item.OrdersId === x.OrdersId).length === 0)
282
+      this.updateList({ list: this.list.concat(newList) }).then(() => {
283
+        newList.forEach((it) => {
284
+          this.printPdf(`item_${it.OrdersId}`)
282 285
           this.putPrintGoodsOrder({
283
-            id: newinfo[i].OrdersId
286
+            id: it.OrdersId
284 287
           })
285
-        }
288
+        })
286 289
       })
287 290
     },
288 291
     open () {

+ 11
- 5
src/util/ajax.js View File

@@ -26,17 +26,14 @@ const Axios = axios.create({
26 26
 
27 27
 Axios.interceptors.request.use((config) => {
28 28
   config.headers.authorization = token()
29
-  config.urlData = { ...config.urlData, org: 'MQ' }
29
+  // config.urlData = { ...config.urlData,  }
30 30
   // 处理请求data,若为get请求,拼到url后面,若为post请求,直接添加到body中
31 31
   let urlData = qs.stringify(config.urlData)
32 32
   let queryData = qs.stringify(config.queryData)
33 33
   // 判断是通过斜杠传参
34 34
   if (config.url.indexOf(':') > -1) {
35 35
     if (typeof config.urlData === 'object') {
36
-      config.url = Object.keys(config.urlData).reduce((url, k) => { // 此方法对每个元素进行处理
37
-        const re = new RegExp(`:${k}(?!w)`, 'i')
38
-        return url.replace(re, config.urlData[k])
39
-      }, config.url)
36
+      config.url = replaceURLParams(config.url, config.urlData)
40 37
     } else {
41 38
       config.url = config.url.slice(0, config.url.indexOf(':')) + urlData
42 39
     }
@@ -83,3 +80,12 @@ const ajax = (...args) => {
83 80
 }
84 81
 
85 82
 export default ajax
83
+
84
+export function replaceURLParams(url, params) {
85
+  const args = { ...(params || {}), org: 'MQ' }
86
+
87
+  return Object.keys(args).reduce((acc, k) => { // 此方法对每个元素进行处理
88
+    const re = new RegExp(`:${k}(?!w)`, 'i')
89
+    return acc.replace(re, args[k])
90
+  }, url)
91
+}

+ 6
- 0
src/util/api.js View File

@@ -23,6 +23,12 @@ const $api = {
23 23
       method: 'put',
24 24
       url: `${baseUrl}${common}/user/:id/password`
25 25
     },
26
+    notify: {
27
+      newGoodsOrders: {
28
+        method: 'put',
29
+        url: `${baseUrl}${common}/websocket/:grps/:id`
30
+      },
31
+    },
26 32
   },
27 33
   systemSet: {
28 34
     getUserList: { // 获取用户列表