dialog.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <div class="page">
  3. <div class="back adfac" v-if="dialogList.length">
  4. <img src="@/assets/images/agent/arrow_left.png">
  5. <span @click="handleBack">返回</span>
  6. </div>
  7. <div class="box adffcacjc" v-if="dialogList.length===0">
  8. <img src="@/assets/images/agent/dialog_logo2.gif">
  9. <div class="title">Hi,我是AI团队教练助手~</div>
  10. <div class="tip">任何关于团队、分析报告、教练的问题,你都可以向我提问,可以为你提供全方位多角度的PREILL团队分析,我正在快速学习和进化中,有新功能时,我一定第一时间告诉你~ </div>
  11. <div class="items">
  12. <template v-if="!idx">
  13. <div class="item" :class="{'active':idx===1}" @click="handleChange(1)">
  14. <div class="i_top adfac">
  15. <img src="@/assets/images/agent/dialog_zndh.png">
  16. <span>智能对话</span>
  17. </div>
  18. <p>解答关于团队、分析报告、教练的问题</p>
  19. </div>
  20. <div class="item" :class="{'active':idx===2}" @click="handleChange(2)">
  21. <div class="i_top adfac">
  22. <img src="@/assets/images/agent/dialog_bgfx.png">
  23. <span>报告分析</span>
  24. </div>
  25. <p>智能解读报告,快速找到关键信息,提出教练重点</p>
  26. </div>
  27. <div class="item" :class="{'active':idx===3}" @click="handleChange(3)">
  28. <div class="i_top adfac">
  29. <img src="@/assets/images/agent/dialog_wdwd.png">
  30. <span>文档问答</span>
  31. </div>
  32. <p>提供全方位多角度的PREILL团队分析</p>
  33. </div>
  34. </template>
  35. </div>
  36. </div>
  37. <div class="dialog" v-else>
  38. <div class="list">
  39. <div class="l_item" v-for="(item,index) in dialogList" :key="index">
  40. <div class="li_pre my adfac" v-if="item.type===1">
  41. <div class="text">{{ item.question }}</div>
  42. <img class="img" src="@/assets/images/agent/dialog_avatar.png">
  43. </div>
  44. <div class="li_pre ai" v-else-if="item.type===2">
  45. <div class="adfac">
  46. <img class="img" src="@/assets/images/agent/dialog_logo3.png">
  47. <!-- <div class="text" v-if="item.answer">{{ item.answer }}</div> -->
  48. <div class="text" v-if="item.answer" v-html="sanitizeHtml(item.answer)"></div>
  49. <div class="text" v-else>
  50. <img src="@/assets/images/agent/dialog_loading.gif">
  51. <span>正在思考中</span>
  52. </div>
  53. </div>
  54. <div class="icons adfac" v-if="item.answer">
  55. <el-popover placement="bottom" trigger="hover" content="重新生成">
  56. <template #reference>
  57. <img alt="重新生成" :src="isSx?require('@/assets/images/agent/dialog_sx2.png'):require('@/assets/images/agent/dialog_sx1.png')" @click="handleSx(index)" class="f">
  58. </template>
  59. </el-popover>
  60. <el-popover placement="bottom" trigger="hover" content="复制">
  61. <template #reference>
  62. <img alt="复制" :src="isFz?require('@/assets/images/agent/dialog_fz2.png'):require('@/assets/images/agent/dialog_fz1.png')" @click="handleFz(index)">
  63. </template>
  64. </el-popover>
  65. <el-popover placement="bottom" trigger="hover" content="喜欢">
  66. <template #reference>
  67. <img alt="喜欢" :src="isDz?require('@/assets/images/agent/dialog_dz2.png'):require('@/assets/images/agent/dialog_dz1.png')" @click="handleDz">
  68. </template>
  69. </el-popover>
  70. <el-popover placement="bottom" trigger="hover" content="评论">
  71. <template #reference>
  72. <img alt="评论" :src="isPl?require('@/assets/images/agent/dialog_pl2.png'):require('@/assets/images/agent/dialog_pl1.png')" @click="handlePl">
  73. </template>
  74. </el-popover>
  75. </div>
  76. </div>
  77. <div class="li_pre ai adfac" v-else-if="item.type===3">
  78. <img class="img" src="@/assets/images/agent/dialog_logo3.png">
  79. <div class="text">
  80. <div class="title">报告分析</div>
  81. <div class="tip">智能解读报告,快速找到关键信息,提出教练重点</div>
  82. <div class="upload adfac">
  83. <img src="@/assets/images/agent/upload.png">
  84. <div class="span">上传报告</div>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="li_pre ai adfac" v-else-if="item.type===4">
  89. <img class="img" src="@/assets/images/agent/dialog_logo3.png">
  90. <div class="text">
  91. <div class="title">文档问答</div>
  92. <div class="tip">提供全方位多角度的PREILL团队分析</div>
  93. <div class="upload adfac">
  94. <img src="@/assets/images/agent/upload.png">
  95. <div class="span">上传文档</div>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. <div class="ask">
  103. <div class="a_top">
  104. <el-input type="textarea" :rows="3" :placeholder="placeholder" v-model="question" resize="none" @keyup.enter.native="handleQuestion"></el-input>
  105. </div>
  106. <div class="a_bottom adfacjb">
  107. <div class="ab_l adfac">
  108. <div class="abl_pre adfac" :class="{'active':isChzq}" @click="isChzq=!isChzq">
  109. <img src="@/assets/images/agent/think.png" v-if="!isChzq">
  110. <img src="@/assets/images/agent/think2.png" v-else>
  111. <span>创衡增强</span>
  112. </div>
  113. <div class="abl_pre adfac" :class="{'active':isLwss}" @click="isLwss=!isLwss">
  114. <img src="@/assets/images/agent/intenet.png" v-if="!isLwss">
  115. <img src="@/assets/images/agent/intenet2.png" v-else>
  116. <span>联网搜索</span>
  117. </div>
  118. <div class="abl_pre adfac" :class="{'active':isScwd}" @click="isScwd=!isScwd">
  119. <img src="@/assets/images/agent/upload.png" v-if="!isScwd">
  120. <img src="@/assets/images/agent/upload2.png" v-else>
  121. <span>上传文档</span>
  122. </div>
  123. </div>
  124. <div class="ab_r">
  125. <img src="@/assets/images/agent/input_hou.png" v-if="question" @click="handleQuestion" style="cursor: pointer;">
  126. <img src="@/assets/images/agent/input_qian.png" v-else style="cursor: not-allowed;">
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </template>
  132. <script setup name="">
  133. import Cookies from "js-cookie";
  134. import DOMPurify from 'dompurify';
  135. import { ref, getCurrentInstance } from 'vue'
  136. import useClipboard from 'vue-clipboard3';
  137. const { toClipboard } = useClipboard();
  138. const { proxy } = getCurrentInstance();
  139. const idx = ref('')
  140. const placeholder = ref('有什么问题,可以向我提问!')
  141. const question = ref('')
  142. const isChzq = ref(false)
  143. const isLwss = ref(false)
  144. const isScwd = ref(false)
  145. const isSx = ref(false)
  146. const isFz = ref(false)
  147. const isDz = ref(false)
  148. const isPl = ref(false)
  149. const dialogList = ref([])
  150. const currentTaskId = ref('');
  151. const handleBack = () => {
  152. dialogList.value = [];
  153. idx.value = '';
  154. proxy.$router.push('/agent-dialog');
  155. }
  156. const handleChange = (val) => {
  157. idx.value = val;
  158. dialogList.value = []
  159. if(val===1) placeholder.value = '有什么问题,可以向我提问!';
  160. else if(val===2){
  161. placeholder.value = '上传报告并输入问题提问';
  162. let obj = {type:3}
  163. dialogList.value.unshift(obj)
  164. }
  165. else if(val===3){
  166. placeholder.value = '上传文件并输入问题提问';
  167. let obj = {type:4}
  168. dialogList.value.unshift(obj)
  169. }
  170. }
  171. const handleQuestion = () => {
  172. if(question.value.trim()=='') return proxy.$message.warning('请输入问题');
  173. let obj1 = {
  174. question: question.value.trim(),
  175. type: 1
  176. }
  177. dialogList.value = [...dialogList.value,obj1]
  178. let obj2 = {
  179. answer: '',
  180. type: 2
  181. }
  182. dialogList.value = [...dialogList.value,obj2]
  183. startStream(question.value.trim());
  184. question.value = '';
  185. }
  186. const startStream = async (query) => {
  187. try {
  188. const response = await fetch(`${window.SITE_CONFIG['apiURL']}/core/chat/messages`, {//streamingMessage messages
  189. method: 'POST',
  190. headers: {
  191. 'token':Cookies.get('token') || '',
  192. 'Content-Type': 'application/json',
  193. // 'Accept': 'text/event-stream',
  194. },
  195. body: JSON.stringify({
  196. query
  197. })
  198. });
  199. if (!response.ok || !response.body) {
  200. throw new Error(`请求失败: ${response.status}`);
  201. }
  202. const reader = response.body.getReader();
  203. const decoder = new TextDecoder('utf-8');
  204. let buffer = ''; // 累积缓冲器
  205. while (true) {
  206. const { value, done } = await reader.read();
  207. if (done) break;
  208. buffer += decoder.decode(value, { stream: true });
  209. // console.log(buffer, 'buffer');
  210. const event = buffer;
  211. if (event.startsWith('data:')) {
  212. try {
  213. const jsonStr = event.replaceAll('data:', '');
  214. console.log(jsonStr, 'jsonStr');
  215. dialogList.value = [...dialogList.value].map((item, idx) => {
  216. if (idx === dialogList.value.length - 1) {
  217. return { ...item, answer: item.answer + (jsonStr || '') };
  218. }
  219. return item;
  220. });
  221. } catch (e) {
  222. console.error('SSE解析失败', e, '原始数据:', event);
  223. }
  224. }
  225. }
  226. } catch (err) {
  227. console.log(err,'err');
  228. }
  229. };
  230. const sanitizeHtml = (html) => {
  231. if (!html) return '';
  232. return DOMPurify.sanitize(html);
  233. }
  234. const handleSx = (index) => {
  235. // isSx.value = !isSx.value;
  236. dialogList.value[index].answer = '';
  237. let query = dialogList.value[index-1].question;
  238. startStream(query)
  239. }
  240. const handleFz = async (index) => {
  241. // isFz.value = !isFz.value;
  242. try {
  243. await toClipboard(dialogList.value[index].answer);
  244. proxy.$message.success('复制成功');
  245. } catch (e) {
  246. proxy.$message.error('复制失败');
  247. }
  248. }
  249. const handleDz = () => {
  250. isDz.value = !isDz.value;
  251. }
  252. const handlePl = () => {
  253. isPl.value = !isPl.value;
  254. }
  255. </script>
  256. <style scoped lang="scss">
  257. ::v-deep .el-textarea textarea{
  258. border: none !important;
  259. padding: 0 !important;
  260. }
  261. ::v-deep .el-popover{
  262. background:#000 !important;
  263. min-width: inherit !important;
  264. color: #FFFFFF !important;
  265. border-radius: 10px;
  266. padding: 10px !important;
  267. }
  268. ::v-deep .popper__arrow::after{
  269. border-bottom-color:#000 !important;
  270. }
  271. .page{
  272. width: 100%;
  273. padding: 40px 290px;
  274. box-sizing: border-box;
  275. position: relative;
  276. .back{
  277. position: absolute;
  278. left: 30px;
  279. top: 20px;
  280. cursor: pointer;
  281. img{
  282. width: 36px;
  283. height: 36px;
  284. }
  285. span{
  286. margin-left: 10px;
  287. font-family: PingFang-SC, PingFang-SC;
  288. font-weight: bold;
  289. font-size: 16px;
  290. color: #252525;
  291. line-height: 22px;
  292. }
  293. }
  294. .box{
  295. width: 100%;
  296. height: calc(100vh - 228px);
  297. &>img{
  298. width: 99px;
  299. height: 94px;
  300. }
  301. .title{
  302. font-family: PingFang-SC, PingFang-SC;
  303. font-weight: bold;
  304. font-size: 24px;
  305. color: #252525;
  306. line-height: 33px;
  307. text-align: center;
  308. margin-top: 30px;
  309. }
  310. .tip{
  311. max-width: 647px;
  312. font-family: PingFangSC, PingFang SC;
  313. font-weight: 400;
  314. font-size: 14px;
  315. color: #646464;
  316. line-height: 20px;
  317. text-align: center;
  318. margin-top: 16px;
  319. }
  320. .items{
  321. width: 700px;
  322. min-height: 124px;
  323. margin-top: 40px;
  324. display: flex;
  325. justify-content: space-between;
  326. .item{
  327. width: calc(100% / 3 - 13px);
  328. padding: 17px 16px;
  329. box-sizing: border-box;
  330. background: #FFFFFF;
  331. box-shadow: 0px 2px 12px 0px rgba(0,0,0,0.04);
  332. border-radius: 10px;
  333. cursor: pointer;
  334. &.active,&:hover{
  335. border: 1px solid #833478;
  336. padding: 16px 15px;
  337. }
  338. .i_top{
  339. img{
  340. width: 32px;
  341. height: 32px;
  342. }
  343. span{
  344. font-family: PingFang-SC, PingFang-SC;
  345. font-weight: bold;
  346. font-size: 16px;
  347. color: #252525;
  348. line-height: 22px;
  349. margin-left: 12px;
  350. }
  351. }
  352. p{
  353. font-family: PingFangSC, PingFang SC;
  354. font-weight: 400;
  355. font-size: 14px;
  356. color: #999999;
  357. line-height: 20px;
  358. margin-top: 18px;
  359. }
  360. }
  361. }
  362. }
  363. .dialog{
  364. width: 100%;
  365. height: calc(100vh - 228px);
  366. padding: 24px 0;
  367. position: relative;
  368. overflow-y: auto;
  369. .list{
  370. .l_item{
  371. margin-top: 36px;
  372. &:first-child{
  373. margin-top: 0;
  374. }
  375. .li_pre{
  376. .text{
  377. max-width: calc(100% - 60px);
  378. padding: 14px 16px;
  379. box-sizing: border-box;
  380. border-radius: 8px;
  381. font-family: PingFangSC, PingFang SC;
  382. font-weight: 400;
  383. font-size: 14px;
  384. line-height: 20px;
  385. .title{
  386. font-family: PingFang-SC, PingFang-SC;
  387. font-weight: bold;
  388. font-size: 16px;
  389. color: #393939;
  390. line-height: 16px;
  391. }
  392. .tip{
  393. font-family: PingFangSC, PingFang SC;
  394. font-weight: 400;
  395. font-size: 14px;
  396. color: #999999;
  397. line-height: 14px;
  398. margin-top: 16px;
  399. }
  400. .upload{
  401. width: 112px;
  402. background: #FFFFFF;
  403. border-radius: 18px;
  404. border: 1px solid #E5E7EB;
  405. margin-top: 24px;
  406. padding: 8px 12px;
  407. box-sizing: border-box;
  408. cursor: pointer;
  409. img{
  410. width: 14px;
  411. height: 14px;
  412. margin: 0;
  413. }
  414. .span{
  415. font-family: PingFangSC, PingFang SC;
  416. font-weight: 400;
  417. font-size: 14px;
  418. color: #252525;
  419. line-height: 20px;
  420. margin-left: 11px;
  421. }
  422. }
  423. }
  424. .icons{
  425. width: 216px;
  426. margin-top: 16px;
  427. margin-left: 60px;
  428. padding: 10px 20px 10px 0;
  429. background: #FFFFFF;
  430. border-radius: 8px;
  431. border: 1px solid #EFEFEF;
  432. img{
  433. width: 24px;
  434. height: 24px;
  435. margin: 0;
  436. margin-left: 20px;
  437. cursor: pointer;
  438. &.f{
  439. width: 44px;
  440. padding-right: 20px;
  441. border-right: 1px solid #E5E7EB;
  442. }
  443. }
  444. .line{
  445. width: 1px;
  446. height: 20px;
  447. background: #E5E7EB;
  448. }
  449. }
  450. .img{
  451. width: 36px;
  452. height: 36px;
  453. }
  454. &.my{
  455. justify-content: flex-end;
  456. .text{
  457. border: 1px solid #833478;
  458. background: #833478;
  459. color: #FFFFFF;
  460. }
  461. .img{
  462. margin-left: 24px;
  463. }
  464. }
  465. &.ai{
  466. .text{
  467. border: 1px solid #EFEFEF;
  468. background: #FFFFFF;
  469. color: #393939;
  470. &>img{
  471. width: 24px;
  472. height: 24px;
  473. }
  474. span{
  475. font-family: PingFang-SC, PingFang-SC;
  476. font-weight: bold;
  477. font-size: 14px;
  478. color: #393939;
  479. line-height: 20px;
  480. margin-left: 5px;
  481. }
  482. }
  483. .img{
  484. width: 42px;
  485. margin-right: 18px;
  486. }
  487. }
  488. }
  489. }
  490. }
  491. }
  492. .ask{
  493. width: 100%;
  494. height: 148px;
  495. background: #FFFFFF;
  496. box-shadow: 0px 2px 12px 0px rgba(0,0,0,0.04);
  497. border-radius: 16px;
  498. padding: 20px 24px;
  499. box-sizing: border-box;
  500. display: flex;
  501. flex-direction: column;
  502. position: relative;
  503. .a_top{
  504. flex: 1;
  505. padding-bottom: 10px;
  506. }
  507. .a_bottom{
  508. .ab_l{
  509. .abl_pre{
  510. background: #FFFFFF;
  511. border-radius: 18px;
  512. border: 1px solid #E0E0E0;
  513. padding: 10px 13px;
  514. margin-left: 16px;
  515. cursor: pointer;
  516. &:first-child{
  517. margin-left: 0;
  518. }
  519. img{
  520. width: 16px;
  521. height: 16px;
  522. }
  523. span{
  524. font-family: PingFangSC, PingFang SC;
  525. font-weight: 400;
  526. font-size: 15px;
  527. color: #393939;
  528. line-height: 15px;
  529. margin-left: 7px;
  530. }
  531. &.active{
  532. background: rgba(118,30,106,0.06);
  533. span{
  534. color: #761E6A;
  535. }
  536. }
  537. }
  538. }
  539. .ab_r{
  540. img{
  541. width: 32px;
  542. height: 32px;
  543. border-radius: 7px;
  544. }
  545. }
  546. }
  547. }
  548. }
  549. </style>