Commit b8e226dc authored by liziwl's avatar liziwl
Browse files

格式化和重构代码

parent fa9ae867
import { defineClientAppEnhance } from '@vuepress/client'
import {defineClientAppEnhance} from '@vuepress/client'
import BusTimer from "./components/BusTimer.vue";
import ObjectSelector from "./components/ObjectSelector.vue";
import DataRequest from "./components/DataRequest.vue";
import GridList from "./components/GridList.vue";
import BusTable from "./components/BusTable.vue";
// import BusTimer from "./components/BusTimer.vue";
// import ObjectSelector from "./components/ObjectSelector.vue";
// import DataRequest from "./components/DataRequest.vue";
// import GridList from "./components/GridList.vue";
import Realtimemap from './components/Realtime-map.vue'
import WeatherSpan from './components/weather-span.vue'
// import AdsenseUnit from './components/adsense-inline-article.vue'
export default defineClientAppEnhance(({ app, router, siteData }) => {
app.component("BusTimer", BusTimer)
app.component("ObjectSelector", ObjectSelector)
app.component("DataRequest", DataRequest)
app.component("GridList", GridList)
})
\ No newline at end of file
export default defineClientAppEnhance(({app, router, siteData}) => {
app.component("BusTable", BusTable)
app.component("Realtimemap", Realtimemap)
app.component("WeatherSpan", WeatherSpan)
// app.component("AdsenseUnit", AdsenseUnit)
})
<template>
<div id="bustable">
<object-selector :objs="{
'工作日 Workday': true,
'节假日 Holiday': false
}" v-slot="weekdayProps">
<br/>
<object-selector :objs="weekdayProps.selected ? {
'Line 1 号线 │ 工学院方向 To COE': '/bus_times/one_down.json',
'Line 1 号线 │ 欣园方向 To Joy Highland': '/bus_times/one_up.json',
'Line 2 号线 │ 科研楼方向 To Research Building': '/bus_times/two_down.json',
'Line 2 号线 │ 欣园方向 To Joy Highland': '/bus_times/two_up.json',
} : {
'Line 1 号线 │ 工学院方向 To COE': '/bus_times/one_down_holiday.json',
'Line 1 号线 │ 欣园方向 To Joy Highland': '/bus_times/one_up_holiday.json'
}" v-slot="routeProps">
<data-request :path="routeProps.selected" v-slot="{ data }">
<bus-timer v-if="data" v-bind="data"></bus-timer>
<grid-list v-if="data" :data="data.times">
</grid-list>
</data-request>
</object-selector>
</object-selector>
</div>
</template>
<script>
import axios from "axios";
import BusTimer from "./BusTimer.vue";
import ObjectSelector from "./ObjectSelector.vue";
import DataRequest from "./DataRequest.vue";
import GridList from "./GridList.vue";
export default {
name: "BusTable",
components: {
BusTimer,
ObjectSelector,
DataRequest,
GridList
},
mounted() {
function bus_redirect(holidata) {
// JSON is from https://github.com/NateScarlet/holiday-cn
// need to update by year.
// Download the JSON to path "docs/.vuepress/public/YYYY.json"
var day_map = {};
for (let i = 0; i < holidata.days.length; i++) {
day_map[holidata.days[i].date] = holidata.days[i].isOffDay;
}
var now_date = new Date();
var ye = new Intl.DateTimeFormat('en', {year: 'numeric'}).format(now_date);
var mo = new Intl.DateTimeFormat('en', {month: '2-digit'}).format(now_date);
var da = new Intl.DateTimeFormat('en', {day: '2-digit'}).format(now_date);
var day_key = `${ye}-${mo}-${da}`;
var is_holiday;
if (day_map[day_key] == null) {
// 不在国家假日调整表里
console.log("Not in GOV declaration");
var day_in_week = now_date.getDay();
var isWeekend = (day_in_week == 6) || (day_in_week == 0);
// 6 = Saturday, 0 = Sunday
is_holiday = isWeekend;
} else {
console.log("In GOV declaration");
is_holiday = day_map[day_key];
}
if (is_holiday) {
console.log("节假日");
const bus_div = document.getElementById("bustable");
const this_day_btn = bus_div.getElementsByTagName("button")[1];
this_day_btn.click();
} else {
console.log("工作日");
const bus_div = document.getElementById("bustable");
const this_day_btn = bus_div.getElementsByTagName("button")[0];
this_day_btn.click();
}
}
axios
.get("/2022.json")
.then(response => {
bus_redirect(response.data);
});
},
}
</script>
<style scoped>
</style>
<template>
<button
v-for="(value, key, index) in objs"
:key="index"
@click="select(key)"
:class="key==keySelected? 'selected' : 'unselected'"
v-for="(value, key, index) in objs"
:key="index"
@click="select(key)"
:class="key==keySelected? 'selected' : 'unselected'"
>
{{ key }}
</button>
......@@ -18,9 +18,14 @@ export default {
},
props: {
objs: {},
initPos: {
type: Number,
default: 0
}
},
mounted() {
this.keySelected = Object.keys(this.objs)[0]
// console.log("pos", this.initPos);
this.select(Object.keys(this.objs)[this.initPos])
},
watch: {
objs(val) {
......@@ -50,12 +55,14 @@ button {
border-radius: 2px;
border: 1px solid rgb(194, 194, 194);
}
.selected{
.selected {
border-color: rgb(64, 169, 255);
background-color: rgb(64, 169, 255);
color:white;
color: white;
}
.unselected{
.unselected {
color: #000;
}
</style>
\ No newline at end of file
</style>
......@@ -578,7 +578,7 @@ export default {
});
this.fetch_bus()
await this.fetch_bus();
//refresh timer
......@@ -603,4 +603,4 @@ export default {
width: 100%;
}
</style>
\ No newline at end of file
</style>
......@@ -3,175 +3,175 @@ let title = '南科手册'
let description = 'Online manual for sustecher'
let color = '#49BF7C'
let author = 'sustech.online'
const { path } = require('@vuepress/utils')
// const {path} = require('@vuepress/utils')
module.exports = {
locales: {
'/': {
title: '南科手册',
lang: 'zh-CN',
description: 'Online manual for sustecher',
}
},
head: [
['link', { rel: 'icon', href: `/logo-assets/touch/homescreen192.png` }],
['meta', { name: 'theme-color', content: color }],
['link', { rel: 'manifest', href: '/manifest.json' }],
['meta', { prefix: ogprefix, property: 'og:type', content: 'article' }],
['meta', { prefix: ogprefix, property: 'og:image', content: 'https://mirrors.sustech.edu.cn/git/sustech-online/sustech-online-ng/-/raw/master/docs/assets/og-image.png' }],
['meta', { prefix: ogprefix, property: 'og:article:author', content: author }],
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
['link', { rel: 'apple-touch-icon', href: '/logo-assets/touch/homescreen168.png' }],
['meta', { name: 'msapplication-TileImage', content: '/logo-assets/touch/homescreen144.png' }],
['meta', { name: 'msapplication-TileColor', content: color }],
['meta', { name: 'google-site-verification', content: 'Av-srANCmFA_yZ8Iasa1yQsIPJCF_zlP5AoD35m6_Ww' }],
['script', {
async: true,
src: 'https://www.googletagmanager.com/gtag/js?id=G-1BQBXDGY3R'
}],
['script', {}, `
locales: {
'/': {
title: '南科手册',
lang: 'zh-CN',
description: 'Online manual for sustecher',
}
},
head: [
['link', {rel: 'icon', href: `/logo-assets/touch/homescreen192.png`}],
['meta', {name: 'theme-color', content: color}],
['link', {rel: 'manifest', href: '/manifest.json'}],
['meta', {prefix: ogprefix, property: 'og:type', content: 'article'}],
['meta', {
prefix: ogprefix,
property: 'og:image',
content: 'https://mirrors.sustech.edu.cn/git/sustech-online/sustech-online-ng/-/raw/master/docs/assets/og-image.png'
}],
['meta', {prefix: ogprefix, property: 'og:article:author', content: author}],
['meta', {name: 'apple-mobile-web-app-capable', content: 'yes'}],
['meta', {name: 'apple-mobile-web-app-status-bar-style', content: 'black'}],
['link', {rel: 'apple-touch-icon', href: '/logo-assets/touch/homescreen168.png'}],
['meta', {name: 'msapplication-TileImage', content: '/logo-assets/touch/homescreen144.png'}],
['meta', {name: 'msapplication-TileColor', content: color}],
['meta', {name: 'google-site-verification', content: 'Av-srANCmFA_yZ8Iasa1yQsIPJCF_zlP5AoD35m6_Ww'}],
['script', {
async: true,
src: 'https://www.googletagmanager.com/gtag/js?id=G-1BQBXDGY3R'
}],
['script', {}, `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-1BQBXDGY3R');
`],
['script', { src: '/wx_helper.js' }],
['script', { src: 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js' }],
['script', { src: 'https://lib.baomitu.com/jquery/3.6.0/jquery.min.js' }],
['script', { src: 'https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js' }],
['link', { rel: 'stylesheet', type: 'text/css', href: 'https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css' }],
['script', { src: 'https://lib.baomitu.com/datatables/1.10.21/js/jquery.dataTables.min.js' }],
['link', { rel: 'stylesheet', type: 'text/css', href: 'https://lib.baomitu.com/datatables/1.10.21/css/jquery.dataTables.min.css' }]
],
plugins: [
// [
// '@vuepress/plugin-search',
// {
// locales: {
// '/': {
// placeholder: 'Search',
// },
// '/zh/': {
// placeholder: '搜索',
// },
// },
// },
// ],
[
'@vuepress/plugin-docsearch',
{
apiKey: '03fed04db0cb1570c99f89739e745ed6',
indexName: 'sustech',
locales: {
'/': {
placeholder: '搜索手册',
},
},
},
],
[
'@vuepress/plugin-google-analytics',
{
id: 'G-1BQBXDGY3R',
},
],
'@vuepress/medium-zoom',
[
'@vuepress/plugin-pwa',
{
maximumFileSizeToCacheInBytes: 524288, // 限制到0.5MB
skipWaiting: true
},
{
generateSWConfig: {
importWorkboxFrom: 'local'
}
}
],
[
'@vuepress/plugin-pwa-popup',
{
locales: {
'/': {
message: '发现新内容可用',
buttonText: '刷新',
},
},
},
['script', {src: '/wx_helper.js'}],
['script', {src: 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'}],
['script', {src: 'https://lib.baomitu.com/jquery/3.6.0/jquery.min.js'}],
['script', {src: 'https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js'}],
['link', {
rel: 'stylesheet',
type: 'text/css',
href: 'https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css'
}],
['script', {src: 'https://lib.baomitu.com/datatables/1.10.21/js/jquery.dataTables.min.js'}],
['link', {
rel: 'stylesheet',
type: 'text/css',
href: 'https://lib.baomitu.com/datatables/1.10.21/css/jquery.dataTables.min.css'
}]
],
'@vuepress/plugin-nprogress',
'@vuepress/back-to-top',
'@vuepress/plugin-git',
'@vuepress/plugin-toc',
[
'@vuepress/register-components',
{
components: {
Realtimemap: path.resolve(__dirname, './components/Realtime-map.vue'),
WeatherSpan: path.resolve(__dirname, './components/weather-span.vue'),
// Adsense_unit: path.resolve(__dirname, './components/adsense-inline-article.vue'),
// componentsDir: path.resolve(__dirname, './components')
},
},
]
],
themeConfig: {
navbar: [
{ text: '主页', link: '/' },
{ text: '快讯网', link: 'https://daily.sustech.online/' },
{ text: '小程序', link: '/miniapp/' },
{ text: '关于', link: '/about/' },
{ text: '站点帮助', link: '/site-help/' },
plugins: [
// [
// '@vuepress/plugin-search',
// {
// locales: {
// '/': {
// placeholder: 'Search',
// },
// '/zh/': {
// placeholder: '搜索',
// },
// },
// },
// ],
[
'@vuepress/plugin-docsearch',
{
apiKey: '03fed04db0cb1570c99f89739e745ed6',
indexName: 'sustech',
locales: {
'/': {
placeholder: '搜索手册',
},
},
},
],
[
'@vuepress/plugin-google-analytics',
{
id: 'G-1BQBXDGY3R',
},
],
'@vuepress/medium-zoom',
[
'@vuepress/plugin-pwa',
{
maximumFileSizeToCacheInBytes: 524288, // 限制到0.5MB
skipWaiting: true
},
{
generateSWConfig: {
importWorkboxFrom: 'local'
}
}
],
[
'@vuepress/plugin-pwa-popup',
{
locales: {
'/': {
message: '发现新内容可用',
buttonText: '刷新',
},
},
},
],
'@vuepress/plugin-nprogress',
'@vuepress/back-to-top',
'@vuepress/plugin-git',
'@vuepress/plugin-toc',
],
repo: 'sustech-cra/sustech-online-ng',
docsRepo: 'sustech-cra/sustech-online-ng',
editLinkText: '一起完善这本手册!',
docsDir: 'docs',
repoLabel: '在Github上查看',
editLinks: true,
docsBranch: 'master',
smoothScroll: true,
sidebarDepth: 2,
sidebar: [
'/',
'/facility/',
'/contact/',
'/calendar/',
'/service/',
'/life/',
'/study/',
'/organizations/',
'/media/',
{
text: '🚄交通',
link: '/transport/',
children: [
// SidebarItem
{
text: '🚌新版巴士时刻表',
link: '/transport/bustimer.md',
children: [],
},
{
text: '🚌校园巴士-工作日',
link: '/transport/workday.md',
children: [],
},
{
text: '🚌校园巴士-节假日',
link: '/transport/holiday.md',
children: [],
},
{
text: '周围交通',
link: '/transport/',
children: [],
},
themeConfig: {
navbar: [
{text: '主页', link: '/'},
{text: '快讯网', link: 'https://daily.sustech.online/'},
{text: '小程序', link: '/miniapp/'},
{text: '关于', link: '/about/'},
{text: '站点帮助', link: '/site-help/'},
],
},
'/surroundings/',
]
}
repo: 'sustech-cra/sustech-online-ng',
docsRepo: 'sustech-cra/sustech-online-ng',
editLinkText: '一起完善这本手册!',
docsDir: 'docs',
repoLabel: '在Github上查看',
editLinks: true,
docsBranch: 'master',
smoothScroll: true,
sidebarDepth: 2,
sidebar: [
'/',
'/facility/',
'/contact/',
'/calendar/',
'/service/',
'/life/',
'/study/',
'/organizations/',
'/media/',
{
text: '🚄交通',
link: '/transport/',
children: [
// SidebarItem
{
text: '🚌新版巴士时刻表',
link: '/transport/bustimer.md',
children: [],
},
{
text: '🚌校园巴士-工作日',
link: '/transport/workday.md',
children: [],
},
{
text: '🚌校园巴士-节假日',
link: '/transport/holiday.md',
children: [],
},
{
text: '周围交通',
link: '/transport/',
children: [],
},
],
},
'/surroundings/',
]
}
}
......@@ -16,74 +16,4 @@ navbar: false
## 时间表 Timetable
<script>
import axios from "axios";
export default {
mounted() {
axios
.get("/2022.json")
.then(response => (bus_redirect(response.data)));
function bus_redirect(holidata) {
// JSON is from https://github.com/NateScarlet/holiday-cn
// need to update by year.
// Download the JSON to path "docs/.vuepress/public/YYYY.json"
var day_map = {};
for (let i = 0; i < holidata.days.length; i++) {
day_map[holidata.days[i].date] = holidata.days[i].isOffDay;
}
var now_date = new Date();
var ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(now_date);
var mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(now_date);
var da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(now_date);
var day_key = `${ye}-${mo}-${da}`;
var is_holiday;
if (day_map[day_key] == null) {
// 不在国家假日调整表里
console.log("Not in GOV declaration");
var day_in_week = now_date.getDay();
var isWeekend = (day_in_week == 6) || (day_in_week == 0);
// 6 = Saturday, 0 = Sunday
is_holiday = isWeekend;
} else {
console.log("In GOV declaration");
is_holiday = day_map[day_key];
}
if (is_holiday) {
console.log("节假日");
var bus_div = document.getElementById("bustable");
var this_day_btn = bus_div.getElementsByTagName("button")[1];
this_day_btn.click();
} else {
console.log("工作日");
var bus_div = document.getElementById("bustable");
var this_day_btn = bus_div.getElementsByTagName("button")[0];
this_day_btn.click();
}
}
},
}
</script>
<div id="bustable">
<object-selector :objs="{
'工作日 Workday': true,
'节假日 Holiday': false
}" v-slot="weekdayProps">
<br />
<object-selector :objs="weekdayProps.selected ? {
'Line 1 号线 │ 工学院方向 To COE': '/bus_times/one_down.json',
'Line 1 号线 │ 欣园方向 To Joy Highland': '/bus_times/one_up.json',
'Line 2 号线 │ 科研楼方向 To Research Building': '/bus_times/two_down.json',
'Line 2 号线 │ 欣园方向 To Joy Highland': '/bus_times/two_up.json',
} : {
'Line 1 号线 │ 工学院方向 To COE': '/bus_times/one_down_holiday.json',
'Line 1 号线 │ 欣园方向 To Joy Highland': '/bus_times/one_up_holiday.json'
}" v-slot="routeProps">
<data-request :path="routeProps.selected" v-slot="{ data }">
<bus-timer v-if="data" v-bind="data"></bus-timer>
<grid-list v-if="data" :data="data.times">
</grid-list>
</data-request>
</object-selector>
</object-selector>
</div>
<BusTable></BusTable>
......@@ -12,76 +12,4 @@
## 时间表 Timetable
<script>