mirror of
https://git.hmsn.ink/kospo/svcm/dmz.git
synced 2026-03-20 08:03:34 +09:00
first
This commit is contained in:
23
src/plugins/cache-headers.ts
Normal file
23
src/plugins/cache-headers.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
export default definePlugin(async ({ event, router }) => {
|
||||
if (!event) return
|
||||
|
||||
const [getRequestURL, setResponseHeader] = await import('h3').then(m => [
|
||||
m.getRequestURL,
|
||||
m.setResponseHeader,
|
||||
] as const)
|
||||
|
||||
const url = getRequestURL(event)
|
||||
if (!url?.pathname) return
|
||||
|
||||
const route = router.resolve(url.pathname)
|
||||
if (!route) return
|
||||
|
||||
if (route.meta.requiresAuth) {
|
||||
setResponseHeader(event, 'Cache-Control', 'private, max-age=3600, stale-while-revalidate=3600')
|
||||
}
|
||||
else {
|
||||
setResponseHeader(event, 'Cache-Control', 'public, max-age=86400, stale-while-revalidate=604800')
|
||||
}
|
||||
})
|
||||
6
src/plugins/darkmode.ts
Normal file
6
src/plugins/darkmode.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createDarkmode } from '/@src/composables/darkmode'
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
app.use(createDarkmode())
|
||||
})
|
||||
11
src/plugins/data-loader.ts
Normal file
11
src/plugins/data-loader.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import { DataLoaderPlugin } from 'vue-router/auto'
|
||||
|
||||
/**
|
||||
* Enable Vue Data Loader plugin from unplugin-vue-router
|
||||
*
|
||||
* @see https://uvr.esm.is/rfcs/data-loaders/
|
||||
*/
|
||||
export default definePlugin(({ app, router }) => {
|
||||
app.use(DataLoaderPlugin, { router })
|
||||
})
|
||||
15
src/plugins/directives.ts
Normal file
15
src/plugins/directives.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import { vPreloadLink } from '/@src/directives/preload-link'
|
||||
import { vTooltip } from '/@src/directives/tooltip'
|
||||
import { vBackground } from '/@src/directives/background'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
// register global v-preload-link directive
|
||||
app.directive('preload-link', vPreloadLink)
|
||||
|
||||
// register global v-tootltip directive
|
||||
app.directive('tooltip', vTooltip)
|
||||
|
||||
// register global v-background directive
|
||||
app.directive('background', vBackground)
|
||||
})
|
||||
19
src/plugins/i18n.ts
Normal file
19
src/plugins/i18n.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
/**
|
||||
* messages are generated using vite-plugin-i18n
|
||||
* each .json files located in the ./src/locales are registered in messages
|
||||
* @see https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
|
||||
*/
|
||||
import messages from '@intlify/unplugin-vue-i18n/messages'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
const defaultLocale = useStorage('locale', 'en')
|
||||
const i18n = createI18n({
|
||||
locale: defaultLocale.value,
|
||||
messages,
|
||||
})
|
||||
|
||||
app.use(i18n)
|
||||
})
|
||||
6
src/plugins/notyf.ts
Normal file
6
src/plugins/notyf.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createNotyf } from '/@src/composables/notyf'
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
export default definePlugin(async ({ app }) => {
|
||||
app.use(createNotyf())
|
||||
})
|
||||
17
src/plugins/nprogress.ts
Normal file
17
src/plugins/nprogress.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
|
||||
export default definePlugin(({ router }) => {
|
||||
if (import.meta.env.SSR) {
|
||||
return
|
||||
}
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
router.beforeEach(() => {
|
||||
NProgress.start()
|
||||
})
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
})
|
||||
})
|
||||
74
src/plugins/session-check.ts
Normal file
74
src/plugins/session-check.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
/**
|
||||
* Here we are setting up two router navigation guards
|
||||
* (note that we can have multiple guards in multiple plugins)
|
||||
*
|
||||
* We can add meta to pages either by declaring them manualy in the
|
||||
* routes declaration (see /@src/router.ts)
|
||||
* or by adding a <route> tag into .vue files (see /@src/pages/sidebar/dashboards.ts)
|
||||
*
|
||||
* <script setup lang="ts">
|
||||
* definePage({
|
||||
* meta: {
|
||||
* requiresAuth: true,
|
||||
* },
|
||||
* })
|
||||
* </script>
|
||||
*
|
||||
* <template>
|
||||
* // HTML content
|
||||
* </template>
|
||||
*/
|
||||
export default definePlugin(async ({ router, pinia, event }) => {
|
||||
const userSession = useUserSession(pinia)
|
||||
const token = useUserToken(event)
|
||||
const $fetch = useApiFetch(event)
|
||||
|
||||
// 1. Load user profile if token is present.
|
||||
// When using SSR, it should be hydrated from the server
|
||||
// if (token.value && !userSession.user) {
|
||||
// try {
|
||||
// // Do api request call to retreive user profile.
|
||||
// // Note that the api is provided with json-server
|
||||
// // await api.tokenValid(userSession.user.value.bizNo)
|
||||
// console.log('me')
|
||||
// const user = await $fetch('/api/business/me')
|
||||
// userSession.setUser(user)
|
||||
// }
|
||||
// catch (err) {
|
||||
// // Delete stored token if it fails
|
||||
// token.value = undefined
|
||||
// }
|
||||
// }
|
||||
|
||||
// 2. If the page requires auth, check if user is logged in
|
||||
// if not, redirect to login page.
|
||||
router.beforeEach(async (to) => {
|
||||
console.log('in')
|
||||
const token = useUserToken()
|
||||
|
||||
if(to.meta.requiresAuth) {
|
||||
try {
|
||||
const user = await $fetch('/api/business/me')
|
||||
userSession.setUser(user)
|
||||
}
|
||||
catch (err: any) {
|
||||
// Delete stored token if it fails
|
||||
userSession.logoutUser()
|
||||
token.value = undefined
|
||||
}
|
||||
if (!token.value) {
|
||||
return {
|
||||
name: '/auth/login',
|
||||
query: { redirect: to.fullPath },
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (userSession.user !== undefined) {
|
||||
router.replace('/navbar/dashboards')
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
22
src/plugins/v-calendar.ts
Normal file
22
src/plugins/v-calendar.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import 'v-calendar/dist/style.css'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
app.component(
|
||||
'VCalendar',
|
||||
defineAsyncComponent({
|
||||
loader: () => import('v-calendar').then(mod => mod.Calendar),
|
||||
delay: 0,
|
||||
suspensible: false,
|
||||
}),
|
||||
)
|
||||
|
||||
app.component(
|
||||
'VDatePicker',
|
||||
defineAsyncComponent({
|
||||
loader: () => import('v-calendar').then(mod => mod.DatePicker),
|
||||
delay: 0,
|
||||
suspensible: false,
|
||||
}),
|
||||
)
|
||||
})
|
||||
12
src/plugins/vue-tippy.ts
Normal file
12
src/plugins/vue-tippy.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { plugin as VueTippy } from 'vue-tippy'
|
||||
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
app.use(VueTippy, {
|
||||
component: 'Tippy',
|
||||
defaultProps: {
|
||||
theme: 'light',
|
||||
},
|
||||
})
|
||||
})
|
||||
18
src/plugins/vue3-apexcharts.ts
Normal file
18
src/plugins/vue3-apexcharts.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
import ClientOnly from '/@src/components/ClientOnly.vue'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
const ApexChart = defineAsyncComponent({
|
||||
// @ts-expect-error - modules does not have exports field (required by moduleResolution = bundler)
|
||||
loader: () => import('vue3-apexcharts'),
|
||||
suspensible: false,
|
||||
})
|
||||
|
||||
app.component('ApexChart', defineComponent({
|
||||
name: 'ApexChart',
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs }) {
|
||||
return () => h(ClientOnly, () => h(ApexChart, attrs))
|
||||
},
|
||||
}))
|
||||
})
|
||||
27
src/plugins/vueform.ts
Normal file
27
src/plugins/vueform.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineAsyncComponent } from 'vue'
|
||||
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
export default definePlugin(({ app }) => {
|
||||
// here we are defining a lazy loaded component
|
||||
// that will be imported on demand
|
||||
app.component(
|
||||
// eslint-disable-next-line vue/multi-word-component-names
|
||||
'Multiselect',
|
||||
defineAsyncComponent({
|
||||
loader: () => import('@vueform/multiselect').then(mod => mod.default),
|
||||
delay: 0,
|
||||
suspensible: false,
|
||||
}),
|
||||
)
|
||||
|
||||
app.component(
|
||||
// eslint-disable-next-line vue/multi-word-component-names
|
||||
'Slider',
|
||||
defineAsyncComponent({
|
||||
loader: () => import('@vueform/slider').then(mod => mod.default),
|
||||
delay: 0,
|
||||
suspensible: false,
|
||||
}),
|
||||
)
|
||||
})
|
||||
28
src/plugins/vuero-context.ts
Normal file
28
src/plugins/vuero-context.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { type VueroContext, createVueroContext } from '/@src/composables/vuero-context'
|
||||
import { definePlugin } from '/@src/utils/plugins'
|
||||
|
||||
// augment the initial state type
|
||||
declare module '/@server/types' {
|
||||
export interface VueroInitialState {
|
||||
ctx?: VueroContext
|
||||
}
|
||||
}
|
||||
|
||||
export default definePlugin(({ app, event }) => {
|
||||
const context: VueroContext = {}
|
||||
|
||||
// persist the context object on the server side
|
||||
if (import.meta.env.SSR && event) {
|
||||
event.context.initialState ??= {}
|
||||
event.context.initialState.ctx ??= context
|
||||
}
|
||||
|
||||
// hydrate the context object on the client side
|
||||
if (!import.meta.env.SSR && window.__vuero__?.ctx) {
|
||||
for (const [key, value] of Object.entries(window.__vuero__.ctx)) {
|
||||
context[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
app.use(createVueroContext(context))
|
||||
})
|
||||
Reference in New Issue
Block a user