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
110
111
112
<script setup lang="ts">
import { reactive, watchEffect, computed } from 'vue';
import { isEmpty, every, omit } from 'src/common/utils';
import type {
CellRenderButtonsType as ButtonsType,
MoreButtonsType,
} from 'src/common/types';
const props = defineProps<{
params: any;
}>();
/**
* buttons: [
* {
* tooltip: '删除',
* round: true,
* icon: 'add',
* unelevated: true,
* callback: (data: any) => {
* onDel(data);
* },
* },
* ];
*/
const state = reactive({
buttons: [] as ButtonsType[],
moreButtons: {} as MoreButtonsType,
});
watchEffect(() => {
state.buttons = props.params.buttons || [];
state.moreButtons = props.params.moreButtons || {};
});
const showMoreButtons = computed(() => {
const hide = state.moreButtons.hide;
const children = state.moreButtons.children;
if (hide) {
return false;
} else {
if (isEmpty(children)) {
return false;
} else {
if (every(children, 'hide')) {
return false;
} else {
return true;
}
}
}
});
const showButtons = computed(() => {
const buttons = state.buttons;
if (isEmpty(buttons)) {
return false;
} else {
if (every(buttons, 'hide')) {
return false;
} else {
return true;
}
}
});
const moreButton = computed(() => {
return omit(state.moreButtons, 'children');
});
</script>
<template>
<div>
<div class="row">
<div class="q-gutter-xs" v-if="showButtons">
<q-btn
v-for="(item, index) in state.buttons"
:key="index"
v-bind="item"
@click="item.callback(props.params)"
>
<q-tooltip v-if="item.tooltip">
{{ item.tooltip }}
</q-tooltip>
</q-btn>
</div>
<div class="q-gutter-xs" v-if="showMoreButtons">
<q-btn v-bind="moreButton">
<q-menu>
<q-list style="min-width: 100px">
<q-item
clickable
v-close-popup
v-for="(item, index) in state.moreButtons.children"
:key="index"
@click="item.callback(props.params)"
>
<q-item-section avatar v-if="!isEmpty(item.icon)">
<q-icon :color="item.color || 'grey-9'" :name="item.icon" />
</q-item-section>
<q-item-section>{{ item.label }}</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</div>
</div>
</div>
</template>
<style lang="scss" scoped></style>