fix:修复无限发送请求,修复不能独立配置,修复不能动态更新

This commit is contained in:
Free-sss 2025-09-04 15:31:16 +08:00
parent 5bf82ab58b
commit 30d47df4bd
7 changed files with 114 additions and 37 deletions

View File

@ -27,7 +27,7 @@
{
"rank": "TOP1",
"name": "株机公司",
"value": 932
"value": 101
},
{
"rank": "TOP2",
@ -330,7 +330,7 @@
{
"title": "调漆作业室",
"label": "智控场景",
"value": null,
"value": 0,
"color": "#FFD700",
"image": "scene-control.png"
}

View File

@ -2,6 +2,7 @@ import { PublicConfigClass } from '@/packages/public'
import { CreateComponentType } from '@/packages/index.d'
import { TopAlarmsConfig } from './index'
import dataJson from './data.json'
import { cloneDeep } from 'lodash'
export const option = {
sceneCode: 'T04',
componentIndexKey: "a",
@ -51,6 +52,6 @@ export const option = {
export default class Config extends PublicConfigClass implements CreateComponentType {
public key = TopAlarmsConfig.key
public chartConfig = TopAlarmsConfig
public option = option
public option = cloneDeep(option)
}

View File

@ -30,15 +30,15 @@
<span class="rank-icon"></span>
{{ index + 1 }}
</span>
<span class="name" :style="{ color: option.nameColor }">{{ item.enterpriseName }}</span>
<span class="name" :style="{ color: option.nameColor }">{{ item.name }}</span>
</div>
<div class="item-value">
<span class="value" :style="{ color: option.valueColor }">{{ item.alarmCount }}</span>
<span class="value" :style="{ color: option.valueColor }">{{ item.value }}</span>
</div>
<div class="progress-bar-wrapper">
<div class="progress-bar">
<div class="progress" :style="{
width: calculateWidth(item.alarmCount),
width: calculateWidth(item.value),
background: `linear-gradient(to right, ${option.barColorStart}, ${option.barColorEnd})`
}"></div>
</div>
@ -112,14 +112,14 @@ const fetchCorpsData = async (option: string) => {
const response: any =
// await axiosInstance.get(`/awjt/screen/corpsFive/${option}/${props.chartConfig.option.sceneCode}`, { baseURL: '' })
// if (response.state === true) {
// displayData.value = response.value || []
// } else {
// console.error('API:', response)
// displayData.value = []
// }
// 使
await getStaticData(key, props.chartConfig.option.componentIndexKey, props.chartConfig.option.sceneCode);
// if (response.state === true) {
// displayData.value = response.value || []
// } else {
// console.error('API:', response)
// displayData.value = []
// }
// 使
await getStaticData(key, props.chartConfig.option.componentIndexKey, props.chartConfig.option.sceneCode);
displayData.value = response['source']
props.chartConfig.option.titleText = response['titleText']
} catch (error) {

View File

@ -2,6 +2,7 @@ import { PublicConfigClass } from '@/packages/public'
import { CreateComponentType } from '@/packages/index.d'
import { ParkingSceneConfig } from './index'
import dataJson from './data.json'
import { cloneDeep } from 'lodash'
export const option = {
sceneCode: "",
@ -25,5 +26,5 @@ export const option = {
export default class Config extends PublicConfigClass implements CreateComponentType {
public key = ParkingSceneConfig.key
public chartConfig = ParkingSceneConfig
public option = option
public option = cloneDeep(option)
}

View File

@ -225,52 +225,84 @@
</div>
</template>
<script setup lang="ts">
import { PropType, computed, onMounted, watch } from 'vue'
import { PropType, computed, onMounted, watch, ref } from 'vue'
import { option as configOption } from './config'
import { ParkingSceneConfig } from './index'
import axios from 'axios';
const props = defineProps({
chartConfig: {
type: Object as PropType<{ option: typeof configOption }>,
required: true
}
})
const key = ParkingSceneConfig.key;
const option = computed(() => props.chartConfig.option)
const isFetching = ref(false) //
//
const getStaticData = async (key: string, componentIndexKey: string, sceneCode: string) => {
let dataTemp = option.value.dataset
try {
const response = await axios.get('/staticData/static.json');
if (response.data) {
console.log('静态数据:', response.data);
dataTemp = response.data[sceneCode]?.[key]?.[componentIndexKey]?.['source'];
const dataTemp = response.data[sceneCode]?.[key]?.[componentIndexKey]?.['source'];
if (!dataTemp) {
console.warn(`Data not found for sceneCode: ${sceneCode}, key: ${key}, componentIndexKey: ${componentIndexKey}`);
return props.chartConfig.option.dataset; //
}
return dataTemp;
}
console.log("datatemp:", dataTemp)
} catch (err) {
// console.error('static.json:', err);
console.error('获取static.json失败:', err);
}
return dataTemp
return props.chartConfig.option.dataset; //
}
//
const fetchData = async () => {
//
if (isFetching.value) return;
isFetching.value = true;
try {
let data;
//
data = await getStaticData(key, option.value.componentIndexKey, option.value.sceneCode);
props.chartConfig.option.dataset = data;
if (JSON.stringify(data) !== JSON.stringify(option.value.dataset)) {
console.log('更新数据:', data);
}
} finally {
isFetching.value = false;
}
}
watch(
() => props.chartConfig.option.dataset,
async (newData: any) => {
option.value.dataset = await getStaticData(key, option.value.componentIndexKey, option.value.sceneCode);
() => [
props.chartConfig.option.sceneCode,
props.chartConfig.option.componentIndexKey,
props.chartConfig.option.dataset
],
async () => {
await fetchData();
},
{
immediate: true,
deep: false
deep: true
}
)
//
onMounted(async () => {
option.value.dataset = await getStaticData(key, option.value.componentIndexKey, option.value.sceneCode);
await fetchData();
})
</script>
<style lang="scss" scoped>

View File

@ -2,6 +2,7 @@ import { PublicConfigClass } from '@/packages/public'
import { CreateComponentType } from '@/packages/index.d'
import { SceneDistributionConfig } from './index'
import dataJson from './data.json'
import { cloneDeep } from 'lodash'
export const option = {
sceneCode: 'T06',
@ -22,5 +23,5 @@ export const option = {
export default class Config extends PublicConfigClass implements CreateComponentType {
public key = SceneDistributionConfig.key
public chartConfig = SceneDistributionConfig
public option = option
public option = cloneDeep(option)
}

View File

@ -221,7 +221,7 @@
</template>
<script setup lang="ts">
import { PropType, computed, onMounted } from 'vue'
import { PropType, computed, onMounted, ref, watch } from 'vue'
import { option as configOption } from './config'
import axios from 'axios'
import { SceneDistributionConfig } from './index'
@ -241,26 +241,68 @@ const getImageUrl = (name: string) => {
const key = SceneDistributionConfig.key;
//
const getStaticData = async (key: string, componentIndexKey: string, sceneCode: string) => {
let dataTemp = option.value.dataset
try {
const response = await axios.get('/staticData/static.json');
if (response.data) {
console.log('静态数据:', response.data);
dataTemp = response.data[sceneCode]?.[key]?.[componentIndexKey]?.['source'];
const dataTemp = response.data[sceneCode]?.[key]?.[componentIndexKey]?.['source'];
if (!dataTemp) {
console.warn(`Data not found for sceneCode: ${sceneCode}, key: ${key}, componentIndexKey: ${componentIndexKey}`);
return props.chartConfig.option.dataset; //
}
return dataTemp;
}
console.log("datatemp:", dataTemp)
} catch (err) {
console.error('获取static.json失败:', err);
}
return dataTemp
return props.chartConfig.option.dataset; //
}
const isFetching = ref(false) //
//
const fetchData = async () => {
//
if (isFetching.value) return;
isFetching.value = true;
try {
let data;
//
data = await getStaticData(key, option.value.componentIndexKey, option.value.sceneCode);
props.chartConfig.option.dataset = data;
if (JSON.stringify(data) !== JSON.stringify(option.value.dataset)) {
console.log('更新数据:', data);
}
} finally {
isFetching.value = false;
}
}
//
watch(
() => [
props.chartConfig.option.sceneCode,
props.chartConfig.option.componentIndexKey,
],
async () => {
await fetchData();
},
{
immediate: true,
deep: true
}
)
//
onMounted(async () => {
option.value.dataset = await getStaticData(key, option.value.componentIndexKey, option.value.sceneCode);
await fetchData();
})
</script>