Optimize code, rebase api path, fix typo
This commit is contained in:
parent
16917a088f
commit
d101d81763
13 changed files with 111 additions and 100 deletions
|
|
@ -1,37 +1,44 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let content = ""
|
||||
let exams:Exam[] = []
|
||||
let res = await fetch("/api/content?page=competitive")
|
||||
if(res.ok){
|
||||
content = (await res.json()).content
|
||||
}
|
||||
|
||||
res = await fetch("/api/competitive")
|
||||
if(!res.ok){
|
||||
const res = await fetch(apibase+"/competitive")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
}
|
||||
exams = await res.json()
|
||||
|
||||
|
||||
const events:CalendarEvent[]=[]
|
||||
exams.forEach((e)=>{
|
||||
if(!e.start){
|
||||
e.date=""
|
||||
return
|
||||
exams.forEach((ex)=>{
|
||||
const {id,title,start,end,category_id} = ex
|
||||
let backgroundColor ="#23ccef"
|
||||
switch (String(category_id)) {
|
||||
case "1":
|
||||
backgroundColor="rgba(251,64,75,.2)"
|
||||
break;
|
||||
case "2":
|
||||
backgroundColor="#23ccef"
|
||||
break;
|
||||
case "3":
|
||||
backgroundColor="rgba(68,125,247,.2)"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
e.date= dayjs(e.start).format("DD MMM BBBB")
|
||||
|
||||
const {id,title,start,category_id} = e
|
||||
|
||||
let backgroundColor ="rgb(153 153 255 / 34%)"
|
||||
if(category_id)
|
||||
backgroundColor ="#99FFEE"
|
||||
|
||||
const url = "/competitive/"+id
|
||||
events.push({id,title,start,url,backgroundColor})
|
||||
if(start){
|
||||
ex.date = dayjs(start).format("DD MMM BBBB")
|
||||
events.push({id,title,start,end,url,backgroundColor})
|
||||
}
|
||||
if(ex.exam_date){
|
||||
events.push({id,"title":"วันสอบแข่งขัน","start":ex.exam_date,url,backgroundColor})
|
||||
}
|
||||
if(ex.announcement_date){
|
||||
events.push({id,"title":"ผลสอบแข่งขัน","start":ex.announcement_date,url,backgroundColor})
|
||||
}
|
||||
})
|
||||
return {content,exams,events}
|
||||
}
|
||||
return {exams,events}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
import ActivityCalendar from '$lib/components/ActivityCalendar.svelte'
|
||||
import type { PageData } from './$types'
|
||||
export let data: PageData;
|
||||
const exams = data.exams
|
||||
const events = data.events
|
||||
const {exams,events} = data
|
||||
</script>
|
||||
<section>
|
||||
<div class="p-one parallax-inner">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
const res = await fetch("/api/competitive/"+id)
|
||||
const res = await fetch(apibase+"/competitive/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue