From 6307b5bba7a5aa3063f85b0836e8a88e75eac850 Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Mon, 8 Apr 2024 10:09:29 +0800 Subject: [PATCH] move isoModal to vue component --- _layouts/index.html | 41 ---------------- _src/components/IsoModal.vue | 90 ++++++++++++++++++++++++++++++++++++ _src/entrypoints/app.js | 11 +++++ static/js/index.es6 | 48 +------------------ 4 files changed, 102 insertions(+), 88 deletions(-) create mode 100644 _src/components/IsoModal.vue diff --git a/_layouts/index.html b/_layouts/index.html index 7bc0fe4..b4349e9 100644 --- a/_layouts/index.html +++ b/_layouts/index.html @@ -172,49 +172,8 @@ {% unless page.legacy or site.issue %} - {% raw %} - {% endraw %} {% endunless %} {% raw %} diff --git a/_src/components/IsoModal.vue b/_src/components/IsoModal.vue new file mode 100644 index 0000000..7e9ed67 --- /dev/null +++ b/_src/components/IsoModal.vue @@ -0,0 +1,90 @@ + + + diff --git a/_src/entrypoints/app.js b/_src/entrypoints/app.js index aa8ba46..a79bd1b 100644 --- a/_src/entrypoints/app.js +++ b/_src/entrypoints/app.js @@ -1,5 +1,16 @@ import Empty from '../components/Empty.vue' +import IsoModal from '../components/IsoModal.vue' import { createApp } from 'vue'; const empty = createApp(Empty); empty.mount("#upgrade-mask"); + +const isoModalEl = document.getElementById('isoModal'); + +createApp(IsoModal, { + onReady: async function() { + if (window.location.hash.match(/#iso-download(\?.*)?/)) { + new bootstrap.Modal(isoModalEl).show(); + } + }, +}).mount(isoModalEl); diff --git a/static/js/index.es6 b/static/js/index.es6 index 500bed4..c421168 100644 --- a/static/js/index.es6 +++ b/static/js/index.es6 @@ -195,53 +195,7 @@ const processMirrorItem = (d) => { [d.last_started, d.last_started_ago] = stringifyTime(d.last_started_ts); [d.next_schedule, d.next_schedule_ago] = stringifyTime(d.next_schedule_ts); return d; -} - -var vmIso = new Vue({ - el: "#isoModal", - data: { - distroList: [], - selected: {}, - curCategory: "", - knownCategories: { - os: "操作系统", - app: "应用软件", - font: "字体", - }, - availableCategories: [] - }, - created: function() { - var self = this; - fetch("/static/status/isoinfo.json").then((res)=>res.json()).then((isoinfo) => { - self.distroList = isoinfo; - self.availableCategories = [... new Set(isoinfo.map((x) => x.category))] - self.curCategory = self.availableCategories[0]; - self.selected = self.curDistroList[0]; - if (window.location.hash.match(/#iso-download(\?.*)?/)) { - new bootstrap.Modal(document.getElementById('isoModal')).show(); - } - }); - }, - computed: { - curDistroList() { - return this.distroList - .filter((x) => x.category === this.curCategory) - .sort(function (a, b) { - return a.distro.localeCompare(b.distro); - }); - }, - }, - methods: { - switchDistro (distro) { - this.selected = distro; - }, - switchCategory (category) { - this.curCategory = category; - this.selected = this.curDistroList[0]; - } - } -}); - +}; }); // vim: ts=2 sts=2 sw=2 noexpandtab