index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="mediaDetail">
  3. <Search :selectedRowKeys="state.selectedRowKeys" :onClickDownload="onClickBatchDownload"
  4. :onClickSearch="async () => { }" :onClickReset="async () => { }" />
  5. <div style="background: #FFFFFF;padding: 20px;">
  6. <div class="mediaDetail-info">
  7. <div class="mediaDetail-info-left">
  8. <div style="color: #7C7C7C;cursor: pointer;" @click="onClickGoBack">
  9. 媒体文件
  10. </div>
  11. <div style="margin: 0 10px;">
  12. /
  13. </div>
  14. <div>
  15. {{ 'DJI_20240624143929_0112_V.JPG' }}
  16. </div>
  17. </div>
  18. <div class="mediaDetail-info-right">
  19. <div class="mediaDetail-info-right-text">
  20. <div>
  21. 已选/全部:
  22. </div>
  23. <div>
  24. 0/175
  25. </div>
  26. </div>
  27. <a-button style="padding:0 5px;" :type="state.mode === 'table' ? 'primary' : 'default'"
  28. :ghost="state.mode === 'table'" size="small" @click="state.mode = 'table'">
  29. <MenuOutlined />
  30. </a-button>
  31. <a-button style="padding:0 5px;" :type="state.mode === 'list' ? 'primary' : 'default'"
  32. :ghost="state.mode === 'list'" size="small" @click="state.mode = 'list'">
  33. <AppstoreOutlined />
  34. </a-button>
  35. </div>
  36. </div>
  37. <div class="mediaDetail-table" v-if="state.mode === 'table'">
  38. <a-table :scroll="{ x: '100%', y: 500 }" :childrenColumnName="null" rowKey="file_id"
  39. :loading="state.listLoading" :columns="columns" :dataSource="state.list" :rowClassName="rowClassName"
  40. :pagination="paginationConfig"
  41. :rowSelection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
  42. <!-- 文件夹名称 -->
  43. <template #file_name="{ record }">
  44. <a-tooltip :title="record.file_name">
  45. <div class="fileName" @click="onClickLookFile(record)">
  46. <div>
  47. <img :src="record" v-if="1">
  48. <img :src="record" v-else>
  49. </div>
  50. <div>
  51. {{ record.file_name }}
  52. </div>
  53. </div>
  54. </a-tooltip>
  55. </template>
  56. <!-- 操作 -->
  57. <template #action="{ record }">
  58. <div class="flex-align-center flex-row" style="color: #2d8cf0">
  59. <a-tooltip title="照片位置" v-if="1">
  60. <EnvironmentOutlined style="margin-right: 10px;" @click="onClickTrajectory" />
  61. </a-tooltip>
  62. <a-tooltip title="重命名" v-else-if="1">
  63. <EditOutlined style="margin-right: 10px;" @click="onClickTrajectory" />
  64. </a-tooltip>
  65. <a-tooltip title="删除" v-else-if="1">
  66. <DeleteOutlined style="margin-right: 10px;" @click="onClickTrajectory" />
  67. </a-tooltip>
  68. <a-tooltip title="压缩下载">
  69. <DownloadOutlined @click="onClickDownload(record)" />
  70. </a-tooltip>
  71. </div>
  72. </template>
  73. </a-table>
  74. </div>
  75. <div class="mediaDetail-list" v-else>
  76. <a-list :grid="{ gutter: 16, xs: 1, sm: 2, md: 3, lg: 4, xl: 8, xxl: 12 }" :loading="state.listLoading"
  77. :dataSource="state.list" :pagination="paginationConfig">
  78. <template #renderItem="{ item }">
  79. <a-list-item>
  80. <a-card hoverable @click="onClickFile(item)">
  81. <template #cover>
  82. <div style="display: flex;justify-content:center;align-items: center;">
  83. <img style="width: 70%;" :src="fileSrc" />
  84. </div>
  85. </template>
  86. <a-card-meta>
  87. <template #description>
  88. <div>
  89. {{ item.file_name }}
  90. </div>
  91. </template>
  92. </a-card-meta>
  93. </a-card>
  94. </a-list-item>
  95. </template>
  96. </a-list>
  97. </div>
  98. </div>
  99. </div>
  100. <ImageModal :visible="state.imageModalVisible" :onClose="imageModalOnClickClose" />
  101. </template>
  102. <script lang="ts" setup>
  103. import { reactive, onMounted } from 'vue';
  104. import { MenuOutlined, AppstoreOutlined, EditOutlined, DeleteOutlined, DownloadOutlined, EnvironmentOutlined } from '@ant-design/icons-vue';
  105. import Search from './components/Search.vue';
  106. import ImageModal from './components/ImageModal.vue';
  107. import { getMediaFiles, downloadMediaFile } from '/@/api/media';
  108. import { downloadFile } from '/@/utils/common';
  109. import router from '/@/router/index';
  110. interface State {
  111. workspaceId: string,
  112. listLoading: boolean,
  113. list: any[],
  114. selectedRowKeys: string[],
  115. mode: 'table' | 'list',
  116. imageModalVisible: boolean,
  117. };
  118. const state: State = reactive({
  119. workspaceId: localStorage.getItem('workspace_id') || '',
  120. listLoading: false,
  121. list: [],
  122. selectedRowKeys: [],
  123. mode: 'table',
  124. imageModalVisible: false,
  125. })
  126. const paginationConfig = reactive({
  127. pageSizeOptions: ['20', '50', '100'],
  128. showQuickJumper: true,
  129. showSizeChanger: true,
  130. pageSize: 20,
  131. current: 1,
  132. total: 0,
  133. onChange: async (current: number) => {
  134. paginationConfig.current = current;
  135. await fetchList();
  136. },
  137. onShowSizeChange: async (current: number, pageSize: number) => {
  138. paginationConfig.pageSize = pageSize;
  139. await fetchList();
  140. }
  141. })
  142. const fetchList = async () => {
  143. state.listLoading = true;
  144. try {
  145. const res = await getMediaFiles(state.workspaceId, { page: paginationConfig.current, page_size: paginationConfig.pageSize });
  146. state.list = res.data.list;
  147. paginationConfig.current = res.data.pagination.page;
  148. paginationConfig.pageSize = res.data.pagination.page_size;
  149. paginationConfig.total = res.data.pagination.total;
  150. } catch (e) {
  151. console.error(e);
  152. } finally {
  153. state.listLoading = false;
  154. }
  155. }
  156. onMounted(async () => {
  157. await fetchList();
  158. })
  159. const columns = [
  160. {
  161. title: '文件名称',
  162. dataIndex: 'file_name',
  163. width: 250,
  164. ellipsis: true,
  165. sorter: (a: any, b: any) => a.file_name.localeCompare(b.file_name),
  166. slots: { customRender: 'file_name' }
  167. },
  168. {
  169. title: '拍摄负载',
  170. dataIndex: 'payload',
  171. width: 150,
  172. ellipsis: true,
  173. },
  174. {
  175. title: '容量大小',
  176. dataIndex: 'is_original',
  177. width: 150,
  178. ellipsis: true,
  179. },
  180. {
  181. title: '创建时间',
  182. dataIndex: 'create_time',
  183. width: 200,
  184. sorter: (a: any, b: any) => a.create_time.localeCompare(b.create_time),
  185. },
  186. {
  187. title: '媒体类型',
  188. dataIndex: 'create_time',
  189. width: 150,
  190. },
  191. {
  192. title: '照片类型',
  193. dataIndex: 'create_time',
  194. width: 150,
  195. },
  196. {
  197. title: '操作',
  198. dataIndex: 'actions',
  199. fixed: 'right',
  200. width: 80,
  201. slots: { customRender: 'action' },
  202. },
  203. ]
  204. const rowClassName = (record: any, index: number) => {
  205. const className = []
  206. if ((index & 1) === 0) {
  207. className.push('table-striped')
  208. }
  209. return className.toString().replaceAll(',', ' ')
  210. }
  211. // 点击批量下载
  212. const onClickBatchDownload = async () => {
  213. console.log(state.selectedRowKeys, '点击批量下载');
  214. }
  215. // 点击返回
  216. const onClickGoBack = () => {
  217. router.push({ path: '/media' })
  218. }
  219. // 勾选
  220. const onSelectChange = (selectedRowKeys: string[]) => {
  221. state.selectedRowKeys = selectedRowKeys;
  222. }
  223. // 点击查看文件
  224. const onClickLookFile = (record: any) => {
  225. state.imageModalVisible = true;
  226. }
  227. // 图片弹出层-点击关闭
  228. const imageModalOnClickClose = () => {
  229. state.imageModalVisible = false;
  230. }
  231. // 点击下载
  232. const onClickDownload = async (record: any) => {
  233. state.listLoading = true;
  234. try {
  235. const res = await downloadMediaFile(state.workspaceId, record.file_id);
  236. if (!res) {
  237. return
  238. }
  239. const data = new Blob([res]);
  240. downloadFile(data, record.file_name);
  241. } catch (e) {
  242. console.error(e);
  243. } finally {
  244. state.listLoading = false;
  245. }
  246. }
  247. // 点击轨迹回放
  248. const onClickTrajectory = () => {
  249. router.push({ path: '/trajectory' })
  250. }
  251. </script>
  252. <style lang="scss">
  253. .mediaDetail {
  254. padding: 20px;
  255. &-info {
  256. display: flex;
  257. justify-content: space-between;
  258. align-items: center;
  259. margin-bottom: 20px;
  260. &-left {
  261. display: flex;
  262. align-items: center;
  263. }
  264. &-right {
  265. display: flex;
  266. align-items: center;
  267. &-text {
  268. display: flex;
  269. align-items: center;
  270. margin-right: 20px;
  271. }
  272. }
  273. }
  274. .fileName {
  275. display: flex;
  276. align-items: center;
  277. cursor: pointer;
  278. img {
  279. width: 36px;
  280. height: 36px;
  281. margin-right: 5px;
  282. }
  283. }
  284. }
  285. .ant-table {
  286. border-top: 1px solid rgb(0, 0, 0, 0.06);
  287. border-bottom: 1px solid rgb(0, 0, 0, 0.06);
  288. }
  289. .ant-table-tbody tr td {
  290. border: 0;
  291. }
  292. .table-striped {
  293. background-color: #f7f9fa;
  294. }
  295. .ant-card-body {
  296. padding: 0 10px 10px;
  297. }
  298. </style>