index.vue
6.46 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
<template>
<div>
<BasicTable
@register="registerTable"
:loading="loading"
:rowSelection="{ type: 'checkbox' }"
:clickToRowSelect="false"
>
<template #toolbar>
<Authority :value="PermissionDataFlowEnum.PERMISSION_POST">
<a-button
type="primary"
@click="handleBussinessModal(BusinessDataFlowTextEnum.BUSINESS_MODAL_ADD_TEXT, null)"
>
{{ BusinessDataFlowTextEnum.BUSINESS_ADD_TEXT }}
</a-button>
</Authority>
<Authority :value="PermissionDataFlowEnum.PERMISSION_DELETE">
<Popconfirm
title="您确定要批量删除数据"
ok-text="确定"
cancel-text="取消"
@confirm="handleDeleteOrBatchDelete(null)"
>
<a-button type="primary" color="error" :disabled="hasBatchDelete">
<span :style="{ color: hasBatchDelete ? 'grey' : 'white' }">{{
BusinessDataFlowTextEnum.BUSINESS_DELETE_TEXT
}}</span>
</a-button>
</Popconfirm>
</Authority>
<a-button
:disabled="hasBatchDelete"
@click="handleBatchEnable"
:type="hasBatchDelete ? 'default' : 'primary'"
>
<span :style="{ color: hasBatchDelete ? 'grey' : 'white' }">{{
BusinessDataFlowTextEnum.BUSINESS_ENABLE_TEXT
}}</span>
</a-button>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: BusinessDataFlowTextEnum.BUSINESS_VIEW_TEXT,
auth: PermissionDataFlowEnum.PERMISSION_GET,
icon: 'ant-design:eye-outlined',
onClick: handleBussinessModal.bind(
null,
BusinessDataFlowTextEnum.BUSINESS_MODAL_VIEW_TEXT,
record
),
ifShow: record.status == 1,
},
{
label: BusinessDataFlowTextEnum.BUSINESS_UPDATE_TEXT,
auth: PermissionDataFlowEnum.PERMISSION_UPDATE,
icon: 'clarity:note-edit-line',
onClick: handleBussinessModal.bind(
null,
BusinessDataFlowTextEnum.BUSINESS_MODAL_EDIT_TEXT,
record
),
ifShow: record.status === 0,
},
{
label: BusinessDataFlowTextEnum.BUSINESS_DELETE_TEXT.slice(2),
auth: PermissionDataFlowEnum.PERMISSION_DELETE,
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDeleteOrBatchDelete.bind(null, record),
},
ifShow: record.status === 0,
},
]"
/>
</template>
<template #status="{ record }">
<Authority :value="PermissionDataFlowEnum.PERMISSION_UPDATE">
<Switch
:checked="record.status === 1"
:loading="record.pendingStatus"
checkedChildren="启用"
unCheckedChildren="禁用"
@change="(checked:boolean)=>hanldeSwitch(checked,record)"
/>
</Authority>
<Tag
v-if="!hasPermission(PermissionDataFlowEnum.PERMISSION_UPDATE)"
:color="record.status ? 'green' : 'red'"
>
{{ record.status ? '启用' : '禁用' }}
</Tag>
</template>
</BasicTable>
<DataFlowModal @register="registerModal" @success="handleSuccess" />
</div>
</template>
<script lang="ts" setup name="dataFlowIndex">
import { ref, nextTick } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import {
getConvertApi,
isEnableOrDisableApi,
deleteConvertApi,
} from '/@/api/datamanager/dataManagerApi';
import { useMessage } from '/@/hooks/web/useMessage';
import { Authority } from '/@/components/Authority';
import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
import { Switch, Popconfirm, Tag } from 'ant-design-vue';
import { PermissionDataFlowEnum, BusinessDataFlowTextEnum } from './enum';
import { DataFlowModal } from './components/dataflowmodal';
import { defaultTableAttribute } from './config';
import { usePermission } from '/@/hooks/web/usePermission';
const { createMessage } = useMessage();
const loading = ref(true);
const { hasPermission } = usePermission();
const handleSuccess = () => {
reload();
};
const [registerModal, { openModal }] = useModal();
const [registerTable, { setProps, reload, getSelectRowKeys, clearSelectedRowKeys }] = useTable({
api: getConvertApi,
...defaultTableAttribute,
});
const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
useBatchDelete(deleteConvertApi, handleSuccess, setProps) as any;
selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
//业务 status为1则禁用
if (record.status === 1) return { disabled: true };
else {
return { disabled: false };
}
};
nextTick(() => {
setProps(selectionOptions);
});
//业务 弹窗
const handleBussinessModal = (text, record) => {
const modalParams = {
text,
record,
};
openModal(true, modalParams);
};
const handleBatchEnable = async () => {
const params: Record<string, any> = {
convertIds: getSelectRowKeys(),
status: 1,
};
const res = await isEnableOrDisableApi(params);
if (!res) createMessage.error('流转配置多项启用失败');
else {
createMessage.success('流转配置多项启用成功');
}
setPropsLoading(false);
handleSuccess();
};
const setPropsLoading = (loading: boolean) => {
setProps({
loading,
});
clearSelectedRowKeys();
resetSelectedRowKeys();
};
const hanldeSwitch = async (checked, record) => {
try {
setPropsLoading(true);
const status = checked ? 1 : 0;
const params: Record<string, any> = {
convertIds: [record.id],
nodeType: 1,
status,
};
const resp = await isEnableOrDisableApi(params);
if (!resp) createMessage.error(`数据流转配置${resp && status ? '启用' : '禁用'}失败`);
else {
createMessage.success(`数据流转配置${resp && status ? '启用' : '禁用'}成功`);
}
} finally {
setPropsLoading(false);
handleSuccess();
}
};
</script>