Appearance
按钮配置指南
在配置列表按钮时,可以参考“采购申请”页面。列表按钮设计为可跨多个页面复用的功能,列表模板已经内置了这些功能,您只需根据具体需求传递 type
或配置 url
即可使用。 目前,内置的通用按钮功能包括(未来将根据实际情况进行补充):
- 新增
- 导出
- 导入
- 列自定义
- 帮助说明
- 附件说明
- 视频说明
- 获取 ERP 数据
- 推送到 ERP
代码示例
请注意,所有的按钮组配置都需要在 buttonConfig
内进行配置。以下是一个配置示例:
vue
<template>
<q-list-layout ref="listLayoutRef" :apiUrls="apiUrls" :pageData="pageData" @add-button-click="handleCreate"/>
</template>
<script lang="ts" setup>
import { srmI18n } from '@/utils/srmI18n'
import { reactive, ref } from 'vue'
import { GlobalListPageLayoutTypes, message } from '@qqt-product/ui'
const listLayoutRef = ref()
const apiUrls = reactive({
columnsCode: 'purchaseRequestHeadList',
excelCode: 'PurchaseRequestHeadExcel',
list: '/demand/purchaseRequestHead/list',
countTabsUrl: '/demand/purchaseRequestHead/counts',
})
// 新增方法 弹窗回调事件
const handleCreate = ({ row }: { row: GlobalListPageLayoutTypes.CurrentRow }) => {
console.log(row)
setCurrentRow(row)
const id = (row.id as string) || ''
router.push({ path: `/srm/demand/purchase/PurchaseRequestHeadEdit/${id}`, query: { t: +new Date() } })
}
const pageData = reactive<GlobalListPageLayoutTypes.PageData>({
buttonConfig: { // 按钮组配置
buttons: [
{
label: srmI18n('i18n_title_add', '新增'),
authorityCode: 'purchaseRequest#purchaseRequestHead:add',
args: {
businessType: 'purchaseRequest',
},
icon: {
type: 'icon-Q-add',
},
attrs: {
type: 'primary',
},
type: 'add',
},
{
authorityCode: 'purchaseRequest#purchaseRequestHead:export',
label: srmI18n('i18n_title_export', '导出'),
args: {
// fileName: '导出文件名字', // 默认取当前路由title
url: '/demand/purchaseRequestHead/exportXls', // 原来的 exportXlsUrl
},
icon: {
type: 'icon-Q-export',
},
type: 'export',
},
{
label: srmI18n('i18n_title_improt', '导入'),
authorityCode: 'purchaseRequest#purchaseRequestHead:import',
icon: 'import',
args: {
excelCode: 'PurchaseRequestHeadExcel', // excelCode
},
type: 'import',
},
{
label: srmI18n('i18n_alert_SMWWWWF_b44eb4e2', '获取ERP数据'),
authorityCode: 'purchaseRequest#purchaseRequestHead:getPurchaseRequestByERP',
args: {
url: '/demand/purchaseRequestHead/getPurchaseRequestByERP',
},
type: 'data-by-ERP',
},
{
label: srmI18n('i18n_btn_YduWWW_211799ec', '推送到ERP'),
authorityCode: 'purchaseRequest#purchaseRequestHead:pushPurchaseRequestData',
args: {
url: '/demand/purchaseRequestHead/pushPurchaseRequestData',
},
type: 'data-to-ERP',
},
{
label: srmI18n('i18n_title_listCustom', '列自定义'),
icon: {
type: 'icon-Q-setting',
},
type: 'setting',
},
{
label: srmI18n('i18n_title_helpText', '帮助说明'),
icon: {
type: 'icon-Q-help-text',
},
type: 'help-text',
},
{
label: srmI18n('i18n_title_attachmentExplain', '附件说明'),
icon: {
type: 'icon-Q-attachment-text',
},
type: 'attachment-text',
},
{
label: srmI18n('i18n_alert_KNlR_40eee965', '视频说明'),
icon: {
type: 'icon-Q-video-text',
},
type: 'video-text',
},
],
}
})
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
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
在这个示例中,我们定义了一个包含多个按钮的 buttonConfig
对象。每个按钮都有一个 type
属性,用于指定按钮的功能类型。您可以根据需要添加其他配置属性,以自定义按钮的行为和外观。
效果截图预览
自定义按钮事件
要实现自定义选项按钮事件,仅需配置 click
函数。此函数的参数将返回当前按钮的信息。 请注意,如果按钮是通用功能按钮且已经配置了 type
,则再配置 click
函数将意味着不执行列表模板内置的函数,而是执行您自定义的 click
函数。例如,下面的代码展示了如何重置新增方法:
代码展示
js
buttonConfig: {
buttons: [
{
label: srmI18n('i18n_btn_YduXL_bf0b657f', '推送到商城'),
authorityCode: 'purchaseRequest#purchaseRequestHead:pushPurchaseRequestDataToMall',
icon: 'arrow-up',
click: pushDataToMall,
}
]
}
function pushDataToMall(buttonItem) {
...
}
// 通用功能新增,自定义事件
buttonConfig: {
buttons: [
{
label: srmI18n('i18n_title_add', '新增'),
authorityCode: 'purchaseRequest#purchaseRequestHead:add',
args: {
businessType: 'purchaseRequest',
},
icon: {
type: 'icon-Q-add',
},
type: 'add',
click(buttonItem){
// 走下面自定义事件,列表模板将不触发add-button-click方法
...
}
},
]
}
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
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
按钮-置灰
按钮组以及后面介绍的选项组,都是只能配置置灰功能,按钮显隐由权限码控制
disabled 返回可以是方法或者是布尔值
代码展示
json
buttonConfig: {
buttons: [
{
label: srmI18n('i18n_title_add', '新增'),
authorityCode: 'purchaseRequest#purchaseRequestHead:add',
args: {
businessType: 'purchaseRequest',
},
icon: {
type: 'icon-Q-add',
},
type: 'add',
// disabled: true,
disabled(buttonItem) {
return true
},
},
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
API
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
label | 按钮文字 | string | |
type | 按钮类型,通用按钮时必填, 如:type:‘add’ | string | |
attrs | ant-design 按钮 Button 属性都可以配置 | object | |
args | 参数,给功能使用,比如请求的 url 等 | object | |
authorityCode | 权限码 | string | |
disabled | 置灰 | boolean| function | |
click | 点击事件 | function | |
handleBefore | 点击事件前钩子 | Promise | |
handleAfter | 点击事件后钩子 | Promise |
TS 类型-ButtonItem
typescript
export interface ButtonItem {
label?: string;
icon?: string | ObjectMap;
type?: string;
attrs?: ObjectMap;
args?: {
url?: string;
[key: string]: unknown;
};
authorityCode?: string;
disabled?: (<T>(args: T) => boolean | void) | boolean;
click?: (args: ButtonItem) => void;
handleBefore?: <T>(args: T) => Promise<T> | void;
handleAfter?: <T>(args: T) => Promise<T> | void;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
工具栏按钮(列表右上按钮)
工具栏按钮配置参数跟上面的按钮一致,为了统一建议用有意义图标,
使用示列代码
js
toolsConfig: {
buttons: [
{
icon: {
type: "icon-Q-card",
},
attrs: {
shape: "circle",
},
type: "zoom",
click: () => {
toggleCardMode.value = !toggleCardMode.value;
pageData.onlyShowNav = true;
},
},
];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17