@@ -3,6 +3,8 @@ const {fillToLength} = require("../utils/string-util");
33const { genFormatArray} = require ( "../utils/log-util" ) ;
44const { getGlobalConfig} = require ( "../config/config" ) ;
55const { highlightJSON} = require ( "./json-formatter" ) ;
6+ const { getUserCodeLocation} = require ( "../utils/code-util" ) ;
7+ const { printStyledTable} = require ( "./table-formatter" ) ;
68
79/**
810 * 用于对响应进行格式化
@@ -15,63 +17,39 @@ class ResponseFormatter {
1517 */
1618 format ( scriptContext ) {
1719
20+ const codeLocation = getUserCodeLocation ( ) ;
21+
1822 const responseContext = scriptContext . responseContext ;
23+ const requestContext = scriptContext . requestContext ;
1924 // const language = getLanguage(getGlobalConfig().language);
2025 const language = chinese ;
2126
22- // 提示词:
23- // 我需要写一些console.log的样式打印在控制台上,接下来会陆陆续续给你一些写样式的任务,球球你帮帮我
24-
25- const valueStyle = `color: black; background: #E50000; font-size: 12px; font-weight: bold;` ;
26- const normalStyle = `color: black; background: #FF6766; font-size: 12px;` ;
27-
28- const titleStyle = 'font-weight: bold; font-size: 16px; background: green; color: white; padding: 5px; border-radius: 3px;' ;
29-
30- const length = 200 ;
31-
32- // const msgs = [];
33- // msgs.push()
34- // msgs.push("Time: " + new Date().toLocaleString() + "\n");
35- // msgs.push(`Request ID: ${scriptContext.requestId} \n`);
36- // msgs.push(`${scriptContext.responseContext.toHumanReadable(0)}`);
37- // return msgs.join("\n");
38-
39- const message = [
40- normalStyle , fillToLength ( `-------------------------------------------------- Script Hook Captured Response --------------------------------------------------` , length ) + "\n" ,
41- normalStyle , fillToLength ( `${ language . console . time } : ${ new Date ( ) . toLocaleString ( ) } ` , length ) + "\n" ,
42- normalStyle , fillToLength ( `${ language . console . requestId } : ${ scriptContext . requestId } ` , length ) + "\n" ,
43- // normalStyle, fillToLength(`${language.console.isJsonpRequest}: ${scriptContext.isJsonp()}`, length) + "\n",
44- // normalStyle, fillToLength(`${language.console.hostname}: ${requestContext.hostname}`, length) + "\n",
45- // normalStyle, fillToLength(`${language.console.path}: ${requestContext.path}`, length) + "\n",
46- // normalStyle, fillToLength((() => {
47- // const paramTitle = `${language.console.param}(${requestContext.params.length})`;
48- // return paramTitle;
49- // })(), length) + "\n",
50- // normalStyle, fillToLength(`${language.console.hash}: ${requestContext.hash}`, length) + "\n",
51-
52- // (() => {
53- //
54- // let paramTitle = `${indentSpace}`;
55- // if (!this.params.length) {
56- // paramTitle += " do not have param.";
57- // }
58- // msgs.push(paramTitle);
59- // for (let param of this.params) {
60- // msgs.push(param.toHumanReadable(indent + 4));
61- // }
62- //
63- //
64- // if (this.hash) {
65- // msgs.push()
66- // }
67- //
68- // return msgs.join("\n\n");
69- // })()
70-
27+ const data = [
28+ // TODO 2025-01-08 01:28:26 国际化
29+ [ "名称" , "值" , "备注" ] ,
30+ [ language . console . time , new Date ( ) . toLocaleString ( ) , "" ] ,
31+ [ language . console . requestId , scriptContext . requestId , "" ] ,
32+ [ language . console . isJsonpRequest , scriptContext . isJsonp ( ) , "" ] ,
33+ [ language . console . hostname , requestContext . hostname , "" ] ,
34+ [ language . console . path , requestContext . path , "" ] ,
35+ [ language . console . hash , requestContext . hash , "" ] ,
36+ [ language . console . codeLocation , codeLocation , "" ] ,
37+ // [language.console.param, requestContext.params.length],
7138 ] ;
72- console . log ( genFormatArray ( message ) , ...message ) ;
39+ // 示例样式
40+ const styles = {
41+ borderColor : '#000' ,
42+ cellBackgroundColor : '#f0f0f0' ,
43+ fontSize : '14px' ,
44+ fontColor : '#333'
45+ } ;
46+
47+ // 打印表格
48+ const title = language . console . titleResponse ;
49+ printStyledTable ( data , styles , title ) ;
50+ const msgs = highlightJSON ( responseContext . jsonpCallbackArguments ) ;
51+ console . log ( msgs ) ;
7352
74- highlightJSON ( responseContext . jsonpCallbackArguments ) ;
7553
7654 }
7755
0 commit comments