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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { useI18n } from '@/hooks/web/useI18n'
import SnowflakeId from 'snowflake-id'
import { ref } from 'vue'
 
const snowflake = new SnowflakeId()
const { t } = useI18n()
 
const guid = () => {
  return snowflake.generate()
}
 
const num = ref(+new Date())
 
const timestampFormatDate = (timestamp, showMs?: boolean) => {
  if (!timestamp || timestamp === -1) {
    return '-'
  }
 
  const date = new Date(timestamp)
 
  const y = date.getFullYear()
 
  let MM = date.getMonth() + 1
  MM = (MM < 10 ? '0' + MM : MM) as number
 
  let d = date.getDate()
  d = (d < 10 ? '0' + d : d) as number
 
  let h = date.getHours()
  h = (h < 10 ? '0' + h : h) as number
 
  let m = date.getMinutes()
  m = (m < 10 ? '0' + m : m) as number
 
  let s = date.getSeconds()
  s = (s < 10 ? '0' + s : s) as number
 
  let format = y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
 
  if (showMs === true) {
    const ms = date.getMilliseconds()
    format += ':' + ms
  }
 
  return format
}
 
const defaultValueScopeList = [
  { label: t('dataset.scope_edit'), value: 'EDIT' },
  { label: t('dataset.scope_all'), value: 'ALLSCOPE' }
]
const fieldOptions = [
  { label: t('dataset.text'), value: 'TEXT' },
  { label: t('dataset.value'), value: 'LONG' },
  {
    label: t('dataset.value') + '(' + t('dataset.float') + ')',
    value: 'DOUBLE'
  },
  { label: t('dataset.time_year'), value: 'DATETIME-YEAR' },
  {
    label: t('dataset.time_year_month'),
    value: 'DATETIME-YEAR-MONTH',
    children: [
      {
        value: 'YYYY-MM',
        label: 'YYYY-MM'
      },
      {
        value: 'YYYY/MM',
        label: 'YYYY/MM'
      }
    ]
  },
  {
    label: t('dataset.time_year_month_day'),
    value: 'DATETIME-YEAR-MONTH-DAY',
    children: [
      {
        value: 'YYYY-MM-DD',
        label: 'YYYY-MM-DD'
      },
      {
        value: 'YYYY/MM/DD',
        label: 'YYYY/MM/DD'
      }
    ]
  },
  {
    label: t('dataset.time_all'),
    value: 'DATETIME',
    children: [
      {
        value: 'YYYY-MM-DD HH:mm:ss',
        label: 'YYYY-MM-DD HH:MI:SS'
      },
      {
        value: 'YYYY/MM/DD HH:mm:ss',
        label: 'YYYY/MM/DD HH:MI:SS'
      }
    ]
  }
]
 
const getFieldName = (fields, name) => {
  let n = name
  n = n + '_copy'
  for (let i = 0; i < fields.length; i++) {
    const field = fields[i]
    if (field.name === n) {
      n = getFieldName(fields, n)
    }
  }
  return n
}
 
const timeTypes = [
  'yyyy-MM-dd',
  'yyyy/MM/dd',
  'yyyy-MM-dd HH:mm:ss',
  'yyyy/MM/dd HH:mm:ss',
  'custom'
]
 
type NodeType = 'db' | 'sql'
type UnionType = 'left' | 'right' | 'inner'
interface UnionField {
  currentField: Field
  parentField: Field
}
interface Node {
  tableName: string
  type: NodeType
  datasourceId: string
  id: string
  unionType: UnionType
  unionFields: UnionField[]
  info: string
  sqlVariableDetails: string
  currentDsFields: Field[]
  children?: Node[]
  confirm?: boolean
  isShadow?: boolean
  flag?: string
}
 
interface Field {
  checked: boolean
  deExtractType: number
  deType: number
  name: string
  type: string
  originName: string
  id: string
}
 
interface DataSource {
  id: string
  name: string
  children?: DataSource[]
}
 
export {
  NodeType,
  UnionType,
  UnionField,
  DataSource,
  Node,
  Field,
  timestampFormatDate,
  defaultValueScopeList,
  fieldOptions,
  guid,
  getFieldName,
  num,
  timeTypes
}