Skip to content

Commit 6f6b6b2

Browse files
committed
更新[BoxJs]: 增加版本判断
1 parent 0702232 commit 6f6b6b2

3 files changed

Lines changed: 99 additions & 3 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,25 +922,52 @@ <h2>{{curbak.name}}</h2>
922922
<v-avatar><img :src="box.syscfgs.boxjs.icons[iconThemeIdx]" /></v-avatar>
923923
</v-btn>
924924
</template>
925-
<v-btn dark v-if="!box.usercfgs.isHideHelp" fab small color="grey" @click="">
925+
<v-btn dark v-if="!box.usercfgs.isHideHelp" fab small color="grey" @click="ui.versionsheet.show = true">
926926
<v-icon>mdi-help</v-icon>
927927
</v-btn>
928928
<v-btn dark fab small color="pink" @click="box.usercfgs.isLeftBoxIcon = !box.usercfgs.isLeftBoxIcon">
929929
<v-icon>
930930
{{box.usercfgs.isLeftBoxIcon ? 'mdi-format-horizontal-align-right' : 'mdi-format-horizontal-align-left'}}
931931
</v-icon>
932932
</v-btn>
933-
<v-btn dark fab small color="indigo" @click="">
933+
<!-- <v-btn dark fab small color="indigo" @click="">
934934
<v-icon>mdi-database-import</v-icon>
935935
</v-btn>
936936
<v-btn dark fab small color="success" @click="">
937937
<v-icon>mdi-export-variant</v-icon>
938-
</v-btn>
938+
</v-btn> -->
939939
<v-btn dark v-if="!box.usercfgs.isHideRefresh" fab small color="orange" @dblclick="window.location.reload()">
940940
<v-icon>mdi-refresh</v-icon>
941941
</v-btn>
942942
</v-speed-dial>
943943
</v-fab-transition>
944+
<v-bottom-sheet v-model="ui.versionsheet.show" scrollable>
945+
<v-card v-if="box.versions">
946+
<v-subheader>
947+
<v-btn icon small @click="ui.versionsheet.show = false">
948+
<v-icon>mdi-help-circle</v-icon>
949+
</v-btn>
950+
<v-spacer></v-spacer>
951+
<v-btn text small v-if="hasNewVersion">新版本</v-btn>
952+
<v-spacer></v-spacer>
953+
<v-btn icon small @click="ui.versionsheet.show = false">
954+
<v-icon>mdi-close</v-icon>
955+
</v-btn>
956+
</v-subheader>
957+
<v-divider></v-divider>
958+
<v-card-text style="height: 80%;">
959+
<div class="mt-6" v-for="(ver, verIdx) in box.versions">
960+
<h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.version}}</h2>
961+
<div class="pl-4 pt-2" v-for="(note, noteIdx) in ver.notes">
962+
<strong>{{note.name}}</strong>
963+
<ul>
964+
<li v-for="(desc, descIdx) in note.descs">{{desc}}</li>
965+
</ul>
966+
</div>
967+
</div>
968+
</v-card-text>
969+
</v-card>
970+
</v-bottom-sheet>
944971
<v-overlay v-model="ui.overlay.show" :opacity="0.8">
945972
<v-progress-circular indeterminate :value="ui.overlay.val" :size="64" color="primary"></v-progress-circular>
946973
</v-overlay>
@@ -974,6 +1001,8 @@ <h2>{{curbak.name}}</h2>
9741001
overlay: { show: false, val: 60 },
9751002
snackbar: { show: false, color: 'primary', msg: '' },
9761003
searchBar: { menuProps: { closeOnContentClick: true } },
1004+
versionsheet: { show: false },
1005+
updatesheet: { show: false },
9771006
naviDrawer: { show: false },
9781007
baksSkeleton: { show: true },
9791008
editProfileDialog: { show: false },
@@ -993,6 +1022,15 @@ <h2>{{curbak.name}}</h2>
9931022
version() {
9941023
return this.box.syscfgs.version
9951024
},
1025+
// 判断是否有新版本
1026+
hasNewVersion() {
1027+
const curver = this.box.syscfgs.version
1028+
const vers = this.box.versions
1029+
if (curver && vers && vers.length > 0) {
1030+
const lastestVer = vers[0].version
1031+
return this.compareVersion(lastestVer, curver) > 0
1032+
}
1033+
},
9961034
// 判断是否需要跨域请求
9971035
isCors() {
9981036
return this.ui.isCors
@@ -1261,6 +1299,7 @@ <h2>{{curbak.name}}</h2>
12611299
}
12621300
// 获取贡献者列表
12631301
this.getContributors()
1302+
this.getVersions()
12641303
this.loadTheme()
12651304
},
12661305
methods: {
@@ -1681,6 +1720,24 @@ <h2>{{curbak.name}}</h2>
16811720
this.ui.contributors.push({ id, login, repo, icon })
16821721
})
16831722
})
1723+
},
1724+
// 获取版本清单
1725+
getVersions() {
1726+
axios.get('/query/versions').then((resp) => {
1727+
if (resp.data && resp.data.releases) {
1728+
Object.assign(this.box, { versions: resp.data.releases })
1729+
if (this.hasNewVersion) {
1730+
this.ui.versionsheet.show = true
1731+
}
1732+
}
1733+
})
1734+
},
1735+
// 对比版本号
1736+
compareVersion(v1, v2) {
1737+
var _v1 = v1.split('.'),
1738+
_v2 = v2.split('.'),
1739+
_r = _v1[0] - _v2[0]
1740+
return _r == 0 && v1 != v2 ? this.compareVersion(_v1.splice(1).join('.'), _v2.splice(1).join('.')) : _r
16841741
}
16851742
}
16861743
})

