wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { useI18n } from '@/hooks/web/useI18n'
import request from '@/config/axios'
const { t } = useI18n()
export interface ShortcutRequest {
  keyword?: string
  type?: string
  asc?: boolean
}
interface TableColumn {
  field: string
  label: string
  type?: string
}
interface BusiRecord {
  columnList: TableColumn[]
  url: string
  busiList: string[]
  dataCache?: any[]
}
class ShortcutOption {
  busiFlag: string
  busiRecordMap: {
    recent: BusiRecord
    store: BusiRecord
    // share: BusiRecord
  }
 
  constructor() {
    this.busiFlag = 'recent'
    this.busiRecordMap = {
      recent: {
        url: '/dataVisualization/findRecent',
        busiList: ['panel', 'screen', 'dataset', 'datasource'],
        dataCache: [],
        columnList: [
          { field: 'type', label: t('datasource.type') },
          { field: 'creator', label: t('visualization.create_by') },
          { field: 'lastEditor', label: t('work_branch.last_edited_by') },
          { field: 'lastEditTime', label: t('work_branch.last_edit_time'), type: 'time' }
        ]
      },
      store: {
        url: '/store/query',
        busiList: ['panel', 'screen'],
        dataCache: [],
        columnList: [
          { field: 'type', label: t('datasource.type') },
          { field: 'creator', label: t('visualization.create_by') },
          { field: 'lastEditor', label: t('work_branch.last_edited_by') },
          { field: 'lastEditTime', label: t('work_branch.last_edit_time'), type: 'time' }
        ]
      }
    }
  }
  getColumnList() {
    return this.busiRecordMap[this.busiFlag].columnList
  }
  loadData(param: ShortcutRequest): Promise<IResponse> {
    const url = this.busiRecordMap[this.busiFlag].url
    if (this.emptyParam(param) && this.getCacheData()?.length) {
      return new Promise(res => {
        const result = {
          code: 200,
          data: this.getCacheData(),
          msg: null
        }
        return res(result)
      })
    }
    return request.post({ url, data: param }).then(res => {
      const data = res.data
      if (this.emptyParam(param)) {
        this.busiRecordMap[this.busiFlag].dataCache = data
      }
      return res
    })
  }
  getCacheData() {
    return this.busiRecordMap[this.busiFlag].dataCache
  }
  emptyParam(param: ShortcutRequest) {
    return param.asc == null && !param.keyword && !param.type
  }
  setBusiFlag(busiFlag) {
    this.busiFlag = busiFlag
  }
  getBusiList() {
    const all = 'all_types'
    return [all, ...this.busiRecordMap[this.busiFlag].busiList]
  }
}
 
export const shortcutOption = new ShortcutOption()