JSON格式化 添加 移除斜杠 功能
This commit is contained in:
@@ -5,7 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faCode, faCopy, faCheck, faCompress, faExpand,
|
||||
faSearch, faTrash, faSync, faFolderOpen, faFolder, faSpinner,
|
||||
faSave, faHistory, faTimes, faEdit, faStar, faTrashAlt
|
||||
faSave, faHistory, faTimes, faEdit, faStar, faTrashAlt, faEraser
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import dynamic from 'next/dynamic';
|
||||
import BackToTop from '@/components/BackToTop';
|
||||
@@ -184,6 +184,33 @@ export default function JsonFormatter() {
|
||||
setIsFoldable(!isFoldable);
|
||||
};
|
||||
|
||||
// 移除JSON中的转义斜杠
|
||||
const removeSlashes = () => {
|
||||
if (!jsonInput) return;
|
||||
|
||||
try {
|
||||
// 直接在原始输入字符串上移除转义斜杠
|
||||
const processed = jsonInput.replace(/\\\//g, '/');
|
||||
|
||||
// 检查是否有变化
|
||||
if (processed === jsonInput) {
|
||||
console.log('没有检测到需要替换的内容,JSON未改变');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('移除斜杠前:', jsonInput);
|
||||
console.log('移除斜杠后:', processed);
|
||||
|
||||
// 更新输入框而不是直接格式化
|
||||
setJsonInput(processed);
|
||||
|
||||
// 手动触发格式化
|
||||
setTimeout(() => formatJson(processed, isCompressed), 100);
|
||||
} catch (error) {
|
||||
console.error('移除斜杠处理失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 复制结果到剪贴板
|
||||
const copyToClipboard = () => {
|
||||
if (jsonOutput) {
|
||||
@@ -757,6 +784,16 @@ export default function JsonFormatter() {
|
||||
<span>{t('tools.json_formatter.history')}</span>
|
||||
</button>
|
||||
|
||||
{/* 移除斜杠按钮 */}
|
||||
<button
|
||||
className={`${toolbarButtonClass} bg-[rgb(var(--color-bg-secondary))] text-[rgb(var(--color-text-secondary))] hover:text-[rgb(var(--color-text-primary))]`}
|
||||
onClick={removeSlashes}
|
||||
disabled={!jsonInput || isLoading}
|
||||
>
|
||||
<FontAwesomeIcon icon={faEraser} />
|
||||
<span>{t('tools.json_formatter.remove_slash')}</span>
|
||||
</button>
|
||||
|
||||
{isLoading && (
|
||||
<button
|
||||
className="px-3 py-1.5 rounded text-sm flex items-center gap-1 transition-all border"
|
||||
|
||||
@@ -57,7 +57,8 @@ export const jsonFormatterEn = {
|
||||
guide_4: 'JSONPath queries support dot notation (e.g., author.name) and array indices (e.g., features[0])',
|
||||
guide_5: 'Compress/Beautify mode can be freely switched',
|
||||
guide_6: 'Processing large JSON data may take a few seconds',
|
||||
guide_7: 'Multiple JSON data can be saved to history for comparison'
|
||||
guide_7: 'Multiple JSON data can be saved to history for comparison',
|
||||
remove_slash: 'Remove Slashes'
|
||||
};
|
||||
|
||||
export default jsonFormatterEn;
|
||||
@@ -57,7 +57,8 @@ export const jsonFormatterZh = {
|
||||
guide_4: 'JSONPath查询支持点符号(如author.name)和数组索引(如features[0])',
|
||||
guide_5: '展示压缩/美化模式可以自由切换',
|
||||
guide_6: '处理大型JSON数据可能需要几秒钟时间',
|
||||
guide_7: '可以保存多个JSON数据到历史记录中,方便比较查看'
|
||||
guide_7: '可以保存多个JSON数据到历史记录中,方便比较查看',
|
||||
remove_slash: '移除斜杠'
|
||||
};
|
||||
|
||||
export default jsonFormatterZh;
|
||||
Reference in New Issue
Block a user