This commit is contained in:
2024-01-31 14:56:48 +08:00
parent 14cbb87311
commit 494e3ee248
97 changed files with 11579 additions and 3858 deletions
+74 -71
View File
@@ -25,87 +25,90 @@
</a-upload-dragger>
<div style="margin: 20px auto; display: flex; justify-content: center">
<a
href="https://file.wsdns.cn/download/20230523/2f5ffa06b0684e138184c6786f6fbb68.xlsx"
href="http://1.14.159.185:10042/template/2f5ffa06b0684e138184c6786f6fbb68.xlsx"
target="_blank"
>下载设备导入模板</a
>下载设备导入模板</a
>
</div>
</ele-modal>
</template>
<script lang="ts" setup>
import { InboxOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import { addBatchTowerEquipment } from '@/api/tower/equipment';
import { TowerEquipment } from '@/api/tower/equipment/model';
import { read, utils } from 'xlsx';
import { ref } from 'vue';
import { InboxOutlined } from "@ant-design/icons-vue";
import { message } from "ant-design-vue";
import { addBatchTowerEquipment } from "@/api/tower/equipment";
import { TowerEquipment } from "@/api/tower/equipment/model";
import { read, utils } from "xlsx";
import { ref } from "vue";
import dayjs from "dayjs";
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
const emit = defineEmits<{
(e: "done"): void;
(e: "update:visible", visible: boolean): void;
}>();
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
/* 更新visible */
const updateVisible = (value: boolean) => {
emit("update:visible", value);
};
// 导入的数据
const importData = ref<TowerEquipment[]>([]);
const handleImport = (file: File) => {
if (
![
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
].includes(file.type)
) {
message.error('只能选择 excel 文件');
return false;
}
if (file.size / 1024 / 1024 > 20) {
message.error('大小不能超过 20MB');
return false;
}
const reader = new FileReader();
reader.onload = (e) => {
const data = new Uint8Array(e.target?.result as any);
const workbook = read(data, { type: 'array' });
const sheetNames = workbook.SheetNames;
const worksheet = workbook.Sheets[sheetNames[0]];
// 解析成二维数组
const aoa = utils.sheet_to_json<string[]>(worksheet, { header: 1 });
console.log(aoa);
aoa.slice(1).map((d) => {
const array = ['闲置', '报废', '注销', '转卖'];
importData.value.push({
status: array.indexOf(d[0]),
name: d[1],
factoryNo: d[2],
model: d[3],
manufactor: d[4],
buyDate: d[5],
filingNo: d[6],
factoryDate: d[7],
company: d[8],
source: d[9],
warehouse: d[10],
users: d[11],
equipmentNo: d[12],
ratedLoad: d[13],
maxLiftingHeight: d[14],
armLength: d[15],
currentLocation: d[16],
machineNo: d[17]
});
});
addBatchTowerEquipment(importData.value).then(() => {
message.success('导入成功');
updateVisible(false);
emit('done');
});
};
reader.readAsArrayBuffer(file);
// 导入的数据
const importData = ref<TowerEquipment[]>([]);
const handleImport = (file: File) => {
if (
![
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
].includes(file.type)
) {
message.error("只能选择 excel 文件");
return false;
}
if (file.size / 1024 / 1024 > 20) {
message.error("大小不能超过 20MB");
return false;
}
const reader = new FileReader();
importData.value = []
reader.onload = (e) => {
const data = new Uint8Array(e.target?.result as any);
const workbook = read(data, { type: "array" });
const sheetNames = workbook.SheetNames;
const worksheet = workbook.Sheets[sheetNames[0]];
// 解析成二维数组
const aoa = utils.sheet_to_json<string[]>(worksheet, { header: 1 });
aoa.slice(1).map((d) => {
const array = ["闲置", "报废", "注销", "转卖", "在用", "停工"];
if (d[1]) {
importData.value.push({
name: d[1],
filingNo: d[2],
factoryNo: d[3],
model: d[4],
manufactor: d[5],
company: d[6],
factoryDate: d[7],
status: array.indexOf(d[8]),
lifeYear: d[9],
buyDate: d[10],
source: d[11],
warehouse: d[12],
users: d[13],
equipmentNo: d[14],
ratedLoad: d[15],
maxLiftingHeight: d[16],
armLength: d[17],
scrapDate: (d[7] && d[9]) ? (dayjs(d[7] ).add(parseInt(d[9]) , 'year').format('YYYY-MM-DD')) : ''
});
}
});
addBatchTowerEquipment(importData.value).then(() => {
message.success("导入成功");
updateVisible(false);
emit("done");
});
};
reader.readAsArrayBuffer(file);
return false;
};
</script>