2024-11-04 14:42:27 +08:00
|
|
|
import useTimeStore from "@/utils/useTimeStore";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import { computed, reactive, ref, watch } from "vue";
|
2024-11-01 18:36:07 +08:00
|
|
|
|
2024-11-04 14:42:27 +08:00
|
|
|
|
|
|
|
const TOTAL_TIME = 60 * 60 * 15
|
2024-11-01 18:36:07 +08:00
|
|
|
export type TomatoTarget = {
|
2024-11-04 14:42:27 +08:00
|
|
|
id: string;
|
|
|
|
finishTime: number;
|
|
|
|
remindTime: number | null;
|
|
|
|
title: string;
|
|
|
|
isCompleted: boolean;
|
|
|
|
|
2024-11-01 18:36:07 +08:00
|
|
|
}
|
2024-11-03 22:34:59 +08:00
|
|
|
export type TomatoTime = {
|
2024-11-04 14:42:27 +08:00
|
|
|
date: number;
|
|
|
|
finishTime: number;
|
2024-11-03 22:34:59 +08:00
|
|
|
}
|
2024-11-04 14:02:48 +08:00
|
|
|
export const musicList = [
|
2024-11-04 14:42:27 +08:00
|
|
|
{
|
|
|
|
name: 'A Part of Us',
|
|
|
|
music: 'https://newfatfox.oss-cn-beijing.aliyuncs.com/admin/music/aPartOfUs.mp3'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'a signal rose',
|
|
|
|
music: 'https://newfatfox.oss-cn-beijing.aliyuncs.com/admin/music/AsignalRose.mp3'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'a thousand lifetimes',
|
|
|
|
music: 'https://newfatfox.oss-cn-beijing.aliyuncs.com/admin/music/aThousandLifetimes.mp3'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'A Very Brady Special',
|
|
|
|
music: 'https://newfatfox.oss-cn-beijing.aliyuncs.com/admin/music/AVeryBradySpecial.mp3'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'A Wonderful Story',
|
|
|
|
music: 'https://newfatfox.oss-cn-beijing.aliyuncs.com/admin/music/AWonderfulStore.mp3'
|
|
|
|
}
|
2024-11-04 14:02:48 +08:00
|
|
|
]
|
2024-11-04 14:42:27 +08:00
|
|
|
export default defineStore("work", () => {
|
|
|
|
const state = reactive({
|
|
|
|
list: [] as TomatoTarget[],
|
|
|
|
timeList: [] as TomatoTime[],
|
|
|
|
isPlaying: false as boolean,
|
|
|
|
selectMusic: 0,
|
|
|
|
isStart: false as boolean,
|
|
|
|
beginTime: -1 as number
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
const time = useTimeStore()
|
|
|
|
const beginTomatoTime = () => {
|
|
|
|
state.beginTime = dayjs().valueOf()
|
|
|
|
state.isStart = true
|
|
|
|
playMusic()
|
|
|
|
}
|
|
|
|
const stopTomatoTime = () => {
|
|
|
|
state.isStart = false
|
|
|
|
state.beginTime = -1
|
|
|
|
stopMusic()
|
|
|
|
}
|
|
|
|
const remainingTime = computed(() => {
|
|
|
|
const totalTime = TOTAL_TIME
|
|
|
|
|
|
|
|
return dayjs(state.beginTime).add(15, 'minute').diff(dayjs(time.date), 'second')
|
|
|
|
})
|
|
|
|
const playAudio = computed(() => {
|
|
|
|
const audio = new Audio(musicList[state.selectMusic].music)
|
|
|
|
return audio
|
|
|
|
})
|
|
|
|
watch(() => remainingTime, (val) => {
|
|
|
|
if (val.value < 0) {
|
|
|
|
state.isPlaying = false
|
|
|
|
state.isStart = false
|
|
|
|
state.beginTime = -1
|
|
|
|
state.timeList.push({
|
|
|
|
date: dayjs().valueOf(),
|
|
|
|
finishTime: TOTAL_TIME
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// watch(() => state.isPlaying, (val) => {
|
|
|
|
// if (val) {
|
|
|
|
// playAudio.value.play()
|
|
|
|
// } else {
|
|
|
|
// playAudio.value.pause()
|
|
|
|
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
const playMusic = () => {
|
|
|
|
state.isPlaying = true
|
|
|
|
playAudio.value.play()
|
|
|
|
}
|
|
|
|
|
|
|
|
const pauseMusic = () => {
|
|
|
|
state.isPlaying = false
|
|
|
|
playAudio.value.pause()
|
|
|
|
}
|
|
|
|
const stopMusic = () => {
|
|
|
|
state.isPlaying = false
|
|
|
|
playAudio.value.pause()
|
|
|
|
playAudio.value.currentTime = 0
|
|
|
|
}
|
|
|
|
const openShowModel = ref<undefined | null | TomatoTarget>()
|
|
|
|
const openFullscreen = ref(false)
|
|
|
|
return {
|
|
|
|
state,
|
|
|
|
openShowModel,
|
|
|
|
openFullscreen,
|
|
|
|
beginTomatoTime,
|
|
|
|
remainingTime,
|
|
|
|
playMusic,
|
|
|
|
pauseMusic,
|
|
|
|
stopMusic,
|
|
|
|
stopTomatoTime
|
|
|
|
}
|
|
|
|
})
|