index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <a-spin :spinning="state.downloadLoading" tip="下载中...">
  3. <div class="mediaList">
  4. <Search :mode="state.mode" :selectedRowKeys="state.selectedRowKeys" :onClickDownload="onClickBatchDownload"
  5. :onClickSearch="onClickSearch" :onClickReset="onClickReset" />
  6. <div style="background: #FFFFFF;padding: 20px;">
  7. <div class="mediaList-info">
  8. <div>
  9. 媒体文件
  10. </div>
  11. <div class="mediaList-info-right">
  12. <div class="mediaList-info-right-text">
  13. <div>
  14. 已选/全部:
  15. </div>
  16. <div>
  17. {{ state.selectedRowKeys.length }}/{{ paginationConfig.total }}
  18. </div>
  19. </div>
  20. <a-button style="padding:0 5px;" :type="state.mode === 'table' ? 'primary' : 'default'"
  21. :ghost="state.mode === 'table'" size="small" @click="state.mode = 'table'">
  22. <MenuOutlined />
  23. </a-button>
  24. <a-button style="padding:0 5px;" :type="state.mode === 'list' ? 'primary' : 'default'"
  25. :ghost="state.mode === 'list'" size="small" @click="state.mode = 'list'">
  26. <AppstoreOutlined />
  27. </a-button>
  28. </div>
  29. </div>
  30. <div class="mediaList-table" v-if="state.mode === 'table'">
  31. <a-table :scroll="{ x: '100%', y: 500 }" :childrenColumnName="null" rowKey="id" :loading="state.listLoading"
  32. :columns="columns" :dataSource="state.list" :rowClassName="rowClassName" :pagination="paginationConfig"
  33. :rowSelection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
  34. <!-- 文件夹名称 -->
  35. <template #dir_name="{ record }">
  36. <a-tooltip :title="record.dir_name">
  37. <div class="fileName" @click="onClickFile(record)">
  38. <img :src="fileSrc">
  39. <div>
  40. {{ record.dir_name }}
  41. </div>
  42. </div>
  43. </a-tooltip>
  44. </template>
  45. <!-- 操作 -->
  46. <template #action="{ record }">
  47. <a-tooltip title="压缩下载">
  48. <DownloadOutlined style="color: #2d8cf0;" @click="onClickDownload(record)" />
  49. </a-tooltip>
  50. </template>
  51. </a-table>
  52. </div>
  53. <div class="mediaList-list" v-else>
  54. <a-list :grid="{ gutter: 16, xs: 1, sm: 2, md: 3, lg: 4, xl: 8, xxl: 12 }" :loading="state.listLoading"
  55. :dataSource="state.list" :pagination="paginationConfig">
  56. <template #renderItem="{ item }">
  57. <a-list-item>
  58. <a-card hoverable @click="onClickFile(item)">
  59. <template #cover>
  60. <div style="display: flex;justify-content:center;align-items: center;">
  61. <img style="width: 70%;" :src="fileSrc" />
  62. </div>
  63. </template>
  64. <a-card-meta>
  65. <template #description>
  66. <a-tooltip placement="bottom" :title="item.dir_name">
  67. <div class="mediaList-list-name">
  68. {{ item.dir_name }}
  69. </div>
  70. </a-tooltip>
  71. </template>
  72. </a-card-meta>
  73. </a-card>
  74. </a-list-item>
  75. </template>
  76. </a-list>
  77. </div>
  78. </div>
  79. </div>
  80. </a-spin>
  81. </template>
  82. <script lang="ts" setup>
  83. import { reactive, onMounted } from 'vue';
  84. import { MenuOutlined, AppstoreOutlined, DownloadOutlined, EnvironmentOutlined } from '@ant-design/icons-vue';
  85. import Search from './components/Search.vue';
  86. import fileSrc from '/@/assets/media/file.svg';
  87. import { apis } from '/@/api/custom';
  88. import router from '/@/router/index';
  89. import { downloadFile } from '/@/utils/common';
  90. import moment from 'moment';
  91. interface State {
  92. listLoading: boolean,
  93. list: any[],
  94. selectedRowKeys: string[],
  95. downloadLoading: boolean,
  96. mode: 'table' | 'list',
  97. };
  98. const state: State = reactive({
  99. listLoading: false,
  100. list: [],
  101. selectedRowKeys: [],
  102. downloadLoading: false,
  103. mode: 'table',
  104. })
  105. const paginationConfig = reactive({
  106. pageSizeOptions: ['20', '50', '100'],
  107. showQuickJumper: true,
  108. showSizeChanger: true,
  109. pageSize: 20,
  110. current: 1,
  111. total: 0,
  112. onChange: async (current: number) => {
  113. paginationConfig.current = current;
  114. await fetchList();
  115. },
  116. onShowSizeChange: async (current: number, pageSize: number) => {
  117. paginationConfig.pageSize = pageSize;
  118. await fetchList();
  119. }
  120. })
  121. const fetchList = async (query?: any) => {
  122. state.listLoading = true;
  123. try {
  124. const res = await apis.fetchMediaFileList({
  125. ...query,
  126. page: paginationConfig.current,
  127. page_size: paginationConfig.pageSize,
  128. });
  129. state.list = res.data.list;
  130. paginationConfig.current = res.data.pagination.page;
  131. paginationConfig.pageSize = res.data.pagination.page_size;
  132. paginationConfig.total = res.data.pagination.total;
  133. } catch (e) {
  134. console.error(e);
  135. } finally {
  136. state.listLoading = false;
  137. }
  138. }
  139. onMounted(async () => {
  140. await fetchList();
  141. })
  142. const columns = [
  143. {
  144. title: '文件夹名称',
  145. dataIndex: 'dir_name',
  146. width: 250,
  147. ellipsis: true,
  148. sorter: (a: any, b: any) => a.dir_name.localeCompare(b.dir_name),
  149. slots: { customRender: 'dir_name' }
  150. },
  151. {
  152. title: '设备型号',
  153. dataIndex: 'device_name',
  154. width: 150,
  155. ellipsis: true,
  156. },
  157. {
  158. title: '拍摄负载',
  159. dataIndex: 'payload',
  160. width: 150,
  161. ellipsis: true,
  162. },
  163. {
  164. title: '容量大小',
  165. dataIndex: 'size',
  166. width: 150,
  167. ellipsis: true,
  168. customRender: ({ text }: any) => {
  169. return text > 0 ? (text / 1024 / 1024).toFixed(1) + 'M' : '--';
  170. }
  171. },
  172. {
  173. title: '创建时间',
  174. dataIndex: 'create_time',
  175. width: 200,
  176. sorter: (a: any, b: any) => a.create_time.localeCompare(b.create_time),
  177. },
  178. {
  179. title: '航线名称',
  180. dataIndex: 'wayline_name',
  181. width: 150,
  182. },
  183. {
  184. title: '任务类型',
  185. dataIndex: 'template_type',
  186. width: 150,
  187. customRender: ({ text }: any) => {
  188. let content = '--';
  189. switch (text) {
  190. case '0':
  191. content = '航点航线';
  192. break;
  193. case '1':
  194. content = '二维正射';
  195. break;
  196. case '2':
  197. content = '倾斜摄影';
  198. break;
  199. case '3':
  200. content = '带状航线';
  201. break;
  202. case '4':
  203. content = '无';
  204. break;
  205. default:
  206. break;
  207. }
  208. return content;
  209. }
  210. },
  211. {
  212. title: '创建人',
  213. dataIndex: 'username',
  214. width: 150,
  215. },
  216. {
  217. title: '操作',
  218. dataIndex: 'actions',
  219. fixed: 'right',
  220. align: 'center',
  221. width: 60,
  222. slots: { customRender: 'action' },
  223. },
  224. ]
  225. const rowClassName = (record: any, index: number) => {
  226. const className = []
  227. if ((index & 1) === 0) {
  228. className.push('table-striped')
  229. }
  230. return className.toString().replaceAll(',', ' ')
  231. }
  232. // 点击批量下载
  233. const onClickBatchDownload = async () => {
  234. state.downloadLoading = true;
  235. try {
  236. const bold = await apis.batchDownloadMediaFile({
  237. id: state.selectedRowKeys.join(',')
  238. });
  239. const data = new Blob([bold], { type: 'application/zip' });
  240. downloadFile(data, moment().format('YYYY-MM-DD HH:mm:ss'));
  241. } catch (e) {
  242. console.error(e);
  243. } finally {
  244. state.downloadLoading = false;
  245. }
  246. }
  247. // 点击搜索
  248. const onClickSearch = async (query: any) => {
  249. await fetchList(query);
  250. }
  251. // 点击重置
  252. const onClickReset = async (query: any) => {
  253. await fetchList(query);
  254. }
  255. // 点击文件夹
  256. const onClickFile = (record: any) => {
  257. router.push({ path: `/media/${record.id}` })
  258. }
  259. // 勾选
  260. const onSelectChange = (selectedRowKeys: string[]) => {
  261. state.selectedRowKeys = selectedRowKeys;
  262. }
  263. // 点击下载
  264. const onClickDownload = async (record: any) => {
  265. state.downloadLoading = true;
  266. try {
  267. const bold = await apis.batchDownloadMediaFile({ id: record.id });
  268. const data = new Blob([bold], { type: 'application/zip' });
  269. downloadFile(data, record.dir_name);
  270. } catch (e) {
  271. console.error(e);
  272. } finally {
  273. state.downloadLoading = false;
  274. }
  275. }
  276. // 点击轨迹回放
  277. const onClickTrajectory = () => {
  278. router.push({ path: '/trajectory' })
  279. }
  280. </script>
  281. <style lang="scss">
  282. .mediaList {
  283. padding: 20px;
  284. &-info {
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: center;
  288. margin-bottom: 20px;
  289. &-right {
  290. display: flex;
  291. align-items: center;
  292. &-text {
  293. display: flex;
  294. align-items: center;
  295. margin-right: 20px;
  296. }
  297. }
  298. }
  299. .fileName {
  300. display: flex;
  301. align-items: center;
  302. cursor: pointer;
  303. img {
  304. width: 36px;
  305. height: 36px;
  306. margin-right: 5px;
  307. }
  308. }
  309. &-list {
  310. &-name {
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. white-space: nowrap;
  314. }
  315. }
  316. }
  317. .ant-table {
  318. border-top: 1px solid rgb(0, 0, 0, 0.06);
  319. border-bottom: 1px solid rgb(0, 0, 0, 0.06);
  320. }
  321. .ant-table-tbody tr td {
  322. border: 0;
  323. }
  324. .table-striped {
  325. background-color: #f7f9fa;
  326. }
  327. .ant-card-body {
  328. padding: 0 10px 10px;
  329. }
  330. </style>