PlanApprovalCard.vue 6.8 KB

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