cwg-file-picker-wrapper.vue 23 KB

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