|
@@ -12,7 +12,7 @@
|
|
|
>
|
|
|
</el-tab-pane>
|
|
|
<template #addIcon>
|
|
|
- <el-button type="primary" size="small" @click="showAddDialog = true">
|
|
|
+ <el-button type="primary" size="small" @click="addReport">
|
|
|
<el-icon><Plus /></el-icon>
|
|
|
新增报表
|
|
|
</el-button>
|
|
@@ -134,59 +134,15 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 新增报表对话框 -->
|
|
|
- <el-dialog v-model="showAddDialog" title="新增报表" width="500px" class="report-dialog sa-dialog">
|
|
|
- <el-form :model="newReportForm" :rules="newReportRules" ref="newReportFormRef" label-width="80px">
|
|
|
- <el-form-item label="报表名称" prop="name">
|
|
|
- <el-input v-model="newReportForm.name" placeholder="请输入报表名称" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="报表描述" prop="description">
|
|
|
- <el-input v-model="newReportForm.description" type="textarea" placeholder="请输入报表描述" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="报表类型" prop="type">
|
|
|
- <el-select v-model="newReportForm.type" placeholder="请选择报表类型">
|
|
|
- <el-option label="销售报表" value="sales" />
|
|
|
- <el-option label="用户报表" value="user" />
|
|
|
- <el-option label="订单报表" value="order" />
|
|
|
- <el-option label="财务报表" value="finance" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <template #footer>
|
|
|
- <el-button @click="showAddDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="addReport" :loading="addingReport">确认</el-button>
|
|
|
- </template>
|
|
|
- </el-dialog>
|
|
|
-
|
|
|
- <!-- 编辑报表对话框 -->
|
|
|
- <el-dialog v-model="showEditDialog" title="编辑报表" width="500px">
|
|
|
- <el-form :model="editReportForm" :rules="newReportRules" ref="editReportFormRef" label-width="80px">
|
|
|
- <el-form-item label="报表名称" prop="name">
|
|
|
- <el-input v-model="editReportForm.name" placeholder="请输入报表名称" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="报表描述" prop="description">
|
|
|
- <el-input v-model="editReportForm.description" type="textarea" placeholder="请输入报表描述" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="报表类型" prop="type">
|
|
|
- <el-select v-model="editReportForm.type" placeholder="请选择报表类型">
|
|
|
- <el-option label="销售报表" value="sales" />
|
|
|
- <el-option label="用户报表" value="user" />
|
|
|
- <el-option label="订单报表" value="order" />
|
|
|
- <el-option label="财务报表" value="finance" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <template #footer>
|
|
|
- <el-button @click="showEditDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="updateReport" :loading="updatingReport">确认</el-button>
|
|
|
- </template>
|
|
|
- </el-dialog>
|
|
|
+ <!-- 对话框已改为 useModal 调用 -->
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import { useModal } from '@/sheep/hooks'
|
|
|
+import AddReportDialog from './add-report-dialog.vue'
|
|
|
import {
|
|
|
Plus,
|
|
|
Refresh,
|
|
@@ -207,12 +163,6 @@ import { api } from '../../data.service.js'
|
|
|
|
|
|
// 响应式数据
|
|
|
const activeTab = ref('1')
|
|
|
-const showAddDialog = ref(false)
|
|
|
-const showEditDialog = ref(false)
|
|
|
-const addingReport = ref(false)
|
|
|
-const updatingReport = ref(false)
|
|
|
-const newReportFormRef = ref()
|
|
|
-const editReportFormRef = ref()
|
|
|
|
|
|
// 标签页数据
|
|
|
const tabs = ref([
|
|
@@ -268,25 +218,7 @@ const tabs = ref([
|
|
|
}
|
|
|
])
|
|
|
|
|
|
-// 表单数据
|
|
|
-const newReportForm = reactive({
|
|
|
- name: '',
|
|
|
- description: '',
|
|
|
- type: ''
|
|
|
-})
|
|
|
-
|
|
|
-const editReportForm = reactive({
|
|
|
- id: '',
|
|
|
- name: '',
|
|
|
- description: '',
|
|
|
- type: ''
|
|
|
-})
|
|
|
|
|
|
-// 表单验证规则
|
|
|
-const newReportRules = {
|
|
|
- name: [{ required: true, message: '请输入报表名称', trigger: 'blur' }],
|
|
|
- type: [{ required: true, message: '请选择报表类型', trigger: 'change' }]
|
|
|
-}
|
|
|
|
|
|
// 方法
|
|
|
const handleTabChange = (tabName) => {
|
|
@@ -308,13 +240,7 @@ const refreshReport = async (tabId) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const editReport = (tab) => {
|
|
|
- editReportForm.id = tab.id
|
|
|
- editReportForm.name = tab.name
|
|
|
- editReportForm.description = tab.description
|
|
|
- editReportForm.type = tab.type
|
|
|
- showEditDialog.value = true
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
const deleteReport = async (tabId) => {
|
|
|
if (tabs.value.length <= 1) {
|
|
@@ -356,82 +282,9 @@ const exportReport = async (tabId) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const addReport = async () => {
|
|
|
- try {
|
|
|
- await newReportFormRef.value.validate()
|
|
|
- addingReport.value = true
|
|
|
-
|
|
|
- // 调用API创建报表
|
|
|
- const response = await api.operating.spectaculars.add({
|
|
|
- name: newReportForm.name,
|
|
|
- description: newReportForm.description,
|
|
|
- type: newReportForm.type
|
|
|
- })
|
|
|
-
|
|
|
- // 添加到本地数组
|
|
|
- const newTab = {
|
|
|
- id: response.data.id || Date.now().toString(),
|
|
|
- name: newReportForm.name,
|
|
|
- description: newReportForm.description,
|
|
|
- type: newReportForm.type,
|
|
|
- loading: false,
|
|
|
- chartType: 'line',
|
|
|
- chartTitle: '数据趋势',
|
|
|
- searchKeyword: '',
|
|
|
- stats: [],
|
|
|
- chartData: [],
|
|
|
- chartOption: {},
|
|
|
- tableData: [],
|
|
|
- tableColumns: []
|
|
|
- }
|
|
|
-
|
|
|
- tabs.value.push(newTab)
|
|
|
- activeTab.value = newTab.id
|
|
|
-
|
|
|
- // 重置表单
|
|
|
- Object.assign(newReportForm, { name: '', description: '', type: '' })
|
|
|
- showAddDialog.value = false
|
|
|
-
|
|
|
- ElMessage.success('创建成功')
|
|
|
-
|
|
|
- // 加载新报表数据
|
|
|
- await loadReportData(newTab.id)
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error('创建失败')
|
|
|
- } finally {
|
|
|
- addingReport.value = false
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-const updateReport = async () => {
|
|
|
- try {
|
|
|
- await editReportFormRef.value.validate()
|
|
|
- updatingReport.value = true
|
|
|
-
|
|
|
- // 调用API更新报表
|
|
|
- await api.operating.spectaculars.update({
|
|
|
- id: editReportForm.id,
|
|
|
- name: editReportForm.name,
|
|
|
- description: editReportForm.description,
|
|
|
- type: editReportForm.type
|
|
|
- })
|
|
|
-
|
|
|
- // 更新本地数据
|
|
|
- const tab = tabs.value.find(t => t.id === editReportForm.id)
|
|
|
- if (tab) {
|
|
|
- tab.name = editReportForm.name
|
|
|
- tab.description = editReportForm.description
|
|
|
- tab.type = editReportForm.type
|
|
|
- }
|
|
|
-
|
|
|
- showEditDialog.value = false
|
|
|
- ElMessage.success('更新成功')
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error('更新失败')
|
|
|
- } finally {
|
|
|
- updatingReport.value = false
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
const updateChart = (tabId) => {
|
|
|
const tab = tabs.value.find(t => t.id === tabId)
|
|
@@ -635,6 +488,75 @@ const generateChartOption = (tab) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 新增报表
|
|
|
+const addReport = () => {
|
|
|
+ useModal(
|
|
|
+ AddReportDialog,
|
|
|
+ { title: '新增报表', type: 'add' },
|
|
|
+ {
|
|
|
+ confirm: (reportData) => {
|
|
|
+ // 添加新标签页
|
|
|
+ const newId = String(tabs.value.length + 1)
|
|
|
+ tabs.value.push({
|
|
|
+ id: newId,
|
|
|
+ name: reportData.name,
|
|
|
+ description: reportData.description,
|
|
|
+ type: reportData.type,
|
|
|
+ loading: false,
|
|
|
+ chartType: 'line',
|
|
|
+ chartTitle: reportData.name + '趋势',
|
|
|
+ searchKeyword: '',
|
|
|
+ stats: [],
|
|
|
+ chartData: [],
|
|
|
+ tableData: [],
|
|
|
+ filteredTableData: []
|
|
|
+ })
|
|
|
+ activeTab.value = newId
|
|
|
+ loadReportData(newId)
|
|
|
+ ElMessage.success('报表创建成功!')
|
|
|
+ },
|
|
|
+ },
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+// 编辑报表
|
|
|
+const editReport = (tab) => {
|
|
|
+ useModal(
|
|
|
+ AddReportDialog,
|
|
|
+ {
|
|
|
+ title: '编辑报表',
|
|
|
+ type: 'edit',
|
|
|
+ reportData: {
|
|
|
+ name: tab.name,
|
|
|
+ description: tab.description,
|
|
|
+ type: tab.type
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ confirm: (reportData) => {
|
|
|
+ // 更新标签页数据
|
|
|
+ tab.name = reportData.name
|
|
|
+ tab.description = reportData.description
|
|
|
+ tab.type = reportData.type
|
|
|
+ tab.chartTitle = reportData.name + '趋势'
|
|
|
+ loadReportData(tab.id)
|
|
|
+ ElMessage.success('报表更新成功!')
|
|
|
+ },
|
|
|
+ },
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+// 暴露方法
|
|
|
+defineExpose({
|
|
|
+ refreshAllTabs: () => {
|
|
|
+ tabs.value.forEach(tab => {
|
|
|
+ loadReportData(tab.id)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ addReport,
|
|
|
+ editReport
|
|
|
+})
|
|
|
+
|
|
|
// 初始化
|
|
|
onMounted(() => {
|
|
|
loadReportData(activeTab.value)
|