‎box/chavy.boxjs.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $.json = $.name // `接口`类请求的响应体
2121
$.html = $.name // `页面`类请求的响应体
2222

2323
$.web = `https://cdn.jsdelivr.net/gh/chavyleung/scripts@${$.version}/box/chavy.boxjs.html`
24+
$.ver = 'https://gitee.com/chavyleung/scripts/raw/master/box/release/box.release.tf.json'
2425

2526
!(async () => {
2627
// 勿扰模式
@@ -132,6 +133,8 @@ async function handleQuery() {
132133
} else if (/^\/baks/.test(query)) {
133134
const globalbaks = getGlobalBaks(true)
134135
$.json = { globalbaks }
136+
} else if (/^\/versions$/.test(query)) {
137+
await getVersions(true)
135138
}
136139
}
137140

@@ -280,6 +283,21 @@ function getGlobalBaks(isComplete = false) {
280283
return globalbaks
281284
}
282285
}
286+
/**
287+
* 获取版本清单
288+
*/
289+
function getVersions() {
290+
return $.http.get($.ver).then(
291+
(resp) => {
292+
try {
293+
$.json = $.toObj(resp.body)
294+
} catch {
295+
$.json = {}
296+
}
297+
},
298+
() => ($.json = {})
299+
)
300+
}
283301

284302
/**
285303
* 获取用户应用

‎box/release/box.release.tf.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"releases": [
3+
{
4+
"version": "0.7.7",
5+
"tags": ["beta"],
6+
"author": "@chavyleung",
7+
"icon": "https://avatars3.githubusercontent.com/u/29748519",
8+
"repo": "https://github.com/chavyleung",
9+
"notes": [
10+
{
11+
"name": "优化",
12+
"descs": ["全程无刷新", "独立分离页面", "优化数据结构减少内存占用"]
13+
},
14+
{
15+
"name": "操作",
16+
"descs": ["可以修复全局备份的名字", "点击'应用'回到顶部,再次单击折叠面板", "点击'订阅'回到顶部,再次单击刷新订阅", "点击具体订阅可刷新"]
17+
}
18+
]
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)