SsChatReply.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view class="ss-chat-reply">
  3. <!-- 网络搜索结果 -->
  4. <view v-if="reply.source && reply.source.length" class="quota" :class="{unfold: unfold}">
  5. <view class="quota-intro">
  6. <view class="quota-small" @tap="toggleUnfold">
  7. <view class="quota-title">基于{{ reply.source.length }}个搜索来源</view>
  8. <view class="quota-brand">
  9. <template v-for="(item, index) in reply.source">
  10. <image v-if="index < 6" class="quota-brand-logo" mode="aspectFill" :src="getLogoUrl(item)" />
  11. </template>
  12. </view>
  13. </view>
  14. <view class="quota-detail">
  15. <view class="quota-line">
  16. <view class="line-left">✓</view>
  17. <view class="line-content">
  18. <view class="line-title">理解问题</view>
  19. </view>
  20. <view class="quota-close" @tap="toggleUnfold">▲</view>
  21. </view>
  22. <view class="quota-line">
  23. <view class="line-left">✓</view>
  24. <view class="line-content">
  25. <view class="line-title">搜索网页</view>
  26. <view class="line-box flex">
  27. <view class="search-text">{{ reply.title }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="quota-line">
  32. <view class="line-left">✓</view>
  33. <view class="line-content">
  34. <view class="line-title">找到{{ reply.source.length }}个搜索来源</view>
  35. </view>
  36. </view>
  37. <scroll-view class="source-scroll" scroll-x :scroll-with-animation="true">
  38. <view class="source">
  39. <view v-for="(item, index) in reply.source" :key="index" class="source-item" @tap.stop="copyLink(item.url)">
  40. <view class="source-title">{{ item.title }}</view>
  41. <view class="source-footer">
  42. <view class="source-brand">
  43. <image class="source-icon" mode="aspectFill" :src="getLogoUrl(item)" />
  44. <view class="source-summary">{{ item.summary }}</view>
  45. </view>
  46. <view class="source-number">{{ index + 1 }}</view>
  47. </view>
  48. </view>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 回复内容 -->
  55. <view class="reply-content">
  56. <!-- Loading 动画:三个点交替跃动 -->
  57. <view v-if="last && showLoading" class="typing-indicator">
  58. <view class="dot"></view>
  59. <view class="dot"></view>
  60. <view class="dot"></view>
  61. </view>
  62. <!-- 内容区域 -->
  63. <view v-else class="replay-container">
  64. <ss-chat-reply-markdown v-if="reply.type == 'text'" :chat-id="reply.chatId" :content="reply.content"
  65. :title="reply.title" :last="last" />
  66. <ss-chat-reply-category v-else-if="reply.type == 'category'" :category-id="reply.content"
  67. @quick-send="quickSend" @change-chat="changeChat" />
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import SsChatReplyMarkdown from '@/components/ss_chat/child/SsChatReplyMarkdown.vue';
  74. import SsChatReplyCategory from '@/components/ss_chat/child/SsChatReplyCategory.vue';
  75. import { useGlobalStore } from '@/stores/global';
  76. export default {
  77. name: 'SsChatReply',
  78. components: {
  79. SsChatReplyMarkdown,
  80. SsChatReplyCategory
  81. },
  82. props: {
  83. reply: {
  84. type: Object,
  85. default: {
  86. chatId: '',
  87. avatar: '/images/robot-avatar.png',
  88. type: 'text',
  89. title: '',
  90. content: null
  91. },
  92. require: true
  93. },
  94. last: {
  95. type: Boolean,
  96. default: false
  97. }
  98. },
  99. data() {
  100. return {
  101. unfold: false,
  102. globalStore: useGlobalStore()
  103. }
  104. },
  105. computed: {
  106. showLoading() {
  107. return this.globalStore.chatLoading && this.reply.type === 'text' && !this.reply.content
  108. }
  109. },
  110. methods: {
  111. getLogoUrl(item) {
  112. // 兼容 logo_url 和 icon 两种字段名
  113. let url = item.logo_url || item.icon || '';
  114. if (url == '') {
  115. url = '/static/images/unlink.png';
  116. }
  117. return url;
  118. },
  119. toggleUnfold() {
  120. this.unfold = !this.unfold;
  121. },
  122. copyLink(url) {
  123. if (url) {
  124. uni.setClipboardData({
  125. data: url,
  126. success: () => {
  127. uni.showToast({
  128. title: '链接已复制',
  129. icon: 'none'
  130. });
  131. }
  132. });
  133. }
  134. },
  135. quickSend(msg) {
  136. this.$emit('quickSend', msg)
  137. },
  138. changeChat() {
  139. this.$emit('changeChat');
  140. }
  141. }
  142. };
  143. </script>
  144. <style scoped lang="scss">
  145. .ss-chat-reply {
  146. .quota {
  147. margin-bottom: 32rpx;
  148. .quota-intro {
  149. border-radius: 32rpx;
  150. .quota-small {
  151. display: inline-flex;
  152. align-items: center;
  153. border-radius: 32rpx;
  154. padding: 16rpx 32rpx;
  155. border: 1px solid #d5d6d8;
  156. .quota-title {
  157. color: #545764;
  158. font-size: 28rpx;
  159. line-height: 28rpx;
  160. margin-right: 16rpx;
  161. }
  162. .quota-brand {
  163. display: flex;
  164. padding-left: 26rpx;
  165. .quota-brand-logo {
  166. background-color: #ffffff;
  167. width: 32rpx;
  168. height: 32rpx;
  169. overflow: hidden;
  170. border-radius: 16rpx;
  171. margin-left: -12rpx;
  172. box-shadow: 0 0 8rpx 0 rgba(0, 0, 0, 0.25);
  173. }
  174. }
  175. }
  176. .quota-detail {
  177. display: none;
  178. }
  179. }
  180. &.unfold {
  181. .quota-intro {
  182. padding: 24rpx;
  183. border-radius: 16rpx;
  184. background-color: #f6f7fb;
  185. .quota-small {
  186. display: none;
  187. }
  188. .quota-detail {
  189. display: block;
  190. .source-scroll {
  191. width: 100%;
  192. white-space: nowrap;
  193. .source {
  194. display: inline-block;
  195. white-space: nowrap;
  196. padding-bottom: 16rpx;
  197. .source-item {
  198. display: inline-block;
  199. vertical-align: top;
  200. width: 400rpx;
  201. border: 1px solid #d5d6d8;
  202. border-radius: 16rpx;
  203. background-color: #ffffff;
  204. padding: 20rpx;
  205. margin-right: 16rpx;
  206. .source-title {
  207. color: #101333;
  208. font-size: 28rpx;
  209. line-height: 36rpx;
  210. font-weight: bold;
  211. margin-bottom: 16rpx;
  212. overflow: hidden;
  213. display: -webkit-box;
  214. -webkit-box-orient: vertical;
  215. -webkit-line-clamp: 2;
  216. text-overflow: ellipsis;
  217. white-space: normal;
  218. height: 72rpx;
  219. }
  220. .source-footer {
  221. display: flex;
  222. align-items: center;
  223. .source-brand {
  224. flex: 1;
  225. display: flex;
  226. align-items: center;
  227. overflow: hidden;
  228. .source-icon {
  229. width: 32rpx;
  230. height: 32rpx;
  231. border-radius: 16rpx;
  232. margin-right: 8rpx;
  233. flex-shrink: 0;
  234. }
  235. .source-summary {
  236. flex: 1;
  237. color: #545764;
  238. font-size: 24rpx;
  239. line-height: 32rpx;
  240. height: 64rpx;
  241. overflow: hidden;
  242. display: -webkit-box;
  243. -webkit-box-orient: vertical;
  244. -webkit-line-clamp: 2;
  245. text-overflow: ellipsis;
  246. white-space: normal;
  247. }
  248. }
  249. .source-number {
  250. color: #ffffff;
  251. font-size: 22rpx;
  252. font-weight: bold;
  253. text-align: center;
  254. background-color: #2943d6;
  255. width: 32rpx;
  256. height: 32rpx;
  257. line-height: 32rpx;
  258. border-radius: 16rpx;
  259. margin-left: 8rpx;
  260. flex-shrink: 0;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. .quota-line {
  267. display: flex;
  268. margin-bottom: 24rpx;
  269. .line-left {
  270. width: 40rpx;
  271. color: #2943d6;
  272. font-size: 28rpx;
  273. }
  274. .line-content {
  275. flex: 1;
  276. .line-title {
  277. color: #545764;
  278. font-size: 28rpx;
  279. line-height: 40rpx;
  280. margin-bottom: 16rpx;
  281. }
  282. .line-box.flex {
  283. display: flex;
  284. flex-wrap: wrap;
  285. .search-text {
  286. color: #545764;
  287. font-size: 26rpx;
  288. padding: 12rpx 24rpx;
  289. border-radius: 8rpx;
  290. background-color: #eaedfb;
  291. }
  292. }
  293. }
  294. .quota-close {
  295. width: 40rpx;
  296. color: #545764;
  297. font-size: 24rpx;
  298. text-align: center;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. }
  305. .reply-content {
  306. width: 100%;
  307. .typing-indicator {
  308. display: inline-flex;
  309. align-items: center;
  310. gap: 8rpx;
  311. padding: 16rpx 24rpx;
  312. background-color: #f5f5f5;
  313. border-radius: 24rpx;
  314. .dot {
  315. width: 12rpx;
  316. height: 12rpx;
  317. background-color: #2942D4;
  318. border-radius: 50%;
  319. animation: bounce 1.4s infinite ease-in-out both;
  320. &:nth-child(1) {
  321. animation-delay: -0.32s;
  322. }
  323. &:nth-child(2) {
  324. animation-delay: -0.16s;
  325. }
  326. &:nth-child(3) {
  327. animation-delay: 0s;
  328. }
  329. }
  330. }
  331. }
  332. @keyframes bounce {
  333. 0%,
  334. 80%,
  335. 100% {
  336. transform: translateY(0);
  337. opacity: 0.4;
  338. }
  339. 40% {
  340. transform: translateY(-10rpx);
  341. opacity: 1;
  342. }
  343. }
  344. }
  345. </style>