mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-03 06:42:09 +08:00
🎨 Style(custom): lint code
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
import { onMounted, onUnmounted } from 'vue'
|
||||
|
||||
import { IRPCActionType } from '@/utils/enum'
|
||||
|
||||
export function useATagClick () {
|
||||
const handleATagClick = (e: MouseEvent) => {
|
||||
if (e.target instanceof HTMLAnchorElement) {
|
||||
if (e.target.href) {
|
||||
if (!e.target.href.startsWith('http://localhost:3000')) {
|
||||
e.preventDefault()
|
||||
window.electron.sendRPC(IRPCActionType.OPEN_URL, e.target.href)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleATagClick)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', handleATagClick)
|
||||
})
|
||||
}
|
||||
import { onMounted, onUnmounted } from 'vue'
|
||||
|
||||
import { IRPCActionType } from '@/utils/enum'
|
||||
|
||||
export function useATagClick() {
|
||||
const handleATagClick = (e: MouseEvent) => {
|
||||
if (e.target instanceof HTMLAnchorElement) {
|
||||
if (e.target.href) {
|
||||
if (!e.target.href.startsWith('http://localhost:3000')) {
|
||||
e.preventDefault()
|
||||
window.electron.sendRPC(IRPCActionType.OPEN_URL, e.target.href)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleATagClick)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', handleATagClick)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,83 +1,82 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { IStringKeyMap } from '#/types/types'
|
||||
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
const settings = ref<IStringKeyMap>({
|
||||
app: {
|
||||
theme: 'light'
|
||||
}
|
||||
})
|
||||
const loading = ref(false)
|
||||
const error = ref<string | undefined>()
|
||||
|
||||
function clearError () {
|
||||
error.value = undefined
|
||||
}
|
||||
|
||||
const loadSettings = () => {
|
||||
const savedTheme = localStorage.getItem('theme')
|
||||
if (savedTheme) {
|
||||
settings.value.app.theme = savedTheme
|
||||
}
|
||||
applyTheme(settings.value.app.theme || 'light')
|
||||
}
|
||||
|
||||
function applyTheme (theme: string) {
|
||||
const root = document.documentElement
|
||||
root.classList.remove('light', 'dark', 'auto')
|
||||
|
||||
if (theme === 'auto') {
|
||||
root.classList.add('auto')
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
root.classList.add(prefersDark ? 'dark' : 'light')
|
||||
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
mediaQuery.addEventListener('change', e => {
|
||||
if (settings.value.app.theme === 'auto') {
|
||||
root.classList.remove('light', 'dark')
|
||||
root.classList.add(e.matches ? 'dark' : 'light')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
root.classList.add(theme)
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme (theme: 'light' | 'dark' | 'auto') {
|
||||
settings.value.app.theme = theme
|
||||
localStorage.setItem('theme', theme)
|
||||
applyTheme(theme)
|
||||
}
|
||||
|
||||
function toggleTheme () {
|
||||
const currentTheme = settings.value.app.theme || 'light'
|
||||
const themes = ['light', 'dark', 'auto'] as const
|
||||
const currentIndex = themes.indexOf(currentTheme as any)
|
||||
const nextTheme = themes[(currentIndex + 1) % themes.length]
|
||||
setTheme(nextTheme)
|
||||
}
|
||||
|
||||
function init () {
|
||||
try {
|
||||
loadSettings()
|
||||
} catch (err) {
|
||||
console.error('Application initialization failed:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
init,
|
||||
loadSettings,
|
||||
settings,
|
||||
loading,
|
||||
error,
|
||||
clearError,
|
||||
setTheme,
|
||||
toggleTheme,
|
||||
applyTheme
|
||||
|
||||
}
|
||||
})
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { IStringKeyMap } from '#/types/types'
|
||||
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
const settings = ref<IStringKeyMap>({
|
||||
app: {
|
||||
theme: 'light'
|
||||
}
|
||||
})
|
||||
const loading = ref(false)
|
||||
const error = ref<string | undefined>()
|
||||
|
||||
function clearError() {
|
||||
error.value = undefined
|
||||
}
|
||||
|
||||
const loadSettings = () => {
|
||||
const savedTheme = localStorage.getItem('theme')
|
||||
if (savedTheme) {
|
||||
settings.value.app.theme = savedTheme
|
||||
}
|
||||
applyTheme(settings.value.app.theme || 'light')
|
||||
}
|
||||
|
||||
function applyTheme(theme: string) {
|
||||
const root = document.documentElement
|
||||
root.classList.remove('light', 'dark', 'auto')
|
||||
|
||||
if (theme === 'auto') {
|
||||
root.classList.add('auto')
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
root.classList.add(prefersDark ? 'dark' : 'light')
|
||||
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
mediaQuery.addEventListener('change', e => {
|
||||
if (settings.value.app.theme === 'auto') {
|
||||
root.classList.remove('light', 'dark')
|
||||
root.classList.add(e.matches ? 'dark' : 'light')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
root.classList.add(theme)
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(theme: 'light' | 'dark' | 'auto') {
|
||||
settings.value.app.theme = theme
|
||||
localStorage.setItem('theme', theme)
|
||||
applyTheme(theme)
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
const currentTheme = settings.value.app.theme || 'light'
|
||||
const themes = ['light', 'dark', 'auto'] as const
|
||||
const currentIndex = themes.indexOf(currentTheme as any)
|
||||
const nextTheme = themes[(currentIndex + 1) % themes.length]
|
||||
setTheme(nextTheme)
|
||||
}
|
||||
|
||||
function init() {
|
||||
try {
|
||||
loadSettings()
|
||||
} catch (err) {
|
||||
console.error('Application initialization failed:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
init,
|
||||
loadSettings,
|
||||
settings,
|
||||
loading,
|
||||
error,
|
||||
clearError,
|
||||
setTheme,
|
||||
toggleTheme,
|
||||
applyTheme
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
export interface ConfirmOptions {
|
||||
title?: string
|
||||
message: string
|
||||
type?: 'info' | 'success' | 'warning' | 'error'
|
||||
confirmButtonText?: string
|
||||
cancelButtonText?: string
|
||||
showClose?: boolean
|
||||
center?: boolean
|
||||
}
|
||||
|
||||
interface ConfirmService {
|
||||
confirm: (options: ConfirmOptions) => Promise<boolean>
|
||||
}
|
||||
|
||||
const confirmServiceRef = ref<ConfirmService | null>(null)
|
||||
|
||||
export function useConfirm () {
|
||||
const setConfirmService = (service: ConfirmService) => {
|
||||
confirmServiceRef.value = service
|
||||
}
|
||||
|
||||
const confirm = (options: ConfirmOptions): Promise<boolean> => {
|
||||
if (confirmServiceRef.value) {
|
||||
return confirmServiceRef.value.confirm(options)
|
||||
}
|
||||
console.warn('Confirm service not initialized')
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
return {
|
||||
setConfirmService,
|
||||
confirm
|
||||
}
|
||||
}
|
||||
|
||||
export default useConfirm
|
||||
import { ref } from 'vue'
|
||||
|
||||
export interface ConfirmOptions {
|
||||
title?: string
|
||||
message: string
|
||||
type?: 'info' | 'success' | 'warning' | 'error'
|
||||
confirmButtonText?: string
|
||||
cancelButtonText?: string
|
||||
showClose?: boolean
|
||||
center?: boolean
|
||||
}
|
||||
|
||||
interface ConfirmService {
|
||||
confirm: (options: ConfirmOptions) => Promise<boolean>
|
||||
}
|
||||
|
||||
const confirmServiceRef = ref<ConfirmService | null>(null)
|
||||
|
||||
export function useConfirm() {
|
||||
const setConfirmService = (service: ConfirmService) => {
|
||||
confirmServiceRef.value = service
|
||||
}
|
||||
|
||||
const confirm = (options: ConfirmOptions): Promise<boolean> => {
|
||||
if (confirmServiceRef.value) {
|
||||
return confirmServiceRef.value.confirm(options)
|
||||
}
|
||||
console.warn('Confirm service not initialized')
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
return {
|
||||
setConfirmService,
|
||||
confirm
|
||||
}
|
||||
}
|
||||
|
||||
export default useConfirm
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { MessageOptions } from '@/components/ui/MessageToast.vue'
|
||||
|
||||
interface MessageService {
|
||||
success: (message: string, options?: Partial<MessageOptions>) => string
|
||||
error: (message: string, options?: Partial<MessageOptions>) => string
|
||||
warning: (message: string, options?: Partial<MessageOptions>) => string
|
||||
info: (message: string, options?: Partial<MessageOptions>) => string
|
||||
}
|
||||
|
||||
const messageServiceRef = ref<MessageService | null>(null)
|
||||
|
||||
export function useMessage () {
|
||||
const setMessageService = (service: MessageService) => {
|
||||
messageServiceRef.value = service
|
||||
}
|
||||
|
||||
const success = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.success(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const error = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.error(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const warning = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.warning(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const info = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.info(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
return {
|
||||
setMessageService,
|
||||
success,
|
||||
error,
|
||||
warning,
|
||||
info
|
||||
}
|
||||
}
|
||||
|
||||
export default useMessage
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { MessageOptions } from '@/components/ui/MessageToast.vue'
|
||||
|
||||
interface MessageService {
|
||||
success: (message: string, options?: Partial<MessageOptions>) => string
|
||||
error: (message: string, options?: Partial<MessageOptions>) => string
|
||||
warning: (message: string, options?: Partial<MessageOptions>) => string
|
||||
info: (message: string, options?: Partial<MessageOptions>) => string
|
||||
}
|
||||
|
||||
const messageServiceRef = ref<MessageService | null>(null)
|
||||
|
||||
export function useMessage() {
|
||||
const setMessageService = (service: MessageService) => {
|
||||
messageServiceRef.value = service
|
||||
}
|
||||
|
||||
const success = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.success(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const error = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.error(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const warning = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.warning(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
const info = (message: string, options?: Partial<MessageOptions>) => {
|
||||
if (messageServiceRef.value) {
|
||||
return messageServiceRef.value.info(message, options)
|
||||
}
|
||||
console.warn('Message service not initialized')
|
||||
return ''
|
||||
}
|
||||
|
||||
return {
|
||||
setMessageService,
|
||||
success,
|
||||
error,
|
||||
warning,
|
||||
info
|
||||
}
|
||||
}
|
||||
|
||||
export default useMessage
|
||||
|
||||
@@ -9,14 +9,8 @@ export interface UseVirtualGridOptions {
|
||||
bufferFactor?: number
|
||||
}
|
||||
|
||||
export function useVirtualGrid (options: UseVirtualGridOptions) {
|
||||
const {
|
||||
items,
|
||||
itemHeight,
|
||||
containerHeight,
|
||||
gridItems = 1,
|
||||
bufferFactor = 0.5
|
||||
} = options
|
||||
export function useVirtualGrid(options: UseVirtualGridOptions) {
|
||||
const { items, itemHeight, containerHeight, gridItems = 1, bufferFactor = 0.5 } = options
|
||||
|
||||
const gridItemsRef = isRef(gridItems) ? gridItems : ref(gridItems)
|
||||
const scrollTop = ref(0)
|
||||
@@ -43,7 +37,7 @@ export function useVirtualGrid (options: UseVirtualGridOptions) {
|
||||
return { startRow: 0, endRow: 0, visibleRows: 0 }
|
||||
}
|
||||
|
||||
const buffer = Math.ceil(height / rowHeight * bufferFactor)
|
||||
const buffer = Math.ceil((height / rowHeight) * bufferFactor)
|
||||
const startRow = Math.max(0, Math.floor(scrollTop.value / rowHeight) - buffer)
|
||||
const visibleRows = Math.ceil(height / rowHeight) + buffer * 2
|
||||
const endRow = Math.min(totalRows, startRow + visibleRows)
|
||||
@@ -74,21 +68,21 @@ export function useVirtualGrid (options: UseVirtualGridOptions) {
|
||||
return startRow * rowHeight
|
||||
})
|
||||
|
||||
function updateScrollTop (newScrollTop: number) {
|
||||
function updateScrollTop(newScrollTop: number) {
|
||||
scrollTop.value = newScrollTop
|
||||
}
|
||||
|
||||
function scrollToItem (index: number) {
|
||||
function scrollToItem(index: number) {
|
||||
const { itemsPerRow, rowHeight } = gridCalculations.value
|
||||
const rowIndex = Math.floor(index / itemsPerRow)
|
||||
scrollTop.value = rowIndex * rowHeight
|
||||
}
|
||||
|
||||
function scrollToTop () {
|
||||
function scrollToTop() {
|
||||
scrollTop.value = 0
|
||||
}
|
||||
|
||||
function scrollToBottom () {
|
||||
function scrollToBottom() {
|
||||
const { totalHeight } = gridCalculations.value
|
||||
scrollTop.value = Math.max(0, totalHeight - containerHeight.value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user