|
|
@ -12,10 +12,22 @@ const isLoading = ref<boolean>(true) |
|
|
const svgError = ref<string>('') |
|
|
const svgError = ref<string>('') |
|
|
const point = ref<{ itemNameArray: string[] }>({ itemNameArray: [] }) |
|
|
const point = ref<{ itemNameArray: string[] }>({ itemNameArray: [] }) |
|
|
// const pointElements = ref<NodeListOf<SVGElement> | undefined>() |
|
|
// const pointElements = ref<NodeListOf<SVGElement> | undefined>() |
|
|
|
|
|
// 监听数据变化 |
|
|
|
|
|
watch( |
|
|
|
|
|
() => data.value, |
|
|
|
|
|
(newValue, oldValue) => { |
|
|
|
|
|
// 下方信息不会打印在控制台中 |
|
|
|
|
|
console.log('a has changed', newValue) |
|
|
|
|
|
if (newValue !== oldValue && newValue !== '' && newValue != null) |
|
|
|
|
|
loadSvg() |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
let updateInterval: NodeJS.Timeout | undefined |
|
|
) |
|
|
// 加载SVG文件 |
|
|
// 加载SVG文件 |
|
|
async function loadSvg() { |
|
|
async function loadSvg() { |
|
|
|
|
|
console.log('加载SVG文件...') |
|
|
|
|
|
console.log(data.value) |
|
|
|
|
|
|
|
|
if (!data.value) { |
|
|
if (!data.value) { |
|
|
svgError.value = '未提供SVG路径' |
|
|
svgError.value = '未提供SVG路径' |
|
|
isLoading.value = false |
|
|
isLoading.value = false |
|
|
@ -40,7 +52,6 @@ async function loadSvg() { |
|
|
url += `?t=${timestamp}` |
|
|
url += `?t=${timestamp}` |
|
|
|
|
|
|
|
|
const response = await fetch(url) |
|
|
const response = await fetch(url) |
|
|
console.log(response) |
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) |
|
|
if (!response.ok) |
|
|
throw new Error(`无法加载SVG: ${response.statusText}`) |
|
|
throw new Error(`无法加载SVG: ${response.statusText}`) |
|
|
@ -49,7 +60,6 @@ async function loadSvg() { |
|
|
|
|
|
|
|
|
// 等待DOM更新后应用实时数据 |
|
|
// 等待DOM更新后应用实时数据 |
|
|
await nextTick() |
|
|
await nextTick() |
|
|
console.log(document.querySelector('.svg-container > svg')) |
|
|
|
|
|
document.querySelector('.svg-container > svg')?.removeAttribute('width') |
|
|
document.querySelector('.svg-container > svg')?.removeAttribute('width') |
|
|
document.querySelector('.svg-container > svg')?.removeAttribute('height') |
|
|
document.querySelector('.svg-container > svg')?.removeAttribute('height') |
|
|
|
|
|
|
|
|
@ -66,13 +76,15 @@ async function loadSvg() { |
|
|
|
|
|
|
|
|
// 更新SVG中的实时数据 |
|
|
// 更新SVG中的实时数据 |
|
|
async function updateRealtimeValues() { |
|
|
async function updateRealtimeValues() { |
|
|
if (!svgContent.value || isLoading.value) |
|
|
console.log('更新SVG实时数据...', Boolean(svgContent.value)) |
|
|
|
|
|
console.log('更新SVG实时数据...', Boolean(isLoading.value)) |
|
|
|
|
|
|
|
|
|
|
|
if (!svgContent.value) |
|
|
return |
|
|
return |
|
|
try { |
|
|
try { |
|
|
const svgElement = document.querySelector('.svg-container > svg') |
|
|
const svgElement = document.querySelector('.svg-container > svg') |
|
|
svgElement?.removeAttribute('width') |
|
|
svgElement?.removeAttribute('width') |
|
|
svgElement?.removeAttribute('height') |
|
|
svgElement?.removeAttribute('height') |
|
|
console.log(svgElement) |
|
|
|
|
|
// 获取SVG元素 |
|
|
// 获取SVG元素 |
|
|
if (!svgElement) |
|
|
if (!svgElement) |
|
|
return |
|
|
return |
|
|
@ -84,27 +96,21 @@ async function updateRealtimeValues() { |
|
|
// 使用同步方式收集point-name |
|
|
// 使用同步方式收集point-name |
|
|
pointElements.forEach((element) => { |
|
|
pointElements.forEach((element) => { |
|
|
const pointName = element.getAttribute('point-name') |
|
|
const pointName = element.getAttribute('point-name') |
|
|
if (pointName) { |
|
|
if (pointName) |
|
|
pointList.push(pointName) |
|
|
pointList.push(pointName) |
|
|
console.log(`找到元素: ${element.tagName}, point-name=${pointName}`) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
point.value = { itemNameArray: pointList } |
|
|
point.value = { itemNameArray: pointList } |
|
|
console.log('收集的point-name列表:', pointList) |
|
|
|
|
|
const res = await getEXANowListReal(point.value) |
|
|
const res = await getEXANowListReal(point.value) |
|
|
console.log('API响应结果:', res) |
|
|
|
|
|
|
|
|
|
|
|
if (res && res.ReturnValue === 1 && res.ValueArray) { |
|
|
if (res && res.ReturnValue === 1 && res.ValueArray) { |
|
|
const dataValues = res.ValueArray |
|
|
const dataValues = res.ValueArray |
|
|
console.log('数据值:', dataValues) |
|
|
|
|
|
|
|
|
|
|
|
if (pointElements) { |
|
|
if (pointElements) { |
|
|
pointElements.forEach((element, index) => { |
|
|
pointElements.forEach((element, index) => { |
|
|
// 不区分大小写比较标签名 |
|
|
// 不区分大小写比较标签名 |
|
|
const tagName = element.tagName.toLowerCase() |
|
|
const tagName = element.tagName.toLowerCase() |
|
|
const value = dataValues[index] || '' |
|
|
const value = dataValues[index] || '' |
|
|
console.log(`更新元素[${index}]: 标签=${element.tagName}, 值=${value}`) |
|
|
|
|
|
|
|
|
|
|
|
// 设置文本内容,不再受标签名条件限制 |
|
|
// 设置文本内容,不再受标签名条件限制 |
|
|
element.textContent = String(value) |
|
|
element.textContent = String(value) |
|
|
@ -120,28 +126,19 @@ async function updateRealtimeValues() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 监听数据变化 |
|
|
const updateInterval = ref<NodeJS.Timeout | null>(null) |
|
|
watch( |
|
|
|
|
|
() => data.value, |
|
|
|
|
|
() => { |
|
|
|
|
|
loadSvg() |
|
|
|
|
|
}, |
|
|
|
|
|
{ immediate: true }, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
loadSvg() |
|
|
|
|
|
|
|
|
|
|
|
// 设置定时器并保存引用,以便在组件卸载时清除 |
|
|
// 设置定时器并保存引用,以便在组件卸载时清除 |
|
|
updateInterval = setTimeout(() => { |
|
|
updateInterval.value = setInterval(() => { |
|
|
console.log('定时更新数据...') |
|
|
console.log('定时更新数据...') |
|
|
updateRealtimeValues() |
|
|
updateRealtimeValues() |
|
|
}, 3000) |
|
|
}, 1000) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
onUnmounted(() => { |
|
|
onUnmounted(() => { |
|
|
// 清理定时器等资源 |
|
|
// 清理定时器等资源 |
|
|
clearTimeout(updateInterval) |
|
|
clearInterval(updateInterval.value!) |
|
|
}) |
|
|
}) |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
@ -169,17 +166,6 @@ onUnmounted(() => { |
|
|
justify-content: center; |
|
|
justify-content: center; |
|
|
width: 100%; |
|
|
width: 100%; |
|
|
height: 100%; |
|
|
height: 100%; |
|
|
min-height: 300px; |
|
|
|
|
|
cursor: pointer; /* 点击时可以手动触发数据更新 */ |
|
|
cursor: pointer; /* 点击时可以手动触发数据更新 */ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.svg-container > svg { |
|
|
|
|
|
max-width: 100%; |
|
|
|
|
|
max-height: 100%; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
svg{ |
|
|
|
|
|
width:initial; |
|
|
|
|
|
height:initial; |
|
|
|
|
|
} |
|
|
|
|
|
</style> |
|
|
</style> |
|
|
|