AskforPanel.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 v-for="(c, i) in options" :key="i" class="choice-btn" @click="submitChoice(c)">
  41. {{ c }}
  42. </button>
  43. </div>
  44. <!-- L-6:自定义输入行 —— 改为 textarea 支持多行,Enter 提交 / Shift+Enter 换行 -->
  45. <div class="custom-row">
  46. <NInput v-model:value="customText" class="custom-input" type="textarea" :autosize="{ minRows: 3, maxRows: 8 }"
  47. placeholder="输入自定义回答... (Enter 提交,Shift+Enter 换行)" :bordered="false"
  48. @keydown.enter.exact.prevent="submitCustom" />
  49. <button class="submit-btn" :disabled="!customText.trim()" @click="submitCustom">
  50. 提交
  51. </button>
  52. </div>
  53. </div>
  54. </template>
  55. <style scoped>
  56. /* v1.1:内嵌式 Askfor,深色风格统一
  57. 整个面板使用同一字体 + 同一号字(选项按钮与输入框完全一致) */
  58. .askfor-inline {
  59. border: 1px solid rgba(168, 85, 247, 0.4);
  60. border-radius: 6px;
  61. background: rgba(168, 85, 247, 0.05);
  62. padding: 10px 12px;
  63. margin: 8px 10px 4px;
  64. /* 容器统一字体,子元素 NInput/button 全部继承 */
  65. font-size: 12px;
  66. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  67. line-height: 1.5;
  68. }
  69. .header {
  70. display: flex;
  71. align-items: center;
  72. gap: 6px;
  73. margin-bottom: 6px;
  74. }
  75. .title {
  76. font-weight: 600;
  77. font-size: 12px;
  78. color: #c084fc;
  79. }
  80. .question {
  81. padding: 8px 10px;
  82. background: rgba(255, 255, 255, 0.03);
  83. border-radius: 4px;
  84. margin-bottom: 8px;
  85. color: var(--text-secondary, #b0b0b0);
  86. white-space: pre-wrap;
  87. word-break: break-word;
  88. font-size: 12px;
  89. border-left: 2px solid rgba(168, 85, 247, 0.5);
  90. }
  91. .choices {
  92. display: flex;
  93. flex-direction: column;
  94. gap: 4px;
  95. margin-bottom: 4px;
  96. }
  97. .choice-btn {
  98. /* 与 custom-row 同高度、同内边距、同宽度、同字体、同字号 */
  99. padding: 5px 12px;
  100. min-height: 32px;
  101. border: 1px solid rgba(168, 85, 247, 0.3);
  102. border-radius: 3px;
  103. background: rgba(255, 255, 255, 0.03);
  104. cursor: pointer;
  105. text-align: left;
  106. transition: all 0.15s;
  107. font-size: 12px;
  108. color: var(--text-primary, #e0e0e0);
  109. font-family: inherit;
  110. /* 继承 .askfor-inline 的字体 */
  111. width: 100%;
  112. }
  113. .choice-btn:hover {
  114. border-color: #c084fc;
  115. background: rgba(168, 85, 247, 0.12);
  116. color: #c084fc;
  117. }
  118. /* 自定义输入行:与选项按钮外观一致,左侧输入 + 右侧提交按钮
  119. 高度由 NInput autosize 控制(minRows=3),容器不强制 min-height */
  120. .custom-row {
  121. display: flex;
  122. align-items: stretch;
  123. margin-top: 4px;
  124. border: 1px solid rgba(168, 85, 247, 0.3);
  125. border-radius: 3px;
  126. background: rgba(255, 255, 255, 0.03);
  127. overflow: hidden;
  128. transition: all 0.15s;
  129. font-family: inherit;
  130. /* 继承字体 */
  131. font-size: 12px;
  132. }
  133. .custom-row:focus-within {
  134. border-color: #c084fc;
  135. background: rgba(168, 85, 247, 0.08);
  136. }
  137. .custom-row :deep(.n-input) {
  138. flex: 1;
  139. background: transparent;
  140. font-family: inherit !important;
  141. font-size: 12px !important;
  142. /* NInput 容器本身零内边距,避免与内部输入元素的 padding 叠加产生"中文 padding"错觉 */
  143. padding: 0 !important;
  144. }
  145. /* NInput 的 wrapper 也是零内边距,让输入元素的 padding 成为唯一水平留白
  146. 不再强制 min-height,交由 autosize 按 minRows 计算 */
  147. .custom-row :deep(.n-input .n-input-wrapper) {
  148. padding: 0 !important;
  149. border: none !important;
  150. }
  151. .custom-row :deep(.n-input .n-input__textarea-el),
  152. .custom-row :deep(.n-input .n-input__input-el) {
  153. font-size: 12px !important;
  154. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace !important;
  155. color: var(--text-primary, #e0e0e0);
  156. padding: 5px 12px;
  157. line-height: 1.5;
  158. resize: none;
  159. }
  160. /* placeholder 同样字体同字号 */
  161. .custom-row :deep(.n-input .n-input__placeholder),
  162. .custom-row :deep(.n-input textarea::placeholder) {
  163. font-size: 12px !important;
  164. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace !important;
  165. }
  166. /* placeholder 与真实输入光标对齐:因为外层 .n-input / .n-input-wrapper 的 padding
  167. 被清零(见上),只有最内层 input 元素有 padding-left:12px,导致绝对定位的
  168. placeholder 元素贴在最左边、与输入光标错位。这里给 placeholder 补上同样的左 padding。 */
  169. .custom-row :deep(.n-input .n-input__placeholder) {
  170. padding-left: 12px !important;
  171. }
  172. /* 提交按钮:纯色背景 + 白字,小尺寸,与"保存"按钮主色一致 */
  173. .submit-btn {
  174. flex-shrink: 0;
  175. padding: 0 14px;
  176. min-height: 32px;
  177. border: none;
  178. border-radius: 0;
  179. background: var(--color-primary, #2563EB);
  180. color: #ffffff;
  181. font-size: 12px;
  182. font-family: inherit;
  183. /* 继承字体,与选项/输入框一致 */
  184. cursor: pointer;
  185. transition: background 0.15s;
  186. }
  187. .submit-btn:hover:not(:disabled) {
  188. background: var(--color-primary-light, #3B82F6);
  189. }
  190. .submit-btn:disabled {
  191. background: rgba(255, 255, 255, 0.1);
  192. color: var(--text-tertiary, #666);
  193. cursor: not-allowed;
  194. }
  195. </style>