add json编辑功能

This commit is contained in:
gcw_IJ7DAiVL
2025-10-15 09:27:20 +08:00
parent 7d22506f18
commit ce70fd98ec

View File

@ -2550,13 +2550,15 @@ export default {
this.dialogJsonVisible = true
},
decodeEscapedJson(str) {
// 去掉最外层的转义引号
str = str.slice(1, -1);
// 循环解码,直到字符串不再包含转义字符
while (str.includes('\\')) {
str = JSON.parse('"' + str + '"');
// 去掉字符串首尾的空白字符
str = str.trim();
// 直接解析 JSON 字符串
try {
return JSON.parse(str);
} catch (e) {
console.error('Error parsing JSON:', e);
return null;
}
return str
},
handleJson() {
this.jsonLoading = true
@ -2573,7 +2575,7 @@ export default {
.then(response => {
this.jsonInfo = {
path: response.data.path,
json: this.decodeEscapedJson(response.data.json)
json: JSON.stringify(response.data.json, null, 2)
}
this.jsonLoading = false
})
@ -2592,7 +2594,7 @@ export default {
.then(response => response.text())
.then(text => {
const parsedData = iniParser.parse(text);
axios.post(`http://${parsedData.http.address}:${parsedData.http.port}/api/json/save?path=${this.jsonInfo.path}`, JSON.stringify(this.jsonInfo.json), {
axios.post(`http://${parsedData.http.address}:${parsedData.http.port}/api/json/save?path=${this.jsonInfo.path}`, JSON.stringify(JSON.parse(this.jsonInfo.json)), {
headers: {
'Content-Type': 'application/json'
}