index.vue
5.63 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
<script setup lang="ts">
import { ref } from 'vue';
import { columns, searchFormSchema } from '.';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { Button, Popconfirm, Switch } from 'ant-design-vue';
import { useBatchOperation } from '/@/utils/useBatchOperation';
import { useMessage } from '/@/hooks/web/useMessage';
import { Authority } from '/@/components/Authority';
import { useModal } from '/@/components/Modal';
import { classModal } from './components/index';
import { useDrawer } from '/@/components/Drawer';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import { authBtn } from '/@/enums/roleEnum';
import {
getDeviceClassList,
deleteDeviceClass,
deviceProfileCategory,
} from '/@/api/device/classModal';
import { BasicDrawer } from '/@/components/Drawer';
import PhysicalModelManagementStep from '/@/views/device/profiles/step/PhysicalModelManagementStep.vue';
const [
registerTable,
{ reload, setLoading, getSelectRowKeys, setSelectedRowKeys, getRowSelection },
] = useTable({
title: '产品品类列表',
api: getDeviceClassList,
columns,
formConfig: {
labelWidth: 100,
schemas: searchFormSchema,
},
immediate: true,
useSearchForm: true,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
clickToRowSelect: false,
rowKey: 'id',
// searchInfo: searchInfo,
actionColumn: {
width: 230,
title: '操作',
slots: { customRender: 'action' },
fixed: 'right',
},
rowSelection: {
type: 'checkbox',
getCheckboxProps: (record: any) => {
return { disabled: !!record.status };
},
},
});
const [registerModal, { openModal }] = useModal();
const [registerDetailDrawer, { openDrawer }] = useDrawer();
const { createMessage } = useMessage();
const { isExistOption } = useBatchOperation(getRowSelection, setSelectedRowKeys);
const switchLoading = ref<boolean>(false);
const userInfo: any = getAuthCache(USER_INFO_KEY);
const role: string = userInfo.roles[0];
const handleReload = () => {
setSelectedRowKeys([]);
reload();
};
// 新增
const handleCreate = () => {
openModal(true, {
isUpdate: false,
});
};
// 编辑
const handleEdit = (record?: any) => {
openModal(true, {
isUpdate: true,
record,
});
};
// 详情
const registerDetailRecord = ref<any>({});
const handleDetail = (record?: any) => {
openDrawer(true);
registerDetailRecord.value = {
...record,
ifShowClass: true,
};
};
// 状态->编辑
const handleSwitch = async (e: any, record: any) => {
switchLoading.value = true;
console.log(e, record);
await deviceProfileCategory({ ...record, status: e });
switchLoading.value = false;
createMessage.success('操作成功');
handleReload();
};
// 删除
const handleDelete = async (record?: any) => {
let ids: string[] = [];
if (record) {
ids = [record.id];
} else {
ids = getSelectRowKeys();
}
try {
setLoading(true);
await deleteDeviceClass({ ids });
createMessage.success('删除成功');
handleReload();
} catch (error) {
throw error;
} finally {
setLoading(false);
}
};
</script>
<template>
<div>
<BasicTable style="flex: auto" @register="registerTable">
<template #toolbar>
<Authority value="api:yt:product:category:post">
<Button type="primary" @click="handleCreate"> 新增品类 </Button>
</Authority>
<Authority value="api:yt:product:category:delete">
<Popconfirm
title="您确定要批量删除数据"
ok-text="确定"
cancel-text="取消"
@confirm="handleDelete()"
>
<a-button color="error" :disabled="!isExistOption"> 批量删除 </a-button>
</Popconfirm>
</Authority>
</template>
<template #status="{ record }">
<Switch
@click="(e) => handleSwitch(e, record)"
:loading="switchLoading"
v-model:checked="record.status"
checked-children="启用"
un-checked-children="禁用"
:checkedValue="1"
:unCheckedValue="0"
/>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '详情',
icon: 'ant-design:eye-outlined',
auth: 'api:yt:product:category:get',
onClick: handleDetail.bind(null, record),
},
{
label: '编辑',
auth: 'api:yt:product:category:update',
icon: 'clarity:note-edit-line',
ifShow: authBtn(role),
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
auth: 'api:yt:product:category:delete',
icon: 'ant-design:delete-outlined',
ifShow: authBtn(role) && !record.status,
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
]"
/>
</template>
</BasicTable>
<classModal @register="registerModal" @handleReload="handleReload" />
<!-- <physicalModel @register="registerDetailDrawer" :record /> -->
<BasicDrawer title="物模型" @register="registerDetailDrawer" width="60%" destroy-on-close>
<PhysicalModelManagementStep :record="registerDetailRecord" />
</BasicDrawer>
</div>
</template>