index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <a-spin :spinning="state.downloadLoading" tip="下载中...">
  3. <div class="mediaDetail">
  4. <Search :fetchList="fetchList" :selectedRowKeys="state.selectedRowKeys" :onClickDownload="onClickBatchDownload"
  5. :onClickDelete="onClickBatchDelete" :onClickSearch="onClickSearch" :onClickReset="onClickReset" />
  6. <div style="background: #FFFFFF;padding: 20px;">
  7. <div class="mediaDetail-info">
  8. <div class="mediaDetail-info-left">
  9. <div style="color: #7C7C7C;cursor: pointer;" @click="onClickGoBack">
  10. 媒体文件
  11. </div>
  12. <div style="margin: 0 10px;">
  13. /
  14. </div>
  15. <div>
  16. {{ state.dirName }}
  17. </div>
  18. </div>
  19. <div class="mediaDetail-info-right">
  20. <div class="mediaDetail-info-right-text">
  21. <div>
  22. 已选/全部:
  23. </div>
  24. <div>
  25. {{ state.selectedRowKeys.length }}/{{ paginationConfig.total }}
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <a-table :scroll="{ x: '100%', y: 500 }" rowKey="file_id"
  31. :loading="state.listLoading" :columns="columns" :dataSource="state.list" :rowClassName="rowClassName"
  32. :pagination="paginationConfig"
  33. :rowSelection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
  34. <!-- 文件夹名称 -->
  35. <template #file_name="{ record }">
  36. <a-tooltip :title="record.file_name">
  37. <div class="fileName">
  38. <div class="fileName-cover" @click="onClickLookFile(record)">
  39. <img class="fileName-cover-img" :src="record.thumbnail_url" />
  40. <img class="fileName-cover-icon" :src="panoramaSrc" v-if="record.media_type === 3" />
  41. <img class="fileName-cover-icon" :src="videoSrc" v-else-if="record.media_type === 4" />
  42. </div>
  43. <div style="margin-left: 5px;">
  44. <a-input v-model:value="record.file_name" v-if="state.editableData[record.file_id]" />
  45. <div @click="onClickLookFile(record)" v-else>
  46. {{ record.file_name }}
  47. </div>
  48. </div>
  49. </div>
  50. </a-tooltip>
  51. </template>
  52. <!-- 操作 -->
  53. <template #action="{ record }">
  54. <!-- 编辑态操作 -->
  55. <div v-if="state.editableData[record.file_id]">
  56. <a-tooltip title="确定">
  57. <CheckOutlined style="color: #28d445;margin-right: 10px;" @click="onClickSave(record)" />
  58. </a-tooltip>
  59. <a-tooltip title="取消">
  60. <CloseOutlined style="color: #e70102;" @click="() => delete state.editableData[record.file_id]" />
  61. </a-tooltip>
  62. </div>
  63. <!-- 非编辑态操作 -->
  64. <div class="flex-align-center flex-row" style="color: #2d8cf0" v-else>
  65. <div v-if="[1, 3].includes(record.media_type)">
  66. <a-tooltip title="在地图上加载" v-if="!record.element_id">
  67. <AimOutlined style="margin-right: 10px;" @click="onClickCreateMapElement(record.file_id)" />
  68. </a-tooltip>
  69. <a-tooltip title="在地图上取消加载" v-else>
  70. <AimOutlined style="color: #e70102;margin-right: 10px;"
  71. @click="onClickDeleteMapElement(record.file_id)" />
  72. </a-tooltip>
  73. </div>
  74. <a-tooltip title="重命名" v-else-if="record.media_type === 4">
  75. <EditOutlined style="margin-right: 10px;" @click="onClickRechristen(record)" />
  76. </a-tooltip>
  77. <a-tooltip title="删除" v-else-if="record.media_type === 2">
  78. <DeleteOutlined style="margin-right: 10px;" @click="onClickDelete(record)" />
  79. </a-tooltip>
  80. <a-tooltip title="压缩下载">
  81. <DownloadOutlined @click="onClickDownload(record)" />
  82. </a-tooltip>
  83. </div>
  84. </template>
  85. </a-table>
  86. </div>
  87. </div>
  88. </a-spin>
  89. <FileInfo :fileId="state.fileId" :fileList="state.list" :onClose="fileInfoOnClickClose"
  90. v-if="state.fileInfoVisible" />
  91. </template>
  92. <script lang="ts" setup>
  93. import { reactive, onMounted } from 'vue';
  94. import { message } from 'ant-design-vue';
  95. import { EditOutlined, DeleteOutlined, DownloadOutlined, AimOutlined, CheckOutlined, CloseOutlined } from '@ant-design/icons-vue';
  96. import Search from './components/Search.vue';
  97. import FileInfo from './components/FileInfo.vue';
  98. import panoramaSrc from '/@/assets/media/panorama.svg';
  99. import videoSrc from '/@/assets/media/video.svg';
  100. import { apis } from '/@/api/custom';
  101. import router from '/@/router/index';
  102. import { downloadFile } from '/@/utils/common';
  103. import { downloadMediaFile } from '/@/api/media';
  104. import { getWorkspaceId } from '/@/utils/index'
  105. interface State {
  106. query: any,
  107. listLoading: boolean,
  108. list: any[],
  109. dirName: string,
  110. selectedRowKeys: string[],
  111. editableData: {
  112. [key: string]: string,
  113. },
  114. downloadLoading: boolean,
  115. fileId: string,
  116. fileInfoVisible: boolean,
  117. };
  118. const state: State = reactive({
  119. query: undefined,
  120. listLoading: false,
  121. list: [],
  122. dirName: '',
  123. selectedRowKeys: [],
  124. editableData: {},
  125. downloadLoading: false,
  126. fileId: '',
  127. fileInfoVisible: false,
  128. })
  129. const paginationConfig = reactive({
  130. pageSizeOptions: ['20', '50', '100'],
  131. showQuickJumper: true,
  132. showSizeChanger: true,
  133. pageSize: 20,
  134. current: 1,
  135. total: 0,
  136. onChange: async (current: number) => {
  137. paginationConfig.current = current;
  138. await fetchList();
  139. },
  140. onShowSizeChange: async (current: number, pageSize: number) => {
  141. paginationConfig.pageSize = pageSize;
  142. await fetchList();
  143. }
  144. })
  145. const fetchList = async () => {
  146. state.listLoading = true;
  147. try {
  148. const dirId = router.currentRoute.value.params?.id;
  149. const res = await apis.fetchFileListByFolder(dirId as string, {
  150. ...state.query,
  151. page: paginationConfig.current,
  152. page_size: paginationConfig.pageSize,
  153. });
  154. state.dirName = res.data.group_name;
  155. state.list = res.data.list;
  156. paginationConfig.current = res.data.pagination.page;
  157. paginationConfig.pageSize = res.data.pagination.page_size;
  158. paginationConfig.total = res.data.pagination.total;
  159. } catch (e) {
  160. console.error(e);
  161. } finally {
  162. state.listLoading = false;
  163. }
  164. }
  165. onMounted(async () => {
  166. await fetchList();
  167. })
  168. const columns = [
  169. {
  170. title: '文件名称',
  171. dataIndex: 'file_name',
  172. width: 250,
  173. ellipsis: true,
  174. sorter: (a: any, b: any) => a.file_name.localeCompare(b.file_name),
  175. slots: { customRender: 'file_name' }
  176. },
  177. {
  178. title: '拍摄负载',
  179. dataIndex: 'payload',
  180. width: 150,
  181. ellipsis: true,
  182. },
  183. {
  184. title: '容量大小',
  185. dataIndex: 'size',
  186. width: 150,
  187. ellipsis: true,
  188. customRender: ({ text }: any) => {
  189. return text > 0 ? (text / 1024 / 1024).toFixed(1) + 'M' : '--';
  190. }
  191. },
  192. {
  193. title: '创建时间',
  194. dataIndex: 'create_time',
  195. width: 200,
  196. sorter: (a: any, b: any) => a.create_time.localeCompare(b.create_time),
  197. },
  198. {
  199. title: '媒体类型',
  200. dataIndex: 'media_type_text',
  201. width: 100,
  202. customRender: ({ text }: any) => {
  203. return text || '--';
  204. }
  205. },
  206. {
  207. title: '文件类型',
  208. dataIndex: 'picture_type',
  209. width: 100,
  210. customRender: ({ text }: any) => {
  211. return text || '--';
  212. }
  213. },
  214. {
  215. title: '操作',
  216. dataIndex: 'actions',
  217. fixed: 'right',
  218. width: 80,
  219. slots: { customRender: 'action' },
  220. },
  221. ]
  222. const rowClassName = (record: any, index: number) => {
  223. const className = []
  224. if ((index & 1) === 0) {
  225. className.push('table-striped')
  226. }
  227. return className.toString().replaceAll(',', ' ')
  228. }
  229. // 点击批量下载
  230. const onClickBatchDownload = async () => {
  231. state.downloadLoading = true;
  232. try {
  233. const bold = await apis.batchDownloadFile({
  234. id: state.selectedRowKeys.join(',')
  235. });
  236. const data = new Blob([bold], { type: 'application/zip' });
  237. downloadFile(data, state.dirName);
  238. } catch (e) {
  239. console.error(e);
  240. } finally {
  241. state.downloadLoading = false;
  242. }
  243. }
  244. // 点击批量删除
  245. const onClickBatchDelete = async () => {
  246. const canDeleteList = state.list.filter(item => state.selectedRowKeys.includes(item.file_id) && item.media_type === 2);
  247. const data = {
  248. id: canDeleteList.map(item => item.file_id).join(',')
  249. }
  250. await apis.batchDeletePicture(data);
  251. await fetchList()
  252. }
  253. // 点击搜索
  254. const onClickSearch = async (query: any) => {
  255. state.query = query;
  256. await fetchList();
  257. }
  258. // 点击重置
  259. const onClickReset = async (query: any) => {
  260. state.query = query;
  261. await fetchList();
  262. }
  263. // 点击返回
  264. const onClickGoBack = () => {
  265. router.push({ path: '/media' })
  266. }
  267. // 勾选
  268. const onSelectChange = (selectedRowKeys: string[]) => {
  269. state.selectedRowKeys = selectedRowKeys;
  270. }
  271. // 点击查看文件
  272. const onClickLookFile = (record: any) => {
  273. state.fileId = record.file_id;
  274. state.fileInfoVisible = true;
  275. }
  276. // 文件信息-点击关闭
  277. const fileInfoOnClickClose = async () => {
  278. state.fileId = '';
  279. state.fileInfoVisible = false;
  280. await fetchList();
  281. }
  282. // 点击在地图上加载
  283. const onClickCreateMapElement = async (id: string) => {
  284. try {
  285. await apis.createMapElement(id);
  286. await fetchList();
  287. message.success('在地图上加载成功');
  288. } catch (e: any) {
  289. console.error(e);
  290. }
  291. }
  292. // 点击在地图上取消加载
  293. const onClickDeleteMapElement = async (id: string) => {
  294. try {
  295. await apis.deleteMapElement(id);
  296. await fetchList();
  297. message.success('在地图上取消加载成功');
  298. } catch (e: any) {
  299. console.error(e);
  300. }
  301. }
  302. // 点击重命名
  303. const onClickRechristen = (record: any) => {
  304. state.editableData[record.file_id] = record;
  305. }
  306. // 点击保存
  307. const onClickSave = async (record: any) => {
  308. delete state.editableData[record.file_id];
  309. await apis.updateFileName(record.file_id, { file_name: record.file_name })
  310. await fetchList();
  311. }
  312. // 点击删除
  313. const onClickDelete = async (record: any) => {
  314. const data = {
  315. id: record.file_id
  316. }
  317. await apis.batchDeletePicture(data);
  318. }
  319. // 点击下载
  320. const onClickDownload = async (record: any) => {
  321. state.downloadLoading = true;
  322. try {
  323. const workspaceId: string = getWorkspaceId();
  324. const res = await downloadMediaFile(workspaceId, record.file_id)
  325. if (!res) {
  326. return
  327. }
  328. const data = new Blob([res])
  329. downloadFile(data, record.file_name)
  330. } catch (e) {
  331. console.error(e);
  332. } finally {
  333. state.downloadLoading = false;
  334. }
  335. }
  336. </script>
  337. <style lang="scss">
  338. .mediaDetail {
  339. padding: 20px;
  340. &-info {
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: center;
  344. margin-bottom: 20px;
  345. &-left {
  346. display: flex;
  347. align-items: center;
  348. }
  349. &-right {
  350. display: flex;
  351. align-items: center;
  352. &-text {
  353. display: flex;
  354. align-items: center;
  355. margin-right: 20px;
  356. }
  357. }
  358. }
  359. .fileName {
  360. display: flex;
  361. align-items: center;
  362. cursor: pointer;
  363. &-cover {
  364. position: relative;
  365. &-img {
  366. width: 36px;
  367. height: 36px;
  368. }
  369. &-icon {
  370. width: 20px;
  371. height: 20px;
  372. position: absolute;
  373. z-index: 2;
  374. top: 50%;
  375. left: 50%;
  376. transform: translate(-50%, -50%);
  377. }
  378. }
  379. }
  380. }
  381. .ant-table {
  382. border-top: 1px solid rgb(0, 0, 0, 0.06);
  383. border-bottom: 1px solid rgb(0, 0, 0, 0.06);
  384. }
  385. .ant-table-tbody tr td {
  386. border: 0;
  387. }
  388. .table-striped {
  389. background-color: #f7f9fa;
  390. }
  391. .ant-card-body {
  392. padding: 0 10px 10px;
  393. }
  394. </style>