@a2simcode/ui 0.0.70 → 0.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,207 +1,439 @@
1
- <template>
2
- <div class="j-block j-user-center-log" style="height: 600px;">
3
- <j-page :noPadding="true" :schema="schema" ref="indexRef" />
4
- </div>
5
- </template>
6
- <script lang="ts" setup>
7
- import type { TableColumnCompConfig, ColumnSchemaConfig,LayerParamType } from '@a2simcode/ui';
8
-
9
- import { ref, h, defineComponent, resolveComponent } from 'vue';
10
- import { iconLoaded, loadIcon } from '@iconify/vue';
11
-
12
- const indexRef = ref();
13
-
14
- const ExecuteResultLayer = defineComponent({
15
- name: 'ExecuteResultLayer',
16
- props: {
17
- text: {
18
- type: String,
19
- default: '',
20
- },
21
- },
22
- setup(props) {
23
- const JCodeMirror = resolveComponent('j-code-mirror');
24
- return () =>
25
- h(
26
- JCodeMirror,
27
- {
28
- readOnly: true,
29
- value: props.text || '',
30
- }
31
- );
32
- },
33
- });
34
-
35
- const browsers = [
36
- { name: 'Chrome', icon: 'logos:chrome' },
37
- { name: 'Firefox', icon: 'logos:firefox' },
38
- { name: 'Safari', icon: 'logos:safari' },
39
- { name: 'Edge', icon: 'logos:microsoft-edge' },
40
- ];
41
-
42
- interface ColumnType {
43
- label: string;
44
- id: string;
45
- }
46
-
47
- const columns: ColumnType[] = [
48
- { label: '浏览器', id: 'j_BrowserTag' },
49
- {
50
- label: '类型',
51
- id: 'j_CategoryId',
52
- },
53
- { label: '时间', id: 'j_CreateDate' },
54
- { label: '时长(ms)', id: 'j_Times' },
55
- { label: '请求接口', id: 'j_Url' },
56
- { label: '请求类型', id: 'j_OperateType' },
57
- { label: 'IP', id: 'j_IPAddress' },
58
- { label: '结果', id: 'j_Result' },
59
- { label: '描述', id: 'j_ExecuteResult' },
60
- ];
61
-
62
- const columnsConfig: Record<string, TableColumnCompConfig> = {
63
- j_BrowserTag: {
64
- width: 72,
65
- type: 'j-icon',
66
- align: 'center',
67
- },
68
- j_CategoryId: {
69
- type: 'j-tag',
70
- width: 72,
71
- align: 'center',
72
- dataType: 'options',
73
- options: [
74
- { label: '登录', value: 1, color: '#e8ffea' },
75
- { label: '访问', value: 2, color: '#e8f3ff' },
76
- { label: '操作', value: 3, color: '#e5f9f8' },
77
- { label: '文件下载', value: 5, color: '#fff7e8' },
78
- { label: '文件预览', value: 6, color: '#f5f2ff' },
79
- { label: '接口请求', value: 7, color: '#f0f5ff' },
80
- { label: '接口限流', value: 8, color: '#fffce8' },
81
- { label: '接口熔断', value: 9, color: '#fff2e8' },
82
- { label: '异常', value: 4, color: '#ffece8' },
83
- ],
84
- },
85
- j_CreateDate: {
86
- width: 160,
87
- dataType: 'dateTime',
88
- },
89
- j_Times: {
90
- width: 80,
91
- align: 'center',
92
- },
93
- j_Url: {
94
- width: 200,
95
- isSearchKeyword: true,
96
- },
97
- j_OperateType: {
98
- width: 80,
99
- align: 'center',
100
- },
101
-
102
- j_IPAddress: {
103
- width: 120,
104
- isSearchKeyword: true,
105
- },
106
- j_Result: {
107
- type: 'j-tag',
108
- width: 72,
109
- align: 'center',
110
- dataType: 'options',
111
- fieldFormat: (row: Record<string, any>) => (row.j_Result === 1 ? 1 : 2),
112
- options: [
113
- { label: '成功', value: 1, color: '#e8ffea' },
114
- { label: '失败', value: 2, color: '#ffece8' },
115
- ],
116
- },
117
- j_ExecuteResult: {
118
- type: 'link',
119
- width: 60,
120
- align: 'center',
121
- fieldFormat: () => '查看',
122
- click: ({ row, openLayer }: { row: any,openLayer: (params: LayerParamType) => void }) => {
123
- openLayer({
124
- title: '描述',
125
- name: ExecuteResultLayer,
126
- config: { text: row?.j_ExecuteResult || '' },
127
- width: 1000,
128
- height: 600,
129
- hasBtns: false,
130
- });
131
- },
132
- },
133
- };
134
-
135
- const myColumns: ColumnSchemaConfig[] = [];
136
- columns.forEach((item) => {
137
- const config = columnsConfig[item.id || ''] || {};
138
- const schemaItem: ColumnSchemaConfig = {
139
- id: item.id || '',
140
- type: config.type || '',
141
- config: { ...config, label: item.label || '' },
142
- };
143
- myColumns.push(schemaItem);
144
- });
145
-
146
- // Mock API
147
- const api = {
148
- getMyPage: async (params: any) => {
149
- // Simulate API call
150
- await new Promise(resolve => setTimeout(resolve, 300));
151
- return {
152
- total: 20,
153
- rows: Array.from({ length: 10 }).map((_, i) => ({
154
- j_Id: i + 1,
155
- j_BrowserTag: browsers[i % browsers.length].name,
156
- j_CategoryId: (i % 9) + 1,
157
- j_CreateDate: new Date().toISOString(),
158
- j_Times: Math.floor(Math.random() * 1000),
159
- j_Url: `/api/v1/resource/${i}`,
160
- j_OperateType: ['GET', 'POST', 'PUT', 'DELETE'][i % 4],
161
- j_IPAddress: `192.168.1.${i}`,
162
- j_Result: i % 5 === 0 ? 2 : 1,
163
- j_ExecuteResult: JSON.stringify({ status: 200, message: 'Success' })
164
- }))
1
+ <template>
2
+ <div class="j-block j-user-center-log" style="height: 600px">
3
+ <j-page :noPadding="true" :schema="schema" />
4
+ </div>
5
+ </template>
6
+ <script lang="ts" setup>
7
+ import type { TableColumnCompConfig, ColumnSchemaConfig, LayerParamType } from '@a2simcode/ui'
8
+
9
+ import { ref, h, defineComponent, resolveComponent } from 'vue'
10
+ import { iconLoaded, loadIcon } from '@iconify/vue'
11
+
12
+ const ExecuteResultLayer = defineComponent({
13
+ name: 'ExecuteResultLayer',
14
+ props: {
15
+ text: {
16
+ type: String,
17
+ default: '',
18
+ },
19
+ },
20
+ setup(props) {
21
+ const JCodeMirror = resolveComponent('j-code-mirror')
22
+ return () =>
23
+ h(JCodeMirror, {
24
+ readOnly: true,
25
+ value: props.text || '',
26
+ })
27
+ },
28
+ })
29
+
30
+ const browsers = [
31
+ { name: 'Chrome', icon: 'logos:chrome' },
32
+ { name: 'Firefox', icon: 'logos:firefox' },
33
+ { name: 'Safari', icon: 'logos:safari' },
34
+ { name: 'Edge', icon: 'logos:microsoft-edge' },
35
+ ]
36
+
37
+ interface ColumnType {
38
+ label: string
39
+ id: string
40
+ }
41
+
42
+ const columns: ColumnType[] = [
43
+ { label: '浏览器', id: 'j_BrowserTag' },
44
+ {
45
+ label: '类型',
46
+ id: 'j_CategoryId',
47
+ },
48
+ { label: '时间', id: 'j_CreateDate' },
49
+ { label: '时长(ms)', id: 'j_Times' },
50
+ { label: '请求接口', id: 'j_Url' },
51
+ { label: '请求类型', id: 'j_OperateType' },
52
+ { label: 'IP', id: 'j_IPAddress' },
53
+ { label: '结果', id: 'j_Result' },
54
+ { label: '描述', id: 'j_ExecuteResult' },
55
+ ]
56
+
57
+ const columnsConfig: Record<string, TableColumnCompConfig> = {
58
+ j_BrowserTag: {
59
+ width: 72,
60
+ type: 'j-icon',
61
+ align: 'center',
62
+ dataType: 'options',
63
+ fieldFormat: (row: Record<string, any>) =>
64
+ browsers.find((b) => b.name === row.j_BrowserTag)?.icon || '',
65
+ options: browsers.map((b) => ({ label: b.name, value: b.name })),
66
+ },
67
+ j_CategoryId: {
68
+ type: 'j-tag',
69
+ width: 100,
70
+ align: 'center',
71
+ dataType: 'options',
72
+ options: [
73
+ { label: '登录', value: 1, color: '#e8ffea' },
74
+ { label: '访问', value: 2, color: '#e8f3ff' },
75
+ { label: '操作', value: 3, color: '#e5f9f8' },
76
+ { label: '文件下载', value: 5, color: '#fff7e8' },
77
+ { label: '文件预览', value: 6, color: '#f5f2ff' },
78
+ { label: '接口请求', value: 7, color: '#f0f5ff' },
79
+ { label: '接口限流', value: 8, color: '#fffce8' },
80
+ { label: '接口熔断', value: 9, color: '#fff2e8' },
81
+ { label: '异常', value: 4, color: '#ffece8' },
82
+ ],
83
+ },
84
+ j_CreateDate: {
85
+ width: 168,
86
+ type: 'dateTime',
87
+ },
88
+ j_Times: {
89
+ width: 80,
90
+ align: 'center',
91
+ type: 'number',
92
+ },
93
+ j_Url: {
94
+ width: 200,
95
+ isSearchKeyword: true,
96
+ },
97
+ j_OperateType: {
98
+ width: 96,
99
+ align: 'center',
100
+ type: 'j-tag',
101
+ dataType: 'options',
102
+ options: [
103
+ { label: 'GET', value: 'GET', color: '#e8f3ff' },
104
+ { label: 'POST', value: 'POST', color: '#e8ffea' },
105
+ { label: 'PUT', value: 'PUT', color: '#fff7e8' },
106
+ { label: 'DELETE', value: 'DELETE', color: '#ffece8' },
107
+ ],
108
+ },
109
+
110
+ j_IPAddress: {
111
+ width: 120,
112
+ isSearchKeyword: true,
113
+ },
114
+ j_Result: {
115
+ type: 'j-tag',
116
+ width: 72,
117
+ align: 'center',
118
+ dataType: 'options',
119
+ fieldFormat: (row: Record<string, any>) => (row.j_Result === 1 ? 1 : 2),
120
+ options: [
121
+ { label: '成功', value: 1, color: '#e8ffea' },
122
+ { label: '失败', value: 2, color: '#ffece8' },
123
+ ],
124
+ },
125
+ j_ExecuteResult: {
126
+ type: 'link',
127
+ width: 60,
128
+ align: 'center',
129
+ frozen: 'right',
130
+ fieldFormat: () => '查看',
131
+ click: ({ row, openLayer }: { row: any; openLayer: (params: LayerParamType) => void }) => {
132
+ openLayer({
133
+ title: '描述',
134
+ name: ExecuteResultLayer,
135
+ config: { text: row?.j_ExecuteResult || '' },
136
+ width: 1000,
137
+ height: 600,
138
+ hasBtns: false,
139
+ })
140
+ },
141
+ },
142
+ }
143
+
144
+ const myColumns: ColumnSchemaConfig[] = []
145
+ columns.forEach((item) => {
146
+ const config = columnsConfig[item.id || ''] || {}
147
+ const schemaItem: ColumnSchemaConfig = {
148
+ id: item.id || '',
149
+ type: config.type || '',
150
+ config: { ...config, label: item.label || '' },
151
+ }
152
+ myColumns.push(schemaItem)
153
+ })
154
+
155
+ // Mock API
156
+ const mockData = Array.from({ length: 100 }).map((_, i) => ({
157
+ j_Id: i + 1,
158
+ j_BrowserTag: browsers[i % browsers.length].name,
159
+ j_CategoryId: (i % 9) + 1,
160
+ j_CreateDate: new Date(Date.now() - Math.floor(Math.random() * 1000000000)).toISOString(),
161
+ j_Times: Math.floor(Math.random() * 1000),
162
+ j_Url: `/api/v1/resource/${i}`,
163
+ j_OperateType: ['GET', 'POST', 'PUT', 'DELETE'][i % 4],
164
+ j_IPAddress: `192.168.1.${i}`,
165
+ j_Result: i % 5 === 0 ? 2 : 1,
166
+ j_ExecuteResult: JSON.stringify({ status: 200, message: 'Success' }),
167
+ }))
168
+
169
+ const api = {
170
+ getMyPage: async (params: any) => {
171
+ console.log(JSON.stringify(params), 'params')
172
+ // Simulate API call
173
+ await new Promise((resolve) => setTimeout(resolve, 300))
174
+
175
+ let result = [...mockData]
176
+
177
+ // Filter
178
+ if (params.filter && params.filter.cond && params.filter.cond.length > 0) {
179
+ const { rel, cond } = params.filter
180
+ const parseDateVal = (s: string) => {
181
+ if (!s) return NaN
182
+ const str = s.includes('T') ? s : s.replace(' ', 'T')
183
+ const d = new Date(str)
184
+ return d.getTime()
185
+ }
186
+ const dayStart = (d: Date) =>
187
+ new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0).getTime()
188
+ const dayEnd = (d: Date) =>
189
+ new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59, 999).getTime()
190
+ const monthStart = (y: number, m: number) => new Date(y, m, 1, 0, 0, 0, 0).getTime()
191
+ const monthEnd = (y: number, m: number) => new Date(y, m + 1, 0, 23, 59, 59, 999).getTime()
192
+ const quarterRange = (y: number, q: number) => {
193
+ const startMonth = (q - 1) * 3
194
+ const start = monthStart(y, startMonth)
195
+ const end = monthEnd(y, startMonth + 2)
196
+ return [start, end] as const
197
+ }
198
+ const weekStartEnd = (d: Date) => {
199
+ const dow = (d.getDay() + 6) % 7
200
+ const startD = new Date(d)
201
+ startD.setDate(d.getDate() - dow)
202
+ const endD = new Date(startD)
203
+ endD.setDate(startD.getDate() + 6)
204
+ return [dayStart(startD), dayEnd(endD)] as const
205
+ }
206
+ const rangeFromFormula = (f: string) => {
207
+ const now = new Date()
208
+ if (f === 'today') return [dayStart(now), dayEnd(now)] as const
209
+ if (f === 'yesterday') {
210
+ const d = new Date(now)
211
+ d.setDate(now.getDate() - 1)
212
+ return [dayStart(d), dayEnd(d)] as const
213
+ }
214
+ if (f === 'tomorrow') {
215
+ const d = new Date(now)
216
+ d.setDate(now.getDate() + 1)
217
+ return [dayStart(d), dayEnd(d)] as const
218
+ }
219
+ if (f === 'last7days') {
220
+ const end = dayEnd(now)
221
+ const d = new Date(now)
222
+ d.setDate(now.getDate() - 6)
223
+ const start = dayStart(d)
224
+ return [start, end] as const
225
+ }
226
+ if (f === 'last30days') {
227
+ const end = dayEnd(now)
228
+ const d = new Date(now)
229
+ d.setDate(now.getDate() - 29)
230
+ const start = dayStart(d)
231
+ return [start, end] as const
232
+ }
233
+ if (f === 'thisWeek') return weekStartEnd(now)
234
+ if (f === 'lastWeek') {
235
+ const d = new Date(now)
236
+ d.setDate(now.getDate() - 7)
237
+ return weekStartEnd(d)
238
+ }
239
+ if (f === 'nextWeek') {
240
+ const d = new Date(now)
241
+ d.setDate(now.getDate() + 7)
242
+ return weekStartEnd(d)
243
+ }
244
+ if (f === 'thisMonth') {
245
+ const y = now.getFullYear()
246
+ const m = now.getMonth()
247
+ return [monthStart(y, m), monthEnd(y, m)] as const
248
+ }
249
+ if (f === 'lastMonth') {
250
+ const d = new Date(now)
251
+ d.setMonth(now.getMonth() - 1)
252
+ const y = d.getFullYear()
253
+ const m = d.getMonth()
254
+ return [monthStart(y, m), monthEnd(y, m)] as const
165
255
  }
256
+ if (f === 'nextMonth') {
257
+ const d = new Date(now)
258
+ d.setMonth(now.getMonth() + 1)
259
+ const y = d.getFullYear()
260
+ const m = d.getMonth()
261
+ return [monthStart(y, m), monthEnd(y, m)] as const
262
+ }
263
+ if (f === 'thisQuarter') {
264
+ const y = now.getFullYear()
265
+ const q = Math.floor(now.getMonth() / 3) + 1
266
+ return quarterRange(y, q)
267
+ }
268
+ if (f === 'lastQuarter') {
269
+ let y = now.getFullYear()
270
+ let q = Math.floor(now.getMonth() / 3)
271
+ if (q === 0) {
272
+ q = 4
273
+ y = y - 1
274
+ }
275
+ return quarterRange(y, q)
276
+ }
277
+ if (f === 'nextQuarter') {
278
+ let y = now.getFullYear()
279
+ let q = Math.floor(now.getMonth() / 3) + 2
280
+ if (q === 5) {
281
+ q = 1
282
+ y = y + 1
283
+ }
284
+ return quarterRange(y, q)
285
+ }
286
+ if (f === 'thisYear') {
287
+ const y = now.getFullYear()
288
+ return [
289
+ new Date(y, 0, 1).getTime(),
290
+ new Date(y, 11, 31, 23, 59, 59, 999).getTime(),
291
+ ] as const
292
+ }
293
+ if (f === 'lastYear') {
294
+ const y = now.getFullYear() - 1
295
+ return [
296
+ new Date(y, 0, 1).getTime(),
297
+ new Date(y, 11, 31, 23, 59, 59, 999).getTime(),
298
+ ] as const
299
+ }
300
+ if (f === 'nextYear') {
301
+ const y = now.getFullYear() + 1
302
+ return [
303
+ new Date(y, 0, 1).getTime(),
304
+ new Date(y, 11, 31, 23, 59, 59, 999).getTime(),
305
+ ] as const
306
+ }
307
+ return [NaN, NaN] as const
308
+ }
309
+ result = result.filter((item) => {
310
+ const matches = cond.map((c: any) => {
311
+ const rawVal = item[c.field as keyof typeof item]
312
+ const val = rawVal == null ? '' : String(rawVal)
313
+ const target = c.value == null ? '' : String(c.value)
314
+
315
+ if (c.type === 'dateTime') {
316
+ const ts = parseDateVal(val)
317
+ if (c.method === 'eq') {
318
+ const t = parseDateVal(target)
319
+ return ts === t
320
+ } else if (c.method === 'ne') {
321
+ const t = parseDateVal(target)
322
+ return ts !== t
323
+ } else if (c.method === 'gte') {
324
+ const t = parseDateVal(target)
325
+ return ts >= t
326
+ } else if (c.method === 'lte') {
327
+ const t = parseDateVal(target)
328
+ return ts <= t
329
+ } else if (c.method === 'range') {
330
+ if (!target) return true
331
+ const [s, e] = target.split(',')
332
+ const st = parseDateVal(s)
333
+ const et = parseDateVal(e)
334
+ if (isNaN(st) && isNaN(et)) return true
335
+ if (!isNaN(st) && !isNaN(et)) return ts >= st && ts <= et
336
+ if (!isNaN(st) && isNaN(et)) return ts >= st
337
+ if (isNaN(st) && !isNaN(et)) return ts <= et
338
+ return true
339
+ } else if (c.method === 'formula') {
340
+ const [st, et] = rangeFromFormula(target)
341
+ if (isNaN(st) || isNaN(et)) return true
342
+ return ts >= st && ts <= et
343
+ } else if (c.method === 'not_empty') {
344
+ return val !== '' && val !== 'null' && val !== 'undefined'
345
+ } else if (c.method === 'empty') {
346
+ return val === '' || val === 'null' || val === 'undefined'
347
+ }
348
+ return false
349
+ } else {
350
+ if (c.method === 'eq') {
351
+ return val === target
352
+ } else if (c.method === 'ne') {
353
+ return val !== target
354
+ } else if (c.method === 'like') {
355
+ return val.includes(target)
356
+ } else if (c.method === 'unlike') {
357
+ return !val.includes(target)
358
+ } else if (c.method === 'in') {
359
+ const targetList = target.split(',')
360
+ return targetList.includes(val)
361
+ } else if (c.method === 'nin') {
362
+ const targetList = target.split(',')
363
+ return !targetList.includes(val)
364
+ } else if (c.method === 'not_empty') {
365
+ return val !== '' && val !== 'null' && val !== 'undefined'
366
+ } else if (c.method === 'empty') {
367
+ return val === '' || val === 'null' || val === 'undefined'
368
+ }
369
+ }
370
+ return false
371
+ })
372
+
373
+ if (rel === 'and') return matches.every((x: boolean) => x)
374
+ if (rel === 'or') return matches.some((x: boolean) => x)
375
+ return true
376
+ })
166
377
  }
167
- }
168
-
169
- const schema = [
170
- {
171
- id: 'mainTable',
172
- type: 'j-table-panel',
173
- config: {
174
- columns: myColumns,
175
- rowKey: 'j_Id',
176
- sort: 'j_CreateDate DESC',
177
- isPage: true,
178
- loadData: async (params: Record<string, any>) => {
179
- let res = await api.getMyPage(params);
180
- if (res && res.rows) {
181
- const iconsToLoad = new Set();
182
- res.rows.forEach((item: any) => {
183
- const browser = browsers.find(
184
- (b) => item.j_BrowserTag && item.j_BrowserTag === b.name
185
- );
186
- if (browser) {
187
- item.j_BrowserTag = browser.icon;
188
- iconsToLoad.add(browser.icon);
189
- }
190
- });
191
-
192
- await Promise.all(
193
- [...iconsToLoad].map(async (icon) => {
194
- if (!iconLoaded(icon as string)) {
195
- await loadIcon(icon as string);
196
- }
197
- })
198
- );
199
- }
200
-
201
- console.log(res, 'res');
202
- return res;
203
- },
204
- },
205
- },
206
- ];
207
- </script>
378
+
379
+ // Sort
380
+ if (params.pagination && params.pagination.sort) {
381
+ const [field, order] = params.pagination.sort.split(' ')
382
+ result.sort((a, b) => {
383
+ const valA = a[field as keyof typeof a]
384
+ const valB = b[field as keyof typeof b]
385
+ if (valA < valB) return order === 'ASC' ? -1 : 1
386
+ if (valA > valB) return order === 'ASC' ? 1 : -1
387
+ return 0
388
+ })
389
+ }
390
+
391
+ // Pagination
392
+ const page = params.pagination?.page || 1
393
+ const rows = params.pagination?.rows || 20
394
+ const start = (page - 1) * rows
395
+ const end = start + rows
396
+
397
+ return {
398
+ total: result.length,
399
+ rows: result.slice(start, end),
400
+ }
401
+ },
402
+ }
403
+
404
+ const schema = [
405
+ {
406
+ id: 'mainTable',
407
+ type: 'j-table-panel',
408
+ config: {
409
+ columns: myColumns,
410
+ rowKey: 'j_Id',
411
+ sort: 'j_CreateDate DESC',
412
+ isPage: true,
413
+ loadData: async (params: Record<string, any>) => {
414
+ let res = await api.getMyPage(params)
415
+ if (res && res.rows) {
416
+ const iconsToLoad = new Set()
417
+ res.rows.forEach((item: any) => {
418
+ const browser = browsers.find((b) => item.j_BrowserTag && item.j_BrowserTag === b.name)
419
+ if (browser) {
420
+ iconsToLoad.add(browser.icon)
421
+ }
422
+ })
423
+
424
+ await Promise.all(
425
+ [...iconsToLoad].map(async (icon) => {
426
+ if (!iconLoaded(icon as string)) {
427
+ await loadIcon(icon as string)
428
+ }
429
+ })
430
+ )
431
+ }
432
+
433
+ console.log(res, 'res')
434
+ return res
435
+ },
436
+ },
437
+ },
438
+ ]
439
+ </script>
@@ -85,6 +85,7 @@ const columns = ref([
85
85
  config: {
86
86
  label: '是否在职',
87
87
  width: 100,
88
+ align: 'center',
88
89
  readonly: true,
89
90
  },
90
91
  },