index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <div class="bm-main-box">
  3. <div class="flex items-center">
  4. <div class="bm-main-box-title">文档</div>
  5. </div>
  6. <template v-if="!state.stage.show">
  7. <CzrContent
  8. v-model:tableHead="state.query.tableHead"
  9. @handleReset="onReset"
  10. @handleSearch="onSearch"
  11. v-model:full="state.query.isFull"
  12. >
  13. <template #tableTitle>
  14. <div class="flex gap-[var(--czr-gap)]">
  15. <CzrButton
  16. type="add"
  17. title="添加文件"
  18. @click="
  19. $router.push({
  20. name: '18e6009c-a72c-4359-864b-e7725fccca69',
  21. params: {
  22. id: ID,
  23. },
  24. })
  25. "
  26. />
  27. <CzrButton
  28. type="add"
  29. title="添加分段"
  30. @click="() => (state.detail.show = true)"
  31. />
  32. <CzrButton title="迁移" icon="move" @click="onKnowledge()" />
  33. <CzrButton title="归档" icon="cloud" />
  34. <CzrButton
  35. type="del"
  36. title="删除"
  37. icon="czr_del"
  38. @click="onDel()"
  39. />
  40. </div>
  41. </template>
  42. <template #buttons>
  43. <div class="flex items-center gap-[var(--czr-gap)]">
  44. <CzrForm
  45. class="bm-filter"
  46. label-width="0px"
  47. @handleEnter="onSearch"
  48. >
  49. <CzrFormColumn
  50. width="6.68rem"
  51. class="__czr-table-form-column"
  52. :span="24"
  53. label-width="0px"
  54. v-model:param="state.query.form.p1"
  55. link="select"
  56. :options="[]"
  57. placeholder="审核状态"
  58. />
  59. <CzrFormColumn
  60. width="15.63rem"
  61. class="__czr-table-form-column"
  62. :span="24"
  63. label-width="0px"
  64. v-model:param="state.text"
  65. placeholder="按文档名称搜索"
  66. :prefix-icon="Search"
  67. />
  68. </CzrForm>
  69. </div>
  70. </template>
  71. <template #table>
  72. <CzrTable
  73. v-loading="state.query.loading"
  74. ref="ref_cusTable"
  75. :data="state.query.result.data"
  76. :head="state.query.head"
  77. :total="state.query.result.total"
  78. :page="state.query.page.pageNum"
  79. :pageSize="state.query.page.pageSize"
  80. @handlePage="onPage"
  81. v-model:selected="state.query.selected"
  82. >
  83. <template #name-column-value="{ scope }">
  84. <div class="flex justify-center">
  85. <template v-if="scope.row.indexingStatus === 'completed'">
  86. <CzrButton
  87. type="table"
  88. :title="scope.row.name"
  89. @click="onStage(scope.row)"
  90. />
  91. </template>
  92. <template v-else>
  93. {{ scope.row.name }}
  94. </template>
  95. </div>
  96. </template>
  97. <template #caozuo-column-value="{ scope }">
  98. <div class="__czr-table-operations">
  99. <template v-if="scope.row.indexingStatus === 'archived'">
  100. <CzrButton
  101. type="table"
  102. title="撤销归档"
  103. @click="onUnArchive(scope.row)"
  104. />
  105. </template>
  106. <template v-if="scope.row.indexingStatus === 'completed'">
  107. <CzrButton
  108. type="table"
  109. title="归档"
  110. @click="onArchive(scope.row)"
  111. />
  112. </template>
  113. <CzrButton
  114. type="table"
  115. title="重命名"
  116. @click="onRename(scope.row)"
  117. />
  118. <CzrButton
  119. type="table"
  120. title="迁移"
  121. @click="onKnowledge(scope.row)"
  122. />
  123. <CzrButton type="table-del" @click="onDel(scope.row)" />
  124. </div>
  125. </template>
  126. </CzrTable>
  127. </template>
  128. </CzrContent>
  129. <detailCom
  130. v-model:show="state.detail.show"
  131. :transfer="state.detail.transfer"
  132. @refresh="onSearch"
  133. />
  134. <renameCom
  135. v-model:show="state.rename.show"
  136. :transfer="state.rename.transfer"
  137. @refresh="onSearch"
  138. />
  139. <knowledgeSelectCom
  140. v-model:show="state.knowledgeSelect.show"
  141. :transfer="state.knowledgeSelect.transfer"
  142. @refresh="onSearch"
  143. />
  144. </template>
  145. <template v-else>
  146. <stageIndexCom
  147. v-model:show="state.stage.show"
  148. :document="state.stage.document"
  149. />
  150. </template>
  151. </div>
  152. </template>
  153. <script setup lang="ts">
  154. import {
  155. computed,
  156. getCurrentInstance,
  157. inject,
  158. onMounted,
  159. reactive,
  160. ref,
  161. watch,
  162. } from 'vue'
  163. import { Search } from '@element-plus/icons-vue'
  164. import { debounce } from 'lodash'
  165. import { useDialogStore, useDictionaryStore } from '@/stores'
  166. import { ElMessage } from 'element-plus'
  167. import detailCom from './detail.vue'
  168. import renameCom from './rename.vue'
  169. import knowledgeSelectCom from './knowledge-select.vue'
  170. import stageIndexCom from './stage-index.vue'
  171. import {
  172. documentArchive,
  173. documentDocsDelete,
  174. documentGetDocumentsByPage,
  175. documentNoArchive,
  176. } from '@/api/modules/knowledge/document'
  177. const DialogStore = useDialogStore()
  178. const DictionaryStore = useDictionaryStore()
  179. const emit = defineEmits([])
  180. const props = defineProps({
  181. knowledge: <any>{},
  182. })
  183. const { proxy }: any = getCurrentInstance()
  184. const ID = inject('ID')
  185. const state: any = reactive({
  186. text: '',
  187. query: {
  188. init: false,
  189. loading: false,
  190. head: [
  191. { value: 'name', label: '文件名称', show: true, width: 200 },
  192. { value: 'wordCount', label: '字符数', show: true, width: 100 },
  193. {
  194. value: 'indexingStatus',
  195. label: '状态',
  196. show: true,
  197. width: 100,
  198. dictList: computed(() => DictionaryStore.indexingStatusList),
  199. },
  200. { value: 'p1', label: '召回次数(无)', show: true },
  201. {
  202. value: 'isUse',
  203. label: '启用/停用',
  204. show: true,
  205. width: 100,
  206. dictList: computed(() => DictionaryStore.documentUseList),
  207. },
  208. { value: 'checkStatus', label: '审核状态', show: true, width: 100 },
  209. { value: 'p1', label: '关联应用(无)', show: true },
  210. {
  211. value: 'createTime',
  212. label: '创建时间',
  213. show: true,
  214. width: 180,
  215. datetime: true,
  216. },
  217. {
  218. value: 'updateTime',
  219. label: '更新时间',
  220. show: true,
  221. width: 180,
  222. datetime: true,
  223. },
  224. {
  225. value: 'caozuo',
  226. label: '操作',
  227. show: true,
  228. width: 300,
  229. fixed: 'right',
  230. popover: false,
  231. },
  232. ],
  233. page: {
  234. pageNum: 1,
  235. pageSize: 20,
  236. },
  237. form: {},
  238. formReal: {},
  239. result: {
  240. total: 0,
  241. data: [],
  242. },
  243. selected: [],
  244. },
  245. detail: {
  246. show: false,
  247. transfer: {
  248. ID: ID,
  249. },
  250. },
  251. rename: {
  252. show: false,
  253. transfer: {},
  254. },
  255. knowledgeSelect: {
  256. show: false,
  257. transfer: {},
  258. },
  259. stage: {
  260. show: false,
  261. document: {},
  262. },
  263. })
  264. const setText = debounce((v) => {
  265. state.query.form.name = v
  266. }, 1000)
  267. watch(
  268. () => state.text,
  269. (n) => {
  270. setText(n)
  271. },
  272. )
  273. watch(
  274. () => state.query.form,
  275. (n) => {
  276. if (state.query.init) {
  277. onSearch()
  278. }
  279. },
  280. { deep: true },
  281. )
  282. const onPage = (pageNum, pageSize) => {
  283. setTimeout(() => {
  284. state.query.init = true
  285. }, 100)
  286. state.query.page = {
  287. pageNum: pageNum,
  288. pageSize: pageSize,
  289. }
  290. const params = {
  291. datasetId: ID,
  292. page: state.query.page.pageNum,
  293. size: state.query.page.pageSize,
  294. }
  295. // 添加表单参数
  296. for (const [k, v] of Object.entries(state.query.formReal)) {
  297. if (proxy.$czrUtil.isValue(v)) {
  298. params[k] = v
  299. }
  300. }
  301. state.query.loading = true
  302. documentGetDocumentsByPage(params)
  303. .then(({ data }: any) => {
  304. state.query.result.total = data.totalElements
  305. state.query.result.data = data.content
  306. })
  307. .catch(() => {})
  308. .finally(() => {
  309. state.query.loading = false
  310. })
  311. }
  312. const onSearch = () => {
  313. state.query.selected = []
  314. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  315. onPage(1, state.query.page.pageSize)
  316. }
  317. const onReset = () => {
  318. state.query.page = {
  319. pageNum: 1,
  320. pageSize: 20,
  321. }
  322. state.query.form = {}
  323. onSearch()
  324. }
  325. const onDel = (row: any = null) => {
  326. if (row) {
  327. DialogStore.confirm({
  328. title: '删除确认',
  329. content: `是否删除文档:${row.name}?<br/>此文档下的${row.p1 ? row.p1 + '个' : ''}分段都会被删除,请谨慎操作。`,
  330. onSubmit: () => {
  331. documentDocsDelete([row.id])
  332. .then(() => {
  333. ElMessage.success('删除成功!')
  334. })
  335. .catch(() => {})
  336. .finally(() => {
  337. onSearch()
  338. })
  339. },
  340. })
  341. } else {
  342. if (state.query.selected.length === 0) {
  343. ElMessage.warning('请至少选择一条记录!')
  344. return
  345. }
  346. DialogStore.confirm({
  347. title: '删除确认',
  348. content: `是否批量删除${state.query.selected.length}个文档?<br/>所选文档中的分段会跟随删除,请谨慎操作。`,
  349. onSubmit: () => {
  350. documentDocsDelete(state.query.selected.map((v) => v.id))
  351. .then(() => {
  352. ElMessage.success('删除成功!')
  353. })
  354. .catch(() => {})
  355. .finally(() => {
  356. onSearch()
  357. })
  358. },
  359. })
  360. }
  361. }
  362. const onArchive = (row: any = null) => {
  363. if (row) {
  364. DialogStore.confirm({
  365. title: '归档确认',
  366. content: `是否归档文档:${row.name}?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
  367. onSubmit: () => {
  368. documentArchive([row.id])
  369. .then(() => {
  370. ElMessage.success('归档成功!')
  371. })
  372. .catch(() => {})
  373. .finally(() => {
  374. onSearch()
  375. })
  376. },
  377. })
  378. } else {
  379. if (state.query.selected.length === 0) {
  380. ElMessage.warning('请至少选择一条记录!')
  381. return
  382. }
  383. DialogStore.confirm({
  384. title: '归档确认',
  385. content: `是否批量删除${state.query.selected.length}个文档?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
  386. onSubmit: () => {
  387. documentArchive(state.query.selected.map((v) => v.id))
  388. .then(() => {
  389. ElMessage.success('归档成功!')
  390. })
  391. .catch(() => {})
  392. .finally(() => {
  393. onSearch()
  394. })
  395. },
  396. })
  397. }
  398. }
  399. const onUnArchive = (row: any = null) => {
  400. DialogStore.confirm({
  401. title: '撤销归档确认',
  402. content: `是否撤销归档:${row.name}?<br/>撤销归档后的数据,可重新编辑,请谨慎操作。`,
  403. onSubmit: () => {
  404. documentNoArchive([row.id])
  405. .then(() => {
  406. ElMessage.success('撤销归档成功!')
  407. })
  408. .catch(() => {})
  409. .finally(() => {
  410. onSearch()
  411. })
  412. },
  413. })
  414. }
  415. const onRename = (row) => {
  416. state.rename.transfer = {
  417. id: row.id,
  418. name: JSON.parse(JSON.stringify(row.name)),
  419. }
  420. state.rename.show = true
  421. }
  422. const onKnowledge = (row: any = null) => {
  423. if (row) {
  424. state.knowledgeSelect.transfer = {
  425. row: JSON.parse(JSON.stringify(row)),
  426. type: 'text',
  427. }
  428. state.knowledgeSelect.show = true
  429. } else {
  430. if (state.query.selected.length === 0) {
  431. ElMessage.warning('请至少选择一条记录!')
  432. return
  433. }
  434. state.knowledgeSelect.transfer = {
  435. list: [...state.query.selected],
  436. type: 'text',
  437. }
  438. state.knowledgeSelect.show = true
  439. }
  440. }
  441. const onStage = (row) => {
  442. state.stage.document = JSON.parse(JSON.stringify(row))
  443. state.stage.show = true
  444. }
  445. onMounted(() => {
  446. initDictionary()
  447. onReset()
  448. })
  449. const initDictionary = () => {
  450. DictionaryStore.initDict('document_use')
  451. DictionaryStore.initDict('indexing_status')
  452. }
  453. </script>
  454. <style lang="scss" scoped>
  455. .knowledge {
  456. width: 100%;
  457. height: 11.81rem;
  458. background-image: url('@/assets/images/knowledge-item-bg.png');
  459. background-repeat: no-repeat;
  460. background-size: 100% 100%;
  461. padding: 1rem 1.5rem;
  462. }
  463. </style>