Skip to content

Commit 023ad3f

Browse files
committed
映射数据库文件改为使用 js 提供
1 parent 99125c2 commit 023ad3f

File tree

6 files changed

+33
-52
lines changed

6 files changed

+33
-52
lines changed

tools/build_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def main():
8080

8181
db = _build_db()
8282

83-
file_path = www_data_dir.joinpath('db.json')
84-
file_path.write_text(json.dumps(db), 'utf-8')
83+
file_path = www_data_dir.joinpath('db.js')
84+
file_path.write_text(f'export default {json.dumps(db)}', 'utf-8')
8585
print(f"Build: '{file_path}'")
8686

8787

www/css/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ body {
88
font-family: sans-serif;
99
}
1010

11+
[v-cloak] {
12+
display: none;
13+
}
14+
1115
.nav {
1216
background-color: deepskyblue;
1317
box-shadow: 0 0 8px gray;

www/data/db.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/data/db.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

www/index.html

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,35 @@
99
</head>
1010
<body>
1111

12-
<div id="app">
12+
<div id="app" v-cloak>
1313
<nav class="nav">
1414
<h1 class="title">思源映射查看器</h1>
1515
</nav>
1616
<main class="main">
17-
<template v-if="dbLoadFailed">
18-
<div class="error-tip">映射数据加载失败,请刷新浏览器重试</div>
19-
</template>
20-
<template v-else-if="!db">
21-
<div class="loading-tip">正在加载映射数据,请稍后</div>
22-
</template>
23-
<template v-if="db">
24-
<label class="input">
25-
<input type="text" placeholder="请在此输入字符" v-model="input">
17+
<label class="input">
18+
<input type="text" placeholder="请在此输入字符" v-model="input">
19+
</label>
20+
<div class="option-line">
21+
<label class="checkbox">
22+
<input type="checkbox" v-model="displaySans">
23+
<span class="name">思源黑体</span>
2624
</label>
27-
<div class="option-line">
28-
<label class="checkbox">
29-
<input type="checkbox" v-model="displaySans">
30-
<span class="name">思源黑体</span>
31-
</label>
32-
<label class="checkbox">
33-
<input type="checkbox" v-model="displaySerif">
34-
<span class="name">思源宋体</span>
35-
</label>
36-
</div>
37-
<div class="option-line">
38-
<label class="range">
39-
<span class="name">字体尺寸: {{ fontSize }}px</span>
40-
<input type="range" min="100" max="400" step="10" v-model="fontSize">
41-
</label>
42-
<label class="range">
43-
<span class="name">字体粗细: {{ fontWeight }}</span>
44-
<input type="range" min="200" max="900" step="50" v-model="fontWeight">
45-
</label>
46-
<button @click="onResetOptionsClick">重置参数</button>
47-
</div>
48-
</template>
25+
<label class="checkbox">
26+
<input type="checkbox" v-model="displaySerif">
27+
<span class="name">思源宋体</span>
28+
</label>
29+
</div>
30+
<div class="option-line">
31+
<label class="range">
32+
<span class="name">字体尺寸: {{ fontSize }}px</span>
33+
<input type="range" min="100" max="400" step="10" v-model="fontSize">
34+
</label>
35+
<label class="range">
36+
<span class="name">字体粗细: {{ fontWeight }}</span>
37+
<input type="range" min="200" max="900" step="50" v-model="fontWeight">
38+
</label>
39+
<button @click="onResetOptionsClick">重置参数</button>
40+
</div>
4941
<div class="search-result">
5042
<div class="item" v-for="codePoint in searchQuery" :key="codePoint" :set="c = String.fromCodePoint(codePoint)">
5143
<div class="title">

www/js/app.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createApp } from './vue.esm-browser.prod.js'
2+
import db from '../data/db.js'
23

34
createApp({
45
data() {
@@ -10,8 +11,7 @@ createApp({
1011
'jp',
1112
'kr',
1213
],
13-
db: null,
14-
dbLoadFailed: false,
14+
db: db,
1515
input: '',
1616
displaySans: true,
1717
displaySerif: true,
@@ -50,21 +50,6 @@ createApp({
5050
},
5151
},
5252
async created() {
53-
try {
54-
const response = await fetch('data/db.json')
55-
if (response.ok) {
56-
const db = await response.json()
57-
console.log('加载映射:', db)
58-
this.db = db
59-
} else {
60-
this.dbLoadFailed = true
61-
return
62-
}
63-
} catch (e) {
64-
this.dbLoadFailed = true
65-
return
66-
}
67-
6853
const json = localStorage.getItem('source-han-mapping-viewer')
6954
if (json) {
7055
const settings = JSON.parse(json)

0 commit comments

Comments
 (0)