导入导出

main
wangqiujuan0808 2024-05-11 23:02:33 +08:00
parent b05fb583ed
commit e2333edf17
4 changed files with 60 additions and 27 deletions

View File

@ -85,9 +85,13 @@ const infoApi = {
return postPBRequest('/template', params, 53310, params.template_name)
},
//
importP(params,template_name) {
return postPBRequest('/template', params, 53212,template_name)
},
importP(params) {
return postPBRequest('/template', params, 53310, params.template_name)
//
exportP(params) {
return postPBRequest('/template', params, 53211, params.template_name)
},
//
getTx(params) {

View File

@ -4,7 +4,7 @@
<label class="filelabel" for="fileinput1">上传</label>
<div class="fileName">
<span>{{ fileName }}</span>
<delete style="width: 18px; height: 18px; margin-left: 8px;" @click="delFile" v-if="fileName"/>
<delete style="width: 18px; height: 18px; margin-left: 8px;" @click="delFile" v-if="fileName" />
</div>
<template #footer>
<span class="dialog-footer">
@ -25,7 +25,7 @@ export default {
const state = reactive({
fileName: '',
formData: new FormData()
importData: new FormData()
});
const visible = computed(() => {
return props.dialogVisible;
@ -39,16 +39,20 @@ export default {
};
const saveP = async () => {
const res = await infoApi.importP(state.formData);
ctx.emit("dialogSuccess");
const res = await infoApi.importP(state.importData, props.formData.name);
if (res.code == 0) {
ElMessage.success(res.message);
ctx.emit("dialogSuccess");
} else {
ElMessage.error(res.data || res.message);
}
};
const uploadFile = (e) => {
const uploadFile = (e) => {
let file = e.target.files[0];
state.fileName = file.name;
state.formData.append("file", file);
state.formData.append("folderName", file.name);
state.importData.append("file", file);
}
const delFile = () => {
@ -68,17 +72,18 @@ export default {
</script>
<style lang="scss" scoped>
.filelabel {
background: #1890ff;
border: 1px solid #1890ff;
font-weight: 500;
padding: 5px 15px 5px;
margin: 0 2px 0 6px;
border-radius: 4px;
color: #fff;
font-size: 12px;
}
.fileName {
margin: 15px 0;
font-size:16px;
}
background: #1890ff;
border: 1px solid #1890ff;
font-weight: 500;
padding: 5px 15px 5px;
margin: 0 2px 0 6px;
border-radius: 4px;
color: #fff;
font-size: 12px;
}
.fileName {
margin: 15px 0;
font-size: 16px;
}
</style>

View File

@ -59,11 +59,13 @@
<AddPoint :type="type" :formData="formData1" :pointData="pointData" :dialogVisible="dialogVisible1"
v-if="dialogVisible1" @dialogClose="dialogVisible1 = false" @dialogSuccess="dialogSuccess1">
</AddPoint>
<ExportPoint :formData="formData1" :dialogVisible="dialogVisible2" v-if="dialogVisible2" @dialogClose="dialogVisible2 = false"
@dialogSuccess="dialogSuccess2"></ExportPoint>
<ExportPoint :formData="formData1" :dialogVisible="dialogVisible2" v-if="dialogVisible2"
@dialogClose="dialogVisible2 = false" @dialogSuccess="dialogSuccess2"></ExportPoint>
</el-drawer>
</template>
<script>
import { Base64 } from 'js-base64';
import axios from "axios";
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
@ -199,8 +201,30 @@ export default {
state.dialogVisible2 = true;
}
const exportData = () => {
const exportData = async () => {
axios({
method: "post",
url: '/template',
headers: {
"action": 53211,
'template_name': Base64.encode(props.formData.name)
},
responseType: 'blob',
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', props.formData.name +'_points.csv');
document.body.appendChild(link);
link.click();
// const link = document.createElement('a');
// link.href = url;
// link.setAttribute('download', '_points.csv');
// link.click();
// document.body.removechild(link);
// window.URL.revokeobjectURL(url);
}).catch(error => console.log(error));
}
return {

View File

@ -11,10 +11,10 @@
<el-button type="primary" @click="manageData">
新增设备
</el-button>
<div>
<!-- <div>
<el-button type="primary" @click="importData"> </el-button>
<el-button type="primary" @click="exportData"> </el-button>
</div>
</div> -->
</div>
<el-table :data="propertiesData" height="640" style="width: 100%" border stripe
:header-cell-style="{ background: '#F6F7FC' }">