cwg-file-picker-wrapper.vue 22 KB

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