index.vue 13 KB

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