cwg-file-picker-wrapper.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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" 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"
  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,
  108. default: ''
  109. },
  110. imageHeight: {
  111. type: String,
  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. const index = innerFileList.value.length - 1
  431. const url = props.action || config.Host80 + props.uploadUrl
  432. console.log({
  433. url,
  434. filePath: fileItem.path,
  435. name: props.uploadName,
  436. header: { 'Access-Token': userToken.value, ...props.uploadHeaders },
  437. formData: props.uploadData
  438. }, 100000);
  439. const task = uni.uploadFile({
  440. url,
  441. filePath: fileItem.path,
  442. name: props.uploadName,
  443. header: { 'Access-Token': userToken.value, ...props.uploadHeaders },
  444. formData: props.uploadData,
  445. success: (res) => {
  446. const result = typeof props.responseHandler === 'function'
  447. ? props.responseHandler(res.data)
  448. : {
  449. success: typeof res.data === 'string'
  450. ? JSON.parse(res.data).code === 200
  451. : res.data.code === 200,
  452. path: typeof res.data === 'string'
  453. ? (JSON.parse(res.data).data?.path || JSON.parse(res.data).data)
  454. : (res.data.data?.path || res.data.data),
  455. message: typeof res.data === 'string'
  456. ? JSON.parse(res.data).msg
  457. : res.data.msg
  458. }
  459. if (result.success) {
  460. innerFileList.value[index].progress = 100
  461. innerFileList.value[index].status = 'success'
  462. innerFileList.value[index].url = config.Host05 + result.path
  463. innerFileList.value[index].path = result.path
  464. emit('success', innerFileList.value[index])
  465. } else {
  466. innerFileList.value[index].status = 'error'
  467. uni.showToast({ title: result.message || '上传失败', icon: 'error' })
  468. emit('fail', result.message || '上传失败')
  469. }
  470. resolve(result)
  471. },
  472. fail: () => {
  473. innerFileList.value[index].status = 'error'
  474. uni.showToast({ title: '上传失败', icon: 'error' })
  475. emit('fail', '网络异常')
  476. resolve(null)
  477. }
  478. })
  479. task.onProgressUpdate((p) => {
  480. innerFileList.value[index].progress = p.progress
  481. emit('progress', p, index)
  482. })
  483. })
  484. }
  485. const uploadBase64 = (fileItem) => {
  486. return new Promise((resolve) => {
  487. innerFileList.value.push({
  488. ...fileItem,
  489. status: 'uploading',
  490. progress: 0
  491. })
  492. const index =
  493. innerFileList.value.length - 1
  494. const url =
  495. props.action ||
  496. config.Host80 + props.uploadUrl
  497. uni.request({
  498. url,
  499. method: 'POST',
  500. header: {
  501. 'Content-Type': 'application/json',
  502. 'Access-Token': userToken.value,
  503. ...props.uploadHeaders
  504. },
  505. data: {
  506. file: fileItem.base64,
  507. fileName: fileItem.name,
  508. fileType: fileItem.type,
  509. ...props.uploadData
  510. },
  511. success: (res) => {
  512. const result =
  513. typeof props.responseHandler === 'function'
  514. ? props.responseHandler(res.data)
  515. : {
  516. success: res.data.code === 200,
  517. path: res.data.data?.path || res.data.data,
  518. message: res.data.msg
  519. }
  520. if (result.success) {
  521. innerFileList.value[index].progress = 100
  522. innerFileList.value[index].status = 'success'
  523. // 这里继续用后端返回URL
  524. innerFileList.value[index].url =
  525. config.Host05 + result.path
  526. innerFileList.value[index].path =
  527. result.path
  528. emit(
  529. 'success',
  530. innerFileList.value[index]
  531. )
  532. } else {
  533. innerFileList.value[index].status = 'error'
  534. uni.showToast({
  535. title: result.message || '上传失败',
  536. icon: 'none'
  537. })
  538. emit('fail', result.message)
  539. }
  540. resolve(result)
  541. },
  542. fail: () => {
  543. innerFileList.value[index].status = 'error'
  544. uni.showToast({
  545. title: '上传失败',
  546. icon: 'none'
  547. })
  548. emit('fail', '网络异常')
  549. resolve(null)
  550. }
  551. })
  552. })
  553. }
  554. const base64ToTempFile = (base64, fileName = 'file.png') => {
  555. return new Promise((resolve, reject) => {
  556. const matches = base64.match(/^data:(.+);base64,(.+)$/)
  557. if (!matches) {
  558. reject('base64格式错误')
  559. return
  560. }
  561. const base64Data = matches[2]
  562. const filePath =
  563. `${plus.io.convertLocalFileSystemURL('_doc/')}${Date.now()}_${fileName}`
  564. plus.io.resolveLocalFileSystemURL(
  565. '_doc/',
  566. (entry) => {
  567. entry.getFile(
  568. `${Date.now()}_${fileName}`,
  569. { create: true },
  570. (fileEntry) => {
  571. fileEntry.createWriter((writer) => {
  572. writer.onwrite = () => {
  573. resolve(fileEntry.toLocalURL())
  574. }
  575. writer.onerror = reject
  576. const bitmap = new plus.nativeObj.Bitmap()
  577. bitmap.loadBase64Data(
  578. base64,
  579. () => {
  580. bitmap.save(
  581. fileEntry.toLocalURL(),
  582. {},
  583. () => {
  584. resolve(fileEntry.toLocalURL())
  585. },
  586. reject
  587. )
  588. },
  589. reject
  590. )
  591. })
  592. },
  593. reject
  594. )
  595. },
  596. reject
  597. )
  598. })
  599. }
  600. const reUploadFile = (index) => {
  601. const file = innerFileList.value[index]
  602. uploadFile(file)
  603. }
  604. const imgStyle = computed(() => {
  605. let style = {}
  606. if (props.imageWidth) {
  607. style.width = typeof props.imageWidth === 'number' ? `${props.imageWidth}px` : `${props.imageWidth}`
  608. }
  609. if (props.imageHeight) {
  610. style.height = typeof props.imageHeight === 'number' ? `${props.imageHeight}px` : `${props.imageHeight}`
  611. }
  612. console.log(style)
  613. return style
  614. })
  615. </script>
  616. <style scoped lang="scss">
  617. /* 布局 */
  618. .uni-file-picker__container {
  619. display: flex;
  620. flex-wrap: wrap;
  621. //margin: -5px;
  622. width: 100%;
  623. }
  624. .file-picker__box {
  625. position: relative;
  626. width: 33.3%;
  627. height: 0;
  628. //padding-top: 33.3%;
  629. box-sizing: border-box;
  630. }
  631. .file-picker__box-content {
  632. position: absolute;
  633. top: 0;
  634. right: 0;
  635. bottom: 0;
  636. left: 0;
  637. //margin: 5px;
  638. border-radius: 5px;
  639. overflow: hidden;
  640. background: #f7f7f7;
  641. }
  642. /* 图片 */
  643. .file-image {
  644. width: 100%;
  645. height: 100%;
  646. }
  647. /* 文件封面 */
  648. .file-cover {
  649. width: 100%;
  650. height: 100%;
  651. display: flex;
  652. align-items: center;
  653. justify-content: center;
  654. flex-direction: column;
  655. color: var(--bs-emphasis-color);
  656. }
  657. /* 视频 */
  658. .video-box {
  659. position: relative;
  660. }
  661. .video-play-icon {
  662. position: absolute;
  663. font-size: 30px;
  664. color: var(--bs-emphasis-color);
  665. background: rgba(0, 0, 0, 0.5);
  666. width: 50px;
  667. height: 50px;
  668. border-radius: 50%;
  669. display: flex;
  670. align-items: center;
  671. justify-content: center;
  672. }
  673. /* 文件类型颜色 */
  674. .file-pdf {
  675. background: #ff4f4f;
  676. }
  677. .file-word {
  678. background: #3a7ff5;
  679. }
  680. .file-excel {
  681. background: #24a148;
  682. }
  683. .file-video {
  684. background: #000;
  685. }
  686. .file-other {
  687. background: #f7f7f7;
  688. }
  689. .file-big-icon {
  690. font-size: 16px;
  691. font-weight: bold;
  692. margin-bottom: 4px;
  693. }
  694. .file-ext-name {
  695. font-size: 12px;
  696. opacity: 0.9;
  697. }
  698. /* 添加按钮 */
  699. .is-add {
  700. display: flex;
  701. align-items: center;
  702. justify-content: center;
  703. background: var(--bs-body-bg);
  704. }
  705. .upload-icon {
  706. color: var(--bs-heading-color);
  707. }
  708. /* 删除按钮 */
  709. .icon-del-box {
  710. position: absolute;
  711. top: 3px;
  712. right: 3px;
  713. width: 26px;
  714. height: 26px;
  715. border-radius: 50%;
  716. background: rgba(0, 0, 0, 0.5);
  717. display: flex;
  718. align-items: center;
  719. justify-content: center;
  720. z-index: 10;
  721. transform: rotate(-45deg);
  722. }
  723. .icon-del {
  724. width: 15px;
  725. height: 2px;
  726. background: #fff;
  727. border-radius: 2px;
  728. }
  729. .rotate {
  730. position: absolute;
  731. transform: rotate(90deg);
  732. }
  733. /* 进度 */
  734. .file-picker__progress {
  735. position: absolute;
  736. bottom: 0;
  737. left: 0;
  738. right: 0;
  739. z-index: 2;
  740. }
  741. /* 失败遮罩 */
  742. .file-picker__mask {
  743. position: absolute;
  744. top: 0;
  745. left: 0;
  746. right: 0;
  747. bottom: 0;
  748. background: rgba(0, 0, 0, 0.4);
  749. color: var(--bs-emphasis-color);
  750. display: flex;
  751. align-items: center;
  752. justify-content: center;
  753. font-size: 12px;
  754. }
  755. /* 只读模式 */
  756. .file-list {
  757. padding: 5px;
  758. }
  759. .file-item {
  760. display: flex;
  761. align-items: center;
  762. gap: 10px;
  763. padding: 10px;
  764. background: #f8f8f8;
  765. border-radius: 8px;
  766. margin-bottom: 10px;
  767. }
  768. .file-thumb,
  769. .file-icon {
  770. width: 60px;
  771. height: 60px;
  772. border-radius: 6px;
  773. }
  774. .file-icon {
  775. background: #eee;
  776. display: flex;
  777. align-items: center;
  778. justify-content: center;
  779. }
  780. .file-icon-text {
  781. font-size: 12px;
  782. font-weight: bold;
  783. }
  784. .file-name {
  785. flex: 1;
  786. font-size: 14px;
  787. color: var(--bs-heading-color);
  788. }
  789. .empty-text {
  790. text-align: center;
  791. color: var(--bs-heading-color);
  792. padding: 20px 0;
  793. }
  794. </style>