tab1.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/usr/bin/env python3
  2. """
  3. Tab1内容生成器 - 选题点(灵感点、目的点、关键点)
  4. """
  5. import html as html_module
  6. from typing import Dict, Any
  7. def generate_tab1_content(data: Dict[str, Any]) -> str:
  8. """生成Tab1内容:选题、灵感点、目的点、关键点"""
  9. html = '<div class="tab-content" id="tab1">\n'
  10. # 选题描述
  11. if '选题描述' in data:
  12. topic = data['选题描述']
  13. html += '<div class="section">\n'
  14. html += '<h3>选题描述</h3>\n'
  15. if '主题' in topic:
  16. html += f'<div class="topic-theme"><strong>主题:</strong>{html_module.escape(topic["主题"])}</div>\n'
  17. if '描述' in topic:
  18. html += f'<div class="topic-desc"><strong>描述:</strong>{html_module.escape(topic["描述"])}</div>\n'
  19. html += '</div>\n'
  20. # 灵感点
  21. if '灵感点' in data:
  22. inspiration = data['灵感点']
  23. html += '<div class="section">\n'
  24. html += '<h3>灵感点</h3>\n'
  25. if isinstance(inspiration, list):
  26. for idx, item in enumerate(inspiration, 1):
  27. point_text = item.get('灵感点', '')
  28. description = item.get('描述', '')
  29. features = item.get('提取的特征', [])
  30. scoring = item.get('scoring', {})
  31. html += f'<div class="point-item inspiration-item">\n'
  32. html += f'<div class="point-header">\n'
  33. html += f'<span class="point-number">#{idx}</span>\n'
  34. html += f'<span class="point-text">{html_module.escape(point_text)}</span>\n'
  35. html += f'</div>\n'
  36. if description:
  37. html += f'<div class="point-description">{html_module.escape(description)}</div>\n'
  38. # 显示提取的特征
  39. if features:
  40. html += f'<div class="point-features">\n'
  41. html += f'<strong>提取的特征:</strong>\n'
  42. html += f'<div class="feature-tags">\n'
  43. for feature in features:
  44. feature_name = feature.get('特征名称', '')
  45. weight = feature.get('权重', 0)
  46. dimension = feature.get('维度分类', '')
  47. html += f'<span class="feature-tag">{html_module.escape(feature_name)} '
  48. if dimension:
  49. html += f'<em class="feature-dimension">({html_module.escape(dimension)})</em> '
  50. html += f'<strong class="feature-weight">权重:{weight}</strong></span>\n'
  51. html += f'</div>\n'
  52. html += f'</div>\n'
  53. # 显示评分信息
  54. if scoring:
  55. html += f'<div class="point-scoring">\n'
  56. html += f'<strong>评分:</strong>\n'
  57. html += f'<div class="scoring-badges">\n'
  58. if '人设契合度' in scoring:
  59. html += f'<span class="scoring-badge">人设契合度: {scoring["人设契合度"]}/10</span>\n'
  60. if '触发可能性' in scoring:
  61. html += f'<span class="scoring-badge">触发可能性: {scoring["触发可能性"]}/10</span>\n'
  62. if '内容解释力' in scoring:
  63. html += f'<span class="scoring-badge">内容解释力: {scoring["内容解释力"]}/10</span>\n'
  64. if '总分' in scoring:
  65. html += f'<span class="scoring-badge total-score">总分: {scoring["总分"]}</span>\n'
  66. html += f'</div>\n'
  67. html += f'</div>\n'
  68. html += f'</div>\n'
  69. html += '</div>\n'
  70. # 目的点
  71. if '目的点' in data:
  72. purpose = data['目的点']
  73. html += '<div class="section">\n'
  74. html += '<h3>目的点</h3>\n'
  75. if isinstance(purpose, list):
  76. for idx, item in enumerate(purpose, 1):
  77. point_text = item.get('目的点', '')
  78. description = item.get('描述', '')
  79. dimension = item.get('维度', {})
  80. features = item.get('提取的特征', [])
  81. html += f'<div class="point-item purpose-item">\n'
  82. html += f'<div class="point-header">\n'
  83. html += f'<span class="point-number">#{idx}</span>\n'
  84. html += f'<span class="point-text">{html_module.escape(point_text)}</span>\n'
  85. # 显示维度标签
  86. if dimension:
  87. html += f'<div class="dimension-tags">\n'
  88. if '一级分类' in dimension:
  89. html += f'<span class="dimension-tag level-1">{html_module.escape(dimension["一级分类"])}</span>\n'
  90. if '二级分类' in dimension:
  91. html += f'<span class="dimension-tag level-2">{html_module.escape(dimension["二级分类"])}</span>\n'
  92. html += f'</div>\n'
  93. html += f'</div>\n'
  94. if description:
  95. html += f'<div class="point-description">{html_module.escape(description)}</div>\n'
  96. # 显示提取的特征
  97. if features:
  98. html += f'<div class="point-features">\n'
  99. html += f'<strong>提取的特征:</strong>\n'
  100. html += f'<div class="feature-tags">\n'
  101. for feature in features:
  102. feature_name = feature.get('特征名称', '')
  103. weight = feature.get('权重', 0)
  104. feature_class = feature.get('特征分类', '')
  105. html += f'<span class="feature-tag">{html_module.escape(feature_name)} '
  106. if feature_class:
  107. html += f'<em class="feature-dimension">({html_module.escape(feature_class)})</em> '
  108. html += f'<strong class="feature-weight">权重:{weight}</strong></span>\n'
  109. html += f'</div>\n'
  110. html += f'</div>\n'
  111. html += f'</div>\n'
  112. html += '</div>\n'
  113. # 关键点
  114. if '关键点' in data:
  115. keypoint = data['关键点']
  116. html += '<div class="section">\n'
  117. html += '<h3>关键点</h3>\n'
  118. if isinstance(keypoint, list):
  119. for idx, item in enumerate(keypoint, 1):
  120. point_text = item.get('关键点', '')
  121. description = item.get('描述', '')
  122. dimension = item.get('维度', '')
  123. features = item.get('提取的特征', [])
  124. html += f'<div class="point-item keypoint-item">\n'
  125. html += f'<div class="point-header">\n'
  126. html += f'<span class="point-number">#{idx}</span>\n'
  127. html += f'<span class="point-text">{html_module.escape(point_text)}</span>\n'
  128. # 显示维度标签
  129. if dimension:
  130. html += f'<span class="dimension-tag keypoint-dimension">{html_module.escape(dimension)}</span>\n'
  131. html += f'</div>\n'
  132. if description:
  133. html += f'<div class="point-description">{html_module.escape(description)}</div>\n'
  134. # 显示提取的特征
  135. if features:
  136. html += f'<div class="point-features">\n'
  137. html += f'<strong>提取的特征:</strong>\n'
  138. html += f'<div class="feature-tags">\n'
  139. for feature in features:
  140. feature_name = feature.get('特征名称', '')
  141. weight = feature.get('权重', 0)
  142. feature_dimension = feature.get('维度', '')
  143. html += f'<span class="feature-tag">{html_module.escape(feature_name)} '
  144. if feature_dimension:
  145. html += f'<em class="feature-dimension">({html_module.escape(feature_dimension)})</em> '
  146. html += f'<strong class="feature-weight">权重:{weight}</strong></span>\n'
  147. html += f'</div>\n'
  148. html += f'</div>\n'
  149. html += f'</div>\n'
  150. html += '</div>\n'
  151. html += '</div>\n'
  152. return html