KnowledgeManagement.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div class="knowledge-management">
  3. <header>
  4. <i class="back-icon" @click="goKBM"></i>
  5. <i class="folder-icon" style="height: 32px;width:32px;cursor: pointer;" @click="goKBM"></i>
  6. </header>
  7. <main>
  8. <div class="aside">
  9. <div class="name">{{ KBData.name }}</div>
  10. <div class="tags">{{ Array.isArray(KBData.tags) ? KBData.tags.join("、") : "" }}</div>
  11. <div class="description">{{ KBData.description }}</div>
  12. <!-- <div class="other">无关联应用ⓘ</div> -->
  13. </div>
  14. <div class="management-content">
  15. <div class="management-content-top">
  16. <div class="search">
  17. <el-input v-model="querySearch" size="large" placeholder="搜索" @keydown.enter="getFilesList"
  18. :prefix-icon="Search" />
  19. </div>
  20. <span @click="addFileVisible = true" class="add-file"><el-icon color="#fff">
  21. <Plus />
  22. </el-icon> <i class="text">添加文件</i></span>
  23. <span class="add-file" style="margin-right: 10px;" @click="handleBatchEditFiles"><i class="text"
  24. style="margin: 0px;">批量修改文件</i></span>
  25. </div>
  26. <div class="management-content-middle">
  27. <el-table :data="filesList" ref="fileTableRef" size="large" style="width: 99% ;">
  28. <el-table-column type="selection" width="35" />
  29. <el-table-column label="#" prop="index" width="60" />
  30. <el-table-column prop="file_name" min-width="150" label="标题">
  31. <template #default="{ row }">
  32. <div class="list-name">
  33. <span class="icon-area">
  34. <i :class="`${row.file_type}-icon file-icon`"></i>
  35. </span>
  36. <span @click="handleViewFile(row.minio_url, row.file_type)" class="text-area">
  37. {{ row.file_name }}
  38. </span>
  39. </div>
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="knowledge_type" label="知识类型" />
  43. <el-table-column prop="version" label="版本" />
  44. <el-table-column prop="author" label="作者(主编)" />
  45. <el-table-column prop="year" label="年份" min-width="70" />
  46. <el-table-column prop="creator" label="上传人" />
  47. <el-table-column prop="created_at" label="上传时间" width="170" />
  48. <el-table-column prop="" label="状态">
  49. <template #default="{ row, $index }">
  50. <div style="display:flex; align-items: center;gap: 10px;">
  51. <span v-if="row.status">
  52. <i class="circle" type="success"></i>
  53. <el-text type="success">可用</el-text>
  54. </span>
  55. <!-- <span v-else>
  56. <i class="circle" type="warning"></i>
  57. <el-text type="warning">异常</el-text>
  58. </span> -->
  59. <span v-else>
  60. <i class="circle" type="danger"></i>
  61. <el-text type="danger">禁用</el-text>
  62. </span>
  63. <el-switch v-model="row.status" @change="handleStatusChange(row.id, row.status)"></el-switch>
  64. </div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="created_at" label="下载" width="70">
  68. <template #default="{ row }">
  69. <i class="document-download-icon" :disabled="row.status ? true : false"
  70. @click="handleDownloadFile(row.minio_url, row.file_name, row.status)"></i>
  71. </template>
  72. </el-table-column>
  73. <el-table-column fixed="right" label="操作">
  74. <template #default="{ row }">
  75. <div class="operation">
  76. <!-- <el-icon size="24">
  77. <Operation />
  78. </el-icon>
  79. <el-icon size="24">
  80. <MoreFilled />
  81. </el-icon> -->
  82. <el-button link type="primary" @click="handleEditFile(toRaw([row]))">修改</el-button>
  83. <el-button link type="danger" @click="handleDeleteFile(row.id)">删除</el-button>
  84. </div>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. </div>
  89. </div>
  90. </main>
  91. <footer>
  92. <div class="pagination" v-if="totalPage > 1 || paginationData.defaultPageSize !== paginationData.currentPageSize">
  93. <el-pagination :current-page="paginationData.currentPage" :page-sizes="paginationData.pageSizes"
  94. :disabled="paginationData.disabled" :default-page-size="paginationData.defaultPageSize"
  95. layout="total, sizes, prev, pager, next, jumper" :total="paginationData.total" @size-change="handleSizeChange"
  96. @current-change="handleCurrentChange" />
  97. </div>
  98. </footer>
  99. <CreateKBFileDialog v-model="addFileVisible" :knowledgeBase="KBData" @updateFiles="getFilesList()" />
  100. <FileViewer v-if="viewFileData.show" :fileType="viewFileData.type" :fileName="viewFileData.name"
  101. :fileUrl="viewFileData.url" :width="viewFileData.width" @closeViewer="handleCloseViewer" />
  102. <EditKBFileDialog v-model="editKBFileData.show" :fileTable="editKBFileData.data"
  103. @updateFiles="() => { getFilesList() }" />
  104. </div>
  105. </template>
  106. <script setup>
  107. import { saveAs } from 'file-saver'
  108. import { ElMessage } from 'element-plus'
  109. import { ref, getCurrentInstance, computed, watch, toRaw, onMounted } from 'vue'
  110. import { Download, Search } from '@element-plus/icons-vue'
  111. import { useRoute, useRouter } from 'vue-router';
  112. import axios from 'axios';
  113. import { api } from '@/utils/config';
  114. import { confirmDelete } from "@/utils/confirmation"
  115. import CreateKBFileDialog from '@/components/CreateKBFileDialog.vue';
  116. import FileViewer from "@/components/FileViewer/FileViewer.vue"
  117. import EditKBFileDialog from "@/components/EditKBFileDialog.vue"
  118. const { proxy } = getCurrentInstance()
  119. const route = useRoute()
  120. const router = useRouter()
  121. const kbId = route.params.kbId
  122. let filesList = ref([])
  123. let KBData = ref({})
  124. let addFileVisible = ref(false)
  125. let querySearch = ref("")
  126. let editKBFileData = ref({
  127. show: false,
  128. data: []
  129. })
  130. let viewFileData = ref({
  131. url: "",
  132. name: "",
  133. type: "",
  134. show: false,
  135. width: 1000,
  136. })
  137. const paginationData = ref({
  138. currentPage: 1,
  139. pageSizes: [10, 50, 100, 200],
  140. disabled: false,
  141. total: 0,
  142. defaultPageSize: 10,
  143. currentPageSize: 10
  144. })
  145. const totalPage = computed(() => {
  146. return Math.ceil(paginationData.value.total / paginationData.value.currentPageSize)
  147. })
  148. const handleSizeChange = (pageSize) => {
  149. paginationData.value.currentPageSize = pageSize
  150. // console.log('handleSizeChange', pageSize)
  151. }
  152. async function checkLinkValidity(index, url) {
  153. try {
  154. const response = await axios.head(url); // 使用 HEAD 请求,仅请求响应头
  155. if (response.status >= 200 && response.status < 300) {
  156. filesList.value[index].isValid = true
  157. } else {
  158. filesList.value[index].isValid = false // 返回 false 表示链接无效
  159. }
  160. } catch (error) {
  161. filesList.value[index].isValid = false // 请求失败,返回 false
  162. }
  163. }
  164. // 定义处理关闭查看器的方法
  165. const handleCloseViewer = () => {
  166. viewFileData.value.show = false;
  167. };
  168. // 修改状态
  169. const handleStatusChange = async (id, status) => {
  170. console.log('handleStatusChange', status)
  171. try {
  172. await proxy.$http.get(api.files + `${id}/changeStatus`, {
  173. params: {
  174. status: status
  175. }
  176. })
  177. ElMessage({
  178. message: '状态修改成功',
  179. type: 'success',
  180. })
  181. }
  182. catch (e) {
  183. console.log(e)
  184. ElMessage({
  185. message: '状态修改失败',
  186. type: 'error',
  187. })
  188. let index = filesList.value.findIndex(item => item.id === id)
  189. filesList.value[index].status = !status // 恢复原状态
  190. }
  191. // 这里可以添加逻辑来处理状态变化
  192. // 比如发送请求到后端更新状态
  193. }
  194. function handleBatchEditFiles() {
  195. const fileTableRef = proxy.$refs['fileTableRef']
  196. const selectionRows = fileTableRef.getSelectionRows()
  197. if (selectionRows.length == 0) return;
  198. handleEditFile(toRaw(selectionRows))
  199. fileTableRef.clearSelection()
  200. }
  201. function handleEditFile(data) {
  202. editKBFileData.value.show = true;
  203. editKBFileData.value.data = data;
  204. }
  205. const handleViewFile = (url, type) => {
  206. viewFileData.value.show = true;
  207. viewFileData.value.url = url;
  208. viewFileData.value.type = type
  209. // console.log(viewFileData.value)
  210. }
  211. function handleDownloadFile(file_url, file_name, status = true) {
  212. if (status) {
  213. saveAs(file_url, file_name)
  214. }
  215. }
  216. const handleCurrentChange = (page) => {
  217. paginationData.value.currentPage = page
  218. // console.log('handleCurrentChange', page)
  219. }
  220. const getKnowledgeBaseById = async () => {
  221. try {
  222. const data = await proxy.$http.get(api.knowledgeBase + `/${kbId}`)
  223. KBData.value = data
  224. } catch (e) {
  225. console.log(e)
  226. }
  227. }
  228. function goKBM() {
  229. router.push({ name: 'kbm' })
  230. }
  231. const getFilesList = async () => {
  232. try {
  233. const data = await proxy.$http.get(api.knowledgeBase + `/${kbId}/files/`, {
  234. params: {
  235. file_name: querySearch.value,
  236. pageSize: paginationData.value.currentPageSize,
  237. pageNo: paginationData.value.currentPage
  238. }
  239. })
  240. filesList.value = data.list
  241. paginationData.value.total = data.total
  242. for (let i = 0; i < filesList.value.length; i++) {
  243. filesList.value[i].index = (paginationData.value.currentPage - 1) * paginationData.value.currentPageSize + i + 1
  244. // filesList.value[i].isValid = true
  245. // filesList.value[i].status = true
  246. // checkLinkValidity(i, filesList.value[i].minio_url)
  247. }
  248. } catch (e) {
  249. console.log(e)
  250. }
  251. }
  252. const handleDeleteFile = (id) => {
  253. confirmDelete({
  254. title: '',
  255. content: '确认要删除该知识文件吗?',
  256. type: 1,
  257. },
  258. async () => {
  259. try {
  260. const data = await proxy.$http.delete(api.files + `/${id}`)
  261. ElMessage({
  262. message: '知识文件删除成功',
  263. type: 'success',
  264. })
  265. getFilesList()
  266. } catch (e) {
  267. ElMessage({
  268. message: '知识文件删除失败',
  269. type: 'error',
  270. })
  271. console.log(e)
  272. }
  273. },
  274. () => {
  275. console.log("不删除")
  276. }
  277. )
  278. }
  279. watch(() => paginationData.value.currentPage, () => {
  280. getFilesList()
  281. }, { immediate: true })
  282. watch(() => paginationData.value.currentPageSize, () => {
  283. getFilesList()
  284. })
  285. getKnowledgeBaseById()
  286. onMounted(() => {
  287. // const fileTableRef = proxy.$refs['fileTableRef']
  288. })
  289. </script>
  290. <style lang="less" scoped>
  291. @import "@/assets/css/common.less";
  292. .knowledge-management {
  293. min-height: 100%;
  294. .file-icon {
  295. width: 20px;
  296. height: 20px;
  297. }
  298. .search {
  299. // padding: 10px 20px;
  300. margin: 5px;
  301. background: white;
  302. display: inline-block;
  303. :deep(.el-input__wrapper) {
  304. background-color: @bgColor;
  305. border-radius: 10px;
  306. }
  307. .el-input {
  308. width: 250px;
  309. }
  310. }
  311. main {
  312. display: flex;
  313. // flex-direction: column;
  314. flex-wrap: nowrap;
  315. .aside {
  316. width: 300px;
  317. flex: 0 0 auto;
  318. // &>div {
  319. // margin-top: 20px;
  320. // }
  321. .name {
  322. font-weight: bold;
  323. font-size: 18px;
  324. margin-top: 20px;
  325. }
  326. .tags {
  327. color: #A8ACB8;
  328. font-size: 14px;
  329. line-height: 1.4;
  330. margin-top: 5px;
  331. }
  332. .description {
  333. color: #A8ACB8;
  334. font-size: 16px;
  335. margin-top: 10px;
  336. line-height: 1.5;
  337. }
  338. .other {
  339. color: #354052;
  340. margin-top: 20px;
  341. }
  342. }
  343. .management-content {
  344. flex: 1 1 auto;
  345. min-width: 0px; //让盒子可以压缩
  346. .management-content-top {
  347. clear: both;
  348. .add-file {
  349. color: white;
  350. background-color: #5780FC;
  351. margin-left: auto;
  352. padding: 10px 15px;
  353. border-radius: 9px;
  354. display: inline-block;
  355. cursor: pointer;
  356. float: right;
  357. display: flex;
  358. // .el-icon,
  359. .text {
  360. // vertical-align: middle;
  361. margin-left: 10px;
  362. }
  363. }
  364. }
  365. }
  366. :deep(.el-table) {
  367. min-width: 0px;
  368. max-width: 100%;
  369. .document-download-icon {
  370. width: 28px;
  371. height: 28px;
  372. cursor: pointer;
  373. &:is([disabled='false']) {
  374. cursor: not-allowed;
  375. opacity: 0.5;
  376. }
  377. }
  378. .list-name {
  379. white-space: nowrap;
  380. text-overflow: ellipsis;
  381. display: inline;
  382. .text-area,
  383. .icon-area {
  384. vertical-align: bottom;
  385. }
  386. }
  387. .circle {
  388. border-radius: 50%;
  389. width: 10px;
  390. height: 10px;
  391. background-color: #8AD068;
  392. display: inline-block;
  393. margin-right: 10px;
  394. &:is([type='warning']) {
  395. background-color: #E6A23C;
  396. }
  397. &:is([type='danger']) {
  398. background-color: #F56C6C;
  399. }
  400. }
  401. .operation {
  402. display: flex;
  403. align-items: center;
  404. // justify-content: space-evenly;
  405. gap: 0px 10px;
  406. .el-button+.el-button {
  407. margin: 0px;
  408. }
  409. }
  410. }
  411. }
  412. footer {
  413. margin-top: 20px;
  414. width: auto;
  415. .pagination {
  416. width: auto;
  417. .el-pagination {
  418. justify-content: end;
  419. }
  420. }
  421. }
  422. .switch {
  423. :deep(.el-switch) {
  424. &:is(.is-checked) {
  425. .el-switch__core {
  426. background-color: #155AEF;
  427. }
  428. }
  429. .el-switch__core {
  430. border-radius: 5px;
  431. width: 35px;
  432. min-width: 0px;
  433. // background-color: #155AEF;
  434. }
  435. .el-switch__action {
  436. border-radius: 3px;
  437. }
  438. }
  439. }
  440. }
  441. </style>