KnowledgeManagement.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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">{{ KBData.tags }}</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 }">
  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"></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="() => viewFileData.show = false" />
  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. function handleBatchEditFiles() {
  165. const fileTableRef = proxy.$refs['fileTableRef']
  166. const selectionRows = fileTableRef.getSelectionRows()
  167. if (selectionRows.length == 0) return;
  168. handleEditFile(toRaw(selectionRows))
  169. }
  170. function handleEditFile(data) {
  171. editKBFileData.value.show = true;
  172. editKBFileData.value.data = data;
  173. }
  174. const handleViewFile = (url, type) => {
  175. viewFileData.value.show = true;
  176. viewFileData.value.url = url;
  177. viewFileData.value.type = type
  178. // console.log(viewFileData.value)
  179. }
  180. function handleDownloadFile(file_url, file_name, status = true) {
  181. if (status) {
  182. saveAs(file_url, file_name)
  183. }
  184. }
  185. const handleCurrentChange = (page) => {
  186. paginationData.value.currentPage = page
  187. // console.log('handleCurrentChange', page)
  188. }
  189. const getKnowledgeBaseById = async () => {
  190. try {
  191. const data = await proxy.$http.get(api.knowledgeBase + `/${kbId}`)
  192. KBData.value = data
  193. } catch (e) {
  194. console.log(e)
  195. }
  196. }
  197. function goKBM() {
  198. router.push({ name: 'kbm' })
  199. }
  200. const getFilesList = async () => {
  201. try {
  202. const data = await proxy.$http.get(api.knowledgeBase + `/${kbId}/files/`, {
  203. params: {
  204. file_name: querySearch.value,
  205. pageSize: paginationData.value.currentPageSize,
  206. pageNo: paginationData.value.currentPage
  207. }
  208. })
  209. filesList.value = data.list
  210. paginationData.value.total = data.total
  211. for (let i = 0; i < filesList.value.length; i++) {
  212. filesList.value[i].index = (paginationData.value.currentPage - 1) * paginationData.value.currentPageSize + i + 1
  213. // filesList.value[i].isValid = true
  214. filesList.value[i].status = true
  215. // checkLinkValidity(i, filesList.value[i].minio_url)
  216. }
  217. } catch (e) {
  218. console.log(e)
  219. }
  220. }
  221. const handleDeleteFile = (id) => {
  222. confirmDelete({
  223. title: '',
  224. content: '确认要删除该知识文件吗?',
  225. type: 1,
  226. },
  227. async () => {
  228. try {
  229. const data = await proxy.$http.delete(api.files + `/${id}`)
  230. ElMessage({
  231. message: '知识文件删除成功',
  232. type: 'success',
  233. })
  234. getFilesList()
  235. } catch (e) {
  236. ElMessage({
  237. message: '知识文件删除失败',
  238. type: 'error',
  239. })
  240. console.log(e)
  241. }
  242. },
  243. () => {
  244. console.log("不删除")
  245. }
  246. )
  247. }
  248. watch(() => paginationData.value.currentPage, () => {
  249. getFilesList()
  250. }, { immediate: true })
  251. watch(() => paginationData.value.currentPageSize, () => {
  252. getFilesList()
  253. })
  254. getKnowledgeBaseById()
  255. onMounted(() => {
  256. // const fileTableRef = proxy.$refs['fileTableRef']
  257. })
  258. </script>
  259. <style lang="less" scoped>
  260. @import "@/assets/css/common.less";
  261. .knowledge-management {
  262. min-height: 100%;
  263. .file-icon {
  264. width: 20px;
  265. height: 20px;
  266. }
  267. .search {
  268. // padding: 10px 20px;
  269. margin: 5px;
  270. background: white;
  271. display: inline-block;
  272. /deep/ .el-input__wrapper {
  273. background-color: @bgColor;
  274. border-radius: 10px;
  275. }
  276. .el-input {
  277. width: 250px;
  278. }
  279. }
  280. main {
  281. display: flex;
  282. // flex-direction: column;
  283. flex-wrap: nowrap;
  284. .aside {
  285. width: 300px;
  286. flex: 0 0 auto;
  287. // &>div {
  288. // margin-top: 20px;
  289. // }
  290. .name {
  291. font-weight: bold;
  292. font-size: 18px;
  293. margin-top: 20px;
  294. }
  295. .tags {
  296. color: #A8ACB8;
  297. font-size: 14px;
  298. line-height: 1.4;
  299. margin-top: 5px;
  300. }
  301. .description {
  302. color: #A8ACB8;
  303. font-size: 16px;
  304. margin-top: 10px;
  305. line-height: 1.5;
  306. }
  307. .other {
  308. color: #354052;
  309. margin-top: 20px;
  310. }
  311. }
  312. .management-content {
  313. flex: 1 1 auto;
  314. min-width: 0px; //让盒子可以压缩
  315. .management-content-top {
  316. clear: both;
  317. .add-file {
  318. color: white;
  319. background-color: #5780FC;
  320. margin-left: auto;
  321. padding: 10px 15px;
  322. border-radius: 9px;
  323. display: inline-block;
  324. cursor: pointer;
  325. float: right;
  326. display: flex;
  327. // .el-icon,
  328. .text {
  329. // vertical-align: middle;
  330. margin-left: 10px;
  331. }
  332. }
  333. }
  334. }
  335. &::v-deep .el-table {
  336. min-width: 0px;
  337. max-width: 100%;
  338. .document-download-icon {
  339. width: 28px;
  340. height: 28px;
  341. cursor: pointer;
  342. &:is([disabled='false']) {
  343. cursor: not-allowed;
  344. opacity: 0.5;
  345. }
  346. }
  347. .list-name {
  348. white-space: nowrap;
  349. text-overflow: ellipsis;
  350. display: inline;
  351. .text-area,
  352. .icon-area {
  353. vertical-align: bottom;
  354. }
  355. }
  356. .circle {
  357. border-radius: 50%;
  358. width: 10px;
  359. height: 10px;
  360. background-color: #8AD068;
  361. display: inline-block;
  362. margin-right: 10px;
  363. &:is([type='warning']) {
  364. background-color: #E6A23C;
  365. }
  366. &:is([type='danger']) {
  367. background-color: #F56C6C;
  368. }
  369. }
  370. .operation {
  371. display: flex;
  372. align-items: center;
  373. // justify-content: space-evenly;
  374. gap: 0px 10px;
  375. .el-button+.el-button {
  376. margin: 0px;
  377. }
  378. .el-switch {
  379. &:is(.is-checked) {
  380. .el-switch__core {
  381. background-color: #155AEF;
  382. }
  383. }
  384. .el-switch__core {
  385. border-radius: 5px;
  386. width: 35px;
  387. min-width: 0px;
  388. // background-color: #155AEF;
  389. }
  390. .el-switch__action {
  391. border-radius: 3px;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. footer {
  398. margin-top: 20px;
  399. width: auto;
  400. .pagination {
  401. width: auto;
  402. .el-pagination {
  403. justify-content: end;
  404. }
  405. }
  406. }
  407. }
  408. </style>