Home.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <template>
  2. <div id="app">
  3. <Slider @select-nav="selectNav" :navId="navId" v-show="!closeOthers"></Slider>
  4. <div class="main">
  5. <div :class="{ 'history-wrap': true, 'history-wrap-open': !closeOthers && navId > -1 }">
  6. <History
  7. :list="historyList"
  8. :selectId="selectId"
  9. @handle-click="selectHistory"
  10. @set-new="handelSetNewChat"
  11. />
  12. </div>
  13. <div class="wrap">
  14. <Index :number="swiperNumber" v-if="navId === -1" @select-nav="selectNav" />
  15. <div :class="{ 'border-wrap': true, 'border-no-wrap': navId === -2 }" v-else>
  16. <div>
  17. <header v-if="!showDialog">
  18. <div>
  19. <img src="@/assets/other/robot.gif" width="52" />
  20. <p>
  21. {{ SYSTEM_NAME }}<span>{{ slider.find(item => item.id === navId).title }}</span>
  22. </p>
  23. <span>{{ slider.find(item => item.id === navId).dialog }}</span>
  24. </div>
  25. </header>
  26. <section :class="{ 'section-padding': showDialog }">
  27. <!-- 报告生成 -->
  28. <DocumentCombine v-if="navId == 0 && !showDialog" />
  29. <!-- 报表合并 -->
  30. <Document v-if="navId === 1 && !showDialog" />
  31. <!-- 知识问答 -->
  32. <DocumentInterlocution v-if="navId === 2 && !showDialog" />
  33. <!-- 文档智能 -->
  34. <DocumentAnswer v-if="navId === 3 && !showDialog" :agentId="selectId" />
  35. <!-- 智能问答 -->
  36. <Answer v-if="navId === 4 && !showDialog" />
  37. <!-- 智能数据 -->
  38. <DocumentsmartData v-if="navId === 5 && !showDialog" :agentId="selectId" />
  39. <!-- 小数绘图 -->
  40. <!-- <PicArticle v-if="navId === 6 && !showDialog" :agentId="selectId" /> -->
  41. <PicArticle v-if="navId === 6 && !showDialog" :agentId="selectId" />
  42. <!-- 文档出卷 -->
  43. <DocumentQuestion v-if="navId === 7 && !showDialog" :agentId="selectId" />
  44. <DocumentQuestion2 v-if="navId === 8 && !showDialog" :agentId="selectId" />
  45. <!-- 文库详情 -->
  46. <DocumentDetail v-if="navId === -2" @go-back="goBack" />
  47. <dialog-wrap
  48. v-if="showDialog && initDialog"
  49. v-show="!hideDialog"
  50. :type="dialogType[navId]"
  51. :isSetting="false"
  52. :readonly="readonly"
  53. :agentId="selectId"
  54. :dialogId="dialogId"
  55. :list="dialogList"
  56. @setReadonly="setReadonly"
  57. @changeParse="changeParse"
  58. @goDocument="goDocument"
  59. />
  60. </section>
  61. <footer v-if="navId !== -2 && navId !== 0 && navId !== 3 && navId !== 6 && !historyMode">
  62. <BtnIframeChujuan v-if="navId==7"/>
  63. <message-input :readonly="readonly" eventName="open-dialog" />
  64. </footer>
  65. <footer v-if="navId === 0 && !showDialog" class="upload-footer">
  66. <section v-for="(item, key) in variables" :key="key">
  67. <div>
  68. <p>
  69. <span>{{ item.variable_name }}</span>
  70. </p>
  71. </div>
  72. <div>
  73. <a-input :style="{ flex: '1' }" :placeholder="`请输入${item.variable_name}`" allow-clear @change="(event) => {
  74. customChange(event, item.node_id, item.variable_name);
  75. }
  76. " v-if="item.value_type === 1" />
  77. <a-upload v-else :style="{ width: '300px' }" :multiple="false" :limit="1" :custom-request="(option) => {
  78. customRequest(option, item.node_id, item.variable_name);
  79. }
  80. " :show-upload-button="{ showOnExceedLimit: true }" accept=".pdf,.doc,.docx,.txt,.md,.ppt.pptx" />
  81. </div>
  82. </section>
  83. <a-textarea :max-length="maxLength" v-model="textValue"
  84. :show-word-limit="textValue.length > maxLength / 2" :auto-size="{ maxRows: 6 }"
  85. placeholder="输入您想了解的内容,Shift+Enter换行" :style="{
  86. flex: 1,
  87. borderRadius: '12px',
  88. marginTop: '20px',
  89. padding: '0px 30px 0 16px',
  90. background: 'transparent',
  91. border: '1px solid #e3e3e3',
  92. minHeight: '120px',
  93. paddingBottom: `${textValue.length > maxLength / 2 ? '20px' : ''}`
  94. }">
  95. </a-textarea>
  96. <a-button :style="{ width: '500px' }" type="primary" @click="beginCombine">开始</a-button>
  97. </footer>
  98. <footer v-if="navId === 3 && !showDialog" class="upload-footer">
  99. <section v-for="(item, key) in variables" :key="key">
  100. <div>
  101. <p>
  102. <span>{{ item.variable_name }}</span>
  103. </p>
  104. </div>
  105. <div>
  106. <a-input :style="{ flex: '1' }" :placeholder="`请输入${item.variable_name}`" allow-clear @change="(event) => {
  107. customChange(event, item.node_id, item.variable_name);
  108. }
  109. " v-if="item.value_type === 1" />
  110. <a-upload v-else :style="{ width: '300px' }" :multiple="false" :limit="1" :custom-request="(option) => {
  111. customRequest(option, item.node_id, item.variable_name);
  112. }
  113. " :show-upload-button="{ showOnExceedLimit: true }" accept=".pdf,.doc,.docx,.txt,.md,.ppt.pptx" />
  114. </div>
  115. </section>
  116. <a-button :style="{ width: '500px' }" type="primary" @click="beginCombine">开始</a-button>
  117. </footer>
  118. <footer v-if="navId === 3 && showDialog && !historyMode" class="upload-footer">
  119. <a-textarea :max-length="maxLength" v-model="textValue" :disabled="parseStatus"
  120. :show-word-limit="textValue.length > maxLength / 2" :auto-size="{ maxRows: 6 }"
  121. placeholder="输入您想了解的内容,Shift+Enter换行" :style="{
  122. flex: 1,
  123. borderRadius: '12px',
  124. marginTop: '20px',
  125. padding: '0px 30px 0 16px',
  126. background: 'transparent',
  127. border: '1px solid #e3e3e3',
  128. minHeight: '120px',
  129. paddingBottom: `${textValue.length > maxLength / 2 ? '20px' : ''}`
  130. }">
  131. </a-textarea>
  132. <a-button :style="{ width: '500px' }" type="primary" @click="continueCombine">开始</a-button>
  133. </footer>
  134. <!-- <footer v-if="navId === 6 && !historyMode">
  135. <picture-cards />
  136. <MessagePicUpload />
  137. </footer> -->
  138. <PictureFooter v-if="navId === 6 && !historyMode" :agentId="selectId"/>
  139. <!-- <a-tooltip :content="closeOthers ? '收起' : '展开'">
  140. <div @click="openAll" v-if="navId !== -2">
  141. <img src="@/assets/other/open.svg" width="20" v-if="closeOthers" />
  142. <img src="@/assets/other/close.svg" width="20" v-else />
  143. </div>
  144. </a-tooltip> -->
  145. <ToggleBtn v-if="navId !== -2" :closeOthers="closeOthers" @toggle="openAll"/>
  146. </div>
  147. </div>
  148. </div>
  149. <!-- <right v-if="navId === 0 || navId === 2" /> -->
  150. </div>
  151. </div>
  152. </template>
  153. <script>
  154. import Right from "../components/Right.vue";
  155. import DialogWrap from "../components/DialogWrap.vue";
  156. import Slider from "../components/Slider.vue";
  157. import History from "../components/History.vue";
  158. import MessageInput from "../components/MessageInput.vue";
  159. import PictureCards from '@/components/PictureCards.vue'
  160. import MessagePicUpload from '../components/MessagePicUpload.vue'
  161. import PictureFooter from '../components/PictureFooter.vue';
  162. import DocumentDetail from "./DocumentDetail.vue";
  163. import DocumentCombine from "./DocumentCombine.vue";
  164. import Index from "./Index.vue";
  165. import Answer from "./Answer.vue";
  166. import Document from "./Document.vue";
  167. import PicArticle from "./PicArticle.vue";
  168. import DocumentAnswer from "./DocumentAnswer.vue";
  169. import DocumentsmartData from "./DocumentsmartData.vue";
  170. import DocumentInterlocution from './DocumentInterlocution.vue';
  171. import DocumentQuestion from "./DocumentQuestion.vue";
  172. import DocumentQuestion2 from "./DocumentQuestion2.vue";
  173. import Analysis from "./Analysis.vue";
  174. import ToggleBtn from '../components/ToggleBtn.vue';
  175. import BtnIframeChujuan from '../components/btn-iframe-chujuan/BtnIframeChujuan.vue'
  176. import { defineComponent, ref, onMounted, inject, onBeforeUnmount } from "vue";
  177. export default defineComponent({
  178. components: {
  179. Right,
  180. Slider,
  181. History,
  182. Index,
  183. Answer,
  184. MessageInput,
  185. PictureCards,
  186. MessagePicUpload,
  187. PictureFooter,
  188. DialogWrap,
  189. Document,
  190. PicArticle,
  191. DocumentAnswer,
  192. DocumentsmartData,
  193. DocumentInterlocution,
  194. DocumentQuestion,
  195. DocumentQuestion2,
  196. Analysis,
  197. DocumentDetail,
  198. DocumentCombine,
  199. ToggleBtn,
  200. BtnIframeChujuan // 文档出卷按钮
  201. },
  202. setup() {
  203. // NOTE: 先把4文库问答的类型改成report类型,后续再改回来
  204. const dialogType = [
  205. "report",
  206. "excel",
  207. "knowledgeQuiz",
  208. "report",
  209. "normal",
  210. "smartData",
  211. "huitu", // 小数绘图
  212. "question",
  213. "question"
  214. ];
  215. const { config, helper, ajax } = inject("$global");
  216. const SYSTEM_NAME = config.defaultTitle
  217. const closeOthers = ref(false);
  218. const swiperNumber = ref(5);
  219. const navId = ref(-1);
  220. const readonly = ref(false);
  221. const showDialog = ref(false); // 是否显示对话内容 v-if
  222. const initDialog = ref(false); // 对话是否初始化
  223. const hideDialog = ref(false); // 是否隐藏对话 v-show
  224. const historyMode = ref(false);
  225. const dialogList = ref([]);
  226. const selectId = ref("");
  227. const agentIds = ref([]);
  228. const dialogId = ref("");
  229. const historyList = ref([]);
  230. const variables = ref([]);
  231. const textValue = ref("");
  232. const parseStatus = ref(false);
  233. const maxLength = ref(6000);
  234. let reportData = {};
  235. let agents = {}
  236. const openAll = () => {
  237. closeOthers.value = !closeOthers.value;
  238. };
  239. const setReadonly = (status) => {
  240. readonly.value = status;
  241. };
  242. const changeParse = (status) => {
  243. parseStatus.value = status;
  244. }
  245. const goDocument = () => {
  246. navId.value = -2;
  247. hideDialog.value = true;
  248. };
  249. const goBack = () => {
  250. navId.value = 0;
  251. hideDialog.value = false;
  252. };
  253. /**
  254. * 当点击某个导航时触发的方法
  255. * 例如:点击 知识问答 文档智能 智能问答 智能数据 等
  256. * @params {object} node
  257. * @params {number} node.id - 例如 3 4 5
  258. * @params {string} node.title - 例如:文档智能 小数绘图
  259. */
  260. const selectNav = async (node) => {
  261. navId.value = node.id;
  262. textValue.value = [];
  263. // 关闭历史模式
  264. historyMode.value = false;
  265. readonly.value = false;
  266. if (node.index === -1) {
  267. swiperNumber.value = 5;
  268. } else {
  269. swiperNumber.value = 4;
  270. }
  271. helper.$bus.emit("stop-writing");
  272. showDialog.value = false;
  273. // 获取当前选定的agent对应的ID
  274. selectId.value = (agents.find(agent => agent.name === node.title) || {}).id || null;
  275. // 获取历史记录
  276. const data = await ajax.message.getDialogs(selectId.value);
  277. if (navId.value === 0 || navId.value === 3) {
  278. const result = await ajax.agent.getVariables(selectId.value);
  279. variables.value = result;
  280. reportData = {};
  281. }
  282. if (data && Array.isArray(data)) {
  283. historyList.value = data.map((value) => {
  284. return {
  285. content: value.name,
  286. id: value.id,
  287. time: value.update_date
  288. };
  289. });
  290. }
  291. // 每次切换功能板块时,清空sendData数据
  292. // helper.write('sendData', {});
  293. clearLocalStorageSendData();
  294. };
  295. /**
  296. * 选择某个历史记录
  297. * @params {string} id - 历史记录对应的ID
  298. */
  299. const selectHistory = async (id) => {
  300. showDialog.value = true;
  301. // 历史记录对话模式,不调用对话ID接口
  302. historyMode.value = true;
  303. readonly.value = true;
  304. selectId.value = id;
  305. helper.$bus.emit("set-loading", true);
  306. helper.$bus.emit("stop-writing");
  307. initDialog.value = false;
  308. // 历史记录 通过当前name取id
  309. const name = config.slider.find(item => item.id === navId.value).title
  310. const agentsId = agents.find(agent => agent.name === name).id;
  311. const data = await ajax.message.getHistoryLogs(agentsId, id);
  312. if (data && Array.isArray(data) && data.length > 0) {
  313. dialogList.value = data
  314. } else {
  315. dialogList.value = []
  316. }
  317. initDialog.value = true;
  318. helper.$bus.emit("set-loading", false);
  319. };
  320. const beginCombine = async () => {
  321. let report_name = "";
  322. let inputData = [];
  323. for (let key in reportData) {
  324. /**
  325. * 此部分代码于 2024/11/25日上午做了简单优化
  326. * 优化时,仅调整了循环体内的代码
  327. * 由于此功能暂时禁用,无法测试优化后的效果是否正常
  328. * 如果后续测试时发现代码异常,可copy此时间之前的原代码
  329. */
  330. const cur_report = reportData[key];
  331. const report_key = cur_report.key;
  332. const report_value = cur_report.value;
  333. const item = {
  334. id: key,
  335. name: report_key,
  336. };
  337. if (typeof report_value === "string") {
  338. report_name += `${report_key}:${report_value}\n`;
  339. item.file_path = '';
  340. item.value = report_value;
  341. } else {
  342. report_name += `${report_key}:${report_value.name}\n`;
  343. item.file_path = report_value.url;
  344. item.value = '';
  345. }
  346. inputData.push(item);
  347. }
  348. // 如果不是历史记录对话模式,则创建对话
  349. if (!historyMode.value) {
  350. const data = await ajax.message.createDialog(selectId.value);
  351. if (data) {
  352. dialogId.value = data.chat_id;
  353. }
  354. }
  355. dialogList.value = [];
  356. showDialog.value = true;
  357. initDialog.value = true;
  358. const sendData = {
  359. chatHistory: [],
  360. message: textValue.value,
  361. name: "报告生成",
  362. description: "报告生成",
  363. inputs: {
  364. report_name,
  365. id: "Report-PRcYL",
  366. data: inputData
  367. }
  368. };
  369. setTimeout(() => {
  370. helper.$bus.emit("send-message", sendData);
  371. }, 500);
  372. };
  373. const continueCombine = async () => {
  374. const sendData = {
  375. chatHistory: [],
  376. name: "报告生成",
  377. description: "报告生成",
  378. inputs: {
  379. report_name: textValue.value,
  380. id: "Report-PRcYL",
  381. query: textValue.value,
  382. }
  383. };
  384. setTimeout(() => {
  385. helper.$bus.emit("send-message", sendData);
  386. textValue.value = "";
  387. }, 500);
  388. };
  389. const customChange = (event, key, value) => {
  390. reportData[key] = {
  391. key: value,
  392. value: event
  393. };
  394. };
  395. const customRequest = async (option, key, value) => {
  396. const { onSuccess, fileItem } = option;
  397. const { file, uid, name } = fileItem;
  398. const fileList = [];
  399. fileList.push({
  400. id: uid,
  401. file
  402. });
  403. onSuccess();
  404. const formData = new FormData();
  405. fileList.forEach((item) => {
  406. formData.append("file", item.file);
  407. });
  408. const data = await ajax.file.uploadFiles(selectId.value, formData);
  409. reportData[key] = {
  410. key: value,
  411. value: {
  412. name,
  413. url: data.file_path
  414. }
  415. };
  416. };
  417. onMounted(async () => {
  418. agents = await ajax.agent.getAgents();
  419. agentIds.value = agents && Array.isArray(agents) && agents.map((data) => data.id) || [];
  420. helper.$bus.on("open-dialog", async (value) => {
  421. // 如果不是历史记录对话模式,则创建对话
  422. if (!historyMode.value) {
  423. const data = await ajax.message.createDialog(selectId.value);
  424. dialogId.value = data.chat_id;
  425. }
  426. dialogList.value = [];
  427. showDialog.value = true;
  428. initDialog.value = true;
  429. // TODO
  430. setTimeout(() => {
  431. helper.$bus.emit("send-message", value);
  432. }, 200);
  433. });
  434. });
  435. onBeforeUnmount(() => {
  436. helper.$bus.off("open-dialog");
  437. });
  438. /**
  439. * 点击新建对话按钮
  440. */
  441. const handelSetNewChat = () => {
  442. showDialog.value = false;
  443. // selectId = selectId;
  444. historyMode.value = false;
  445. setReadonly(false);
  446. // 每次新建对话时,清空sendData数据
  447. // helper.write('sendData', {});
  448. clearLocalStorageSendData();
  449. };
  450. function clearLocalStorageSendData(){
  451. // helper.write('sendData', {});
  452. }
  453. return {
  454. SYSTEM_NAME,
  455. customChange,
  456. customRequest,
  457. historyList,
  458. beginCombine,
  459. continueCombine,
  460. selectId,
  461. dialogId,
  462. navId,
  463. variables,
  464. selectNav,
  465. swiperNumber,
  466. slider: config.slider,
  467. readonly,
  468. setReadonly,
  469. showDialog,
  470. selectHistory,
  471. historyMode,
  472. closeOthers,
  473. openAll,
  474. dialogType,
  475. dialogList,
  476. initDialog,
  477. goDocument,
  478. goBack,
  479. changeParse,
  480. hideDialog,
  481. agentIds,
  482. textValue,
  483. parseStatus,
  484. maxLength,
  485. handelSetNewChat
  486. };
  487. }
  488. });
  489. </script>
  490. <style lang="scss" scoped>
  491. .main {
  492. .upload-footer {
  493. margin-bottom: 50px;
  494. padding: 20px;
  495. width: 540px;
  496. border: 1px solid #eee;
  497. >section {
  498. >div {
  499. display: flex;
  500. align-items: center;
  501. justify-content: space-between;
  502. width: 500px;
  503. >p {
  504. width: 150px;
  505. margin-right: 10px;
  506. }
  507. }
  508. p {
  509. span {
  510. position: relative;
  511. &:after {
  512. content: "*";
  513. display: block;
  514. color: red;
  515. position: absolute;
  516. right: -10px;
  517. top: -5px;
  518. }
  519. }
  520. }
  521. >p,
  522. >div {
  523. margin: 10px 0;
  524. }
  525. }
  526. }
  527. flex: 1;
  528. position: relative;
  529. display: flex;
  530. .history-wrap {
  531. width: 0px;
  532. opacity: 0;
  533. overflow: hidden;
  534. transition-duration: 0.3s;
  535. transition-property: width;
  536. &-open {
  537. opacity: 1;
  538. width: 260px;
  539. }
  540. }
  541. .wrap {
  542. flex: 1;
  543. }
  544. .border-wrap {
  545. position: relative;
  546. padding: 30px 16px 30px 40px;
  547. flex: 1;
  548. height: 100%;
  549. &.border-no-wrap {
  550. padding: 0;
  551. >div {
  552. padding: 0;
  553. >section.section-padding {
  554. padding: 0;
  555. }
  556. }
  557. }
  558. >div {
  559. width: 100%;
  560. height: 100%;
  561. background: #fff;
  562. box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.03);
  563. border-radius: 14px;
  564. display: flex;
  565. flex-direction: column;
  566. padding-left: 32px;
  567. position: relative;
  568. >div {
  569. position: absolute;
  570. bottom: -10px;
  571. left: -10px;
  572. z-index: 10;
  573. width: 38px;
  574. height: 38px;
  575. border-radius: 20px;
  576. background: #fff;
  577. display: flex;
  578. align-items: center;
  579. justify-content: center;
  580. cursor: pointer;
  581. }
  582. >header {
  583. >div {
  584. display: inline-block;
  585. margin-top: 20px;
  586. >img {
  587. transform: translateX(-12px);
  588. }
  589. >p {
  590. font-size: 36px;
  591. font-weight: bold;
  592. color: #000;
  593. >span {
  594. font-weight: bold;
  595. background: linear-gradient(180deg, #41d98c, #31c4c9);
  596. -webkit-background-clip: text;
  597. -webkit-text-fill-color: transparent;
  598. }
  599. }
  600. >span {
  601. display: block;
  602. color: #000;
  603. font-size: 15px;
  604. margin: 5px 0 32px;
  605. }
  606. }
  607. }
  608. >section {
  609. flex: 1;
  610. overflow: hidden;
  611. &.section-padding {
  612. padding-right: 32px;
  613. padding-bottom: 50px;
  614. }
  615. }
  616. >footer {}
  617. }
  618. }
  619. }
  620. </style>