diff --git a/build/vite/plugin/html.ts b/build/vite/plugin/html.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b107f439d4f4cc5c52154c8aaab10a7f10d2e3f --- /dev/null +++ b/build/vite/plugin/html.ts @@ -0,0 +1,32 @@ +import type { Plugin } from 'vite'; +import ViteHtmlPlugin from 'vite-plugin-html'; +import { isProdFn, isSiteMode, ViteEnv } from '../../utils'; + +import { hmScript } from '../hm'; +// @ts-ignore +import pkg from '../../../package.json'; +import { GLOB_CONFIG_FILE_NAME } from '../../constant'; + +export function setupHtmlPlugin(plugins: Plugin[], env: ViteEnv) { + const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env; + + const htmlPlugin = ViteHtmlPlugin({ + // html title + title: VITE_GLOB_APP_TITLE, + minify: isProdFn(), + options: { + // Package and insert additional configuration files + injectConfig: isProdFn() + ? `` + : '', + // Insert Baidu statistics code + hmScript: isSiteMode() ? hmScript : '', + title: VITE_GLOB_APP_TITLE, + }, + }); + + plugins.push(htmlPlugin); + return plugins; +} diff --git a/build/vite/plugin/index.ts b/build/vite/plugin/index.ts index 86323b117c5501044152fac984f43f1db435c7ee..922432fd638e1a08f6a6c8a18deaef8105bf418c 100644 --- a/build/vite/plugin/index.ts +++ b/build/vite/plugin/index.ts @@ -1,84 +1,32 @@ import type { Plugin as VitePlugin } from 'vite'; import type { Plugin as rollupPlugin } from 'rollup'; -import { createMockServer } from 'vite-plugin-mock'; -import { VitePWA } from 'vite-plugin-pwa'; -import ViteHtmlPlugin from 'vite-plugin-html'; import PurgeIcons from 'vite-plugin-purge-icons'; import visualizer from 'rollup-plugin-visualizer'; import gzipPlugin from './gzip/index'; -import { hmScript } from '../hm'; - // @ts-ignore import pkg from '../../../package.json'; -import { isDevFn, isProdFn, isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils'; -import { GLOB_CONFIG_FILE_NAME } from '../../constant'; +import { isProdFn, isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils'; +import { setupHtmlPlugin } from './html'; +import { setupPwaPlugin } from './pwa'; +import { setupMockPlugin } from './mock'; // gen vite plugins export function createVitePlugins(viteEnv: ViteEnv) { - const { VITE_USE_MOCK, VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH, VITE_USE_PWA } = viteEnv; - const vitePlugins: VitePlugin[] = []; // vite-plugin-html - vitePlugins.push( - ViteHtmlPlugin({ - // html title - title: VITE_GLOB_APP_TITLE, - minify: isProdFn(), - options: { - // Package and insert additional configuration files - injectConfig: isProdFn() - ? `` - : '', - // Insert Baidu statistics code - hmScript: isSiteMode() ? hmScript : '', - title: VITE_GLOB_APP_TITLE, - }, - }) - ); + setupHtmlPlugin(vitePlugins, viteEnv); + // vite-plugin-pwa + setupPwaPlugin(vitePlugins, viteEnv); + // vite-plugin-mock + setupMockPlugin(vitePlugins, viteEnv); // vite-plugin-purge-icons vitePlugins.push(PurgeIcons()); - if (isProdFn() && VITE_USE_PWA) { - vitePlugins.push( - VitePWA({ - manifest: { - name: 'Vben Admin', - short_name: 'vben_admin', - icons: [ - { - src: './resource/img/pwa-192x192.png', - sizes: '192x192', - type: 'image/png', - }, - { - src: './resource/img/pwa-512x512.png', - sizes: '512x512', - type: 'image/png', - }, - ], - }, - }) - ); - } - - // vite-plugin-mock - if (isDevFn() && VITE_USE_MOCK) { - // open mock - vitePlugins.push( - createMockServer({ - ignore: /^\_/, - mockPath: 'mock', - showTime: true, - }) - ); - } return vitePlugins; } @@ -86,17 +34,15 @@ export function createVitePlugins(viteEnv: ViteEnv) { export function createRollupPlugin() { const rollupPlugins: rollupPlugin[] = []; - if (isProdFn()) { - if (isReportMode()) { - // rollup-plugin-visualizer - rollupPlugins.push( - visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin - ); - } - if (isBuildGzip() || isSiteMode()) { - // rollup-plugin-gizp - rollupPlugins.push(gzipPlugin()); - } + if (!isProdFn() && isReportMode()) { + // rollup-plugin-visualizer + rollupPlugins.push(visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin); } + + if (!isProdFn() && (isBuildGzip() || isSiteMode())) { + // rollup-plugin-gizp + rollupPlugins.push(gzipPlugin()); + } + return rollupPlugins; } diff --git a/build/vite/plugin/mock.ts b/build/vite/plugin/mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..ee720a468aa4b483a48fac9b4cadcbd20c52760a --- /dev/null +++ b/build/vite/plugin/mock.ts @@ -0,0 +1,16 @@ +import { createMockServer } from 'vite-plugin-mock'; +import type { Plugin } from 'vite'; +import { isDevFn, ViteEnv } from '../../utils'; + +export function setupMockPlugin(plugins: Plugin[], env: ViteEnv) { + const { VITE_USE_MOCK } = env; + const mockPlugin = createMockServer({ + ignore: /^\_/, + mockPath: 'mock', + showTime: true, + }); + if (isDevFn() && VITE_USE_MOCK) { + plugins.push(mockPlugin); + } + return plugins; +} diff --git a/build/vite/plugin/pwa.ts b/build/vite/plugin/pwa.ts new file mode 100644 index 0000000000000000000000000000000000000000..0748696397c58dfe0d49f21f2c4157b78c85a771 --- /dev/null +++ b/build/vite/plugin/pwa.ts @@ -0,0 +1,31 @@ +import { VitePWA } from 'vite-plugin-pwa'; +import type { Plugin } from 'vite'; +import { isProdFn, ViteEnv } from '../../utils'; + +export function setupPwaPlugin(plugins: Plugin[], env: ViteEnv) { + const { VITE_USE_PWA } = env; + + const pwaPlugin = VitePWA({ + manifest: { + name: 'Vben Admin', + short_name: 'vben_admin', + icons: [ + { + src: './resource/img/pwa-192x192.png', + sizes: '192x192', + type: 'image/png', + }, + { + src: './resource/img/pwa-512x512.png', + sizes: '512x512', + type: 'image/png', + }, + ], + }, + }); + + if (isProdFn() && VITE_USE_PWA) { + plugins.push(pwaPlugin); + } + return plugins; +} diff --git a/src/components/Menu/src/BasicMenu.tsx b/src/components/Menu/src/BasicMenu.tsx index 32a83d250ed7e60e584e4abcb717c2f60e6bcf9f..91d6cb2aa4efa194678354055ffa349a36ce344c 100644 --- a/src/components/Menu/src/BasicMenu.tsx +++ b/src/components/Menu/src/BasicMenu.tsx @@ -103,7 +103,7 @@ export default defineComponent({ const isHorizontal = unref(getIsHorizontal) || getSplit.value; return { - height: isHorizontal ? `calc(100%)` : `calc(100% - ${props.showLogo ? '48px' : '0px'})`, + height: isHorizontal ? '100%' : `calc(100% - ${props.showLogo ? '48px' : '0px'})`, overflowY: isHorizontal ? 'hidden' : 'auto', }; } diff --git a/src/hooks/web/useI18n.ts b/src/hooks/web/useI18n.ts index 34bcb2c28cda73cb1c58e2bf1c4501fc55e9db75..9c10e98ec2c9560841e808506caaca8a10b595d7 100644 --- a/src/hooks/web/useI18n.ts +++ b/src/hooks/web/useI18n.ts @@ -25,9 +25,9 @@ export function useI18n(namespace?: string) { return { ...methods, - t: (key: string, ...arg: Parameters) => { + t: (key: string, ...arg: Partial>) => { if (!key) return ''; - return t(getKey(key), ...arg); + return t(getKey(key), ...(arg as Parameters)); }, }; } diff --git a/src/layouts/default/setting/SettingDrawer.tsx b/src/layouts/default/setting/SettingDrawer.tsx index 9bcdbe1180f49cb4b774737cfd0577814b8ffde0..d738ced051aba1a2be9c001a3ec7a57251ee16d3 100644 --- a/src/layouts/default/setting/SettingDrawer.tsx +++ b/src/layouts/default/setting/SettingDrawer.tsx @@ -1,18 +1,17 @@ -import type { ProjectConfig } from '/@/types/config'; - -import defaultSetting from '/@/settings/projectSetting'; - -import { defineComponent, computed, unref, FunctionalComponent } from 'vue'; +import { defineComponent, computed, unref } from 'vue'; import { BasicDrawer } from '/@/components/Drawer/index'; -import { Divider, Switch, Tooltip, InputNumber, Select } from 'ant-design-vue'; -import { Button } from '/@/components/Button'; -import { CopyOutlined, RedoOutlined, CheckOutlined } from '@ant-design/icons-vue'; +import { Divider } from 'ant-design-vue'; +import { + TypePicker, + ThemePicker, + SettingFooter, + SwitchItem, + SelectItem, + InputNumberItem, +} from './components'; import { MenuTypeEnum } from '/@/enums/menuEnum'; -import { appStore } from '/@/store/modules/app'; -import { useMessage } from '/@/hooks/web/useMessage'; -import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard'; import { useRootSetting } from '/@/hooks/setting/useRootSetting'; import { useMenuSetting } from '/@/hooks/setting/useMenuSetting'; import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting'; @@ -20,8 +19,6 @@ import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; import { useI18n } from '/@/hooks/web/useI18n'; -import { updateColorWeak, updateGrayMode } from '/@/setup/theme'; - import { baseHandler } from './handler'; import { @@ -35,146 +32,8 @@ import { import { HEADER_PRESET_BG_COLOR_LIST, SIDE_BAR_BG_COLOR_LIST } from '/@/settings/colorSetting'; -interface SwitchOptions { - config?: DeepPartial; - def?: any; - disabled?: boolean; - handler?: Fn; -} - -interface SelectConfig { - options?: LabelValueOptions; - def?: any; - disabled?: boolean; - handler?: Fn; -} - -interface ThemePickerProps { - colorList: string[]; - handler: Fn; - def: string; -} - -const { createSuccessModal, createMessage } = useMessage(); const { t } = useI18n(); -/** - * Menu type Picker comp - */ -const MenuTypePicker: FunctionalComponent = () => { - const { getIsHorizontal, getMenuType } = useMenuSetting(); - return ( -
- {menuTypeList.map((item) => { - const { title, type: ItemType, mode, src } = item; - return ( - - {{ - default: () => ( -
- - -
- ), - }} -
- ); - })} -
- ); -}; - -const ThemePicker: FunctionalComponent = (props) => { - return ( -
- {props.colorList.map((color) => { - return ( - props.handler?.(color)} - key={color} - class={[props.def === color ? 'active' : '']} - style={{ - background: color, - }} - > - - - ); - })} -
- ); -}; - -/** - * FooterButton component - */ -const FooterButton: FunctionalComponent = () => { - const { getRootSetting } = useRootSetting(); - function handleCopy() { - const { isSuccessRef } = useCopyToClipboard(JSON.stringify(unref(getRootSetting), null, 2)); - unref(isSuccessRef) && - createSuccessModal({ - title: t('layout.setting.operatingTitle'), - content: t('layout.setting.operatingContent'), - }); - } - function handleResetSetting() { - try { - appStore.commitProjectConfigState(defaultSetting); - const { colorWeak, grayMode } = defaultSetting; - // updateTheme(themeColor); - updateColorWeak(colorWeak); - updateGrayMode(grayMode); - createMessage.success(t('layout.setting.resetSuccess')); - } catch (error) { - createMessage.error(error); - } - } - - function handleClearAndRedo() { - localStorage.clear(); - appStore.resumeAllState(); - location.reload(); - } - - return ( - - ); -}; - export default defineComponent({ name: 'SettingDrawer', setup(_, { attrs }) { @@ -187,6 +46,7 @@ export default defineComponent({ getFullContent, getColorWeak, getGrayMode, + getLockTime, } = useRootSetting(); const { @@ -229,38 +89,44 @@ export default defineComponent({ function renderSidebar() { return ( <> - - {renderSwitchItem(t('layout.setting.splitMenu'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_SPLIT, e); - }, - def: unref(getSplit), - disabled: !unref(getShowMenuRef) || unref(getMenuType) !== MenuTypeEnum.MIX, - })} + { + baseHandler(HandlerEnum.CHANGE_LAYOUT, { + mode: item.mode, + type: item.type, + split: unref(getIsHorizontal) ? false : undefined, + }); + }} + def={unref(getMenuType)} + /> + ); } - function renderTheme() { + function renderHeaderTheme() { return ( - <> - {() => t('layout.setting.headerTheme')} - { - baseHandler(HandlerEnum.HEADER_THEME, e); - }} - /> - {() => t('layout.setting.sidebarTheme')} - { - baseHandler(HandlerEnum.MENU_THEME, e); - }} - /> - + + ); + } + + function renderSiderTheme() { + return ( + ); } @@ -268,264 +134,192 @@ export default defineComponent({ * @description: */ function renderFeatures() { - return [ - renderSwitchItem(t('layout.setting.menuDrag'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_HAS_DRAG, e); - }, - def: unref(getCanDrag), - disabled: !unref(getShowMenuRef), - }), - renderSwitchItem(t('layout.setting.menuSearch'), { - handler: (e) => { - baseHandler(HandlerEnum.HEADER_SEARCH, e); - }, - def: unref(getShowSearch), - disabled: !unref(getShowHeader), - }), - renderSwitchItem(t('layout.setting.menuAccordion'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_ACCORDION, e); - }, - def: unref(getAccordion), - disabled: !unref(getShowMenuRef), - }), - renderSwitchItem(t('layout.setting.menuCollapse'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_COLLAPSED, e); - }, - def: unref(getCollapsed), - disabled: !unref(getShowMenuRef), - }), - renderSwitchItem(t('layout.setting.collapseMenuDisplayName'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_COLLAPSED_SHOW_TITLE, e); - }, - def: unref(getCollapsedShowTitle), - disabled: !unref(getShowMenuRef) || !unref(getCollapsed), - }), - renderSwitchItem(t('layout.setting.fixedHeader'), { - handler: (e) => { - baseHandler(HandlerEnum.HEADER_FIXED, e); - }, - def: unref(getHeaderFixed), - disabled: !unref(getShowHeader), - }), - renderSwitchItem(t('layout.setting.fixedSideBar'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_FIXED, e); - }, - def: unref(getMenuFixed), - disabled: !unref(getShowMenuRef), - }), - renderSelectItem(t('layout.setting.topMenuLayout'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_TOP_ALIGN, e); - }, - def: unref(getTopMenuAlign), - options: topMenuAlignOptions, - disabled: !unref(getShowHeader) || (!unref(getIsTopMenu) && !unref(getSplit)), - }), - renderSelectItem(t('layout.setting.menuCollapseButton'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_TRIGGER, e); - }, - disabled: !unref(getShowMenuRef), - def: unref(getTrigger), - options: menuTriggerOptions, - }), - - renderSelectItem(t('layout.setting.contentMode'), { - handler: (e) => { - baseHandler(HandlerEnum.CONTENT_MODE, e); - }, - def: unref(getContentMode), - options: contentModeOptions, - }), -
- {t('layout.setting.autoScreenLock')} - + + + + + + + + + + + { - baseHandler(HandlerEnum.LOCK_TIME, e); - }} - defaultValue={appStore.getProjectConfig.lockTime} + event={HandlerEnum.LOCK_TIME} + defaultValue={unref(getLockTime)} formatter={(value: string) => { - if (parseInt(value) === 0) { - return `0(${t('layout.setting.notAutoScreenLock')})`; - } - return `${value}${t('layout.setting.minute')}`; + return parseInt(value) === 0 + ? `0(${t('layout.setting.notAutoScreenLock')})` + : `${value}${t('layout.setting.minute')}`; }} /> -
, -
- {t('layout.setting.expandedMenuWidth')} - `${parseInt(value)}px`} - onChange={(e: any) => { - baseHandler(HandlerEnum.MENU_WIDTH, e); - }} /> -
, - ]; + + ); } function renderContent() { - return [ - renderSwitchItem(t('layout.setting.breadcrumb'), { - handler: (e) => { - baseHandler(HandlerEnum.SHOW_BREADCRUMB, e); - }, - def: unref(getShowBreadCrumb), - disabled: !unref(getShowHeader), - }), - renderSwitchItem(t('layout.setting.breadcrumbIcon'), { - handler: (e) => { - baseHandler(HandlerEnum.SHOW_BREADCRUMB_ICON, e); - }, - def: unref(getShowBreadCrumbIcon), - disabled: !unref(getShowHeader), - }), - renderSwitchItem(t('layout.setting.tabs'), { - handler: (e) => { - baseHandler(HandlerEnum.TABS_SHOW, e); - }, - def: unref(getShowMultipleTab), - }), - renderSwitchItem(t('layout.setting.tabsQuickBtn'), { - handler: (e) => { - baseHandler(HandlerEnum.TABS_SHOW_QUICK, e); - }, - def: unref(getShowQuick), - disabled: !unref(getShowMultipleTab), - }), - - renderSwitchItem(t('layout.setting.sidebar'), { - handler: (e) => { - baseHandler(HandlerEnum.MENU_SHOW_SIDEBAR, e); - }, - def: unref(getShowMenu), - disabled: unref(getIsHorizontal), - }), - renderSwitchItem(t('layout.setting.header'), { - handler: (e) => { - baseHandler(HandlerEnum.HEADER_SHOW, e); - }, - def: unref(getShowHeader), - }), - renderSwitchItem('Logo', { - handler: (e) => { - baseHandler(HandlerEnum.SHOW_LOGO, e); - }, - def: unref(getShowLogo), - }), - renderSwitchItem(t('layout.setting.footer'), { - handler: (e) => { - baseHandler(HandlerEnum.SHOW_FOOTER, e); - }, - def: unref(getShowFooter), - }), - renderSwitchItem(t('layout.setting.fullContent'), { - handler: (e) => { - baseHandler(HandlerEnum.FULL_CONTENT, e); - }, - def: unref(getFullContent), - }), - renderSwitchItem(t('layout.setting.grayMode'), { - handler: (e) => { - baseHandler(HandlerEnum.GRAY_MODE, e); - }, - def: unref(getGrayMode), - }), - renderSwitchItem(t('layout.setting.colorWeak'), { - handler: (e) => { - baseHandler(HandlerEnum.COLOR_WEAK, e); - }, - def: unref(getColorWeak), - }), - ]; - } - - function renderTransition() { return ( <> - {renderSwitchItem(t('layout.setting.progress'), { - handler: (e) => { - baseHandler(HandlerEnum.OPEN_PROGRESS, e); - }, - def: unref(getOpenNProgress), - })} - {renderSwitchItem(t('layout.setting.switchLoading'), { - handler: (e) => { - baseHandler(HandlerEnum.OPEN_PAGE_LOADING, e); - }, - def: unref(getOpenPageLoading), - })} + + + + + + + + + + + + + + - {renderSwitchItem(t('layout.setting.switchAnimation'), { - handler: (e) => { - baseHandler(HandlerEnum.OPEN_ROUTE_TRANSITION, e); - }, - def: unref(getEnableTransition), - })} + - {renderSelectItem(t('layout.setting.animationType'), { - handler: (e) => { - baseHandler(HandlerEnum.ROUTER_TRANSITION, e); - }, - def: unref(getBasicTransition), - options: routerTransitionOptions, - disabled: !unref(getEnableTransition), - })} + ); } - function renderSelectItem(text: string, config?: SelectConfig) { - const { handler, def, disabled = false, options } = config || {}; - const opt = def ? { value: def, defaultValue: def } : {}; + function renderTransition() { return ( -
- {text} -