add json编辑功能
This commit is contained in:
@ -2550,13 +2550,15 @@ export default {
|
|||||||
this.dialogJsonVisible = true
|
this.dialogJsonVisible = true
|
||||||
},
|
},
|
||||||
decodeEscapedJson(str) {
|
decodeEscapedJson(str) {
|
||||||
// 去掉最外层的转义引号
|
// 去掉字符串首尾的空白字符
|
||||||
str = str.slice(1, -1);
|
str = str.trim();
|
||||||
// 循环解码,直到字符串不再包含转义字符
|
// 直接解析 JSON 字符串
|
||||||
while (str.includes('\\')) {
|
try {
|
||||||
str = JSON.parse('"' + str + '"');
|
return JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error parsing JSON:', e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return str
|
|
||||||
},
|
},
|
||||||
handleJson() {
|
handleJson() {
|
||||||
this.jsonLoading = true
|
this.jsonLoading = true
|
||||||
@ -2573,7 +2575,7 @@ export default {
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
this.jsonInfo = {
|
this.jsonInfo = {
|
||||||
path: response.data.path,
|
path: response.data.path,
|
||||||
json: this.decodeEscapedJson(response.data.json)
|
json: JSON.stringify(response.data.json, null, 2)
|
||||||
}
|
}
|
||||||
this.jsonLoading = false
|
this.jsonLoading = false
|
||||||
})
|
})
|
||||||
@ -2592,7 +2594,7 @@ export default {
|
|||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(text => {
|
.then(text => {
|
||||||
const parsedData = iniParser.parse(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: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user