wui-components-v2 1.2.37 → 1.2.39
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.
- package/api/page.ts +7 -0
- package/components/form-control/form-control.vue +10 -0
- package/components/report-table/report-table.vue +416 -0
- package/components/search/search.vue +42 -13
- package/components/wui-list/wui-list.vue +10 -2
- package/components/wui-select-list/wui-select-list.vue +8 -1
- package/components/wui-select-popup/wui-select-popup.vue +8 -1
- package/composables/useMenus.ts +1 -3
- package/package.json +1 -1
package/api/page.ts
CHANGED
|
@@ -36,6 +36,13 @@ export function listData(queryKey: string, pageNo: number, pageSize: number): Pr
|
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// 获取报表页面数据
|
|
40
|
+
export function reportData(queryKey: string, pageNo: number, pageSize: number): Promise<PageData> {
|
|
41
|
+
return req({
|
|
42
|
+
url: `/v3/ltmpl/report-data?queryKey=${queryKey}&pageNo=${pageNo}&pageSize=${pageSize}`,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// 获取新增面配置
|
|
40
47
|
export function addPageConfig(sourceId: string) {
|
|
41
48
|
return req({
|
|
@@ -588,6 +588,16 @@ function submit() {
|
|
|
588
588
|
} else {
|
|
589
589
|
data[key] = model.value[key]
|
|
590
590
|
}
|
|
591
|
+
} else if (ControlTypeSupportor.getControlType(item) === 'date') {
|
|
592
|
+
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY-MM-DD') : ''
|
|
593
|
+
} else if (ControlTypeSupportor.getControlType(item) === 'datetime') {
|
|
594
|
+
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY-MM-DD HH:mm:ss') : ''
|
|
595
|
+
} else if (ControlTypeSupportor.getControlType(item) === 'time') {
|
|
596
|
+
data[key] = model.value[key] ? dayjs(model.value[key]).format('HH:mm:ss') : ''
|
|
597
|
+
} else if (ControlTypeSupportor.getControlType(item) === 'date-YY') {
|
|
598
|
+
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY') : ''
|
|
599
|
+
} else if (ControlTypeSupportor.getControlType(item) === 'date-M1') {
|
|
600
|
+
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY-MM') : ''
|
|
591
601
|
} else {
|
|
592
602
|
data[key] = model.value[key]
|
|
593
603
|
}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
3
|
+
import { onLoad } from '@dcloudio/uni-app'
|
|
4
|
+
import { reportData, pageConfig, pageKey } from '../../api/page'
|
|
5
|
+
import type { Columns, Config, Entities, Fields } from '../../type'
|
|
6
|
+
import Search from '../search/search.vue'
|
|
7
|
+
import ListTopButtons from '../list-top-buttons/list-top-buttons.vue'
|
|
8
|
+
import { generateHighResolutionID, formatItemData } from '../../utils/index'
|
|
9
|
+
import tabSearch from '../tab-search/tab-search.vue'
|
|
10
|
+
import { useEnums } from '../../composables/useEnumes'
|
|
11
|
+
import ControlTypeSupportor from '../../utils/control-type-supportor'
|
|
12
|
+
import dayjs from 'dayjs/esm/index'
|
|
13
|
+
import formControl from '../form-control/form-control.vue'
|
|
14
|
+
|
|
15
|
+
defineOptions({
|
|
16
|
+
name: 'WuiReportTable',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(
|
|
20
|
+
defineProps<{
|
|
21
|
+
/** 数据源 ID */
|
|
22
|
+
sourceId?: string
|
|
23
|
+
/** 查询条件 */
|
|
24
|
+
query?: string
|
|
25
|
+
/** 顶部操作按钮区是否显示 */
|
|
26
|
+
showTopButtons?: boolean
|
|
27
|
+
/** 搜索区域是否显示 */
|
|
28
|
+
showSearch?: boolean
|
|
29
|
+
}>(),
|
|
30
|
+
{
|
|
31
|
+
showTopButtons: true,
|
|
32
|
+
showSearch: true,
|
|
33
|
+
sourceId: '',
|
|
34
|
+
query: '',
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const config = ref<Config>({
|
|
39
|
+
buttons: [],
|
|
40
|
+
columns: [],
|
|
41
|
+
primaryColumn: {
|
|
42
|
+
sourceId: '',
|
|
43
|
+
controlType: '',
|
|
44
|
+
mstrucId: '',
|
|
45
|
+
extControlType: '',
|
|
46
|
+
},
|
|
47
|
+
primaryCriterion: {
|
|
48
|
+
hidden: false,
|
|
49
|
+
disabled: false,
|
|
50
|
+
defaultValue: '',
|
|
51
|
+
transDefaultValue: '',
|
|
52
|
+
required: false,
|
|
53
|
+
controlType: '',
|
|
54
|
+
sourceId: '',
|
|
55
|
+
mstrucId: '',
|
|
56
|
+
extControlType: '',
|
|
57
|
+
},
|
|
58
|
+
secondColumn: {
|
|
59
|
+
sourceId: '',
|
|
60
|
+
controlType: '',
|
|
61
|
+
mstrucId: '',
|
|
62
|
+
extControlType: '',
|
|
63
|
+
},
|
|
64
|
+
criteria: [],
|
|
65
|
+
id: '',
|
|
66
|
+
fields: [],
|
|
67
|
+
title: '',
|
|
68
|
+
type: '',
|
|
69
|
+
pointSourceId: '',
|
|
70
|
+
mstrucId: '',
|
|
71
|
+
relationNames: [],
|
|
72
|
+
readOnly: false,
|
|
73
|
+
displayConfig: [],
|
|
74
|
+
showType: 'table',
|
|
75
|
+
})
|
|
76
|
+
const { getEnums, enumColumn } = useEnums({ config })
|
|
77
|
+
const datas = ref<Entities[]>([])
|
|
78
|
+
const pageTitle = ref('')
|
|
79
|
+
const searchData = ref('')
|
|
80
|
+
const tabSearchData = ref('')
|
|
81
|
+
const pageType = ref('')
|
|
82
|
+
const mainCode = ref('')
|
|
83
|
+
const queryKey = ref('')
|
|
84
|
+
const rowGrids = ref<Record<string, any>>({})
|
|
85
|
+
const addEvent = generateHighResolutionID()
|
|
86
|
+
const loading = ref(false)
|
|
87
|
+
|
|
88
|
+
// 时间相关的控件类型
|
|
89
|
+
const TIME_TYPES = ['date', 'daterange', 'datetime', 'datetimerange', 'time', 'timerange']
|
|
90
|
+
|
|
91
|
+
// 从 criteria 中筛选出时间类型的字段
|
|
92
|
+
const timeCriteria = computed<Fields[]>(() => {
|
|
93
|
+
return config.value.criteria.filter(item => {
|
|
94
|
+
const type = ControlTypeSupportor.getSupportControlType(item as any)
|
|
95
|
+
return TIME_TYPES.some(t => type.startsWith(t))
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// 从 criteria 中排除时间类型字段,传给 Search
|
|
100
|
+
const nonTimeCriteria = computed<Fields[]>(() => {
|
|
101
|
+
return config.value.criteria.filter(item => {
|
|
102
|
+
const type = ControlTypeSupportor.getSupportControlType(item as any)
|
|
103
|
+
return !TIME_TYPES.some(t => type.startsWith(t))
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
// 过滤掉「操作」列
|
|
108
|
+
const tableColumns = computed<Columns[]>(() => {
|
|
109
|
+
return config.value.columns.filter(item => item.title !== '操作')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// 将 Entities[] 转成 wd-table 需要的 Record<string, any>[]
|
|
113
|
+
const tableData = computed<Record<string, any>[]>(() => {
|
|
114
|
+
return datas.value.map(row => {
|
|
115
|
+
const record: Record<string, any> = { code: row.code }
|
|
116
|
+
tableColumns.value.forEach(col => {
|
|
117
|
+
const raw = row.fieldMap[col.sourceId]
|
|
118
|
+
if (raw !== undefined && raw !== null) {
|
|
119
|
+
const type = ControlTypeSupportor.getControlType(col as any, raw)
|
|
120
|
+
record[col.sourceId] = formatItemData(raw, type)
|
|
121
|
+
} else {
|
|
122
|
+
record[col.sourceId] = ''
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
return record
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// 根据内容计算每列宽度(中文字符约16px,英文/数字约8px,最大宽度300px)
|
|
130
|
+
// 无数据时用 1fr 让列均分占满整行
|
|
131
|
+
const columnWidths = computed<Record<string, string>>(() => {
|
|
132
|
+
const widths: Record<string, string> = {}
|
|
133
|
+
const MAX_WIDTH = 300
|
|
134
|
+
const MIN_WIDTH = 80
|
|
135
|
+
const CHAR_WIDTH_CN = 16
|
|
136
|
+
const CHAR_WIDTH_EN = 8
|
|
137
|
+
const PADDING = 32
|
|
138
|
+
|
|
139
|
+
// 无数据时,所有列按百分比均分占满整行
|
|
140
|
+
// 注意:不能用 1fr,因为 wd-table 的 contentWidthStyle 会用 calc() 求和,
|
|
141
|
+
// fr 单位在 calc() 中是非法值,这里改用百分比
|
|
142
|
+
if (datas.value.length === 0 && tableColumns.value.length > 0) {
|
|
143
|
+
const colCount = tableColumns.value.length
|
|
144
|
+
const percent = (100 / colCount).toFixed(4) + '%'
|
|
145
|
+
tableColumns.value.forEach(col => {
|
|
146
|
+
widths[col.sourceId] = percent
|
|
147
|
+
})
|
|
148
|
+
return widths
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
tableColumns.value.forEach(col => {
|
|
152
|
+
let maxLen = col.title?.length || 0
|
|
153
|
+
// 遍历所有行找该列最长内容
|
|
154
|
+
tableData.value.forEach(row => {
|
|
155
|
+
const val = String(row[col.sourceId] || '')
|
|
156
|
+
// 计算字符宽度:中文算2个单位,英文算1个单位
|
|
157
|
+
let charCount = 0
|
|
158
|
+
for (const ch of val) {
|
|
159
|
+
charCount += /[一-鿿]/.test(ch) ? 2 : 1
|
|
160
|
+
}
|
|
161
|
+
maxLen = Math.max(maxLen, charCount)
|
|
162
|
+
})
|
|
163
|
+
const px = Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, maxLen * CHAR_WIDTH_EN + PADDING))
|
|
164
|
+
widths[col.sourceId] = `${px}px`
|
|
165
|
+
})
|
|
166
|
+
return widths
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const internalSourceId = ref(props.sourceId)
|
|
170
|
+
|
|
171
|
+
onLoad((option: any) => {
|
|
172
|
+
if (!internalSourceId.value) {
|
|
173
|
+
internalSourceId.value = option.sourceId
|
|
174
|
+
}
|
|
175
|
+
pageTitle.value = option.title
|
|
176
|
+
pageType.value = option.pageType
|
|
177
|
+
mainCode.value = option.mainCode || ''
|
|
178
|
+
uni.setNavigationBarTitle({
|
|
179
|
+
title: option.title,
|
|
180
|
+
})
|
|
181
|
+
getPageConfig()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
onMounted(async () => {
|
|
185
|
+
uni.$on(addEvent, async () => {
|
|
186
|
+
fetchData()
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
onUnmounted(() => {
|
|
191
|
+
uni.$off(addEvent)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
async function getPageConfig() {
|
|
195
|
+
try {
|
|
196
|
+
const res = await pageConfig(internalSourceId.value)
|
|
197
|
+
if (res.ltmplConfig) {
|
|
198
|
+
config.value = res.ltmplConfig
|
|
199
|
+
getEnums()
|
|
200
|
+
fetchData()
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.log(error)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 一次性请求所有数据(pageSize 设一个足够大的值)
|
|
208
|
+
async function fetchData() {
|
|
209
|
+
// 首次加载时,从字段默认值构建时间查询条件
|
|
210
|
+
if (!timeInited.value) {
|
|
211
|
+
timeInited.value = true
|
|
212
|
+
let defaultTimeData = ''
|
|
213
|
+
timeCriteria.value.forEach(item => {
|
|
214
|
+
const defaultVal = item.transDefaultValue || item.defaultValue
|
|
215
|
+
if (defaultVal && defaultVal !== '') {
|
|
216
|
+
const formatted =
|
|
217
|
+
defaultVal === '$$currentD'
|
|
218
|
+
? dayjs().format('YYYY-MM-DD')
|
|
219
|
+
: /^\d+$/.test(String(defaultVal))
|
|
220
|
+
? dayjs(Number(defaultVal)).format('YYYY-MM-DD')
|
|
221
|
+
: defaultVal
|
|
222
|
+
defaultTimeData = defaultTimeData
|
|
223
|
+
? `${defaultTimeData}&c_${item.sourceId}=${formatted}`
|
|
224
|
+
: `c_${item.sourceId}=${formatted}`
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
timeSearchData.value = defaultTimeData
|
|
228
|
+
}
|
|
229
|
+
// 合并时间筛选和其他搜索条件
|
|
230
|
+
const parts = [searchData.value, timeSearchData.value].filter(Boolean)
|
|
231
|
+
let qre = parts.join('&') || tabSearchData.value
|
|
232
|
+
if (props.query) {
|
|
233
|
+
qre = qre ? `${qre}&${props.query}` : props.query
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
loading.value = true
|
|
237
|
+
try {
|
|
238
|
+
const res = await pageKey(internalSourceId.value, mainCode.value, qre)
|
|
239
|
+
const data: any = await reportData(res.key, 1, 9999)
|
|
240
|
+
queryKey.value = res.key || data?.key || ''
|
|
241
|
+
rowGrids.value = data?.rowGrids || {}
|
|
242
|
+
datas.value = data.entities || []
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.error(error)
|
|
245
|
+
} finally {
|
|
246
|
+
loading.value = false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 单元格合并:根据 rowGrids 配置返回 { rowspan, colspan }
|
|
251
|
+
function spanMethod({ row, columnIndex }: any) {
|
|
252
|
+
const code = row?.code
|
|
253
|
+
if (!code || !rowGrids.value[code]) return { rowspan: 1, colspan: 1 }
|
|
254
|
+
|
|
255
|
+
const cellMap = rowGrids.value[code]?.cellMap
|
|
256
|
+
if (!cellMap) return { rowspan: 1, colspan: 1 }
|
|
257
|
+
|
|
258
|
+
const col = tableColumns.value[columnIndex]
|
|
259
|
+
if (!col) return { rowspan: 1, colspan: 1 }
|
|
260
|
+
|
|
261
|
+
const cell = cellMap[col.sourceId]
|
|
262
|
+
if (!cell) return { rowspan: 1, colspan: 1 }
|
|
263
|
+
|
|
264
|
+
const rowspan = cell.rowSpan ?? 1
|
|
265
|
+
const colspan = cell.colSpan ?? 1
|
|
266
|
+
|
|
267
|
+
if (rowspan === 0 || colspan === 0) return { rowspan: 0, colspan: 0 }
|
|
268
|
+
|
|
269
|
+
return { rowspan, colspan }
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function submitSearch(data: any) {
|
|
273
|
+
searchData.value = data
|
|
274
|
+
// 同时收集时间筛选条件
|
|
275
|
+
if (timeFormRef.value) {
|
|
276
|
+
timeFormRef.value.submit().then((fdata: any) => {
|
|
277
|
+
let timeData = ''
|
|
278
|
+
timeCriteria.value.forEach(item => {
|
|
279
|
+
const val = fdata[item.sourceId]
|
|
280
|
+
if (val === undefined || val === null || val === '') return
|
|
281
|
+
if (Array.isArray(val) && val.length === 0) return
|
|
282
|
+
if (item.transDefaultValue && String(val) === String(item.transDefaultValue)) return
|
|
283
|
+
// 时间戳转日期字符串
|
|
284
|
+
const formatted = typeof val === 'number' ? dayjs(val).format('YYYY-MM-DD') : val
|
|
285
|
+
timeData = timeData ? `${timeData}&c_${item.sourceId}=${formatted}` : `c_${item.sourceId}=${formatted}`
|
|
286
|
+
})
|
|
287
|
+
timeSearchData.value = timeData
|
|
288
|
+
fetchData()
|
|
289
|
+
})
|
|
290
|
+
} else {
|
|
291
|
+
fetchData()
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 时间筛选
|
|
296
|
+
const timeFormEntity = ref({})
|
|
297
|
+
const timeFormRef = ref()
|
|
298
|
+
const timeInited = ref(false)
|
|
299
|
+
|
|
300
|
+
// 区分时间筛选和其他搜索条件
|
|
301
|
+
const timeSearchData = ref('')
|
|
302
|
+
function submitTimeFilter() {
|
|
303
|
+
if (!timeFormRef.value) return
|
|
304
|
+
timeFormRef.value.submit().then((fdata: any) => {
|
|
305
|
+
let data = ''
|
|
306
|
+
timeCriteria.value.forEach(item => {
|
|
307
|
+
const val = fdata[item.sourceId]
|
|
308
|
+
if (val === undefined || val === null || val === '') return
|
|
309
|
+
if (Array.isArray(val) && val.length === 0) return
|
|
310
|
+
if (item.transDefaultValue && String(val) === String(item.transDefaultValue)) return
|
|
311
|
+
// 时间戳转日期字符串
|
|
312
|
+
const formatted = typeof val === 'number' ? dayjs(val).format('YYYY-MM-DD') : val
|
|
313
|
+
data = data ? `${data}&c_${item.sourceId}=${formatted}` : `c_${item.sourceId}=${formatted}`
|
|
314
|
+
})
|
|
315
|
+
timeSearchData.value = data
|
|
316
|
+
fetchData()
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function tabSearchClick(data: any) {
|
|
321
|
+
if (searchData.value) {
|
|
322
|
+
tabSearchData.value = `${searchData.value}&${data}`
|
|
323
|
+
} else {
|
|
324
|
+
tabSearchData.value = data
|
|
325
|
+
}
|
|
326
|
+
fetchData()
|
|
327
|
+
}
|
|
328
|
+
</script>
|
|
329
|
+
|
|
330
|
+
<template>
|
|
331
|
+
<view>
|
|
332
|
+
<slot name="top" />
|
|
333
|
+
<!-- 时间筛选区域 -->
|
|
334
|
+
<view v-if="timeCriteria.length" class="time-filter-bar">
|
|
335
|
+
<formControl
|
|
336
|
+
ref="timeFormRef"
|
|
337
|
+
:field-group="{
|
|
338
|
+
fields: timeCriteria,
|
|
339
|
+
readOnly: false,
|
|
340
|
+
displayConfig: [],
|
|
341
|
+
id: '',
|
|
342
|
+
buttons: [],
|
|
343
|
+
title: '',
|
|
344
|
+
type: '',
|
|
345
|
+
pointSourceId: '',
|
|
346
|
+
mstrucId: '',
|
|
347
|
+
relationNames: [],
|
|
348
|
+
}"
|
|
349
|
+
:entity="timeFormEntity"
|
|
350
|
+
:enum-column="enumColumn"
|
|
351
|
+
/>
|
|
352
|
+
</view>
|
|
353
|
+
<view class="px-[16px]">
|
|
354
|
+
<Search
|
|
355
|
+
:main-code="mainCode"
|
|
356
|
+
:enum-column="enumColumn"
|
|
357
|
+
:criteria="nonTimeCriteria"
|
|
358
|
+
:primary-criterion="config.primaryCriterion"
|
|
359
|
+
:split2-tab-criterias="config.split2TabCriterias"
|
|
360
|
+
@submit="submitSearch"
|
|
361
|
+
/>
|
|
362
|
+
</view>
|
|
363
|
+
|
|
364
|
+
<view class="mt-2 px-[16px]">
|
|
365
|
+
<ListTopButtons
|
|
366
|
+
:add-event="addEvent"
|
|
367
|
+
:main-code="mainCode"
|
|
368
|
+
:buttons="config.buttons"
|
|
369
|
+
:source-id="internalSourceId"
|
|
370
|
+
:page-title="pageTitle"
|
|
371
|
+
:page-type="pageType"
|
|
372
|
+
:config="config"
|
|
373
|
+
:show-buttons="showTopButtons"
|
|
374
|
+
:query-key="queryKey"
|
|
375
|
+
/>
|
|
376
|
+
</view>
|
|
377
|
+
<view v-if="config.split2TabCriterias" class="mt-2">
|
|
378
|
+
<tabSearch :split2-tab-criterias="config.split2TabCriterias" :enums="enumColumn" @click="tabSearchClick" />
|
|
379
|
+
</view>
|
|
380
|
+
|
|
381
|
+
<!-- wot-ui Table -->
|
|
382
|
+
<wd-table :data="tableData" :border="false" :span-method="spanMethod" :stripe="false" center>
|
|
383
|
+
<wd-table-column
|
|
384
|
+
v-for="col in tableColumns"
|
|
385
|
+
:key="col.sourceId"
|
|
386
|
+
:prop="col.sourceId"
|
|
387
|
+
:label="col.title || col.sourceId"
|
|
388
|
+
:width="columnWidths[col.sourceId]"
|
|
389
|
+
align="left"
|
|
390
|
+
/>
|
|
391
|
+
</wd-table>
|
|
392
|
+
|
|
393
|
+
<slot name="bottom" />
|
|
394
|
+
</view>
|
|
395
|
+
</template>
|
|
396
|
+
|
|
397
|
+
<style scoped lang="scss">
|
|
398
|
+
:deep(.wd-table) {
|
|
399
|
+
margin: 16rpx;
|
|
400
|
+
width: auto;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// 修复合并单元格后内容不垂直居中
|
|
404
|
+
::deep(.wd-table__value) {
|
|
405
|
+
display: flex !important;
|
|
406
|
+
align-items: center !important;
|
|
407
|
+
line-height: 1.5 !important;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.time-filter-bar {
|
|
411
|
+
padding: 16rpx;
|
|
412
|
+
}
|
|
413
|
+
:deep(.wd-table__cell) {
|
|
414
|
+
border: 0.5px solid #e5e5e5;
|
|
415
|
+
}
|
|
416
|
+
</style>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed, defineEmits, defineOptions, defineProps, ref } from 'vue'
|
|
3
3
|
import type { Enums, Fields, Split2TabCriterias } from '../../type'
|
|
4
4
|
import formControl from '../form-control/form-control.vue'
|
|
5
|
+
import ControlTypeSupportor from '../../utils/control-type-supportor'
|
|
5
6
|
import { useManualThemeStore } from '../../store/manualThemeStore'
|
|
6
7
|
|
|
7
8
|
defineOptions({ name: 'Search' })
|
|
@@ -21,19 +22,32 @@ const show = ref(false)
|
|
|
21
22
|
const search = ref('')
|
|
22
23
|
const formControlRef = ref()
|
|
23
24
|
const entity = ref({})
|
|
25
|
+
// 判断字段实际渲染的控件类型是否为纯文本输入(优先 extControlType,回退 controlType)
|
|
26
|
+
const isTextCriterion = (item: Fields) => ControlTypeSupportor.getControlType(item) === 'text'
|
|
27
|
+
// 用于 wd-search 的搜索字段:优先使用 primaryCriterion,否则取 criteria 中第一个文本类型的筛选项
|
|
28
|
+
const searchCriterion = computed(() => {
|
|
29
|
+
if (props.primaryCriterion && isTextCriterion(props.primaryCriterion)) {
|
|
30
|
+
return props.primaryCriterion
|
|
31
|
+
}
|
|
32
|
+
return props.criteria.find(item => isTextCriterion(item)) || null
|
|
33
|
+
})
|
|
34
|
+
// 仅当 searchCriterion 为文本类型时显示搜索框
|
|
35
|
+
const showSearch = computed(() => searchCriterion.value !== null)
|
|
24
36
|
const filterCriteria = computed(() => {
|
|
25
37
|
const criteriaSourceIds = props.split2TabCriterias?.map(item => item.sourceId) || []
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
// 仅当搜索框真正显示时,才把 searchCriterion 从筛选弹窗中排除;
|
|
39
|
+
// 否则(extControlType 存在)该字段应回落到筛选弹窗中参与筛选
|
|
40
|
+
const searchSourceId = showSearch.value ? searchCriterion.value?.sourceId : undefined
|
|
41
|
+
if (!searchSourceId) return props.criteria.filter(item => !criteriaSourceIds.includes(item.sourceId))
|
|
42
|
+
return props.criteria.filter(item => ![searchSourceId, ...criteriaSourceIds].includes(item.sourceId))
|
|
29
43
|
})
|
|
30
44
|
function handleClose() {
|
|
31
45
|
show.value = false
|
|
32
46
|
}
|
|
33
47
|
function handleSubmit() {
|
|
34
48
|
if (!formControlRef.value) {
|
|
35
|
-
if (!
|
|
36
|
-
const data = `c_${
|
|
49
|
+
if (!showSearch.value || !searchCriterion.value?.sourceId) return
|
|
50
|
+
const data = `c_${searchCriterion.value.sourceId}=${search.value}`
|
|
37
51
|
emits('submit', data)
|
|
38
52
|
handleClose()
|
|
39
53
|
return
|
|
@@ -41,19 +55,28 @@ function handleSubmit() {
|
|
|
41
55
|
formControlRef.value.submit().then((fdata: any) => {
|
|
42
56
|
entity.value = {
|
|
43
57
|
...fdata,
|
|
44
|
-
...(
|
|
58
|
+
...(showSearch.value && searchCriterion.value?.sourceId
|
|
59
|
+
? { [searchCriterion.value.sourceId]: search.value }
|
|
60
|
+
: {}),
|
|
45
61
|
}
|
|
46
62
|
let data = ''
|
|
47
63
|
|
|
48
|
-
if (
|
|
49
|
-
data = `c_${
|
|
64
|
+
if (showSearch.value && searchCriterion.value?.sourceId) {
|
|
65
|
+
data = `c_${searchCriterion.value.sourceId}=${search.value}`
|
|
50
66
|
}
|
|
51
67
|
|
|
52
68
|
filterCriteria.value.forEach(item => {
|
|
53
69
|
const element = fdata[item.sourceId]
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
if (
|
|
70
|
+
// 空值(空字符串、undefined、null、空数组)仍拼接 `c_${sourceId}=` 空参数,
|
|
71
|
+
// 让父组件识别「该字段已被用户清空」,从而跳过 defaultCriteriaValue 的默认值兜底
|
|
72
|
+
if (element === undefined || element === null || element === '') {
|
|
73
|
+
data = `${data}&c_${item.sourceId}=`
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(element) && element.length === 0) {
|
|
77
|
+
data = `${data}&c_${item.sourceId}=`
|
|
78
|
+
return
|
|
79
|
+
}
|
|
57
80
|
// 跳过用户未修改的默认值(时间字段常被自动填充当前时间,不应作为查询条件)
|
|
58
81
|
if (item.transDefaultValue && String(element) === String(item.transDefaultValue)) return
|
|
59
82
|
if (item.extControlType === 'relselectvalue') {
|
|
@@ -83,11 +106,11 @@ function handleSubmit() {
|
|
|
83
106
|
|
|
84
107
|
<template>
|
|
85
108
|
<wd-config-provider :theme="theme">
|
|
86
|
-
<view v-if="
|
|
109
|
+
<view v-if="showSearch" class="w-full">
|
|
87
110
|
<wd-search
|
|
88
111
|
v-model="search"
|
|
89
112
|
cancel-txt="搜索"
|
|
90
|
-
:placeholder="`请输入${
|
|
113
|
+
:placeholder="`请输入${searchCriterion?.title || ''}搜索`"
|
|
91
114
|
@clear="handleSubmit"
|
|
92
115
|
@cancel="handleSubmit"
|
|
93
116
|
>
|
|
@@ -103,6 +126,12 @@ function handleSubmit() {
|
|
|
103
126
|
</template>
|
|
104
127
|
</wd-search>
|
|
105
128
|
</view>
|
|
129
|
+
<view v-else-if="filterCriteria.length" class="px-[8px] mt-2">
|
|
130
|
+
<wd-button block custom-class="search-filter-btn" @click="show = true">
|
|
131
|
+
<wd-icon name="filter" size="17px" class="mr-1" />
|
|
132
|
+
筛选
|
|
133
|
+
</wd-button>
|
|
134
|
+
</view>
|
|
106
135
|
<wd-popup v-model="show" position="bottom" custom-class="h-80vh" closable @close="handleClose">
|
|
107
136
|
<view class="relative box-border h-full p-1 bg-white dark:bg-[var(--wot-dark-background)]">
|
|
108
137
|
<view class="h-34px flex items-center justify-center text-black dark:text-[var(--wot-dark-color)]">筛选</view>
|
|
@@ -8,6 +8,7 @@ import Search from '../search/search.vue'
|
|
|
8
8
|
import ListTopButtons from '../list-top-buttons/list-top-buttons.vue'
|
|
9
9
|
import CardBotomButtons from '../card-botom-buttons/card-botom-buttons.vue'
|
|
10
10
|
import { generateHighResolutionID } from '../../utils/index'
|
|
11
|
+
import dayjs from 'dayjs/esm/index'
|
|
11
12
|
import productCard from '../product-card/product-card.vue'
|
|
12
13
|
import tabSearch from '../tab-search/tab-search.vue'
|
|
13
14
|
import { useEnums } from '../../composables/useEnumes'
|
|
@@ -67,7 +68,7 @@ const props = withDefaults(
|
|
|
67
68
|
sourceId: '',
|
|
68
69
|
// 查询条件默认为空
|
|
69
70
|
query: '',
|
|
70
|
-
}
|
|
71
|
+
}
|
|
71
72
|
)
|
|
72
73
|
|
|
73
74
|
const Zpaging = ref<any>(null)
|
|
@@ -181,7 +182,13 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
|
181
182
|
if (config.value.defaultCriteriaValue) {
|
|
182
183
|
for (const key in config.value.defaultCriteriaValue) {
|
|
183
184
|
if (Object.prototype.hasOwnProperty.call(config.value.defaultCriteriaValue, key)) {
|
|
184
|
-
|
|
185
|
+
let element = config.value.defaultCriteriaValue[key]
|
|
186
|
+
// $$currentD 占位符转换为当日时间(年-月-日),没有值则传空字符串
|
|
187
|
+
if (element === '$$currentD') {
|
|
188
|
+
element = dayjs().format('YYYY-MM-DD')
|
|
189
|
+
} else if (element === undefined || element === null) {
|
|
190
|
+
element = ''
|
|
191
|
+
}
|
|
185
192
|
if (!qre.includes(key)) {
|
|
186
193
|
qre = `${qre}&${key}=${element}`
|
|
187
194
|
}
|
|
@@ -190,6 +197,7 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
try {
|
|
200
|
+
console.log('qre', qre)
|
|
193
201
|
const res = await pageKey(internalSourceId.value, mainCode.value, qre) // 获取key
|
|
194
202
|
const data = await listData(res.key, pageNo, pageSize) // 获取数据
|
|
195
203
|
// 缓存最新一次的 queryKey,给顶部「导出」接口使用
|
|
@@ -8,6 +8,7 @@ import type { Config, Entities, Enums, FoldCardModel } from '../../type'
|
|
|
8
8
|
import { useGlobalToast } from '../../composables/useGlobalToast'
|
|
9
9
|
import Search from '../search/search.vue'
|
|
10
10
|
import foldCard from '../fold-card/fold-card.vue'
|
|
11
|
+
import dayjs from 'dayjs/esm/index'
|
|
11
12
|
|
|
12
13
|
defineOptions({
|
|
13
14
|
name: 'WuiSelectList',
|
|
@@ -155,7 +156,13 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
|
155
156
|
if (config.value.defaultCriteriaValue) {
|
|
156
157
|
for (const key in config.value.defaultCriteriaValue) {
|
|
157
158
|
if (Object.prototype.hasOwnProperty.call(config.value.defaultCriteriaValue, key)) {
|
|
158
|
-
|
|
159
|
+
let element = config.value.defaultCriteriaValue[key]
|
|
160
|
+
// $$currentD 占位符转换为当日时间(年-月-日),没有值则传空字符串
|
|
161
|
+
if (element === '$$currentD') {
|
|
162
|
+
element = dayjs().format('YYYY-MM-DD')
|
|
163
|
+
} else if (element === undefined || element === null) {
|
|
164
|
+
element = ''
|
|
165
|
+
}
|
|
159
166
|
if (!qre.includes(key)) {
|
|
160
167
|
qre = `${qre}&${key}=${element}`
|
|
161
168
|
}
|
|
@@ -6,6 +6,7 @@ import Search from '../search/search.vue'
|
|
|
6
6
|
import type { Config, Entities, Enums, FoldCardModel } from '../../type'
|
|
7
7
|
import { useGlobalToast } from '../../composables/useGlobalToast'
|
|
8
8
|
import listTopButtons from '../list-top-buttons/list-top-buttons.vue'
|
|
9
|
+
import dayjs from 'dayjs/esm/index'
|
|
9
10
|
|
|
10
11
|
defineOptions({
|
|
11
12
|
name: 'WuiSelectPopup',
|
|
@@ -301,7 +302,13 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
|
301
302
|
if (config.value.defaultCriteriaValue) {
|
|
302
303
|
for (const key in config.value.defaultCriteriaValue) {
|
|
303
304
|
if (Object.prototype.hasOwnProperty.call(config.value.defaultCriteriaValue, key)) {
|
|
304
|
-
|
|
305
|
+
let element = config.value.defaultCriteriaValue[key]
|
|
306
|
+
// $$currentD 占位符转换为当日时间(年-月-日),没有值则传空字符串
|
|
307
|
+
if (element === '$$currentD') {
|
|
308
|
+
element = dayjs().format('YYYY-MM-DD')
|
|
309
|
+
} else if (element === undefined || element === null) {
|
|
310
|
+
element = ''
|
|
311
|
+
}
|
|
305
312
|
if (!qre.includes(key)) {
|
|
306
313
|
qre = `${qre}&${key}=${element}`
|
|
307
314
|
}
|
package/composables/useMenus.ts
CHANGED
|
@@ -68,9 +68,7 @@ export function useMenus(props?: Props, pagingRef?: Ref<any>) {
|
|
|
68
68
|
router.push(`/pages/tree-page/index?sourceId=${item.id}&title=${item.title}`)
|
|
69
69
|
return true
|
|
70
70
|
case '报表':
|
|
71
|
-
|
|
72
|
-
// url: `/pages/report-table/report-table?sourceId=${item.id}&title=${item.title}`,
|
|
73
|
-
// })
|
|
71
|
+
router.push(`/pages/report-table/index?sourceId=${item.id}&title=${item.title}`)
|
|
74
72
|
return true
|
|
75
73
|
|
|
76
74
|
default:
|