init
This commit is contained in:
@@ -257,7 +257,13 @@ const currentColor = computed(() => {
|
||||
return `rgb(${rgb.value.r}, ${rgb.value.g}, ${rgb.value.b})`
|
||||
})
|
||||
|
||||
// RGB转十六进制
|
||||
/**
|
||||
* RGB转十六进制
|
||||
* @param {number} r - 红色值 (0-255)
|
||||
* @param {number} g - 绿色值 (0-255)
|
||||
* @param {number} b - 蓝色值 (0-255)
|
||||
* @returns {string} 十六进制颜色值(不含#号)
|
||||
*/
|
||||
function rgbToHex(r, g, b) {
|
||||
const toHex = (n) => {
|
||||
const hex = Math.round(Math.max(0, Math.min(255, n))).toString(16)
|
||||
@@ -266,7 +272,13 @@ function rgbToHex(r, g, b) {
|
||||
return (toHex(r) + toHex(g) + toHex(b)).toUpperCase()
|
||||
}
|
||||
|
||||
// RGB转HSL
|
||||
/**
|
||||
* RGB转HSL
|
||||
* @param {number} r - 红色值 (0-255)
|
||||
* @param {number} g - 绿色值 (0-255)
|
||||
* @param {number} b - 蓝色值 (0-255)
|
||||
* @returns {{h: number, s: number, l: number}} HSL对象
|
||||
*/
|
||||
function rgbToHsl(r, g, b) {
|
||||
r /= 255
|
||||
g /= 255
|
||||
@@ -302,7 +314,11 @@ function rgbToHsl(r, g, b) {
|
||||
}
|
||||
}
|
||||
|
||||
// 十六进制转RGB
|
||||
/**
|
||||
* 十六进制转RGB
|
||||
* @param {string} hex - 十六进制颜色值(不含#号)
|
||||
* @returns {{r: number, g: number, b: number}|null} RGB对象或null
|
||||
*/
|
||||
function hexToRgb(hex) {
|
||||
const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
||||
return result
|
||||
@@ -314,7 +330,13 @@ function hexToRgb(hex) {
|
||||
: null
|
||||
}
|
||||
|
||||
// HSL转RGB
|
||||
/**
|
||||
* HSL转RGB
|
||||
* @param {number} h - 色相 (0-360)
|
||||
* @param {number} s - 饱和度 (0-100)
|
||||
* @param {number} l - 亮度 (0-100)
|
||||
* @returns {{r: number, g: number, b: number}} RGB对象
|
||||
*/
|
||||
function hslToRgb(h, s, l) {
|
||||
h /= 360
|
||||
s /= 100
|
||||
@@ -568,7 +590,6 @@ async function copyRgb() {
|
||||
await navigator.clipboard.writeText(rgbText)
|
||||
showToast('RGB已复制到剪贴板', 'info', 2000)
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
showToast('复制失败:' + err.message)
|
||||
}
|
||||
}
|
||||
@@ -651,7 +672,6 @@ async function pasteRgb() {
|
||||
const text = await navigator.clipboard.readText()
|
||||
processPastedText(text, 'rgb')
|
||||
} catch (err) {
|
||||
console.error('粘贴失败:', err)
|
||||
// Clipboard API 失败,使用备用方法
|
||||
currentPasteType.value = 'rgb'
|
||||
pasteInputValue.value = ''
|
||||
@@ -682,7 +702,6 @@ async function copyHex() {
|
||||
await navigator.clipboard.writeText(hexText)
|
||||
showToast('十六进制已复制到剪贴板', 'info', 2000)
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
showToast('复制失败:' + err.message)
|
||||
}
|
||||
}
|
||||
@@ -695,7 +714,6 @@ async function pasteHex() {
|
||||
const text = await navigator.clipboard.readText()
|
||||
processPastedText(text, 'hex')
|
||||
} catch (err) {
|
||||
console.error('粘贴失败:', err)
|
||||
// Clipboard API 失败,使用备用方法
|
||||
currentPasteType.value = 'hex'
|
||||
pasteInputValue.value = ''
|
||||
@@ -726,7 +744,6 @@ async function copyHsl() {
|
||||
await navigator.clipboard.writeText(hslText)
|
||||
showToast('HSL已复制到剪贴板', 'info', 2000)
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
showToast('复制失败:' + err.message)
|
||||
}
|
||||
}
|
||||
@@ -739,7 +756,6 @@ async function pasteHsl() {
|
||||
const text = await navigator.clipboard.readText()
|
||||
processPastedText(text, 'hsl')
|
||||
} catch (err) {
|
||||
console.error('粘贴失败:', err)
|
||||
// Clipboard API 失败,使用备用方法
|
||||
currentPasteType.value = 'hsl'
|
||||
pasteInputValue.value = ''
|
||||
@@ -779,7 +795,10 @@ function handlePasteEvent(event) {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存到历史记录
|
||||
/**
|
||||
* 保存当前颜色到历史记录
|
||||
* 自动去重,最多保存50条记录
|
||||
*/
|
||||
function saveToHistory() {
|
||||
const colorData = {
|
||||
rgb: `rgb(${rgb.value.r}, ${rgb.value.g}, ${rgb.value.b})`,
|
||||
@@ -803,7 +822,7 @@ function saveToHistory() {
|
||||
history = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取历史记录失败', e)
|
||||
// 读取历史记录失败,忽略错误
|
||||
}
|
||||
|
||||
// 检查是否与最后一条历史记录相同
|
||||
@@ -828,11 +847,13 @@ function saveToHistory() {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
|
||||
loadHistoryList()
|
||||
} catch (e) {
|
||||
console.error('保存历史记录失败', e)
|
||||
// 保存历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
// 加载历史记录列表
|
||||
/**
|
||||
* 从localStorage加载历史记录列表
|
||||
*/
|
||||
function loadHistoryList() {
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
@@ -840,12 +861,15 @@ function loadHistoryList() {
|
||||
historyList.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载历史记录失败', e)
|
||||
// 加载历史记录失败,重置为空数组
|
||||
historyList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载历史记录
|
||||
/**
|
||||
* 加载历史记录到编辑器
|
||||
* @param {Object} colorData - 颜色数据对象
|
||||
*/
|
||||
function loadHistory(colorData) {
|
||||
updating.value = true
|
||||
rgb.value = { ...colorData.rgbValues }
|
||||
@@ -860,7 +884,11 @@ function toggleSidebar() {
|
||||
sidebarOpen.value = !sidebarOpen.value
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
/**
|
||||
* 格式化时间戳为相对时间或日期字符串
|
||||
* @param {number} timestamp - 时间戳(毫秒)
|
||||
* @returns {string} 格式化后的时间字符串
|
||||
*/
|
||||
function formatTime(timestamp) {
|
||||
const date = new Date(timestamp)
|
||||
const now = new Date()
|
||||
|
||||
@@ -274,7 +274,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {ref, computed, watch, onMounted, onUnmounted} from 'vue'
|
||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
const MAX_INPUT_BYTES = 500 * 1024 // 最大 500KB
|
||||
|
||||
@@ -1271,7 +1271,6 @@ const compareListsIgnoreOrder = (listA, listB, ignoreOrder = false) => {
|
||||
|
||||
// 对比List(数组)- 寻找最佳匹配使相似度最高
|
||||
const compareLists = (listA, listB, ignoreOrder = false) => {
|
||||
|
||||
const n = listA.length
|
||||
const m = listB.length
|
||||
|
||||
@@ -1693,11 +1692,9 @@ const compareJson = (textA, textB) => {
|
||||
|
||||
// 执行节点对比,传递忽略列表顺序的参数
|
||||
const comparison = compareJsonNodes(jsonA, jsonB, ignoreListOrder.value)
|
||||
console.log(comparison)
|
||||
|
||||
// 转换为展示格式
|
||||
const displayResult = convertComparisonToDisplay(comparison, 0)
|
||||
console.log(displayResult)
|
||||
|
||||
// 计算统计信息
|
||||
const stats = calculateStats(comparison)
|
||||
@@ -1778,77 +1775,6 @@ const copyResult = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const compareTest = () => {
|
||||
let total = {
|
||||
left: [],
|
||||
right: [],
|
||||
stats: {same: 0, insert: 0, delete: 0, modify: 0}
|
||||
}
|
||||
const cases = [
|
||||
["[]","[\"a\"]"],
|
||||
["[\"a\"]", "[]"],
|
||||
["[[\"a\",\"b\"]]", "[]"],
|
||||
["[]","[\"a\",\"b\"]"],
|
||||
["[]","[[\"a\",\"b\"]]"],
|
||||
["{}","{\"a\": {\"c\":\"d\"}}"],
|
||||
["{}", "{\"a\":\"b\"}"],
|
||||
["[\"a\",\"b\"]", "[]"],
|
||||
["{\"a\": {\"c\":\"d\"}}", "[]"],
|
||||
["{\"a\":\"b\"}", "{}"],
|
||||
["{\"a\":\"a\",\"b\":\"b\",\"d\":null}", "{\"a\":\"a\",\"c\":\"c\"}"],
|
||||
["[\"a\",\"b\",null]", "[\"a\",\"c\"]"],
|
||||
["[{\"a\":\"a\"},{\"b\":\"b\"},null]", "[{\"a\":\"a\"},{\"c\":\"c\"}]"],
|
||||
["{\"a\":\"a\",\"b\":\"b\",\"c\":null}", "{\"a\":\"a\",\"c\":\"c\"}"],
|
||||
["[{\"c\":\"d\"}]","[[\"c\",\"d\"]]"],
|
||||
["{\"a\": {\"c\":\"d\"}}","{\"a\": [\"c\",\"d\"]}"],
|
||||
["{\"a\": {\"c\":\"d\"}}","[\"c\",\"d\"]"],
|
||||
["{\"a\": {\"c\":\"d\"}}","{\"a\": null}"],
|
||||
["{\"a\": null}","{\"a\": {\"c\":\"d\"}}"],
|
||||
["{\"a\": {\"c\":\"d\"}}","{}"],
|
||||
["{\"a\":\"a1\"}", "{\"b\":\"b2\"}"],
|
||||
["{\"a\":{\"c\":\"d\",\"e\":\"f\"}}", "{\"b\":{\"c\":\"d\",\"m\":\"l\"}}"],
|
||||
["{\"a\":{\"c\":\"d\",\"e\":\"f\"}}", "{\"a\":{\"c\":\"d\",\"e\":\"l\"}}"],
|
||||
["{\"a\": {\"c\":\"d\"}}", "{\"a\":[\"c\",\"d\"]}"],
|
||||
["[{\"a\":\"a1\"},{\"b\":\"b2\"}]", "[{\"c\":\"b1\"},{\"a\":\"a1\"}]"],
|
||||
["[{\"a\":\"a1\"},{\"b\":\"b2\"}]", "[{\"b\":\"b1\"},{\"a\":\"a1\"}]"],
|
||||
["[{\"a\":\"a1\"},{\"b\":\"b2\"}]", "[{\"c\":\"b1\"},{\"a\":\"a1\"}]"],
|
||||
["{\"a\":{\"c\":\"d\",\"e\":\"f\"},\"c\":\"a\",\"d\":\"e\",\"g\":[\"a\",\"b\",\"c\"],\"h\":[\"a\"],\"i\":[{\"a\":\"a1\"},{\"b\":\"b2\"},{\"c\":\"b1\"}]}", "{\"b\":{\"c\":\"d\",\"m\":\"l\"},\"c\":\"a\",\"d\":\"f\",\"g\":[\"a\",\"c\",\"b\"],\"h\":[\"b\",\"a\"],\"i\":[{\"b\":\"b1\"},{\"a\":\"a1\"},{\"d\":\"b1\"}]}"],
|
||||
["[[[\"a\",\"b\"],[]]]","[[[\"a\",\"b\",\"c\"],[\"b\"]],[\"c\"]]"]
|
||||
]
|
||||
for (let item of cases) {
|
||||
console.log("=================================================")
|
||||
console.log(item)
|
||||
console.log("=================================================")
|
||||
let res = compareJson(item[0], item[1])
|
||||
total.left.push({type: 'same', content: ''}, {
|
||||
type: 'same',
|
||||
content: '====================================='
|
||||
}, {type: 'same', content: ''}, {type: 'same', content: item[0]}, {type: 'same', content: ''}, {
|
||||
type: 'same',
|
||||
content: '-----------------------------------'
|
||||
})
|
||||
total.right.push({type: 'same', content: ''}, {
|
||||
type: 'same',
|
||||
content: '====================================='
|
||||
}, {type: 'same', content: ''}, {type: 'same', content: item[1]}, {type: 'same', content: ''}, {
|
||||
type: 'same',
|
||||
content: '-----------------------------------'
|
||||
})
|
||||
total.left.push({type: 'same', content: JSON.stringify(res.stats)}, {
|
||||
type: 'same',
|
||||
content: '-----------------------------------'
|
||||
})
|
||||
total.right.push({type: 'same', content: JSON.stringify(res.stats)}, {
|
||||
type: 'same',
|
||||
content: '-----------------------------------'
|
||||
})
|
||||
total.left.push(...res.left)
|
||||
total.right.push(...res.right)
|
||||
}
|
||||
compareResult.value = total
|
||||
}
|
||||
|
||||
// 切换侧栏
|
||||
const toggleSidebar = () => {
|
||||
sidebarOpen.value = !sidebarOpen.value
|
||||
@@ -1912,7 +1838,7 @@ const saveToHistory = () => {
|
||||
history = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取历史记录失败', e)
|
||||
// 读取历史记录失败,忽略错误
|
||||
}
|
||||
|
||||
// 检查是否与最新记录相同,如果相同则不保存
|
||||
@@ -1940,7 +1866,7 @@ const saveToHistory = () => {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
|
||||
loadHistoryList()
|
||||
} catch (e) {
|
||||
console.error('保存历史记录失败', e)
|
||||
// 保存历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1952,7 +1878,7 @@ const loadHistoryList = () => {
|
||||
historyList.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载历史记录失败', e)
|
||||
// 加载历史记录失败,忽略错误
|
||||
historyList.value = []
|
||||
}
|
||||
}
|
||||
@@ -1973,7 +1899,6 @@ onMounted(() => {
|
||||
updateLeftLineCount()
|
||||
updateRightLineCount()
|
||||
loadHistoryList()
|
||||
// compareTest()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -484,7 +484,7 @@ const saveToHistory = (item) => {
|
||||
history = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取历史记录失败', e)
|
||||
// 读取历史记录失败,忽略错误
|
||||
}
|
||||
|
||||
// 避免重复保存相同的记录
|
||||
@@ -510,7 +510,7 @@ const saveToHistory = (item) => {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
|
||||
loadHistoryList()
|
||||
} catch (e) {
|
||||
console.error('保存历史记录失败', e)
|
||||
// 保存历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +522,7 @@ const loadHistoryList = () => {
|
||||
historyList.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载历史记录失败', e)
|
||||
// 加载历史记录失败,重置为空数组
|
||||
historyList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div class="home-container">
|
||||
<div class="hero-section">
|
||||
<h2 class="hero-title">今天是{{`${new Date().getFullYear()}年${new Date().getMonth()+1}月${new Date().getDate()}日`}}</h2>
|
||||
<h2 class="hero-title">
|
||||
今天是{{ `${new Date().getFullYear()}年${new Date().getMonth() + 1}月${new Date().getDate()}日` }}
|
||||
</h2>
|
||||
<p class="hero-subtitle">凭君莫话封侯事,一将功成万骨枯。</p>
|
||||
</div>
|
||||
<div class="tools-grid">
|
||||
@@ -167,9 +169,6 @@ const tools = ref([
|
||||
.tool-card {
|
||||
flex: 0 0 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ const handleJsonPathInput = () => {
|
||||
}
|
||||
} catch (e) {
|
||||
matchedPaths.value.clear()
|
||||
console.error('JSONPath 解析错误:', e)
|
||||
// JSONPath 解析错误,忽略
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ const loadJsonPathHistory = () => {
|
||||
jsonPathHistory.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载 JSONPath 历史记录失败', e)
|
||||
// 加载 JSONPath 历史记录失败,重置为空数组
|
||||
jsonPathHistory.value = []
|
||||
}
|
||||
}
|
||||
@@ -660,7 +660,7 @@ const saveJsonPathHistory = (jsonPath) => {
|
||||
try {
|
||||
localStorage.setItem(JSONPATH_HISTORY_KEY, JSON.stringify(jsonPathHistory.value))
|
||||
} catch (e) {
|
||||
console.error('保存 JSONPath 历史记录失败', e)
|
||||
// 保存 JSONPath 历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,7 +1163,7 @@ const saveToHistory = (json) => {
|
||||
history = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取历史记录失败', e)
|
||||
// 读取历史记录失败,忽略错误
|
||||
}
|
||||
|
||||
// 添加到开头
|
||||
@@ -1179,7 +1179,7 @@ const saveToHistory = (json) => {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
|
||||
loadHistoryList()
|
||||
} catch (e) {
|
||||
console.error('保存历史记录失败', e)
|
||||
// 保存历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1191,7 +1191,7 @@ const loadHistoryList = () => {
|
||||
historyList.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载历史记录失败', e)
|
||||
// 加载历史记录失败,重置为空数组
|
||||
historyList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ const saveToHistory = (text) => {
|
||||
history = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取历史记录失败', e)
|
||||
// 读取历史记录失败,忽略错误
|
||||
}
|
||||
|
||||
// 避免重复保存相同的记录
|
||||
@@ -243,7 +243,7 @@ const saveToHistory = (text) => {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
|
||||
loadHistoryList()
|
||||
} catch (e) {
|
||||
console.error('保存历史记录失败', e)
|
||||
// 保存历史记录失败,忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ const loadHistoryList = () => {
|
||||
historyList.value = JSON.parse(stored)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载历史记录失败', e)
|
||||
// 加载历史记录失败,重置为空数组
|
||||
historyList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user