mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-27 11:10:25 +08:00
✨ Feature(custom): optimize logic to get raw data from reactive object
This commit is contained in:
@@ -8,7 +8,7 @@ import { gunzipSync, gzipSync, strFromU8 } from 'fflate'
|
||||
import FormData from 'form-data'
|
||||
import fs from 'fs-extra'
|
||||
import { IPicGo } from 'piclist'
|
||||
import { isReactive, isRef, toRaw, unref } from 'vue'
|
||||
import { isProxy, isRef, toRaw, unref } from 'vue'
|
||||
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
import { IShortUrlServer } from '~/utils/enum'
|
||||
@@ -17,17 +17,39 @@ import { IShortUrlServer } from '~/utils/enum'
|
||||
* get raw data from reactive or ref
|
||||
*/
|
||||
export const getRawData = (args: any): any => {
|
||||
if (isRef(args)) return unref(args)
|
||||
if (isReactive(args)) return toRaw(args)
|
||||
if (Array.isArray(args)) return args.map(getRawData)
|
||||
if (typeof args === 'object' && args !== null) {
|
||||
const data = {} as Record<string, any>
|
||||
for (const key in args) {
|
||||
data[key] = getRawData(args[key])
|
||||
if (args === null || typeof args !== 'object') {
|
||||
return args
|
||||
}
|
||||
const raw = isRef(args) ? unref(args) : isProxy(args) ? toRaw(args) : args
|
||||
if (raw instanceof Date) return new Date(raw)
|
||||
if (raw instanceof RegExp) return new RegExp(raw)
|
||||
if (raw instanceof Map) {
|
||||
const result = new Map()
|
||||
raw.forEach((value, key) => {
|
||||
result.set(getRawData(key), getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (raw instanceof Set) {
|
||||
const result = new Set()
|
||||
raw.forEach(value => {
|
||||
result.add(getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.map(item => getRawData(item))
|
||||
}
|
||||
if (typeof raw === 'object') {
|
||||
const data: Record<string, any> = {}
|
||||
for (const key in raw) {
|
||||
if (Object.prototype.hasOwnProperty.call(raw, key)) {
|
||||
data[key] = getRawData(raw[key])
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
return args
|
||||
return raw
|
||||
}
|
||||
|
||||
const getExtension = (fileName: string) => path.extname(fileName).slice(1)
|
||||
|
||||
@@ -4,21 +4,43 @@ import path from 'node:path'
|
||||
import { clipboard, contextBridge, ipcRenderer, IpcRendererEvent, webFrame, webUtils } from 'electron'
|
||||
import fs from 'fs-extra'
|
||||
import mime from 'mime'
|
||||
import { isReactive, isRef, toRaw, unref } from 'vue'
|
||||
import { isProxy, isRef, toRaw, unref } from 'vue'
|
||||
import yaml from 'yaml'
|
||||
|
||||
export const getRawData = (args: any): any => {
|
||||
if (isRef(args)) return unref(args)
|
||||
if (isReactive(args)) return toRaw(args)
|
||||
if (Array.isArray(args)) return args.map(getRawData)
|
||||
if (typeof args === 'object' && args !== null) {
|
||||
const data = {} as Record<string, any>
|
||||
for (const key in args) {
|
||||
data[key] = getRawData(args[key])
|
||||
if (args === null || typeof args !== 'object') {
|
||||
return args
|
||||
}
|
||||
const raw = isRef(args) ? unref(args) : isProxy(args) ? toRaw(args) : args
|
||||
if (raw instanceof Date) return new Date(raw)
|
||||
if (raw instanceof RegExp) return new RegExp(raw)
|
||||
if (raw instanceof Map) {
|
||||
const result = new Map()
|
||||
raw.forEach((value, key) => {
|
||||
result.set(getRawData(key), getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (raw instanceof Set) {
|
||||
const result = new Set()
|
||||
raw.forEach(value => {
|
||||
result.add(getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.map(item => getRawData(item))
|
||||
}
|
||||
if (typeof raw === 'object') {
|
||||
const data: Record<string, any> = {}
|
||||
for (const key in raw) {
|
||||
if (Object.prototype.hasOwnProperty.call(raw, key)) {
|
||||
data[key] = getRawData(raw[key])
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
return args
|
||||
return raw
|
||||
}
|
||||
|
||||
function sendToMain(channel: string, ...args: any[]) {
|
||||
|
||||
@@ -1,20 +1,39 @@
|
||||
import { isReactive, isRef, toRaw, unref } from 'vue'
|
||||
import { isProxy, isRef, toRaw, unref } from 'vue'
|
||||
|
||||
/**
|
||||
* get raw data from reactive or ref
|
||||
*/
|
||||
export const getRawData = (args: any): any => {
|
||||
if (isRef(args)) return unref(args)
|
||||
if (isReactive(args)) return toRaw(args)
|
||||
if (Array.isArray(args)) return args.map(getRawData)
|
||||
if (typeof args === 'object' && args !== null) {
|
||||
const data = {} as Record<string, any>
|
||||
for (const key in args) {
|
||||
data[key] = getRawData(args[key])
|
||||
if (args === null || typeof args !== 'object') {
|
||||
return args
|
||||
}
|
||||
const raw = isRef(args) ? unref(args) : isProxy(args) ? toRaw(args) : args
|
||||
if (raw instanceof Date) return new Date(raw)
|
||||
if (raw instanceof RegExp) return new RegExp(raw)
|
||||
if (raw instanceof Map) {
|
||||
const result = new Map()
|
||||
raw.forEach((value, key) => {
|
||||
result.set(getRawData(key), getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (raw instanceof Set) {
|
||||
const result = new Set()
|
||||
raw.forEach(value => {
|
||||
result.add(getRawData(value))
|
||||
})
|
||||
return result
|
||||
}
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.map(item => getRawData(item))
|
||||
}
|
||||
if (typeof raw === 'object') {
|
||||
const data: Record<string, any> = {}
|
||||
for (const key in raw) {
|
||||
if (Object.prototype.hasOwnProperty.call(raw, key)) {
|
||||
data[key] = getRawData(raw[key])
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
return args
|
||||
return raw
|
||||
}
|
||||
|
||||
export const isUrl = (url: string): boolean => {
|
||||
|
||||
Reference in New Issue
Block a user