Commit cd10eb94 by vben

feat: Regular monitoring page update [deploy]

1 parent 66fd0527
Showing 37 changed files with 405 additions and 209 deletions
...@@ -15,6 +15,7 @@ coverage ...@@ -15,6 +15,7 @@ coverage
**/.vitepress/cache **/.vitepress/cache
.cache .cache
.turbo .turbo
.temp
dev-dist dev-dist
.stylelintcache .stylelintcache
yarn.lock yarn.lock
......
...@@ -2,3 +2,4 @@ dist ...@@ -2,3 +2,4 @@ dist
public public
__tests__ __tests__
coverage coverage
ui-kit
...@@ -7,7 +7,7 @@ VITE_GLOB_API_URL=https://mock-napi.vben.pro/api ...@@ -7,7 +7,7 @@ VITE_GLOB_API_URL=https://mock-napi.vben.pro/api
VITE_COMPRESS=none VITE_COMPRESS=none
# 是否开启 PWA # 是否开启 PWA
VITE_PWA=false VITE_PWA=true
# vue-router 的模式 # vue-router 的模式
VITE_ROUTER_HISTORY=hash VITE_ROUTER_HISTORY=hash
......
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { GlobalProvider } from '@vben/common-ui';
import { useDesignTokens } from '@vben/hooks'; import { useDesignTokens } from '@vben/hooks';
import { preferences, usePreferences } from '@vben/preferences'; import { preferences, usePreferences } from '@vben/preferences';
...@@ -26,17 +25,15 @@ const tokenTheme = computed(() => { ...@@ -26,17 +25,15 @@ const tokenTheme = computed(() => {
return { return {
algorithm, algorithm,
token: antDesignTokens.value, token: antDesignTokens,
}; };
}); });
</script> </script>
<template> <template>
<GlobalProvider> <ConfigProvider :locale="antdLocale" :theme="tokenTheme">
<ConfigProvider :locale="antdLocale" :theme="tokenTheme"> <App>
<App> <RouterView />
<RouterView /> </App>
</App> </ConfigProvider>
</ConfigProvider>
</GlobalProvider>
</template> </template>
...@@ -3,7 +3,7 @@ import { computed, ref } from 'vue'; ...@@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { AuthenticationLoginExpiredModal } from '@vben/common-ui'; import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH, VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons'; import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
import { import {
BasicLayout, BasicLayout,
...@@ -57,7 +57,7 @@ const showDot = computed(() => ...@@ -57,7 +57,7 @@ const showDot = computed(() =>
const menus = computed(() => [ const menus = computed(() => [
{ {
handler: () => { handler: () => {
openWindow('https://github.com/vbenjs/vue-vben-admin', { openWindow(VBEN_DOC_URL, {
target: '_blank', target: '_blank',
}); });
}, },
...@@ -66,7 +66,7 @@ const menus = computed(() => [ ...@@ -66,7 +66,7 @@ const menus = computed(() => [
}, },
{ {
handler: () => { handler: () => {
openWindow('https://github.com/vbenjs/vue-vben-admin', { openWindow(VBEN_GITHUB_URL, {
target: '_blank', target: '_blank',
}); });
}, },
...@@ -75,7 +75,7 @@ const menus = computed(() => [ ...@@ -75,7 +75,7 @@ const menus = computed(() => [
}, },
{ {
handler: () => { handler: () => {
openWindow('https://github.com/vbenjs/vue-vben-admin/issues', { openWindow(`${VBEN_GITHUB_URL}/issues`, {
target: '_blank', target: '_blank',
}); });
}, },
......
import type { RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
import { VBEN_GITHUB_URL, VBEN_LOGO_URL } from '@vben/constants'; import { VBEN_DOC_URL, VBEN_GITHUB_URL, VBEN_LOGO_URL } from '@vben/constants';
import { BasicLayout, IFrameView } from '#/layouts'; import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales'; import { $t } from '#/locales';
...@@ -35,7 +35,7 @@ const routes: RouteRecordRaw[] = [ ...@@ -35,7 +35,7 @@ const routes: RouteRecordRaw[] = [
component: IFrameView, component: IFrameView,
meta: { meta: {
icon: 'lucide:book-open-text', icon: 'lucide:book-open-text',
iframeSrc: 'https://doc.vvbin.cn/', iframeSrc: VBEN_DOC_URL,
keepAlive: true, keepAlive: true,
title: $t('page.vben.document'), title: $t('page.vben.document'),
}, },
......
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
"ependencies", "ependencies",
"vite", "vite",
"echarts", "echarts",
"sortablejs" "sortablejs",
"etag"
], ],
"ignorePaths": [ "ignorePaths": [
"**/node_modules/**", "**/node_modules/**",
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
"eslint": "^9.8.0", "eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jsdoc": "^48.8.3", "eslint-plugin-jsdoc": "^48.9.2",
"eslint-plugin-jsonc": "^2.16.0", "eslint-plugin-jsonc": "^2.16.0",
"eslint-plugin-n": "^17.10.1", "eslint-plugin-n": "^17.10.1",
"eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-no-only-tests": "^3.1.0",
......
...@@ -43,11 +43,6 @@ const customConfig: Linter.FlatConfig[] = [ ...@@ -43,11 +43,6 @@ const customConfig: Linter.FlatConfig[] = [
message: message:
'The #/stores package cannot be imported, please use the @core package itself', 'The #/stores package cannot be imported, please use the @core package itself',
}, },
{
group: ['#/forward/*'],
message:
'The #/forward package cannot be imported, please use the @core package itself',
},
], ],
}, },
], ],
...@@ -99,6 +94,9 @@ const customConfig: Linter.FlatConfig[] = [ ...@@ -99,6 +94,9 @@ const customConfig: Linter.FlatConfig[] = [
'packages/icons/**/**', 'packages/icons/**/**',
'packages/constants/**/**', 'packages/constants/**/**',
'packages/styles/**/**', 'packages/styles/**/**',
'packages/stores/**/**',
'packages/preferences/**/**',
'packages/locales/**/**',
], ],
ignores: restrictedImportIgnores, ignores: restrictedImportIgnores,
rules: { rules: {
...@@ -118,11 +116,12 @@ const customConfig: Linter.FlatConfig[] = [ ...@@ -118,11 +116,12 @@ const customConfig: Linter.FlatConfig[] = [
}, },
// 后端模拟代码,不需要太多规则 // 后端模拟代码,不需要太多规则
{ {
files: ['apps/backend-mock/**/**'], files: ['apps/backend-mock/**/**', 'website/**/**'],
rules: { rules: {
'@typescript-eslint/no-extraneous-class': 'off', '@typescript-eslint/no-extraneous-class': 'off',
'n/no-extraneous-import': 'off', 'n/no-extraneous-import': 'off',
'n/prefer-global/buffer': 'off', 'n/prefer-global/buffer': 'off',
'n/prefer-global/process': 'off',
'no-console': 'off', 'no-console': 'off',
'unicorn/prefer-module': 'off', 'unicorn/prefer-module': 'off',
}, },
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
"postcss-html": "^1.7.0", "postcss-html": "^1.7.0",
"postcss-scss": "^4.0.9", "postcss-scss": "^4.0.9",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"stylelint": "^16.7.0", "stylelint": "^16.8.0",
"stylelint-config-recommended": "^14.0.1", "stylelint-config-recommended": "^14.0.1",
"stylelint-config-recommended-scss": "^14.1.0", "stylelint-config-recommended-scss": "^14.1.0",
"stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-recommended-vue": "^1.5.0",
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
"tailwindcss": "^3.4.3" "tailwindcss": "^3.4.3"
}, },
"dependencies": { "dependencies": {
"@iconify/json": "^2.2.231", "@iconify/json": "^2.2.232",
"@iconify/tailwind": "^1.1.2", "@iconify/tailwind": "^1.1.2",
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e", "@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
"@tailwindcss/typography": "^0.5.13", "@tailwindcss/typography": "^0.5.13",
......
...@@ -13,7 +13,7 @@ import { loadApplicationPlugins } from '../plugins'; ...@@ -13,7 +13,7 @@ import { loadApplicationPlugins } from '../plugins';
import { loadAndConvertEnv } from '../utils/env'; import { loadAndConvertEnv } from '../utils/env';
import { getCommonConfig } from './common'; import { getCommonConfig } from './common';
function defineApplicationConfig(userConfigPromise: DefineApplicationOptions) { function defineApplicationConfig(userConfigPromise?: DefineApplicationOptions) {
return defineConfig(async (config) => { return defineConfig(async (config) => {
const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv(); const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
const options = await userConfigPromise?.(config); const options = await userConfigPromise?.(config);
......
...@@ -9,7 +9,7 @@ import { defineConfig, mergeConfig } from 'vite'; ...@@ -9,7 +9,7 @@ import { defineConfig, mergeConfig } from 'vite';
import { loadLibraryPlugins } from '../plugins'; import { loadLibraryPlugins } from '../plugins';
import { getCommonConfig } from './common'; import { getCommonConfig } from './common';
function defineLibraryConfig(userConfigPromise: DefineLibraryOptions) { function defineLibraryConfig(userConfigPromise?: DefineLibraryOptions) {
return defineConfig(async (config: ConfigEnv) => { return defineConfig(async (config: ConfigEnv) => {
const options = await userConfigPromise?.(config); const options = await userConfigPromise?.(config);
const { command, mode } = config; const { command, mode } = config;
......
...@@ -20,7 +20,7 @@ const getDefaultPwaOptions = (name: string): Partial<PwaPluginOptions> => ({ ...@@ -20,7 +20,7 @@ const getDefaultPwaOptions = (name: string): Partial<PwaPluginOptions> => ({
type: 'image/png', type: 'image/png',
}, },
], ],
name: `${name}o${isDevelopment ? ' dev' : ''}`, name: `${name}${isDevelopment ? ' dev' : ''}`,
short_name: `${name}${isDevelopment ? ' dev' : ''}`, short_name: `${name}${isDevelopment ? ' dev' : ''}`,
}, },
}); });
......
...@@ -150,10 +150,6 @@ async function loadApplicationPlugins( ...@@ -150,10 +150,6 @@ async function loadApplicationPlugins(
condition: pwa, condition: pwa,
plugins: () => plugins: () =>
VitePWA({ VitePWA({
devOptions: {
enabled: true,
type: 'module',
},
injectRegister: false, injectRegister: false,
workbox: { workbox: {
globPatterns: [], globPatterns: [],
......
...@@ -4,6 +4,7 @@ const defaultPreferences: Preferences = { ...@@ -4,6 +4,7 @@ const defaultPreferences: Preferences = {
app: { app: {
accessMode: 'frontend', accessMode: 'frontend',
authPageLayout: 'panel-right', authPageLayout: 'panel-right',
checkUpdatesPollingTime: 1,
colorGrayMode: false, colorGrayMode: false,
colorWeakMode: false, colorWeakMode: false,
compact: false, compact: false,
...@@ -11,6 +12,7 @@ const defaultPreferences: Preferences = { ...@@ -11,6 +12,7 @@ const defaultPreferences: Preferences = {
defaultAvatar: defaultAvatar:
'https://unpkg.com/@vbenjs/static-source@0.1.5/source/avatar-v1.webp', 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/avatar-v1.webp',
dynamicTitle: true, dynamicTitle: true,
enableCheckUpdates: true,
enablePreferences: true, enablePreferences: true,
isMobile: false, isMobile: false,
layout: 'sidebar-nav', layout: 'sidebar-nav',
...@@ -27,7 +29,7 @@ const defaultPreferences: Preferences = { ...@@ -27,7 +29,7 @@ const defaultPreferences: Preferences = {
styleType: 'normal', styleType: 'normal',
}, },
copyright: { copyright: {
companyName: 'Vben Admin', companyName: 'Vben',
companySiteLink: 'https://www.vben.pro', companySiteLink: 'https://www.vben.pro',
date: '2024', date: '2024',
enable: true, enable: true,
......
...@@ -21,6 +21,8 @@ interface AppPreferences { ...@@ -21,6 +21,8 @@ interface AppPreferences {
accessMode: AccessModeType; accessMode: AccessModeType;
/** 登录注册页面布局 */ /** 登录注册页面布局 */
authPageLayout: AuthPageLayoutType; authPageLayout: AuthPageLayoutType;
/** 检查更新轮询时间 */
checkUpdatesPollingTime: number;
/** 是否开启灰色模式 */ /** 是否开启灰色模式 */
colorGrayMode: boolean; colorGrayMode: boolean;
/** 是否开启色弱模式 */ /** 是否开启色弱模式 */
...@@ -33,6 +35,8 @@ interface AppPreferences { ...@@ -33,6 +35,8 @@ interface AppPreferences {
defaultAvatar: string; defaultAvatar: string;
// /** 开启动态标题 */ // /** 开启动态标题 */
dynamicTitle: boolean; dynamicTitle: boolean;
/** 是否开启检查更新 */
enableCheckUpdates: boolean;
/** 是否显示偏好设置 */ /** 是否显示偏好设置 */
enablePreferences: boolean; enablePreferences: boolean;
/** 是否移动端 */ /** 是否移动端 */
......
<script setup lang="ts">
import { Toaster } from '@vben-core/shadcn-ui';
defineOptions({ name: 'GlobalProvider' });
</script>
<template>
<Toaster />
<slot></slot>
</template>
export { default as GlobalProvider } from './global-provider.vue';
...@@ -2,5 +2,4 @@ export * from './about'; ...@@ -2,5 +2,4 @@ export * from './about';
export * from './authentication'; export * from './authentication';
export * from './dashboard'; export * from './dashboard';
export * from './fallback'; export * from './fallback';
export * from './global-provider';
export { useToast } from '@vben-core/shadcn-ui'; export { useToast } from '@vben-core/shadcn-ui';
import { computed, ref, watch } from 'vue'; import { reactive, watch } from 'vue';
import { preferences } from '@vben/preferences'; import { preferences } from '@vben/preferences';
export function useDesignTokens() { export function useDesignTokens() {
const rootStyles = getComputedStyle(document.documentElement); const rootStyles = getComputedStyle(document.documentElement);
const colorPrimary = ref(''); const antDesignTokens = reactive({
const colorError = ref(''); borderRadius: '' as any,
const colorSuccess = ref(''); colorBgBase: '',
const colorWarning = ref(''); colorBgContainer: '',
const colorInfo = ref(''); colorBgElevated: '',
const colorBgBase = ref(''); colorBgLayout: '',
const colorTextBase = ref(''); colorBgMask: '',
const colorBgContainer = ref(''); colorBorder: '',
const colorBgElevated = ref(''); colorError: '',
const colorBgLayout = ref(''); colorInfo: '',
const colorBgMask = ref(''); colorPrimary: '',
const colorBorder = ref(''); colorSuccess: '',
const borderRadius = ref<any>(''); colorTextBase: '',
colorWarning: '',
});
const getCssVariableValue = (variable: string, isColor: boolean = true) => { const getCssVariableValue = (variable: string, isColor: boolean = true) => {
const value = rootStyles.getPropertyValue(variable); const value = rootStyles.getPropertyValue(variable);
...@@ -27,52 +29,23 @@ export function useDesignTokens() { ...@@ -27,52 +29,23 @@ export function useDesignTokens() {
watch( watch(
() => preferences.theme, () => preferences.theme,
() => { () => {
colorInfo.value = colorPrimary.value = getCssVariableValue('--primary'); antDesignTokens.colorPrimary = getCssVariableValue('--primary');
colorError.value = getCssVariableValue('--destructive'); antDesignTokens.colorError = getCssVariableValue('--destructive');
colorWarning.value = getCssVariableValue('--warning'); antDesignTokens.colorWarning = getCssVariableValue('--warning');
colorSuccess.value = getCssVariableValue('--success'); antDesignTokens.colorSuccess = getCssVariableValue('--success');
colorBgBase.value = getCssVariableValue('--background'); antDesignTokens.colorBgBase = getCssVariableValue('--background');
colorBgLayout.value = getCssVariableValue('--background-deep'); antDesignTokens.colorBgLayout = getCssVariableValue('--background-deep');
colorBgMask.value = getCssVariableValue('--overlay'); antDesignTokens.colorBgMask = getCssVariableValue('--overlay');
colorBorder.value = getCssVariableValue('--border'); antDesignTokens.colorBorder = getCssVariableValue('--border');
colorTextBase.value = getCssVariableValue('--foreground'); antDesignTokens.colorTextBase = getCssVariableValue('--foreground');
colorBgElevated.value = getCssVariableValue('--popover'); antDesignTokens.colorBgElevated = getCssVariableValue('--popover');
colorBgContainer.value = getCssVariableValue('--card'); antDesignTokens.colorBgContainer = getCssVariableValue('--card');
borderRadius.value = getCssVariableValue('--radius', false); antDesignTokens.borderRadius = getCssVariableValue('--radius', false);
}, },
{ immediate: true }, { immediate: true },
); );
const antDesignTokens = computed(() => {
return {
borderRadius: borderRadius.value,
colorBgBase: colorBgBase.value,
colorBgContainer: colorBgContainer.value,
colorBgElevated: colorBgElevated.value,
colorBgLayout: colorBgLayout.value,
colorBgMask: colorBgMask.value,
colorBorder: colorBorder.value,
colorError: colorError.value,
colorInfo: colorInfo.value,
colorPrimary: colorPrimary.value,
colorSuccess: colorSuccess.value,
colorTextBase: colorTextBase.value,
colorWarning: colorWarning.value,
};
});
return { return {
antDesignTokens, antDesignTokens,
borderRadius,
colorBgBase,
colorBgContainer,
colorBgElevated,
colorBorder,
colorError,
colorInfo,
colorPrimary,
colorSuccess,
colorTextBase,
colorWarning,
}; };
} }
...@@ -12,9 +12,9 @@ import { useCoreAccessStore, useCoreLockStore } from '@vben/stores'; ...@@ -12,9 +12,9 @@ import { useCoreAccessStore, useCoreLockStore } from '@vben/stores';
import { MenuRecordRaw } from '@vben/types'; import { MenuRecordRaw } from '@vben/types';
import { mapTree } from '@vben/utils'; import { mapTree } from '@vben/utils';
import { VbenAdminLayout } from '@vben-core/layout-ui'; import { VbenAdminLayout } from '@vben-core/layout-ui';
import { VbenBackTop, VbenLogo } from '@vben-core/shadcn-ui'; import { Toaster, VbenBackTop, VbenLogo } from '@vben-core/shadcn-ui';
import { Breadcrumb, Preferences } from '../widgets'; import { Breadcrumb, CheckUpdates, Preferences } from '../widgets';
import { LayoutContent } from './content'; import { LayoutContent } from './content';
import { Copyright } from './copyright'; import { Copyright } from './copyright';
import { LayoutFooter } from './footer'; import { LayoutFooter } from './footer';
...@@ -310,6 +310,12 @@ watch( ...@@ -310,6 +310,12 @@ watch(
<template #extra> <template #extra>
<slot name="extra"></slot> <slot name="extra"></slot>
<Toaster />
<CheckUpdates
v-if="preferences.app.enableCheckUpdates"
:polling-time="preferences.app.checkUpdatesPollingTime"
/>
<Transition v-if="preferences.widget.lockScreen" name="slide-up"> <Transition v-if="preferences.widget.lockScreen" name="slide-up">
<slot v-if="coreLockStore.isLockScreen" name="lock-screen"></slot> <slot v-if="coreLockStore.isLockScreen" name="lock-screen"></slot>
</Transition> </Transition>
......
<script setup lang="ts">
import { h, onMounted, onUnmounted, ref } from 'vue';
import { $t } from '@vben/locales';
import { ToastAction, useToast } from '@vben-core/shadcn-ui';
interface Props {
// 轮训时间,分钟
pollingTime?: number;
}
defineOptions({ name: 'CheckUpdates' });
const props = withDefaults(defineProps<Props>(), {
pollingTime: 1,
});
const lastVersionTag = ref('');
let isCheckingUpdates = false;
const timer = ref<ReturnType<typeof setInterval>>();
const { toast } = useToast();
async function getVersionTag() {
try {
const response = await fetch('/', {
cache: 'no-cache',
method: 'HEAD',
});
return (
response.headers.get('etag') || response.headers.get('last-modified')
);
} catch {
console.error('Failed to fetch version tag');
return null;
}
}
async function checkForUpdates() {
const versionTag = await getVersionTag();
if (!versionTag) {
return;
}
// 首次运行时不提示更新
if (!lastVersionTag.value) {
lastVersionTag.value = versionTag;
return;
}
if (lastVersionTag.value !== versionTag) {
lastVersionTag.value = versionTag;
clearInterval(timer.value);
handleNotice();
}
}
function handleNotice() {
const { dismiss } = toast({
action: h('div', [
h(
ToastAction,
{
altText: $t('common.cancel'),
onClick: () => dismiss(),
},
{
default: () => $t('common.cancel'),
},
),
h(
ToastAction,
{
altText: $t('common.refresh'),
class: 'bg-primary hover:bg-primary-hover mx-1',
onClick: () => {
window.location.reload();
},
},
{
default: () => $t('common.refresh'),
},
),
]),
description: $t('widgets.checkUpdatesDescription'),
duration: 0,
title: $t('widgets.checkUpdatesTitle'),
});
}
function start() {
// 每5分钟检查一次
timer.value = setInterval(checkForUpdates, props.pollingTime * 60 * 1000);
}
function handleVisibilitychange() {
if (document.hidden) {
stop();
} else {
if (!isCheckingUpdates) {
isCheckingUpdates = true;
checkForUpdates().finally(() => {
isCheckingUpdates = false;
start();
});
}
}
}
function stop() {
clearInterval(timer.value);
}
onMounted(() => {
start();
document.addEventListener('visibilitychange', handleVisibilitychange);
});
onUnmounted(() => {
stop();
document.removeEventListener('visibilitychange', handleVisibilitychange);
});
</script>
<template>
<slot></slot>
</template>
export { default as CheckUpdates } from './check-updates.vue';
export { default as Breadcrumb } from './breadcrumb.vue'; export { default as Breadcrumb } from './breadcrumb.vue';
export * from './check-updates';
export { default as AuthenticationColorToggle } from './color-toggle.vue'; export { default as AuthenticationColorToggle } from './color-toggle.vue';
export * from './global-search'; export * from './global-search';
export { default as LanguageToggle } from './language-toggle.vue'; export { default as LanguageToggle } from './language-toggle.vue';
......
...@@ -12,6 +12,7 @@ defineOptions({ ...@@ -12,6 +12,7 @@ defineOptions({
const appLocale = defineModel<string>('appLocale'); const appLocale = defineModel<string>('appLocale');
const appDynamicTitle = defineModel<boolean>('appDynamicTitle'); const appDynamicTitle = defineModel<boolean>('appDynamicTitle');
const appWatermark = defineModel<boolean>('appWatermark'); const appWatermark = defineModel<boolean>('appWatermark');
const appEnableCheckUpdates = defineModel<boolean>('appEnableCheckUpdates');
</script> </script>
<template> <template>
...@@ -24,4 +25,7 @@ const appWatermark = defineModel<boolean>('appWatermark'); ...@@ -24,4 +25,7 @@ const appWatermark = defineModel<boolean>('appWatermark');
<SwitchItem v-model="appWatermark"> <SwitchItem v-model="appWatermark">
{{ $t('preferences.watermark') }} {{ $t('preferences.watermark') }}
</SwitchItem> </SwitchItem>
<SwitchItem v-model="appEnableCheckUpdates">
{{ $t('preferences.checkUpdates') }}
</SwitchItem>
</template> </template>
...@@ -62,6 +62,7 @@ const appColorGrayMode = defineModel<boolean>('appColorGrayMode'); ...@@ -62,6 +62,7 @@ const appColorGrayMode = defineModel<boolean>('appColorGrayMode');
const appColorWeakMode = defineModel<boolean>('appColorWeakMode'); const appColorWeakMode = defineModel<boolean>('appColorWeakMode');
const appContentCompact = defineModel<ContentCompactType>('appContentCompact'); const appContentCompact = defineModel<ContentCompactType>('appContentCompact');
const appWatermark = defineModel<boolean>('appWatermark'); const appWatermark = defineModel<boolean>('appWatermark');
const appEnableCheckUpdates = defineModel<boolean>('appEnableCheckUpdates');
const transitionProgress = defineModel<boolean>('transitionProgress'); const transitionProgress = defineModel<boolean>('transitionProgress');
const transitionName = defineModel<string>('transitionName'); const transitionName = defineModel<string>('transitionName');
...@@ -254,6 +255,7 @@ async function handleReset() { ...@@ -254,6 +255,7 @@ async function handleReset() {
<Block :title="$t('preferences.general')"> <Block :title="$t('preferences.general')">
<General <General
v-model:app-dynamic-title="appDynamicTitle" v-model:app-dynamic-title="appDynamicTitle"
v-model:app-enable-check-updates="appEnableCheckUpdates"
v-model:app-locale="appLocale" v-model:app-locale="appLocale"
v-model:app-watermark="appWatermark" v-model:app-watermark="appWatermark"
/> />
......
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
"notifications": "Notifications", "notifications": "Notifications",
"markAllAsRead": "Make All as Read", "markAllAsRead": "Make All as Read",
"clearNotifications": "Clear", "clearNotifications": "Clear",
"checkUpdatesTitle": "New Version Available",
"checkUpdatesDescription": "Click to refresh and get the latest version",
"search": { "search": {
"title": "Search", "title": "Search",
"searchNavigate": "Search Navigation", "searchNavigate": "Search Navigation",
...@@ -166,6 +168,7 @@ ...@@ -166,6 +168,7 @@
"language": "Language", "language": "Language",
"dynamicTitle": "Dynamic Title", "dynamicTitle": "Dynamic Title",
"watermark": "Watermark", "watermark": "Watermark",
"checkUpdates": "Periodic update check",
"sidebar": { "sidebar": {
"title": "Sidebar", "title": "Sidebar",
"width": "Width", "width": "Width",
......
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
"notifications": "通知", "notifications": "通知",
"markAllAsRead": "全部标记为已读", "markAllAsRead": "全部标记为已读",
"clearNotifications": "清空", "clearNotifications": "清空",
"checkUpdatesTitle": "新版本可用",
"checkUpdatesDescription": "点击刷新以获取最新版本",
"search": { "search": {
"title": "搜索", "title": "搜索",
"searchNavigate": "搜索导航菜单", "searchNavigate": "搜索导航菜单",
...@@ -166,6 +168,7 @@ ...@@ -166,6 +168,7 @@
"language": "语言", "language": "语言",
"dynamicTitle": "动态标题", "dynamicTitle": "动态标题",
"watermark": "水印", "watermark": "水印",
"checkUpdates": "定时检查更新",
"sidebar": { "sidebar": {
"title": "侧边栏", "title": "侧边栏",
"width": "宽度", "width": "宽度",
......
import type { DefaultTheme, HeadConfig } from 'vitepress'; import type { DefaultTheme, HeadConfig } from 'vitepress';
import { resolve } from 'node:path';
import { type PwaOptions, withPwa } from '@vite-pwa/vitepress';
import { defineConfigWithTheme } from 'vitepress'; import { defineConfigWithTheme } from 'vitepress';
import { version } from '../../package.json'; import { version } from '../../package.json';
export default defineConfigWithTheme({ export default withPwa(
description: 'Vben Admin& 企业级管理系统框架', defineConfigWithTheme({
head: head(), description: 'Vben Admin& 企业级管理系统框架',
lang: 'zh', head: head(),
srcDir: 'src', lang: 'zh',
// locales: { pwa: pwa(),
// en: { // locales: {
// label: 'English', // en: {
// lang: 'en', // label: 'English',
// link: '/en/', // lang: 'en',
// }, // link: '/en/',
// root: { // },
// label: '简体中文', // root: {
// lang: 'zh-CN', // label: '简体中文',
// }, // lang: 'zh-CN',
themeConfig: { srcDir: 'src',
darkModeSwitchLabel: '主题', // },
darkModeSwitchTitle: '切换到深色模式', themeConfig: {
docFooter: { darkModeSwitchLabel: '主题',
next: '下一页', darkModeSwitchTitle: '切换到深色模式',
prev: '上一页', docFooter: {
}, next: '下一页',
editLink: { prev: '上一页',
pattern: 'https://github.com/vbenjs/vue-vben-admin/edit/main/docs/:path',
text: '在 GitHub 上编辑此页面',
},
footer: {
copyright: `Copyright © 2020-${new Date().getFullYear()} Vben`,
message: '基于 MIT 许可发布.',
},
i18nRouting: true,
langMenuLabel: '多语言',
lastUpdated: {
formatOptions: {
dateStyle: 'short',
timeStyle: 'medium',
}, },
text: '最后更新于', editLink: {
}, pattern:
lightModeSwitchTitle: '切换到浅色模式', 'https://github.com/vbenjs/vue-vben-admin/edit/main/docs/:path',
logo: 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/logo-v1.webp', text: '在 GitHub 上编辑此页面',
nav: nav(), },
outline: { footer: {
label: '页面导航', copyright: `Copyright © 2020-${new Date().getFullYear()} Vben`,
}, message: '基于 MIT 许可发布.',
returnToTopLabel: '回到顶部', },
search: { i18nRouting: true,
options: { langMenuLabel: '多语言',
locales: { lastUpdated: {
zh: { formatOptions: {
translations: { dateStyle: 'short',
button: { timeStyle: 'medium',
buttonAriaLabel: '搜索文档', },
buttonText: '搜索文档', text: '最后更新于',
}, },
modal: { lightModeSwitchTitle: '切换到浅色模式',
footer: { logo: 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/logo-v1.webp',
navigateText: '切换', nav: nav(),
selectText: '选择', outline: {
label: '页面导航',
},
returnToTopLabel: '回到顶部',
search: {
options: {
locales: {
zh: {
translations: {
button: {
buttonAriaLabel: '搜索文档',
buttonText: '搜索文档',
},
modal: {
footer: {
navigateText: '切换',
selectText: '选择',
},
noResultsText: '无法找到相关结果',
resetButtonTitle: '清除查询条件',
}, },
noResultsText: '无法找到相关结果',
resetButtonTitle: '清除查询条件',
}, },
}, },
}, },
}, },
provider: 'local',
}, },
provider: 'local', sidebar: {
}, '/commercial/': { base: '/commercial/', items: sidebarCommercial() },
sidebar: { '/guide/': { base: '/guide/', items: sidebarGuide() },
'/commercial/': { base: '/commercial/', items: sidebarCommercial() },
'/guide/': { base: '/guide/', items: sidebarGuide() },
},
sidebarMenuLabel: '菜单',
siteTitle: 'Vben Admin',
socialLinks: [
{ icon: 'github', link: 'https://github.com/vbenjs/vue-vben-admin' },
],
},
title: 'Vben Admin',
vite: {
build: {
chunkSizeWarningLimit: Infinity,
minify: 'terser',
},
json: {
stringify: true,
},
server: {
fs: {
allow: ['../..'],
}, },
host: true, sidebarMenuLabel: '菜单',
port: 6173, siteTitle: 'Vben Admin',
socialLinks: [
{ icon: 'github', link: 'https://github.com/vbenjs/vue-vben-admin' },
],
}, },
ssr: { title: 'Vben Admin',
external: ['@vue/repl'], vite: {
build: {
chunkSizeWarningLimit: Infinity,
minify: 'terser',
},
json: {
stringify: true,
},
server: {
fs: {
allow: ['../..'],
},
host: true,
port: 6173,
},
ssr: {
external: ['@vue/repl'],
},
}, },
}, }),
}); );
function nav(): DefaultTheme.NavItem[] { function nav(): DefaultTheme.NavItem[] {
return [ return [
...@@ -306,18 +313,36 @@ function head(): HeadConfig[] { ...@@ -306,18 +313,36 @@ function head(): HeadConfig[] {
// src: 'https://cdn.tailwindcss.com', // src: 'https://cdn.tailwindcss.com',
// }, // },
// ], // ],
[
'script',
{},
`
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?2e443a834727c065877c01d89921545e";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
`,
],
]; ];
} }
function pwa(): PwaOptions {
return {
includeManifestIcons: false,
manifest: {
description:
'Vben Admin is a modern admin dashboard template based on Vue 3. ',
icons: [
{
sizes: '192x192',
src: 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/pwa-icon-192.png',
type: 'image/png',
},
{
sizes: '512x512',
src: 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/pwa-icon-512.png',
type: 'image/png',
},
],
id: '/',
name: 'Vben Admin Doc',
short_name: 'vben_admin_doc',
theme_color: '#ffffff',
},
outDir: resolve(process.cwd(), '.vitepress/dist'),
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{css,js,html,svg,png,ico,txt,woff2}'],
},
};
}
...@@ -5,14 +5,17 @@ import DefaultTheme from 'vitepress/theme'; ...@@ -5,14 +5,17 @@ import DefaultTheme from 'vitepress/theme';
import SiteLayout from './components/site-layout.vue'; import SiteLayout from './components/site-layout.vue';
import VbenContributors from './components/vben-contributors.vue'; import VbenContributors from './components/vben-contributors.vue';
import { initHmPlugin } from './plugins/hm';
import './styles'; import './styles';
export default { export default {
// eslint-disable-next-line @typescript-eslint/no-unused-vars enhanceApp({ app }) {
enhanceApp({ app, router, siteData }) {
// ... // ...
app.component('VbenContributors', VbenContributors); app.component('VbenContributors', VbenContributors);
// 百度统计
initHmPlugin();
}, },
extends: DefaultTheme, extends: DefaultTheme,
Layout: SiteLayout, Layout: SiteLayout,
......
import { inBrowser } from 'vitepress';
const SITE_ID = '2e443a834727c065877c01d89921545e';
declare global {
interface Window {
_hmt: any;
}
}
function registerAnalytics() {
window._hmt = window._hmt || [];
const script = document.createElement('script');
script.innerHTML = `var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?${SITE_ID}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})()`;
document.querySelector('head')?.append(script);
}
export function initHmPlugin() {
if (inBrowser && import.meta.env.PROD) {
registerAnalytics(SITE_ID);
}
}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"medium-zoom": "^1.1.0" "medium-zoom": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"@vite-pwa/vitepress": "^0.5.0",
"vitepress": "^1.3.1", "vitepress": "^1.3.1",
"vue": "^3.4.34" "vue": "^3.4.34"
} }
......
...@@ -174,6 +174,7 @@ const defaultPreferences: Preferences = { ...@@ -174,6 +174,7 @@ const defaultPreferences: Preferences = {
app: { app: {
accessMode: 'frontend', accessMode: 'frontend',
authPageLayout: 'panel-right', authPageLayout: 'panel-right',
checkUpdatesPollingTime: 1,
colorGrayMode: false, colorGrayMode: false,
colorWeakMode: false, colorWeakMode: false,
compact: false, compact: false,
...@@ -181,11 +182,12 @@ const defaultPreferences: Preferences = { ...@@ -181,11 +182,12 @@ const defaultPreferences: Preferences = {
defaultAvatar: defaultAvatar:
'https://unpkg.com/@vbenjs/static-source@0.1.5/source/avatar-v1.webp', 'https://unpkg.com/@vbenjs/static-source@0.1.5/source/avatar-v1.webp',
dynamicTitle: true, dynamicTitle: true,
enableCheckUpdates: true,
enablePreferences: true, enablePreferences: true,
isMobile: false, isMobile: false,
layout: 'sidebar-nav', layout: 'sidebar-nav',
locale: 'zh-CN', locale: 'zh-CN',
loginExpiredMode: 'page', loginExpiredMode: 'modal',
name: 'Vben Admin', name: 'Vben Admin',
watermark: false, watermark: false,
}, },
...@@ -288,6 +290,8 @@ interface AppPreferences { ...@@ -288,6 +290,8 @@ interface AppPreferences {
accessMode: AccessModeType; accessMode: AccessModeType;
/** 登录注册页面布局 */ /** 登录注册页面布局 */
authPageLayout: AuthPageLayoutType; authPageLayout: AuthPageLayoutType;
/** 检查更新轮询时间 */
checkUpdatesPollingTime: number;
/** 是否开启灰色模式 */ /** 是否开启灰色模式 */
colorGrayMode: boolean; colorGrayMode: boolean;
/** 是否开启色弱模式 */ /** 是否开启色弱模式 */
...@@ -300,6 +304,8 @@ interface AppPreferences { ...@@ -300,6 +304,8 @@ interface AppPreferences {
defaultAvatar: string; defaultAvatar: string;
// /** 开启动态标题 */ // /** 开启动态标题 */
dynamicTitle: boolean; dynamicTitle: boolean;
/** 是否开启检查更新 */
enableCheckUpdates: boolean;
/** 是否显示偏好设置 */ /** 是否显示偏好设置 */
enablePreferences: boolean; enablePreferences: boolean;
/** 是否移动端 */ /** 是否移动端 */
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
4. 在下面列表找不到问题可以到 issue 提问 [issues](https://github.com/vbenjs/vue-vben-admin/issues) 4. 在下面列表找不到问题可以到 issue 提问 [issues](https://github.com/vbenjs/vue-vben-admin/issues)
5. 如果不是问题类型的,需要讨论的,请到 [discussions](https://github.com/vbenjs/vue-vben-admin/discussions) 讨论 5. 如果不是问题类型的,需要讨论的,请到 [discussions](https://github.com/vbenjs/vue-vben-admin/discussions) 讨论
## 依赖安装问题 ## 依赖问题
在 `Monorepo` 项目下,需要养成每次 `git pull`代码都要执行`pnpm install`的习惯,因为经常会有新的依赖包加入,项目在`.husky/git-merge`已经配置了自动执行`pnpm install`,但是有时候会出现问题,如果没有自动执行,建议手动执行一次。 在 `Monorepo` 项目下,需要养成每次 `git pull`代码都要执行`pnpm install`的习惯,因为经常会有新的依赖包加入,项目在`.husky/git-merge`已经配置了自动执行`pnpm install`,但是有时候会出现问题,如果没有自动执行,建议手动执行一次。
...@@ -135,3 +135,21 @@ at Object.extractor (vue-vben-admin-main\node_modules@purge-icons\core\dist\inde ...@@ -135,3 +135,21 @@ at Object.extractor (vue-vben-admin-main\node_modules@purge-icons\core\dist\inde
at Extract (vue-vben-admin-main\node_modules@purge-icons\core\dist\index.js:173:54) at Extract (vue-vben-admin-main\node_modules@purge-icons\core\dist\index.js:173:54)
``` ```
## nginx 部署
部署到 `nginx`后,可能会出现以下错误:
```bash
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.
```
解决方式:
```bash
http {
types {
application/javascript js mjs;
}
}
```
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@vben/tsconfig/web.json",
"include": [".vitepress/*.mts", ".vitepress/**/*.ts", ".vitepress/**/*.vue"],
"exclude": ["node_modules"]
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!