AskforPanel.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <script setup>
  2. /**
  3. * v1.1:区域 ⑤ —— Askfor 用户确认(内嵌式)
  4. * 全局唯一(同 run 同时只有一个 pending),嵌在 AgentThinkingPanel 内。
  5. *
  6. * 行为:
  7. * - 展示 question + choices 列表(按钮形式,宽度一致)
  8. * - 自定义输入行与选项按钮外观/高度一致,下方独立一行
  9. * - 用户点击选项 → 直接提交该选项值
  10. * - 用户在输入框输入并提交 → 提交自定义文本
  11. */
  12. import { ref, computed } from 'vue'
  13. import { NInput } from 'naive-ui'
  14. const props = defineProps({
  15. pending: { type: Object, default: null }, // {clarifyId, question, choices}
  16. })
  17. const emit = defineEmits(['submit'])
  18. const customText = ref('')
  19. const options = computed(() => {
  20. return Array.isArray(props.pending?.choices) ? [...props.pending.choices] : []
  21. })
  22. function submitChoice(c) {
  23. emit('submit', c)
  24. }
  25. function submitCustom() {
  26. const text = customText.value.trim()
  27. if (!text) return
  28. emit('submit', text)
  29. customText.value = ''
  30. }
  31. </script>
  32. <template>
  33. <div v-if="pending" class="askfor-inline">
  34. <div class="header">
  35. <span class="title">需要您的确认</span>
  36. </div>
  37. <div class="question">{{ pending.question }}</div>
  38. <!-- 选项按钮:始终显示,宽度一致 -->
  39. <div v-if="options.length" class="choices">
  40. <button
  41. v-for="(c, i) in options"
  42. :key="i"
  43. class="choice-btn"
  44. @click="submitChoice(c)"
  45. >
  46. {{ c }}
  47. </button>
  48. </div>
  49. <!-- 自定义输入行:与选项按钮高度/外观一致 -->
  50. <div class="custom-row">
  51. <NInput
  52. v-model:value="customText"
  53. class="custom-input"
  54. placeholder="或输入自定义回答..."
  55. :bordered="false"
  56. @keydown.enter.prevent="submitCustom"
  57. />
  58. <button
  59. class="submit-btn"
  60. :disabled="!customText.trim()"
  61. @click="submitCustom"
  62. >
  63. 提交
  64. </button>
  65. </div>
  66. </div>
  67. </template>
  68. <style scoped>
  69. /* v1.1:内嵌式 Askfor,深色风格统一
  70. 整个面板使用同一字体 + 同一号字(选项按钮与输入框完全一致) */
  71. .askfor-inline {
  72. border: 1px solid rgba(168, 85, 247, 0.4);
  73. border-radius: 6px;
  74. background: rgba(168, 85, 247, 0.05);
  75. padding: 10px 12px;
  76. margin: 8px 10px 4px;
  77. /* 容器统一字体,子元素 NInput/button 全部继承 */
  78. font-size: 12px;
  79. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  80. line-height: 1.5;
  81. }
  82. .header {
  83. display: flex;
  84. align-items: center;
  85. gap: 6px;
  86. margin-bottom: 6px;
  87. }
  88. .title {
  89. font-weight: 600;
  90. font-size: 12px;
  91. color: #c084fc;
  92. }
  93. .question {
  94. padding: 8px 10px;
  95. background: rgba(255, 255, 255, 0.03);
  96. border-radius: 4px;
  97. margin-bottom: 8px;
  98. color: var(--text-secondary, #b0b0b0);
  99. white-space: pre-wrap;
  100. word-break: break-word;
  101. font-size: 12px;
  102. border-left: 2px solid rgba(168, 85, 247, 0.5);
  103. }
  104. .choices {
  105. display: flex;
  106. flex-direction: column;
  107. gap: 4px;
  108. margin-bottom: 4px;
  109. }
  110. .choice-btn {
  111. /* 与 custom-row 同高度、同内边距、同宽度、同字体、同字号 */
  112. padding: 5px 12px;
  113. min-height: 32px;
  114. border: 1px solid rgba(168, 85, 247, 0.3);
  115. border-radius: 3px;
  116. background: rgba(255, 255, 255, 0.03);
  117. cursor: pointer;
  118. text-align: left;
  119. transition: all 0.15s;
  120. font-size: 12px;
  121. color: var(--text-primary, #e0e0e0);
  122. font-family: inherit; /* 继承 .askfor-inline 的字体 */
  123. width: 100%;
  124. }
  125. .choice-btn:hover {
  126. border-color: #c084fc;
  127. background: rgba(168, 85, 247, 0.12);
  128. color: #c084fc;
  129. }
  130. /* 自定义输入行:与选项按钮外观一致,左侧输入 + 右侧提交按钮 */
  131. .custom-row {
  132. display: flex;
  133. align-items: stretch;
  134. margin-top: 4px;
  135. min-height: 32px;
  136. border: 1px solid rgba(168, 85, 247, 0.3);
  137. border-radius: 3px;
  138. background: rgba(255, 255, 255, 0.03);
  139. overflow: hidden;
  140. transition: all 0.15s;
  141. font-family: inherit; /* 继承字体 */
  142. font-size: 12px;
  143. }
  144. .custom-row:focus-within {
  145. border-color: #c084fc;
  146. background: rgba(168, 85, 247, 0.08);
  147. }
  148. .custom-row :deep(.n-input) {
  149. flex: 1;
  150. background: transparent;
  151. font-family: inherit !important;
  152. font-size: 12px !important;
  153. /* NInput 容器本身零内边距,避免与内部输入元素的 padding 叠加产生"中文 padding"错觉 */
  154. padding: 0 !important;
  155. }
  156. /* NInput 的 wrapper 也是零内边距,让输入元素的 padding 成为唯一水平留白 */
  157. .custom-row :deep(.n-input .n-input-wrapper) {
  158. padding: 0 !important;
  159. border: none !important;
  160. min-height: 32px !important;
  161. }
  162. .custom-row :deep(.n-input .n-input__textarea-el),
  163. .custom-row :deep(.n-input .n-input__input-el) {
  164. font-size: 12px !important;
  165. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace !important;
  166. color: var(--text-primary, #e0e0e0);
  167. padding: 5px 12px;
  168. min-height: 32px !important;
  169. line-height: 1.5;
  170. resize: none;
  171. }
  172. /* placeholder 同样字体同字号 */
  173. .custom-row :deep(.n-input .n-input__placeholder),
  174. .custom-row :deep(.n-input textarea::placeholder) {
  175. font-size: 12px !important;
  176. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace !important;
  177. }
  178. /* placeholder 与真实输入光标对齐:因为外层 .n-input / .n-input-wrapper 的 padding
  179. 被清零(见上),只有最内层 input 元素有 padding-left:12px,导致绝对定位的
  180. placeholder 元素贴在最左边、与输入光标错位。这里给 placeholder 补上同样的左 padding。 */
  181. .custom-row :deep(.n-input .n-input__placeholder) {
  182. padding-left: 12px !important;
  183. }
  184. /* 提交按钮:纯色背景 + 白字,小尺寸,与"保存"按钮主色一致 */
  185. .submit-btn {
  186. flex-shrink: 0;
  187. padding: 0 14px;
  188. min-height: 32px;
  189. border: none;
  190. border-radius: 0;
  191. background: var(--color-primary, #2563EB);
  192. color: #ffffff;
  193. font-size: 12px;
  194. font-family: inherit; /* 继承字体,与选项/输入框一致 */
  195. cursor: pointer;
  196. transition: background 0.15s;
  197. }
  198. .submit-btn:hover:not(:disabled) {
  199. background: var(--color-primary-light, #3B82F6);
  200. }
  201. .submit-btn:disabled {
  202. background: rgba(255, 255, 255, 0.1);
  203. color: var(--text-tertiary, #666);
  204. cursor: not-allowed;
  205. }
  206. </style>