wui-components-v2 1.2.28 → 1.2.29
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 +32 -0
- package/components/card-botom-buttons/card-botom-buttons.vue +57 -6
- package/components/list-top-buttons/list-top-buttons.vue +409 -3
- package/components/search/search.vue +21 -20
- package/components/wui-list/wui-list.vue +12 -1
- package/index.ts +8 -0
- package/package.json +1 -1
- package/type.ts +22 -0
package/api/page.ts
CHANGED
|
@@ -131,6 +131,38 @@ export function copyDataApi(sourceId: string, code: string) {
|
|
|
131
131
|
})
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// 导出 Excel 数据(GET,参数拼到 Query String)
|
|
135
|
+
export function exportLtmplExcel(params: {
|
|
136
|
+
language?: string
|
|
137
|
+
scope: 'current' | 'page' | 'all'
|
|
138
|
+
withDetail?: boolean
|
|
139
|
+
queryKey: string
|
|
140
|
+
startPageNo?: number
|
|
141
|
+
endPageNo?: number
|
|
142
|
+
}) {
|
|
143
|
+
const { language = 'zh', scope, withDetail = false, queryKey, startPageNo, endPageNo } = params
|
|
144
|
+
const searchParts = [
|
|
145
|
+
`language=${encodeURIComponent(language)}`,
|
|
146
|
+
`scope=${encodeURIComponent(scope)}`,
|
|
147
|
+
`withDetail=${withDetail}`,
|
|
148
|
+
`queryKey=${encodeURIComponent(queryKey)}`,
|
|
149
|
+
]
|
|
150
|
+
if (typeof startPageNo === 'number') searchParts.push(`startPageNo=${startPageNo}`)
|
|
151
|
+
if (typeof endPageNo === 'number') searchParts.push(`endPageNo=${endPageNo}`)
|
|
152
|
+
return req({
|
|
153
|
+
url: `/v3/export/ltmpl-data-excel?${searchParts.join('&')}`,
|
|
154
|
+
method: 'GET',
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 轮询导出状态
|
|
159
|
+
export function exportStatus(exportId: string) {
|
|
160
|
+
return req({
|
|
161
|
+
url: `/v3/export/status?exportId=${encodeURIComponent(exportId)}`,
|
|
162
|
+
method: 'GET',
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
134
166
|
// 关联字段联动:通过 relValueField 下选中值请求默认值
|
|
135
167
|
// relValueField 下存在 extRefPageId 时请求 /v3/ltmpl/top-data,
|
|
136
168
|
// 否则请求 /v3/dtmpl/data
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { computed, defineOptions, defineProps, ref } from 'vue'
|
|
3
3
|
import { useRouter } from 'uni-mini-router'
|
|
4
4
|
import { onLoad } from '@dcloudio/uni-app'
|
|
5
|
-
import type { ClassEditConfigs, Columns, Entities, Enums, Fields, Groups, rowActions } from '../../type'
|
|
5
|
+
import type { ClassEditConfigs, Columns, EditButtonConfig, Entities, Enums, Fields, Groups, rowActions } from '../../type'
|
|
6
6
|
import ActionPopup from '../action-popup/action-popup.vue'
|
|
7
7
|
import { actionDataSave, copyDataApi, deleteData, editPageConfig } from '../../api/page'
|
|
8
8
|
import { useGlobalToast } from '../../composables/useGlobalToast'
|
|
@@ -36,6 +36,11 @@ const props = defineProps<{
|
|
|
36
36
|
*/
|
|
37
37
|
isShowAction?: boolean
|
|
38
38
|
copyMode?: string
|
|
39
|
+
/**
|
|
40
|
+
* 自定义编辑按钮配置:动态文字 / 显隐 / 点击行为。
|
|
41
|
+
* 不传时走组件内置的 edit() 跳转逻辑。
|
|
42
|
+
*/
|
|
43
|
+
editButtonConfig?: EditButtonConfig
|
|
39
44
|
}>()
|
|
40
45
|
const toast = useGlobalToast()
|
|
41
46
|
const message = useGlobalMessage()
|
|
@@ -81,6 +86,54 @@ function edit() {
|
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
89
|
+
// ===== 自定义编辑按钮(editButtonConfig) =====
|
|
90
|
+
// Entities 仅含 code/fieldMap/arrayMap,缺失 sourceId 等上下文,统一通过 ctx 补回。
|
|
91
|
+
const editButtonCtx = computed(() => ({
|
|
92
|
+
sourceId: props.sourceId,
|
|
93
|
+
code: props.code,
|
|
94
|
+
mainCode: (props.item as any)?.mainCode || '',
|
|
95
|
+
pageType: props.pageType || '',
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
// 按钮文字:优先用 editButtonConfig.label,否则默认「编辑」
|
|
99
|
+
const editButtonLabel = computed(() => {
|
|
100
|
+
if (props.editButtonConfig?.label) {
|
|
101
|
+
try {
|
|
102
|
+
return props.editButtonConfig.label(props.data, editButtonCtx.value) || '编辑'
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.error('[editButtonConfig.label] 执行异常', e)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return '编辑'
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// 是否显示:优先用 editButtonConfig.show,否则默认显示
|
|
111
|
+
const editButtonShow = computed(() => {
|
|
112
|
+
if (props.editButtonConfig?.show) {
|
|
113
|
+
try {
|
|
114
|
+
return props.editButtonConfig.show(props.data, editButtonCtx.value)
|
|
115
|
+
} catch (e) {
|
|
116
|
+
console.error('[editButtonConfig.show] 执行异常', e)
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// 未配置自定义时,沿用原有「dtmplEdit 且 visible」逻辑
|
|
121
|
+
return props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// 点击:优先走 editButtonConfig.clickAction,否则回退默认 edit() 跳转
|
|
125
|
+
function editButtonClick() {
|
|
126
|
+
if (props.editButtonConfig?.clickAction) {
|
|
127
|
+
try {
|
|
128
|
+
props.editButtonConfig.clickAction(props.data, editButtonCtx.value)
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error('[editButtonConfig.clickAction] 执行异常', e)
|
|
131
|
+
}
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
edit()
|
|
135
|
+
}
|
|
136
|
+
|
|
84
137
|
const actionItem = ref<Groups>()
|
|
85
138
|
const actionItemShow = ref(false) // rowActions输入弹框开关
|
|
86
139
|
// 打开rowActions弹框
|
|
@@ -307,13 +360,11 @@ console.log(props, '3333333333333')
|
|
|
307
360
|
复制
|
|
308
361
|
</wd-button>
|
|
309
362
|
<wd-button
|
|
310
|
-
v-if="
|
|
311
|
-
isShowAction !== false && props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)
|
|
312
|
-
"
|
|
363
|
+
v-if="isShowAction !== false && editButtonShow"
|
|
313
364
|
size="small"
|
|
314
|
-
@click="
|
|
365
|
+
@click="editButtonClick()"
|
|
315
366
|
>
|
|
316
|
-
|
|
367
|
+
{{ editButtonLabel }}
|
|
317
368
|
</wd-button>
|
|
318
369
|
<wd-button v-if="props.item.buttons.includes('detail')" size="small" type="info" @click="detail()">详情</wd-button>
|
|
319
370
|
<wd-button
|
|
@@ -1,24 +1,430 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
2
3
|
import { useRouter } from 'uni-mini-router'
|
|
4
|
+
import { exportLtmplExcel, exportStatus as fetchExportStatus } from '../../api/page'
|
|
3
5
|
|
|
4
6
|
defineOptions({
|
|
5
7
|
name: 'ListTopButtons',
|
|
6
8
|
})
|
|
7
9
|
const props = withDefaults(
|
|
8
|
-
defineProps<{
|
|
10
|
+
defineProps<{
|
|
11
|
+
mainCode: string
|
|
12
|
+
buttons: string[]
|
|
13
|
+
sourceId: string
|
|
14
|
+
id?: string
|
|
15
|
+
pageTitle: string
|
|
16
|
+
pageType?: string
|
|
17
|
+
addEvent?: string
|
|
18
|
+
config?: any
|
|
19
|
+
showButtons?: boolean
|
|
20
|
+
/**
|
|
21
|
+
* 列表查询 key,由 wui-list 调用 pageKey 后透传到导出接口。
|
|
22
|
+
* 不传时,多页/全部会报错提示。
|
|
23
|
+
*/
|
|
24
|
+
queryKey?: string
|
|
25
|
+
/**
|
|
26
|
+
* 导出参数 withDetail,传给 /v3/export/ltmpl-data-excel,可由父级覆盖。
|
|
27
|
+
*/
|
|
28
|
+
withDetail?: boolean
|
|
29
|
+
}>(),
|
|
9
30
|
{
|
|
10
31
|
showButtons: true,
|
|
32
|
+
withDetail: false,
|
|
11
33
|
}
|
|
12
34
|
)
|
|
13
35
|
const router = useRouter()
|
|
14
36
|
// 跳转添加页面
|
|
15
37
|
function gotoAddPage() {
|
|
16
|
-
router.push(
|
|
38
|
+
router.push(
|
|
39
|
+
`/pages/edit-page/index?sourceId=${props.sourceId}&id=${props.id || ''}&title=${props.pageTitle}&mainCode=${props.mainCode}&pageType=${props.pageType}&addEvent=${props.addEvent}`
|
|
40
|
+
)
|
|
17
41
|
}
|
|
42
|
+
|
|
43
|
+
// 导出范围弹窗
|
|
44
|
+
// 点击「导出」按钮时触发,弹出当前页 / 多页 / 全部 三选一弹窗
|
|
45
|
+
const exportPopupShow = ref(false)
|
|
46
|
+
const exportScope = ref<'current' | 'page' | 'all'>('current')
|
|
47
|
+
const exportScopeOptions = [
|
|
48
|
+
{ value: 'current', label: '当前页' },
|
|
49
|
+
{ value: 'page', label: '多页' },
|
|
50
|
+
{ value: 'all', label: '全部' },
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
// 导出状态:'idle' 待开始 / 'running' 导出中 / 'done' 已完成 / 'cancelled' 已取消
|
|
54
|
+
type ExportStatus = 'idle' | 'running' | 'done' | 'cancelled'
|
|
55
|
+
const exportStatus = ref<ExportStatus>('idle')
|
|
56
|
+
const exportProgress = ref(0) // 0-100
|
|
57
|
+
const exportTimer = ref<ReturnType<typeof setInterval> | null>(null) // 进度条定时器
|
|
58
|
+
const pollTimer = ref<ReturnType<typeof setInterval> | null>(null) // 轮询定时器
|
|
59
|
+
const exportId = ref('') // 导出任务 ID,下载时使用
|
|
60
|
+
const exportFileName = ref('') // 生成的文件名
|
|
61
|
+
|
|
62
|
+
// 多页导出:起始页 / 结束页
|
|
63
|
+
const exportStartPage = ref<string>('1')
|
|
64
|
+
const exportEndPage = ref<string>('10')
|
|
65
|
+
|
|
66
|
+
function clearExportTimer() {
|
|
67
|
+
if (exportTimer.value) {
|
|
68
|
+
clearInterval(exportTimer.value)
|
|
69
|
+
exportTimer.value = null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function clearPollTimer() {
|
|
73
|
+
if (pollTimer.value) {
|
|
74
|
+
clearInterval(pollTimer.value)
|
|
75
|
+
pollTimer.value = null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function openExportPopup() {
|
|
80
|
+
exportScope.value = 'current'
|
|
81
|
+
exportStatus.value = 'idle'
|
|
82
|
+
exportProgress.value = 0
|
|
83
|
+
exportId.value = ''
|
|
84
|
+
exportFileName.value = ''
|
|
85
|
+
exportStartPage.value = '1'
|
|
86
|
+
exportEndPage.value = '10'
|
|
87
|
+
exportPopupShow.value = true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function closeExportPopup() {
|
|
91
|
+
// 关闭时如果仍在导出,自动取消
|
|
92
|
+
if (exportStatus.value === 'running') {
|
|
93
|
+
cancelExport()
|
|
94
|
+
}
|
|
95
|
+
exportPopupShow.value = false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 点击「开始导出」:调用导出接口,拿到 exportId 后轮询状态
|
|
99
|
+
async function confirmExport() {
|
|
100
|
+
if (exportStatus.value === 'running') return
|
|
101
|
+
|
|
102
|
+
// 多页模式下校验页号
|
|
103
|
+
const startPageNo = exportScope.value === 'page' ? Number(exportStartPage.value) : undefined
|
|
104
|
+
const endPageNo = exportScope.value === 'page' ? Number(exportEndPage.value) : undefined
|
|
105
|
+
if (exportScope.value === 'page') {
|
|
106
|
+
if (!Number.isInteger(startPageNo) || !Number.isInteger(endPageNo) || startPageNo! < 1 || endPageNo! < 1) {
|
|
107
|
+
uni.showToast({ title: '请输入合法的页号', icon: 'none' })
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
if (startPageNo! > endPageNo!) {
|
|
111
|
+
uni.showToast({ title: '起始页不能大于结束页', icon: 'none' })
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// queryKey 必传
|
|
117
|
+
if (!props.queryKey) {
|
|
118
|
+
uni.showToast({ title: '列表未就绪,无法导出', icon: 'none' })
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
exportStatus.value = 'running'
|
|
123
|
+
exportProgress.value = 0
|
|
124
|
+
exportFileName.value = ''
|
|
125
|
+
clearExportTimer()
|
|
126
|
+
clearPollTimer()
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
// 1. 发起导出请求,获取 exportId
|
|
130
|
+
const exportRes: any = await exportLtmplExcel({
|
|
131
|
+
language: 'zh',
|
|
132
|
+
scope: exportScope.value,
|
|
133
|
+
withDetail: props.withDetail,
|
|
134
|
+
queryKey: props.queryKey,
|
|
135
|
+
startPageNo,
|
|
136
|
+
endPageNo,
|
|
137
|
+
})
|
|
138
|
+
exportId.value = exportRes?.exportId || exportRes?.data?.exportId
|
|
139
|
+
if (!exportId.value) {
|
|
140
|
+
exportStatus.value = 'cancelled'
|
|
141
|
+
uni.showToast({ title: '导出任务创建失败', icon: 'none' })
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 2. 启动进度条动画(每 100ms +3%,到 90% 封顶等待轮询)
|
|
146
|
+
exportTimer.value = setInterval(() => {
|
|
147
|
+
exportProgress.value = Math.min(90, exportProgress.value + 3)
|
|
148
|
+
}, 100)
|
|
149
|
+
|
|
150
|
+
// 3. 开始轮询导出状态(每 1s 请求一次)
|
|
151
|
+
pollTimer.value = setInterval(async () => {
|
|
152
|
+
try {
|
|
153
|
+
const statusRes: any = await fetchExportStatus(exportId.value)
|
|
154
|
+
const completed = statusRes?.completed || statusRes?.data?.completed
|
|
155
|
+
if (completed === true) {
|
|
156
|
+
// 导出完成
|
|
157
|
+
clearExportTimer()
|
|
158
|
+
clearPollTimer()
|
|
159
|
+
exportProgress.value = 100
|
|
160
|
+
exportFileName.value =
|
|
161
|
+
statusRes?.fileName || statusRes?.data?.fileName || `export_${props.sourceId}_${Date.now()}.xlsx`
|
|
162
|
+
// 延迟一帧切状态,让进度条先渲染到 100% 再显示完成文案
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
exportStatus.value = 'done'
|
|
165
|
+
}, 100)
|
|
166
|
+
}
|
|
167
|
+
} catch (pollErr: any) {
|
|
168
|
+
// 轮询失败不中断,继续下一次尝试
|
|
169
|
+
console.error('[export poll] error', pollErr)
|
|
170
|
+
}
|
|
171
|
+
}, 1000)
|
|
172
|
+
} catch (e: any) {
|
|
173
|
+
clearExportTimer()
|
|
174
|
+
clearPollTimer()
|
|
175
|
+
exportStatus.value = 'cancelled'
|
|
176
|
+
uni.showToast({ title: e?.data?.message || e?.message || '导出失败', icon: 'none' })
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function cancelExport() {
|
|
181
|
+
if (exportStatus.value !== 'running') return
|
|
182
|
+
clearExportTimer()
|
|
183
|
+
clearPollTimer()
|
|
184
|
+
exportStatus.value = 'cancelled'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function retryExport() {
|
|
188
|
+
// 重新导出:清空状态后回到初始态
|
|
189
|
+
exportStatus.value = 'idle'
|
|
190
|
+
exportProgress.value = 0
|
|
191
|
+
exportFileName.value = ''
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function downloadExportFile() {
|
|
195
|
+
if (!exportId.value) {
|
|
196
|
+
uni.showToast({ title: '导出任务 ID 丢失,请重新导出', icon: 'none' })
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
const baseUrl = uni.getStorageSync('BASE_URL') || ''
|
|
200
|
+
const hydrocarbonProgramToken = uni.getStorageSync('HYDROCARBON_PROGRAM_TOKEN') || ''
|
|
201
|
+
const token = uni.getStorageSync('TOKEN') || uni.getStorageSync('token') || ''
|
|
202
|
+
const applicationToken = uni.getStorageSync('HYDROCARBON_APPLICATION_TOKEN') || ''
|
|
203
|
+
const downloadUrl = `${baseUrl}/v3/export/download?exportId=${exportId.value}&@token=${token}&@programToken=${hydrocarbonProgramToken}&@applicationToken=${applicationToken}`
|
|
204
|
+
|
|
205
|
+
// #ifdef H5
|
|
206
|
+
// H5 端直接用 a 标签下载
|
|
207
|
+
const a = document.createElement('a')
|
|
208
|
+
a.href = downloadUrl
|
|
209
|
+
a.download = exportFileName.value || ''
|
|
210
|
+
document.body.appendChild(a)
|
|
211
|
+
a.click()
|
|
212
|
+
document.body.removeChild(a)
|
|
213
|
+
uni.showToast({ title: '下载中...', icon: 'none' })
|
|
214
|
+
// #endif
|
|
215
|
+
|
|
216
|
+
// #ifndef H5
|
|
217
|
+
// 小程序/APP:用 request 获取文件二进制,再写入本地
|
|
218
|
+
uni.showLoading({ title: '下载中...' })
|
|
219
|
+
uni.request({
|
|
220
|
+
url: downloadUrl,
|
|
221
|
+
method: 'GET',
|
|
222
|
+
responseType: 'arraybuffer',
|
|
223
|
+
success: (res) => {
|
|
224
|
+
uni.hideLoading()
|
|
225
|
+
if (res.statusCode === 200 || res.statusCode === 201) {
|
|
226
|
+
const fs = uni.getFileSystemManager()
|
|
227
|
+
const filePath = `${uni.env.USER_DATA_PATH}/${exportFileName.value || 'export.xlsx'}`
|
|
228
|
+
fs.writeFile({
|
|
229
|
+
filePath,
|
|
230
|
+
data: res.data as ArrayBuffer,
|
|
231
|
+
success: () => {
|
|
232
|
+
uni.openDocument({
|
|
233
|
+
filePath,
|
|
234
|
+
showMenu: true,
|
|
235
|
+
fail: () => {
|
|
236
|
+
uni.showToast({ title: '文件已保存', icon: 'none' })
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
},
|
|
240
|
+
fail: () => {
|
|
241
|
+
uni.showToast({ title: '保存失败', icon: 'none' })
|
|
242
|
+
},
|
|
243
|
+
})
|
|
244
|
+
} else {
|
|
245
|
+
uni.showToast({ title: `下载失败(${res.statusCode})`, icon: 'none' })
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
fail: (err) => {
|
|
249
|
+
uni.hideLoading()
|
|
250
|
+
console.error('[download] fail', err)
|
|
251
|
+
uni.showToast({ title: '下载失败', icon: 'none' })
|
|
252
|
+
},
|
|
253
|
+
})
|
|
254
|
+
// #endif
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
console.log(props.buttons, '33333')
|
|
18
258
|
</script>
|
|
19
259
|
|
|
20
260
|
<template>
|
|
21
261
|
<view v-if="showButtons" class="flex justify-end gap-1 py-2 px-2 bg-white dark:bg-[var(--wot-dark-background)]">
|
|
22
|
-
<wd-button class="flex-1" v-if="buttons.includes('dtmplAdd')" type="primary" @click="gotoAddPage" icon="plus">
|
|
262
|
+
<wd-button class="flex-1" v-if="buttons.includes('dtmplAdd')" type="primary" @click="gotoAddPage" icon="plus">
|
|
263
|
+
{{ props.config?.editBtnTitle || '新增' }}
|
|
264
|
+
</wd-button>
|
|
265
|
+
<wd-button
|
|
266
|
+
class="flex-1"
|
|
267
|
+
v-if="buttons.includes('exportLtmplExcel')"
|
|
268
|
+
type="primary"
|
|
269
|
+
@click="openExportPopup"
|
|
270
|
+
icon="download"
|
|
271
|
+
>
|
|
272
|
+
{{ props.config?.exportBtnTitle || '导出' }}
|
|
273
|
+
</wd-button>
|
|
23
274
|
</view>
|
|
275
|
+
|
|
276
|
+
<!-- 导出范围选择 / 进度弹窗 -->
|
|
277
|
+
<wd-popup
|
|
278
|
+
v-model="exportPopupShow"
|
|
279
|
+
position="center"
|
|
280
|
+
custom-style="border-radius: 12px; width: 80%;"
|
|
281
|
+
:close-on-click-modal="false"
|
|
282
|
+
@close="closeExportPopup"
|
|
283
|
+
>
|
|
284
|
+
<view class="export-popup bg-white dark:bg-[var(--wot-dark-background)]">
|
|
285
|
+
<view class="export-popup__header text-black dark:text-[var(--wot-dark-color)]">导出</view>
|
|
286
|
+
|
|
287
|
+
<!-- 单选范围 -->
|
|
288
|
+
<wd-radio-group
|
|
289
|
+
v-model="exportScope"
|
|
290
|
+
direction="horizontal"
|
|
291
|
+
shape="dot"
|
|
292
|
+
:disabled="exportStatus === 'running'"
|
|
293
|
+
custom-class="export-popup__group"
|
|
294
|
+
>
|
|
295
|
+
<wd-radio v-for="option in exportScopeOptions" :key="option.value" :value="option.value">
|
|
296
|
+
{{ option.label }}
|
|
297
|
+
</wd-radio>
|
|
298
|
+
</wd-radio-group>
|
|
299
|
+
|
|
300
|
+
<!-- 多页时显示页码范围输入 -->
|
|
301
|
+
<view v-if="exportScope === 'page'" class="export-popup__pages text-black dark:text-[var(--wot-dark-color)]">
|
|
302
|
+
<text class="export-popup__pages-label">页号:</text>
|
|
303
|
+
<input
|
|
304
|
+
v-model="exportStartPage"
|
|
305
|
+
class="export-popup__pages-input"
|
|
306
|
+
type="number"
|
|
307
|
+
:disabled="exportStatus === 'running'"
|
|
308
|
+
/>
|
|
309
|
+
<text class="export-popup__pages-sep">-</text>
|
|
310
|
+
<input
|
|
311
|
+
v-model="exportEndPage"
|
|
312
|
+
class="export-popup__pages-input"
|
|
313
|
+
type="number"
|
|
314
|
+
:disabled="exportStatus === 'running'"
|
|
315
|
+
/>
|
|
316
|
+
</view>
|
|
317
|
+
|
|
318
|
+
<!-- 按钮区(按状态切换) -->
|
|
319
|
+
<view class="export-popup__footer">
|
|
320
|
+
<template v-if="exportStatus === 'idle' || exportStatus === 'cancelled'">
|
|
321
|
+
<wd-button custom-class="export-popup__btn" type="primary" block @click="confirmExport">开始导出</wd-button>
|
|
322
|
+
</template>
|
|
323
|
+
|
|
324
|
+
<template v-else-if="exportStatus === 'running'">
|
|
325
|
+
<view class="export-popup__actions">
|
|
326
|
+
<wd-button custom-class="export-popup__btn export-popup__btn--half" @click="cancelExport">
|
|
327
|
+
取消导出
|
|
328
|
+
</wd-button>
|
|
329
|
+
</view>
|
|
330
|
+
</template>
|
|
331
|
+
|
|
332
|
+
<template v-else-if="exportStatus === 'done'">
|
|
333
|
+
<view class="export-popup__actions">
|
|
334
|
+
<wd-button custom-class="export-popup__btn export-popup__btn--half" plain @click="retryExport">
|
|
335
|
+
重新导出
|
|
336
|
+
</wd-button>
|
|
337
|
+
<wd-button
|
|
338
|
+
custom-class="export-popup__btn export-popup__btn--half export-popup__btn--primary"
|
|
339
|
+
type="primary"
|
|
340
|
+
@click="downloadExportFile"
|
|
341
|
+
>
|
|
342
|
+
下载文件
|
|
343
|
+
</wd-button>
|
|
344
|
+
</view>
|
|
345
|
+
</template>
|
|
346
|
+
|
|
347
|
+
<!-- 进度条:v-show 保活,:duration="0" 取消内部动画直接渲染 -->
|
|
348
|
+
<view v-show="exportStatus === 'running' || exportStatus === 'done'" class="export-popup__progress">
|
|
349
|
+
<wd-progress :percentage="exportProgress" :show-text="false" :duration="0" color="#3B82F6" />
|
|
350
|
+
</view>
|
|
351
|
+
|
|
352
|
+
<!-- 完成提示放在进度条下方 -->
|
|
353
|
+
<view v-if="exportStatus === 'done'" class="export-popup__tip text-black dark:text-[var(--wot-dark-color)]">
|
|
354
|
+
文件生成成功,请点击[下载文件]
|
|
355
|
+
</view>
|
|
356
|
+
</view>
|
|
357
|
+
</view>
|
|
358
|
+
</wd-popup>
|
|
24
359
|
</template>
|
|
360
|
+
|
|
361
|
+
<style scoped>
|
|
362
|
+
.export-popup {
|
|
363
|
+
padding: 24px;
|
|
364
|
+
border-radius: 12px;
|
|
365
|
+
}
|
|
366
|
+
.export-popup__header {
|
|
367
|
+
font-size: 18px;
|
|
368
|
+
font-weight: 600;
|
|
369
|
+
margin-bottom: 20px;
|
|
370
|
+
}
|
|
371
|
+
.export-popup__group {
|
|
372
|
+
display: flex;
|
|
373
|
+
justify-content: space-between;
|
|
374
|
+
gap: 16px;
|
|
375
|
+
padding-bottom: 20px;
|
|
376
|
+
border-bottom: 1px solid #eee;
|
|
377
|
+
}
|
|
378
|
+
.export-popup__pages {
|
|
379
|
+
display: flex;
|
|
380
|
+
align-items: center;
|
|
381
|
+
margin-top: 16px;
|
|
382
|
+
font-size: 14px;
|
|
383
|
+
}
|
|
384
|
+
.export-popup__pages-label {
|
|
385
|
+
margin-right: 8px;
|
|
386
|
+
}
|
|
387
|
+
.export-popup__pages-sep {
|
|
388
|
+
margin: 0 8px;
|
|
389
|
+
}
|
|
390
|
+
.export-popup__pages-input {
|
|
391
|
+
width: 80px;
|
|
392
|
+
height: 32px;
|
|
393
|
+
padding: 0 12px;
|
|
394
|
+
border: 1px solid #dcdfe6;
|
|
395
|
+
border-radius: 4px;
|
|
396
|
+
background: transparent;
|
|
397
|
+
text-align: center;
|
|
398
|
+
font-size: 14px;
|
|
399
|
+
color: inherit;
|
|
400
|
+
}
|
|
401
|
+
.export-popup__footer {
|
|
402
|
+
margin-top: 20px;
|
|
403
|
+
}
|
|
404
|
+
.export-popup__btn {
|
|
405
|
+
width: 100%;
|
|
406
|
+
}
|
|
407
|
+
.export-popup__actions {
|
|
408
|
+
display: flex;
|
|
409
|
+
align-items: center;
|
|
410
|
+
gap: 12px;
|
|
411
|
+
}
|
|
412
|
+
.export-popup__btn--half {
|
|
413
|
+
flex: 1;
|
|
414
|
+
}
|
|
415
|
+
.export-popup__percent {
|
|
416
|
+
font-size: 16px;
|
|
417
|
+
font-weight: 600;
|
|
418
|
+
white-space: nowrap;
|
|
419
|
+
}
|
|
420
|
+
.export-popup__progress {
|
|
421
|
+
display: flex;
|
|
422
|
+
align-items: center;
|
|
423
|
+
gap: 12px;
|
|
424
|
+
margin-top: 12px;
|
|
425
|
+
}
|
|
426
|
+
.export-popup__tip {
|
|
427
|
+
margin-top: 12px;
|
|
428
|
+
font-size: 14px;
|
|
429
|
+
}
|
|
430
|
+
</style>
|
|
@@ -50,25 +50,26 @@ function handleSubmit() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
filterCriteria.value.forEach(item => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
const element = fdata[item.sourceId]
|
|
54
|
+
// 跳过空值(空字符串、undefined、null、空数组),避免拼接无意义的参数
|
|
55
|
+
if (element === undefined || element === null || element === '') return
|
|
56
|
+
if (Array.isArray(element) && element.length === 0) return
|
|
57
|
+
// 跳过用户未修改的默认值(时间字段常被自动填充当前时间,不应作为查询条件)
|
|
58
|
+
if (item.transDefaultValue && String(element) === String(item.transDefaultValue)) return
|
|
59
|
+
if (item.extControlType === 'relselectvalue') {
|
|
60
|
+
const elements = Array.isArray(element) ? element : [element]
|
|
61
|
+
data = `${data}&c_${item.sourceId}=${elements
|
|
62
|
+
.map((item: string) => {
|
|
63
|
+
return item.split('@R@')[1]
|
|
64
|
+
})
|
|
65
|
+
.join('@,@')}`
|
|
66
|
+
} else if (item.extControlType === 'multiselect') {
|
|
67
|
+
const elements = Array.isArray(element) ? element : [element]
|
|
68
|
+
elements.forEach((subitem: string) => {
|
|
69
|
+
data = `${data}&c_${item.sourceId}=${subitem}`
|
|
70
|
+
})
|
|
71
|
+
} else {
|
|
72
|
+
data = `${data}&c_${item.sourceId}=${element}`
|
|
72
73
|
}
|
|
73
74
|
})
|
|
74
75
|
|
|
@@ -104,7 +105,7 @@ function handleSubmit() {
|
|
|
104
105
|
</view>
|
|
105
106
|
<wd-popup v-model="show" position="bottom" custom-class="h-80vh" closable @close="handleClose">
|
|
106
107
|
<view class="relative box-border h-full p-1 bg-white dark:bg-[var(--wot-dark-background)]">
|
|
107
|
-
<view class="h-34px flex items-center justify-center text-black dark:text-[var(--wot-dark-color)]"
|
|
108
|
+
<view class="h-34px flex items-center justify-center text-black dark:text-[var(--wot-dark-color)]">筛选</view>
|
|
108
109
|
<formControl
|
|
109
110
|
ref="formControlRef"
|
|
110
111
|
:field-group="{
|
|
@@ -3,7 +3,7 @@ import { defineOptions, defineProps, onMounted, onUnmounted, ref } from 'vue'
|
|
|
3
3
|
import { onLoad } from '@dcloudio/uni-app'
|
|
4
4
|
import { listData, pageConfig, pageKey } from '../../api/page'
|
|
5
5
|
import foldCard2 from '../fold-card2/fold-card2.vue'
|
|
6
|
-
import type { Config, Entities } from '../../type'
|
|
6
|
+
import type { Config, EditButtonConfig, Entities } from '../../type'
|
|
7
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'
|
|
@@ -32,6 +32,11 @@ withDefaults(
|
|
|
32
32
|
* 标题旁标签(labelTag)是否展示,由父级读取控制,默认不展示。
|
|
33
33
|
*/
|
|
34
34
|
showLabel?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* 自定义编辑按钮配置:动态文字 / 显隐 / 点击行为。
|
|
37
|
+
* 不传时走组件内置的「编辑」按钮逻辑。
|
|
38
|
+
*/
|
|
39
|
+
editButtonConfig?: EditButtonConfig
|
|
35
40
|
}>(),
|
|
36
41
|
{
|
|
37
42
|
// 操作按钮区域(编辑/删除/morebutns)默认显示
|
|
@@ -92,6 +97,7 @@ const searchData = ref('')
|
|
|
92
97
|
const tabSearchData = ref('')
|
|
93
98
|
const pageType = ref('')
|
|
94
99
|
const mainCode = ref('')
|
|
100
|
+
const queryKey = ref('') // 用于导出接口的列表查询 key
|
|
95
101
|
const addEvent = generateHighResolutionID() // 全局事件名称
|
|
96
102
|
onLoad((option: any) => {
|
|
97
103
|
sourceId.value = option.sourceId
|
|
@@ -156,6 +162,8 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
|
156
162
|
try {
|
|
157
163
|
const res = await pageKey(sourceId.value, mainCode.value, qre) // 获取key
|
|
158
164
|
const data = await listData(res.key, pageNo, pageSize) // 获取数据
|
|
165
|
+
// 缓存最新一次的 queryKey,给顶部「导出」接口使用
|
|
166
|
+
queryKey.value = res.key || res.data?.key || ''
|
|
159
167
|
// const count = await getPageTotal(key.data?.key)// 获取总数
|
|
160
168
|
Zpaging.value.complete(data.entities)
|
|
161
169
|
|
|
@@ -219,6 +227,7 @@ function tabSearchClick(data: any) {
|
|
|
219
227
|
:page-type="pageType"
|
|
220
228
|
:config="config"
|
|
221
229
|
:show-buttons="showTopButtons"
|
|
230
|
+
:query-key="queryKey"
|
|
222
231
|
/>
|
|
223
232
|
</view>
|
|
224
233
|
<!-- 自定义tab搜索 -->
|
|
@@ -262,6 +271,7 @@ function tabSearchClick(data: any) {
|
|
|
262
271
|
:data="item"
|
|
263
272
|
:is-show-action="isShowAction"
|
|
264
273
|
:copy-mode="config.copyMode"
|
|
274
|
+
:edit-button-config="editButtonConfig"
|
|
265
275
|
/>
|
|
266
276
|
</template>
|
|
267
277
|
</productCard>
|
|
@@ -303,6 +313,7 @@ function tabSearchClick(data: any) {
|
|
|
303
313
|
:button-edit-action="config.buttonEditAction"
|
|
304
314
|
:is-show-action="isShowAction"
|
|
305
315
|
:copy-mode="config.copyMode"
|
|
316
|
+
:edit-button-config="editButtonConfig"
|
|
306
317
|
/>
|
|
307
318
|
</template>
|
|
308
319
|
</foldCard2>
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/type.ts
CHANGED
|
@@ -73,6 +73,28 @@ export interface PageData {
|
|
|
73
73
|
entities: Entities[]
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 编辑按钮的自定义配置(对标 w-table 的 editButtonConfig)。
|
|
78
|
+
* 用于父级在不改动组件内置跳转逻辑的前提下,定制按钮文字、显隐与点击行为。
|
|
79
|
+
* 回调统一接收 (data, ctx):
|
|
80
|
+
* - data:当前行实体(Entities,仅含 code/fieldMap/arrayMap)
|
|
81
|
+
* - ctx:组件补充的上下文(Entities 上缺失的 sourceId/code/mainCode/pageType 等)
|
|
82
|
+
*/
|
|
83
|
+
export interface EditButtonCtx {
|
|
84
|
+
sourceId: string
|
|
85
|
+
code: string
|
|
86
|
+
mainCode: string
|
|
87
|
+
pageType: string
|
|
88
|
+
}
|
|
89
|
+
export interface EditButtonConfig {
|
|
90
|
+
/** 动态按钮文字,默认「编辑」 */
|
|
91
|
+
label?: (data: Entities, ctx: EditButtonCtx) => string
|
|
92
|
+
/** 是否显示该按钮,默认 true;返回 false 时整颗按钮隐藏 */
|
|
93
|
+
show?: (data: Entities, ctx: EditButtonCtx) => boolean
|
|
94
|
+
/** 点击回调;提供时优先于组件内置的 edit() 跳转 */
|
|
95
|
+
clickAction?: (data: Entities, ctx: EditButtonCtx) => void
|
|
96
|
+
}
|
|
97
|
+
|
|
76
98
|
// 字段自定义校验规则(如 { message, pattern })
|
|
77
99
|
export interface FieldRule {
|
|
78
100
|
message?: string | null
|