|
@@ -1608,7 +1608,7 @@ func HandleReportContentTable(reportId int, body string) (newBody string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- replaceIframeSrcTable(doc, reportId)
|
|
|
+ replaceIframeSrcTable(doc, reportId, 0)
|
|
|
|
|
|
// 输出修改后的HTML
|
|
|
var modifiedHtml strings.Builder
|
|
@@ -1624,12 +1624,48 @@ func HandleReportContentTable(reportId int, body string) (newBody string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// HandleReportContentTableAndScene
|
|
|
+// @Description: 处理报告内容(动态表格添加报告来源id)(跟另一个需求代码冲突了,不好处理,只能额外写个方法出来使用了)
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-01-10 10:15:39
|
|
|
+// @param reportId int
|
|
|
+// @param fromScene int
|
|
|
+// @param body string
|
|
|
+// @return newBody string
|
|
|
+func HandleReportContentTableAndScene(reportId, fromScene int, body string) (newBody string) {
|
|
|
+ if body == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = body
|
|
|
+
|
|
|
+ // 解析HTML
|
|
|
+ doc, err := html2.Parse(strings.NewReader(body))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error parsing HTML:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ replaceIframeSrcTable(doc, reportId, fromScene)
|
|
|
+
|
|
|
+ // 输出修改后的HTML
|
|
|
+ var modifiedHtml strings.Builder
|
|
|
+ err = html2.Render(&modifiedHtml, doc)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error rendering HTML:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ newBody = modifiedHtml.String()
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// replaceIframeSrc 遍历HTML节点,替换iframe的src属性
|
|
|
-func replaceIframeSrcTable(n *html2.Node, reportId int) {
|
|
|
+func replaceIframeSrcTable(n *html2.Node, reportId, fromScene int) {
|
|
|
if n.Type == html2.ElementNode && n.Data == "iframe" {
|
|
|
for i, attr := range n.Attr {
|
|
|
if attr.Key == "src" {
|
|
|
- newLink := handleTableLinkReportId(attr.Val, reportId)
|
|
|
+ newLink := handleTableLinkReportId(attr.Val, reportId, fromScene)
|
|
|
// 替换原来的链接
|
|
|
n.Attr[i].Val = newLink
|
|
|
break
|
|
@@ -1638,12 +1674,12 @@ func replaceIframeSrcTable(n *html2.Node, reportId int) {
|
|
|
}
|
|
|
// 递归处理子节点
|
|
|
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
|
|
- replaceIframeSrcTable(c, reportId)
|
|
|
+ replaceIframeSrcTable(c, reportId, fromScene)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// handleTableLinkReportId 链接添加token
|
|
|
-func handleTableLinkReportId(link string, reportId int) string {
|
|
|
+func handleTableLinkReportId(link string, reportId, fromScene int) string {
|
|
|
var err error
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -1663,6 +1699,11 @@ func handleTableLinkReportId(link string, reportId int) string {
|
|
|
|
|
|
queryParams.Add("sourceId", fmt.Sprint(reportId))
|
|
|
|
|
|
+ if fromScene > 0 {
|
|
|
+ queryParams.Del("fromScene")
|
|
|
+ queryParams.Add("fromScene", fmt.Sprint(fromScene))
|
|
|
+ }
|
|
|
+
|
|
|
// 更新URL的查询参数
|
|
|
parsedURL.RawQuery = queryParams.Encode()
|
|
|
|
|
@@ -1692,7 +1733,46 @@ func HandleReportContentStructTable(reportId int, body string) (newBody string)
|
|
|
|
|
|
// 处理每个组件
|
|
|
for i := range jsonData {
|
|
|
- if err := processMapTable(jsonData[i], reportId); err != nil {
|
|
|
+ if err := processMapTable(jsonData[i], reportId, 0); err != nil {
|
|
|
+ fmt.Println("Error processing component:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将处理后的数据转换回JSON字符串
|
|
|
+ modifiedJSON, err := json.MarshalIndent(jsonData, "", " ")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error marshaling JSON:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = string(modifiedJSON)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HandleReportContentStructTableAndScene
|
|
|
+// @Description: 处理内容组件的表格链接,需要处理来源(跟另一个需求代码冲突了,不好处理,只能额外写个方法出来使用了)
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-01-09 13:40:35
|
|
|
+// @param reportId int
|
|
|
+// @param body string
|
|
|
+// @return newBody string
|
|
|
+func HandleReportContentStructTableAndScene(reportId, fromScene int, body string) (newBody string) {
|
|
|
+ if body == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = body
|
|
|
+
|
|
|
+ // 解析JSON数据到map[string]interface{}
|
|
|
+ var jsonData []map[string]interface{}
|
|
|
+ if err := json.Unmarshal([]byte(body), &jsonData); err != nil {
|
|
|
+ fmt.Println("Error parsing JSON:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理每个组件
|
|
|
+ for i := range jsonData {
|
|
|
+ if err := processMapTable(jsonData[i], reportId, 0); err != nil {
|
|
|
fmt.Println("Error processing component:", err)
|
|
|
return
|
|
|
}
|
|
@@ -1710,22 +1790,22 @@ func HandleReportContentStructTable(reportId int, body string) (newBody string)
|
|
|
}
|
|
|
|
|
|
// processMapTable 递归处理map中的content字段
|
|
|
-func processMapTable(data map[string]interface{}, reportId int) error {
|
|
|
+func processMapTable(data map[string]interface{}, reportId, fromScene int) error {
|
|
|
for key, value := range data {
|
|
|
switch v := value.(type) {
|
|
|
case string:
|
|
|
if key == "content" {
|
|
|
- newContent := handleTableLinkReportId(v, reportId)
|
|
|
+ newContent := handleTableLinkReportId(v, reportId, fromScene)
|
|
|
data[key] = newContent
|
|
|
}
|
|
|
case map[string]interface{}:
|
|
|
- if err := processMapTable(v, reportId); err != nil {
|
|
|
+ if err := processMapTable(v, reportId, fromScene); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
case []interface{}:
|
|
|
for i := range v {
|
|
|
if m, ok := v[i].(map[string]interface{}); ok {
|
|
|
- if err := processMapTable(m, reportId); err != nil {
|
|
|
+ if err := processMapTable(m, reportId, fromScene); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|