|
@@ -62,7 +62,7 @@
|
|
import { ref, onMounted } from 'vue';
|
|
import { ref, onMounted } from 'vue';
|
|
import { ElTable, ElButton, ElCol, ElRow, ElTableColumn } from 'element-plus';
|
|
import { ElTable, ElButton, ElCol, ElRow, ElTableColumn } from 'element-plus';
|
|
import * as XLSX from 'xlsx';
|
|
import * as XLSX from 'xlsx';
|
|
-
|
|
|
|
|
|
+const emits = defineEmits(['close']);
|
|
const detailData = ref({
|
|
const detailData = ref({
|
|
title: '测试表单',
|
|
title: '测试表单',
|
|
start: '2024-10-15 17:02:22',
|
|
start: '2024-10-15 17:02:22',
|
|
@@ -70,22 +70,38 @@ const detailData = ref({
|
|
});
|
|
});
|
|
|
|
|
|
const editableHeaders = ref(['时间', '地点', '损坏程度', '救援人员', '物资']);
|
|
const editableHeaders = ref(['时间', '地点', '损坏程度', '救援人员', '物资']);
|
|
-const tableData = ref([
|
|
|
|
- {
|
|
|
|
- 时间: '2024-01-01',
|
|
|
|
- 地点: '某地',
|
|
|
|
- 损坏程度: '轻度',
|
|
|
|
- 救援人员: '张三, 李四',
|
|
|
|
- 物资: '食品, 水'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- 时间: '2024-01-02',
|
|
|
|
- 地点: '某地',
|
|
|
|
- 损坏程度: '中度',
|
|
|
|
- 救援人员: '王五, 赵六',
|
|
|
|
- 物资: '帐篷, 医疗用品'
|
|
|
|
|
|
+const tableData = ref([]);
|
|
|
|
+
|
|
|
|
+// 初始化表格数据
|
|
|
|
+onMounted(() => {
|
|
|
|
+ loadFromLocalStorage();
|
|
|
|
+ addDefaultRow();
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 加载数据
|
|
|
|
+function loadFromLocalStorage() {
|
|
|
|
+ const storedData = localStorage.getItem('tableData');
|
|
|
|
+ if (storedData) {
|
|
|
|
+ tableData.value = JSON.parse(storedData);
|
|
|
|
+ } else {
|
|
|
|
+ tableData.value = [
|
|
|
|
+ {
|
|
|
|
+ 时间: '2024-01-01',
|
|
|
|
+ 地点: '某地',
|
|
|
|
+ 损坏程度: '轻度',
|
|
|
|
+ 救援人员: '张三, 李四',
|
|
|
|
+ 物资: '食品, 水'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 时间: '2024-01-02',
|
|
|
|
+ 地点: '某地',
|
|
|
|
+ 损坏程度: '中度',
|
|
|
|
+ 救援人员: '王五, 赵六',
|
|
|
|
+ 物资: '帐篷, 医疗用品'
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
}
|
|
}
|
|
-]);
|
|
|
|
|
|
+}
|
|
|
|
|
|
function saveEdit(rowIndex, header, value) {
|
|
function saveEdit(rowIndex, header, value) {
|
|
tableData.value[rowIndex][header] = value;
|
|
tableData.value[rowIndex][header] = value;
|
|
@@ -108,10 +124,6 @@ function addDefaultRow() {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-onMounted(() => {
|
|
|
|
- addDefaultRow();
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
const exportToExcel = () => {
|
|
const exportToExcel = () => {
|
|
const worksheet = XLSX.utils.json_to_sheet(tableData.value);
|
|
const worksheet = XLSX.utils.json_to_sheet(tableData.value);
|
|
const workbook = { Sheets: { data: worksheet }, SheetNames: ['data'] };
|
|
const workbook = { Sheets: { data: worksheet }, SheetNames: ['data'] };
|
|
@@ -130,8 +142,15 @@ const handleAdd = () => console.log('批量导入');
|
|
const handleDownloadEmptyTable = () => console.log('下载空表格');
|
|
const handleDownloadEmptyTable = () => console.log('下载空表格');
|
|
const handleAddRow = () => addDefaultRow();
|
|
const handleAddRow = () => addDefaultRow();
|
|
const handleReport = () => console.log('上报');
|
|
const handleReport = () => console.log('上报');
|
|
-const handleSave = () => console.log('保存');
|
|
|
|
-const handleReturn = () => console.log('返回');
|
|
|
|
|
|
+
|
|
|
|
+const handleSave = () => {
|
|
|
|
+ // 保存本地状态
|
|
|
|
+ localStorage.setItem('tableData', JSON.stringify(tableData.value));
|
|
|
|
+ alert('数据已保存');
|
|
|
|
+};
|
|
|
|
+const handleReturn = () => {
|
|
|
|
+ emits('close');
|
|
|
|
+};
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|