控制左边自动播放
parent
2aad2576cb
commit
f683498946
|
|
@ -27,6 +27,8 @@ export const LOCK_INFO_KEY = 'LOCK__INFO__KEY__'
|
||||||
|
|
||||||
export const YEAR_KEY = 'YEAR_KEY__'
|
export const YEAR_KEY = 'YEAR_KEY__'
|
||||||
|
|
||||||
|
export const PLAY_KEY = 'PLAY_KEY__'
|
||||||
|
|
||||||
export const INIT_TIME = 'INIT_TIME_'
|
export const INIT_TIME = 'INIT_TIME_'
|
||||||
|
|
||||||
export enum CacheTypeEnum {
|
export enum CacheTypeEnum {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
import { YEAR_KEY } from '/@/enums/cacheEnum'
|
import { YEAR_KEY, PLAY_KEY } from '/@/enums/cacheEnum'
|
||||||
|
|
||||||
interface VisualizationState {
|
interface VisualizationState {
|
||||||
year: number
|
year: number
|
||||||
addressId?: number | null
|
addressId?: number | null
|
||||||
|
play: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useVisualizationStore = defineStore({
|
export const useVisualizationStore = defineStore({
|
||||||
id: 'app-visualization',
|
id: 'app-visualization',
|
||||||
state: (): VisualizationState => ({
|
state: (): VisualizationState => ({
|
||||||
year: Number(localStorage.getItem(YEAR_KEY)) || new Date().getFullYear() - 1,
|
year: Number(localStorage.getItem(YEAR_KEY)) || new Date().getFullYear() - 1,
|
||||||
addressId: null,
|
addressId: null,
|
||||||
|
play: localStorage.getItem(PLAY_KEY) === 'true' ? true : false,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getYear(): number {
|
getYear(): number {
|
||||||
|
|
@ -20,6 +21,9 @@ export const useVisualizationStore = defineStore({
|
||||||
getAddresId(): number | null {
|
getAddresId(): number | null {
|
||||||
return this?.addressId ?? null
|
return this?.addressId ?? null
|
||||||
},
|
},
|
||||||
|
getPlay(): boolean {
|
||||||
|
return this.play
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setAddressId(id: number | null) {
|
setAddressId(id: number | null) {
|
||||||
|
|
@ -29,6 +33,10 @@ export const useVisualizationStore = defineStore({
|
||||||
this.year = year
|
this.year = year
|
||||||
localStorage.setItem(YEAR_KEY, String(year))
|
localStorage.setItem(YEAR_KEY, String(year))
|
||||||
},
|
},
|
||||||
|
setPlay(play: boolean) {
|
||||||
|
this.play = play
|
||||||
|
localStorage.setItem(PLAY_KEY, String(play))
|
||||||
|
},
|
||||||
plus() {
|
plus() {
|
||||||
this.setYear(this.year + 1)
|
this.setYear(this.year + 1)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,9 @@
|
||||||
series: obj.series,
|
series: obj.series,
|
||||||
})
|
})
|
||||||
|
|
||||||
chartAmi()
|
if (visualizationStore.getPlay) {
|
||||||
|
chartAmi()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer: any = null
|
let timer: any = null
|
||||||
|
|
@ -233,6 +235,14 @@
|
||||||
() => getData(),
|
() => getData(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => visualizationStore.getPlay,
|
||||||
|
() => {
|
||||||
|
timer && clearInterval(timer)
|
||||||
|
getData()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isChart,
|
isChart,
|
||||||
changeChart,
|
changeChart,
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, reactive, ref, Ref, onBeforeMount, onBeforeUnmount } from 'vue'
|
import { defineComponent, reactive, ref, Ref, onBeforeMount, onBeforeUnmount, watch } from 'vue'
|
||||||
import Box from './Box.vue'
|
import Box from './Box.vue'
|
||||||
import { useECharts } from '/@/hooks/web/useECharts'
|
import { useECharts } from '/@/hooks/web/useECharts'
|
||||||
import { getRiceShrimpPrice } from '/@/api/sys/other'
|
import { getRiceShrimpPrice } from '/@/api/sys/other'
|
||||||
import { chartLineColors } from './colors'
|
import { chartLineColors } from './colors'
|
||||||
|
import { useVisualizationStore } from '/@/store/modules/visualization'
|
||||||
import { useVContext } from '../useVContext'
|
import { useVContext } from '../useVContext'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
Box,
|
Box,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
|
const visualizationStore = useVisualizationStore()
|
||||||
const { rootEmitter } = useVContext()
|
const { rootEmitter } = useVContext()
|
||||||
const tabList = reactive([
|
const tabList = reactive([
|
||||||
{
|
{
|
||||||
|
|
@ -151,7 +152,9 @@
|
||||||
series: obj.series,
|
series: obj.series,
|
||||||
animationDuration: 2000,
|
animationDuration: 2000,
|
||||||
})
|
})
|
||||||
chartAmi()
|
if (visualizationStore.getPlay) {
|
||||||
|
chartAmi()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let timer: any = null
|
let timer: any = null
|
||||||
|
|
||||||
|
|
@ -218,7 +221,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getData(init = true) {
|
async function getData(init = true) {
|
||||||
const resData = await getRiceShrimpPrice()
|
const resData = await getRiceShrimpPrice({
|
||||||
|
year: visualizationStore.getYear,
|
||||||
|
})
|
||||||
Data.x_axis = resData.x_axis
|
Data.x_axis = resData.x_axis
|
||||||
Data.series = resData.series
|
Data.series = resData.series
|
||||||
if (init) {
|
if (init) {
|
||||||
|
|
@ -240,6 +245,19 @@
|
||||||
timer && clearInterval(timer)
|
timer && clearInterval(timer)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => visualizationStore.getYear,
|
||||||
|
() => getData(),
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => visualizationStore.getPlay,
|
||||||
|
() => {
|
||||||
|
timer && clearInterval(timer)
|
||||||
|
getData()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tabList,
|
tabList,
|
||||||
currentTab,
|
currentTab,
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,9 @@
|
||||||
animationDuration: 2000,
|
animationDuration: 2000,
|
||||||
})
|
})
|
||||||
|
|
||||||
chartAmi()
|
if (visualizationStore.getPlay) {
|
||||||
|
chartAmi()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer: any = null
|
let timer: any = null
|
||||||
|
|
@ -216,6 +218,14 @@
|
||||||
() => getData(),
|
() => getData(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => visualizationStore.getPlay,
|
||||||
|
() => {
|
||||||
|
timer && clearInterval(timer)
|
||||||
|
getData()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chartRef,
|
chartRef,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,9 @@
|
||||||
series: obj.series,
|
series: obj.series,
|
||||||
})
|
})
|
||||||
|
|
||||||
chartAmi()
|
if (visualizationStore.getPlay) {
|
||||||
|
chartAmi()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer: any = null
|
let timer: any = null
|
||||||
|
|
@ -266,6 +268,14 @@
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => visualizationStore.getPlay,
|
||||||
|
() => {
|
||||||
|
timer && clearInterval(timer)
|
||||||
|
getData()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
getData()
|
getData()
|
||||||
rootEmitter.on('interval:auto', () => {
|
rootEmitter.on('interval:auto', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="text-4xl text-white flex items-center justify-center relative">
|
<div class="text-4xl text-white flex items-center justify-center relative">
|
||||||
<div
|
<div
|
||||||
class="absolute left-36px text-15px font-bold bg-clip-text text-transparent bg-gradient-to-t from-[#76E9F0] to-[#A7E6EE] flex items-center"
|
class="absolute left-20px text-15px font-bold bg-clip-text text-transparent bg-gradient-to-t from-[#76E9F0] to-[#A7E6EE] flex items-center"
|
||||||
>
|
>
|
||||||
|
<Tooltip placement="topLeft" title="自动播放">
|
||||||
|
<CaretRightOutlined
|
||||||
|
v-if="!play"
|
||||||
|
class="!text-white text-lg mr-4 opacity-80 cursor-pointer"
|
||||||
|
@click="setPlay"
|
||||||
|
/>
|
||||||
|
<PauseOutlined
|
||||||
|
v-else
|
||||||
|
class="!text-white text-lg mr-4 opacity-80 cursor-pointer"
|
||||||
|
@click="setPlay"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
v-model:value="value1"
|
v-model:value="value1"
|
||||||
picker="year"
|
picker="year"
|
||||||
|
|
@ -68,10 +80,15 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { DatePicker } from 'ant-design-vue'
|
import { DatePicker, Tooltip } from 'ant-design-vue'
|
||||||
import { reactive, computed, ref, onBeforeMount } from 'vue'
|
import { reactive, computed, ref, onBeforeMount } from 'vue'
|
||||||
import headTitleImg from '/@/assets/images/head-title.png'
|
import headTitleImg from '/@/assets/images/head-title.png'
|
||||||
import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons-vue'
|
import {
|
||||||
|
CaretUpOutlined,
|
||||||
|
CaretDownOutlined,
|
||||||
|
CaretRightOutlined,
|
||||||
|
PauseOutlined,
|
||||||
|
} from '@ant-design/icons-vue'
|
||||||
import dayjs, { Dayjs } from 'dayjs'
|
import dayjs, { Dayjs } from 'dayjs'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
|
@ -79,7 +96,8 @@
|
||||||
|
|
||||||
const visualizationStore = useVisualizationStore()
|
const visualizationStore = useVisualizationStore()
|
||||||
|
|
||||||
const year = computed(() => visualizationStore.getYear)
|
// const year = computed(() => visualizationStore.getYear)
|
||||||
|
const play = computed(() => visualizationStore.getPlay)
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
@ -90,6 +108,10 @@
|
||||||
value1.value = dayjs(visualizationStore.getYear + '', 'YYYY')
|
value1.value = dayjs(visualizationStore.getYear + '', 'YYYY')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function setPlay() {
|
||||||
|
visualizationStore.setPlay(!play.value)
|
||||||
|
}
|
||||||
|
|
||||||
function goHome() {
|
function goHome() {
|
||||||
router.push('/')
|
router.push('/')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue