From 4984da592c45910db9958c09bc2733d7523d77ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Sun, 20 Feb 2022 00:13:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SizeSelect/index.vue | 54 +++++++++++++++++++++++++++++ src/main.ts | 10 ++++-- src/store/modules/app.ts | 21 ++++++----- src/store/modules/tagsView.ts | 6 ++-- 4 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 src/components/SizeSelect/index.vue diff --git a/src/components/SizeSelect/index.vue b/src/components/SizeSelect/index.vue new file mode 100644 index 00000000..aaa643b0 --- /dev/null +++ b/src/components/SizeSelect/index.vue @@ -0,0 +1,54 @@ + + + + + \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 778e8ece..0dff71dd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,10 +2,11 @@ import {createApp, Directive} from 'vue' import App from './App.vue' import router from "./router"; import '@/styles/index.scss' -import { store } from "./store"; +import {store} from "@/store"; import ElementPlus from 'element-plus' import 'element-plus/theme-chalk/index.css' import locale from 'element-plus/lib/locale/lang/zh-cn' +import {Local} from "@/utils/storage"; import 'virtual:svg-icons-register'; // @see https://blog.csdn.net/qq_37213281/article/details/121422027 @@ -19,6 +20,8 @@ const app = createApp(App) // 自定义指令 import * as directive from "@/directive"; + + Object.keys(directive).forEach(key => { app.directive(key, (directive as { [key: string]: Directive })[key]); }); @@ -30,8 +33,9 @@ for (let iconName in ElIconModules) { // 全局方法 app.config.globalProperties.$listDictsByCode = listDictsByCode + app.component('Pagination', Pagination) // 全局组件 - .use(store) + .use(store) .use(router) - .use(ElementPlus, {locale}) + .use(ElementPlus, {locale: locale, size: Local.get('size')||'small'}) .mount('#app') diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index c2ba1519..a0df8aaa 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -1,21 +1,21 @@ import {AppState} from "@/store/interface"; import {Local} from "@/utils/storage"; -import { store } from "@/store"; -import { defineStore } from "pinia"; +import {store} from "@/store"; +import {defineStore} from "pinia"; export const useAppStore = defineStore({ id: "app", - state: ():AppState=>({ + state: (): AppState => ({ device: 'desktop', sidebar: { opened: Local.get('sidebarStatus') ? !!+Local.get('sidebarStatus') : true, withoutAnimation: false }, - language:'zh', - size:'medium' + language: 'zh', + size: Local.get('size')||'default' }), actions: { - toggleSidebar() { + toggleSidebar() { this.sidebar.opened = !this.sidebar.opened this.sidebar.withoutAnimation = false if (this.sidebar.opened) { @@ -24,16 +24,21 @@ export const useAppStore = defineStore({ Local.set('sidebarStatus', 0) } }, - closeSideBar ( withoutAnimation:any) { + closeSideBar(withoutAnimation: any) { Local.set('sidebarStatus', 0) this.sidebar.opened = false this.sidebar.withoutAnimation = withoutAnimation }, - toggleDevice( device:any) { + toggleDevice(device: string) { this.device = device + }, + setSize(size: string) { + this.size = size + Local.set('size', size) } } }) + export function useAppStoreHook() { return useAppStore(store); } diff --git a/src/store/modules/tagsView.ts b/src/store/modules/tagsView.ts index ef045c04..c9213259 100644 --- a/src/store/modules/tagsView.ts +++ b/src/store/modules/tagsView.ts @@ -2,7 +2,7 @@ import {defineStore} from "pinia"; import {store} from "@/store"; import {TagsViewState} from "@/store/interface"; -const tagsViewStore = defineStore({ +const useTagsViewStore = defineStore({ id: "tagsView", state: (): TagsViewState => ({ visitedViews: [], @@ -174,7 +174,7 @@ const tagsViewStore = defineStore({ }) -export function tagsViewStoreHook() { - return tagsViewStore(store); +export function useTagsViewStoreHook() { + return useTagsViewStore(store); }