From 33ea08fa4b2f7720f8dfad67062a12b09529baf4 Mon Sep 17 00:00:00 2001 From: Hooray <304327508@qq.com> Date: Sun, 2 Oct 2022 03:29:37 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=8E=A7=E5=88=B6=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 2 - .eslintrc | 5 +- plop-templates/component/prompt.js | 15 +++--- plop-templates/page/prompt.js | 7 +-- plop-templates/store/prompt.js | 7 +-- src/App.vue | 15 +++--- src/api/index.ts | 16 +++---- src/components/BatchActionBar/index.vue | 8 ++-- src/components/FileUpload/index.vue | 8 ++-- src/components/ImageUpload/index.vue | 12 ++--- src/components/ImagesUpload/index.vue | 20 ++++---- src/components/PcasCascader/index.vue | 17 ++++--- src/components/SvgIcon/index.vue | 4 +- src/components/Trend/index.vue | 4 +- src/layouts/components/AppSetting/index.vue | 3 +- src/layouts/components/Logo/index.vue | 4 +- src/layouts/components/Search/index.vue | 49 +++++++++++--------- src/layouts/components/SidebarItem/index.vue | 3 +- src/layouts/components/Topbar/index.vue | 4 +- src/layouts/index.vue | 7 +-- src/main.ts | 3 +- src/router/index.ts | 21 +++++---- src/store/modules/menu.ts | 10 ++-- src/store/modules/route.ts | 10 ++-- src/store/modules/settings.ts | 9 ++-- src/store/modules/user.ts | 3 +- src/utils/composables/useAuth.ts | 7 +-- src/utils/composables/useMenu.ts | 7 +-- src/utils/directive.ts | 6 ++- src/utils/index.ts | 8 ++-- src/views/login.vue | 15 +++--- src/views/personal/edit.password.vue | 7 +-- src/views/personal/setting.vue | 7 +-- vite/plugins/restart.ts | 3 +- vite/plugins/spritesmith.ts | 3 +- 35 files changed, 179 insertions(+), 150 deletions(-) delete mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1eae0cf6..00000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -dist/ -node_modules/ diff --git a/.eslintrc b/.eslintrc index 09c2e423..0b360627 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "@antfu" + "extends": "@antfu", + "rules": { + "curly": ["error", "all"] + } } diff --git a/plop-templates/component/prompt.js b/plop-templates/component/prompt.js index 43a2f20c..2b42bd28 100644 --- a/plop-templates/component/prompt.js +++ b/plop-templates/component/prompt.js @@ -36,22 +36,23 @@ module.exports = { name: 'name', message: '请输入组件名称', validate: (v) => { - if (!v || v.trim === '') + if (!v || v.trim === '') { return '组件名称不能为空' - - else + } + else { return true + } }, }, ], actions: (data) => { let path = '' - if (data.isGlobal) + if (data.isGlobal) { path = 'src/components/{{properCase name}}/index.vue' - - else + } + else { path = `${data.path}/components/{{properCase name}}/index.vue` - + } const actions = [ { type: 'add', diff --git a/plop-templates/page/prompt.js b/plop-templates/page/prompt.js index 0f0026c0..1de90119 100644 --- a/plop-templates/page/prompt.js +++ b/plop-templates/page/prompt.js @@ -28,11 +28,12 @@ module.exports = { name: 'name', message: '请输入文件名', validate: (v) => { - if (!v || v.trim === '') + if (!v || v.trim === '') { return '文件名不能为空' - - else + } + else { return true + } }, }, ], diff --git a/plop-templates/store/prompt.js b/plop-templates/store/prompt.js index 527bcea5..2cefa24c 100644 --- a/plop-templates/store/prompt.js +++ b/plop-templates/store/prompt.js @@ -6,11 +6,12 @@ module.exports = { name: 'name', message: '请输入模块名称', validate: (v) => { - if (!v || v.trim === '') + if (!v || v.trim === '') { return '模块名称不能为空' - - else + } + else { return true + } }, }, ], diff --git a/src/App.vue b/src/App.vue index bf910fda..3ff00fd2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -14,27 +14,28 @@ const buttonConfig = ref({ // 侧边栏主导航当前实际宽度 const mainSidebarActualWidth = computed(() => { let actualWidth = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-main-sidebar-width')) - if (['head', 'single'].includes(settingsStore.menu.menuMode)) + if (['head', 'single'].includes(settingsStore.menu.menuMode)) { actualWidth = 0 - + } return `${actualWidth}px` }) // 侧边栏次导航当前实际宽度 const subSidebarActualWidth = computed(() => { let actualWidth = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-sub-sidebar-width')) - if (settingsStore.menu.subMenuCollapse) + if (settingsStore.menu.subMenuCollapse) { actualWidth = 64 - + } return `${actualWidth}px` }) watch(() => settingsStore.app.colorScheme, () => { - if (settingsStore.app.colorScheme === 'dark') + if (settingsStore.app.colorScheme === 'dark') { document.documentElement.classList.add('dark') - - else + } + else { document.documentElement.classList.remove('dark') + } }, { immediate: true, }) diff --git a/src/api/index.ts b/src/api/index.ts index a0b8fe3e..7a723bcf 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -25,9 +25,9 @@ api.interceptors.request.use( * 全局拦截请求发送前提交的参数 * 以下代码为示例,在请求头里带上 token 信息 */ - if (userStore.isLogin && request.headers) + if (userStore.isLogin && request.headers) { request.headers.Token = userStore.token - + } // 是否将 POST 请求参数进行字符串化处理 if (request.method === 'post') { // request.data = qs.stringify(request.data, { @@ -63,15 +63,15 @@ api.interceptors.response.use( }, (error) => { let message = error.message - if (message === 'Network Error') + if (message === 'Network Error') { message = '后端网络故障' - - else if (message.includes('timeout')) + } + else if (message.includes('timeout')) { message = '接口请求超时' - - else if (message.includes('Request failed with status code')) + } + else if (message.includes('Request failed with status code')) { message = `接口${message.substr(message.length - 3)}异常` - + } ElMessage({ message, type: 'error', diff --git a/src/components/BatchActionBar/index.vue b/src/components/BatchActionBar/index.vue index 1e0dc48a..6102c0b7 100644 --- a/src/components/BatchActionBar/index.vue +++ b/src/components/BatchActionBar/index.vue @@ -15,9 +15,9 @@ const emit = defineEmits(['checkAll', 'checkNull']) const checkAll = computed({ get() { let flag = false - if (props.data.length !== 0 && props.data.length === props.selectionData.length) + if (props.data.length !== 0 && props.data.length === props.selectionData.length) { flag = true - + } return flag }, set(newVal) { @@ -27,9 +27,9 @@ const checkAll = computed({ const isIndeterminate = computed(() => { let flag = false - if (props.selectionData.length > 0 && props.selectionData.length < props.data.length) + if (props.selectionData.length > 0 && props.selectionData.length < props.data.length) { flag = true - + } return flag }) diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue index 37a1db78..d61fbe06 100644 --- a/src/components/FileUpload/index.vue +++ b/src/components/FileUpload/index.vue @@ -48,12 +48,12 @@ const beforeUpload: UploadProps['beforeUpload'] = (file) => { const fileExt = fileName.at(-1) const isTypeOk = props.ext.includes(fileExt) const isSizeOk = file.size / 1024 / 1024 < props.size - if (!isTypeOk) + if (!isTypeOk) { ElMessage.error(`上传文件只支持 ${props.ext.join(' / ')} 格式!`) - - if (!isSizeOk) + } + if (!isSizeOk) { ElMessage.error(`上传文件大小不能超过 ${props.size}MB!`) - + } return isTypeOk && isSizeOk } diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue index ac369cbe..b0249211 100644 --- a/src/components/ImageUpload/index.vue +++ b/src/components/ImageUpload/index.vue @@ -75,15 +75,15 @@ const beforeUpload: UploadProps['beforeUpload'] = (file) => { const fileExt = fileName.at(-1) const isTypeOk = props.ext.includes(fileExt) const isSizeOk = file.size / 1024 / 1024 < props.size - if (!isTypeOk) + if (!isTypeOk) { ElMessage.error(`上传图片只支持 ${props.ext.join(' / ')} 格式!`) - - if (!isSizeOk) + } + if (!isSizeOk) { ElMessage.error(`上传图片大小不能超过 ${props.size}MB!`) - - if (isTypeOk && isSizeOk) + } + if (isTypeOk && isSizeOk) { uploadData.value.progress.preview = URL.createObjectURL(file) - + } return isTypeOk && isSizeOk } const onProgress: UploadProps['onProgress'] = (file) => { diff --git a/src/components/ImagesUpload/index.vue b/src/components/ImagesUpload/index.vue index 5e765389..f94ffe04 100644 --- a/src/components/ImagesUpload/index.vue +++ b/src/components/ImagesUpload/index.vue @@ -81,12 +81,12 @@ function remove(index: number) { // 移动 function move(index: number, type: 'left' | 'right') { const url = props.url - if (type === 'left' && index !== 0) + if (type === 'left' && index !== 0) { url[index] = url.splice(index - 1, 1, url[index])[0] - - if (type === 'right' && index !== url.length - 1) + } + if (type === 'right' && index !== url.length - 1) { url[index] = url.splice(index + 1, 1, url[index])[0] - + } emit('update:url', url) } @@ -95,15 +95,15 @@ const beforeUpload: UploadProps['beforeUpload'] = (file) => { const fileExt = fileName.at(-1) const isTypeOk = props.ext.includes(fileExt) const isSizeOk = file.size / 1024 / 1024 < props.size - if (!isTypeOk) + if (!isTypeOk) { ElMessage.error(`上传图片只支持 ${props.ext.join(' / ')} 格式!`) - - if (!isSizeOk) + } + if (!isSizeOk) { ElMessage.error(`上传图片大小不能超过 ${props.size}MB!`) - - if (isTypeOk && isSizeOk) + } + if (isTypeOk && isSizeOk) { uploadData.value.progress.preview = URL.createObjectURL(file) - + } return isTypeOk && isSizeOk } const onProgress: UploadProps['onProgress'] = (file) => { diff --git a/src/components/PcasCascader/index.vue b/src/components/PcasCascader/index.vue index 69029488..45aaa743 100644 --- a/src/components/PcasCascader/index.vue +++ b/src/components/PcasCascader/index.vue @@ -91,18 +91,20 @@ function anyToCode(value: any[], dictionarie: any[] = pcasData.value) { const input: string[] = [] if (value.length > 0) { const findItem = dictionarie.find((item) => { - if (props.format === 'code') + if (props.format === 'code') { return item.code === value[0] - - else if (props.format === 'name') + } + else if (props.format === 'name') { return item.name === value[0] - - else + } + else { return item.name === value[0].name && item.code === value[0].code + } }) input.push(findItem.code) - if (findItem.children) + if (findItem.children) { input.push(...anyToCode(value.slice(1 - value.length), findItem.children)) + } } return input } @@ -125,8 +127,9 @@ function codeToAny(codes: string[], dictionarie: any[] = pcasData.value): any { }) } const newCodes = codes.slice(1 - codes.length) - if (newCodes.length > 0 && findItem.children) + if (newCodes.length > 0 && findItem.children) { output.push(...codeToAny(newCodes, findItem.children)) + } } return output } diff --git a/src/components/SvgIcon/index.vue b/src/components/SvgIcon/index.vue index 65fb51b0..01a2257a 100644 --- a/src/components/SvgIcon/index.vue +++ b/src/components/SvgIcon/index.vue @@ -32,9 +32,9 @@ const transformStyle = computed(() => { break } } - if (props.rotate !== 0) + if (props.rotate !== 0) { style.push(`rotate(${props.rotate}deg)`) - + } return `transform: ${style.join(' ')};` }) diff --git a/src/components/Trend/index.vue b/src/components/Trend/index.vue index e51e5e21..aa9ba395 100644 --- a/src/components/Trend/index.vue +++ b/src/components/Trend/index.vue @@ -24,9 +24,9 @@ const props = defineProps({ const isUp = computed(() => { let isUp = props.type === 'up' - if (props.reverse) + if (props.reverse) { isUp = !isUp - + } return isUp }) diff --git a/src/layouts/components/AppSetting/index.vue b/src/layouts/components/AppSetting/index.vue index 8918186c..ea475c43 100644 --- a/src/layouts/components/AppSetting/index.vue +++ b/src/layouts/components/AppSetting/index.vue @@ -31,8 +31,9 @@ onMounted(() => { const { copy, copied, isSupported } = useClipboard() watch(copied, (val) => { - if (val) + if (val) { ElMessage.success('复制成功,请粘贴到 src/settings.ts 文件中!') + } }) function handleCopy() { diff --git a/src/layouts/components/Logo/index.vue b/src/layouts/components/Logo/index.vue index 68eed913..ac87cc2d 100644 --- a/src/layouts/components/Logo/index.vue +++ b/src/layouts/components/Logo/index.vue @@ -22,9 +22,9 @@ const to = computed(() => { const rtn: { name?: string } = {} - if (settingsStore.dashboard.enable) + if (settingsStore.dashboard.enable) { rtn.name = 'dashboard' - + } return rtn }) diff --git a/src/layouts/components/Search/index.vue b/src/layouts/components/Search/index.vue index 2ad595b6..17d5a223 100644 --- a/src/layouts/components/Search/index.vue +++ b/src/layouts/components/Search/index.vue @@ -38,15 +38,15 @@ const resultList = computed(() => { let result = [] result = sourceList.value.filter((item) => { let flag = false - if (item.title.includes(searchInput.value)) + if (item.title.includes(searchInput.value)) { flag = true - - if (item.path.includes(searchInput.value)) + } + if (item.path.includes(searchInput.value)) { flag = true - - if (item.breadcrumb.some(b => b.includes(searchInput.value))) + } + if (item.breadcrumb.some(b => b.includes(searchInput.value))) { flag = true - + } return flag }) return result @@ -111,9 +111,9 @@ onMounted(() => { function hasChildren(item: Route.recordRaw) { let flag = true - if (item.children && item.children.every(i => i.meta.sidebar === false)) + if (item.children && item.children.every(i => i.meta.sidebar === false)) { flag = false - + } return flag } function getSourceList(arr: Route.recordRaw[], basePath?: string, icon?: string, breadcrumb?: string[]) { @@ -127,12 +127,12 @@ function getSourceList(arr: Route.recordRaw[], basePath?: string, icon?: string, else { breadcrumbTemp.push(typeof item.meta.title === 'function' ? item.meta.title() : item.meta.title) let path = '' - if (isExternalLink(item.path)) + if (isExternalLink(item.path)) { path = item.path - - else + } + else { path = basePath ? [basePath, item.path].join('/') : item.path - + } sourceList.value.push({ icon: item.meta.icon || icon, title: typeof item.meta.title === 'function' ? item.meta.title() : item.meta.title, @@ -165,24 +165,25 @@ function getSourceListByMenus(arr: Menu.recordRaw[], icon?: string, breadcrumb?: function keyUp() { if (resultList.value.length) { actived.value -= 1 - if (actived.value < 0) + if (actived.value < 0) { actived.value = resultList.value.length - 1 - + } handleScroll() } } function keyDown() { if (resultList.value.length) { actived.value += 1 - if (actived.value > resultList.value.length - 1) + if (actived.value > resultList.value.length - 1) { actived.value = 0 - + } handleScroll() } } function keyEnter() { - if (actived.value !== -1) + if (actived.value !== -1) { searchResultItemRef.value[actived.value].click() + } } function handleScroll() { let scrollTo = 0 @@ -192,11 +193,12 @@ function handleScroll() { const activedClientHeight = searchResultItemRef.value[actived.value].clientHeight const searchScrollTop = searchResultRef.value.scrollTop const searchClientHeight = searchResultRef.value.clientHeight - if (activedOffsetTop + activedClientHeight > searchScrollTop + searchClientHeight) + if (activedOffsetTop + activedClientHeight > searchScrollTop + searchClientHeight) { scrollTo = activedOffsetTop + activedClientHeight - searchClientHeight - - else if (activedOffsetTop <= searchScrollTop) + } + else if (activedOffsetTop <= searchScrollTop) { scrollTo = activedOffsetTop + } } searchResultRef.value.scrollTo({ top: scrollTo, @@ -204,11 +206,12 @@ function handleScroll() { } function pageJump(url: string) { - if (isExternalLink(url)) + if (isExternalLink(url)) { window.open(url, 'top') - - else + } + else { router.push(url) + } } diff --git a/src/layouts/components/SidebarItem/index.vue b/src/layouts/components/SidebarItem/index.vue index 1a236f93..995efeec 100644 --- a/src/layouts/components/SidebarItem/index.vue +++ b/src/layouts/components/SidebarItem/index.vue @@ -17,8 +17,9 @@ const props = defineProps({ const hasChildren = computed(() => { let flag = true if (props.item.children) { - if (props.item.children.every(item => item.meta.sidebar === false)) + if (props.item.children.every(item => item.meta.sidebar === false)) { flag = false + } } else { flag = false diff --git a/src/layouts/components/Topbar/index.vue b/src/layouts/components/Topbar/index.vue index 1d3c4092..828ab656 100644 --- a/src/layouts/components/Topbar/index.vue +++ b/src/layouts/components/Topbar/index.vue @@ -22,9 +22,9 @@ const breadcrumbList = computed(() => { title: settingsStore.dashboard.title, }) } - if (route.meta.breadcrumbNeste) + if (route.meta.breadcrumbNeste) { breadcrumbList.push(...route.meta.breadcrumbNeste.filter(item => item.hide === false)) - + } return breadcrumbList }) diff --git a/src/layouts/index.vue b/src/layouts/index.vue index 37da88be..5364a1fc 100644 --- a/src/layouts/index.vue +++ b/src/layouts/index.vue @@ -19,11 +19,12 @@ const menuStore = useMenuStore() watch(() => settingsStore.menu.subMenuCollapse, (val) => { if (settingsStore.mode === 'mobile') { - if (!val) + if (!val) { document.body.classList.add('hidden') - - else + } + else { document.body.classList.remove('hidden') + } } }) diff --git a/src/main.ts b/src/main.ts index 41759e36..40f937bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,8 +13,9 @@ import 'virtual:svg-icons-register' import '@/assets/styles/globals.scss' // 加载 iconify 图标(element plus) import { downloadAndInstall } from '@/iconify-ep' -if (useSettingsStore().app.iconifyOfflineUse) +if (useSettingsStore().app.iconifyOfflineUse) { downloadAndInstall() +} const app = createApp(App) app.use(ElementPlus) diff --git a/src/router/index.ts b/src/router/index.ts index 3d680a81..59464136 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -88,8 +88,9 @@ router.beforeEach(async (to, from, next) => { } const removeRoutes: Function[] = [] routeStore.flatRoutes.forEach((route) => { - if (!/^(https?:|mailto:|tel:)/.test(route.path)) + if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) + } }) if (settingsStore.app.routeBaseOn !== 'filesystem') { routeStore.flatSystemRoutes.forEach((route) => { @@ -129,11 +130,12 @@ router.afterEach((to, from) => { // 判断当前页面是否开启缓存,如果开启,则将当前页面的 name 信息存入 keep-alive 全局状态 if (to.meta.cache) { const componentName = to.matched.at(-1)?.components?.default.name - if (componentName) + if (componentName) { keepAliveStore.add(componentName) - - else + } + else { console.warn('该页面组件未设置组件名,会导致缓存失效,请检查') + } } // 判断离开页面是否开启缓存,如果开启,则根据缓存规则判断是否需要清空 keep-alive 全局状态里离开页面的 name 信息 if (from.meta.cache) { @@ -142,19 +144,20 @@ router.afterEach((to, from) => { // 通过 meta.cache 判断针对哪些页面进行缓存 switch (typeof from.meta.cache) { case 'string': - if (from.meta.cache !== to.name) + if (from.meta.cache !== to.name) { keepAliveStore.remove(componentName) - + } break case 'object': - if (!from.meta.cache.includes(to.name as string)) + if (!from.meta.cache.includes(to.name as string)) { keepAliveStore.remove(componentName) - + } break } // 如果进入的是 reload 页面,则也将离开页面的缓存清空 - if (to.name === 'reload') + if (to.name === 'reload') { keepAliveStore.remove(componentName) + } } } document.body.scrollTop = 0 diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index 43e44825..f37fd307 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -75,8 +75,9 @@ function getDefaultOpenedPaths(menus: Menu.recordRaw[], rootPath = '') { if (item.path && item.meta.defaultOpened && item.children) { defaultOpenedPaths.push(resolveRoutePath(rootPath, item.path)) const childrenDefaultOpenedPaths = getDefaultOpenedPaths(item.children, resolveRoutePath(rootPath, item.path)) - if (childrenDefaultOpenedPaths.length > 0) + if (childrenDefaultOpenedPaths.length > 0) { defaultOpenedPaths.push(...childrenDefaultOpenedPaths) + } } }) return defaultOpenedPaths @@ -133,9 +134,9 @@ const useMenuStore = defineStore( defaultOpenedPaths() { const settingsStore = useSettingsStore() let defaultOpenedPaths: string[] = [] - if (settingsStore.app.routeBaseOn !== 'filesystem') + if (settingsStore.app.routeBaseOn !== 'filesystem') { defaultOpenedPaths = getDefaultOpenedPaths(this.sidebarMenus) - + } return defaultOpenedPaths }, }, @@ -194,8 +195,9 @@ const useMenuStore = defineStore( item.children.some((r) => { return data.indexOf(`${r.path}/`) === 0 || data === r.path }) - ) + ) { this.actived = index + } }) } }, diff --git a/src/store/modules/route.ts b/src/store/modules/route.ts index b4f5e534..5d0a7cab 100644 --- a/src/store/modules/route.ts +++ b/src/store/modules/route.ts @@ -47,12 +47,13 @@ function formatBackRoutes(routes: any, views = import.meta.glob('../../views/**/ route.component = () => import('@/layouts/index.vue') break default: - if (route.component) + if (route.component) { route.component = views[`../../views/${route.component}`] + } } - if (route.children) + if (route.children) { route.children = formatBackRoutes(route.children, views) - + } return route }) } @@ -91,8 +92,9 @@ function flatAsyncRoutesRecursive(routes: Route.recordRaw[], breadcrumb: Route.b // 如果 path 一样则覆盖,因为子路由的 path 可能设置为空,导致和父路由一样,直接注册会提示路由重复 if (res.some(v => v.path === item.path)) { res.forEach((v, i) => { - if (v.path === item.path) + if (v.path === item.path) { res[i] = item + } }) } else { diff --git a/src/store/modules/settings.ts b/src/store/modules/settings.ts index 644817dd..0cbbfa9e 100644 --- a/src/store/modules/settings.ts +++ b/src/store/modules/settings.ts @@ -40,11 +40,7 @@ const useSettingsStore = defineStore( } else { // 如果为桌面设备,再根据页面宽度判断是否需要切换为移动端展示 - if (width < 992) - this.mode = 'mobile' - - else - this.mode = 'pc' + this.mode = width < 992 ? 'mobile' : 'pc' } } else { @@ -54,8 +50,9 @@ const useSettingsStore = defineStore( // 切换侧边栏导航展开/收起 toggleSidebarCollapse() { this.menu.subMenuCollapse = !this.menu.subMenuCollapse - if (this.mode === 'pc') + if (this.mode === 'pc') { this.subMenuCollapseLastStatus = !this.subMenuCollapseLastStatus + } }, // 设置主题颜色模式 setColorScheme(color: Required['colorScheme']) { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index abeba47c..1f7c054e 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -16,8 +16,9 @@ const useUserStore = defineStore( isLogin: (state) => { let retn = false if (state.token) { - if (new Date().getTime() < parseInt(state.failure_time) * 1000) + if (new Date().getTime() < parseInt(state.failure_time) * 1000) { retn = true + } } return retn }, diff --git a/src/utils/composables/useAuth.ts b/src/utils/composables/useAuth.ts index cb9ba136..f7762483 100644 --- a/src/utils/composables/useAuth.ts +++ b/src/utils/composables/useAuth.ts @@ -5,11 +5,12 @@ export default function useAuth() { function hasPermission(permission: string) { const settingsStore = useSettingsStore() const userStore = useUserStore() - if (settingsStore.app.enablePermission) + if (settingsStore.app.enablePermission) { return userStore.permissions.includes(permission) - - else + } + else { return true + } } function auth(value: string | string[]) { diff --git a/src/utils/composables/useMenu.ts b/src/utils/composables/useMenu.ts index aca65ca8..0b7c6c37 100644 --- a/src/utils/composables/useMenu.ts +++ b/src/utils/composables/useMenu.ts @@ -10,11 +10,12 @@ export default function useMenu() { function switchTo(index: number | string) { menuStore.setActived(index) if (settingsStore.menu.switchMainMenuAndPageJump) { - if (isExternalLink(menuStore.sidebarMenusFirstDeepestPath)) + if (isExternalLink(menuStore.sidebarMenusFirstDeepestPath)) { window.open(menuStore.sidebarMenusFirstDeepestPath, '_blank') - - else + } + else { router.push(menuStore.sidebarMenusFirstDeepestPath) + } } } diff --git a/src/utils/directive.ts b/src/utils/directive.ts index b42fb0f1..bbd2481a 100644 --- a/src/utils/directive.ts +++ b/src/utils/directive.ts @@ -4,14 +4,16 @@ export default function directive(app: App) { // 注册 v-auth 和 v-auth-all 指令 app.directive('auth', { mounted: (el, binding) => { - if (!useAuth().auth(binding.value)) + if (!useAuth().auth(binding.value)) { el.remove() + } }, }) app.directive('auth-all', { mounted: (el, binding) => { - if (!useAuth().authAll(binding.value)) + if (!useAuth().authAll(binding.value)) { el.remove() + } }, }) } diff --git a/src/utils/index.ts b/src/utils/index.ts index c48e7d7f..e2380edb 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,11 +5,11 @@ export function isExternalLink(path: string) { } export function resolveRoutePath(basePath: string, routePath: string) { - if (isExternalLink(routePath)) + if (isExternalLink(routePath)) { return routePath - - if (isExternalLink(basePath)) + } + if (isExternalLink(basePath)) { return basePath - + } return basePath ? path.resolve(basePath, routePath) : routePath } diff --git a/src/views/login.vue b/src/views/login.vue index 8f636b44..1fbc0fd1 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -46,12 +46,12 @@ function handleLogin() { loading.value = true userStore.login(loginForm.value).then(() => { loading.value = false - if (loginForm.value.remember) + if (loginForm.value.remember) { localStorage.setItem('login_account', loginForm.value.account) - - else + } + else { localStorage.removeItem('login_account') - + } router.push(redirect.value) }).catch(() => { loading.value = false @@ -85,11 +85,12 @@ const registerRules = ref({ { required: true, trigger: 'blur', message: '请再次输入密码' }, { validator: (rule, value, callback) => { - if (value !== registerForm.value.password) + if (value !== registerForm.value.password) { callback(new Error('两次输入的密码不一致')) - - else + } + else { callback() + } }, }, ], diff --git a/src/views/personal/edit.password.vue b/src/views/personal/edit.password.vue index 57054be7..7445e202 100644 --- a/src/views/personal/edit.password.vue +++ b/src/views/personal/edit.password.vue @@ -32,11 +32,12 @@ const rules = ref({ { required: true, message: '请输入新密码', trigger: 'blur' }, { validator: (rule: any, value: any, callback: any) => { - if (value !== form.value.newpassword) + if (value !== form.value.newpassword) { callback(new Error('请确认新密码')) - - else + } + else { callback() + } }, }, ], diff --git a/src/views/personal/setting.vue b/src/views/personal/setting.vue index 2da2e562..286dc83c 100644 --- a/src/views/personal/setting.vue +++ b/src/views/personal/setting.vue @@ -19,11 +19,12 @@ const form = ref({ }) const handleSuccess: UploadProps['onSuccess'] = (res) => { - if (res.error === '') + if (res.error === '') { form.value.headimg = res.data.path - - else + } + else { ElMessage.warning(res.error) + } } const editPassword = () => { router.push({ diff --git a/vite/plugins/restart.ts b/vite/plugins/restart.ts index 0b5724ce..f664c45a 100644 --- a/vite/plugins/restart.ts +++ b/vite/plugins/restart.ts @@ -4,8 +4,9 @@ import ViteRestart from 'vite-plugin-restart' export default function createRestart() { const pluginsFile: string[] = [] fs.readdirSync('vite/plugins').forEach((dirname) => { - if (fs.statSync(`vite/plugins/${dirname}`).isFile()) + if (fs.statSync(`vite/plugins/${dirname}`).isFile()) { pluginsFile.push(`vite/plugins/${dirname}`) + } }) return ViteRestart({ restart: pluginsFile, diff --git a/vite/plugins/spritesmith.ts b/vite/plugins/spritesmith.ts index 5d5e28a8..86ca829a 100644 --- a/vite/plugins/spritesmith.ts +++ b/vite/plugins/spritesmith.ts @@ -4,8 +4,9 @@ import spritesmith from 'vite-plugin-spritesmith' export default function createSpritesmith(isBuild) { const spriteDirnames: string[] = [] fs.readdirSync('src/assets/sprites').forEach((dirname) => { - if (fs.statSync(`src/assets/sprites/${dirname}`).isDirectory()) + if (fs.statSync(`src/assets/sprites/${dirname}`).isDirectory()) { spriteDirnames.push(dirname) + } }) const plugin: any[] = [] spriteDirnames.forEach((item) => {