DocumentCards.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <main>
  3. <section>
  4. <div v-for="(item, key) in data" :key="key" :style="{ background: item.background }">
  5. <img :src="getAssetURL(item.img)" />
  6. <div :style="{ color: item.color }">
  7. {{ item.title }}
  8. <span>{{ item.content }}</span>
  9. </div>
  10. </div>
  11. </section>
  12. <footer v-if="hasUpload">
  13. <a-popover :popup-visible="showUpload" position="tl" @popup-visible-change="() => {
  14. showDeleteTooltip = false;
  15. }
  16. ">
  17. <div :class="{ 'text-hide': showUpload }">
  18. <div @click="() => {
  19. showUpload = true;
  20. }
  21. ">
  22. <img src="@/assets/document/3.svg" class="img-normal" v-if="!showUpload" />
  23. <img src="@/assets/document/4.svg" class="img-hover" v-if="!showUpload" />
  24. <img src="@/assets/document/5.svg" class="img-active" v-if="showUpload" />
  25. </div>
  26. <p>已选择 {{ fileList.length }} 个文档</p>
  27. </div>
  28. <template #content>
  29. <div :class="{ 'upload-wrap': true, 'upload-wrap-narrow': uploadFile }">
  30. <header>
  31. <p>{{ uploadFile ? "上传文档" : "文档解析站" }}</p>
  32. <div @click="() => {
  33. showUpload = false;
  34. }
  35. ">
  36. <icon-close size="large" />
  37. </div>
  38. </header>
  39. <div>
  40. <section v-if="agengtName == '智能数据'">
  41. <a-upload draggable :multiple="!uploadFile" :limit="50" :show-file-list="false"
  42. @before-upload="onBeforeUpload" @exceed-limit="onExceedLimit" @before-remove="onBeforeRemove"
  43. :custom-request="customRequest" :show-upload-button="{ showOnExceedLimit: true }"
  44. accept=".xls,.xlsx,.csv,.db">
  45. <template #upload-button>
  46. <div class="upload-main">
  47. <p>拖拽文档到这里,或<span>点此上传</span></p>
  48. <span>
  49. 支持上传 Excel (.xls, .xlsx),CSV (.csv),DB (.db),大小不超过30M
  50. </span>
  51. </div>
  52. </template>
  53. </a-upload>
  54. </section>
  55. <section v-else>
  56. <a-upload draggable :multiple="!uploadFile" :limit="50" :show-file-list="false"
  57. @before-upload="onBeforeUpload" @exceed-limit="onExceedLimit" @before-remove="onBeforeRemove"
  58. :custom-request="customRequest" :show-upload-button="{ showOnExceedLimit: true }" accept="*">
  59. <template #upload-button>
  60. <div class="upload-main">
  61. <p>拖拽文档到这里,或<span>点此上传</span></p>
  62. <span>
  63. 支持上传{{ uploadFile ? ".txt,.pdf" : ".xlsx‌文档" }},大小不超过30M
  64. </span>
  65. </div>
  66. </template>
  67. </a-upload>
  68. </section>
  69. <div v-if="tableData.length > 0">
  70. <p>
  71. <span>已解析文件列表</span>
  72. <span>共{{ tableData.length }}个</span>
  73. </p>
  74. <div>
  75. <a-table :pagination="false" row-key="name" :columns="columns" :data="tableData"
  76. :row-selection="rowSelection" v-model:selectedKeys="selectedKeys">
  77. <template #methods="{ record }">
  78. <a-tooltip content="下载">
  79. <div class="method-button" @click="downloadDocument(record)">
  80. <icon-cloud-download />
  81. </div>
  82. </a-tooltip>
  83. <a-popover :popup-visible="showDeleteTooltip && deleteId === record.key">
  84. <a-tooltip content="删除">
  85. <div class="method-button" @click="handleDeleteButton(record.key)">
  86. <icon-delete />
  87. </div>
  88. </a-tooltip>
  89. <template #content>
  90. <div>
  91. <p>删除后无法恢复,您是否删除?</p>
  92. <div class="delete-buttons">
  93. <div>
  94. <a-button size="mini" type="primary" style="margin-right: 10px"
  95. @click="deleteDocument">确认</a-button>
  96. <a-button size="mini" type="outline" @click="() => {
  97. showDeleteTooltip = false;
  98. }
  99. ">取消</a-button>
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. </a-popover>
  105. </template>
  106. </a-table>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <div class="bottom-buttons">
  112. <div>
  113. <a-button type="outline" style="margin-right: 10px" @click="selectFiles(false)">取消</a-button>
  114. <a-button :loading="buttonLoading" type="primary" @click="selectFiles(true, 'paper')">去{{
  115. uploadFile ? '提问'
  116. : '合并'
  117. }}({{ fileList.length
  118. }})</a-button>
  119. </div>
  120. </div>
  121. </template>
  122. </a-popover>
  123. <!-- <section v-if="hasSlider">
  124. <p>出题随机性</p>
  125. <a-slider :default-value="50" :style="{ width: '100px' }" />
  126. </section> -->
  127. </footer>
  128. </main>
  129. </template>
  130. <script>
  131. import dayjs from "dayjs";
  132. import { defineComponent, ref, inject, reactive } from "vue";
  133. export default defineComponent({
  134. props: ["data", "hasUpload", "hasSlider", "uploadFile", "isQuestion", "agentId", "agengtName"],
  135. setup(props) {
  136. const showUpload = ref(false);
  137. const { helper, ajax } = inject("$global");
  138. const maxSize = 30 * 1024 * 1024;
  139. let fileList = ref([]);
  140. const tableData = reactive([]);
  141. let formData = new FormData();
  142. let inputData = ref([]);
  143. const showDeleteTooltip = ref(false);
  144. const deleteId = ref("");
  145. const buttonLoading = ref(false);
  146. const selectFiles = async (isSelect, type) => {
  147. if (isSelect) {
  148. if (props.uploadFile) {
  149. const data = await ajax.message.createDialog(props.agentId);
  150. fileList.value.forEach(file => {
  151. formData.append('file', file)
  152. });
  153. buttonLoading.value = true;
  154. const result = await ajax.file.uploadFile(props.agentId, data.chat_id, formData);
  155. showUpload.value = false;
  156. helper.dialogConfig = {
  157. isQuestion: props.isQuestion,
  158. selectedKeys: selectedKeys.value,
  159. type
  160. };
  161. buttonLoading.value = false;
  162. // if (result) {
  163. // helper.write('docId', result.doc_ids[0]);
  164. // }
  165. // 以下为判断是毕生还是regflow
  166. // TODO 判断是毕生还是regflow
  167. // 以下为毕生
  168. inputData.value.push({
  169. name: result.file_name,
  170. file_path: result.file_path,
  171. value: ""
  172. });
  173. const sendData = {
  174. chatHistory: [],
  175. chat_id: data.chat_id,
  176. agent_id: props.agentId,
  177. name: "文档智能",
  178. description: "文档智能",
  179. inputs: {
  180. report_name: inputData.value.map(item => item.name).join(', '),
  181. id: "Report-PRcYL",
  182. data: inputData.value
  183. }
  184. };
  185. if (sendData) {
  186. helper.write('sendData', sendData);
  187. }
  188. } else {
  189. fileList.value.forEach(file => {
  190. formData.append('files', file)
  191. });
  192. await ajax.file.uploadExcels(formData);
  193. helper.$bus.emit("open-dialog", '合并Excel');
  194. }
  195. }
  196. };
  197. const handleDeleteButton = (id) => {
  198. showDeleteTooltip.value = true;
  199. deleteId.value = id;
  200. };
  201. const onBeforeUpload = (file) => {
  202. if (file.size > maxSize) {
  203. helper.message("error", `上传文件大小不能超过10M`);
  204. return false;
  205. }
  206. return true;
  207. };
  208. const onExceedLimit = () => {
  209. helper.message("error", `最多上传50个文件`);
  210. };
  211. const customRequest = async (option) => {
  212. const { onSuccess, fileItem } = option;
  213. const { file } = fileItem;
  214. fileList.value.push(file);
  215. tableData.push({
  216. key: file.uid,
  217. name: file.name,
  218. type: file.type,
  219. size: helper.formatSize(file.size),
  220. time: dayjs(file.lastModified).format("YYYY-MM-DD HH:mm:ss")
  221. });
  222. onSuccess();
  223. };
  224. const onBeforeRemove = (data) => {
  225. console.log('data', data)
  226. fileList.value = fileList.value.filter((item) => item.id !== data.uid);
  227. return true;
  228. };
  229. const selectedKeys = ref([]);
  230. const rowSelection = reactive({
  231. type: "checkbox",
  232. showCheckedAll: true,
  233. onlyCurrent: false
  234. });
  235. const columns = [
  236. {
  237. title: "文件名称",
  238. dataIndex: "name",
  239. ellipsis: true,
  240. tooltip: true,
  241. width: 150
  242. },
  243. {
  244. title: "类型",
  245. dataIndex: "type",
  246. ellipsis: true,
  247. tooltip: true,
  248. width: 150
  249. },
  250. {
  251. title: "大小",
  252. dataIndex: "size"
  253. },
  254. {
  255. title: "上传时间",
  256. dataIndex: "time",
  257. ellipsis: true,
  258. tooltip: true,
  259. width: 150
  260. },
  261. {
  262. title: "操作",
  263. slotName: "methods"
  264. }
  265. ];
  266. const downloadDocument = (record) => { };
  267. const deleteDocument = () => {
  268. const index = tableData.findIndex(item => item.key === deleteId.value);
  269. tableData.splice(index, 1);
  270. fileList.value = fileList.value.filter(item => item.uid !== deleteId.value);
  271. };
  272. return {
  273. agengtName: props.agengtName,
  274. buttonLoading,
  275. fileList,
  276. selectedKeys,
  277. getAssetURL: helper.getAssetURL,
  278. showUpload,
  279. onBeforeUpload,
  280. onExceedLimit,
  281. onBeforeRemove,
  282. customRequest,
  283. columns,
  284. tableData,
  285. rowSelection,
  286. downloadDocument,
  287. deleteDocument,
  288. showDeleteTooltip,
  289. deleteId,
  290. handleDeleteButton,
  291. selectFiles
  292. };
  293. }
  294. });
  295. </script>
  296. <style lang="scss" scoped>
  297. .bottom-buttons {
  298. display: flex;
  299. justify-content: right;
  300. >div {
  301. display: flex;
  302. }
  303. }
  304. .delete-buttons {
  305. margin-top: 10px;
  306. display: flex;
  307. justify-content: center;
  308. }
  309. .method-button {
  310. display: inline-block;
  311. padding: 4px 8px;
  312. border-radius: 5px;
  313. cursor: pointer;
  314. &:hover {
  315. background: rgba(150, 171, 185, 0.2);
  316. }
  317. }
  318. .upload-main {
  319. width: 800px;
  320. height: 109px;
  321. background: url("@/assets/document/upload.svg");
  322. margin: 0 auto;
  323. padding: 24px 0px 24px 277px;
  324. background-size: 100%;
  325. >p {
  326. color: #000;
  327. font-weight: bold;
  328. margin-bottom: 5px;
  329. margin-top: 10px;
  330. >span {
  331. color: #00aea3;
  332. text-decoration: underline;
  333. }
  334. }
  335. >span {
  336. font-size: 13px;
  337. color: #7f7f7f;
  338. }
  339. }
  340. main {
  341. height: 100%;
  342. display: flex;
  343. flex-direction: column;
  344. overflow: hidden;
  345. >section {
  346. overflow-y: auto;
  347. display: flex;
  348. flex-wrap: wrap;
  349. gap: 20px;
  350. &.section-full {
  351. flex: 1;
  352. }
  353. >div {
  354. width: 382px;
  355. height: 120px;
  356. padding: 20px 24px;
  357. border-radius: 8px;
  358. display: flex;
  359. >img {
  360. width: 38px;
  361. height: 38px;
  362. margin-right: 12px;
  363. }
  364. >div {
  365. font-size: 18px;
  366. font-weight: bold;
  367. >span {
  368. font-size: 15px;
  369. font-weight: 400;
  370. color: #797d7f;
  371. margin-top: 8px;
  372. overflow: hidden;
  373. text-overflow: ellipsis;
  374. display: -webkit-box;
  375. -webkit-line-clamp: 2;
  376. -webkit-box-orient: vertical;
  377. line-height: 1.4;
  378. }
  379. }
  380. }
  381. }
  382. >footer {
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. margin-top: auto;
  387. >div {
  388. display: inline-flex;
  389. align-items: center;
  390. gap: 8px;
  391. height: 32px;
  392. border-radius: 21px;
  393. border: 1px solid #e3e3e3;
  394. white-space: nowrap;
  395. overflow: hidden;
  396. transition-duration: 0.3s;
  397. width: 250px;
  398. &.text-hide {
  399. width: 110px;
  400. overflow: hidden;
  401. }
  402. &.text-narrow {
  403. width: 100px;
  404. overflow: hidden;
  405. >div>img {
  406. width: 100px;
  407. }
  408. }
  409. >p {
  410. overflow: hidden;
  411. white-space: nowrap;
  412. }
  413. >div {
  414. cursor: pointer;
  415. width: 110px;
  416. height: 32px;
  417. .img-normal {
  418. display: block;
  419. }
  420. .img-hover {
  421. display: none;
  422. }
  423. &:hover {
  424. .img-normal {
  425. display: none;
  426. }
  427. .img-hover {
  428. display: block;
  429. }
  430. }
  431. >img {
  432. width: 110px;
  433. height: 32px;
  434. }
  435. }
  436. }
  437. >section {
  438. display: flex;
  439. align-items: center;
  440. background: rgba(150, 171, 185, 0.2);
  441. border-radius: 20px;
  442. padding: 5px 10px;
  443. >p {
  444. margin-right: 5px;
  445. }
  446. }
  447. }
  448. }
  449. .upload-wrap {
  450. width: 800px;
  451. height: 300px;
  452. display: flex;
  453. flex-direction: column;
  454. padding-bottom: 30px;
  455. &.upload-wrap-narrow {
  456. height: auto;
  457. }
  458. >header {
  459. display: flex;
  460. align-items: center;
  461. justify-content: space-between;
  462. margin-bottom: 13px;
  463. >p {
  464. font-size: 18px;
  465. font-weight: bold;
  466. }
  467. >div {
  468. width: 38px;
  469. height: 38px;
  470. border-radius: 6px;
  471. cursor: pointer;
  472. justify-content: center;
  473. align-items: center;
  474. display: flex;
  475. &:hover {
  476. background: rgba(0, 0, 0, 0.05);
  477. }
  478. }
  479. }
  480. >div {
  481. flex: 1;
  482. overflow-y: auto;
  483. >div {
  484. >p {
  485. margin: 20px 0;
  486. color: #7f7f7f;
  487. font-size: 13px;
  488. display: flex;
  489. justify-content: space-between;
  490. }
  491. }
  492. }
  493. }
  494. </style>