dialog.vue 23 KB

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