myResources.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. <template>
  2. <a-card>
  3. <!-- 标签页 -->
  4. <a-tabs v-model:activeKey="formState.verifyStatus" @change="tabChange">
  5. <a-tab-pane key="0,3" tab="未发布" v-if="!pageType"></a-tab-pane>
  6. <a-tab-pane key="1" tab="待审核"></a-tab-pane>
  7. <a-tab-pane key="2" tab="已发布"></a-tab-pane>
  8. <!-- <a-tab-pane key="3" tab="已审核" v-if="pageType == 'economize'"></a-tab-pane> -->
  9. <a-tab-pane key="4" tab="回收站"></a-tab-pane>
  10. </a-tabs>
  11. <!-- 搜索和操作区域 -->
  12. <a-card style="margin-bottom: 16px">
  13. <div style="display: flex; justify-content: space-between ;">
  14. <div style="display: flex; flex-direction: column; width: 200%;">
  15. <!-- 第一行:名称、院系、类型 -->
  16. <a-row :gutter="16" style="margin-bottom: 16px">
  17. <a-col :span="6">
  18. <span>名称:</span>
  19. <a-input
  20. v-model:value="formState.fileName"
  21. placeholder="请输入名字"
  22. style="width: calc(100% - 50px); margin-left: 8px"
  23. />
  24. </a-col>
  25. <a-col :span="6">
  26. <span>层级:</span>
  27. <a-cascader
  28. style="width: calc(100% - 50px); margin-left: 8px"
  29. v-model:value="majorIdName"
  30. :options="collegeMajorOptions"
  31. :fieldNames="{ label: 'name', value: 'id', children: 'children' }"
  32. placeholder="请选择"
  33. changeOnSelect
  34. @change="changeCollegeMajor"
  35. />
  36. </a-col>
  37. <a-col :span="6">
  38. <span>类型:</span>
  39. <a-cascader
  40. style="width: calc(100% - 50px); margin-left: 8px"
  41. v-model:value="resourceName"
  42. :options="resourceTypeOptions"
  43. :fieldNames="{ label: 'name', value: 'id', children: 'children' }"
  44. placeholder="请选择"
  45. changeOnSelect
  46. @change="changeCollegeResource"
  47. />
  48. </a-col>
  49. </a-row>
  50. <!-- 第二行:状态、租户、创建人 -->
  51. <a-row :gutter="16">
  52. <a-col :span="6">
  53. <span>状态:</span>
  54. <a-select
  55. v-if="['0,3', '0', '3'].includes(formState.verifyStatus)"
  56. v-model:value="isVerifyStatus"
  57. placeholder="请选择"
  58. style="width: calc(100% - 50px); margin-left: 8px"
  59. >
  60. <a-select-option value="0">未发布</a-select-option>
  61. <a-select-option value="3">未通过</a-select-option>
  62. </a-select>
  63. <a-select
  64. v-else
  65. v-model:value="formState.suffix"
  66. style="width: calc(100% - 50px); margin-left: 8px"
  67. :options="fileformatOptions"
  68. :fieldNames="{ label: 'fileExtendName', value: 'fileExtendName', children: 'children' }"
  69. placeholder="请选择"
  70. />
  71. </a-col>
  72. <!-- <a-col :span="6">-->
  73. <!-- <span>租户:</span>-->
  74. <!-- <a-input placeholder="请选择" style="width: calc(100% - 50px); margin-left: 8px" disabled />-->
  75. <!-- </a-col>-->
  76. <!-- <a-col :span="6">-->
  77. <!-- <span>创建人:</span>-->
  78. <!-- <a-input placeholder="请输入名字" style="width: calc(100% - 64px); margin-left: 8px" />-->
  79. <!-- </a-col>-->
  80. </a-row>
  81. <a-row style="margin-top: 16px">
  82. <a-col :span="24" style="text-align: left">
  83. <a-button
  84. type="primary"
  85. style="margin-right: 8px"
  86. v-if="formState.verifyStatus === '0,3' && !pageType"
  87. @click="batchPublish"
  88. :disabled="selectedRowKeys.length === 0"
  89. >
  90. + 批量发布
  91. </a-button>
  92. <a-button type="primary" v-if="!pageType && formState.verifyStatus === '0,3'" @click="showUploadModal">+ 新增</a-button>
  93. </a-col>
  94. </a-row>
  95. </div>
  96. <div>
  97. <a-button type="primary" @click="handleSearch">查询</a-button>
  98. <a-button @click="handleReset" style="margin-top: 20px">重置</a-button>
  99. </div>
  100. </div>
  101. </a-card>
  102. <!-- 表格 -->
  103. <a-table
  104. :columns="columnsPending"
  105. :data-source="dataSource"
  106. :pagination="false"
  107. :loading="loading"
  108. bordered
  109. :row-key="(record) => record.id"
  110. :row-selection="rowSelection"
  111. :scroll="{ x: 1300 }"
  112. >
  113. <template #bodyCell="{ column, text, record }">
  114. <template
  115. v-if="
  116. ['fileName', 'collegeAllIdName', 'majorIdName', 'resourceALLTypeName', 'suffix', 'uploadTime'].includes(
  117. column.dataIndex
  118. )
  119. "
  120. >
  121. <div class="multiLine-ellipsis" :title="text">{{ text || '-' }}</div>
  122. </template>
  123. <!-- 状态列 -->
  124. <template v-if="column.key === 'verifyStatus'">
  125. <span v-if="record.verifyStatus === '0'">
  126. <a-badge status="processing" text="未发布" />
  127. </span>
  128. <span v-else-if="record.verifyStatus === 'uploaded'">
  129. <a-badge status="success" text="已上传" />
  130. </span>
  131. <span v-else-if="record.verifyStatus === '1'">
  132. <a-badge status="default" text="待审核" />
  133. </span>
  134. <span v-else-if="record.verifyStatus === '2'">
  135. <a-badge status="success" text="已发布" />
  136. </span>
  137. <span v-if="record.verifyStatus === '3'">
  138. <a-badge status="error" text="未通过" />
  139. </span>
  140. <span v-else-if="record.verifyStatus === '4'">
  141. <a-badge status="error" text="已删除" />
  142. </span>
  143. </template>
  144. <template v-if="column.dataIndex === 'fileUrl'">
  145. <!-- 动态图标 + 格式提示 -->
  146. <a-tooltip :title="`${record.suffix || '未知'}`">
  147. <component
  148. :is="fileTypeIcons[record.suffix?.toLowerCase()] || fileTypeIcons['*']"
  149. :style="{ fontSize: '24px', color: getIconColor(record.suffix) }"
  150. />
  151. </a-tooltip>
  152. </template>
  153. <!-- 个人资源操作列 -->
  154. <template v-if="column.key === 'action' && !pageType">
  155. <div class="editable-cell">
  156. <span v-if="formState.verifyStatus === '0,3'" style="cursor: pointer" @click="handlePublish(record)">发布</span>
  157. <span v-if="formState.verifyStatus === '4'" style="cursor: pointer" @click="handleRestore(record)">恢复</span>
  158. <a-dropdown>
  159. <span class="ant-dropdown-link" style="cursor: pointer">
  160. 更多
  161. <DownOutlined />
  162. </span>
  163. <template #overlay>
  164. <a-menu>
  165. <a-menu-item>
  166. <a href="javascript:;" @click="handleView(record)">预览</a>
  167. </a-menu-item>
  168. <a-menu-item>
  169. <a
  170. target="_blank"
  171. style="display: block; color: inherit"
  172. :href="$file.getDownloadFilePath3(record)"
  173. :download="record.fileName"
  174. >
  175. 下载
  176. </a>
  177. </a-menu-item>
  178. <a-menu-item v-if="formState.verifyStatus == '2'">
  179. <a-popconfirm title="确认下架吗?" @confirm="resourcesDown(record)">
  180. <a href="javascript:;">下架</a>
  181. </a-popconfirm>
  182. </a-menu-item>
  183. <a-menu-item >
  184. <a href="javascript:;" @click="edit(record)">编辑</a>
  185. </a-menu-item>
  186. <a-menu-item v-if="formState.verifyStatus !== '2'">
  187. <a-popconfirm title="确认删除吗?" @confirm="resourcesDelete(record)">
  188. <a href="javascript:;">删除</a>
  189. </a-popconfirm>
  190. </a-menu-item>
  191. </a-menu>
  192. </template>
  193. </a-dropdown>
  194. </div>
  195. </template>
  196. <!-- 资源管理操作列 -->
  197. <template v-if="column.key === 'action' && pageType == 'economize'">
  198. <div class="editable-cell">
  199. <a v-if="formState.verifyStatus === '1'" @click="handleAudit(record)">审核</a>
  200. <a v-if="formState.verifyStatus === '2'" @click="handlePermission(record)">权限</a>
  201. <a v-if="formState.verifyStatus === '4'" @click="handleRestore(record)">恢复</a>
  202. <a-divider type="vertical" />
  203. <a-dropdown>
  204. <a class="ant-dropdown-link">
  205. 更多
  206. <DownOutlined />
  207. </a>
  208. <template #overlay>
  209. <a-menu>
  210. <a-menu-item>
  211. <a href="javascript:;" @click="handleView(record)">预览</a>
  212. </a-menu-item>
  213. <a-menu-item>
  214. <a
  215. target="_blank"
  216. style="display: block; color: inherit"
  217. :href="$file.getDownloadFilePath3(record)"
  218. :download="record.fileName"
  219. >
  220. 下载
  221. </a>
  222. </a-menu-item>
  223. <a-menu-item v-if="formState.verifyStatus !== '1'">
  224. <a-popconfirm title="确认删除吗?" @confirm="resourcesDelete(record)">
  225. <a href="javascript:;">删除</a>
  226. </a-popconfirm>
  227. </a-menu-item>
  228. </a-menu>
  229. </template>
  230. </a-dropdown>
  231. </div>
  232. </template>
  233. </template>
  234. </a-table>
  235. <div class="dis-flex-sb margin-top">
  236. <div>
  237. <a-button @click="selectAll">选择全部</a-button>
  238. <a-button @click="invertSelection" style="margin-left: 8px">反选选择</a-button>
  239. </div>
  240. <div>
  241. <CustomPagination
  242. :total="pagination.total"
  243. :current="pagination.pageNum"
  244. :pageSize="pagination.pageSize"
  245. :showQuickJumper="true"
  246. :showSizeChanger="true"
  247. :showTotal="(total) => `共 ${total} 条数据`"
  248. @change="handlePageChange"
  249. @showSizeChange="handlePageSizeChange"
  250. />
  251. </div>
  252. </div>
  253. <!-- 权限树模态框 -->
  254. <permissionTree v-if="permissionTreeVisible" @close="permissionTreeVisible = false"></permissionTree>
  255. <!-- 审核播放模态框 -->
  256. <auditModal
  257. v-if="auditModalVisible"
  258. :recordData="publishedData"
  259. :isAudit="auditState"
  260. @confirm="auditConfirm"
  261. @close="auditModalVisible = false"
  262. ></auditModal>
  263. <!-- 资源上传模态框 -->
  264. <resourceUpload
  265. v-if="uploadModalVisible"
  266. :isState="isState"
  267. :isVerifyStatus="formState.verifyStatus"
  268. :resourcesId="editResourcesId"
  269. @close="uploadModalVisible = false"
  270. @getList="getList"
  271. ></resourceUpload>
  272. <!-- 发布模态框 -->
  273. <releaseModal v-if="releaseVisible" @close="releaseVisible = false" @confirm="releaseConfirm"></releaseModal>
  274. <div style="height: 20px"></div>
  275. <span>容量</span><span style="color: #6abe39"> {{ bToGb(storageMin) }} GB</span><span> / </span
  276. ><span style="color: red">{{ bToGb(storageMax) }} GB</span>
  277. </a-card>
  278. </template>
  279. <script setup>
  280. import { ref, onMounted } from 'vue'
  281. import { DownOutlined } from '@ant-design/icons-vue'
  282. import releaseModal from './releaseModal.vue'
  283. import resourceUpload from './resourceUpload.vue'
  284. import resourceAuditApi from '@/api/resourceAudit.js'
  285. import permissionTree from './permissionTree.vue'
  286. import auditModal from './auditModal.vue'
  287. import { getstorage } from '@/api/myResource/user'
  288. import CustomPagination from '@/components/customPagination.vue'
  289. import tool from '@/utils/tool'
  290. import { useRoute, useRouter } from 'vue-router'
  291. const router = useRouter()
  292. // eslint-disable-next-line vue/no-setup-props-destructure
  293. const { pageType } = defineProps({
  294. pageType: {
  295. type: String,
  296. default: () => {}
  297. }
  298. })
  299. const fileTypeIcons = {
  300. // 图片类
  301. jpg: 'FileImageOutlined',
  302. jpeg: 'FileImageOutlined',
  303. png: 'FileImageOutlined',
  304. gif: 'FileImageOutlined',
  305. // 文档类
  306. pdf: 'FilePdfOutlined',
  307. ppt: 'FilePptOutlined',
  308. pptx: 'FilePptOutlined',
  309. doc: 'FileWordOutlined',
  310. docx: 'FileWordOutlined',
  311. xls: 'FileExcelOutlined',
  312. xlsx: 'FileExcelOutlined',
  313. txt: 'FileTextOutlined',
  314. // 视频类
  315. mp4: 'PlaySquareOutlined',
  316. mov: 'PlaySquareOutlined',
  317. // 压缩包
  318. zip: 'FileZipOutlined',
  319. rar: 'FileZipOutlined',
  320. // 默认图标
  321. '*': 'FileOutlined'
  322. }
  323. // 数据源
  324. const dataSource = ref([])
  325. //发布按钮状态
  326. const releaseVisible = ref(false)
  327. const permissionTreeVisible = ref(false) //权限树
  328. const auditModalVisible = ref(false) //播放审核
  329. const isPublishBulk = ref(false) //是否批量发布
  330. const loading = ref(false) // 列表loading
  331. const isState = ref(0) //是否是编辑 0:新增 1:编辑
  332. const isVerifyStatus = ref(null) //未发布状态 0未发布 3已驳回
  333. const editResourcesId = ref(null) //资源id
  334. const storageMin = ref(0) //资源id
  335. const storageMax = ref(0) //资源id
  336. // 搜索值
  337. const searchValue = ref('')
  338. //课程类型
  339. const courseTypeOptions = tool.dictList('COURSE_TYPE')
  340. const suffixTypeOptions = ref([])
  341. const pagination = reactive({
  342. pageSize: 10,
  343. pageNum: 1,
  344. total: 0
  345. })
  346. const formState = reactive({
  347. fileName: null,
  348. verifyStatus: '0,3',
  349. resourcesId: null,
  350. // majorId: null, //专业
  351. collegeId: null, //院校一级id
  352. collegeTwoId: null, //院校二级id
  353. collegeThreeId: null, //院校三级id
  354. resourceType: null, //资源类型一级
  355. resourceTwoType: null, //资源类型二级
  356. suffix: null
  357. })
  358. // 添加选择状态
  359. const majorIdName = ref([])
  360. const resourceName = ref([])
  361. const majorOptions = ref([]) //专业
  362. const selectedRowKeys = ref([])
  363. const selectedRows = ref([])
  364. const publishedData = ref([]) //当前点击数据
  365. // 行选择配置
  366. const rowSelection = computed(() => {
  367. return {
  368. selectedRowKeys: selectedRowKeys.value,
  369. onChange: (keys, rows) => {
  370. selectedRowKeys.value = keys
  371. selectedRows.value = rows
  372. },
  373. onSelectAll: (selected, selectedRows, changeRows) => {
  374. if (selected) {
  375. // 全选当前页
  376. selectedRowKeys.value = dataSource.value.map((item) => item.id)
  377. selectedRows.value = dataSource.value
  378. } else {
  379. // 取消全选
  380. selectedRowKeys.value = []
  381. selectedRows.value = []
  382. }
  383. },
  384. onSelectInvert: () => {
  385. // 反选当前页
  386. const allKeys = dataSource.value.map((item) => item.id)
  387. const newSelectedKeys = allKeys.filter((key) => !selectedRowKeys.value.includes(key))
  388. selectedRowKeys.value = newSelectedKeys
  389. selectedRows.value = dataSource.value.filter((item) => newSelectedKeys.includes(item.id))
  390. }
  391. }
  392. })
  393. // 列定义
  394. const columnsUnpublished = [
  395. // {
  396. // title: '编号',
  397. // align: 'center',
  398. // dataIndex: 'fileId',
  399. // key: 'fileId'
  400. // },
  401. {
  402. title: '资源名称',
  403. align: 'center',
  404. dataIndex: 'fileName',
  405. key: 'fileName',
  406. },
  407. {
  408. title: '课件格式',
  409. align: 'center',
  410. dataIndex: 'suffix',
  411. key: 'suffix'
  412. },
  413. {
  414. title: '上传时间',
  415. dataIndex: 'uploadTime',
  416. align: 'center',
  417. key: 'uploadTime'
  418. },
  419. {
  420. title: '状态',
  421. align: 'center',
  422. key: 'verifyStatus'
  423. },
  424. {
  425. title: '资源缩略图',
  426. align: 'center',
  427. dataIndex: 'fileUrl',
  428. key: 'fileUrl'
  429. },
  430. {
  431. title: '操作',
  432. align: 'center',
  433. width: 150,
  434. key: 'action'
  435. }
  436. ]
  437. const columnsPending = [
  438. // {
  439. // title: '编号',
  440. // dataIndex: 'id',
  441. // align: 'center',
  442. // key: 'id'
  443. // },
  444. {
  445. title: '资源名称',
  446. align: 'center',
  447. dataIndex: 'fileName',
  448. key: 'fileName'
  449. },
  450. {
  451. title: '所属单位',
  452. align: 'center',
  453. dataIndex: 'collegeAllIdName',
  454. key: 'collegeAllIdName'
  455. },
  456. // {
  457. // title: '所属课程',
  458. // align: 'center',
  459. // dataIndex: 'collegeIdName',
  460. // key: 'collegeIdName'
  461. // },
  462. // {
  463. // title: '所属专业',
  464. // align: 'center',
  465. // dataIndex: 'majorIdName',
  466. // key: 'majorIdName'
  467. // },
  468. {
  469. title: '资源类型',
  470. align: 'center',
  471. dataIndex: 'resourceALLTypeName',
  472. key: 'resourceALLTypeName',
  473. width: 110
  474. },
  475. {
  476. title: '资源格式',
  477. align: 'center',
  478. dataIndex: 'suffix',
  479. key: 'suffix',
  480. width: 90
  481. },
  482. {
  483. title: '上传时间',
  484. align: 'center',
  485. dataIndex: 'uploadTime',
  486. key: 'uploadTime',
  487. width: 180
  488. },
  489. {
  490. title: '状态',
  491. align: 'center',
  492. key: 'verifyStatus',
  493. width: 100
  494. },
  495. {
  496. title: '资源缩略图',
  497. align: 'center',
  498. dataIndex: 'fileUrl',
  499. key: 'fileUrl',
  500. width: 110
  501. },
  502. {
  503. title: '操作',
  504. align: 'center',
  505. width: 140,
  506. fixed: 'right',
  507. key: 'action'
  508. }
  509. ]
  510. const columnsPublished = [...columnsPending]
  511. const columnsRecycle = [...columnsPending]
  512. const collegeMajorOptions = ref([]) //院校下拉数据
  513. const resourceTypeOptions = ref([]) //资源类型下拉数据
  514. const fileformatOptions = ref([]) //资源格式下拉数据
  515. const currentColumns = computed(() => {
  516. switch (formState.verifyStatus) {
  517. case '0':
  518. return columnsUnpublished
  519. case '1':
  520. return columnsPending
  521. case '2':
  522. return columnsPublished
  523. case '3':
  524. return columnsPublished
  525. case '4':
  526. return columnsRecycle
  527. default:
  528. return []
  529. }
  530. })
  531. const getIconColor = (suffix) => {
  532. const type = suffix?.toLowerCase()
  533. if (['jpg', 'jpeg', 'png', 'gif'].includes(type)) return '#ff4d4f' // 图片红色
  534. if (['pdf'].includes(type)) return '#f5222d' // PDF红色
  535. if (['ppt', 'pptx'].includes(type)) return '#fa8c16' // PPT橙色
  536. if (['doc', 'docx'].includes(type)) return '#1890ff' // Word蓝色
  537. if (['xls', 'xlsx'].includes(type)) return '#52c41a' // Excel绿色
  538. return '#666' // 默认灰色
  539. }
  540. const getListData = () => {
  541. loading.value = true
  542. let params = {
  543. current: pagination.pageNum,
  544. size: pagination.pageSize,
  545. verifyStatus: isVerifyStatus.value ? isVerifyStatus.value : formState.verifyStatus,
  546. fileName: formState.fileName,
  547. resourceType: formState.resourceType,
  548. resourceTwoType: formState.resourceTwoType,
  549. suffix: formState.suffix,
  550. // majorId: formState.majorId,
  551. collegeTwoId: formState.collegeTwoId,
  552. collegeId: formState.collegeId,
  553. collegeThreeId: formState.collegeThreeId,
  554. isSelf: !pageType ? 1 : 0
  555. }
  556. resourceAuditApi
  557. .page(params)
  558. .then((res) => {
  559. console.log(res, '资源审核列表')
  560. dataSource.value = res.data.records
  561. pagination.total = res.data.total
  562. loading.value = false
  563. })
  564. .catch((err) => {
  565. console.log(err)
  566. dataSource.value = []
  567. pagination.total = 0
  568. loading.value = false
  569. })
  570. }
  571. const bToMb = (b) => {
  572. if (typeof b !== 'number' || b < 0) {
  573. throw new Error('请输入有效的非负数字')
  574. }
  575. return (b / (1024 * 1024)).toFixed(2) // 保留两位小数
  576. }
  577. const bToGb = (b) => {
  578. if (typeof b !== 'number' || b < 0) {
  579. throw new Error('请输入有效的非负数字')
  580. }
  581. return (b / (1024 * 1024 * 1024)).toFixed(2) // 保留两位小数
  582. }
  583. const changeCollegeMajor = (value, selectedOptions) => {
  584. console.log('Selected:', value, selectedOptions)
  585. if (!value) {
  586. majorIdName.value = ''
  587. return false
  588. }
  589. majorIdName.value = selectedOptions.map((it) => it.name).join('/')
  590. formState.collegeId = value[0] || null
  591. formState.collegeTwoId = value[1] || null
  592. formState.collegeThreeId = value[2] || null
  593. if (selectedOptions.length) {
  594. // 获取选中的最后一级
  595. const lastSelected = selectedOptions[selectedOptions.length - 1]
  596. console.log(lastSelected, '最后一级id')
  597. getCollegeMajor(lastSelected.id)
  598. }
  599. }
  600. const changeCollegeResource = (value, selectedOptions) => {
  601. console.log('Selected:', value, selectedOptions)
  602. if (!value) {
  603. resourceName.value = ''
  604. formState.resourceType = undefined
  605. formState.resourceTwoType = undefined
  606. return false
  607. }
  608. resourceName.value = selectedOptions.map((it) => it.name).join('/')
  609. formState.resourceType = value[0] || undefined
  610. formState.resourceTwoType = value[1] || undefined
  611. console.log('已经修改:', formState)
  612. }
  613. const getList = () => {
  614. getListData()
  615. uploadModalVisible.value = false
  616. }
  617. //院系组织查询
  618. const getOrgTreeSelector = () => {
  619. resourceAuditApi
  620. .orgTreeSelector()
  621. .then((res) => {
  622. console.log(res.data, '获取组织树选择器')
  623. collegeMajorOptions.value = res.data
  624. })
  625. .catch((err) => {
  626. console.log(err)
  627. })
  628. }
  629. //资源类型下拉查询
  630. const getResourceTypeTree = () => {
  631. resourceAuditApi
  632. .resourceTypeTree()
  633. .then((res) => {
  634. console.log(res.data, '资源类型下拉')
  635. resourceTypeOptions.value = res.data
  636. })
  637. .catch((err) => {
  638. console.log(err)
  639. })
  640. }
  641. //资源格式下拉查询
  642. const getFileformat = () => {
  643. resourceAuditApi
  644. .fileformat()
  645. .then((res) => {
  646. console.log(res.data, '资源类型下拉')
  647. fileformatOptions.value = res.data.records
  648. })
  649. .catch((err) => {
  650. console.log(err)
  651. })
  652. }
  653. const getCollegeMajor = (id) => {
  654. resourceAuditApi
  655. .zyselect({ collegeId: id })
  656. .then((res) => {
  657. console.log(res.data, '专业下拉数据')
  658. majorOptions.value = res.data
  659. })
  660. .catch((err) => {
  661. console.log(err)
  662. })
  663. }
  664. // 方法
  665. const handleSearch = () => {
  666. console.log('Search:', searchValue.value)
  667. getListData()
  668. }
  669. const handleReset = () => {
  670. searchValue.value = null
  671. majorIdName.value = null
  672. resourceName.value = null
  673. isVerifyStatus.value = null
  674. if (formState.verifyStatus == '3' || formState.verifyStatus == '0') {
  675. formState.verifyStatus = '0,3'
  676. }
  677. formState.fileName = null
  678. formState.resourceType = null
  679. formState.resourceTwoType = null
  680. formState.suffix = null
  681. formState.collegeTwoId = null
  682. // formState.majorId = null
  683. formState.collegeId = null
  684. formState.collegeThreeId = null
  685. getListData()
  686. }
  687. const tabChange = () => {
  688. dataSource.value = []
  689. getListData()
  690. }
  691. //发布
  692. const handlePublish = (record) => {
  693. publishedData.value = record
  694. releaseVisible.value = true
  695. isPublishBulk.value = false
  696. }
  697. // 批量发布方法
  698. const batchPublish = () => {
  699. if (selectedRows.value.length === 0) {
  700. message.warning('请至少选择一条记录')
  701. return
  702. }
  703. isState.value = 0
  704. isPublishBulk.value = true
  705. releaseVisible.value = true
  706. }
  707. // 全选当前页数据
  708. const selectAll = () => {
  709. selectedRowKeys.value = dataSource.value.map((item) => item.id)
  710. selectedRows.value = dataSource.value
  711. }
  712. // 反选当前页数据
  713. const invertSelection = () => {
  714. const allKeys = dataSource.value.map((item) => item.id)
  715. const newSelectedKeys = allKeys.filter((key) => !selectedRowKeys.value.includes(key))
  716. selectedRowKeys.value = newSelectedKeys
  717. selectedRows.value = dataSource.value.filter((item) => newSelectedKeys.includes(item.id))
  718. }
  719. //发布确定
  720. const releaseConfirm = (obj) => {
  721. console.log(obj, selectedRows.value, '传回来的数据')
  722. releaseVisible.value = false
  723. if (isPublishBulk.value) {
  724. // const batchParams = selectedRows.value.map((item) => ({
  725. // id: item.id,
  726. // coverImage: item.coverImage,
  727. // resourceDesc: item.resourceDesc,
  728. // verifyStatus: 1
  729. // }))
  730. const params = {
  731. ids: selectedRows.value.map((item) => item.id).join(','),
  732. coverImage: obj.coverImageId,
  733. resourceDesc: obj.courseDesc,
  734. verifyStatus: 1
  735. }
  736. console.log(params, '批量发布参数')
  737. handleRelease(params)
  738. } else {
  739. const params = {
  740. ids: publishedData.value.id,
  741. coverImage: obj.coverImageId,
  742. resourceDesc: obj.courseDesc,
  743. verifyStatus: 1
  744. }
  745. console.log(params, '发布参数')
  746. handleRelease(params)
  747. }
  748. }
  749. // updateStatus接口调用
  750. const handleRelease = (Params) => {
  751. resourceAuditApi
  752. .updateStatus(Params)
  753. .then((res) => {
  754. getListData()
  755. selectedRowKeys.value = []
  756. })
  757. .catch((err) => {
  758. console.error(err)
  759. })
  760. }
  761. const auditState = ref(null)
  762. const handleAudit = (record) => {
  763. // console.log('Audit:', record)
  764. // publishedData.value = record
  765. // auditState.value = true
  766. // auditModalVisible.value = true
  767. router.push({
  768. path: '/portal/resourceDetails',
  769. query: {
  770. id: record.id,
  771. state: 1,
  772. audit: 1
  773. }
  774. })
  775. }
  776. const handleView = (record) => {
  777. router.push({
  778. path: '/portal/resourceDetails',
  779. query: {
  780. id: record.id,
  781. state: 1
  782. }
  783. })
  784. // publishedData.value = record
  785. // auditState.value = false
  786. // auditModalVisible.value = true
  787. }
  788. const handleDownload = (record) => {
  789. resourceAuditApi
  790. .downloadfile({
  791. userFileId: record.fileId,
  792. shareBatchNum: record.shareBatchNum == null ? '' : record.shareBatchNum,
  793. extractionCode: record.extractionCode == null ? '' : record.extractionCode,
  794. admin: true
  795. })
  796. .then((res) => {
  797. console.log('下载成功:', res)
  798. // 创建Blob对象
  799. const url = window.URL.createObjectURL(new Blob([res]))
  800. const link = document.createElement('a')
  801. link.href = url
  802. link.download = record.fileName || `file_${record.id}.${record.suffix}`
  803. document.body.appendChild(link)
  804. link.click()
  805. window.URL.revokeObjectURL(url)
  806. document.body.removeChild(link)
  807. })
  808. .catch((err) => {
  809. console.error(err)
  810. })
  811. }
  812. const handlePermission = (record) => {
  813. console.log('Permission:', record)
  814. permissionTreeVisible.value = true
  815. }
  816. const auditConfirm = (obj) => {
  817. console.log('auditConfirm:', obj)
  818. const params = {
  819. ids: obj.id,
  820. verifyStatus: obj.auditResult
  821. }
  822. resourceAuditApi
  823. .updateStatus(params)
  824. .then((res) => {
  825. if (res.code == 200) {
  826. auditModalVisible.value = false
  827. }
  828. getListData()
  829. })
  830. .catch((err) => {
  831. console.error(err)
  832. })
  833. }
  834. const handleDelete = (record) => {
  835. console.log('Delete:', record)
  836. }
  837. const handleRestore = (record) => {
  838. const params = {
  839. ids: record.id,
  840. verifyStatus: 0
  841. }
  842. resourceAuditApi
  843. .updateStatus(params)
  844. .then((res) => {
  845. getListData()
  846. })
  847. .catch((err) => {
  848. console.error(err)
  849. })
  850. }
  851. //资源编辑
  852. const edit = (record) => {
  853. console.log('Restore:', record)
  854. uploadModalVisible.value = true
  855. console.log('打开什么呢:', formState.verifyStatus)
  856. isState.value = 1
  857. formState.verifyStatus = '0,3'
  858. editResourcesId.value = record.id
  859. }
  860. //资源删除
  861. const resourcesDelete = (record) => {
  862. if (formState.verifyStatus == 4) {
  863. const params = [
  864. {
  865. id: record.id
  866. }
  867. ]
  868. resourceAuditApi
  869. .deletefile(params)
  870. .then((res) => {
  871. getListData()
  872. })
  873. .catch((err) => {
  874. console.error(err)
  875. })
  876. } else {
  877. const params = {
  878. ids: record.id,
  879. verifyStatus: 4
  880. }
  881. resourceAuditApi
  882. .updateStatus(params)
  883. .then((res) => {
  884. getListData()
  885. })
  886. .catch((err) => {
  887. console.error(err)
  888. })
  889. }
  890. }
  891. const resourcesDown = (record) => {
  892. const params =
  893. {
  894. ids: record.id,
  895. verifyStatus : 0
  896. }
  897. resourceAuditApi
  898. .updateStatus(params)
  899. .then((res) => {
  900. getListData()
  901. })
  902. .catch((err) => {
  903. console.error(err)
  904. })
  905. }
  906. // 上传资源模态框
  907. const uploadModalVisible = ref(false)
  908. // 显示上传模态框
  909. const showUploadModal = () => {
  910. isState.value = 0
  911. uploadModalVisible.value = true
  912. }
  913. // 翻页
  914. const handlePageChange = (page) => {
  915. pagination.pageNum = page
  916. getListData()
  917. }
  918. // 每页条数
  919. const handlePageSizeChange = (pageNum, size) => {
  920. pagination.pageNum = 1
  921. pagination.pageSize = size
  922. getListData()
  923. }
  924. onMounted(() => {
  925. if (pageType == 'economize') {
  926. formState.verifyStatus = '1'
  927. }
  928. getOrgTreeSelector()
  929. getFileformat()
  930. getResourceTypeTree()
  931. getListData()
  932. getstorage().then((res) => {
  933. console.log('容量', res)
  934. storageMin.value = res.data.storageSize
  935. storageMax.value = res.data.totalStorageSize
  936. })
  937. })
  938. </script>
  939. <style scoped>
  940. .editable-cell {
  941. position: relative;
  942. }
  943. .ant-dropdown-link {
  944. margin-left: 8px;
  945. }
  946. .upload-area {
  947. border: 2px dashed #3ca9f5;
  948. padding: 40px;
  949. text-align: center;
  950. }
  951. .upload-area p {
  952. margin: 10px 0;
  953. }
  954. .file-item {
  955. display: flex;
  956. align-items: center;
  957. margin: 10px 0;
  958. }
  959. .file-item .ant-progress {
  960. flex: 1;
  961. margin: 0 10px;
  962. }
  963. </style>