fix(lint): resolve eslint error

This commit is contained in:
Coffee-crocodile 2023-06-21 12:04:28 +08:00
parent 828466d08c
commit 6bc16a28f9
16 changed files with 59 additions and 58 deletions

View File

@ -3,4 +3,12 @@ process.env.ESLINT_TSCONFIG = 'tsconfig.json'
module.exports = {
extends: '@chansee97/eslint-config-vue',
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
}

View File

@ -10,7 +10,7 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // https://github.c
export default [
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
include: [
/\.[tj]sx?$/,
/\.vue$/,

View File

@ -41,7 +41,7 @@
"dev:prod": "vite --mode production",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"lint": "eslint --fix",
"lint": "eslint . --fix",
"prepare": "husky install",
"commit": "cz",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"

View File

@ -11,13 +11,13 @@ export function useAppRouter(isSetup = true) {
const route = router.currentRoute
/* 路由跳转方法 */
function routerPush(to: RouteLocationRaw) {
router.push(to)
async function routerPush(to: RouteLocationRaw) {
await router.push(to)
}
/* 路由跳转方法 */
function routerReplace(to: RouteLocationRaw) {
router.replace(to)
async function routerReplace(to: RouteLocationRaw) {
await router.replace(to)
}
/* 前进后退方法 */
@ -26,25 +26,25 @@ export function useAppRouter(isSetup = true) {
}
/* 跳转根页方法 */
function toRoot() {
routerPush({ path: '/appRoot' })
async function toRoot() {
await routerPush({ path: '/appRoot' })
}
/* 跳转至登录页 */
function toLogin(redirectUrl?: string) {
async function toLogin(redirectUrl?: string) {
const redirect = redirectUrl || route.value.fullPath
const targetUrl = {
name: 'login',
query: { redirect },
}
routerPush(targetUrl)
await routerPush(targetUrl)
}
/* 跳转重定向方法 */
function toLoginRedirect() {
async function toLoginRedirect() {
const { query } = route.value
if (query?.redirect)
routerPush(query.redirect as string)
await routerPush(query.redirect as string)
else
toRoot()
await toRoot()
}
return {

View File

@ -2,7 +2,7 @@ export function useClipBoard() {
function isSupport() {
return !navigator.clipboard
}
async function copy(text: string) {
function copy(text: string) {
if (isSupport())
return window.$message?.error('当前浏览器不支持复制!')

View File

@ -30,7 +30,6 @@ import {
import { LabelLayout, UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'
import { useElementSize } from '@vueuse/core'
import { useAppStore } from '@/store'
// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
@ -109,7 +108,7 @@ export function useEcharts(options: Ref<ECOption>) {
chart?.dispose()
chart = null
}
const sizeWatch = watch([width, height], ([newWidth, newHeight]) => {
const sizeWatch = watch([width, height], async ([newWidth, newHeight]) => {
initialSize.width = newWidth
initialSize.height = newHeight
if (newWidth === 0 && newHeight === 0) {
@ -120,7 +119,7 @@ export function useEcharts(options: Ref<ECOption>) {
return
if (isRendered())
resize()
else render()
else await render()
})
const OptionWatch = watch(options, (newValue) => {

View File

@ -49,7 +49,7 @@ function createCatheRoutes(routes: AppRoute.Route[]) {
})
.map(item => item.name)
}
export async function createDynamicRoutes(routes: AppRoute.Route[]) {
export function createDynamicRoutes(routes: AppRoute.Route[]) {
/* 复制一层 */
let resultRouter = JSON.parse(JSON.stringify(routes))
/* 设置路由重定向到子级第一个 */

View File

@ -102,7 +102,7 @@ export function handleBusinessError(data: Record<string, any>, config: Service.B
* @param {Service} error
* @return {*} result
*/
export async function handleServiceResult<T = any>(data: any, error: Service.RequestError | null) {
export function handleServiceResult<T = any>(data: any, error: Service.RequestError | null) {
if (error) {
const fail: Service.FailedResult = {
error,
@ -123,7 +123,7 @@ export async function handleServiceResult<T = any>(data: any, error: Service.Req
* @return {*}
*/
export async function handleRefreshToken(config: AxiosRequestConfig) {
const { resetAuthStore } = useAuthStore()
const authStore = useAuthStore()
const refreshToken = local.get('refreshToken')
const { data } = await fetchUpdateToken(refreshToken)
if (data) {
@ -136,6 +136,6 @@ export async function handleRefreshToken(config: AxiosRequestConfig) {
return config
}
resetAuthStore()
await authStore.resetAuthStore()
return null
}

View File

@ -16,7 +16,7 @@ export function showError(error: Service.RequestError) {
* @param requestData -
* @param contentType - Content-Type
*/
export async function transformRequestData(
export function transformRequestData(
requestData: any,
contentType?: UnionKey.ContentType,
) {
@ -29,16 +29,16 @@ export async function transformRequestData(
// form-data类型转换
if (contentType === 'multipart/form-data')
data = await handleFormData(data)
data = handleFormData(data)
return data
}
async function handleFormData(data: Record<string, any>) {
function handleFormData(data: Record<string, any>) {
const formData = new FormData()
const entries = Object.entries(data)
entries.forEach(async ([key, value]) => {
entries.forEach(([key, value]) => {
const isFileType
= isFile(value) || (isArray(value) && value.length && isFile(value[0]))

View File

@ -21,12 +21,14 @@ interface AppStatus {
const docEle = document.documentElement
const { isFullscreen, toggle } = useFullscreen(docEle)
export const useAppStore = defineStore('app-store', {
state: (): AppStatus => {
return {
footerText: 'Copyright ©2023 Ench Admin',
collapsed: false,
fullScreen: false,
fullScreen: isFullscreen.value,
darkMode: false,
grayMode: false,
colorWeak: false,
@ -47,15 +49,9 @@ export const useAppStore = defineStore('app-store', {
this.collapsed = !this.collapsed
},
/* 切换全屏 */
toggleFullScreen() {
if (!document.fullscreenElement) {
this.fullScreen = true
document.documentElement.requestFullscreen()
}
else if (document.exitFullscreen) {
this.fullScreen = false
document.exitFullscreen()
}
async toggleFullScreen() {
this.fullScreen = isFullscreen.value
await toggle()
},
/* 切换主题 亮/深色 */
toggleDarkMode() {

View File

@ -4,6 +4,7 @@ import { router } from '@/router'
import { useAppRouter } from '@/hooks'
import { local } from '@/utils'
const routeStore = useRouteStore()
const emptyInfo: Auth.UserInfo = {
userId: 0,
userName: '',
@ -28,17 +29,16 @@ export const useAuthStore = defineStore('auth-store', {
},
actions: {
/* 登录退出,重置用户信息等 */
resetAuthStore() {
async resetAuthStore() {
const route = unref(router.currentRoute)
const { toLogin } = useAppRouter(false)
const { resetRouteStore } = useRouteStore()
// 清除本地缓存
this.clearAuthStorage()
// 清空路由、菜单等数据
resetRouteStore()
routeStore.resetRouteStore()
this.$reset()
if (route.meta.requiresAuth)
toLogin()
await toLogin()
},
clearAuthStorage() {
local.remove('token')
@ -66,14 +66,14 @@ export const useAuthStore = defineStore('auth-store', {
const catchSuccess = await this.catchUserInfo(data)
// 添加路由和菜单
const { initAuthRoute } = useRouteStore()
await initAuthRoute()
// const { initAuthRoute } = useRouteStore()
await routeStore.initAuthRoute()
// 登录写入信息成功
if (catchSuccess) {
// 进行重定向跳转
const { toLoginRedirect } = useAppRouter(false)
toLoginRedirect()
await toLoginRedirect()
// 触发用户提示
window.$notification?.success({
@ -84,7 +84,7 @@ export const useAuthStore = defineStore('auth-store', {
return
}
// 如果不成功则重置存储
this.resetAuthStore()
await this.resetAuthStore()
},
/* 缓存用户信息 */
@ -107,8 +107,8 @@ export const useAuthStore = defineStore('auth-store', {
return catchSuccess
},
toggleUserRole(role: Auth.RoleType) {
this.login(role, '123456')
async toggleUserRole(role: Auth.RoleType) {
await this.login(role, '123456')
},
},
})

View File

@ -160,16 +160,16 @@ export const useRouteStore = defineStore('route-store', {
if (!routes)
return
// 根据用户返回的路由表来生成真实路由
const appRoutes = await createDynamicRoutes(routes)
const appRoutes = createDynamicRoutes(routes)
// 生成侧边菜单
this.createMenus(routes)
// 插入路由表
router.addRoute(appRoutes)
},
/* 初始化静态路由 */
async initStaticRoute() {
initStaticRoute() {
// 根据静态路由表来生成真实路由
const appRoutes = await createDynamicRoutes(staticRoutes)
const appRoutes = createDynamicRoutes(staticRoutes)
// 生成侧边菜单
this.createMenus(staticRoutes)
// 插入路由表
@ -180,7 +180,7 @@ export const useRouteStore = defineStore('route-store', {
this.isInitAuthRoute = false
if (this.authRouteMode === 'dynamic')
await this.initDynamicRoute()
else await this.initStaticRoute()
else this.initStaticRoute()
this.isInitAuthRoute = true
},

View File

@ -49,7 +49,7 @@ export const useTabStore = defineStore('tab-store', {
this.tabs.push(route)
},
closeTab(name: string) {
async closeTab(name: string) {
const { routerPush, toRoot } = useAppRouter(false)
const tabsLength = this.tabs.length
// 如果动态标签大于一个,才会标签跳转
@ -60,11 +60,11 @@ export const useTabStore = defineStore('tab-store', {
// 如果是关闭的当前页面,路由跳转到原先标签的后一个标签
if (this.currentTab === name && !isLast) {
// 跳转到后一个标签
routerPush(this.tabs[index + 1].path)
await routerPush(this.tabs[index + 1].path)
}
else if (this.currentTab === name && isLast) {
// 已经是最后一个了,就跳转前一个
routerPush(this.tabs[index - 1].path)
await routerPush(this.tabs[index - 1].path)
}
}
// 删除标签
@ -73,7 +73,7 @@ export const useTabStore = defineStore('tab-store', {
})
// 删除后如果清空了,就跳转到默认首页
if (tabsLength - 1 === 0)
toRoot()
await toRoot()
},
closeOtherTabs(name: string) {
@ -88,10 +88,10 @@ export const useTabStore = defineStore('tab-store', {
const index = this.getTabIndex(name)
this.tabs = this.tabs.filter((item, i) => i <= index)
},
closeAllTabs() {
async closeAllTabs() {
const { toRoot } = useAppRouter(false)
this.tabs.length = 0
toRoot()
await toRoot()
},
hasExistTab(name: string) {

View File

@ -1,4 +1,4 @@
const toString = Object.prototype.toString
const toString = Object.prototype.toString.bind({})
export function is(val: unknown, type: string) {
return toString.call(val) === `[object ${type}]`

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { useScriptTag } from '@vueuse/core'
import { GAODE_MAP_SDK_URL } from '@/config'
const { load } = useScriptTag(GAODE_MAP_SDK_URL)

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { useScriptTag } from '@vueuse/core'
import { BAIDU_MAP_SDK_URL } from '@/config'
const { load } = useScriptTag(BAIDU_MAP_SDK_URL)