PlanApprovalCard.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="plan-card" :class="`plan-card--${part.confirmState}`">
  3. <div class="plan-card__head">
  4. <span class="plan-card__icon"><Icon icon="i-mdi:clipboard-list-outline" /></span>
  5. <div class="plan-card__titles">
  6. <span class="plan-card__title">研判方案待批准</span>
  7. <span class="plan-card__sub">计划模式 · 批准后退出计划模式并开始执行</span>
  8. </div>
  9. <a-tag class="plan-card__tag" :color="stateColor">{{ stateLabel }}</a-tag>
  10. </div>
  11. <div class="plan-card__body">
  12. <div class="plan-card__summary">{{ displayText || '(计划正文为空,请查看完整计划文档)' }}</div>
  13. <div class="plan-card__meta">
  14. <button class="plan-card__doc" type="button" @click="$emit('open-doc')">
  15. <Icon icon="i-mdi:file-document-outline" />
  16. 查看完整计划文档
  17. </button>
  18. <span v-if="part.planPath" class="plan-card__path" :title="part.planPath">{{ part.planPath }}</span>
  19. <span
  20. v-if="part.confirmState === 'pending' && part.planRejectCount > 0"
  21. class="plan-card__reject"
  22. >已被驳回 {{ part.planRejectCount }} 次(累计 3 次将终止本轮)</span>
  23. <button class="plan-card__raw-toggle" type="button" @click="showRaw = !showRaw">
  24. {{ showRaw ? '收起原始参数' : '原始参数' }}
  25. </button>
  26. </div>
  27. <pre v-show="showRaw" class="plan-card__raw">{{ rawInput }}</pre>
  28. </div>
  29. <div v-if="part.confirmState === 'pending'" class="plan-card__actions">
  30. <a-button type="primary" @click="$emit('approve')">
  31. <template #icon><Icon icon="i-mdi:check-circle-outline" /></template>
  32. 批准并执行
  33. </a-button>
  34. <a-button danger @click="$emit('reject')">
  35. <template #icon><Icon icon="i-mdi:close-circle-outline" /></template>
  36. 拒绝
  37. </a-button>
  38. </div>
  39. <div v-else-if="part.confirmState === 'rejected'" class="plan-card__tip">
  40. 已拒绝{{ part.confirmReason ? `:${part.confirmReason}` : '' }}。计划未执行。
  41. </div>
  42. <div v-else-if="part.confirmState === 'expired'" class="plan-card__tip">
  43. 计划批准已失效(过期或被新请求替代),请重新提问。
  44. </div>
  45. <div v-else class="plan-card__tip plan-card__tip--ok">已批准,计划进入执行阶段。</div>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. /**
  50. * 计划模式专用批准卡:把计划正文以可读 prose 呈现(替代通用确认卡的 raw JSON),
  51. * 提供「查看完整计划文档」入口与批准/拒绝动作;原始参数折叠留证。
  52. *
  53. * <p>正文优先取后端随待确认记录下发的 planContent(最近一次 plan_write 全文,对齐上游 1.1.2);
  54. * 未下发时回退 plan_exit 入参中的 summary / plan。</p>
  55. */
  56. import { computed, ref } from 'vue';
  57. import { Button as AButton, Tag as ATag } from 'ant-design-vue';
  58. import { Icon } from '@/core/components/Icon';
  59. const props = defineProps<{ part: any }>();
  60. defineEmits<{ (e: 'approve'): void; (e: 'reject'): void; (e: 'open-doc'): void }>();
  61. const showRaw = ref(false);
  62. const planCall = computed(() =>
  63. (props.part?.toolCalls ?? []).find(
  64. (c: any) => c.toolName === 'plan_exit' || /批准计划/.test(c.toolLabel || ''),
  65. ),
  66. );
  67. const summary = computed(() => {
  68. const input = planCall.value?.input;
  69. if (!input) return '';
  70. if (typeof input === 'string') {
  71. try {
  72. const p = JSON.parse(input);
  73. return p?.summary || p?.plan || input;
  74. } catch {
  75. return input;
  76. }
  77. }
  78. return input.summary || input.plan || '';
  79. });
  80. /** 展示正文:后端下发的 plan_write 全文优先(完整方案),否则回退 plan_exit 摘要 */
  81. const displayText = computed(() => props.part?.planContent || summary.value || '');
  82. const rawInput = computed(() => {
  83. const input = planCall.value?.input;
  84. if (input == null) return '';
  85. return typeof input === 'string' ? input : JSON.stringify(input, null, 2);
  86. });
  87. const stateLabel = computed(() => {
  88. const m: Record<string, string> = { pending: '待批准', approved: '已批准', rejected: '已拒绝', expired: '已失效' };
  89. return m[props.part?.confirmState] || props.part?.confirmState;
  90. });
  91. const stateColor = computed(() => {
  92. const m: Record<string, string> = { pending: 'warning', approved: 'success', rejected: 'error', expired: 'default' };
  93. return m[props.part?.confirmState] || 'default';
  94. });
  95. </script>
  96. <style scoped lang="less">
  97. .plan-card {
  98. margin: 10px 0;
  99. overflow: hidden;
  100. border: 1px solid var(--wb-border, #e5e9f2);
  101. border-radius: 12px;
  102. background: #fff;
  103. box-shadow: 0 2px 10px rgba(42, 80, 236, 0.06);
  104. &__head {
  105. display: flex;
  106. align-items: center;
  107. gap: 10px;
  108. padding: 12px 14px;
  109. background: linear-gradient(120deg, var(--wb-primary-soft, #e8eefc), #f5f3ff 70%);
  110. border-bottom: 1px solid var(--wb-border, #e5e9f2);
  111. }
  112. &__icon {
  113. display: grid;
  114. place-items: center;
  115. width: 34px;
  116. height: 34px;
  117. flex: none;
  118. border-radius: 10px;
  119. color: #fff;
  120. background: linear-gradient(135deg, var(--wb-primary, #2a50ec), #7c3aed);
  121. box-shadow: 0 3px 10px rgba(42, 80, 236, 0.3);
  122. font-size: 18px;
  123. }
  124. &__titles {
  125. display: flex;
  126. flex-direction: column;
  127. min-width: 0;
  128. }
  129. &__title {
  130. font-size: 14.5px;
  131. font-weight: 700;
  132. color: var(--wb-text, #1f2937);
  133. }
  134. &__sub {
  135. font-size: 11.5px;
  136. color: var(--wb-text-2, #64748b);
  137. }
  138. &__tag {
  139. margin-left: auto;
  140. margin-inline-end: 0;
  141. }
  142. &__body {
  143. padding: 14px;
  144. }
  145. &__summary {
  146. max-height: 260px;
  147. overflow: auto;
  148. padding: 12px 14px;
  149. font-size: 13.5px;
  150. line-height: 1.8;
  151. color: var(--wb-text, #1f2937);
  152. background: #f8fafc;
  153. border: 1px solid var(--wb-border, #e5e9f2);
  154. border-left: 3px solid var(--wb-primary, #2a50ec);
  155. border-radius: 0 8px 8px 0;
  156. white-space: pre-wrap;
  157. word-break: break-word;
  158. }
  159. &__meta {
  160. display: flex;
  161. align-items: center;
  162. gap: 10px;
  163. margin-top: 10px;
  164. }
  165. &__doc {
  166. display: inline-flex;
  167. align-items: center;
  168. gap: 6px;
  169. padding: 5px 12px;
  170. font-size: 12.5px;
  171. font-weight: 600;
  172. color: var(--wb-primary, #2a50ec);
  173. background: var(--wb-primary-soft, #e8eefc);
  174. border: 1px solid rgba(42, 80, 236, 0.25);
  175. border-radius: 8px;
  176. cursor: pointer;
  177. transition: 0.15s;
  178. &:hover {
  179. background: #dbe6ff;
  180. border-color: var(--wb-primary, #2a50ec);
  181. }
  182. }
  183. &__path {
  184. overflow: hidden;
  185. max-width: 200px;
  186. font-size: 11.5px;
  187. color: var(--wb-text-muted, #94a3b8);
  188. text-overflow: ellipsis;
  189. white-space: nowrap;
  190. }
  191. &__reject {
  192. font-size: 11.5px;
  193. color: var(--wb-danger, #dc2626);
  194. }
  195. &__raw-toggle {
  196. margin-left: auto;
  197. padding: 4px 10px;
  198. font-size: 12px;
  199. color: var(--wb-text-muted, #94a3b8);
  200. background: transparent;
  201. border: 1px solid var(--wb-border, #e5e9f2);
  202. border-radius: 6px;
  203. cursor: pointer;
  204. &:hover {
  205. color: var(--wb-text-2, #64748b);
  206. }
  207. }
  208. &__raw {
  209. margin: 10px 0 0;
  210. max-height: 200px;
  211. overflow: auto;
  212. padding: 10px 12px;
  213. font-size: 12px;
  214. background: #f8fafc;
  215. border: 1px solid var(--wb-border, #e5e9f2);
  216. border-radius: 8px;
  217. white-space: pre-wrap;
  218. word-break: break-all;
  219. }
  220. &__actions {
  221. display: flex;
  222. gap: 10px;
  223. padding: 0 14px 14px;
  224. }
  225. &__tip {
  226. padding: 0 14px 14px;
  227. font-size: 12.5px;
  228. color: var(--wb-text-2, #64748b);
  229. &--ok {
  230. color: var(--wb-success, #16a34a);
  231. }
  232. }
  233. }
  234. </style>