Browse Source

fix(财务账户): 修复地区参数处理和图表实例引用问题

修复从工作台跳转时地区参数可能为数组的情况,并添加标准化处理函数
解决图表组件中实例引用和初始化时机问题,确保正确初始化和销毁
zhangyong/feature-20260113094820-现金重构
zhangrenyuan 1 month ago
parent
commit
a4cd9e0476
  1. 18
      src/components/workspace/GoldGraph.vue
  2. 12
      src/views/moneyManage/financialAccount/cashFlow.vue

18
src/components/workspace/GoldGraph.vue

@ -84,7 +84,7 @@
<script setup> <script setup>
import * as echarts from 'echarts' import * as echarts from 'echarts'
import {onMounted, onUnmounted, ref, watch} from 'vue'
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import API from '@/util/http' import API from '@/util/http'
import {ElMessage} from 'element-plus' import {ElMessage} from 'element-plus'
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@ -150,9 +150,9 @@ const length = ref(0)
const chartLoading = ref(true) const chartLoading = ref(true)
const handleResize = () => { const handleResize = () => {
if (chartInstance.value) {
if (chartInstance) {
try { try {
chartInstance.value.resize()
chartInstance.resize()
console.log('resize一下') console.log('resize一下')
} catch (error) { } catch (error) {
console.error('图表resize失败:', error) console.error('图表resize失败:', error)
@ -168,13 +168,13 @@ const initChart = () => {
} }
// //
const destroyChart = () => { const destroyChart = () => {
if (chartInstance.value) {
if (chartInstance) {
try { try {
chartInstance.value.dispose()
chartInstance.dispose()
} catch (error) { } catch (error) {
console.error('图表销毁失败:', error) console.error('图表销毁失败:', error)
} }
chartInstance.value = null
chartInstance = null
} }
window.removeEventListener('resize', handleResize) window.removeEventListener('resize', handleResize)
} }
@ -519,6 +519,7 @@ const updateChart = (chartData) => {
if (!chartInstance) { if (!chartInstance) {
initChart() initChart()
} }
if (!chartInstance) return
chartLoading.value = true chartLoading.value = true
try { try {
let series = [] let series = []
@ -686,10 +687,9 @@ const handleDatePickerChange = () => {
onMounted(async () => { onMounted(async () => {
await getAdminData() await getAdminData()
await getMarkets() await getMarkets()
await nextTick()
initChart()
getYear() getYear()
window.addEventListener('resize', () => {
chartInstance.resize()
})
}) })
onUnmounted(() => { onUnmounted(() => {
destroyChart() destroyChart()

12
src/views/moneyManage/financialAccount/cashFlow.vue

@ -315,10 +315,16 @@ const throttledsubmitRefund = _.throttle(handleRefund, 5000, {
trailing: false trailing: false
}) })
// ID // ID
const normalizeMarketLabel = (value) => {
return String(value ?? '')
.trim()
.toLowerCase()
.replace(/[\s_-]+/g, '')
}
const findValueByLabel = (options, label) => { const findValueByLabel = (options, label) => {
const normalizedLabel = normalizeMarketLabel(label)
for (const option of options) { for (const option of options) {
// trim
if (option.label === label || option.label?.trim() === label?.trim()) {
if (normalizeMarketLabel(option.label) === normalizedLabel) {
return option.value return option.value
} }
if (option.children && option.children.length) { if (option.children && option.children.length) {
@ -333,7 +339,7 @@ onMounted(async () => {
await getMarket() await getMarket()
// //
const regionName = route.query.region
const regionName = Array.isArray(route.query.region) ? route.query.region[0] : route.query.region
if (regionName && marketOptions.value.length) { if (regionName && marketOptions.value.length) {
const matchedId = findValueByLabel(marketOptions.value, regionName) const matchedId = findValueByLabel(marketOptions.value, regionName)
if (matchedId) { if (matchedId) {

Loading…
Cancel
Save