index.vue
7.21 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<script lang="ts" setup>
import { Button, Tooltip, Card, Popconfirm } from 'ant-design-vue';
import { AuthIcon, EnumTableCardMode } from '/@/components/Widget';
import { useMessage } from '/@/hooks/web/useMessage';
import { BasicCardList, useCardList } from '/@/components/CardList';
import { ref } from 'vue';
import { HandleOperationEnum, HandleOperationNameEnum } from '../../config';
import { deleteApplicationConfig, applicationConfigPage } from '/@/api/application/application';
import { ApplicationConfigItemType } from '/@/api/application/model/application';
import { FormDrawer } from '../FormDrawer';
import { useDrawer } from '/@/components/Drawer';
import moment from 'moment';
import { isArray } from '/@/utils/is';
import AuthDropDown from '/@/components/Widget/AuthDropDown.vue';
import { useI18n } from '/@/hooks/web/useI18n';
import { searchFormSchema } from '../FormDrawer/config';
defineProps<{
mode: EnumTableCardMode;
}>();
defineEmits(['register']);
enum DropMenuEvent {
DELETE = 'delete',
}
const { t } = useI18n();
const { createMessage } = useMessage();
const disabledDeleteFlag = ref(true);
const [registerCardList, { reload, getSelectedRecords, clearSelectedKeys }] = useCardList({
api: applicationConfigPage,
useSearchForm: true,
gutter: 4,
rowKey: 'id',
formConfig: {
schemas: searchFormSchema,
labelWidth: 100,
baseColProps: { span: 8 },
},
selections: {
beforeSelectValidate: () => {
return true;
},
onSelect: (_record, _flag, allSelecteds) => {
disabledDeleteFlag.value = !allSelecteds.length;
},
onSelectAll: () => {
// 全选事件
disabledDeleteFlag.value = false;
},
onUnSelectAll: () => {
// 反选事件
disabledDeleteFlag.value = true;
},
onSelectToggle: (status: boolean) => {
// 全选是false,反选是true
if (!status) disabledDeleteFlag.value = false;
else disabledDeleteFlag.value = true;
},
},
});
const [registerApplicationConfigFormDrawer, { openDrawer: openApplicationConfigFormDrawer }] =
useDrawer();
const handleApplicationConfigIsSuccess = () => reload();
const handleOperationEvent = (
event: HandleOperationEnum,
record: ApplicationConfigItemType | null
) => {
const isUpdate = event === HandleOperationEnum.CREATE ? false : true;
const isUpdateText =
event === HandleOperationEnum.CREATE
? HandleOperationNameEnum.CREATE
: event === HandleOperationEnum.UPDATE
? HandleOperationNameEnum.UPDATE
: HandleOperationNameEnum.VIEW;
if (event === HandleOperationEnum.VIEW) {
openApplicationConfigFormDrawer(true, { isUpdate, record, isUpdateText, event });
} else {
openApplicationConfigFormDrawer(true, { isUpdate, record, isUpdateText, event });
}
};
const handleDelete = async (event: HandleOperationEnum, id?: string | null) => {
try {
if (event === HandleOperationEnum.BATCH_DELETE) {
const batchDeleteIds = getSelectedRecords().map(
(rowRecord: ApplicationConfigItemType) => rowRecord?.id
) as string[];
if (isArray(batchDeleteIds) && batchDeleteIds.length === 0) return;
await deleteApplicationConfig(batchDeleteIds);
} else {
await deleteApplicationConfig([id] as string[]);
}
createMessage.success(t('common.deleteSuccessText'));
clearSelectedKeys();
disabledDeleteFlag.value = true;
await reload();
} catch (error) {
throw error;
}
};
</script>
<template>
<section>
<BasicCardList @register="registerCardList">
<template #toolbar>
<Button type="primary" @click="handleOperationEvent(HandleOperationEnum.CREATE, null)">
{{ t('application.config.action.create') }}
</Button>
<Popconfirm
:title="t('common.batchDeleteConfirmText')"
@confirm="handleDelete(HandleOperationEnum.BATCH_DELETE, null)"
:disabled="disabledDeleteFlag"
>
<Button type="primary" danger :disabled="disabledDeleteFlag">
{{ t('common.batchDeleteText') }}
</Button>
</Popconfirm>
</template>
<template #renderItem="{ item }: BasicCardListRenderItem<ApplicationConfigItemType>">
<Card hoverable>
<template #cover>
<div class="w-full h-full !flex flex-col justify-between m-3">
<div class="!flex justify-between align-center text-center">
<Tooltip :title="item.name">
<span class="truncate font-bold fill-dark-900 text-sm"> {{ item.name }} </span>
</Tooltip>
</div>
<div class="!flex justify-between align-center text-center">
<span class="truncate text-xs" style="color: #86909c">
{{ moment(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}
</span>
</div>
</div>
</template>
<template class="ant-card-actions" #actions>
<Tooltip :title="t('common.detailText')">
<AuthIcon
class="!text-lg"
icon="ant-design:eye-outlined"
@click.stop="handleOperationEvent(HandleOperationEnum.VIEW, item)"
/>
</Tooltip>
<Tooltip :title="t('common.editText')">
<AuthIcon
class="!text-lg"
icon="ant-design:form-outlined"
@click.stop="handleOperationEvent(HandleOperationEnum.UPDATE, item)"
/>
</Tooltip>
<AuthDropDown
@click.stop
:trigger="['hover']"
:drop-menu-list="[
{
text: t('common.delText'),
event: DropMenuEvent.DELETE,
icon: 'ant-design:delete-outlined',
popconfirm: {
title: t('common.deleteConfirmText'),
onConfirm: handleDelete.bind(null, HandleOperationEnum.DELETE, item?.id),
},
},
]"
/>
</template>
<Card.Meta>
<template #description>
<div class="truncate h-17 !flex justify-between flex-col">
<div class="truncate !flex">
<span class="text-xs" style="color: #86909c">
{{ t('application.config.text.organizationName') }}
</span>
<Tooltip :title="item.organizationName">
<span class="truncate ml-7.5 text-xs" style="color: #00b42a">{{
item.organizationName
}}</span>
</Tooltip>
</div>
</div>
</template>
</Card.Meta>
</Card>
</template>
</BasicCardList>
<FormDrawer
@register="registerApplicationConfigFormDrawer"
@success="handleApplicationConfigIsSuccess"
/>
</section>
</template>
<style lang="less" scoped>
.profile-list:deep(.ant-image-img) {
@apply !w-full !h-full;
}
.profile-list:deep(.ant-card-body) {
@apply !p-4;
}
:deep(.ant-card-body) {
padding: 12px;
}
</style>