es lint fix

This commit is contained in:
thofx
2023-07-22 16:09:07 +08:00
parent 48749b29fe
commit 018778488a
80 changed files with 3994 additions and 2981 deletions
+8 -5
View File
@@ -1,15 +1,18 @@
<script lang="ts" setup>
// 定义触发的自定义事件
const emit = defineEmits(["click"]);
const emit = defineEmits(['click'])
// 按钮点击
const onClick = () => {
emit("click");
};
function onClick() {
emit('click')
}
</script>
<template>
<IconBtn class="absolute right-3 top-3" @click="onClick">
<IconBtn
class="absolute right-3 top-3"
@click="onClick"
>
<VIcon icon="mdi-close" />
</IconBtn>
</template>
+12 -6
View File
@@ -1,20 +1,26 @@
<script setup lang="ts">
interface Props {
errorCode?: string;
errorTitle?: string;
errorDescription?: string;
errorCode?: string
errorTitle?: string
errorDescription?: string
}
const props = defineProps<Props>();
const props = defineProps<Props>()
</script>
<template>
<div class="text-center mb-4">
<!-- 👉 Title and subtitle -->
<h1 v-if="props.errorCode" class="text-h1 font-weight-medium">
<h1
v-if="props.errorCode"
class="text-h1 font-weight-medium"
>
{{ props.errorCode }}
</h1>
<h5 v-if="props.errorTitle" class="text-h5 font-weight-medium mb-3">
<h5
v-if="props.errorTitle"
class="text-h5 font-weight-medium mb-3"
>
{{ props.errorTitle }}
</h5>
<p v-if="props.errorDescription">
+3 -7
View File
@@ -1,12 +1,8 @@
<template>
<div class="absolute top-0 right-0 flex items-center justify-between p-2">
<div class="pointer-events-none z-40 flex items-center">
<div
class="relative inline-flex whitespace-nowrap rounded-full border-gray-700 font-semibold leading-5 ring-gray-700"
>
<div
class="rounded-full bg-opacity-80 shadow-md w-5 border p-0 bg-green-500 border-green-400 ring-green-400 text-green-100"
>
<div class="relative inline-flex whitespace-nowrap rounded-full border-gray-700 font-semibold leading-5 ring-gray-700">
<div class="rounded-full bg-opacity-80 shadow-md w-5 border p-0 bg-green-500 border-green-400 ring-green-400 text-green-100">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
@@ -17,7 +13,7 @@
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
clip-rule="evenodd"
></path>
/>
</svg>
</div>
</div>
+12 -5
View File
@@ -1,18 +1,25 @@
<script lang="ts" setup>
interface Props {
menuList?: unknown[];
itemProps?: boolean;
menuList?: unknown[]
itemProps?: boolean
}
const props = defineProps<Props>();
const props = defineProps<Props>()
</script>
<template>
<IconBtn>
<VIcon icon="mdi-dots-vertical" />
<VMenu v-if="props.menuList" activator="parent" close-on-content-click>
<VList :items="props.menuList" :item-props="props.itemProps" />
<VMenu
v-if="props.menuList"
activator="parent"
close-on-content-click
>
<VList
:items="props.menuList"
:item-props="props.itemProps"
/>
</VMenu>
</IconBtn>
</template>
+21 -21
View File
@@ -1,45 +1,45 @@
<script setup lang="ts">
import type { ThemeSwitcherTheme } from "@layouts/types";
import { ref, watch } from "vue";
import { useTheme } from "vuetify";
import { ref, watch } from 'vue'
import { useTheme } from 'vuetify'
import type { ThemeSwitcherTheme } from '@layouts/types'
const props = defineProps<{
themes: ThemeSwitcherTheme[];
}>();
themes: ThemeSwitcherTheme[]
}>()
const { name: themeName, global: globalTheme } = useTheme();
const { name: themeName, global: globalTheme } = useTheme()
const savedTheme = ref(localStorage.getItem("theme") ?? themeName);
const savedTheme = ref(localStorage.getItem('theme') ?? themeName)
const {
state: currentThemeName,
next: getNextThemeName,
index: currentThemeIndex,
} = useCycleList(
props.themes.map((t) => t.name),
{ initialValue: savedTheme.value }
);
props.themes.map(t => t.name),
{ initialValue: savedTheme.value },
)
const changeTheme = () => {
const nextTheme = getNextThemeName();
function changeTheme() {
const nextTheme = getNextThemeName()
globalTheme.name.value = nextTheme;
savedTheme.value = nextTheme;
localStorage.setItem("theme", nextTheme);
};
globalTheme.name.value = nextTheme
savedTheme.value = nextTheme
localStorage.setItem('theme', nextTheme)
}
// Update icon if theme is changed from other sources
watch(
() => globalTheme.name.value,
(val) => {
currentThemeName.value = val;
}
);
currentThemeName.value = val
},
)
// Apply saved theme on page load
onMounted(() => {
globalTheme.name.value = savedTheme.value;
});
globalTheme.name.value = savedTheme.value
})
</script>
<template>
+13 -13
View File
@@ -2,7 +2,7 @@ import type { ThemeInstance } from 'vuetify'
import { hexToRgb } from '@layouts/utils'
// 👉 Colors variables
const colorVariables = (themeColors: ThemeInstance['themes']['value']['colors']) => {
function colorVariables(themeColors: ThemeInstance['themes']['value']['colors']) {
const themeSecondaryTextColor = `rgba(${hexToRgb(themeColors.colors['on-surface'])},${themeColors.variables['medium-emphasis-opacity']})`
const themeDisabledTextColor = `rgba(${hexToRgb(themeColors.colors['on-surface'])},${themeColors.variables['disabled-opacity']})`
const themeBorderColor = `rgba(${hexToRgb(String(themeColors.variables['border-color']))},${themeColors.variables['border-opacity']})`
@@ -11,7 +11,7 @@ const colorVariables = (themeColors: ThemeInstance['themes']['value']['colors'])
return { themeSecondaryTextColor, themeDisabledTextColor, themeBorderColor, themePrimaryTextColor }
}
export const getScatterChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getScatterChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const scatterColors = {
series1: '#ff9f43',
series2: '#7367f0',
@@ -67,7 +67,7 @@ export const getScatterChartConfig = (themeColors: ThemeInstance['themes']['valu
},
}
}
export const getLineChartSimpleConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getLineChartSimpleConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const { themeBorderColor, themeDisabledTextColor } = colorVariables(themeColors)
return {
@@ -94,7 +94,7 @@ export const getLineChartSimpleConfig = (themeColors: ThemeInstance['themes']['v
},
},
tooltip: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
custom(data: any) {
return `<div class='bar-chart pa-2'>
<span>${data.series[data.seriesIndex][data.dataPointIndex]}%</span>
@@ -137,7 +137,7 @@ export const getLineChartSimpleConfig = (themeColors: ThemeInstance['themes']['v
}
}
export const getBarChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getBarChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const { themeBorderColor, themeDisabledTextColor } = colorVariables(themeColors)
return {
@@ -180,7 +180,7 @@ export const getBarChartConfig = (themeColors: ThemeInstance['themes']['value'][
}
}
export const getCandlestickChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getCandlestickChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const candlestickColors = {
series1: '#28c76f',
series2: '#ea5455',
@@ -231,7 +231,7 @@ export const getCandlestickChartConfig = (themeColors: ThemeInstance['themes']['
},
}
}
export const getRadialBarChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getRadialBarChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const radialBarColors = {
series1: '#fdd835',
series2: '#32baff',
@@ -282,7 +282,7 @@ export const getRadialBarChartConfig = (themeColors: ThemeInstance['themes']['va
fontSize: '1.125rem',
color: themePrimaryTextColor,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
formatter(w: { globals: { seriesTotals: any[]; series: string | any[] } }) {
const totalValue
= w.globals.seriesTotals.reduce((a: number, b: number) => {
@@ -307,7 +307,7 @@ export const getRadialBarChartConfig = (themeColors: ThemeInstance['themes']['va
}
}
export const getDonutChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getDonutChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const donutColors = {
series1: '#fdd835',
series2: '#00d4bd',
@@ -401,7 +401,7 @@ export const getDonutChartConfig = (themeColors: ThemeInstance['themes']['value'
}
}
export const getAreaChartSplineConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getAreaChartSplineConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const areaColors = {
series3: '#e0cffe',
series2: '#b992fe',
@@ -482,7 +482,7 @@ export const getAreaChartSplineConfig = (themeColors: ThemeInstance['themes']['v
}
}
export const getColumnChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getColumnChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const columnColors = {
series1: '#826af9',
series2: '#d2b0ff',
@@ -568,7 +568,7 @@ export const getColumnChartConfig = (themeColors: ThemeInstance['themes']['value
}
}
export const getHeatMapChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getHeatMapChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const { themeSecondaryTextColor, themeDisabledTextColor } = colorVariables(themeColors)
return {
@@ -627,7 +627,7 @@ export const getHeatMapChartConfig = (themeColors: ThemeInstance['themes']['valu
}
}
export const getRadarChartConfig = (themeColors: ThemeInstance['themes']['value']['colors']) => {
export function getRadarChartConfig(themeColors: ThemeInstance['themes']['value']['colors']) {
const radarColors = {
series1: '#9b88fa',
series2: '#ffa1a1',
+31 -34
View File
@@ -1,6 +1,6 @@
import { isToday } from './index'
export const avatarText = (value: string) => {
export function avatarText(value: string) {
if (!value)
return ''
const nameArray = value.split(' ')
@@ -9,7 +9,7 @@ export const avatarText = (value: string) => {
}
// TODO: Try to implement this: https://twitter.com/fireship_dev/status/1565424801216311297
export const kFormatter = (num: number) => {
export function kFormatter(num: number) {
const regex = /\B(?=(\d{3})+(?!\d))/g
return Math.abs(num) > 9999 ? `${Math.sign(num) * +((Math.abs(num) / 1000).toFixed(1))}k` : Math.abs(num).toFixed(0).replace(regex, ',')
@@ -22,7 +22,7 @@ export const kFormatter = (num: number) => {
* @param {String} value date to format
* @param {Intl.DateTimeFormatOptions} formatting Intl object to format with
*/
export const formatDate = (value: string, formatting: Intl.DateTimeFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' }) => {
export function formatDate(value: string, formatting: Intl.DateTimeFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' }) {
if (!value)
return value
@@ -35,7 +35,7 @@ export const formatDate = (value: string, formatting: Intl.DateTimeFormatOptions
* @param {String} value date to format
* @param {Boolean} toTimeForCurrentDay Shall convert to time if day is today/current
*/
export const formatDateToMonthShort = (value: string, toTimeForCurrentDay = true) => {
export function formatDateToMonthShort(value: string, toTimeForCurrentDay = true) {
const date = new Date(value)
let formatting: Record<string, string> = { month: 'short', day: 'numeric' }
@@ -51,50 +51,47 @@ export const prefixWithPlus = (value: number) => value > 0 ? `+${value}` : value
export const formatSeason = (value: string) => value ? `S${value.padStart(2, '0')}` : ''
// 格式化为xx[TGMK]B
export const formatFileSize = (bytes: number) => {
if (bytes < 0) {
throw new Error("字节数不能为负数。");
}
export function formatFileSize(bytes: number) {
if (bytes < 0)
throw new Error('字节数不能为负数。')
const units = ["B", "K", "M", "G", "T"];
let size = bytes;
let unitIndex = 0;
const units = ['B', 'K', 'M', 'G', 'T']
let size = bytes
let unitIndex = 0
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
size /= 1024
unitIndex++
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
return `${size.toFixed(2)} ${units[unitIndex]}`
}
// 将时间秒格式化为时分秒
export const formatSeconds = (seconds: number) => {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
export function formatSeconds(seconds: number) {
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const remainingSeconds = seconds % 60
let formattedTime = '';
let formattedTime = ''
if (hours > 0) {
formattedTime += `${hours}小时`;
}
if (hours > 0)
formattedTime += `${hours}小时`
if (minutes > 0) {
formattedTime += `${minutes}`;
}
if (minutes > 0)
formattedTime += `${minutes}`
if ((remainingSeconds > 0 || formattedTime === '') && hours <= 0) {
formattedTime += `${remainingSeconds}`;
}
if ((remainingSeconds > 0 || formattedTime === '') && hours <= 0)
formattedTime += `${remainingSeconds}`
return formattedTime;
return formattedTime
}
// YYYY-MM-DD 转化为Date
export const parseDate = (dateString: string): Date => {
if (!dateString) return new Date();
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day);
export function parseDate(dateString: string): Date {
if (!dateString)
return new Date()
const [year, month, day] = dateString.split('-').map(Number)
return new Date(year, month - 1, day)
}
+34 -29
View File
@@ -1,5 +1,5 @@
// 👉 IsEmpty
export const isEmpty = (value: unknown): boolean => {
export function isEmpty(value: unknown): boolean {
if (value === null || value === undefined || value === '')
return true
@@ -7,20 +7,21 @@ export const isEmpty = (value: unknown): boolean => {
}
// 👉 IsNullOrUndefined
export const isNullOrUndefined = (value: unknown): value is undefined | null => {
export function isNullOrUndefined(value: unknown): value is undefined | null {
return value === null || value === undefined
}
// 👉 IsEmptyArray
export const isEmptyArray = (arr: unknown): boolean => {
export function isEmptyArray(arr: unknown): boolean {
return Array.isArray(arr) && arr.length === 0
}
// 👉 IsObject
export const isObject = (obj: unknown): obj is Record<string, unknown> =>
obj !== null && !!obj && typeof obj === 'object' && !Array.isArray(obj)
export function isObject(obj: unknown): obj is Record<string, unknown> {
return obj !== null && !!obj && typeof obj === 'object' && !Array.isArray(obj)
}
export const isToday = (date: Date) => {
export function isToday(date: Date) {
const today = new Date()
return (
@@ -33,38 +34,42 @@ export const isToday = (date: Date) => {
}
// 计算时间差,返回xx天xx小时xx分钟
export const calculateTimeDifference = (inputTime: string): string => {
export function calculateTimeDifference(inputTime: string): string {
if (!inputTime)
return ''
if (!inputTime) {
return '';
}
const inputDate = new Date(inputTime)
const currentDate = new Date()
const inputDate = new Date(inputTime);
const currentDate = new Date();
const timeDifference = currentDate.getTime() - inputDate.getTime();
const secondsDifference = Math.floor(timeDifference / 1000);
const timeDifference = currentDate.getTime() - inputDate.getTime()
const secondsDifference = Math.floor(timeDifference / 1000)
if (secondsDifference < 60) {
return `${secondsDifference}`;
} else if (secondsDifference < 3600) {
const minutes = Math.floor(secondsDifference / 60);
return `${minutes}分钟`;
} else if (secondsDifference < 86400) {
const hours = Math.floor(secondsDifference / 3600);
return `${hours}小时`;
} else {
const days = Math.floor(secondsDifference / 86400);
return `${days}`;
return `${secondsDifference}`
}
else if (secondsDifference < 3600) {
const minutes = Math.floor(secondsDifference / 60)
return `${minutes}分钟`
}
else if (secondsDifference < 86400) {
const hours = Math.floor(secondsDifference / 3600)
return `${hours}小时`
}
else {
const days = Math.floor(secondsDifference / 86400)
return `${days}`
}
}
// 判断一个数组subArray是不是在另一个数组mainArray中
export const isContained = (subArray: any[], mainArray: any[]): boolean => {
return subArray.every(element => mainArray.includes(element));
export function isContained(subArray: any[], mainArray: any[]): boolean {
return subArray.every(element => mainArray.includes(element))
}
// 判断两个数组是否存在交集
export const isIntersected = (array1: any[], array2: any[]): boolean => {
return array1.some(element => array2.includes(element));
export function isIntersected(array1: any[], array2: any[]): boolean {
return array1.some(element => array2.includes(element))
}