index.vue 7.6 KB

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