-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use typescript and vue 3; add service worker script
- Loading branch information
Showing
8 changed files
with
147 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createI18n } from 'vue-i18n' | ||
|
||
const i18n = createI18n({ | ||
legacy: false, | ||
locale: 'en', | ||
availableLocales: ['en', 'ru'], | ||
}) | ||
|
||
export function setI18nLanguage(locale: string): void { | ||
i18n.global.locale.value = locale | ||
document.querySelector('html')?.setAttribute('lang', locale) | ||
} | ||
|
||
export async function loadLocaleMessages(locale: string): Promise<void> { | ||
const messages = await import(/* webpackChunkName: "locale-[request]" */ `./locales/${locale}.json`) | ||
i18n.global.setLocaleMessage(locale, messages.default) | ||
} | ||
|
||
export default i18n |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createApp } from 'vue' | ||
import App from '@/App.vue' | ||
import i18n from '@/i18n' | ||
import router from '@/router' | ||
import store from '@/store' | ||
import '@/registerServiceWorker' | ||
|
||
createApp(App).use(i18n).use(router).use(store).mount('body') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { register } from 'register-service-worker' | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
register(`${process.env.BASE_URL}service-worker.js`, { | ||
ready() { | ||
console.log( | ||
'App is being served from cache by a service worker.\n' + 'For more details, visit https://goo.gl/AFskqB' | ||
) | ||
}, | ||
registered() { | ||
console.log('Service worker has been registered.') | ||
}, | ||
cached() { | ||
console.log('Content has been cached for offline use.') | ||
}, | ||
updatefound() { | ||
console.log('New content is downloading.') | ||
}, | ||
updated() { | ||
console.log('New content is available; please refresh.') | ||
}, | ||
offline() { | ||
console.log('No internet connection found. App is running in offline mode.') | ||
}, | ||
error(error) { | ||
console.error('Error during service worker registration:', error) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import i18n from '@/i18n' | ||
import { createRouter, createWebHistory } from 'vue-router' | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(process.env.BASE_URL), | ||
routes: [ | ||
{ | ||
path: '/', | ||
component: () => import(/* webpackChunkName: 'Home' */ '@/views/Home.vue'), | ||
meta: { | ||
title: i18n.global.t('pages.Home'), | ||
}, | ||
}, | ||
{ | ||
path: '/damage', | ||
component: () => import(/* webpackChunkName: 'DamageCalculator' */ '@/views/DamageCalculator.vue'), | ||
meta: { | ||
title: i18n.global.t('pages.DamageCalculator'), | ||
}, | ||
}, | ||
{ | ||
path: '/creatures', | ||
component: () => import(/* webpackChunkName: 'CreaturesLibrary' */ '@/views/CreaturesLibrary.vue'), | ||
meta: { | ||
title: i18n.global.t('pages.CreaturesLibrary'), | ||
disabled: true, | ||
}, | ||
}, | ||
{ | ||
path: '/:pathMatch(.*)*', | ||
name: 'not-found', | ||
component: () => import(/* webpackChunkName: 'Error' */ '@/views/Error.vue'), | ||
meta: { | ||
title: i18n.global.t('pages.Error'), | ||
}, | ||
}, | ||
], | ||
scrollBehavior(to, from, savedPosition) { | ||
return new Promise((resolve) => { | ||
if (savedPosition) return resolve(savedPosition) | ||
else if (to.hash) return resolve({ el: to.hash }) | ||
else return resolve({ left: 0, top: 0 }) | ||
}) | ||
}, | ||
}) | ||
|
||
router.resolve({ | ||
name: 'not-found', | ||
params: { pathMatch: ['not', 'found'] }, | ||
}).href | ||
|
||
router.beforeEach((to, from, next) => { | ||
if (to.meta.disabled) next({ path: '/' }) | ||
|
||
next() | ||
}) | ||
|
||
router.afterEach((to) => { | ||
if (to.meta.title) document.title = to.meta.title | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
declare module '*.vue' { | ||
import type { DefineComponent } from 'vue' | ||
const component: DefineComponent<{}, {}, any> | ||
export default component | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createStore } from 'vuex' | ||
import { CalculatorInstance } from '@/models/Calculator' | ||
|
||
export default createStore({ | ||
state: { | ||
calculators: [] as Array<CalculatorInstance>, | ||
activeIndex: 0, | ||
}, | ||
actions: { | ||
rememberCalculators({ commit }, payload: { calculators: Array<CalculatorInstance> }) { | ||
commit('REMEMBER_CALCULATORS', { calculators: payload.calculators }) | ||
}, | ||
}, | ||
mutations: { | ||
REMEMBER_CALCULATORS(state, payload: { calculators: Array<CalculatorInstance> }) { | ||
state.calculators = payload.calculators | ||
}, | ||
}, | ||
strict: process.env.NODE_ENV === 'development', | ||
}) |