update:大屏调整

This commit is contained in:
zk
2024-01-22 15:49:00 +08:00
parent 84dfa935ea
commit 5cf32ce40e
16 changed files with 298 additions and 138 deletions
@@ -12,10 +12,13 @@
<script setup lang="ts">
import PublicTitle from '/@/components/publicTitle.vue';
import * as echarts from 'echarts';
import { ref, onMounted, watch } from 'vue';
import { ref, watch } from 'vue';
import { formatStr, sleepCharts } from '/@/components/secondaryScreen/screen-right/screenRightHooks';
import { getSleep } from '/@/components/secondaryScreen/commonApi.ts';
import { useSession, caching } from '/@/hooks/autoRefresh/caching.ts';
const { setSession, getSession } = useSession();
const { PAGE2_RIGHT1 } = caching;
const props = defineProps({
orgCode: String,
type: String,
@@ -26,7 +29,7 @@
() => {
init();
},
{ immediate: true }
{ immediate: true, deep: true }
);
const nums = ref({
avgShort: '',
@@ -35,30 +38,40 @@
});
async function init() {
const params = {
orgCode: props.orgCode,
type: props.type,
};
const { code, result } = await getSleep(params);
if (code == 200 && result.length > 0) {
let time = result?.map((item) => item.dataDate);
let short = result?.map((item) => item.avgShortDuration);
let long = result?.map((item) => item.avgLongDuration);
let awake = result?.map((item) => item.awakeDuration);
let avg = result?.map((item) => item.averageDuration);
initChart({ time, short, long, awake, type: props.type });
const len = time.length;
if (!len > 0) {
return;
}
nums.value = {
avgShort: formatStr({ list: short, len }),
avgLong: formatStr({ list: long, len }),
avg: formatStr({ list: avg, len }), //平均
try {
const params = {
orgCode: props.orgCode,
type: props.type,
};
const { code, result } = await getSleep(params);
if (code == 200 && result.length > 0) {
setSession(PAGE2_RIGHT1, JSON.stringify(result));
setValue(result);
}
} catch {
const result = JSON.parse(getSession(PAGE2_RIGHT1));
setValue(result);
}
}
function setValue(result) {
let time = result?.map((item) => item.dataDate);
let short = result?.map((item) => item.avgShortDuration);
let long = result?.map((item) => item.avgLongDuration);
let awake = result?.map((item) => item.awakeDuration);
let avg = result?.map((item) => item.averageDuration);
initChart({ time, short, long, awake, type: props.type });
const len = time.length;
if (!len > 0) {
return;
}
nums.value = {
avgShort: formatStr({ list: short, len }),
avgLong: formatStr({ list: long, len }),
avg: formatStr({ list: avg, len }), //平均
};
}
function initChart({ time, short, long, awake, type }) {
let myChart = echarts.init(sleepChart.value);
let options = sleepCharts({ time, short, long, awake, type });