wui-components-v2 1.2.31 → 1.2.32
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.
|
@@ -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, EditButtonConfig, Entities, Enums, Fields, Groups, rowActions } from '../../type'
|
|
5
|
+
import type { ClassEditConfigs, Columns, DeleteButtonConfig, DetailButtonConfig, 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'
|
|
@@ -41,6 +41,16 @@ const props = defineProps<{
|
|
|
41
41
|
* 不传时走组件内置的 edit() 跳转逻辑。
|
|
42
42
|
*/
|
|
43
43
|
editButtonConfig?: EditButtonConfig
|
|
44
|
+
/**
|
|
45
|
+
* 自定义删除按钮配置:动态文字 / 显隐 / 点击行为。
|
|
46
|
+
* 不传时走组件内置的 del() 逻辑。
|
|
47
|
+
*/
|
|
48
|
+
deleteButtonConfig?: DeleteButtonConfig
|
|
49
|
+
/**
|
|
50
|
+
* 自定义详情按钮配置:动态文字 / 显隐 / 点击行为。
|
|
51
|
+
* 不传时走组件内置的 detail() 跳转逻辑。
|
|
52
|
+
*/
|
|
53
|
+
detailButtonConfig?: DetailButtonConfig
|
|
44
54
|
}>()
|
|
45
55
|
const toast = useGlobalToast()
|
|
46
56
|
const message = useGlobalMessage()
|
|
@@ -134,6 +144,86 @@ function editButtonClick() {
|
|
|
134
144
|
edit()
|
|
135
145
|
}
|
|
136
146
|
|
|
147
|
+
// ===== 自定义删除按钮(deleteButtonConfig) =====
|
|
148
|
+
// 按钮文字:优先用 deleteButtonConfig.label,否则默认「删除」
|
|
149
|
+
const deleteButtonLabel = computed(() => {
|
|
150
|
+
if (props.deleteButtonConfig?.label) {
|
|
151
|
+
try {
|
|
152
|
+
return props.deleteButtonConfig.label(props.data, editButtonCtx.value) || '删除'
|
|
153
|
+
} catch (e) {
|
|
154
|
+
console.error('[deleteButtonConfig.label] 执行异常', e)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return '删除'
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// 是否显示:优先用 deleteButtonConfig.show,否则默认显示
|
|
161
|
+
const deleteButtonShow = computed(() => {
|
|
162
|
+
if (props.deleteButtonConfig?.show) {
|
|
163
|
+
try {
|
|
164
|
+
return props.deleteButtonConfig.show(props.data, editButtonCtx.value)
|
|
165
|
+
} catch (e) {
|
|
166
|
+
console.error('[deleteButtonConfig.show] 执行异常', e)
|
|
167
|
+
return true
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// 未配置自定义时,沿用原有「singleDelete 且 visible」逻辑
|
|
171
|
+
return props.item.buttons.includes('singleDelete') && isActionVisible(props.buttonDeleteAction)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// 点击:优先走 deleteButtonConfig.clickAction,否则回退默认 del() 逻辑
|
|
175
|
+
function deleteButtonClick() {
|
|
176
|
+
if (props.deleteButtonConfig?.clickAction) {
|
|
177
|
+
try {
|
|
178
|
+
props.deleteButtonConfig.clickAction(props.data, editButtonCtx.value)
|
|
179
|
+
} catch (e) {
|
|
180
|
+
console.error('[deleteButtonConfig.clickAction] 执行异常', e)
|
|
181
|
+
}
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
del()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ===== 自定义详情按钮(detailButtonConfig) =====
|
|
188
|
+
// 按钮文字:优先用 detailButtonConfig.label,否则默认「详情」
|
|
189
|
+
const detailButtonLabel = computed(() => {
|
|
190
|
+
if (props.detailButtonConfig?.label) {
|
|
191
|
+
try {
|
|
192
|
+
return props.detailButtonConfig.label(props.data, editButtonCtx.value) || '详情'
|
|
193
|
+
} catch (e) {
|
|
194
|
+
console.error('[detailButtonConfig.label] 执行异常', e)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return '详情'
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// 是否显示:优先用 detailButtonConfig.show,否则默认显示
|
|
201
|
+
const detailButtonShow = computed(() => {
|
|
202
|
+
if (props.detailButtonConfig?.show) {
|
|
203
|
+
try {
|
|
204
|
+
return props.detailButtonConfig.show(props.data, editButtonCtx.value)
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.error('[detailButtonConfig.show] 执行异常', e)
|
|
207
|
+
return true
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 未配置自定义时,沿用原有「detail 按钮存在」逻辑
|
|
211
|
+
return props.item.buttons.includes('detail')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
// 点击:优先走 detailButtonConfig.clickAction,否则回退默认 detail() 跳转
|
|
215
|
+
function detailButtonClick() {
|
|
216
|
+
if (props.detailButtonConfig?.clickAction) {
|
|
217
|
+
try {
|
|
218
|
+
props.detailButtonConfig.clickAction(props.data, editButtonCtx.value)
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.error('[detailButtonConfig.clickAction] 执行异常', e)
|
|
221
|
+
}
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
detail()
|
|
225
|
+
}
|
|
226
|
+
|
|
137
227
|
const actionItem = ref<Groups>()
|
|
138
228
|
const actionItemShow = ref(false) // rowActions输入弹框开关
|
|
139
229
|
// 打开rowActions弹框
|
|
@@ -366,18 +456,25 @@ console.log(props, '3333333333333')
|
|
|
366
456
|
>
|
|
367
457
|
{{ editButtonLabel }}
|
|
368
458
|
</wd-button>
|
|
369
|
-
<wd-button
|
|
459
|
+
<wd-button
|
|
460
|
+
v-if="isShowAction !== false && props.item.buttons.includes('detail') && detailButtonShow"
|
|
461
|
+
size="small"
|
|
462
|
+
type="info"
|
|
463
|
+
@click="detailButtonClick()"
|
|
464
|
+
>
|
|
465
|
+
{{ detailButtonLabel }}
|
|
466
|
+
</wd-button>
|
|
370
467
|
<wd-button
|
|
371
468
|
v-if="
|
|
372
469
|
isShowAction !== false &&
|
|
373
470
|
props.item.buttons.includes('singleDelete') &&
|
|
374
|
-
|
|
471
|
+
deleteButtonShow
|
|
375
472
|
"
|
|
376
473
|
size="small"
|
|
377
474
|
type="danger"
|
|
378
|
-
@click="
|
|
475
|
+
@click="deleteButtonClick()"
|
|
379
476
|
>
|
|
380
|
-
|
|
477
|
+
{{ deleteButtonLabel }}
|
|
381
478
|
</wd-button>
|
|
382
479
|
<ActionPopup
|
|
383
480
|
v-model:show="actionItemShow"
|
|
@@ -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, EditButtonConfig, Entities } from '../../type'
|
|
6
|
+
import type { Config, DeleteButtonConfig, DetailButtonConfig, 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'
|
|
@@ -37,6 +37,16 @@ withDefaults(
|
|
|
37
37
|
* 不传时走组件内置的「编辑」按钮逻辑。
|
|
38
38
|
*/
|
|
39
39
|
editButtonConfig?: EditButtonConfig
|
|
40
|
+
/**
|
|
41
|
+
* 自定义删除按钮配置:动态文字 / 显隐 / 点击行为。
|
|
42
|
+
* 不传时走组件内置的「删除」按钮逻辑。
|
|
43
|
+
*/
|
|
44
|
+
deleteButtonConfig?: DeleteButtonConfig
|
|
45
|
+
/**
|
|
46
|
+
* 自定义详情按钮配置:动态文字 / 显隐 / 点击行为。
|
|
47
|
+
* 不传时走组件内置的「详情」按钮逻辑。
|
|
48
|
+
*/
|
|
49
|
+
detailButtonConfig?: DetailButtonConfig
|
|
40
50
|
}>(),
|
|
41
51
|
{
|
|
42
52
|
// 操作按钮区域(编辑/删除/morebutns)默认显示
|
|
@@ -272,6 +282,8 @@ function tabSearchClick(data: any) {
|
|
|
272
282
|
:is-show-action="isShowAction"
|
|
273
283
|
:copy-mode="config.copyMode"
|
|
274
284
|
:edit-button-config="editButtonConfig"
|
|
285
|
+
:delete-button-config="deleteButtonConfig"
|
|
286
|
+
:detail-button-config="detailButtonConfig"
|
|
275
287
|
/>
|
|
276
288
|
</template>
|
|
277
289
|
</productCard>
|
|
@@ -314,6 +326,8 @@ function tabSearchClick(data: any) {
|
|
|
314
326
|
:is-show-action="isShowAction"
|
|
315
327
|
:copy-mode="config.copyMode"
|
|
316
328
|
:edit-button-config="editButtonConfig"
|
|
329
|
+
:delete-button-config="deleteButtonConfig"
|
|
330
|
+
:detail-button-config="detailButtonConfig"
|
|
317
331
|
/>
|
|
318
332
|
</template>
|
|
319
333
|
</foldCard2>
|
package/package.json
CHANGED
package/type.ts
CHANGED
|
@@ -95,6 +95,44 @@ export interface EditButtonConfig {
|
|
|
95
95
|
clickAction?: (data: Entities, ctx: EditButtonCtx) => void
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* 删除按钮的自定义配置。
|
|
100
|
+
* 用于父级在不改动组件内置删除逻辑的前提下,定制按钮文字、显隐与点击行为。
|
|
101
|
+
*/
|
|
102
|
+
export interface DeleteButtonCtx {
|
|
103
|
+
sourceId: string
|
|
104
|
+
code: string
|
|
105
|
+
mainCode: string
|
|
106
|
+
pageType: string
|
|
107
|
+
}
|
|
108
|
+
export interface DeleteButtonConfig {
|
|
109
|
+
/** 动态按钮文字,默认「删除」 */
|
|
110
|
+
label?: (data: Entities, ctx: DeleteButtonCtx) => string
|
|
111
|
+
/** 是否显示该按钮,默认 true;返回 false 时整颗按钮隐藏 */
|
|
112
|
+
show?: (data: Entities, ctx: DeleteButtonCtx) => boolean
|
|
113
|
+
/** 点击回调;提供时优先于组件内置的 del() 逻辑 */
|
|
114
|
+
clickAction?: (data: Entities, ctx: DeleteButtonCtx) => void
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 详情按钮的自定义配置。
|
|
119
|
+
* 用于父级在不改动组件内置详情跳转的前提下,定制按钮文字、显隐与点击行为。
|
|
120
|
+
*/
|
|
121
|
+
export interface DetailButtonCtx {
|
|
122
|
+
sourceId: string
|
|
123
|
+
code: string
|
|
124
|
+
mainCode: string
|
|
125
|
+
pageType: string
|
|
126
|
+
}
|
|
127
|
+
export interface DetailButtonConfig {
|
|
128
|
+
/** 动态按钮文字,默认「详情」 */
|
|
129
|
+
label?: (data: Entities, ctx: DetailButtonCtx) => string
|
|
130
|
+
/** 是否显示该按钮,默认 true;返回 false 时整颗按钮隐藏 */
|
|
131
|
+
show?: (data: Entities, ctx: DetailButtonCtx) => boolean
|
|
132
|
+
/** 点击回调;提供时优先于组件内置的 detail() 跳转 */
|
|
133
|
+
clickAction?: (data: Entities, ctx: DetailButtonCtx) => void
|
|
134
|
+
}
|
|
135
|
+
|
|
98
136
|
// 字段自定义校验规则(如 { message, pattern })
|
|
99
137
|
export interface FieldRule {
|
|
100
138
|
message?: string | null
|