Запилил стор для расписания стримов

This commit is contained in:
Dhaverd 2024-04-20 01:08:18 +08:00
parent d128e6f90a
commit e04bc5ba98
4 changed files with 49 additions and 30 deletions

View File

@ -1,15 +1,37 @@
import {defineStore} from "pinia";
import axios from "axios";
export const useScheduleStore = defineStore('Schedule', {
state: () => ({
fetchingDates: true,
fetchingTable: true,
fetchingLinks: true
dates: Object,
links: Object,
schedules: Object
}),
getters: {
},
actions: {
async getDates(){
await axios
.get('/api/v1/dates')
.then((response) => {
this.dates = response.data;
});
},
async getLinks(){
await axios
.get('/api/v1/links')
.then((response)=>{
this.links = response.data;
})
},
async getSchedules(){
await axios
.get('/api/v1/schedules')
.then((response)=>{
this.schedules = response.data;
})
}
},
})

View File

@ -10,33 +10,30 @@
</template>
<script>
import axios from "axios";
import ScheduleTable from "./Schedule/ScheduleTable.vue";
import Links from "./Schedule/Links.vue";
import {ref} from "vue";
import {useScheduleStore} from '../stores/schedule.js';
export default {
name: "Schedule",
components: {Links, ScheduleTable},
data: () => ({
dates: [],
dates: ref(),
scheduleStore: useScheduleStore(),
fetching: true
}),
methods: {
parseDate(date){
let dateArr = date.split("-");
return dateArr[2] + "." + dateArr[1];
},
async getDates(){
await axios
.get('/api/v1/dates')
.then(response => {
this.dates = response.data;
this.fetching = false;
});
}
},
mounted() {
this.getDates();
this.scheduleStore.getDates().then(()=>{
this.dates = this.scheduleStore.dates;
this.fetching = false;
});
}
}
</script>

View File

@ -1,22 +1,22 @@
<script>
import axios from "axios";
import {ref} from "vue";
import {useScheduleStore} from '../../stores/schedule.js';
export default {
name: "Links",
data: () => ({
links: [],
links: ref(),
fetching: true,
scheduleStore: useScheduleStore(),
windowHeight: document.documentElement.clientHeight,
windowWidth: document.documentElement.clientWidth,
isWide: window.innerWidth >= 460
}),
mounted() {
axios
.get('/api/v1/links')
.then(response => {
this.links = response.data;
this.fetching = false;
});
this.scheduleStore.getLinks().then(()=>{
this.links = this.scheduleStore.links;
this.fetching = false;
});
this.myEventHandler();
window.addEventListener("resize", this.myEventHandler, { passive: true });
},

View File

@ -1,10 +1,12 @@
<script>
import axios from "axios";
import {useScheduleStore} from '../../stores/schedule.js';
import {ref} from "vue";
export default {
name: "ScheduleTable",
data: () => ({
schedules: [],
schedules: ref(),
scheduleStore: useScheduleStore(),
fetching: true
}),
methods: {
@ -14,12 +16,10 @@
}
},
mounted() {
axios
.get('/api/v1/schedules')
.then(response => {
this.schedules = response.data;
this.fetching = false;
});
this.scheduleStore.getSchedules().then(()=>{
this.schedules = this.scheduleStore.schedules;
this.fetching = false;
});
}
}
</script>