diff --git a/plop-templates/component/index.hbs b/plop-templates/component/index.hbs index e5eb12a2..2ca042bb 100644 --- a/plop-templates/component/index.hbs +++ b/plop-templates/component/index.hbs @@ -1,5 +1,6 @@ diff --git a/plop-templates/page/index.hbs b/plop-templates/page/index.hbs index e24a994a..390fefb3 100644 --- a/plop-templates/page/index.hbs +++ b/plop-templates/page/index.hbs @@ -1,5 +1,4 @@ diff --git a/src/layout/components/AppSetting/index.vue b/src/layout/components/AppSetting/index.vue index f6b7f3ff..d1ca2f0e 100644 --- a/src/layout/components/AppSetting/index.vue +++ b/src/layout/components/AppSetting/index.vue @@ -1,10 +1,10 @@ @@ -19,7 +18,7 @@ const switchMenu = inject('switchMenu') - + diff --git a/src/layout/components/MainSidebar/index.vue b/src/layout/components/MainSidebar/index.vue index 34dcdf37..53e08954 100644 --- a/src/layout/components/MainSidebar/index.vue +++ b/src/layout/components/MainSidebar/index.vue @@ -2,11 +2,10 @@ import Logo from '../Logo/index.vue' import useSettingsStore from '@/store/modules/settings' import useMenuStore from '@/store/modules/menu' +import { useMenu } from '@/util/composables' const settingsStore = useSettingsStore() const menuStore = useMenuStore() - -const switchMenu = inject('switchMenu') @@ -20,7 +19,7 @@ const switchMenu = inject('switchMenu') v-if="item.children && item.children.length !== 0" :key="index" :class="{ 'item': true, 'active': index === menuStore.actived - }" :title="item.meta.title" @click="switchMenu(index)" + }" :title="item.meta.title" @click="useMenu().switchTo(index)" > diff --git a/src/layout/components/Search/index.vue b/src/layout/components/Search/index.vue index 858031fc..310f24b9 100644 --- a/src/layout/components/Search/index.vue +++ b/src/layout/components/Search/index.vue @@ -1,11 +1,11 @@ - + - + @@ -220,9 +228,9 @@ function handleScroll() { - + - + diff --git a/src/layout/components/Tools/index.vue b/src/layout/components/Tools/index.vue index 71c5ae99..b6018192 100644 --- a/src/layout/components/Tools/index.vue +++ b/src/layout/components/Tools/index.vue @@ -1,9 +1,10 @@ diff --git a/src/main.js b/src/main.js index 27a5ea47..89dae636 100644 --- a/src/main.js +++ b/src/main.js @@ -10,9 +10,6 @@ app.use(router) /* importElementPlusPlaceholder */ -import globalProperties from '@/util/global.properties' -globalProperties(app) - // 自定义指令 import directive from '@/util/directive' directive(app) diff --git a/src/util/composables/index.js b/src/util/composables/index.js index 28c96ccb..f3593063 100644 --- a/src/util/composables/index.js +++ b/src/util/composables/index.js @@ -1,5 +1,9 @@ import useAuth from './auth' +import useMainPage from './mainPage' +import useMenu from './menu' export { - useAuth + useAuth, + useMainPage, + useMenu } diff --git a/src/util/composables/mainPage/index.js b/src/util/composables/mainPage/index.js new file mode 100644 index 00000000..52ded1e3 --- /dev/null +++ b/src/util/composables/mainPage/index.js @@ -0,0 +1,15 @@ +import router from '@/router' + +function useMainPage() { + function reload() { + router.push({ + name: 'reload' + }) + } + + return { + reload + } +} + +export default useMainPage diff --git a/src/util/composables/menu/index.js b/src/util/composables/menu/index.js new file mode 100644 index 00000000..599b3099 --- /dev/null +++ b/src/util/composables/menu/index.js @@ -0,0 +1,24 @@ +import router from '@/router' +import useSettingsStore from '@/store/modules/settings' +import useMenuStore from '@/store/modules/menu' +import { isExternalLink } from '@/util' + +export default function useMenu() { + const settingsStore = useSettingsStore() + const menuStore = useMenuStore() + + function switchTo(index) { + menuStore.setActived(index) + if (settingsStore.menu.switchMainMenuAndPageJump) { + if (isExternalLink(menuStore.sidebarMenusFirstDeepestPath)) + window.open(menuStore.sidebarMenusFirstDeepestPath, '_blank') + + else + router.push(menuStore.sidebarMenusFirstDeepestPath) + } + } + + return { + switchTo + } +} diff --git a/src/util/eventBus.js b/src/util/eventBus.js new file mode 100644 index 00000000..9ea06008 --- /dev/null +++ b/src/util/eventBus.js @@ -0,0 +1,3 @@ +import mitt from 'mitt' + +export default mitt() diff --git a/src/util/global.properties.js b/src/util/global.properties.js deleted file mode 100644 index 8a9d9224..00000000 --- a/src/util/global.properties.js +++ /dev/null @@ -1,21 +0,0 @@ -import api from '@/api' -import { useAuth } from '@/util/composables' -import dayjs from 'dayjs' -import 'dayjs/locale/zh-cn' -import Cookies from 'js-cookie' -import hotkeys from 'hotkeys-js' -import mitt from 'mitt' - -export default function globalProperties(app) { - // 请求 - app.config.globalProperties.$api = api - // 鉴权 - const { auth, authAll } = useAuth() - app.config.globalProperties.$auth = auth - app.config.globalProperties.$authAll = authAll - dayjs.locale('zh-cn') - app.config.globalProperties.$dayjs = dayjs - app.config.globalProperties.$cookies = Cookies - app.config.globalProperties.$hotkeys = hotkeys - app.config.globalProperties.$eventBus = mitt() -} diff --git a/src/views/login.vue b/src/views/login.vue index 17b29397..96164dbd 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -12,7 +12,6 @@ import useSettingsStore from '@/store/modules/settings' import useUserStore from '@/store/modules/user' -const { proxy } = getCurrentInstance() const route = useRoute(), router = useRouter() const settingsStore = useSettingsStore() @@ -25,6 +24,7 @@ const title = import.meta.env.VITE_APP_TITLE const formType = ref('login') // 登录 +const loginFormRef = ref() const loginForm = ref({ account: localStorage.login_account || '', password: '', @@ -40,7 +40,7 @@ const loginRules = ref({ ] }) function handleLogin() { - proxy.$refs.loginFormRef.validate(valid => { + loginFormRef.value.validate(valid => { if (valid) { loading.value = true userStore.login(loginForm.value).then(() => { @@ -59,6 +59,7 @@ function handleLogin() { } // 注册 +const registerFormRef = ref() const registerForm = ref({ account: '', captcha: '', @@ -92,7 +93,7 @@ function handleRegister() { message: '注册模块仅提供界面演示,无实际功能,需开发者自行扩展', type: 'warning' }) - proxy.$refs.registerFormRef.validate(valid => { + registerFormRef.value.validate(valid => { if (valid) { // 这里编写业务代码 } @@ -100,6 +101,7 @@ function handleRegister() { } // 重置密码 +const resetFormRef = ref() const resetForm = ref({ account: localStorage.login_account || '', captcha: '', @@ -122,7 +124,7 @@ function handleReset() { message: '重置密码模块仅提供界面演示,无实际功能,需开发者自行扩展', type: 'warning' }) - proxy.$refs.resetFormRef.validate(valid => { + resetFormRef.value.validate(valid => { if (valid) { // 这里编写业务代码 } @@ -132,6 +134,7 @@ function handleReset() { const loading = ref(false) const passwordType = ref('password') const redirect = ref(null) +const passwordRef = ref() onMounted(() => { redirect.value = route.query.redirect ?? '/' @@ -140,7 +143,7 @@ onMounted(() => { function showPassword() { passwordType.value = passwordType.value === 'password' ? '' : 'password' nextTick(() => { - proxy.$refs.password.focus() + passwordRef.value.focus() }) } @@ -174,7 +177,7 @@ function testAccount(account) { - + @@ -230,7 +233,7 @@ function testAccount(account) { - + diff --git a/src/views/permission_example/index.vue b/src/views/permission_example/index.vue index 1b464265..0f6a557e 100644 --- a/src/views/permission_example/index.vue +++ b/src/views/permission_example/index.vue @@ -9,11 +9,11 @@