cwg-file-picker-wrapper.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. <template>
  2. <view class="file-picker-wrapper">
  3. <!-- 只读模式:仅展示 -->
  4. <view v-if="readonly" class="file-list readonly-list">
  5. <view v-for="(file, index) in innerFileList" :key="index" class="file-item readonly-item"
  6. @click="previewFile(file, index)">
  7. <image v-if="isImage(file)" :src="file.url || file.path" mode="aspectFill" class="file-thumb"
  8. :style="imgStyle" />
  9. <view v-else class="file-icon" :class="getFileClass(file.name)">
  10. <text class="file-icon-text">{{ getFileIcon(file.name) }}</text>
  11. </view>
  12. <text class="file-name">{{ file.name }}</text>
  13. </view>
  14. <view v-if="!innerFileList?.length" class="empty-text">暂无文件</view>
  15. </view>
  16. <!-- 正常模式:宫格上传(完全对齐官方 upload-image 样式) -->
  17. <view v-else class="uni-file-picker__container">
  18. <view class="file-picker__box cursor-pointer" v-for="(item, index) in innerFileList" :key="index"
  19. :style="typeof boxStyle === 'object' ? boxStyle : { cssText: boxStyle }" :data-tooltip="t('vu.tooltip.t3')" data-placement="top">
  20. <view class="file-picker__box-content" :style="borderStyle">
  21. <!-- 图片 -->
  22. <image v-if="isImage(item)" class="file-image" :src="item.url || item.path" mode="aspectFill"
  23. :style="imgStyle" @click.stop="previewFile(item, index)" />
  24. <!-- 视频 → 显示第一帧 + 播放图标 -->
  25. <view v-else-if="isVideo(item)" class="file-cover video-box" @click.stop="previewFile(item, index)">
  26. <image :src="item.url || item.path" class="file-image" mode="aspectFill" :style="imgStyle" />
  27. <view class="video-play-icon">▶</view>
  28. </view>
  29. <!-- 其他文件(PDF/Word/Excel) -->
  30. <view v-else class="file-cover file-box" :class="getFileClass(item.name)"
  31. @click.stop="previewFile(item, index)">
  32. <text class="file-big-icon">{{ getFileIcon(item.name) }}</text>
  33. <text class="file-ext-name">{{ getFileExt(item.name) }}</text>
  34. </view>
  35. <!-- 删除 -->
  36. <view v-if="delIcon" class="icon-del-box" @click.stop="deleteFile(index)">
  37. <view class="icon-del"></view>
  38. <view class="icon-del rotate"></view>
  39. </view>
  40. <!-- 进度 -->
  41. <view v-if="item.status === 'uploading'" class="file-picker__progress">
  42. <progress class="file-picker__progress-item" :percent="item.progress" stroke-width="4"
  43. backgroundColor="#EBEBEB" />
  44. </view>
  45. <!-- 失败重试 -->
  46. <view v-if="item.status === 'error'" class="file-picker__mask" @click.stop="reUploadFile(index)">
  47. 点击重试
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 添加按钮 -->
  52. <view v-if="innerFileList?.length < limit" class="file-picker__box cursor-pointer"
  53. :style="typeof boxStyle === 'object' ? boxStyle : { cssText: boxStyle }">
  54. <view class="file-picker__box-content is-add" :style="borderStyle" @click="handleChoose">
  55. <cwg-icon name="icon_add" class="upload-icon" :size="24" />
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <cop-chooseFile :trigger="triggerFlag" accept="*" @receiveRenderFile="handleFile">
  61. </cop-chooseFile>
  62. </template>
  63. <script setup>
  64. import { ref, watch, nextTick, computed } from 'vue'
  65. import config from '@/config'
  66. import { useI18n } from 'vue-i18n';
  67. import { userToken } from '@/composables/config'
  68. import copChooseFile from '@/uni_modules/cop-chooseFile/components/cop-chooseFile/cop-chooseFile.vue'
  69. const { t, locale } = useI18n();
  70. // === Vue3 v-model 标准写法 + 多类型兼容 ===
  71. const props = defineProps({
  72. modelValue: {
  73. type: [Array, String, Object],
  74. default: () => []
  75. },
  76. readonly: {
  77. type: Boolean,
  78. default: false
  79. },
  80. disabled: {
  81. type: Boolean,
  82. default: false
  83. },
  84. limit: {
  85. type: Number,
  86. default: 9
  87. },
  88. fileMediatype: {
  89. type: String,
  90. default: 'all'
  91. },
  92. delIcon: {
  93. type: Boolean,
  94. default: true
  95. },
  96. disablePreview: {
  97. type: Boolean,
  98. default: false
  99. },
  100. autoUpload: {
  101. type: Boolean,
  102. default: true
  103. },
  104. action: {
  105. type: String,
  106. default: ''
  107. },
  108. imageWidth: {
  109. type: [String,Number],
  110. default: ''
  111. },
  112. imageHeight: {
  113. type: [String,Number],
  114. default: ''
  115. },
  116. uploadUrl: {
  117. type: String,
  118. default: '/custom/bank/upload'
  119. },
  120. uploadHeaders: {
  121. type: Object,
  122. default: () => ({})
  123. },
  124. uploadName: {
  125. type: String,
  126. default: 'file'
  127. },
  128. uploadData: {
  129. type: Object,
  130. default: () => ({})
  131. },
  132. responseHandler: {
  133. type: Function,
  134. default: (res) => {
  135. try {
  136. const data = typeof res === 'string' ? JSON.parse(res) : res
  137. return {
  138. success: data.code === 200,
  139. path: data.data?.path || data.data,
  140. message: data.msg || '上传成功'
  141. }
  142. } catch (e) {
  143. return { success: false, message: '解析失败' }
  144. }
  145. }
  146. }
  147. })
  148. const emit = defineEmits([
  149. 'update:modelValue',
  150. 'change',
  151. 'delete',
  152. 'success',
  153. 'fail',
  154. 'progress',
  155. 'select'
  156. ])
  157. const triggerFlag = ref(0)
  158. // 内部数据
  159. const innerFileList = ref([])
  160. const tempFileQueue = ref([])
  161. const originalType = ref('array') // 'string' | 'object' | 'array'
  162. const borderStyle = 'border:1px #eee solid;border-radius:5px;'
  163. const boxStyle = computed(() => {
  164. if (props.imageWidth || props.imageHeight) {
  165. const width = typeof props.imageWidth === 'number' ? `${props.imageWidth}px` : props.imageWidth || 'auto'
  166. const height = typeof props.imageHeight === 'number' ? `${props.imageHeight}px` : props.imageHeight || 'auto'
  167. return { width, height }
  168. }
  169. return 'width:33.3%;height:0;'
  170. })
  171. // ==============================================
  172. // 统一格式化函数(修复递归核心)
  173. // ==============================================
  174. function formatValue(val) {
  175. if (!val) return []
  176. // 字符串
  177. if (typeof val === 'string') {
  178. return [{
  179. path: val,
  180. url: val.startsWith('http') ? val : config.Host05 + val,
  181. name: val.split('/').pop(),
  182. status: 'success'
  183. }]
  184. }
  185. // 对象
  186. if (typeof val === 'object' && !Array.isArray(val)) {
  187. const path = val.path || val.url || ''
  188. return [{
  189. ...val,
  190. path,
  191. url: val.url || (path.startsWith('http') ? path : config.Host05 + path),
  192. name: val.name || path.split('/').pop(),
  193. status: 'success'
  194. }]
  195. }
  196. // 数组
  197. if (Array.isArray(val)) {
  198. return val.map(item => {
  199. if (typeof item === 'string') {
  200. return {
  201. path: item,
  202. url: item.startsWith('http') ? item : config.Host05 + item,
  203. name: item.split('/').pop(),
  204. status: 'success'
  205. }
  206. } else {
  207. const path = item?.path || item?.url || ''
  208. return {
  209. ...item,
  210. path,
  211. url: item?.url || (path.startsWith('http') ? path : config.Host05 + path),
  212. name: item?.name || path.split('/').pop(),
  213. status: 'success'
  214. }
  215. }
  216. })
  217. }
  218. return []
  219. }
  220. // ==============================================
  221. // 监听外部传入:防重复赋值 → 无递归
  222. // ==============================================
  223. watch(
  224. () => props.modelValue,
  225. (val) => {
  226. const formatted = formatValue(val)
  227. // 值相同不更新,防止死循环
  228. if (JSON.stringify(innerFileList.value) === JSON.stringify(formatted)) return
  229. if (!val) {
  230. // innerFileList.value = []
  231. // originalType.value = 'array'
  232. return
  233. }
  234. // 记录原始类型
  235. if (typeof val === 'string') originalType.value = 'string'
  236. else if (typeof val === 'object' && !Array.isArray(val)) originalType.value = 'object'
  237. else originalType.value = 'array'
  238. innerFileList.value = formatted
  239. },
  240. { immediate: true, deep: true }
  241. )
  242. // ==============================================
  243. // 内部变化同步外部:nextTick → 无递归
  244. // ==============================================
  245. watch(
  246. innerFileList,
  247. (list) => {
  248. nextTick(() => {
  249. let returnValue = []
  250. if (!list || list.length === 0) {
  251. returnValue = originalType.value === 'string' ? '' :
  252. originalType.value === 'object' ? {} : []
  253. emitUpdate(returnValue)
  254. return
  255. }
  256. // 只返回干净的 path 数据
  257. const cleanList = list.map(item => item.path || item.url || '')
  258. // 按原始类型返回
  259. if (props.limit === 1) {
  260. returnValue = cleanList[0] || ''
  261. } else if (originalType.value === 'string') returnValue = cleanList[0] || ''
  262. else if (originalType.value === 'object') returnValue = { path: cleanList[0] || '' }
  263. else returnValue = cleanList
  264. emitUpdate(returnValue)
  265. })
  266. },
  267. { deep: true }
  268. )
  269. // 统一触发更新
  270. function emitUpdate(val) {
  271. emit('update:modelValue', val)
  272. emit('change', val)
  273. }
  274. // ==============================================
  275. // 文件类型判断
  276. // ==============================================
  277. const isImage = (file) => {
  278. const ext = (file.path || file.name || '').split('.').pop()?.toLowerCase()
  279. return ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'].includes(ext)
  280. }
  281. const isVideo = (file) => {
  282. const ext = (file.path || file.name || '').split('.').pop()?.toLowerCase()
  283. return ['mp4', 'mov', 'avi', 'flv', 'wmv', 'rmvb'].includes(ext)
  284. }
  285. const getFileExt = (name) => {
  286. if (!name) return ''
  287. return name.split('.').pop()?.toUpperCase()
  288. }
  289. const getFileIcon = (name) => {
  290. const ext = getFileExt(name)
  291. if (ext === 'PDF') return 'PDF'
  292. if (['DOC', 'DOCX'].includes(ext)) return 'WORD'
  293. if (['XLS', 'XLSX'].includes(ext)) return 'EXCEL'
  294. if (isVideo({ name })) return '▶'
  295. if (isImage({ name })) return 'IMG'
  296. return 'FILE'
  297. }
  298. const getFileClass = (name) => {
  299. const ext = getFileExt(name)
  300. if (ext === 'PDF') return 'file-pdf'
  301. if (['DOC', 'DOCX'].includes(ext)) return 'file-word'
  302. if (['XLS', 'XLSX'].includes(ext)) return 'file-excel'
  303. if (isVideo({ name })) return 'file-video'
  304. return 'file-other'
  305. }
  306. // ==============================================
  307. // 预览
  308. // ==============================================
  309. const previewFile = (file, index) => {
  310. if (props.disablePreview || file.status === 'uploading' || file.status === 'error') return
  311. const url = file.url || file.path
  312. const name = file.name || '文件'
  313. if (isImage(file)) {
  314. const successImages = innerFileList.value.filter(item => isImage(item) && item.status === 'success')
  315. const realIndex = successImages.findIndex(item => item.url === file.url && item.path === file.path)
  316. const urls = successImages.map(item => item.url || item.path)
  317. uni.previewImage({ current: realIndex, urls, loop: true })
  318. return
  319. }
  320. uni.navigateTo({
  321. url: `/pages/common/webview?url=${encodeURIComponent(url)}&title=${encodeURIComponent(name)}`
  322. })
  323. }
  324. // ==============================================
  325. // 上传 / 删除 / 重试
  326. // ==============================================
  327. const deleteFile = (index) => {
  328. const item = innerFileList.value[index]
  329. innerFileList.value.splice(index, 1)
  330. emit('delete', item, index)
  331. }
  332. const handleChoose = () => {
  333. if (props.disabled || props.readonly) return
  334. const count = props.limit - innerFileList.value.length
  335. // #ifdef H5
  336. uni.chooseFile({
  337. type: props.fileMediatype,
  338. count,
  339. success: (res) => {
  340. const files = res.tempFiles || res.tempFilePaths.map((p, i) => ({
  341. path: p, name: `file_${i}`
  342. }))
  343. emit('select', { tempFiles: files })
  344. tempFileQueue.value = files
  345. if (props.autoUpload) startUpload()
  346. }
  347. })
  348. // #endif
  349. // #ifdef APP-PLUS
  350. triggerFlag.value = Date.now()
  351. // chooseFileFromModule({
  352. // complete: (res) => {
  353. // console.log(res)
  354. // let path = res.path
  355. // let name = res.name
  356. // let fileType = ''
  357. // // 如果没有name,默认为:截取最后一个/之后的内容
  358. // if (!name) {
  359. // let lastIndex = path.lastIndexOf('/');
  360. // if (lastIndex !== -1) {
  361. // name = path.substring(lastIndex + 1);
  362. // } else {
  363. // name = Math.random().toString(36).substr(2) + Date.now();
  364. // }
  365. // }
  366. // // 使用 lastIndexOf 方法找到最后一个 . 的位置
  367. // let lastDotIndex = name.lastIndexOf('.');
  368. // if (lastDotIndex !== -1) {
  369. // fileType = name.substring(lastDotIndex + 1);
  370. // } else {
  371. // console.log('文件路径中没有 .');
  372. // }
  373. // let file = {
  374. // size: res.size,
  375. // path,
  376. // fileType,
  377. // name
  378. // }
  379. // console.log('根据需求构造的数据', file)
  380. // }
  381. // })
  382. // #endif
  383. }
  384. // 处理选择的文件
  385. const handleFile = async (fileData) => {
  386. try {
  387. const tempPath = await base64ToTempFile(
  388. fileData.filePath,
  389. fileData.name
  390. )
  391. const file = {
  392. name: fileData.name,
  393. size: fileData.size,
  394. type: fileData.type,
  395. // 关键
  396. path: tempPath,
  397. status: 'ready'
  398. }
  399. console.log(file, 121212);
  400. tempFileQueue.value = [file]
  401. emit('select', {
  402. tempFiles: [file]
  403. })
  404. if (props.autoUpload) {
  405. startUpload()
  406. }
  407. } catch (e) {
  408. uni.showToast({
  409. title: '文件处理失败',
  410. icon: 'none'
  411. })
  412. console.error(e)
  413. }
  414. }
  415. const startUpload = async () => {
  416. const files = tempFileQueue.value
  417. tempFileQueue.value = []
  418. for (const file of files) {
  419. // APP base64
  420. if (file.base64) {
  421. await uploadBase64(file)
  422. }
  423. // H5 正常文件
  424. else {
  425. await uploadFile(file)
  426. }
  427. }
  428. }
  429. const uploadFile = (fileItem) => {
  430. return new Promise((resolve) => {
  431. innerFileList.value.push({ ...fileItem, status: 'uploading', progress: 0 })
  432. console.log(innerFileList.value,'upload231')
  433. const index = innerFileList.value.length - 1
  434. const url = props.action || config.Host80 + props.uploadUrl
  435. console.log({
  436. url,
  437. filePath: fileItem.path,
  438. name: props.uploadName,
  439. header: { 'Access-Token': userToken.value, ...props.uploadHeaders },
  440. formData: props.uploadData
  441. }, 100000);
  442. const task = uni.uploadFile({
  443. url,
  444. filePath: fileItem.path,
  445. name: props.uploadName,
  446. header: { 'Access-Token': userToken.value, ...props.uploadHeaders },
  447. formData: props.uploadData,
  448. success: (res) => {
  449. const result = typeof props.responseHandler === 'function'
  450. ? props.responseHandler(res.data)
  451. : {
  452. success: typeof res.data === 'string'
  453. ? JSON.parse(res.data).code === 200
  454. : res.data.code === 200,
  455. path: typeof res.data === 'string'
  456. ? (JSON.parse(res.data).data?.path || JSON.parse(res.data).data)
  457. : (res.data.data?.path || res.data.data),
  458. message: typeof res.data === 'string'
  459. ? JSON.parse(res.data).msg
  460. : res.data.msg
  461. }
  462. console.log(innerFileList.value,'file',result)
  463. if (result.success) {
  464. innerFileList.value[index].progress = 100
  465. innerFileList.value[index].status = 'success'
  466. innerFileList.value[index].url = config.Host05 + result.path
  467. innerFileList.value[index].path = result.path
  468. emit('success', innerFileList.value[index])
  469. } else {
  470. innerFileList.value[index].status = 'error'
  471. uni.showToast({ title: result.message || '上传失败', icon: 'error' })
  472. emit('fail', result.message || '上传失败')
  473. }
  474. resolve(result)
  475. },
  476. fail: () => {
  477. innerFileList.value[index].status = 'error'
  478. uni.showToast({ title: '上传失败', icon: 'error' })
  479. emit('fail', '网络异常')
  480. resolve(null)
  481. }
  482. })
  483. task.onProgressUpdate((p) => {
  484. innerFileList.value[index].progress = p.progress
  485. emit('progress', p, index)
  486. })
  487. })
  488. }
  489. const uploadBase64 = (fileItem) => {
  490. return new Promise((resolve) => {
  491. innerFileList.value.push({
  492. ...fileItem,
  493. status: 'uploading',
  494. progress: 0
  495. })
  496. const index =
  497. innerFileList.value.length - 1
  498. const url =
  499. props.action ||
  500. config.Host80 + props.uploadUrl
  501. uni.request({
  502. url,
  503. method: 'POST',
  504. header: {
  505. 'Content-Type': 'application/json',
  506. 'Access-Token': userToken.value,
  507. ...props.uploadHeaders
  508. },
  509. data: {
  510. file: fileItem.base64,
  511. fileName: fileItem.name,
  512. fileType: fileItem.type,
  513. ...props.uploadData
  514. },
  515. success: (res) => {
  516. const result =
  517. typeof props.responseHandler === 'function'
  518. ? props.responseHandler(res.data)
  519. : {
  520. success: res.data.code === 200,
  521. path: res.data.data?.path || res.data.data,
  522. message: res.data.msg
  523. }
  524. if (result.success) {
  525. innerFileList.value[index].progress = 100
  526. innerFileList.value[index].status = 'success'
  527. // 这里继续用后端返回URL
  528. innerFileList.value[index].url =
  529. config.Host05 + result.path
  530. innerFileList.value[index].path =
  531. result.path
  532. emit(
  533. 'success',
  534. innerFileList.value[index]
  535. )
  536. } else {
  537. innerFileList.value[index].status = 'error'
  538. uni.showToast({
  539. title: result.message || '上传失败',
  540. icon: 'none'
  541. })
  542. emit('fail', result.message)
  543. }
  544. resolve(result)
  545. },
  546. fail: () => {
  547. innerFileList.value[index].status = 'error'
  548. uni.showToast({
  549. title: '上传失败',
  550. icon: 'none'
  551. })
  552. emit('fail', '网络异常')
  553. resolve(null)
  554. }
  555. })
  556. })
  557. }
  558. const base64ToTempFile = (base64, fileName = 'file.png') => {
  559. return new Promise((resolve, reject) => {
  560. const matches = base64.match(/^data:(.+);base64,(.+)$/)
  561. if (!matches) {
  562. reject('base64格式错误')
  563. return
  564. }
  565. const base64Data = matches[2]
  566. const filePath =
  567. `${plus.io.convertLocalFileSystemURL('_doc/')}${Date.now()}_${fileName}`
  568. plus.io.resolveLocalFileSystemURL(
  569. '_doc/',
  570. (entry) => {
  571. entry.getFile(
  572. `${Date.now()}_${fileName}`,
  573. { create: true },
  574. (fileEntry) => {
  575. fileEntry.createWriter((writer) => {
  576. writer.onwrite = () => {
  577. resolve(fileEntry.toLocalURL())
  578. }
  579. writer.onerror = reject
  580. const bitmap = new plus.nativeObj.Bitmap()
  581. bitmap.loadBase64Data(
  582. base64,
  583. () => {
  584. bitmap.save(
  585. fileEntry.toLocalURL(),
  586. {},
  587. () => {
  588. resolve(fileEntry.toLocalURL())
  589. },
  590. reject
  591. )
  592. },
  593. reject
  594. )
  595. })
  596. },
  597. reject
  598. )
  599. },
  600. reject
  601. )
  602. })
  603. }
  604. const reUploadFile = (index) => {
  605. const file = innerFileList.value[index]
  606. uploadFile(file)
  607. }
  608. const imgStyle = computed(() => {
  609. let style = {}
  610. if (props.imageWidth) {
  611. style.width = typeof props.imageWidth === 'number' ? `${props.imageWidth}px` : `${props.imageWidth}`
  612. }
  613. if (props.imageHeight) {
  614. style.height = typeof props.imageHeight === 'number' ? `${props.imageHeight}px` : `${props.imageHeight}`
  615. }
  616. console.log(style)
  617. return style
  618. })
  619. </script>
  620. <style scoped lang="scss">
  621. .file-picker-wrapper{
  622. }
  623. /* 布局 */
  624. .uni-file-picker__container {
  625. display: flex;
  626. flex-wrap: wrap;
  627. //margin: -5px;
  628. justify-content: center;
  629. align-self: center;
  630. gap: px2rpx(5);
  631. width: 100%;
  632. }
  633. .file-picker__box {
  634. position: relative;
  635. width: 33.3%;
  636. height: 0;
  637. //padding-top: 33.3%;
  638. box-sizing: border-box;
  639. }
  640. .file-picker__box-content {
  641. position: absolute;
  642. top: 0;
  643. right: 0;
  644. bottom: 0;
  645. left: 0;
  646. //margin: 5px;
  647. border-radius: 5px;
  648. overflow: hidden;
  649. background: #f7f7f7;
  650. }
  651. /* 图片 */
  652. .file-image {
  653. width: 100%;
  654. height: 100%;
  655. }
  656. /* 文件封面 */
  657. .file-cover {
  658. width: 100%;
  659. height: 100%;
  660. display: flex;
  661. align-items: center;
  662. justify-content: center;
  663. flex-direction: column;
  664. color: var(--bs-emphasis-color);
  665. }
  666. /* 视频 */
  667. .video-box {
  668. position: relative;
  669. }
  670. .video-play-icon {
  671. position: absolute;
  672. font-size: 30px;
  673. color: var(--bs-emphasis-color);
  674. background: rgba(0, 0, 0, 0.5);
  675. width: 50px;
  676. height: 50px;
  677. border-radius: 50%;
  678. display: flex;
  679. align-items: center;
  680. justify-content: center;
  681. }
  682. /* 文件类型颜色 */
  683. .file-pdf {
  684. background: #ff4f4f;
  685. }
  686. .file-word {
  687. background: #3a7ff5;
  688. }
  689. .file-excel {
  690. background: #24a148;
  691. }
  692. .file-video {
  693. background: #000;
  694. }
  695. .file-other {
  696. background: #f7f7f7;
  697. }
  698. .file-big-icon {
  699. font-size: 16px;
  700. font-weight: bold;
  701. margin-bottom: 4px;
  702. }
  703. .file-ext-name {
  704. font-size: 12px;
  705. opacity: 0.9;
  706. }
  707. /* 添加按钮 */
  708. .is-add {
  709. display: flex;
  710. align-items: center;
  711. justify-content: center;
  712. background: var(--bs-body-bg);
  713. }
  714. .upload-icon {
  715. color: var(--bs-heading-color);
  716. }
  717. /* 删除按钮 */
  718. .icon-del-box {
  719. position: absolute;
  720. top: 3px;
  721. right: 3px;
  722. width: 26px;
  723. height: 26px;
  724. border-radius: 50%;
  725. background: rgba(0, 0, 0, 0.5);
  726. display: flex;
  727. align-items: center;
  728. justify-content: center;
  729. z-index: 10;
  730. transform: rotate(-45deg);
  731. }
  732. .icon-del {
  733. width: 15px;
  734. height: 2px;
  735. background: #fff;
  736. border-radius: 2px;
  737. }
  738. .rotate {
  739. position: absolute;
  740. transform: rotate(90deg);
  741. }
  742. /* 进度 */
  743. .file-picker__progress {
  744. position: absolute;
  745. bottom: 0;
  746. left: 0;
  747. right: 0;
  748. z-index: 2;
  749. }
  750. /* 失败遮罩 */
  751. .file-picker__mask {
  752. position: absolute;
  753. top: 0;
  754. left: 0;
  755. right: 0;
  756. bottom: 0;
  757. background: rgba(0, 0, 0, 0.4);
  758. color: var(--bs-emphasis-color);
  759. display: flex;
  760. align-items: center;
  761. justify-content: center;
  762. font-size: 12px;
  763. }
  764. /* 只读模式 */
  765. .file-list {
  766. padding: 5px;
  767. }
  768. .file-item {
  769. display: flex;
  770. align-items: center;
  771. gap: 10px;
  772. padding: 10px;
  773. background: #f8f8f8;
  774. border-radius: 8px;
  775. margin-bottom: 10px;
  776. }
  777. .file-thumb,
  778. .file-icon {
  779. width: 60px;
  780. height: 60px;
  781. border-radius: 6px;
  782. }
  783. .file-icon {
  784. background: #eee;
  785. display: flex;
  786. align-items: center;
  787. justify-content: center;
  788. }
  789. .file-icon-text {
  790. font-size: 12px;
  791. font-weight: bold;
  792. }
  793. .file-name {
  794. flex: 1;
  795. font-size: 14px;
  796. color: var(--bs-heading-color);
  797. }
  798. .empty-text {
  799. text-align: center;
  800. color: var(--bs-heading-color);
  801. padding: 20px 0;
  802. }
  803. </style>