KnowledgeManagement.vue 14 KB

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