diff --git a/.prettierrc.js b/.prettierrc.js index 5a3868d..fae9475 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,5 +1,5 @@ module.exports = { - // 一行最多 180 字符 + // 超过最大值换行 printWidth: 148, // 使用 2 个空格缩进 tabWidth: 2, @@ -13,14 +13,14 @@ module.exports = { quoteProps: 'as-needed', // jsx 不使用单引号,而使用双引号 jsxSingleQuote: false, - // 末尾不需要逗号 - trailingComma: 'all', - // 大括号内的首尾需要空格 + // 多行时尽可能打印尾随逗号。(例如,单行数组永远不会出现逗号结尾。) 可选值"",默认none + trailingComma: 'none', + // 在对象,数组括号与文字之间加空格 "{ foo: bar }" bracketSpacing: true, // jsx 标签的反尖括号需要换行 jsxBracketSameLine: true, bracketSameLine: true, - // 箭头函数,只有一个参数的时候,也需要括号 + // 箭头函数,always只有一个参数的时候,也需要括号,'avoid'箭头函数只有一个参数的时候可以忽略括号 arrowParens: 'always', // 每个文件格式化的范围是文件的全部内容 rangeStart: 0, @@ -33,6 +33,6 @@ module.exports = { proseWrap: 'preserve', // 根据显示样式决定 html 要不要折行 htmlWhitespaceSensitivity: 'css', - // 换行符使用 lf - endOfLine: 'auto', -}; \ No newline at end of file + // 换行符使用 lf 结尾是 可选值"" + endOfLine: 'auto' +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 3314c35..fff106c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,9 @@ "[ts]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "[js]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, // 保存时 prettier 自动格式化 "editor.formatOnSave": true, // 保存时自动启用 eslint --fix 自动修复 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 2655bc8..4452058 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,78 +1,5 @@ import Cookies from 'js-cookie' -// const state = { -// sidebar: { -// opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, -// withoutAnimation: false, -// hide: false -// }, -// device: 'desktop', -// size: Cookies.get('size') || 'small', -// lang: Cookies.get('lang') || 'zh-cn' -// } - -// const mutations = { -// TOGGLE_SIDEBAR: state => { -// if (state.sidebar.hide) { -// return false; -// } -// state.sidebar.opened = !state.sidebar.opened -// state.sidebar.withoutAnimation = true - -// if (state.sidebar.opened) { -// Cookies.set('sidebarStatus', 1) -// } else { -// Cookies.set('sidebarStatus', 0) -// } -// }, -// CLOSE_SIDEBAR: (state, withoutAnimation) => { -// Cookies.set('sidebarStatus', 0) -// state.sidebar.opened = false -// state.sidebar.withoutAnimation = withoutAnimation -// }, -// TOGGLE_DEVICE: (state, device) => { -// state.device = device -// }, -// SET_SIZE: (state, size) => { -// state.size = size -// Cookies.set('size', size) -// }, -// SET_SIDEBAR_HIDE: (state, status) => { -// state.sidebar.hide = status -// }, -// SET_LANG: (state, lang) => { -// state.lang = lang -// Cookies.set('lang', lang) -// }, -// } - -// const actions = { -// toggleSideBar({ commit }) { -// commit('TOGGLE_SIDEBAR') -// }, -// closeSideBar({ commit }) { -// commit('CLOSE_SIDEBAR', '') -// }, -// toggleDevice({ commit }, device) { -// commit('TOGGLE_DEVICE', device) -// }, -// setSize({ commit }, size) { -// commit('SET_SIZE', size) -// }, -// toggleSideBarHide({ commit }, status) { -// commit('SET_SIDEBAR_HIDE', status) -// }, -// setLang({ commit }, lang) { -// commit('SET_LANG', lang) -// }, -// } - -// export default { -// namespaced: true, -// state, -// mutations, -// actions -// } const useAppStore = defineStore('app', { state: () => ({ sidebar: { @@ -106,7 +33,7 @@ const useAppStore = defineStore('app', { this.device = device }, setSize(size) { - this.size = size; + this.size = size Cookies.set('size', size) }, toggleSideBarHide(status) { @@ -119,4 +46,4 @@ const useAppStore = defineStore('app', { } }) -export default useAppStore \ No newline at end of file +export default useAppStore diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index ce1b704..ceb7e73 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -5,8 +5,7 @@ import ParentView from '@/components/ParentView' import InnerLink from '@/layout/components/InnerLink' // 匹配views里面所有的.vue文件 -const modules = - import.meta.glob('./../../views/**/*.vue') +const modules = import.meta.glob('./../../views/**/*.vue') const usePermissionStore = defineStore('permission', { state: () => ({ @@ -31,9 +30,9 @@ const usePermissionStore = defineStore('permission', { }, // 生成路由 generateRoutes() { - return new Promise(resolve => { + return new Promise((resolve) => { // 向后端请求路由数据 - getRouters().then(res => { + getRouters().then((res) => { const sdata = JSON.parse(JSON.stringify(res.data)) const rdata = JSON.parse(JSON.stringify(res.data)) const defaultData = JSON.parse(JSON.stringify(res.data)) @@ -53,7 +52,7 @@ const usePermissionStore = defineStore('permission', { // 遍历后台传来的路由字符串,转换为组件对象 function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { - return asyncRouterMap.filter(route => { + return asyncRouterMap.filter((route) => { if (type && route.children) { route.children = filterChildren(route.children) } @@ -84,7 +83,7 @@ function filterChildren(childrenMap, lastRouter = false) { childrenMap.forEach((el, index) => { if (el.children && el.children.length) { if (el.component === 'ParentView' && !lastRouter) { - el.children.forEach(c => { + el.children.forEach((c) => { c.path = el.path + '/' + c.path if (c.children && c.children.length) { children = children.concat(filterChildren(c.children, c)) @@ -104,14 +103,14 @@ function filterChildren(childrenMap, lastRouter = false) { } export const loadView = (view) => { - let res; + let res for (const path in modules) { - const dir = path.split('views/')[1].split('.vue')[0]; + const dir = path.split('views/')[1].split('.vue')[0] if (dir === view) { - res = () => modules[path](); + res = () => modules[path]() } } - return res; + return res } -export default usePermissionStore \ No newline at end of file +export default usePermissionStore diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index cde2efa..dd365cd 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,7 +1,8 @@ import defaultSettings from '@/settings' import { useDynamicTitle } from '@/utils/dynamicTitle' -const { sideTheme, theme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle, showFooter, showWatermark, watermarkText } = defaultSettings +const { sideTheme, theme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle, showFooter, showWatermark, watermarkText } = + defaultSettings const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || '' const useSettingsStore = defineStore('settings', { @@ -30,8 +31,8 @@ const useSettingsStore = defineStore('settings', { // 设置网页标题 setTitle(title) { this.title = title - useDynamicTitle(); + useDynamicTitle() } } }) -export default useSettingsStore \ No newline at end of file +export default useSettingsStore diff --git a/src/store/modules/socket.js b/src/store/modules/socket.js index 9e10b5d..b21927e 100644 --- a/src/store/modules/socket.js +++ b/src/store/modules/socket.js @@ -24,4 +24,4 @@ const useSocketStore = defineStore('socket', { } } }) -export default useSocketStore \ No newline at end of file +export default useSocketStore diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index 92317e8..0a30d00 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -1,156 +1,154 @@ -const useTagsViewStore = defineStore( - 'tagsView', - { - state: () => ({ - visitedViews: [], - cachedViews: [] - }), - actions: { - addView(view) { - this.addVisitedView(view) - this.addCachedView(view) - }, - addVisitedView(view) { - if (this.visitedViews.some(v => v.path === view.path)) return - this.visitedViews.push( - Object.assign({}, view, { - title: view.meta.title || 'no-name' - }) - ) - }, - addCachedView(view) { - if (this.cachedViews.includes(view.name)) return - if (!view.meta.noCache) { - this.cachedViews.push(view.name) - } - }, - delView(view) { - return new Promise(resolve => { - this.delVisitedView(view) - this.delCachedView(view) - resolve({ - visitedViews: [...this.visitedViews], - cachedViews: [...this.cachedViews] - }) +const useTagsViewStore = defineStore('tagsView', { + state: () => ({ + visitedViews: [], + cachedViews: [] + }), + actions: { + addView(view) { + this.addVisitedView(view) + this.addCachedView(view) + }, + addVisitedView(view) { + if (this.visitedViews.some((v) => v.path === view.path)) return + this.visitedViews.push( + Object.assign({}, view, { + title: view.meta.title || 'no-name' }) - }, - delVisitedView(view) { - return new Promise(resolve => { - for (const [i, v] of this.visitedViews.entries()) { - if (v.path === view.path) { - this.visitedViews.splice(i, 1) - break - } - } - resolve([...this.visitedViews]) + ) + }, + addCachedView(view) { + if (this.cachedViews.includes(view.name)) return + if (!view.meta.noCache) { + this.cachedViews.push(view.name) + } + }, + delView(view) { + return new Promise((resolve) => { + this.delVisitedView(view) + this.delCachedView(view) + resolve({ + visitedViews: [...this.visitedViews], + cachedViews: [...this.cachedViews] }) - }, - delCachedView(view) { - return new Promise(resolve => { - const index = this.cachedViews.indexOf(view.name) - index > -1 && this.cachedViews.splice(index, 1) - resolve([...this.cachedViews]) - }) - }, - delOthersViews(view) { - return new Promise(resolve => { - this.delOthersVisitedViews(view) - this.delOthersCachedViews(view) - resolve({ - visitedViews: [...this.visitedViews], - cachedViews: [...this.cachedViews] - }) - }) - }, - delOthersVisitedViews(view) { - return new Promise(resolve => { - this.visitedViews = this.visitedViews.filter(v => { - return v.meta.affix || v.path === view.path - }) - resolve([...this.visitedViews]) - }) - }, - delOthersCachedViews(view) { - return new Promise(resolve => { - const index = this.cachedViews.indexOf(view.name) - if (index > -1) { - this.cachedViews = this.cachedViews.slice(index, index + 1) - } else { - this.cachedViews = [] - } - resolve([...this.cachedViews]) - }) - }, - delAllViews(view) { - return new Promise(resolve => { - this.delAllVisitedViews(view) - this.delAllCachedViews(view) - resolve({ - visitedViews: [...this.visitedViews], - cachedViews: [...this.cachedViews] - }) - }) - }, - delAllVisitedViews(view) { - return new Promise(resolve => { - const affixTags = this.visitedViews.filter(tag => tag.meta.affix) - this.visitedViews = affixTags - resolve([...this.visitedViews]) - }) - }, - delAllCachedViews(view) { - return new Promise(resolve => { - this.cachedViews = [] - resolve([...this.cachedViews]) - }) - }, - updateVisitedView(view) { - for (let v of this.visitedViews) { + }) + }, + delVisitedView(view) { + return new Promise((resolve) => { + for (const [i, v] of this.visitedViews.entries()) { if (v.path === view.path) { - v = Object.assign(v, view) + this.visitedViews.splice(i, 1) break } } - }, - delRightTags(view) { - return new Promise(resolve => { - const index = this.visitedViews.findIndex(v => v.path === view.path) - if (index === -1) { - return - } - this.visitedViews = this.visitedViews.filter((item, idx) => { - if (idx <= index || (item.meta && item.meta.affix)) { - return true - } - const i = this.cachedViews.indexOf(item.name) - if (i > -1) { - this.cachedViews.splice(i, 1) - } - return false - }) - resolve([...this.visitedViews]) + resolve([...this.visitedViews]) + }) + }, + delCachedView(view) { + return new Promise((resolve) => { + const index = this.cachedViews.indexOf(view.name) + index > -1 && this.cachedViews.splice(index, 1) + resolve([...this.cachedViews]) + }) + }, + delOthersViews(view) { + return new Promise((resolve) => { + this.delOthersVisitedViews(view) + this.delOthersCachedViews(view) + resolve({ + visitedViews: [...this.visitedViews], + cachedViews: [...this.cachedViews] }) - }, - delLeftTags(view) { - return new Promise(resolve => { - const index = this.visitedViews.findIndex(v => v.path === view.path) - if (index === -1) { - return - } - this.visitedViews = this.visitedViews.filter((item, idx) => { - if (idx >= index || (item.meta && item.meta.affix)) { - return true - } - const i = this.cachedViews.indexOf(item.name) - if (i > -1) { - this.cachedViews.splice(i, 1) - } - return false - }) - resolve([...this.visitedViews]) + }) + }, + delOthersVisitedViews(view) { + return new Promise((resolve) => { + this.visitedViews = this.visitedViews.filter((v) => { + return v.meta.affix || v.path === view.path }) + resolve([...this.visitedViews]) + }) + }, + delOthersCachedViews(view) { + return new Promise((resolve) => { + const index = this.cachedViews.indexOf(view.name) + if (index > -1) { + this.cachedViews = this.cachedViews.slice(index, index + 1) + } else { + this.cachedViews = [] + } + resolve([...this.cachedViews]) + }) + }, + delAllViews(view) { + return new Promise((resolve) => { + this.delAllVisitedViews(view) + this.delAllCachedViews(view) + resolve({ + visitedViews: [...this.visitedViews], + cachedViews: [...this.cachedViews] + }) + }) + }, + delAllVisitedViews(view) { + return new Promise((resolve) => { + const affixTags = this.visitedViews.filter((tag) => tag.meta.affix) + this.visitedViews = affixTags + resolve([...this.visitedViews]) + }) + }, + delAllCachedViews(view) { + return new Promise((resolve) => { + this.cachedViews = [] + resolve([...this.cachedViews]) + }) + }, + updateVisitedView(view) { + for (let v of this.visitedViews) { + if (v.path === view.path) { + v = Object.assign(v, view) + break + } } + }, + delRightTags(view) { + return new Promise((resolve) => { + const index = this.visitedViews.findIndex((v) => v.path === view.path) + if (index === -1) { + return + } + this.visitedViews = this.visitedViews.filter((item, idx) => { + if (idx <= index || (item.meta && item.meta.affix)) { + return true + } + const i = this.cachedViews.indexOf(item.name) + if (i > -1) { + this.cachedViews.splice(i, 1) + } + return false + }) + resolve([...this.visitedViews]) + }) + }, + delLeftTags(view) { + return new Promise((resolve) => { + const index = this.visitedViews.findIndex((v) => v.path === view.path) + if (index === -1) { + return + } + this.visitedViews = this.visitedViews.filter((item, idx) => { + if (idx >= index || (item.meta && item.meta.affix)) { + return true + } + const i = this.cachedViews.indexOf(item.name) + if (i > -1) { + this.cachedViews.splice(i, 1) + } + return false + }) + resolve([...this.visitedViews]) + }) } - }) + } +}) -export default useTagsViewStore \ No newline at end of file +export default useTagsViewStore diff --git a/src/store/modules/user.js b/src/store/modules/user.js index e347df7..bb2f6a7 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -25,29 +25,31 @@ const useUserStore = defineStore('user', { const code = userInfo.code const uuid = userInfo.uuid return new Promise((resolve, reject) => { - login(username, password, code, uuid).then(res => { - if (res.code == 200) { - setToken(res.data) - this.token = res.data - resolve() //then处理 - } else { - console.log('login error ', res) - reject(res) //catch处理 - } - }).catch(error => { - reject(error) - }) + login(username, password, code, uuid) + .then((res) => { + if (res.code == 200) { + setToken(res.data) + this.token = res.data + resolve() //then处理 + } else { + console.log('login error ', res) + reject(res) //catch处理 + } + }) + .catch((error) => { + reject(error) + }) }) }, /** * 三方授权登录 - * @param {*} data - * @param { *} param { authSource : ''} - * @returns + * @param {*} data + * @param {*} param { authSource : ''} + * @returns */ oauthLogin(data, param) { return new Promise((resolve, reject) => { - oauthCallback(data, param).then(res => { + oauthCallback(data, param).then((res) => { const { code, data } = res if (code == 200) { setToken(data.token) @@ -66,45 +68,50 @@ const useUserStore = defineStore('user', { // 获取用户信息 getInfo() { return new Promise((resolve, reject) => { - getInfo().then(res => { - const data = res.data - const avatar = data.user.avatar == "" ? defAva : data.user.avatar; + getInfo() + .then((res) => { + const data = res.data + const avatar = data.user.avatar == '' ? defAva : data.user.avatar - if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组 - this.roles = data.roles - this.permissions = data.permissions - } else { - this.roles = ['ROLE_DEFAULT'] - } + if (data.roles && data.roles.length > 0) { + // 验证返回的roles是否是一个非空数组 + this.roles = data.roles + this.permissions = data.permissions + } else { + this.roles = ['ROLE_DEFAULT'] + } - this.name = data.user.nickName - this.avatar = avatar - this.userInfo = data.user //新加 - this.userId = data.user.userId //新加 - resolve(res) - }).catch(error => { - console.error(error); - reject("获取用户信息失败") - }) + this.name = data.user.nickName + this.avatar = avatar + this.userInfo = data.user //新加 + this.userId = data.user.userId //新加 + resolve(res) + }) + .catch((error) => { + console.error(error) + reject('获取用户信息失败') + }) }) }, // 退出系统 logOut() { return new Promise((resolve, reject) => { - logout(this.token).then((res) => { - this.token = '' - this.roles = [] - this.permissions = [] - removeToken() - resolve(res) - }).catch(error => { - reject(error) - }) + logout(this.token) + .then((res) => { + this.token = '' + this.roles = [] + this.permissions = [] + removeToken() + resolve(res) + }) + .catch((error) => { + reject(error) + }) }) }, // 前端 登出 fedLogOut() { - return new Promise(resolve => { + return new Promise((resolve) => { this.token = '' removeToken() resolve() @@ -112,4 +119,4 @@ const useUserStore = defineStore('user', { } } }) -export default useUserStore \ No newline at end of file +export default useUserStore diff --git a/vite.config.js b/vite.config.js index 92343dd..886afcd 100644 --- a/vite.config.js +++ b/vite.config.js @@ -23,7 +23,7 @@ export default defineConfig(({ mode, command }) => { alias: alias, // 导入时想要省略的扩展名列表 // https://cn.vitejs.dev/config/#resolve-extensions - extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], + extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] }, css: { devSourcemap: true //开发模式时启用 @@ -37,11 +37,11 @@ export default defineConfig(({ mode, command }) => { // 将js、css文件分离到单独文件夹 rollupOptions: { output: { - chunkFileNames: "static/js/[name]-[hash].js", - entryFileNames: "static/js/[name]-[hash].js", - assetFileNames: "static/[ext]/[name]-[hash].[ext]" + chunkFileNames: 'static/js/[name]-[hash].js', + entryFileNames: 'static/js/[name]-[hash].js', + assetFileNames: 'static/[ext]/[name]-[hash].[ext]' } - }, + } }, // vite 相关配置 server: { @@ -60,7 +60,7 @@ export default defineConfig(({ mode, command }) => { ws: true, rewrite: (path) => path.replace(/^\/msgHub/, '') } - }, - }, + } + } } -}) \ No newline at end of file +})