@bams-app/ui-quick-qa 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ <template>
2
+ <!--
3
+ 修改时间:2026-11-11
4
+ 修改原因:统一智能问答与 Agent 对话中的 AI/用户头像视觉。
5
+ 修改内容:封装 Ant Design Vue 的 a-avatar,并提供品牌渐变和主题化中性样式。
6
+ -->
7
+ <a-avatar
8
+ :size="normalizedSize"
9
+ :src="props.image || undefined"
10
+ :class="avatarClasses"
11
+ :aria-label="props.role === 'user' ? '用户头像' : 'AI 助手头像'"
12
+ >
13
+ {{ fallbackText }}
14
+ </a-avatar>
15
+ </template>
16
+
17
+ <script setup>
18
+ import { computed } from "vue";
19
+
20
+ /**
21
+ * 修改时间:2026-11-11
22
+ * 修改原因:不同宿主中的头像文案、尺寸和角色样式不一致。
23
+ * 修改内容:定义最小化的展示型 props,不包含任何会话或请求逻辑。
24
+ */
25
+ const props = defineProps({
26
+ /** 头像图片地址;为空时展示名称首字。 */
27
+ image: {
28
+ type: String,
29
+ default: "",
30
+ },
31
+ /** 头像兜底文字,通常传入用户名称或 Agent 名称。 */
32
+ label: {
33
+ type: String,
34
+ default: "AI",
35
+ },
36
+ /** 头像视觉角色,用于区分 AI 与用户。 */
37
+ role: {
38
+ type: String,
39
+ default: "assistant",
40
+ validator: value => ["assistant", "user"].includes(value),
41
+ },
42
+ /** 头像尺寸,保持与 Ant Design Avatar 的数值尺寸一致。 */
43
+ size: {
44
+ type: [Number, String],
45
+ default: 32,
46
+ },
47
+ });
48
+
49
+ /**
50
+ * 修改时间:2026-11-11
51
+ * 修改原因:props.size 允许字符串传入,需要保证最终尺寸合法。
52
+ * 修改内容:对尺寸进行数值归一化,并在异常时回退到 32px。
53
+ */
54
+ const normalizedSize = computed(() => {
55
+ const numericSize = Number(props.size);
56
+ return Number.isFinite(numericSize) && numericSize > 0 ? numericSize : 32;
57
+ });
58
+
59
+ /**
60
+ * 修改时间:2026-11-11
61
+ * 修改原因:图片加载失败或 Agent 未配置头像时仍需要稳定展示。
62
+ * 修改内容:取名称第一个可见字符作为头像兜底文字。
63
+ */
64
+ const fallbackText = computed(() => {
65
+ const normalizedLabel = String(props.label || "").trim();
66
+ if (!normalizedLabel) return props.role === "user" ? "我" : "AI";
67
+ return normalizedLabel.slice(0, 1).toUpperCase();
68
+ });
69
+
70
+ /**
71
+ * 修改时间:2026-11-11
72
+ * 修改原因:避免模板中重复拼接角色 class。
73
+ * 修改内容:按角色生成稳定的样式类名。
74
+ */
75
+ const avatarClasses = computed(() => [
76
+ "quick-qa-avatar",
77
+ `quick-qa-avatar--${props.role}`,
78
+ ]);
79
+ </script>
80
+
81
+ <style scoped>
82
+ /* 修改时间:2026-11-11;原因:头像需要接入 BAMS 主题;内容:补充边框和字体规范。 */
83
+ .quick-qa-avatar {
84
+ flex: 0 0 auto;
85
+ border: 1px solid var(--bams-border-color);
86
+ color: var(--bams-text-color);
87
+ font-weight: 600;
88
+ }
89
+
90
+ /* 修改时间:2026-11-11;原因:AI 头像需要复现 ui-quick-qa 的品牌识别;内容:使用主题渐变。 */
91
+ .quick-qa-avatar.quick-qa-avatar--assistant {
92
+ border-color: color-mix(in srgb, var(--bams-primary) 34%, transparent);
93
+ background: linear-gradient(
94
+ 135deg,
95
+ var(--bams-primary),
96
+ var(--bams-primary-hover)
97
+ );
98
+ color: var(--bams-button-primary-text);
99
+ box-shadow: 0 6px 18px var(--bams-primary-outline);
100
+ }
101
+
102
+ /* 修改时间:2026-11-11;原因:用户头像需要保持中性层级;内容:改用表面弱化色。 */
103
+ .quick-qa-avatar.quick-qa-avatar--user {
104
+ border-color: var(--bams-border-color);
105
+ background: var(--bams-surface-bg-muted);
106
+ color: var(--bams-text-secondary);
107
+ box-shadow: none;
108
+ }
109
+ </style>
@@ -0,0 +1,117 @@
1
+ <template>
2
+ <!--
3
+ 修改时间:2026-11-11
4
+ 修改原因:ui-quick-qa 的输入区视觉需要在 Agent 聊天和助手中复用。
5
+ 修改内容:提供只负责布局与主题的输入容器,具体输入控件和按钮由业务组件通过插槽注入。
6
+ -->
7
+ <div
8
+ class="quick-qa-composer"
9
+ :class="{
10
+ 'quick-qa-composer--compact': props.compact,
11
+ 'quick-qa-composer--streaming': props.streaming,
12
+ }"
13
+ >
14
+ <div class="quick-qa-composer__body">
15
+ <slot />
16
+ </div>
17
+
18
+ <div v-if="$slots.footer" class="quick-qa-composer__footer">
19
+ <slot name="footer" />
20
+ </div>
21
+ </div>
22
+ </template>
23
+
24
+ <script setup>
25
+ /**
26
+ * 修改时间:2026-11-11
27
+ * 修改原因:Agent 对话页与右下角助手需要不同内边距,但应共享同一套输入框视觉。
28
+ * 修改内容:提供 compact 和 streaming 两个展示开关。
29
+ */
30
+ const props = defineProps({
31
+ /** 是否使用浮窗内的紧凑内边距。 */
32
+ compact: {
33
+ type: Boolean,
34
+ default: false,
35
+ },
36
+ /** 当前是否正在生成回答,用于展示轻量运行态强调。 */
37
+ streaming: {
38
+ type: Boolean,
39
+ default: false,
40
+ },
41
+ });
42
+ </script>
43
+
44
+ <style scoped>
45
+ /* 修改时间:2026-11-11;原因:输入区需要复用 ui-quick-qa 的圆角卡片;内容:主题化容器。 */
46
+ .quick-qa-composer {
47
+ display: flex;
48
+ flex-direction: column;
49
+ gap: 8px;
50
+ border: 1px solid var(--bams-input-border);
51
+ border-radius: 14px;
52
+ padding: 10px 12px;
53
+ background: var(--bams-input-bg);
54
+ box-shadow: 0 4px 16px color-mix(in srgb, var(--bams-primary) 7%, transparent);
55
+ transition:
56
+ border-color 0.18s ease,
57
+ box-shadow 0.18s ease,
58
+ transform 0.18s ease;
59
+ }
60
+
61
+ /* 修改时间:2026-11-11;原因:需要复现 ui-quick-qa 的聚焦光晕;内容:统一焦点态。 */
62
+ .quick-qa-composer:focus-within {
63
+ border-color: var(--bams-input-border-focus);
64
+ box-shadow:
65
+ var(--bams-input-shadow-focus),
66
+ 0 10px 26px color-mix(in srgb, var(--bams-primary) 12%, transparent);
67
+ }
68
+
69
+ /* 修改时间:2026-11-11;原因:生成中需要弱提示但不应抢夺消息内容注意力;内容:增加顶部品牌线。 */
70
+ .quick-qa-composer--streaming {
71
+ position: relative;
72
+ border-color: color-mix(in srgb, var(--bams-primary) 44%, var(--bams-border-color));
73
+ }
74
+
75
+ .quick-qa-composer--streaming::before {
76
+ position: absolute;
77
+ top: -1px;
78
+ right: 18px;
79
+ left: 18px;
80
+ height: 2px;
81
+ border-radius: 999px;
82
+ background: linear-gradient(
83
+ 90deg,
84
+ transparent,
85
+ var(--bams-primary),
86
+ var(--bams-primary-hover),
87
+ transparent
88
+ );
89
+ content: "";
90
+ animation: quick-qa-composer-pulse 1.6s ease-in-out infinite;
91
+ }
92
+
93
+ /* 修改时间:2026-11-11;原因:助手浮窗空间有限;内容:压缩内边距和圆角。 */
94
+ .quick-qa-composer--compact {
95
+ gap: 6px;
96
+ border-radius: 12px;
97
+ padding: 8px 10px;
98
+ }
99
+
100
+ .quick-qa-composer__body,
101
+ .quick-qa-composer__footer {
102
+ min-width: 0;
103
+ }
104
+
105
+ @keyframes quick-qa-composer-pulse {
106
+ 0%,
107
+ 100% {
108
+ opacity: 0.38;
109
+ transform: scaleX(0.82);
110
+ }
111
+
112
+ 50% {
113
+ opacity: 1;
114
+ transform: scaleX(1);
115
+ }
116
+ }
117
+ </style>
@@ -0,0 +1,253 @@
1
+ <template>
2
+ <!--
3
+ 修改时间:2026-11-11
4
+ 修改原因:ui-quick-qa 的推荐问题胶囊需要复用到 Agent 对话空态和助手欢迎页。
5
+ 修改内容:抽出可折叠、可禁用、可压缩的推荐问题面板。
6
+ -->
7
+ <section
8
+ v-if="safeQuestions.length"
9
+ class="quick-qa-prompts"
10
+ :class="{
11
+ 'quick-qa-prompts--collapsed': props.collapsed,
12
+ 'quick-qa-prompts--compact': props.compact,
13
+ }"
14
+ :aria-label="props.label"
15
+ >
16
+ <span class="quick-qa-prompts__label">
17
+ <span class="quick-qa-prompts__marker" aria-hidden="true"></span>
18
+ {{ props.label }}
19
+ </span>
20
+
21
+ <a-button
22
+ v-if="props.showRefresh"
23
+ class="quick-qa-prompts__refresh"
24
+ type="link"
25
+ size="small"
26
+ html-type="button"
27
+ :disabled="props.disabled"
28
+ @click="$emit('refresh')"
29
+ >
30
+ 换一批
31
+ </a-button>
32
+
33
+ <div class="quick-qa-prompts__list">
34
+ <a-button
35
+ v-for="question in safeQuestions"
36
+ :key="question"
37
+ class="quick-qa-prompt-tag"
38
+ size="small"
39
+ html-type="button"
40
+ :disabled="props.disabled"
41
+ @click="$emit('select', question)"
42
+ >
43
+ {{ question }}
44
+ </a-button>
45
+ </div>
46
+
47
+ <a-button
48
+ v-if="props.showToggle"
49
+ class="quick-qa-prompts__toggle"
50
+ type="text"
51
+ size="small"
52
+ html-type="button"
53
+ :aria-expanded="!props.collapsed"
54
+ @click="$emit('toggle', !props.collapsed)"
55
+ >
56
+ {{ props.collapsed ? "展开" : "收起" }}
57
+ <span class="quick-qa-prompts__caret" aria-hidden="true">
58
+ {{ props.collapsed ? "▾" : "▴" }}
59
+ </span>
60
+ </a-button>
61
+ </section>
62
+ </template>
63
+
64
+ <script setup>
65
+ import { computed } from "vue";
66
+
67
+ /**
68
+ * 修改时间:2026-11-11
69
+ * 修改原因:对话页与助手页需要复用同一推荐问题交互,但布局密度不同。
70
+ * 修改内容:定义问题列表、标题、折叠、禁用和紧凑展示等纯展示参数。
71
+ */
72
+ const props = defineProps({
73
+ /** 推荐问题列表,空项会被过滤。 */
74
+ questions: {
75
+ type: Array,
76
+ default: () => [],
77
+ },
78
+ /** 面板标题,默认沿用 ui-quick-qa 的“预设问题”。 */
79
+ label: {
80
+ type: String,
81
+ default: "预设问题",
82
+ },
83
+ /** 是否折叠为单行横向滚动。 */
84
+ collapsed: {
85
+ type: Boolean,
86
+ default: false,
87
+ },
88
+ /** 是否显示展开/收起按钮。 */
89
+ showToggle: {
90
+ type: Boolean,
91
+ default: false,
92
+ },
93
+ /** 是否显示“换一批”按钮;默认关闭,避免影响其它调用方。 */
94
+ showRefresh: {
95
+ type: Boolean,
96
+ default: false,
97
+ },
98
+ /** 回答生成中或未选择 Agent 时禁用问题按钮。 */
99
+ disabled: {
100
+ type: Boolean,
101
+ default: false,
102
+ },
103
+ /** 助手浮窗内使用更紧凑的间距。 */
104
+ compact: {
105
+ type: Boolean,
106
+ default: false,
107
+ },
108
+ });
109
+
110
+ /**
111
+ * 修改时间:2026-11-11
112
+ * 修改原因:调用方可能传入空值或非字符串,直接渲染会产生脏 key 和空胶囊。
113
+ * 修改内容:统一去除空白,并仅保留非空字符串。
114
+ */
115
+ const safeQuestions = computed(() =>
116
+ (props.questions || [])
117
+ .filter(question => typeof question === "string")
118
+ .map(question => question.trim())
119
+ .filter(Boolean)
120
+ );
121
+
122
+ /**
123
+ * 修改时间:2026-11-11
124
+ * 修改原因:父组件需要接收用户选择,但面板本身不应持有发送逻辑。
125
+ * 修改内容:对外提供 select 与 toggle 两个语义化事件。
126
+ */
127
+ defineEmits(["select", "toggle", "refresh"]);
128
+ </script>
129
+
130
+ <style scoped>
131
+ /* 修改时间:2026-11-11;原因:推荐问题需要复现 ui-quick-qa 的卡片视觉;内容:主题化外层容器。 */
132
+ .quick-qa-prompts {
133
+ display: flex;
134
+ flex-wrap: wrap;
135
+ align-items: center;
136
+ gap: 8px;
137
+ border: 1px solid var(--bams-border-color);
138
+ border-radius: 14px;
139
+ padding: 11px 12px;
140
+ background: var(--bams-surface-bg-elevated);
141
+ box-shadow: var(--bams-shadow-card);
142
+ }
143
+
144
+ .quick-qa-prompts__label {
145
+ display: inline-flex;
146
+ flex: 1 1 auto;
147
+ align-items: center;
148
+ gap: 7px;
149
+ color: var(--bams-text-secondary);
150
+ font-size: 12px;
151
+ font-weight: 600;
152
+ }
153
+
154
+ .quick-qa-prompts__marker {
155
+ width: 7px;
156
+ height: 7px;
157
+ border-radius: 50%;
158
+ background: linear-gradient(
159
+ 135deg,
160
+ var(--bams-primary),
161
+ var(--bams-primary-hover)
162
+ );
163
+ box-shadow: 0 0 0 3px var(--bams-primary-soft);
164
+ }
165
+
166
+ .quick-qa-prompts__refresh.ant-btn {
167
+ flex: 0 0 auto;
168
+ height: 24px;
169
+ padding: 0 4px;
170
+ color: var(--bams-primary);
171
+ font-size: 12px;
172
+ }
173
+
174
+ .quick-qa-prompts__list {
175
+ order: 3;
176
+ display: flex;
177
+ flex: 1 1 100%;
178
+ flex-wrap: wrap;
179
+ gap: 8px;
180
+ min-width: 0;
181
+ }
182
+
183
+ /* 修改时间:2026-11-11;原因:推荐问题按钮需要轻量胶囊外观;内容:覆盖 Ant Button 默认视觉。 */
184
+ .quick-qa-prompt-tag.ant-btn {
185
+ height: 28px;
186
+ border-color: var(--bams-border-color);
187
+ border-radius: 999px;
188
+ padding: 0 12px;
189
+ background: var(--bams-button-default-bg);
190
+ color: var(--bams-text-color);
191
+ font-size: 12px;
192
+ transition:
193
+ transform 0.16s ease,
194
+ border-color 0.16s ease,
195
+ background 0.16s ease,
196
+ color 0.16s ease;
197
+ }
198
+
199
+ .quick-qa-prompt-tag.ant-btn:not(:disabled):hover {
200
+ border-color: var(--bams-primary-border);
201
+ background: var(--bams-primary-bg);
202
+ color: var(--bams-primary);
203
+ transform: translateY(-1px);
204
+ }
205
+
206
+ .quick-qa-prompts__toggle.ant-btn {
207
+ flex: 0 0 auto;
208
+ color: var(--bams-text-secondary);
209
+ font-size: 12px;
210
+ }
211
+
212
+ .quick-qa-prompts__caret {
213
+ margin-left: 3px;
214
+ font-size: 10px;
215
+ }
216
+
217
+ .quick-qa-prompts--collapsed {
218
+ flex-wrap: nowrap;
219
+ }
220
+
221
+ .quick-qa-prompts--collapsed .quick-qa-prompts__label {
222
+ flex: 0 0 auto;
223
+ }
224
+
225
+ .quick-qa-prompts--collapsed .quick-qa-prompts__list {
226
+ order: 1;
227
+ flex-wrap: nowrap;
228
+ overflow-x: auto;
229
+ padding-bottom: 2px;
230
+ }
231
+
232
+ .quick-qa-prompts--collapsed .quick-qa-prompts__toggle {
233
+ order: 2;
234
+ }
235
+
236
+ .quick-qa-prompts--compact {
237
+ gap: 6px;
238
+ padding: 9px 10px;
239
+ box-shadow: none;
240
+ }
241
+
242
+ .quick-qa-prompts--compact .quick-qa-prompts__list {
243
+ gap: 6px;
244
+ }
245
+
246
+ .quick-qa-prompts--compact .quick-qa-prompt-tag.ant-btn {
247
+ max-width: 100%;
248
+ height: 26px;
249
+ overflow: hidden;
250
+ padding: 0 10px;
251
+ text-overflow: ellipsis;
252
+ }
253
+ </style>
@@ -1,4 +1,4 @@
1
- export {};
2
-
3
-
4
-
1
+ export {};
2
+
3
+
4
+
@@ -1 +1 @@
1
-
1
+