Commit b8e226dc authored by liziwl's avatar liziwl
Browse files

格式化和重构代码

parent fa9ae867
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
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)
    app.component("BusTable", BusTable)
    app.component("Realtimemap", Realtimemap)
    app.component("WeatherSpan", WeatherSpan)
    // app.component("AdsenseUnit", AdsenseUnit)
})
+92 −0
Original line number Diff line number Diff line
<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>
+16 −9
Original line number Diff line number Diff line
@@ -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,11 +55,13 @@ button {
  border-radius: 2px;
  border: 1px solid rgb(194, 194, 194);
}

.selected {
  border-color: rgb(64, 169, 255);
  background-color: rgb(64, 169, 255);
  color: white;
}

.unselected {
  color: #000;
}
+2 −2
Original line number Diff line number Diff line
@@ -578,7 +578,7 @@ export default {
    });


    this.fetch_bus()
    await this.fetch_bus();

    //refresh timer

+161 −161
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ 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: {
@@ -18,7 +18,11 @@ module.exports = {
        ['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: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'}],
@@ -40,9 +44,17 @@ module.exports = {
        ['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' }],
        ['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' }]
        ['link', {
            rel: 'stylesheet',
            type: 'text/css',
            href: 'https://lib.baomitu.com/datatables/1.10.21/css/jquery.dataTables.min.css'
        }]
    ],
    plugins: [
        // [
@@ -104,18 +116,6 @@ module.exports = {
        '@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: [
Loading