index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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.tag"
  55. link="select"
  56. :options="DictionaryStore.knowledgeTags.list"
  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. <CzrButton
  86. type="table"
  87. :title="scope.row.p1"
  88. @click="onStage(scope.row)"
  89. />
  90. </div>
  91. </template>
  92. <template #caozuo-column-value="{ scope }">
  93. <div class="__czr-table-operations">
  94. <CzrButton
  95. type="table"
  96. title="重命名"
  97. @click="onRename(scope.row)"
  98. />
  99. <CzrButton
  100. type="table"
  101. title="迁移"
  102. @click="onKnowledge(scope.row)"
  103. />
  104. <CzrButton type="table" title="归档" />
  105. <CzrButton type="table-del" @click="onDel(scope.row)" />
  106. </div>
  107. </template>
  108. </CzrTable>
  109. </template>
  110. </CzrContent>
  111. <detailCom
  112. v-model:show="state.detail.show"
  113. :transfer="state.detail.transfer"
  114. @refresh="onSearch"
  115. />
  116. <renameCom
  117. v-model:show="state.rename.show"
  118. :transfer="state.rename.transfer"
  119. @refresh="onSearch"
  120. />
  121. <knowledgeSelectCom
  122. v-model:show="state.knowledgeSelect.show"
  123. :transfer="state.knowledgeSelect.transfer"
  124. @refresh="onSearch"
  125. />
  126. </template>
  127. <template v-else>
  128. <stageIndexCom
  129. v-model:show="state.stage.show"
  130. :document="state.stage.document"
  131. />
  132. </template>
  133. </div>
  134. </template>
  135. <script setup lang="ts">
  136. import {
  137. getCurrentInstance,
  138. inject,
  139. onMounted,
  140. reactive,
  141. ref,
  142. watch,
  143. } from 'vue'
  144. import { Search } from '@element-plus/icons-vue'
  145. import { debounce } from 'lodash'
  146. import { useDialogStore, useDictionaryStore } from '@/stores'
  147. import { ElMessage } from 'element-plus'
  148. import detailCom from './detail.vue'
  149. import renameCom from './rename.vue'
  150. import knowledgeSelectCom from './knowledge-select.vue'
  151. import stageIndexCom from './stage-index.vue'
  152. import { documentGetDocumentsByPage } from '@/api/modules/knowledge/document'
  153. const DialogStore = useDialogStore()
  154. const DictionaryStore = useDictionaryStore()
  155. const emit = defineEmits([])
  156. const props = defineProps({
  157. knowledge: <any>{},
  158. })
  159. const { proxy }: any = getCurrentInstance()
  160. const ID = inject('ID')
  161. const state: any = reactive({
  162. text: '',
  163. query: {
  164. init: false,
  165. loading: false,
  166. head: [
  167. { value: 'name', label: '文件名称', show: true },
  168. { value: 'wordCount', label: '字符数', show: true },
  169. { value: 'indexingStatus', label: '状态', show: true },
  170. { value: 'p1', label: '召回次数(NO)', show: true },
  171. { value: 'isUse', label: '启用/停用', show: true },
  172. { value: 'checkStatus', label: '审核状态', show: true },
  173. { value: 'p1', label: '关联应用(NO)', show: true },
  174. { value: 'createTime', label: '创建时间', show: true },
  175. { value: 'updateTime', label: '更新时间', show: true },
  176. {
  177. value: 'caozuo',
  178. label: '操作',
  179. show: true,
  180. width: 300,
  181. fixed: 'right',
  182. popover: false,
  183. },
  184. ],
  185. page: {
  186. pageNum: 1,
  187. pageSize: 20,
  188. },
  189. form: {},
  190. formReal: {},
  191. result: {
  192. total: 0,
  193. data: [],
  194. },
  195. selected: [],
  196. },
  197. detail: {
  198. show: false,
  199. transfer: {
  200. ID: ID,
  201. },
  202. },
  203. rename: {
  204. show: false,
  205. transfer: {},
  206. },
  207. knowledgeSelect: {
  208. show: false,
  209. transfer: {},
  210. },
  211. stage: {
  212. show: false,
  213. document: {},
  214. },
  215. })
  216. const setText = debounce((v) => {
  217. state.query.form.name = v
  218. }, 1000)
  219. watch(
  220. () => state.text,
  221. (n) => {
  222. setText(n)
  223. },
  224. )
  225. watch(
  226. () => state.query.form,
  227. (n) => {
  228. if (state.query.init) {
  229. onSearch()
  230. }
  231. },
  232. { deep: true },
  233. )
  234. const onPage = (pageNum, pageSize) => {
  235. setTimeout(() => {
  236. state.query.init = true
  237. }, 100)
  238. state.query.page = {
  239. pageNum: pageNum,
  240. pageSize: pageSize,
  241. }
  242. const params = {
  243. datasetId: ID,
  244. page: state.query.page.pageNum,
  245. size: state.query.page.pageSize,
  246. }
  247. // 添加表单参数
  248. for (const [k, v] of Object.entries(state.query.formReal)) {
  249. if (proxy.$czrUtil.isValue(v)) {
  250. params[k] = v
  251. }
  252. }
  253. state.query.loading = true
  254. documentGetDocumentsByPage(params)
  255. .then(({ data }: any) => {
  256. state.query.result.total = data.totalElements
  257. state.query.result.data = data.content
  258. })
  259. .catch(() => {})
  260. .finally(() => {
  261. state.query.loading = false
  262. })
  263. }
  264. const onSearch = () => {
  265. state.query.selected = []
  266. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  267. onPage(1, state.query.page.pageSize)
  268. }
  269. const onReset = () => {
  270. state.query.page = {
  271. pageNum: 1,
  272. pageSize: 20,
  273. }
  274. state.query.form = {}
  275. onSearch()
  276. }
  277. const onDel = (row: any = null) => {
  278. if (row) {
  279. DialogStore.confirm({
  280. title: '删除确认',
  281. content: `是否删除文档:${row.p1}?<br/>此文档下的29个分段都会被删除,请谨慎操作。`,
  282. onSubmit: () => {
  283. ElMessage.success('删除成功!')
  284. onSearch()
  285. },
  286. })
  287. } else {
  288. if (state.query.selected.length === 0) {
  289. ElMessage.warning('请至少选择一条记录!')
  290. return
  291. }
  292. DialogStore.confirm({
  293. title: '删除确认',
  294. content: `是否批量删除${state.query.selected.length}个文档?<br/>所选文档中的分段会跟随删除,请谨慎操作。`,
  295. onSubmit: () => {
  296. ElMessage.success('删除成功!')
  297. onSearch()
  298. },
  299. })
  300. }
  301. }
  302. const onRename = (row) => {
  303. state.rename.transfer = {
  304. row: JSON.parse(JSON.stringify(row)),
  305. }
  306. state.rename.show = true
  307. }
  308. const onKnowledge = (row: any = null) => {
  309. if (row) {
  310. state.knowledgeSelect.transfer = {
  311. row: JSON.parse(JSON.stringify(row)),
  312. type: 'text',
  313. }
  314. state.knowledgeSelect.show = true
  315. } else {
  316. if (state.query.selected.length === 0) {
  317. ElMessage.warning('请至少选择一条记录!')
  318. return
  319. }
  320. state.knowledgeSelect.transfer = {
  321. list: [...state.query.selected],
  322. type: 'text',
  323. }
  324. state.knowledgeSelect.show = true
  325. }
  326. }
  327. const onStage = (row) => {
  328. state.stage.document = JSON.parse(JSON.stringify(row))
  329. state.stage.show = true
  330. }
  331. onMounted(() => {
  332. initDictionary()
  333. onReset()
  334. })
  335. const initDictionary = () => {}
  336. </script>
  337. <style lang="scss" scoped>
  338. .knowledge {
  339. width: 100%;
  340. height: 11.81rem;
  341. background-image: url('@/assets/images/knowledge-item-bg.png');
  342. background-repeat: no-repeat;
  343. background-size: 100% 100%;
  344. padding: 1rem 1.5rem;
  345. }
  346. </style>