dialog.vue 22 KB

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