Browse Source

前台、后台搜索页搜索时重新请求各tab项总数、服务tab项下各项的数量

chaihaorui 1 year ago
parent
commit
3283f7d188
2 changed files with 84 additions and 121 deletions
  1. 41 67
      src/pages/homepage/components/searchPage.vue
  2. 43 54
      src/pages/index/components/searchPage.vue

+ 41 - 67
src/pages/homepage/components/searchPage.vue

@@ -155,6 +155,15 @@
155 155
 
156 156
 <script>
157 157
 import api from "@/api/homepage/search.js";
158
+const resourceTypeMap = {
159
+  first: 'theme',
160
+  second: 'specialSubject',
161
+  third: 'index',
162
+  fourth: 'service'
163
+}
164
+const tabNames = {
165
+  first: '主题库', second: '专题库',third: '指标', fourth: '服务'
166
+}
158 167
 export default {
159 168
   data() {
160 169
     return {
@@ -202,24 +211,22 @@ export default {
202 211
       this.getSearchData()
203 212
     },
204 213
     jumpToDetailPage(id) {
205
-      const resourceTypeMap = {
214
+      const resourceTypeMapA = {
206 215
         first: 'theme',
207 216
         second: 'special',
208 217
         third: 'target',
209 218
         fourth: this.serviceType === 'API' ? 'api' : 'message'
210 219
       }
211
-      let type = resourceTypeMap[this.activeName]
220
+      let type = resourceTypeMapA[this.activeName]
212 221
       this.$router.push({
213 222
         name: "entityDetail",
214 223
         path: "/entityDetail",
215
-        query: {
216
-          id: id,
217
-          type
218
-        }
224
+        query: {id: id, type}
219 225
       });
220 226
     },
221 227
     handleSearch() {
222
-      this.getSearchData()
228
+      this.initData()
229
+      this.getMenu()
223 230
     },
224 231
     getCardClass() {
225 232
       let ret = 'entity-card'
@@ -239,12 +246,6 @@ export default {
239 246
       this.cancelCollect([id])
240 247
     },
241 248
     cancelCollect(ids) {
242
-      const resourceTypeMap = {
243
-        first: 'theme',
244
-        second: 'specialSubject',
245
-        third: 'index',
246
-        fourth: 'service'
247
-      }
248 249
       const params = {resourceType: resourceTypeMap[this.activeName], resourceIds: ids,}
249 250
       api.deleteCollect(params).then(res => {
250 251
         if (res.success) {
@@ -272,14 +273,10 @@ export default {
272 273
     handleUp() {
273 274
       console.log('up')
274 275
     },
275
-    // 初始化tablist 数据,并请求每个tab项的总数
276
+    // 1.初始化tablist 数据,2.请求每个tab项包含数据的总数, 3.请求右侧列表数据
276 277
     initData() {
277
-      let tabList = [
278
-        {name: '主题库',id: 'first'},
279
-        {name: '专题库',id: 'second'},
280
-        {name: '指标',id: 'third'},
281
-        {name: '服务',id: 'fourth'}
282
-      ]
278
+      let tabList = [{name: '主题库',id: 'first'}, {name: '专题库',id: 'second'},
279
+        {name: '指标',id: 'third'}, {name: '服务',id: 'fourth'}]
283 280
       if (this.$route.query.pageType === 'theme') {
284 281
         tabList = [{ name: '主题库', id: 'first' }]
285 282
         this.activeName = 'first'
@@ -302,17 +299,10 @@ export default {
302 299
       }
303 300
       this.tabList = tabList
304 301
       if (this.pageType === 'all') {
305
-        api.esItemDataNum({resourceType: 'theme', shelvesType: '1'}).then(res => {
306
-          this.tabList[0].name = `主题库(${res.data})`
307
-        })
308
-        api.esItemDataNum({resourceType: 'specialSubject', shelvesType: '1'}).then(res => {
309
-          this.tabList[1].name = `专题库(${res.data})`
310
-        })
311
-        api.esItemDataNum({resourceType: 'index', shelvesType: '1'}).then(res => {
312
-          this.tabList[2].name = `指标(${res.data})`
313
-        })
314
-        api.esItemDataNum({resourceType: 'service', shelvesType: '1'}).then(res => {
315
-          this.tabList[3].name = `服务(${res.data})`
302
+        this.tabList.map((item, index) => {
303
+          api.esItemDataNum({resourceType: resourceTypeMap[item.id], shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}).then(res => {
304
+            this.tabList[index].name = `${tabNames[item.id]}(${res.data})`
305
+          })
316 306
         })
317 307
       }
318 308
       if (this.pageType === 'collect') {
@@ -321,30 +311,15 @@ export default {
321 311
       this.getSearchData()
322 312
     },
323 313
     getCollectTabTotal() {
324
-      api.collectMenuDataNum({resourceType: 'theme'}).then(res => {
325
-        this.tabList[0].name = `主题库(${res.data})`
326
-      })
327
-      api.collectMenuDataNum({resourceType: 'specialSubject'}).then(res => {
328
-        this.tabList[1].name = `专题库(${res.data})`
329
-      })
330
-      api.collectMenuDataNum({resourceType: 'index'}).then(res => {
331
-        this.tabList[2].name = `指标(${res.data})`
332
-      })
333
-      api.collectMenuDataNum({resourceType: 'service'}).then(res => {
334
-        this.tabList[3].name = `服务(${res.data})`
314
+      this.tabList.map((item, index) => {
315
+        api.collectMenuDataNum({resourceType: resourceTypeMap[item.id], menuId: this.menuId, resourceName: this.searchWords}).then(res => {
316
+          this.tabList[index].name = `${tabNames[item.id]}(${res.data})`
317
+        })
335 318
       })
336 319
     },
320
+    // 获取树形列表数据,并在tab选项为服务时请求所有树形数据项对应包含的数据条数
337 321
     getMenu() {
338
-      const params = {resourceType: 'theme'}
339
-      if (this.activeName === 'second') {
340
-        params.resourceType = 'specialSubject'
341
-      }
342
-      if (this.activeName === 'third') {
343
-        params.resourceType = 'index'
344
-      }
345
-      if (this.activeName === 'fourth') {
346
-        params.resourceType = 'service'
347
-      }
322
+      const params = {resourceType: resourceTypeMap[this.activeName]}
348 323
       api.menuInfo(params).then(res => {
349 324
         if (res.success) {
350 325
           this.data = res.data
@@ -361,21 +336,18 @@ export default {
361 336
       this.getSearchData()
362 337
     },
363 338
     getSearchData() {
339
+      const resourceTypeMapB = {
340
+        first: 'theme',
341
+        second: 'specialSubject',
342
+        third: 'index',
343
+        fourth: this.serviceType === 'API' ? 'api' : 'mqs'
344
+      }
364 345
       const params = {
365
-        resourceType: 'theme', pageNum: this.currentPage, 
346
+        resourceType: resourceTypeMapB[this.activeName], pageNum: this.currentPage, 
366 347
         pageSize: this.pageSize, menuId: this.menuId,
367 348
         keyword: this.searchWords,
368 349
         shelvesType: '1'
369 350
       }
370
-      if (this.activeName === 'second') {
371
-        params.resourceType = 'specialSubject'
372
-      }
373
-      if (this.activeName === 'third') {
374
-        params.resourceType = 'index'
375
-      }
376
-      if (this.activeName === 'fourth') {
377
-        params.resourceType = this.serviceType === 'API' ? 'api' : 'mqs'
378
-      }
379 351
       if (this.pageType === 'collect') {
380 352
         params.shelvesType = undefined
381 353
         params.keyword = undefined
@@ -414,12 +386,14 @@ export default {
414 386
       }
415 387
     },
416 388
     getServiceStatNum() {
417
-      let params = {resourceType: 'api', shelvesType: '1'}
389
+      let params = {resourceType: 'api', shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}
418 390
       if (this.serviceType === 'MQ') {
419 391
         params.resourceType = 'mqs'
420 392
       }
421 393
       if (this.pageType === 'collect') {
422 394
         params.shelvesType = undefined
395
+        params.keyword = undefined
396
+        params.resourceName = this.searchWords
423 397
         api.collectMenuStatNum(params).then(res => {
424 398
           this.handleMenuStatNumRes(res)
425 399
         })
@@ -448,22 +422,22 @@ export default {
448 422
       this.currentPage = 1
449 423
     },
450 424
     getThemeTotal() {
451
-      api.esItemDataNum({resourceType: 'theme', shelvesType: '1'}).then(res => {
425
+      api.esItemDataNum({resourceType: 'theme', shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}).then(res => {
452 426
         this.tabList[0].name = `主题库(${res.data})`
453 427
       })
454 428
     },
455 429
     getSpecialTotal() {
456
-      api.esItemDataNum({resourceType: 'specialSubject', shelvesType: '1'}).then(res => {
430
+      api.esItemDataNum({resourceType: 'specialSubject', shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}).then(res => {
457 431
         this.tabList[0].name = `专题库(${res.data})`
458 432
       })
459 433
     },
460 434
     getIndexTotal() {
461
-      api.esItemDataNum({resourceType: 'index', shelvesType: '1'}).then(res => {
435
+      api.esItemDataNum({resourceType: 'index', shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}).then(res => {
462 436
         this.tabList[0].name = `指标(${res.data})`
463 437
       })
464 438
     },
465 439
     getServiceTotal() {
466
-      api.esItemDataNum({resourceType: 'service', shelvesType: '1'}).then(res => {
440
+      api.esItemDataNum({resourceType: 'service', shelvesType: '1', menuId: this.menuId, keyword: this.searchWords}).then(res => {
467 441
         this.tabList[0].name = `服务(${res.data})`
468 442
       })
469 443
     }

+ 43 - 54
src/pages/index/components/searchPage.vue

@@ -258,17 +258,19 @@ export default {
258 258
       this.getSearchData()
259 259
     },
260 260
     getEveryTabTotal() {
261
-      api.esItemDataNum({resourceType: 'theme'}).then(res => {
262
-        this.tabList[0].name = `主题库(${res.data})`
263
-      })
264
-      api.esItemDataNum({resourceType: 'specialSubject'}).then(res => {
265
-        this.tabList[1].name = `专题库(${res.data})`
266
-      })
267
-      api.esItemDataNum({resourceType: 'index'}).then(res => {
268
-        this.tabList[2].name = `指标(${res.data})`
269
-      })
270
-      api.esItemDataNum({resourceType: 'service'}).then(res => {
271
-        this.tabList[3].name = `服务(${res.data})`
261
+      const resourceTypeMap = {
262
+        first: 'theme',
263
+        second: 'specialSubject',
264
+        third: 'index',
265
+        fourth: 'service'
266
+      }
267
+      const tabNames = {
268
+        first: '主题库', second: '专题库',third: '指标', fourth: '服务'
269
+      }
270
+      this.tabList.map((item, index) => {
271
+        api.esItemDataNum({resourceType: resourceTypeMap[item.id], menuId: this.menuId, keyword: this.searchWords}).then(res => {
272
+          this.tabList[index].name = `${tabNames[item.id]}(${res.data})`
273
+        })
272 274
       })
273 275
     },
274 276
     handleNodeClick(data) {
@@ -284,26 +286,22 @@ export default {
284 286
       this.getSearchData()
285 287
     },
286 288
     jumpToDetailPage(id) {
287
-      let type = 'theme'
288
-      if (this.activeName === 'second') {
289
-        type = 'special'
290
-      }
291
-      if (this.activeName === 'third') {
292
-        type = 'target'
293
-      }
294
-      if (this.activeName === 'fourth') {
295
-        type = this.serviceType === 'API' ? 'api' : 'message'
289
+      const resourceTypeMap = {
290
+        first: 'theme',
291
+        second: 'special',
292
+        third: 'target',
293
+        fourth: this.serviceType === 'API' ? 'api' : 'message'
296 294
       }
295
+      let type = resourceTypeMap[this.activeName]
297 296
       this.$router.push({
298 297
         name: "entityDetail",
299 298
         path: "/entityDetail",
300
-        query: {
301
-          id: id,
302
-          type
303
-        }
299
+        query: {id: id, type}
304 300
       });
305 301
     },
306 302
     handleSearch() {
303
+      this.getEveryTabTotal()
304
+      this.getMenu()
307 305
       this.getSearchData()
308 306
     },
309 307
     getCardClass() {
@@ -322,7 +320,7 @@ export default {
322 320
       } else {
323 321
         this.selectIds = this.selectIds.filter(item => item !== id)
324 322
       }
325
-      console.log('selectIds', this.selectIds)
323
+      // console.log('selectIds', this.selectIds)
326 324
     },
327 325
     handleDown(id) {
328 326
       const params = this.getListingParam()
@@ -345,16 +343,13 @@ export default {
345 343
       })
346 344
     },
347 345
     getMenu() {
348
-      const params = {resourceType: 'theme'}
349
-      if (this.activeName === 'second') {
350
-        params.resourceType = 'specialSubject'
351
-      }
352
-      if (this.activeName === 'third') {
353
-        params.resourceType = 'index'
354
-      }
355
-      if (this.activeName === 'fourth') {
356
-        params.resourceType = 'service'
346
+      const resourceTypeMap = {
347
+        first: 'theme',
348
+        second: 'specialSubject',
349
+        third: 'index',
350
+        fourth: 'service'
357 351
       }
352
+      const params = {resourceType: resourceTypeMap[this.activeName]}
358 353
       api.menuInfo(params).then(res => {
359 354
         if (res.success) {
360 355
           this.data = res.data
@@ -371,20 +366,17 @@ export default {
371 366
       this.getSearchData()
372 367
     },
373 368
     getSearchData() {
369
+      const resourceTypeMap = {
370
+        first: 'theme',
371
+        second: 'specialSubject',
372
+        third: 'index',
373
+        fourth: this.serviceType === 'API' ? 'api' : 'mqs'
374
+      }
374 375
       const params = {
375
-        resourceType: 'theme', pageNum: this.currentPage, 
376
+        resourceType: resourceTypeMap[this.activeName], pageNum: this.currentPage, 
376 377
         pageSize: this.pageSize, menuId: this.menuId,
377 378
         keyword: this.searchWords
378 379
       }
379
-      if (this.activeName === 'second') {
380
-        params.resourceType = 'specialSubject'
381
-      }
382
-      if (this.activeName === 'third') {
383
-        params.resourceType = 'index'
384
-      }
385
-      if (this.activeName === 'fourth') {
386
-        params.resourceType = this.serviceType === 'API' ? 'api' : 'mqs'
387
-      }
388 380
       api.searchData(params).then(res => {
389 381
         if(res.success) {
390 382
           this.total = res.data.total
@@ -403,7 +395,7 @@ export default {
403 395
       })
404 396
     },
405 397
     getServiceStatNum() {
406
-      let params = {resourceType: 'api'}
398
+      let params = {resourceType: 'api', menuId: this.menuId, keyword: this.searchWords}
407 399
       if (this.serviceType === 'MQ') {
408 400
         params.resourceType = 'mqs'
409 401
       }
@@ -422,16 +414,13 @@ export default {
422 414
       })
423 415
     },
424 416
     getListingParam() {
425
-      const params = {resourceType: 'theme', resourceIds: this.selectIds,}
426
-      if (this.activeName === 'second') {
427
-        params.resourceType = 'specialSubject'
428
-      }
429
-      if (this.activeName === 'third') {
430
-        params.resourceType = 'index'
431
-      }
432
-      if (this.activeName === 'fourth') {
433
-        params.resourceType = this.serviceType === 'API' ? 'api' : 'mqs'
417
+      const resourceTypeMap = {
418
+        first: 'theme',
419
+        second: 'specialSubject',
420
+        third: 'index',
421
+        fourth: this.serviceType === 'API' ? 'api' : 'mqs'
434 422
       }
423
+      const params = {resourceType: resourceTypeMap[this.activeName], resourceIds: this.selectIds}
435 424
       return params
436 425
     },
437 426
     // 批量上架