Browse Source

fix:增强用户体验,挂载前就修改变色

dev-xjf
肖晋飞 4 weeks ago
parent
commit
f43216a9f4
  1. 43
      src/views/dashboard/demo/components/ProjectCard.vue
  2. 68
      src/views/dashboard/demo/index.vue

43
src/views/dashboard/demo/components/ProjectCard.vue

@ -10,54 +10,13 @@ const props = defineProps({
default: () => {}, default: () => {},
}, },
}) })
const gridData = ref<any>([])
watch( watch(
() => props.data, () => props.data,
(newValue, oldValue) => { (newValue, oldValue) => {
// //
console.log('a has changed', newValue, oldValue) console.log('a has changed', newValue, oldValue)
getNewData()
}, },
) )
async function getNewData() {
const rows = props.data.Content || []
for (const item of rows) {
try {
const param = item.Point
const res = await getExaNow(param)
let ifColor: boolean = false
if (res != null)
ifColor = res === '1'
gridData.value.push(Object.assign({}, item, { ifColor }))
}
catch (e) {
}
}
}
//
// onMounted(async () => {
// const rows = props.data.Content || []
// for (const item of rows) {
// try {
// const param = item.Point
// const res = await getExaNow(param)
// let ifColor: boolean = false
// if (res != null)
// ifColor = res === '1'
// gridData.value.push(Object.assign({}, item, { ifColor }))
// console.log(gridData.value)
// }
// catch (e) {
// }
// }
// })
</script> </script>
<template> <template>
@ -68,7 +27,7 @@ async function getNewData() {
</a-button> </a-button>
</template> </template>
<CardGrid v-for="item in gridData" :key="item.Point" :class="{ 'bg-[#990000] bg-opacity-50': item.ifColor }" class="flex flex-col items-center justify-center !h-1/3 !w-full !md:w-1/4"> <CardGrid v-for="item in props.data.Content" :key="item.Point" :class="{ 'bg-[#990000] bg-opacity-50': item.ifColor }" class="flex flex-col items-center justify-center !h-1/3 !w-full !md:w-1/4">
<!-- <Icon :icon="item.icon" :color="item.color" size="30" /> --> <!-- <Icon :icon="item.icon" :color="item.color" size="30" /> -->
<div class="flex flex-col items-center justify-center"> <div class="flex flex-col items-center justify-center">
<div class="text-center text-base"> <div class="text-center text-base">

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

@ -1,7 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import ProjectCard from './components/ProjectCard.vue' import ProjectCard from './components/ProjectCard.vue'
import DynamicInfo from './components/DynamicInfo.vue' import DynamicInfo from './components/DynamicInfo.vue'
import StaticImg from './components/staticImg.vue' import StaticImg from './components/staticImg.vue'
@ -16,10 +15,8 @@ import { getExaNow } from '@/api/alert/exa'
const loading = ref(true) const loading = ref(true)
const route = useRoute() const route = useRoute()
const gridData = ref<any[]>([])
setTimeout(() => {
loading.value = false
}, 500)
// idcommitbug // idcommitbug
const id = route.path.split('/').pop() || '' const id = route.path.split('/').pop() || ''
const data = ref<any>(data1) const data = ref<any>(data1)
@ -28,30 +25,32 @@ onMounted(async () => {
const res = await getDeviceInfo(id) const res = await getDeviceInfo(id)
if (res) if (res)
data.value = JSON.parse(res.Page_Content) data.value = JSON.parse(res.Page_Content)
// getColor(data.value) // getNewData LeftMidUp
await getNewData()
loading.value = false
}) })
// async function getColor(data: any) { // ifColor
// const rows = data.LeftMidUp.Content || [] async function getNewData() {
// const gridData = [] as any[] const rows = data.value.LeftMidUp.Content || []
// for (const item of rows) { for (const item of rows) {
// try { try {
// const param = item.Point const param = item.Point
// const res = await getExaNow(param) const res = await getExaNow(param)
console.log(res)
// let ifColor: boolean = false let ifColor: boolean = false
// if (res != null) if (res != null)
// ifColor = res === '1' ifColor = res === '1'
// ifColor
// gridData.push(Object.assign({}, item, { ifColor })) item.ifColor = ifColor
}
// console.log(gridData) catch (e) {
// } // ifColorfalse
// catch (e) { item.ifColor = false
// } }
// } }
// data.LeftMidUp.Content = gridData console.log(data.value)
// } }
</script> </script>
<template> <template>
@ -72,23 +71,6 @@ onMounted(async () => {
<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>
<!-- <div class="enter-y w-full !mr-4 lg:w-7/10">
<StaticImg :loading="loading" :data="data.LeftUp" class="enter-y" />
</div> -->
<!-- <div class="enter-y w-full !mr-4 lg:w-7/10">
<ProjectCard :loading="loading" class="enter-y" />
<DynamicInfo :loading="loading" class="enter-y !my-4" />
</div>
<div class="enter-y w-full lg:w-3/10">
<QuickNav :loading="loading" class="enter-y" />
<Card class="enter-y !my-4" :loading="loading">
<img class="mx-auto h-30 xl:h-50" src="@/assets/svg/illustration.svg">
</Card>
<SaleRadar :loading="loading" class="enter-y" />
</div> -->
</div> </div>
</pagewrapper> </pagewrapper>
</template> </template>

Loading…
Cancel
Save