Skip to content

Commit dbaa6ed

Browse files
committed
Add dashboard menu item and deprecate router history (#94)
1 parent e90c0c7 commit dbaa6ed

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2022 Hengyang Zhang
3+
*
4+
* This software is released under the MIT License.
5+
* https://opensource.org/licenses/MIT
6+
*/
7+
8+
import { defineComponent, h } from "vue"
9+
import ContentContainer from "@app/components/common/content-container"
10+
11+
const _default = defineComponent({
12+
name: 'Dashboard',
13+
setup() {
14+
return () => h(ContentContainer)
15+
}
16+
})
17+
18+
export default _default

src/app/layout/menu.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from "vue-
1111
import { I18nKey, t } from "@app/locale"
1212
import { MenuMessage } from "@app/locale/components/menu"
1313
import { GITHUB_ISSUE_ADD, HOME_PAGE, MEAT_URL, TU_CAO_PAGE } from "@util/constant/url"
14-
import { Aim, Calendar, ChatSquare, Folder, Food, HotWater, Rank, SetUp, Stopwatch, Sugar, Tickets, Timer } from "@element-plus/icons-vue"
14+
import { Aim, Calendar, ChatSquare, Folder, Food, HotWater, Rank, SetUp, Stopwatch, Sugar, Tickets, Timer, TrendCharts } from "@element-plus/icons-vue"
1515
import ElementIcon from "../element-ui/icon"
1616
import { locale } from "@util/i18n"
17-
import { IS_EDGE } from "@util/constant/environment"
1817

1918
type _MenuItem = {
2019
title: keyof MenuMessage
@@ -68,6 +67,10 @@ const ALL_MENU: _MenuGroup[] = [
6867
{
6968
title: 'data',
7069
children: [{
70+
title: 'dashboard',
71+
route: '/data/dashboard',
72+
icon: TrendCharts
73+
}, {
7174
title: 'dataReport',
7275
route: '/data/report',
7376
icon: Calendar
@@ -171,7 +174,7 @@ const _default = defineComponent({
171174
current: useRoute()
172175
})
173176

174-
onMounted(() => document.title = t(msg => msg.menu.data))
177+
onMounted(() => document.title = t(msg => msg.menu.dashboard))
175178

176179
return () => h(ElMenu,
177180
{ defaultActive: routeProps.current.path },

src/app/locale/components/menu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { Messages } from "@util/i18n"
99

1010
export type MenuMessage = {
11+
dashboard: string
1112
data: string
1213
dataReport: string
1314
dataHistory: string
@@ -27,6 +28,7 @@ export type MenuMessage = {
2728
}
2829
const _default: Messages<MenuMessage> = {
2930
zh_CN: {
31+
dashboard: '仪表盘',
3032
data: '我的数据',
3133
dataReport: '报表明细',
3234
dataHistory: '历史趋势',
@@ -45,6 +47,7 @@ const _default: Messages<MenuMessage> = {
4547
meat: '请作者吃饭~'
4648
},
4749
zh_TW: {
50+
dashboard: '儀錶盤',
4851
data: '我的數據',
4952
dataReport: '報表明細',
5053
dataHistory: '曆史趨勢',
@@ -63,6 +66,7 @@ const _default: Messages<MenuMessage> = {
6366
meat: '請作者吃飯~'
6467
},
6568
en: {
69+
dashboard: "Dashboard",
6670
data: 'My Data',
6771
dataReport: 'Record',
6872
dataHistory: 'Trend',
@@ -81,6 +85,7 @@ const _default: Messages<MenuMessage> = {
8185
meat: 'Invite the author to dinner'
8286
},
8387
ja: {
88+
dashboard: 'ダッシュボード',
8489
data: '私のデータ',
8590
dataReport: '報告する',
8691
dataHistory: '歴史傾向',

src/app/router/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77

88
import { App } from "vue"
99
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"
10-
import RouterDatabase from "@db/router-database"
1110
import { OPTION_ROUTE, TREND_ROUTE, LIMIT_ROUTE, REPORT_ROUTE } from "./constants"
1211
import metaService from "@service/meta-service"
1312

1413
const dataRoutes: RouteRecordRaw[] = [
1514
{
1615
path: '/data',
17-
redirect: '/data/report',
16+
redirect: '/data/dashboard',
1817
},
1918
// Needn't nested router
19+
{
20+
path: '/data/dashboard',
21+
component: () => import('../components/dashboard')
22+
},
2023
{
2124
path: REPORT_ROUTE,
2225
component: () => import('../components/report')
@@ -73,16 +76,12 @@ const router = createRouter({
7376
routes,
7477
})
7578

76-
const db: RouterDatabase = new RouterDatabase(chrome.storage.local)
77-
7879
async function handleChange() {
7980
await router.isReady()
8081
const current = router.currentRoute.value.fullPath
8182
current && metaService.increaseApp(current)
82-
current && await db.update(current)
8383
router.afterEach((to, from, failure: Error | void) => {
8484
if (failure || to.fullPath === from.fullPath) return
85-
db.update(to.fullPath)
8685
metaService.increaseApp(to.fullPath)
8786
})
8887
}

src/database/router-database.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ import BaseDatabase from "./common/base-database"
99
import { REMAIN_WORD_PREFIX } from "./common/constant"
1010

1111
const KEY = REMAIN_WORD_PREFIX + "app_router"
12+
13+
/**
14+
* @deprecated since 0.9.3
15+
*/
1216
class RouterDatabase extends BaseDatabase {
17+
/**
18+
* @deprecated since 0.9.3
19+
*/
1320
async getHistory(): Promise<string | undefined> {
1421
const items = await this.storage.get(KEY)
1522
return items[KEY]
1623
}
1724

25+
/**
26+
* @deprecated since 0.9.3
27+
*/
1828
update(newRoute: string): Promise<void> {
1929
return this.setByKey(KEY, newRoute)
2030
}
2131

32+
/**
33+
* @deprecated since 0.9.3
34+
*/
2235
async importData(_data: any): Promise<void> {
2336
// Do nothing
2437
}

src/popup/components/footer/all-function.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
66
*/
7-
8-
import RouterDatabase from "@db/router-database"
97
import { getAppPageUrl } from "@util/constant/url"
108
import { t } from "@popup/locale"
119

12-
const db: RouterDatabase = new RouterDatabase(chrome.storage.local)
13-
1410
const allFunctionLink = document.getElementById('all-function-link')
1511
allFunctionLink.onclick = async () => {
16-
const historyRoute = await db.getHistory()
17-
chrome.tabs.create({ url: getAppPageUrl(false, historyRoute || '/') })
12+
chrome.tabs.create({ url: getAppPageUrl(false, '/') })
1813
}
1914
allFunctionLink.innerText = t(msg => msg.viewMore)

src/service/components/immigration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import IconUrlDatabase from "@db/icon-url-database"
1313
import LimitDatabase from "@db/limit-database"
1414
import MergeRuleDatabase from "@db/merge-rule-database"
1515
import PeriodDatabase from "@db/period-database"
16-
import RouterDatabase from "@db/router-database"
1716
import TimerDatabase from "@db/timer-database"
1817
import WhitelistDatabase from "@db/whitelist-database"
1918
import HostAliasDatabase from "@db/host-alias-database"
@@ -36,7 +35,6 @@ function initDatabase(storage: chrome.storage.StorageArea): BaseDatabase[] {
3635
new LimitDatabase(storage),
3736
new MergeRuleDatabase(storage),
3837
new WhitelistDatabase(storage),
39-
new RouterDatabase(storage),
4038
new HostAliasDatabase(storage)
4139
]
4240

0 commit comments

Comments
 (0)