feat: 产品管理添加导入导出功能

This commit is contained in:
xiongqian 2023-02-08 17:00:43 +08:00
parent 3b799e53d7
commit 839d14937d
3 changed files with 142 additions and 11 deletions

View File

@ -0,0 +1,59 @@
.config .title {
width: 100%;
margin-bottom: 10px;
color: rgba(0, 0, 0, 0.8);
font-weight: 600;
}
.config .title::before {
margin-right: 10px;
background-color: #2810ff;
content: '|';
}
.config .item {
margin-bottom: 10px;
}
.config .item .context {
margin: 5px 0;
color: rgba(0, 0, 0, 0.8);
}
.info {
display: flex;
align-items: center;
justify-content: center;
height: 630px;
padding: 20px;
background-color: #e6e6e6;
}
.driver .driver-next-btn {
color: #fff !important;
font-size: 14px !important;
line-height: 22px !important;
text-shadow: 0 0 black !important;
background-color: #2f54eb !important;
}
.driver .driver-prev-btn {
font-size: 14px !important;
line-height: 22px !important;
background-color: #fff !important;
}
.driver .driver-prev-btn.driver-disabled {
display: none !important;
}
.driver .driver-close-btn {
padding: 5px 0 0 0 !important;
color: #828282 !important;
font-size: 14px !important;
background-color: #fff !important;
border: none !important;
}
.driver .driver-popover-description {
margin-bottom: 10px !important;
}
.driver .driver-popover-title {
display: flex !important;
justify-content: space-between !important;
}
.driver .driver-popover-title #guide {
margin-top: 3px;
font-size: 14px;
}

View File

@ -487,6 +487,7 @@ defineExpose({
.button-style {
background-color: #fff;
height: 66px;
overflow: hidden;
.card-content {
width: 100%;
.img-style {
@ -498,23 +499,35 @@ defineExpose({
right: -22px;
bottom: -22px;
z-index: 2;
width: 44px;
height: 44px;
color: #2f54eb;
// background-color: #2f54eb;
color: #fff;
background-color: @primary-color-active;
transform: rotate(-45deg);
> div {
position: relative;
height: 100%;
transform: rotate(45deg);
background-color: transparent;
> span {
position: absolute;
top: 6px;
left: 6px;
font-size: 12px;
}
}
}
&.checked {
position: relative;
color: @primary-color-active;
border-color: @primary-color-active;
> .checked-icon {
display: block;
}
}
}
// &:hover {
// color: #2f54eb;
// border: 1px solid #2f54eb;
// }
}
</style>

View File

@ -15,9 +15,19 @@
:params="params"
>
<template #headerTitle>
<a-button type="primary" @click="add"
><plus-outlined />新增</a-button
>
<a-space>
<a-button type="primary" @click="add"
><plus-outlined />新增</a-button
>
<a-upload
name="file"
accept=".json"
:showUploadList="false"
:before-upload="beforeUpload"
>
<a-button>导入</a-button>
</a-upload>
</a-space>
</template>
<template #deviceType="slotProps">
<div>{{ slotProps.deviceType.text }}</div>
@ -172,8 +182,10 @@ import {
addProduct,
editProduct,
queryProductId,
updateDevice,
} from '@/api/device/product';
import { isNoCommunity } from '@/utils/utils';
import { isNoCommunity, downloadObject } from '@/utils/utils';
import { omit } from 'lodash-es';
import { typeOptions } from '@/components/Search/util';
import Save from './Save/index.vue';
/**
@ -293,6 +305,17 @@ const getActions = (
},
icon: 'icon-xiazai',
onClick: () => {
const extra = omit(data, [
'transportProtocol',
'protocolName',
'accessId',
'accessName',
'accessProvider',
'messageProtocol',
]);
downloadObject(extra, '产品');
},
},
{
key: 'action',
@ -356,6 +379,42 @@ const add = () => {
saveRef.value.show(currentForm.value);
});
};
/**
* 导入
*/
const beforeUpload = (file: any) => {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = async (result) => {
const text = result.target?.result;
console.log('text: ', text);
if (!file.type.includes('json')) {
message.error('请上传json格式文件');
return false;
}
try {
const data = JSON.parse(text || '{}');
//
data.state = 0;
if (Array.isArray(data)) {
message.error('请上传json格式文件');
return false;
}
delete data.state;
const res = await updateDevice(data);
if (res.status === 200) {
message.success('操作成功');
tableRef.value?.reload();
}
return true;
} catch {
message.error('请上传json格式文件');
}
return true;
};
return false;
};
/**
* 查看
*/