Browse Source

fix:修改定时刷新数据

dev-xjf
肖晋飞 4 weeks ago
parent
commit
213d05eee9
  1. 2
      src/views/dashboard/demo/components/ParameterInfo.vue
  2. 2
      src/views/dashboard/demo/components/demo.json
  3. 58
      src/views/dashboard/demo/components/svg.vue
  4. 8
      src/views/dashboard/demo/index.vue

2
src/views/dashboard/demo/components/ParameterInfo.vue

@ -96,6 +96,6 @@ onBeforeUpdate(async () => {
<style scoped> <style scoped>
::v-deep(.ant-card-body) { ::v-deep(.ant-card-body) {
padding:5px; padding:10px;
} }
</style> </style>

2
src/views/dashboard/demo/components/demo.json

@ -34,7 +34,7 @@
}, },
"LeftDown": { "LeftDown": {
"Header": "生产流程", "Header": "生产流程",
"path": "svg/illustration.svg" "path": ""
}, },
"RightDown": { "RightDown": {
"Header": "参数信息", "Header": "参数信息",

58
src/views/dashboard/demo/components/svg.vue

@ -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>

8
src/views/dashboard/demo/index.vue

@ -59,16 +59,16 @@ onMounted(async () => {
<!-- <template #headerContent> <!-- <template #headerContent>
<WorkbenchHeader class="m-1" :data="data" /> <WorkbenchHeader class="m-1" :data="data" />
</template> --> </template> -->
<div class="h-[calc(91vh)] bg-[#f5f5f5]"> <div class="h-[calc(92vh)] bg-[#f5f5f5]">
<div class="enter-y h-[calc(91vh/2)] md:flex"> <div class="enter-y h-[calc(92vh/2)] md:flex">
<StaticImg class="m-1 w-full md:w-1/4" :loading="loading" :data="data.LeftUp || {}" /> <StaticImg class="m-1 w-full md:w-1/4" :loading="loading" :data="data.LeftUp || {}" />
<ProjectCard class="enter-y m-1 w-full md:w-1/2" :loading="loading" :data="data.LeftMidUp || {}" /> <ProjectCard class="enter-y m-1 w-full md:w-1/2" :loading="loading" :data="data.LeftMidUp || {}" />
<div class="enter-y h-[calc(91vh/2)] w-full md:w-1/4"> <div class="enter-y h-[calc(92vh/2)] w-full md:w-1/4">
<DynamicInfo :loading="loading" class="enter-y m-1 h-[calc(17vh)] w-full" :data="data.RightMidUp || {}" /> <DynamicInfo :loading="loading" class="enter-y m-1 h-[calc(17vh)] w-full" :data="data.RightMidUp || {}" />
<Operation class="enter-y m-1 h-[calc(27vh)] w-full" :loading="loading" :data="data.RightUp || {}" /> <Operation class="enter-y m-1 h-[calc(27vh)] w-full" :loading="loading" :data="data.RightUp || {}" />
</div> </div>
</div> </div>
<div class="enter-y h-[calc(91vh/2)] md:flex"> <div class="enter-y h-[calc(92vh/2)] md:flex">
<StaticSvg class="m-1 w-full md:w-1/2" :loading="loading" :data="data.LeftDown || {}" /> <StaticSvg class="m-1 w-full md:w-1/2" :loading="loading" :data="data.LeftDown || {}" />
<ParameterInfo class="m-1 w-full md:w-1/2" :loading="loading" :data="data.RightDown || {}" /> <ParameterInfo class="m-1 w-full md:w-1/2" :loading="loading" :data="data.RightDown || {}" />
</div> </div>

Loading…
Cancel
Save