|
@@ -1,172 +1,258 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<!-- 操作按钮区 -->
|
|
|
- <el-row :gutter="10" style="margin-bottom: 20px;">
|
|
|
+ <el-row :gutter="10" style="margin-bottom: 20px">
|
|
|
<el-col :span="4">
|
|
|
- <el-button :icon="Plus" type="primary" @click="openDialog('add')" style="background-color: #3EC01E; border-color: #67C23A; color: white;">新增记录</el-button>
|
|
|
+ <el-button
|
|
|
+ :icon="Plus"
|
|
|
+ type="primary"
|
|
|
+ @click="openDialog('add')"
|
|
|
+ style="background-color: #3ec01e; border-color: #67c23a; color: white"
|
|
|
+ >新增记录</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
<el-col :span="4">
|
|
|
- <el-button :icon="Download" type="primary" @click="downloadTemplateAction" style="background-color: #3EC01E; border-color: #67C23A; color: white;">下载模板</el-button>
|
|
|
+ <el-button
|
|
|
+ :icon="Download"
|
|
|
+ type="primary"
|
|
|
+ @click="downloadTemplateAction"
|
|
|
+ style="background-color: #3ec01e; border-color: #67c23a; color: white"
|
|
|
+ >下载模板</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
<el-col :span="4">
|
|
|
- <el-button :icon="Download" type="primary" @click="exportDataAction" style="background-color: #3EC01E; border-color: #67C23A; color: white;">导出数据</el-button>
|
|
|
+ <el-button
|
|
|
+ :icon="Download"
|
|
|
+ type="primary"
|
|
|
+ @click="exportDataAction"
|
|
|
+ style="background-color: #3ec01e; border-color: #67c23a; color: white"
|
|
|
+ >导出数据</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
<el-col :span="4">
|
|
|
<el-upload :before-upload="importDataAction" accept=".xlsx, .csv">
|
|
|
- <el-button :icon="Upload" type="primary" style="background-color: #3EC01E; border-color: #67C23A; color: white;">导入数据</el-button>
|
|
|
+ <el-button
|
|
|
+ :icon="Upload"
|
|
|
+ type="primary"
|
|
|
+ style="
|
|
|
+ background-color: #3ec01e;
|
|
|
+ border-color: #67c23a;
|
|
|
+ color: white;
|
|
|
+ "
|
|
|
+ >导入数据</el-button
|
|
|
+ >
|
|
|
</el-upload>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
<!-- 数据表格 -->
|
|
|
- <el-table :data="pagedTableDataWithIndex" style="width: 100%" @row-click="handleRowClick" highlight-current-row class="custom-table"
|
|
|
- v-loading="loading">
|
|
|
- <el-table-column key="displayIndex" prop="displayIndex" label="序号" width="80"></el-table-column>
|
|
|
- <el-table-column v-for="col in columns.filter(col => col.key !== 'id')" :key="col.key" :prop="col.dataKey" :label="col.title" :width="col.width"
|
|
|
- :formatter="formatNumber">
|
|
|
+ <el-table
|
|
|
+ :data="pagedTableDataWithIndex"
|
|
|
+ style="width: 100%"
|
|
|
+ @row-click="handleRowClick"
|
|
|
+ highlight-current-row
|
|
|
+ class="custom-table"
|
|
|
+ v-loading="loading"
|
|
|
+ >
|
|
|
+ <el-table-column
|
|
|
+ key="displayIndex"
|
|
|
+ prop="displayIndex"
|
|
|
+ label="序号"
|
|
|
+ width="80"
|
|
|
+ ></el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ v-for="col in columns.filter((col) => col.key !== 'id')"
|
|
|
+ :key="col.key"
|
|
|
+ :prop="col.dataKey"
|
|
|
+ :label="col.title"
|
|
|
+ :width="col.width"
|
|
|
+ :formatter="formatNumber"
|
|
|
+ >
|
|
|
</el-table-column>
|
|
|
<el-table-column label="操作" width="120">
|
|
|
<template #default="scope">
|
|
|
<el-tooltip class="item" effect="dark" content="编辑" placement="top">
|
|
|
- <el-button circle :icon="EditPen" @click.stop="openDialog('edit', scope.row)" style="font-size: 16px; color: #409EFF;"></el-button>
|
|
|
+ <el-button
|
|
|
+ circle
|
|
|
+ :icon="EditPen"
|
|
|
+ @click.stop="openDialog('edit', scope.row)"
|
|
|
+ style="font-size: 16px; color: #409eff"
|
|
|
+ ></el-button>
|
|
|
</el-tooltip>
|
|
|
<el-tooltip class="item" effect="dark" content="删除" placement="top">
|
|
|
- <el-button circle :icon="DeleteFilled" @click.stop="deleteItem(scope.row)" style="font-size: 16px; color: red;"></el-button>
|
|
|
+ <el-button
|
|
|
+ circle
|
|
|
+ :icon="DeleteFilled"
|
|
|
+ @click.stop="deleteItem(scope.row)"
|
|
|
+ style="font-size: 16px; color: red"
|
|
|
+ ></el-button>
|
|
|
</el-tooltip>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
|
|
|
<!-- 分页控制 -->
|
|
|
- <PaginationComponent
|
|
|
- :total="tableData.length"
|
|
|
- :currentPage="currentPage4"
|
|
|
- :pageSize="pageSize4"
|
|
|
- @update:currentPage="currentPage4 = $event"
|
|
|
- @update:pageSize="pageSize4 = $event"
|
|
|
- @size-change="handleSizeChange"
|
|
|
+ <PaginationComponent
|
|
|
+ :total="tableData.length"
|
|
|
+ :currentPage="currentPage4"
|
|
|
+ :pageSize="pageSize4"
|
|
|
+ @update:currentPage="currentPage4 = $event"
|
|
|
+ @update:pageSize="pageSize4 = $event"
|
|
|
+ @size-change="handleSizeChange"
|
|
|
@current-change="handleCurrentChange"
|
|
|
/>
|
|
|
|
|
|
<!-- 新增/编辑对话框 -->
|
|
|
<el-dialog :title="dialogTitle" v-model="dialogVisible">
|
|
|
<el-form :model="formData">
|
|
|
- <el-form-item v-for="col in editableColumns" :key="col.key" :label="col.title">
|
|
|
- <el-input v-model="formData[col.dataKey]" :type="col.inputType || 'text'"></el-input>
|
|
|
+ <el-form-item
|
|
|
+ v-for="col in editableColumns"
|
|
|
+ :key="col.key"
|
|
|
+ :label="col.title"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ v-model="formData[col.dataKey]"
|
|
|
+ :type="col.inputType || 'text'"
|
|
|
+ ></el-input>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<el-button @click="dialogVisible = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="submitForm">{{ dialogSubmitButtonText }}</el-button>
|
|
|
+ <el-button type="primary" @click="submitForm">{{
|
|
|
+ dialogSubmitButtonText
|
|
|
+ }}</el-button>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { ref, reactive, computed, onMounted } from 'vue'
|
|
|
-import { DeleteFilled, Download, Upload, Plus, EditPen } from '@element-plus/icons-vue';
|
|
|
-import { ElMessage } from 'element-plus'
|
|
|
-import { table, updateItem, addItem, deleteItemApi, downloadTemplate, exportData, importData } from '@/API/menus'
|
|
|
-import PaginationComponent from './packaged/PaginationComponent.vue'
|
|
|
+import { ref, reactive, computed, onMounted } from "vue";
|
|
|
+import {
|
|
|
+ DeleteFilled,
|
|
|
+ Download,
|
|
|
+ Upload,
|
|
|
+ Plus,
|
|
|
+ EditPen,
|
|
|
+} from "@element-plus/icons-vue";
|
|
|
+import { ElMessage } from "element-plus";
|
|
|
+import {
|
|
|
+ table,
|
|
|
+ updateItem,
|
|
|
+ addItem,
|
|
|
+ deleteItemApi,
|
|
|
+ downloadTemplate,
|
|
|
+ exportData,
|
|
|
+ importData,
|
|
|
+} from "@/API/menus";
|
|
|
+import PaginationComponent from "./packaged/PaginationComponent.vue";
|
|
|
|
|
|
interface Column {
|
|
|
- key: string;
|
|
|
- dataKey: string;
|
|
|
- title: string;
|
|
|
- width: number;
|
|
|
- inputType?: string;
|
|
|
+ key: string;
|
|
|
+ dataKey: string;
|
|
|
+ title: string;
|
|
|
+ width: number;
|
|
|
+ inputType?: string;
|
|
|
}
|
|
|
|
|
|
const columns: Column[] = [
|
|
|
- { key: 'id', dataKey: 'id', title: 'ID', width: 80 },
|
|
|
- { key: 'OM', dataKey: 'OM', title: '有机质含量', width: 150 },
|
|
|
- { key: 'CL', dataKey: 'CL', title: '土壤粘粒', width: 150 },
|
|
|
- { key: 'CEC', dataKey: 'CEC', title: '阳离子交换量', width: 150 },
|
|
|
- { key: 'H_plus', dataKey: 'H_plus', title: '交换性氢', width: 150, inputType: 'number' },
|
|
|
- { key: 'N', dataKey: 'N', title: '水解氮', width: 150 },
|
|
|
- { key: 'Al3_plus', dataKey: 'Al3_plus', title: '交换性铝', width: 150 },
|
|
|
- { key: 'Delta_pH', dataKey: 'Delta_pH', title: 'ΔpH', width: 150 },
|
|
|
-]
|
|
|
-
|
|
|
-const editableColumns = columns.filter(col => col.key !== 'id')
|
|
|
-
|
|
|
-const tableData = ref<any[]>([])
|
|
|
-const selectedRow = ref<any | null>(null)
|
|
|
-const dialogVisible = ref(false)
|
|
|
-const formData = reactive<any>({})
|
|
|
-const dialogMode = ref<'add' | 'edit'>('add') // 新增还是编辑模式
|
|
|
-
|
|
|
-const currentPage4 = ref(1)
|
|
|
-const pageSize4 = ref(10)
|
|
|
+ { key: "id", dataKey: "id", title: "ID", width: 80 },
|
|
|
+ { key: "OM", dataKey: "OM", title: "有机质含量", width: 150 },
|
|
|
+ { key: "CL", dataKey: "CL", title: "土壤粘粒", width: 150 },
|
|
|
+ { key: "CEC", dataKey: "CEC", title: "阳离子交换量", width: 150 },
|
|
|
+ {
|
|
|
+ key: "H_plus",
|
|
|
+ dataKey: "H_plus",
|
|
|
+ title: "交换性氢",
|
|
|
+ width: 150,
|
|
|
+ inputType: "number",
|
|
|
+ },
|
|
|
+ { key: "N", dataKey: "N", title: "水解氮", width: 150 },
|
|
|
+ { key: "Al3_plus", dataKey: "Al3_plus", title: "交换性铝", width: 150 },
|
|
|
+ { key: "Delta_pH", dataKey: "Delta_pH", title: "ΔpH", width: 150 },
|
|
|
+];
|
|
|
+
|
|
|
+const editableColumns = columns.filter((col) => col.key !== "id");
|
|
|
+
|
|
|
+const tableData = ref<any[]>([]);
|
|
|
+const selectedRow = ref<any | null>(null);
|
|
|
+const dialogVisible = ref(false);
|
|
|
+const formData = reactive<any>({});
|
|
|
+const dialogMode = ref<"add" | "edit">("add"); // 新增还是编辑模式
|
|
|
+
|
|
|
+const currentPage4 = ref(1);
|
|
|
+const pageSize4 = ref(10);
|
|
|
|
|
|
const pagedTableDataWithIndex = computed(() => {
|
|
|
- return pagedTableData.value.map((item, index) => ({
|
|
|
- ...item,
|
|
|
- displayIndex: (currentPage4.value - 1) * pageSize4.value + index + 1
|
|
|
- }));
|
|
|
-})
|
|
|
+ return pagedTableData.value.map((item, index) => ({
|
|
|
+ ...item,
|
|
|
+ displayIndex: (currentPage4.value - 1) * pageSize4.value + index + 1,
|
|
|
+ }));
|
|
|
+});
|
|
|
|
|
|
const pagedTableData = computed(() => {
|
|
|
- const start = (currentPage4.value - 1) * pageSize4.value
|
|
|
- const end = start + pageSize4.value
|
|
|
- return tableData.value.slice(start, end)
|
|
|
-})
|
|
|
+ const start = (currentPage4.value - 1) * pageSize4.value;
|
|
|
+ const end = start + pageSize4.value;
|
|
|
+ return tableData.value.slice(start, end);
|
|
|
+});
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
const currentTableName = "current_reflux";
|
|
|
|
|
|
const fetchTable = async () => {
|
|
|
- console.log('正在获取表格数据...');
|
|
|
+ console.log("正在获取表格数据...");
|
|
|
try {
|
|
|
loading.value = true;
|
|
|
const response = await table({ table: currentTableName });
|
|
|
console.log("获取到的数据:", response);
|
|
|
tableData.value = response.data.rows;
|
|
|
} catch (error) {
|
|
|
- console.error('获取数据时出错:', error);
|
|
|
- ElMessage.error('获取数据失败,请检查网络连接或服务器状态');
|
|
|
+ console.error("获取数据时出错:", error);
|
|
|
+ ElMessage.error("获取数据失败,请检查网络连接或服务器状态");
|
|
|
} finally {
|
|
|
loading.value = false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
- fetchTable()
|
|
|
-})
|
|
|
+ fetchTable();
|
|
|
+});
|
|
|
|
|
|
const handleRowClick = (row: any) => {
|
|
|
- selectedRow.value = row
|
|
|
- Object.assign(formData, row)
|
|
|
-}
|
|
|
+ selectedRow.value = row;
|
|
|
+ Object.assign(formData, row);
|
|
|
+};
|
|
|
|
|
|
-const openDialog = (mode: 'add' | 'edit', row?: any) => {
|
|
|
- console.log(`${mode === 'add' ? '打开新增记录' : '打开编辑记录'}对话框`);
|
|
|
- if (mode === 'add') {
|
|
|
- selectedRow.value = null;
|
|
|
- editableColumns.forEach(col => {
|
|
|
- formData[col.dataKey] = '';
|
|
|
- });
|
|
|
- } else if (row) {
|
|
|
- console.log('编辑记录:', row);
|
|
|
- selectedRow.value = row;
|
|
|
- Object.assign(formData, row);
|
|
|
- }
|
|
|
- dialogMode.value = mode;
|
|
|
- dialogVisible.value = true;
|
|
|
-}
|
|
|
+const openDialog = (mode: "add" | "edit", row?: any) => {
|
|
|
+ console.log(`${mode === "add" ? "打开新增记录" : "打开编辑记录"}对话框`);
|
|
|
+ if (mode === "add") {
|
|
|
+ selectedRow.value = null;
|
|
|
+ editableColumns.forEach((col) => {
|
|
|
+ formData[col.dataKey] = "";
|
|
|
+ });
|
|
|
+ } else if (row) {
|
|
|
+ console.log("编辑记录:", row);
|
|
|
+ selectedRow.value = row;
|
|
|
+ Object.assign(formData, row);
|
|
|
+ }
|
|
|
+ dialogMode.value = mode;
|
|
|
+ dialogVisible.value = true;
|
|
|
+};
|
|
|
|
|
|
-function prepareFormData(formData: { [x: string]: any; }, excludeKeys = ['displayIndex']): { [x: string]: any; } {
|
|
|
- const result: { [x: string]: any; } = {};
|
|
|
+function prepareFormData(
|
|
|
+ formData: { [x: string]: any },
|
|
|
+ excludeKeys = ["displayIndex"]
|
|
|
+): { [x: string]: any } {
|
|
|
+ const result: { [x: string]: any } = {};
|
|
|
|
|
|
for (const key in formData) {
|
|
|
if (!excludeKeys.includes(key)) {
|
|
|
let value = formData[key];
|
|
|
-
|
|
|
+
|
|
|
// 如果是 'displayIndex-' 格式的键,则提取原始 id
|
|
|
- if (typeof value === 'string' && value.startsWith('displayIndex-')) {
|
|
|
- value = value.replace('displayIndex-', '');
|
|
|
+ if (typeof value === "string" && value.startsWith("displayIndex-")) {
|
|
|
+ value = value.replace("displayIndex-", "");
|
|
|
}
|
|
|
|
|
|
result[key] = value;
|
|
@@ -177,58 +263,76 @@ function prepareFormData(formData: { [x: string]: any; }, excludeKeys = ['displa
|
|
|
}
|
|
|
|
|
|
const submitForm = async () => {
|
|
|
- console.log('开始提交表单...');
|
|
|
+ console.log("开始提交表单...");
|
|
|
try {
|
|
|
- console.log('验证表单数据...');
|
|
|
+ console.log("验证表单数据...");
|
|
|
const isValid = validateFormData(formData);
|
|
|
if (!isValid) {
|
|
|
- console.error('表单验证失败,请检查输入的数据');
|
|
|
- alert('请检查输入的数据');
|
|
|
+ console.error("表单验证失败,请检查输入的数据");
|
|
|
+ alert("请检查输入的数据");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 准备要提交的数据
|
|
|
- console.log('准备提交的数据:', formData);
|
|
|
+ console.log("准备提交的数据:", formData);
|
|
|
const dataToSubmit = prepareFormData(formData);
|
|
|
|
|
|
- console.log('已准备的数据:', dataToSubmit);
|
|
|
+ console.log("已准备的数据:", dataToSubmit);
|
|
|
|
|
|
// 检查是否存在 id 字段
|
|
|
- if (!dataToSubmit.id && dialogMode.value !== 'add') {
|
|
|
- console.error('无法找到记录ID,请联系管理员');
|
|
|
- alert('无法找到记录ID,请联系管理员');
|
|
|
+ if (!dataToSubmit.id && dialogMode.value !== "add") {
|
|
|
+ console.error("无法找到记录ID,请联系管理员");
|
|
|
+ alert("无法找到记录ID,请联系管理员");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let response;
|
|
|
- if (dialogMode.value === 'add') {
|
|
|
- console.log('正在添加新记录...');
|
|
|
+ if (dialogMode.value === "add") {
|
|
|
+ console.log("正在添加新记录...");
|
|
|
response = await addItem({ table: currentTableName, item: dataToSubmit });
|
|
|
} else {
|
|
|
- console.log('正在更新现有记录...');
|
|
|
- response = await updateItem({ table: currentTableName, item: dataToSubmit });
|
|
|
+ console.log("正在更新现有记录...");
|
|
|
+ response = await updateItem({
|
|
|
+ table: currentTableName,
|
|
|
+ item: dataToSubmit,
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- console.log(dialogMode.value === 'add' ? '添加响应:' : '更新响应:', response);
|
|
|
+ console.log(
|
|
|
+ dialogMode.value === "add" ? "添加响应:" : "更新响应:",
|
|
|
+ response
|
|
|
+ );
|
|
|
|
|
|
dialogVisible.value = false;
|
|
|
fetchTable();
|
|
|
- alert(dialogMode.value === 'add' ? '添加成功' : '修改成功');
|
|
|
+ alert(dialogMode.value === "add" ? "添加成功" : "修改成功");
|
|
|
} catch (error) {
|
|
|
- console.error('提交表单时发生错误:', error);
|
|
|
- let errorMessage = '未知错误';
|
|
|
- if (error.response && error.response.data && error.response.data.message) {
|
|
|
- errorMessage = error.response.data.message;
|
|
|
+ console.error("提交表单时发生错误:", error);
|
|
|
+
|
|
|
+ let errorMessage = "未知错误";
|
|
|
+
|
|
|
+ // 类型检查:确认 error 是否具有 response 属性,并且该属性是否包含 data 和 message 属性
|
|
|
+ if (error && typeof error === "object" && "response" in error) {
|
|
|
+ const response = (error as { response?: { data?: { message?: string } } })
|
|
|
+ .response;
|
|
|
+ if (
|
|
|
+ response &&
|
|
|
+ response.data &&
|
|
|
+ typeof response.data.message === "string"
|
|
|
+ ) {
|
|
|
+ errorMessage = response.data.message;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
console.error(`提交失败原因: ${errorMessage}`);
|
|
|
alert(`提交失败: ${errorMessage}`);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 示例 validateFormData 函数,需根据实际需求调整
|
|
|
-function validateFormData(data) {
|
|
|
+function validateFormData(data: { [x: string]: undefined }) {
|
|
|
for (let key in data) {
|
|
|
- if (data[key] === '' || data[key] === undefined) {
|
|
|
+ if (data[key] === "" || data[key] === undefined) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -236,90 +340,102 @@ function validateFormData(data) {
|
|
|
}
|
|
|
|
|
|
const deleteItem = async (row: any) => {
|
|
|
- console.log('准备删除记录:', row);
|
|
|
- if (!row) {
|
|
|
- ElMessage.warning('请先选择一行记录')
|
|
|
- return
|
|
|
- }
|
|
|
- try {
|
|
|
- const condition = { id: row.id };
|
|
|
- console.log('删除记录条件:', condition);
|
|
|
- await deleteItemApi({ table: 'current_reflux', condition });
|
|
|
- const index = tableData.value.findIndex(item => item.id === row.id);
|
|
|
- if (index > -1) {
|
|
|
- tableData.value.splice(index, 1);
|
|
|
- }
|
|
|
- fetchTable()
|
|
|
- console.log('记录删除成功');
|
|
|
- } catch (error) {
|
|
|
- console.error('删除记录时发生错误:', error);
|
|
|
- }
|
|
|
-}
|
|
|
+ console.log("准备删除记录:", row);
|
|
|
+ if (!row) {
|
|
|
+ ElMessage.warning("请先选择一行记录");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const condition = { id: row.id };
|
|
|
+ console.log("删除记录条件:", condition);
|
|
|
+ await deleteItemApi({ table: "current_reflux", condition });
|
|
|
+ const index = tableData.value.findIndex((item) => item.id === row.id);
|
|
|
+ if (index > -1) {
|
|
|
+ tableData.value.splice(index, 1);
|
|
|
+ }
|
|
|
+ fetchTable();
|
|
|
+ console.log("记录删除成功");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("删除记录时发生错误:", error);
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
const downloadTemplateAction = async () => {
|
|
|
- try {
|
|
|
- console.log('正在下载模板...');
|
|
|
- await downloadTemplate('current_reflux');
|
|
|
- } catch (error) {
|
|
|
- console.error('下载模板时发生错误:', error);
|
|
|
- }
|
|
|
-}
|
|
|
+ try {
|
|
|
+ console.log("正在下载模板...");
|
|
|
+ await downloadTemplate("current_reflux");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("下载模板时发生错误:", error);
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
const exportDataAction = async () => {
|
|
|
- try {
|
|
|
- console.log('正在导出数据...');
|
|
|
- await exportData('current_reflux');
|
|
|
- } catch (error) {
|
|
|
- console.error('导出数据时发生错误:', error);
|
|
|
- }
|
|
|
-}
|
|
|
+ try {
|
|
|
+ console.log("正在导出数据...");
|
|
|
+ await exportData("current_reflux");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("导出数据时发生错误:", error);
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
const importDataAction = async (file: File) => {
|
|
|
- try {
|
|
|
- console.log('正在导入数据...');
|
|
|
- const response = await importData('current_reflux', file);
|
|
|
- if(response && response.data){
|
|
|
- const { total_data, new_data, duplicate_data, message } = response.data;
|
|
|
- ElMessage({
|
|
|
- message: `导入结果: ${message} 新增总数:${total_data}, 成功新增:${new_data}, 数据重复:${duplicate_data}`,
|
|
|
- type: 'success',
|
|
|
- });
|
|
|
- fetchTable(); // 刷新表格数据
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('数据导入时发生错误:', error);
|
|
|
- let errorMessage = '数据导入失败';
|
|
|
- if (error.response && error.response.data && error.response.data.message) {
|
|
|
- errorMessage += `: ${error.response.data.message}`;
|
|
|
- }
|
|
|
- ElMessage.error(errorMessage);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ console.log("正在导入数据...");
|
|
|
+ const response = await importData("current_reflux", file);
|
|
|
+ if (response && response.data) {
|
|
|
+ const { total_data, new_data, duplicate_data, message } = response.data;
|
|
|
+ ElMessage({
|
|
|
+ message: `导入结果: ${message} 新增总数:${total_data}, 成功新增:${new_data}, 数据重复:${duplicate_data}`,
|
|
|
+ type: "success",
|
|
|
+ });
|
|
|
+ fetchTable(); // 刷新表格数据
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("数据导入时发生错误:", error);
|
|
|
+
|
|
|
+ let errorMessage = "数据导入失败";
|
|
|
+
|
|
|
+ // 类型检查:确认 error 是否具有 response 属性,并且该属性是否包含 data 和 message 属性
|
|
|
+ if (error && typeof error === "object" && "response" in error) {
|
|
|
+ const response = (error as { response?: { data?: { message?: string } } })
|
|
|
+ .response;
|
|
|
+ if (
|
|
|
+ response &&
|
|
|
+ response.data &&
|
|
|
+ typeof response.data.message === "string"
|
|
|
+ ) {
|
|
|
+ errorMessage += `: ${response.data.message}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ElMessage.error(errorMessage);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const handleFileChange = (event: Event) => {
|
|
|
- const target = event.target as HTMLInputElement;
|
|
|
- if (target.files && target.files.length > 0) {
|
|
|
- importDataAction(target.files[0]);
|
|
|
- }
|
|
|
+ const target = event.target as HTMLInputElement;
|
|
|
+ if (target.files && target.files.length > 0) {
|
|
|
+ importDataAction(target.files[0]);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-const handleSizeChange = (val: number) => {}
|
|
|
+const handleSizeChange = (val: number) => {};
|
|
|
|
|
|
-const handleCurrentChange = (val: number) => {}
|
|
|
+const handleCurrentChange = (val: number) => {};
|
|
|
|
|
|
const formatNumber = (row: any, column: any, cellValue: any) => {
|
|
|
- if (typeof cellValue === 'number') {
|
|
|
- return cellValue.toFixed(3)
|
|
|
- }
|
|
|
- return cellValue
|
|
|
-}
|
|
|
+ if (typeof cellValue === "number") {
|
|
|
+ return cellValue.toFixed(3);
|
|
|
+ }
|
|
|
+ return cellValue;
|
|
|
+};
|
|
|
|
|
|
const dialogTitle = computed(() => {
|
|
|
- return dialogMode.value === 'add' ? '新增记录' : '编辑记录';
|
|
|
+ return dialogMode.value === "add" ? "新增记录" : "编辑记录";
|
|
|
});
|
|
|
|
|
|
const dialogSubmitButtonText = computed(() => {
|
|
|
- return dialogMode.value === 'add' ? '添加' : '保存';
|
|
|
+ return dialogMode.value === "add" ? "添加" : "保存";
|
|
|
});
|
|
|
</script>
|
|
|
|
|
@@ -346,22 +462,23 @@ const dialogSubmitButtonText = computed(() => {
|
|
|
|
|
|
/* 设置表头背景色 */
|
|
|
::v-deep .el-table th {
|
|
|
- background-color: #61E054 !important; /* 保持原有颜色 */
|
|
|
+ background-color: #61e054 !important; /* 保持原有颜色 */
|
|
|
color: #030803; /* 保持原有颜色 */
|
|
|
}
|
|
|
|
|
|
/* 设置奇数行背景色 */
|
|
|
::v-deep .el-table__row:nth-child(odd) {
|
|
|
- background-color: #E4FBE5 !important; /* 保持原有颜色 */
|
|
|
+ background-color: #e4fbe5 !important; /* 保持原有颜色 */
|
|
|
}
|
|
|
|
|
|
/* 设置偶数行背景色 */
|
|
|
::v-deep .el-table__row:nth-child(even) {
|
|
|
- background-color: #FFFFFF !important; /* 新增:设置偶数行为白色 */
|
|
|
+ background-color: #ffffff !important; /* 新增:设置偶数行为白色 */
|
|
|
}
|
|
|
|
|
|
/* 减少表格单元格的内边距 */
|
|
|
-::v-deep .el-table td, ::v-deep .el-table th.is-leaf {
|
|
|
+::v-deep .el-table td,
|
|
|
+::v-deep .el-table th.is-leaf {
|
|
|
padding: 8px 0; /* 减少内边距 */
|
|
|
}
|
|
|
|
|
@@ -393,7 +510,7 @@ const dialogSubmitButtonText = computed(() => {
|
|
|
.el-table-column--action .el-button.el-button--primary {
|
|
|
background-color: transparent;
|
|
|
border-color: transparent;
|
|
|
- color: #409EFF;
|
|
|
+ color: #409eff;
|
|
|
}
|
|
|
|
|
|
.el-table-column--action .el-button.el-button--danger {
|
|
@@ -401,4 +518,4 @@ const dialogSubmitButtonText = computed(() => {
|
|
|
border-color: transparent;
|
|
|
color: red;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|