EmailPanel.vue
4.94 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
<template>
<div class="p-4">
<BasicTable @register="registerTable">
<template #toolbar>
<!-- <a-button type="primary" class="my-4" @click="handleCreate"> 新增 </a-button> -->
<a-button type="primary" @click="handleCreate">新建</a-button>
<DrawerEdit @register="registerEdit" @success="handleSuccess" />
<DrawerCreate @register="registerCreate" @success2="handleSuccessCreate" />
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[
{
label: '编辑',
onClick: handleEdit.bind(null, record),
// auth: 'other', // 根据权限控制是否显示: 无权限,不显示
},
{
label: '删除',
popConfirm: {
title: '是否删除?',
confirm: handleDelete.bind(null, record),
},
// onClick: handleDelete.bind(null, record),
// auth: 'super', // 根据权限控制是否显示: 有权限,会显示
},
{
label: '启用',
popConfirm: {
title: '是否启用?',
confirm: handleOpen.bind(null, record),
},
ifShow: (_action) => {
return record.enableFlag !== 10; // 根据业务控制是否显示: 非enable状态的不显示启用按钮
},
},
{
label: '禁用',
popConfirm: {
title: '是否禁用?',
confirm: handleForbid.bind(null, record),
},
ifShow: () => {
return record.enableFlag === 10; // 根据业务控制是否显示: enable状态的显示禁用按钮
},
},
]"
:dropDownActions="[
// {
// label: '同时控制',
// popConfirm: {
// title: '是否动态显示?',
// confirm: handleOpen.bind(null, record),
// },
// auth: 'super', // 同时根据权限和业务控制是否显示
// ifShow: () => {
// return true;
// },
// },
]"
/>
</template>
</template>
</BasicTable>
</div>
</template>
<script lang="ts" setup>
import { BasicTable, useTable, BasicColumn, TableAction } from '@/components/Table';
import DrawerEdit from './DrawerEdit.vue';
import DrawerCreate from './DrawerCreate.vue';
import { useDrawer } from '@/components/Drawer';
import { columns } from './data';
import {
getEmailList,
getList,
emailCreate,
emailDelete,
emailEdit,
emailOpt,
} from '/@/api/sys/config';
import { ref, reactive } from 'vue';
const [registerEdit, { openDrawer: openDrawerEdit }] = useDrawer();
const [registerCreate, { openDrawer: openDrawerCreate }] = useDrawer();
const [registerTable, { reload }] = useTable({
// title: 'TableAction组件及固定列示例',
api: getEmailList,
pagination: false,
columns: columns,
bordered: true,
rowKey: 'id',
// rowSelection: {
// type: 'checkbox',
// },
actionColumn: {
width: 180,
title: '操作',
dataIndex: 'action',
},
// showSelectionBar: true, // 显示多选状态栏
});
function handleCreate() {
openDrawerCreate(true, {
isUpdate: false,
});
}
function handleEdit(record) {
console.log('点击了编辑', record);
openDrawerEdit(true, {
data: record,
isUpdate: true,
});
}
// async function handleSuccess({ isUpdate, values }) {
// console.log(values, 888, 999);
// if (isUpdate) {
// await emailEdit({ ...values });
// } else {
// await emailCreate({ ...values });
// }
// console.log(isUpdate);
// console.log(values);
// reload();
// }
async function handleSuccess({ values }) {
console.log(values, 899);
// const valueJson = JSON.stringify(values);
// await emailEdit({ values.id });
reload();
}
async function handleSuccessCreate({ values }) {
// await emailCreate({ ...values });
const valueJson = JSON.stringify(values);
console.log(valueJson, 777);
reload();
}
async function handleDelete(record: any) {
console.log('点击了删除', record);
await emailDelete({ id: record.id });
reload();
}
async function handleOpen(record) {
console.log(record, 'opt');
await emailOpt({ id: record.id, enableflag: record.enableFlag === 10 ? 30 : 10 });
reload();
}
async function handleForbid(record) {
console.log(record.id, record.enableFlag, 999);
await emailOpt({ id: record.id, enableflag: record.enableFlag === 10 ? 30 : 10 });
reload();
}
</script>
<style></style>