1 changed files with 494 additions and 0 deletions
@ -0,0 +1,494 @@
@@ -0,0 +1,494 @@
|
||||
<template> |
||||
<div class="app-container app-container-bg"> |
||||
<el-card class="first-card" ref='firstCard' shadow="always"> |
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" @submit.native.prevent> |
||||
<el-form-item label="测站" prop="stnm"> |
||||
<el-input v-model="queryParams.stnm" placeholder="请输入测站" clearable @keyup.enter.native="handleQuery" /> |
||||
</el-form-item> |
||||
<el-form-item> |
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button> |
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button> |
||||
</el-form-item> |
||||
</el-form> |
||||
<el-row :gutter="10" class="mb8"> |
||||
<el-col :span="1.5"> |
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['basic:storage:add']">新增</el-button> |
||||
</el-col> |
||||
<el-col :span="1.5"> |
||||
<el-button type="info" plain icon="Upload" @click="handleImport" v-hasPermi="['basic:storage:import']">导入</el-button> |
||||
</el-col> |
||||
<el-col :span="1.5"> |
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['basic:storage:export']">导出</el-button> |
||||
</el-col> |
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> |
||||
</el-row> |
||||
</el-card> |
||||
<div class="el-card-p card-shadow carder-border mt10 pad10 "> |
||||
<el-table class="table-box" v-table-height v-loading="loading" :data="storageList"> |
||||
<el-table-column type="selection" width="55" :align="alignment" /> |
||||
<el-table-column label="测站" :align="alignment" prop="stnm" /> |
||||
<el-table-column label="操作" :align="alignment" class-name="small-padding fixed-width"> |
||||
<template #default="scope"> |
||||
<el-button type="text" icon="View" @click="handleDetails(scope.row)">详情</el-button> |
||||
<el-button text type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button> |
||||
</template> |
||||
</el-table-column> |
||||
</el-table> |
||||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" /> |
||||
</div> |
||||
<!-- 新增修改弹窗 --> |
||||
<el-dialog class="custom-dialog" :title="title" v-model="open" width="500px" append-to-body> |
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="auto"> |
||||
<el-form-item label="测站" prop="typeId"> |
||||
<el-select-v2 v-model="form.stnm" :options="stationList" :props="{ value: 'stnmId', label: 'stnm' }" placeholder="请选择测站" filterable></el-select-v2> |
||||
</el-form-item> |
||||
<el-form-item label="水位(m)" prop="rz"> |
||||
<el-input-number controls-position="right" :min="0" v-model="form.rz" placeholder="请输入水位(m)" style="width:210px" /> |
||||
</el-form-item> |
||||
<el-form-item label="蓄水量(万立方米)" prop="w"> |
||||
<el-input-number controls-position="right" :min="0" v-model="form.w" placeholder="请输入蓄水量(万立方米)" style="width:210px" /> |
||||
</el-form-item> |
||||
</el-form> |
||||
<template #footer> |
||||
<div class="dialog-footer"> |
||||
<el-button type="primary" @click="submitForm(formRef)" v-loading='btnLoading'>确 定</el-button> |
||||
<el-button @click="cancel">取 消</el-button> |
||||
</div> |
||||
</template> |
||||
</el-dialog> |
||||
<!-- 详情弹窗 --> |
||||
<el-dialog class="custom-dialog" :title="detailsTitle" v-model="detailsOpen" width="1000px" append-to-body> |
||||
<el-row :gutter="10" class="mb8"> |
||||
<el-col :span="1.5"> |
||||
<el-button type="primary" plain icon="DataAnalysis" @click="openEarchets">视图 |
||||
</el-button> |
||||
</el-col> |
||||
</el-row> |
||||
<el-table height="500px" v-loading="loading" :data="detailsTableData" style="width: 100%; " border lazy> |
||||
<el-table-column label="测站" :align="alignment" prop="stnm" /> |
||||
<el-table-column label="水位(m)" :align="alignment" prop="rz" /> |
||||
<el-table-column label="蓄水量(万立方米)" :align="alignment" prop="w" /> |
||||
<el-table-column label="操作" :align="alignment" class-name="small-padding fixed-width"> |
||||
<template #default="scope"> |
||||
<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)">修改 |
||||
</el-button> |
||||
<el-button text type="danger" icon="Delete" @click="handleDetailsDelete(scope.row)">删除 |
||||
</el-button> |
||||
</template> |
||||
</el-table-column> |
||||
</el-table> |
||||
</el-dialog> |
||||
<!-- 视图趋势图弹窗 --> |
||||
<el-dialog v-model="echartsOpen" :title="echartsTitle" width="1000px" append-to-body> |
||||
<div ref="lineChart" style="width: 100%; height: 400px;"></div> |
||||
</el-dialog> |
||||
<!-- 导入弹窗 --> |
||||
<el-dialog class="custom-dialog" :title="upload.title" v-model="upload.open" width="400px" append-to-body> |
||||
<el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag> |
||||
<el-icon class="el-icon--upload"><upload-filled /></el-icon> |
||||
<div class="el-upload__text"> |
||||
将文件拖到此处 <em>点击上传</em> |
||||
</div> |
||||
<template #tip> |
||||
<div class="el-upload__tip text-center"> |
||||
<span>仅允许导入xls、xlsx格式文件。</span> |
||||
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板 |
||||
</el-link> |
||||
</div> |
||||
</template> |
||||
</el-upload> |
||||
<template #footer> |
||||
<div class="dialog-footer"> |
||||
<el-button type="primary" @click="submitFileForm()" v-loading='btnLoading'>确 定</el-button> |
||||
<el-button @click="upload.open = false">取 消</el-button> |
||||
</div> |
||||
</template> |
||||
</el-dialog> |
||||
<!-- 到处弹窗 --> |
||||
<el-dialog class="custom-dialog" title="库容导出" v-model="exportOpen" width="400px" append-to-body> |
||||
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple collapse-tags style="width:100%"> |
||||
<el-option v-for="item in stationList" :key="item.stnmId" :label="item.stnm" :value="item.stnmId" /> |
||||
</el-select> |
||||
<template #footer> |
||||
<div class="dialog-footer"> |
||||
<el-button type="primary" @click="submitExportForm()" v-loading='btnLoading'>确 定</el-button> |
||||
<el-button @click="exportOpen = false">取 消</el-button> |
||||
</div> |
||||
</template> |
||||
</el-dialog> |
||||
|
||||
</div> |
||||
</template> |
||||
<script setup> |
||||
import * as echarts from "echarts"; |
||||
import * as XLSX from 'xlsx'; |
||||
import { ref, reactive, onMounted, nextTick, getCurrentInstance } from 'vue' |
||||
import { getToken } from "@/utils/auth"; |
||||
|
||||
const { proxy } = getCurrentInstance() |
||||
const alignment = 'center' |
||||
const showSearch = ref(true) |
||||
const queryParams = reactive({ |
||||
pageNum: 1, |
||||
pageSize: 10, |
||||
stnm: '', |
||||
}) |
||||
const loading = ref(false) |
||||
const total = ref(0) |
||||
const storageList = ref([]) |
||||
const open = ref(false) |
||||
const title = ref("") |
||||
const detailsTitle = ref('') |
||||
const detailsOpen = ref(false) |
||||
const detailsTableData = ref([]) |
||||
let detailsID = ref('') |
||||
const form = reactive({}) |
||||
const rules = reactive({}) |
||||
let formRef = ref(null) |
||||
const btnLoading = ref(false) |
||||
const echartsOpen = ref(false) |
||||
const echartsTitle = ref('趋势图') |
||||
let chartData = ref(null) |
||||
let lineChart = ref(null) |
||||
let uploadRef = ref(null) |
||||
|
||||
// 先声明 upload 变量 |
||||
const upload = reactive({ |
||||
// 是否显示弹出层(资产导入) |
||||
open: false, |
||||
// 弹出层标题(资产导入) |
||||
title: '', |
||||
// 是否禁用上传 |
||||
isUploading: false, |
||||
// 是否更新已经存在的用户数据 |
||||
updateSupport: 0, |
||||
// 设置上传的请求头部 |
||||
headers: { Authorization: 'Bearer ' + getToken() }, |
||||
// 上传的地址 |
||||
url: '' |
||||
}) |
||||
|
||||
// 初始化上传URL |
||||
upload.url = `${import.meta.env.VITE_APP_BASE_API}/basic/storage/importdata?updateSupport=${upload.updateSupport}` |
||||
|
||||
const getList = async () => { |
||||
loading.value = true; |
||||
try { |
||||
const res = await proxy.axiosGet('/basic/storage/list', queryParams) |
||||
if (res.code == 0) { |
||||
storageList.value = res.data |
||||
total.value = res.count |
||||
} |
||||
|
||||
} catch (error) { |
||||
} finally { |
||||
loading.value = false |
||||
} |
||||
} |
||||
|
||||
/** 搜索按钮操作 */ |
||||
const handleQuery = () => { |
||||
queryParams.pageNum = 1 |
||||
getList() |
||||
} |
||||
|
||||
const resetQuery = () => { |
||||
proxy.resetForm("queryForm"); |
||||
handleQuery(); |
||||
} |
||||
|
||||
/** 新增按钮操作 */ |
||||
const handleAdd = () => { |
||||
reset(); |
||||
open.value = true; |
||||
title.value = "添加库容"; |
||||
} |
||||
|
||||
/** 详情按钮操作 */ |
||||
const handleDetails = async (row) => { |
||||
reset(); |
||||
let id = row.stnmId |
||||
detailsID.value = id |
||||
detailsTitle.value = `${row.stnm}库容详情`; |
||||
getDetailList(id) |
||||
} |
||||
|
||||
/** 删除按钮操作 */ |
||||
const handleDelete = (row) => { |
||||
let stnms = row.stnm |
||||
const stnmIds = row.stnmId |
||||
proxy.$modal.confirm('是否确认删除站点名称为"' + stnms + '"的数据项?').then(async function () { |
||||
let res = await proxy.axiosDelete('/basic/storage/deleteParent/' + stnmIds); |
||||
if (res.code === 0) { |
||||
proxy.$modal.msgSuccess("删除成功"); |
||||
getList(); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
/************************************************************* 弹窗 ***************************************/ |
||||
const stationList = ref([]) |
||||
const getStnmandStnmId = async () => { |
||||
let res = await proxy.axiosGet('/basic/station/queryStnmandStnmId', { 'type': 'C' }); |
||||
if (res.code === 200) { |
||||
stationList.value = res.data |
||||
} |
||||
} |
||||
|
||||
// 取消按钮 |
||||
const cancel = () => { |
||||
open.value = false; |
||||
reset(); |
||||
} |
||||
|
||||
const reset = () => { |
||||
Object.assign(form, { |
||||
id: null, |
||||
stnmId: null, |
||||
rz: null, |
||||
w: null, |
||||
mstm: null, |
||||
moditime: null |
||||
}); |
||||
proxy.resetForm("formRef"); |
||||
} |
||||
|
||||
const getDetailList = async (id) => { |
||||
try { |
||||
let res = await proxy.axiosGet('/basic/storage/listById/' + id); |
||||
if (res.code === 0) { |
||||
detailsTableData.value = res.data |
||||
detailsOpen.value = true; |
||||
} |
||||
} catch (error) { |
||||
console.log(error) |
||||
} |
||||
} |
||||
|
||||
const handleUpdate = async (row) => { |
||||
reset(); |
||||
let id = row.id |
||||
try { |
||||
let res = await proxy.axiosPost('/basic/storage/info/' + id); |
||||
if (res.code === 0) { |
||||
Object.assign(form, res.data) |
||||
open.value = true; |
||||
title.value = `修改库容`; |
||||
} |
||||
} catch (error) { |
||||
console.log(error) |
||||
} |
||||
} |
||||
|
||||
/** 提交按钮 */ |
||||
const submitForm = async (formEl) => { |
||||
if (!formEl) return |
||||
await formEl.validate((valid, fields) => { |
||||
if (valid) { |
||||
if (form.id != null) { |
||||
editMethod(); |
||||
} else { |
||||
addMethod(); |
||||
} |
||||
} |
||||
}) |
||||
} |
||||
|
||||
// 警戒水位新增方法 |
||||
const addMethod = async () => { |
||||
btnLoading.value = true |
||||
try { |
||||
let res = await proxy.axiosPost('/basic/storage/add', form); |
||||
if (res.code === 0) { |
||||
proxy.$modal.msgSuccess("新增成功"); |
||||
open.value = false; |
||||
getList() |
||||
btnLoading.value = false |
||||
} |
||||
} catch (error) { |
||||
btnLoading.value = false |
||||
} |
||||
} |
||||
|
||||
// 警戒水位修改方法 |
||||
const editMethod = async () => { |
||||
btnLoading.value = true |
||||
try { |
||||
let res = await proxy.axiosPost('/basic/storage/edit', form); |
||||
if (res.code === 0) { |
||||
proxy.$modal.msgSuccess("修改成功"); |
||||
open.value = false; |
||||
getDetailList(detailsID.value); |
||||
btnLoading.value = false |
||||
} |
||||
} catch (error) { |
||||
btnLoading.value = false |
||||
} |
||||
} |
||||
|
||||
// 视图按钮操作 |
||||
const openEarchets = async () => { |
||||
let res = await proxy.axiosGet(`/basic/storage/getById`, detailsTableData.value[0]) |
||||
echartsOpen.value = true // 打开对话框 |
||||
chartData.value = res.data |
||||
nextTick(() => { |
||||
echartsTitle.value = `${chartData.value.stnm}趋势图` |
||||
initChart(chartData.value) // 确保对话框渲染后再初始化图表 |
||||
}) |
||||
} |
||||
|
||||
const initChart = (value) => { |
||||
let myChart = echarts.init(lineChart.value); |
||||
|
||||
// 指定图表的配置项和数据 |
||||
const option = { |
||||
// title: { |
||||
// text: value.stnm |
||||
// }, |
||||
tooltip: { |
||||
trigger: 'axis' |
||||
}, |
||||
xAxis: { |
||||
type: 'category', |
||||
data: value.xAxis, |
||||
name: '水位', // 添加 X 轴名称 |
||||
nameLocation: 'middle', // 位置在中间 |
||||
nameGap: 50 // 名称和轴的间距 |
||||
}, |
||||
yAxis: { |
||||
type: 'value', |
||||
name: '蓄水量', // 添加 Y 轴名称 |
||||
nameLocation: 'middle', // 位置在中间 |
||||
nameGap: 50 // 名称和轴的间距 |
||||
}, |
||||
series: [ |
||||
{ |
||||
type: 'line', |
||||
data: value.yAxis, |
||||
smooth: true // 平滑曲线 |
||||
} |
||||
] |
||||
} |
||||
|
||||
// 使用刚指定的配置项和数据显示图表 |
||||
myChart.setOption(option) |
||||
} |
||||
|
||||
/******************************************* 导入弹窗 ***************************************************/ |
||||
const handleImport = () => { |
||||
upload.title = '库容导入' |
||||
upload.open = true |
||||
} |
||||
|
||||
// 注意:以下两个函数在原代码中被引用但在代码中未定义,需要补充或移除引用 |
||||
const handleFileUploadProgress = (event, file, fileList) => { |
||||
upload.isUploading = true |
||||
} |
||||
|
||||
const handleFileSuccess = (response, file, fileList) => { |
||||
upload.open = false; |
||||
upload.isUploading = false; |
||||
proxy.$refs["uploadRef"].handleRemove(file); |
||||
proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true }); |
||||
getList(); |
||||
} |
||||
|
||||
const submitFileForm = () => { |
||||
proxy.$refs["uploadRef"].submit(); |
||||
} |
||||
// 下载模板 |
||||
const importTemplate = async () => { |
||||
try { |
||||
const templateName = '库容模板.xls'; |
||||
const url = `${import.meta.env.VITE_APP_BASE_API}/excel/storage.xls`; |
||||
|
||||
// 使用fetch API获取文件 |
||||
const response = await fetch(url); |
||||
const blob = await response.blob(); |
||||
|
||||
// 创建对象URL |
||||
const blobUrl = window.URL.createObjectURL(blob); |
||||
|
||||
// 创建并触发下载 |
||||
const link = document.createElement('a'); |
||||
link.href = blobUrl; |
||||
link.download = templateName; |
||||
link.click(); |
||||
// 清理 |
||||
window.URL.revokeObjectURL(blobUrl); |
||||
} catch (error) { |
||||
console.error('下载模板失败:', error); |
||||
proxy.$modal.msgError("模板下载失败,请稍后重试"); |
||||
} |
||||
}; |
||||
|
||||
const handleDetailsDelete = (row) => { |
||||
// 详情删除操作 |
||||
proxy.$modal.confirm('是否确认删除该条记录?').then(async function () { |
||||
let res = await proxy.axiosDelete('/basic/storage/' + row.id); |
||||
if (res.code === 0) { |
||||
proxy.$modal.msgSuccess("删除成功"); |
||||
getDetailList(detailsID.value); |
||||
} |
||||
}) |
||||
} |
||||
const exportOpen = ref(false) |
||||
const checkboxList = ref([]) |
||||
const handleExport = () => { |
||||
exportOpen.value = true |
||||
} |
||||
const submitExportForm = async () => { |
||||
if (checkboxList.value.length == 0) { |
||||
proxy.$modal.msgWarning("请选择需要导出的测站"); |
||||
return |
||||
} |
||||
// 1. 按站点分组数据 |
||||
let siteDataMap = new Map(); |
||||
for (const id of checkboxList.value) { |
||||
try { |
||||
const res = await proxy.axiosGet(`/basic/storage/listById/${id}`); |
||||
if (res.code === 0 && res.data?.length) { |
||||
for (const item of res.data) { |
||||
const siteName = item.stnm; |
||||
if (!siteDataMap.has(siteName)) { |
||||
siteDataMap.set(siteName, []); |
||||
} |
||||
// 转换列名并保留数据 |
||||
siteDataMap.get(siteName).push({ |
||||
站点: item.stnm, |
||||
水位: item.rz, |
||||
库容: item.w |
||||
}); |
||||
} |
||||
} |
||||
} catch (error) { |
||||
proxy.$modal.msgError(`获取ID ${id} 数据失败`); |
||||
} |
||||
} |
||||
// 2. 检查有效数据 |
||||
if (siteDataMap.size === 0) { |
||||
proxy.$modal.msgWarning('所有站点数据获取失败'); |
||||
exportOpen.value = false; |
||||
return; |
||||
} |
||||
|
||||
// 3. 创建Excel并添加多个Sheet |
||||
const wb = XLSX.utils.book_new(); |
||||
|
||||
siteDataMap.forEach((data, siteName) => { |
||||
// 清理Sheet名称非法字符 |
||||
const safeName = siteName.replace(/[\\/:*?"<>|]/g, '_'); |
||||
const ws = XLSX.utils.json_to_sheet(data); |
||||
XLSX.utils.book_append_sheet(wb, ws, safeName); |
||||
}); |
||||
|
||||
// 4. 下载文件 |
||||
const filename = `水库库容_${new Date().toLocaleDateString()}.xlsx`; |
||||
XLSX.writeFile(wb, filename); |
||||
exportOpen.value = false; |
||||
} |
||||
onMounted(() => { |
||||
getList() |
||||
getStnmandStnmId() |
||||
}) |
||||
</script> |
||||
Loading…
Reference in new issue