| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <template>
- <div class="plan-card" :class="`plan-card--${part.confirmState}`">
- <div class="plan-card__head">
- <span class="plan-card__icon"><Icon icon="i-mdi:clipboard-list-outline" /></span>
- <div class="plan-card__titles">
- <span class="plan-card__title">研判方案待批准</span>
- <span class="plan-card__sub">计划模式 · 批准后退出计划模式并开始执行</span>
- </div>
- <a-tag class="plan-card__tag" :color="stateColor">{{ stateLabel }}</a-tag>
- </div>
- <div class="plan-card__body">
- <div class="plan-card__summary">{{ displayText || '(计划正文为空,请查看完整计划文档)' }}</div>
- <div class="plan-card__meta">
- <button class="plan-card__doc" type="button" @click="$emit('open-doc')">
- <Icon icon="i-mdi:file-document-outline" />
- 查看完整计划文档
- </button>
- <span v-if="part.planPath" class="plan-card__path" :title="part.planPath">{{ part.planPath }}</span>
- <span
- v-if="part.confirmState === 'pending' && part.planRejectCount > 0"
- class="plan-card__reject"
- >已被驳回 {{ part.planRejectCount }} 次(累计 3 次将终止本轮)</span>
- <button class="plan-card__raw-toggle" type="button" @click="showRaw = !showRaw">
- {{ showRaw ? '收起原始参数' : '原始参数' }}
- </button>
- </div>
- <pre v-show="showRaw" class="plan-card__raw">{{ rawInput }}</pre>
- </div>
- <div v-if="part.confirmState === 'pending'" class="plan-card__actions">
- <a-button type="primary" @click="$emit('approve')">
- <template #icon><Icon icon="i-mdi:check-circle-outline" /></template>
- 批准并执行
- </a-button>
- <a-button danger @click="$emit('reject')">
- <template #icon><Icon icon="i-mdi:close-circle-outline" /></template>
- 拒绝
- </a-button>
- </div>
- <div v-else-if="part.confirmState === 'rejected'" class="plan-card__tip">
- 已拒绝{{ part.confirmReason ? `:${part.confirmReason}` : '' }}。计划未执行。
- </div>
- <div v-else-if="part.confirmState === 'expired'" class="plan-card__tip">
- 计划批准已失效(过期或被新请求替代),请重新提问。
- </div>
- <div v-else class="plan-card__tip plan-card__tip--ok">已批准,计划进入执行阶段。</div>
- </div>
- </template>
- <script setup lang="ts">
- /**
- * 计划模式专用批准卡:把计划正文以可读 prose 呈现(替代通用确认卡的 raw JSON),
- * 提供「查看完整计划文档」入口与批准/拒绝动作;原始参数折叠留证。
- *
- * <p>正文优先取后端随待确认记录下发的 planContent(最近一次 plan_write 全文,对齐上游 1.1.2);
- * 未下发时回退 plan_exit 入参中的 summary / plan。</p>
- */
- import { computed, ref } from 'vue';
- import { Button as AButton, Tag as ATag } from 'ant-design-vue';
- import { Icon } from '@/core/components/Icon';
- const props = defineProps<{ part: any }>();
- defineEmits<{ (e: 'approve'): void; (e: 'reject'): void; (e: 'open-doc'): void }>();
- const showRaw = ref(false);
- const planCall = computed(() =>
- (props.part?.toolCalls ?? []).find(
- (c: any) => c.toolName === 'plan_exit' || /批准计划/.test(c.toolLabel || ''),
- ),
- );
- const summary = computed(() => {
- const input = planCall.value?.input;
- if (!input) return '';
- if (typeof input === 'string') {
- try {
- const p = JSON.parse(input);
- return p?.summary || p?.plan || input;
- } catch {
- return input;
- }
- }
- return input.summary || input.plan || '';
- });
- /** 展示正文:后端下发的 plan_write 全文优先(完整方案),否则回退 plan_exit 摘要 */
- const displayText = computed(() => props.part?.planContent || summary.value || '');
- const rawInput = computed(() => {
- const input = planCall.value?.input;
- if (input == null) return '';
- return typeof input === 'string' ? input : JSON.stringify(input, null, 2);
- });
- const stateLabel = computed(() => {
- const m: Record<string, string> = { pending: '待批准', approved: '已批准', rejected: '已拒绝', expired: '已失效' };
- return m[props.part?.confirmState] || props.part?.confirmState;
- });
- const stateColor = computed(() => {
- const m: Record<string, string> = { pending: 'warning', approved: 'success', rejected: 'error', expired: 'default' };
- return m[props.part?.confirmState] || 'default';
- });
- </script>
- <style scoped lang="less">
- .plan-card {
- margin: 10px 0;
- overflow: hidden;
- border: 1px solid var(--wb-border, #e5e9f2);
- border-radius: 12px;
- background: #fff;
- box-shadow: 0 2px 10px rgba(42, 80, 236, 0.06);
- &__head {
- display: flex;
- align-items: center;
- gap: 10px;
- padding: 12px 14px;
- background: linear-gradient(120deg, var(--wb-primary-soft, #e8eefc), #f5f3ff 70%);
- border-bottom: 1px solid var(--wb-border, #e5e9f2);
- }
- &__icon {
- display: grid;
- place-items: center;
- width: 34px;
- height: 34px;
- flex: none;
- border-radius: 10px;
- color: #fff;
- background: linear-gradient(135deg, var(--wb-primary, #2a50ec), #7c3aed);
- box-shadow: 0 3px 10px rgba(42, 80, 236, 0.3);
- font-size: 18px;
- }
- &__titles {
- display: flex;
- flex-direction: column;
- min-width: 0;
- }
- &__title {
- font-size: 14.5px;
- font-weight: 700;
- color: var(--wb-text, #1f2937);
- }
- &__sub {
- font-size: 11.5px;
- color: var(--wb-text-2, #64748b);
- }
- &__tag {
- margin-left: auto;
- margin-inline-end: 0;
- }
- &__body {
- padding: 14px;
- }
- &__summary {
- max-height: 260px;
- overflow: auto;
- padding: 12px 14px;
- font-size: 13.5px;
- line-height: 1.8;
- color: var(--wb-text, #1f2937);
- background: #f8fafc;
- border: 1px solid var(--wb-border, #e5e9f2);
- border-left: 3px solid var(--wb-primary, #2a50ec);
- border-radius: 0 8px 8px 0;
- white-space: pre-wrap;
- word-break: break-word;
- }
- &__meta {
- display: flex;
- align-items: center;
- gap: 10px;
- margin-top: 10px;
- }
- &__doc {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- padding: 5px 12px;
- font-size: 12.5px;
- font-weight: 600;
- color: var(--wb-primary, #2a50ec);
- background: var(--wb-primary-soft, #e8eefc);
- border: 1px solid rgba(42, 80, 236, 0.25);
- border-radius: 8px;
- cursor: pointer;
- transition: 0.15s;
- &:hover {
- background: #dbe6ff;
- border-color: var(--wb-primary, #2a50ec);
- }
- }
- &__path {
- overflow: hidden;
- max-width: 200px;
- font-size: 11.5px;
- color: var(--wb-text-muted, #94a3b8);
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- &__reject {
- font-size: 11.5px;
- color: var(--wb-danger, #dc2626);
- }
- &__raw-toggle {
- margin-left: auto;
- padding: 4px 10px;
- font-size: 12px;
- color: var(--wb-text-muted, #94a3b8);
- background: transparent;
- border: 1px solid var(--wb-border, #e5e9f2);
- border-radius: 6px;
- cursor: pointer;
- &:hover {
- color: var(--wb-text-2, #64748b);
- }
- }
- &__raw {
- margin: 10px 0 0;
- max-height: 200px;
- overflow: auto;
- padding: 10px 12px;
- font-size: 12px;
- background: #f8fafc;
- border: 1px solid var(--wb-border, #e5e9f2);
- border-radius: 8px;
- white-space: pre-wrap;
- word-break: break-all;
- }
- &__actions {
- display: flex;
- gap: 10px;
- padding: 0 14px 14px;
- }
- &__tip {
- padding: 0 14px 14px;
- font-size: 12.5px;
- color: var(--wb-text-2, #64748b);
- &--ok {
- color: var(--wb-success, #16a34a);
- }
- }
- }
- </style>
|