Skip to content

Commit 1abfee0

Browse files
Fix error when isoinfo contains no os distros
Fixes: tuna#399 Signed-off-by: Miao Wang <[email protected]>
1 parent 4583973 commit 1abfee0

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

_layouts/index.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ <h4> {% fa_svg fas.fa-paperclip %} 友情链接 </h4>
181181
<h4 class="modal-title" id="isoModalLabel">获取安装镜像</h4>
182182
</div>
183183
<div class="modal-body">
184-
<div class="row">
184+
<div class="row" v-if="availableCategories.length > 0">
185185
<div class="col-md-12">
186186
<ul class="nav nav-tabs">
187-
<li role="presentation" :class="[curCategory === 'os' ? 'active' : '']" @click="switchCategory('os')" v-show="showCategory('os')"><a href="#">操作系统</a></li>
188-
<li role="presentation" :class="[curCategory === 'app' ? 'active' : '']" @click="switchCategory('app')" v-show="showCategory('app')"><a href="#">应用软件</a></li>
189-
<li role="presentation" :class="[curCategory === 'font' ? 'active' : '']" @click="switchCategory('font')" v-show="showCategory('font')"><a href="#">字体</a></li>
187+
<li role="presentation"
188+
v-for="cat in availableCategories"
189+
:class="[curCategory === cat ? 'active' : '']"
190+
@click="switchCategory(cat)"
191+
>
192+
<a href="#">{{ knownCategories[cat] ? knownCategories[cat] : cat }}</a>
193+
</li>
190194
</ul>
191195
</div>
192196
<div class="col-md-3">

static/js/index.es6

+9-5
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,20 @@ var vmIso = new Vue({
189189
data: {
190190
distroList: [],
191191
selected: {},
192-
curCategory: "os"
192+
curCategory: "",
193+
knownCategories: {
194+
os: "操作系统",
195+
app: "应用软件",
196+
font: "字体",
197+
},
198+
availableCategories: []
193199
},
194200
created: function () {
195201
var self = this;
196202
$.getJSON("/static/status/isoinfo.json", function (isoinfo) {
197203
self.distroList = isoinfo;
204+
self.availableCategories = [... new Set(isoinfo.map((x) => x.category))]
205+
self.curCategory = self.availableCategories[0];
198206
self.selected = self.curDistroList[0];
199207
if (window.location.hash.match(/#iso-download(\?.*)?/)) {
200208
$('#isoModal').modal();
@@ -211,10 +219,6 @@ var vmIso = new Vue({
211219
},
212220
},
213221
methods: {
214-
showCategory(category) {
215-
return this.distroList
216-
.findIndex((x) => x.category === category) > -1;
217-
},
218222
switchDistro (distro) {
219223
this.selected = distro;
220224
},

0 commit comments

Comments
 (0)