u-upload-file.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <template>
  2. <view class="u-upload" v-if="!disabled">
  3. <view
  4. v-if="showUploadList"
  5. class="u-list-item u-preview-wrap"
  6. v-for="(item, index) in lists"
  7. :key="index"
  8. :style="{
  9. width: $u.addUnit(width),
  10. height: $u.addUnit(height)
  11. }"
  12. >
  13. <view
  14. v-if="deletable"
  15. class="u-delete-icon"
  16. @tap.stop="deleteItem(index)"
  17. :style="{
  18. background: delBgColor
  19. }"
  20. >
  21. <u-icon class="u-icon" :name="delIcon" size="20" :color="delColor"></u-icon>
  22. </view>
  23. <u-line-progress
  24. v-if="showProgress && item.progress > 0 && item.progress != 100 && !item.error"
  25. :show-percent="false"
  26. height="16"
  27. class="u-progress"
  28. ></u-line-progress>
  29. <view @tap.stop="retry(index)" v-if="item.error" class="u-error-btn2 u-error-btn">点击重试</view>
  30. <view v-else-if="item.progress==100&&item.response&&item.response.result" class="u-error-btn2 u-primary-btn">上传成功</view>
  31. <view v-else-if="!item.error" class="u-error-btn2 u-warning-btn">上传中</view>
  32. <video v-if="item.fileType=='video/mp4'" :src="item.url"
  33. enable-danmu danmu-btn controls></video>
  34. <image class="u-preview-image" v-else :src="item.url || item.path" :mode="imageMode"></image>
  35. </view>
  36. <slot name="file" :file="lists"></slot>
  37. <view style="display: inline-block;" @tap="selectFile" v-if="maxCount > lists.length">
  38. <slot name="addBtn"></slot>
  39. <view
  40. v-if="!customBtn"
  41. class="u-list-item u-add-wrap"
  42. hover-class="u-add-wrap__hover"
  43. hover-stay-time="150"
  44. :style="{
  45. width: $u.addUnit(width),
  46. height: $u.addUnit(height)
  47. }"
  48. >
  49. <u-icon name="plus" class="u-add-btn" size="40"></u-icon>
  50. <view class="u-add-tips">{{ uploadText }}</view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. /**
  57. * upload 图片上传
  58. * @description 该组件用于上传图片场景
  59. * @tutorial https://www.uviewui.com/components/upload.html
  60. * @property {String} action 服务器上传地址
  61. * @property {String Number} max-count 最大选择图片的数量(默认99)
  62. * @property {Boolean} custom-btn 如果需要自定义选择图片的按钮,设置为true(默认false)
  63. * @property {Boolean} show-progress 是否显示进度条(默认true)
  64. * @property {Boolean} disabled 是否启用(显示/移仓)组件(默认false)
  65. * @property {String} image-mode 预览图片等显示模式,可选值为uni的image的mode属性值(默认aspectFill)
  66. * @property {String} del-icon 右上角删除图标名称,只能为uView内置图标
  67. * @property {String} del-bg-color 右上角关闭按钮的背景颜色
  68. * @property {String | Number} index 在各个回调事件中的最后一个参数返回,用于区别是哪一个组件的事件
  69. * @property {String} del-color 右上角关闭按钮图标的颜色
  70. * @property {Object} header 上传携带的头信息,对象形式
  71. * @property {Object} form-data 上传额外携带的参数
  72. * @property {String} name 上传文件的字段名,供后端获取使用(默认file)
  73. * @property {Array<String>} size-type original 原图,compressed 压缩图,默认二者都有(默认['original', 'compressed'])
  74. * @property {Array<String>} source-type 选择图片的来源,album-从相册选图,camera-使用相机,默认二者都有(默认['album', 'camera'])
  75. * @property {Boolean} preview-full-image 是否可以通过uni.previewImage预览已选择的图片(默认true)
  76. * @property {Boolean} multiple 是否开启图片多选,部分安卓机型不支持(默认true)
  77. * @property {Boolean} deletable 是否显示删除图片的按钮(默认true)
  78. * @property {String Number} max-size 选择单个文件的最大大小,单位B(byte),默认不限制(默认Number.MAX_VALUE)
  79. * @property {Array<Object>} file-list 默认显示的图片列表,数组元素为对象,必须提供url属性
  80. * @property {Boolean} upload-text 选择图片按钮的提示文字(默认“选择图片”)
  81. * @property {Boolean} auto-upload 选择完图片是否自动上传,见上方说明(默认true)
  82. * @property {Boolean} show-tips 特殊情况下是否自动提示toast,见上方说明(默认true)
  83. * @property {Boolean} show-upload-list 是否显示组件内部的图片预览(默认true)
  84. * @event {Function} on-oversize 图片大小超出最大允许大小
  85. * @event {Function} on-preview 全屏预览图片时触发
  86. * @event {Function} on-remove 移除图片时触发
  87. * @event {Function} on-success 图片上传成功时触发
  88. * @event {Function} on-change 图片上传后,无论成功或者失败都会触发
  89. * @event {Function} on-error 图片上传失败时触发
  90. * @event {Function} on-progress 图片上传过程中的进度变化过程触发
  91. * @event {Function} on-uploaded 所有图片上传完毕触发
  92. * @event {Function} on-choose-complete 每次选择图片后触发,只是让外部可以得知每次选择后,内部的文件列表
  93. * @example <u-upload :action="action" :file-list="fileList" ></u-upload>
  94. */
  95. export default {
  96. name: 'u-upload',
  97. props: {
  98. //是否显示组件自带的图片预览功能
  99. showUploadList: {
  100. type: Boolean,
  101. default: true
  102. },
  103. // 后端地址
  104. action: {
  105. type: String,
  106. default: ''
  107. },
  108. // 最大上传数量
  109. maxCount: {
  110. type: [String, Number],
  111. default: 9
  112. },
  113. // 是否显示进度条
  114. showProgress: {
  115. type: Boolean,
  116. default: true
  117. },
  118. // 是否启用
  119. disabled: {
  120. type: Boolean,
  121. default: false
  122. },
  123. // 预览上传的图片时的裁剪模式,和image组件mode属性一致
  124. imageMode: {
  125. type: String,
  126. default: 'aspectFill'
  127. },
  128. // 头部信息
  129. header: {
  130. type: Object,
  131. default() {
  132. return {};
  133. }
  134. },
  135. // 额外携带的参数
  136. formData: {
  137. type: Object,
  138. default() {
  139. return {};
  140. }
  141. },
  142. // 上传的文件字段名
  143. name: {
  144. type: String,
  145. default: 'photoFile'
  146. },
  147. // 所选的图片的尺寸, 可选值为original compressed
  148. sizeType: {
  149. type: Array,
  150. default() {
  151. return ['original', 'compressed'];
  152. }
  153. },
  154. sourceType: {
  155. type: Array,
  156. default() {
  157. return ['album', 'camera'];
  158. }
  159. },
  160. // 是否在点击预览图后展示全屏图片预览
  161. previewFullImage: {
  162. type: Boolean,
  163. default: true
  164. },
  165. // 是否开启图片多选,部分安卓机型不支持
  166. multiple: {
  167. type: Boolean,
  168. default: false
  169. },
  170. // 是否展示删除按钮
  171. deletable: {
  172. type: Boolean,
  173. default: true
  174. },
  175. // 文件大小限制,单位为byte
  176. maxSize: {
  177. type: [String, Number],
  178. default: Number.MAX_VALUE
  179. },
  180. // 文件大小限制,单位为byte
  181. fileMaxSize: {
  182. type: [String, Number],
  183. default: Number.MAX_VALUE
  184. },
  185. // 显示已上传的文件列表
  186. fileList: {
  187. type: Array,
  188. default() {
  189. return [];
  190. }
  191. },
  192. // 上传区域的提示文字
  193. uploadText: {
  194. type: String,
  195. default: '图片/视频'
  196. },
  197. // 是否自动上传
  198. autoUpload: {
  199. type: Boolean,
  200. default: true
  201. },
  202. // 是否显示toast消息提示
  203. showTips: {
  204. type: Boolean,
  205. default: true
  206. },
  207. // 是否通过slot自定义传入选择图标的按钮
  208. customBtn: {
  209. type: Boolean,
  210. default: false
  211. },
  212. // 内部预览图片区域和选择图片按钮的区域宽度
  213. width: {
  214. type: [String, Number],
  215. default: 200
  216. },
  217. // 内部预览图片区域和选择图片按钮的区域高度
  218. height: {
  219. type: [String, Number],
  220. default: 200
  221. },
  222. // 右上角关闭按钮的背景颜色
  223. delBgColor: {
  224. type: String,
  225. default: '#fa3534'
  226. },
  227. // 右上角关闭按钮的叉号图标的颜色
  228. delColor: {
  229. type: String,
  230. default: '#ffffff'
  231. },
  232. // 右上角删除图标名称,只能为uView内置图标
  233. delIcon: {
  234. type: String,
  235. default: 'close'
  236. },
  237. // 如果上传后的返回值为json字符串,是否自动转json
  238. toJson: {
  239. type: Boolean,
  240. default: true
  241. },
  242. // 上传前的钩子,每个文件上传前都会执行
  243. beforeUpload: {
  244. type: Function,
  245. default: null
  246. },
  247. // 移除文件前的钩子
  248. beforeRemove: {
  249. type: Function,
  250. default: null
  251. },
  252. // 允许上传的图片后缀
  253. limitType:{
  254. type: Array,
  255. default() {
  256. // 支付宝小程序真机选择图片的后缀为"image"
  257. // https://opendocs.alipay.com/mini/api/media-image
  258. return ['png', 'jpg', 'jpeg', 'webp', 'gif', 'image','mp4'];
  259. }
  260. },
  261. // 放一起,免得忘记了, 用于 图片上传限制, 和文件上传限制区别
  262. fileLimitType:{
  263. type: Array,
  264. default() {
  265. // 支付宝小程序真机选择图片的后缀为"image"
  266. // https://opendocs.alipay.com/mini/api/media-image
  267. return ['mp4'];
  268. }
  269. },
  270. // 在各个回调事件中的最后一个参数返回,用于区别是哪一个组件的事件
  271. index: {
  272. type: [Number, String],
  273. default: ''
  274. }
  275. },
  276. mounted() {},
  277. data() {
  278. return {
  279. lists: [],
  280. isInCount: true,
  281. uploading: false
  282. };
  283. },
  284. watch: {
  285. fileList: {
  286. immediate: true,
  287. handler(val) {
  288. val.map(value => {
  289. // 首先检查内部是否已经添加过这张图片,因为外部绑定了一个对象给fileList的话(对象引用),进行修改外部fileList
  290. // 时,会触发watch,导致重新把原来的图片再次添加到this.lists
  291. // 数组的some方法意思是,只要数组元素有任意一个元素条件符合,就返回true,而另一个数组的every方法的意思是数组所有元素都符合条件才返回true
  292. let tmp = this.lists.some(val => {
  293. return val.url == value.url;
  294. })
  295. // 如果内部没有这个图片(tmp为false),则添加到内部
  296. !tmp && this.lists.push({ url: value.url, error: false, progress: 100 });
  297. });
  298. }
  299. },
  300. // 监听lists的变化,发出事件
  301. lists(n) {
  302. this.$emit('on-list-change', n, this.index);
  303. }
  304. },
  305. methods: {
  306. // 清除列表
  307. clear() {
  308. this.lists = [];
  309. },
  310. // 重新上传队列中上传失败的所有文件
  311. reUpload() {
  312. this.uploadFile();
  313. },
  314. // 选择图片
  315. selectFile() {
  316. if (this.disabled) return;
  317. const { name = '', maxCount, multiple, maxSize, fileMaxSize, sizeType, lists, camera, compressed, maxDuration, sourceType } = this;
  318. let chooseFile = null;
  319. const newMaxCount = maxCount - lists.length;
  320. // 设置为只选择图片的时候使用 chooseImage 来实现
  321. chooseFile = new Promise((resolve, reject) => {
  322. uni.chooseFile({
  323. count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1,
  324. sourceType: sourceType,
  325. sizeType,
  326. extension:this.limitType,
  327. success: resolve,
  328. fail: reject
  329. });
  330. });
  331. chooseFile
  332. .then(res => {
  333. let file = null;
  334. let listOldLength = this.lists.length;
  335. res.tempFiles.map((val, index) => {
  336. // 检查文件后缀是否允许,如果不在this.limitType内,就会返回false
  337. if(!this.checkFileExt(val)) return ;
  338. // 如果是非多选,index大于等于1或者超出最大限制数量时,不处理
  339. if (!multiple && index >= 1) return;
  340. console.log(this.getFileExt(val),this.fileLimitType,fileMaxSize)
  341. var ckvalsize=true;
  342. if (this.fileLimitType.indexOf(this.getFileExt(val))>-1) {
  343. if(val.size > fileMaxSize){
  344. this.$emit('on-oversize', val, this.lists, this.index);
  345. this.showToast('超出允许的视频大小'+(fileMaxSize/1024/1024)+"M");
  346. ckvalsize=false
  347. }
  348. }else {
  349. if(val.size > maxSize) {
  350. this.$emit('on-oversize', val, this.lists, this.index);
  351. this.showToast('超出允许的图片大小'+(maxSize/1024/1024)+"M");
  352. ckvalsize=false
  353. }
  354. }
  355. if(!ckvalsize){
  356. }else {
  357. if (maxCount <= lists.length) {
  358. this.$emit('on-exceed', val, this.lists, this.index);
  359. this.showToast('超出最大允许的文件个数');
  360. return;
  361. }
  362. lists.push({
  363. url: val.path,
  364. progress: 0,
  365. error: false,
  366. data:null,
  367. response:null,
  368. file: val,
  369. fileType:val.type
  370. });
  371. }
  372. });
  373. // 每次图片选择完,抛出一个事件,并将当前内部选择的图片数组抛出去
  374. this.$emit('on-choose-complete', this.lists, this.index);
  375. if (this.autoUpload) this.uploadFile(listOldLength);
  376. })
  377. .catch(error => {
  378. this.$emit('on-choose-fail', error);
  379. });
  380. },
  381. // 提示用户消息
  382. showToast(message, force = false) {
  383. if (this.showTips || force) {
  384. uni.showToast({
  385. title: message,
  386. icon: 'none'
  387. });
  388. }
  389. },
  390. // 该方法供用户通过ref调用,手动上传
  391. upload() {
  392. this.uploadFile();
  393. },
  394. // 对失败的图片重新上传
  395. retry(index) {
  396. this.lists[index].progress = 0;
  397. this.lists[index].error = false;
  398. this.lists[index].response = null;
  399. uni.showLoading({
  400. title: '重新上传'
  401. });
  402. this.uploadFile(index);
  403. },
  404. // 上传图片
  405. async uploadFile(index = 0) {
  406. if (this.disabled) return;
  407. if (this.uploading) return;
  408. // 全部上传完成
  409. if (index >= this.lists.length) {
  410. this.$emit('on-uploaded', this.lists, this.index);
  411. return;
  412. }
  413. // 检查是否是已上传或者正在上传中
  414. if (this.lists[index].progress == 100) {
  415. if (this.autoUpload == false) this.uploadFile(index + 1);
  416. return;
  417. }
  418. // 执行before-upload钩子
  419. if(this.beforeUpload && typeof(this.beforeUpload) === 'function') {
  420. // 执行回调,同时传入索引和文件列表当作参数
  421. // 在微信,支付宝等环境(H5正常),会导致父组件定义的customBack()函数体中的this变成子组件的this
  422. // 通过bind()方法,绑定父组件的this,让this.customBack()的this为父组件的上下文
  423. // 因为upload组件可能会被嵌套在其他组件内,比如u-form,这时this.$parent其实为u-form的this,
  424. // 非页面的this,所以这里需要往上历遍,一直寻找到最顶端的$parent,这里用了this.$u.$parent.call(this)
  425. // 明白意思即可,无需纠结this.$u.$parent.call(this)的细节
  426. let beforeResponse = this.beforeUpload.bind(this.$u.$parent.call(this))(index, this.lists);
  427. // 判断是否返回了promise
  428. if (!!beforeResponse && typeof beforeResponse.then === 'function') {
  429. await beforeResponse.then(res => {
  430. // promise返回成功,不进行动作,继续上传
  431. }).catch(err => {
  432. // 进入catch回调的话,继续下一张
  433. return this.uploadFile(index + 1);
  434. })
  435. } else if(beforeResponse === false) {
  436. // 如果返回false,继续下一张图片的上传
  437. return this.uploadFile(index + 1);
  438. } else {
  439. // 此处为返回"true"的情形,这里不写代码,就跳过此处,继续执行当前的上传逻辑
  440. }
  441. }
  442. // 检查上传地址
  443. if (!this.action) {
  444. this.showToast('请配置上传地址', true);
  445. return;
  446. }
  447. this.lists[index].error = false;
  448. this.uploading = true;
  449. // 创建上传对象
  450. const task = uni.uploadFile({
  451. timeout:60*1000*3,
  452. url: this.action,
  453. filePath: this.lists[index].url,
  454. name: this.name,
  455. formData: this.formData,
  456. header: this.header,
  457. // #ifdef MP-ALIPAY
  458. fileType:'image',
  459. // #endif
  460. success: res => {
  461. // 判断是否json字符串,将其转为json格式
  462. let data = this.toJson && this.$u.test.jsonString(res.data) ? JSON.parse(res.data) : res.data;
  463. if (![200, 201, 204].includes(res.statusCode)) {
  464. this.uploadError(index, data);
  465. } else {
  466. if(data.result){
  467. // 上传成功
  468. this.lists[index].response = data;
  469. this.lists[index].progress = 100;
  470. this.lists[index].error = false;
  471. this.$emit('on-success', data, index, this.lists, this.index);
  472. }else{
  473. this.uploadError(index, data.message);
  474. }
  475. }
  476. },
  477. fail: e => {
  478. this.uploadError(index, e);
  479. },
  480. complete: res => {
  481. uni.hideLoading();
  482. this.uploading = false;
  483. this.uploadFile(index + 1);
  484. this.$emit('on-change', res, index, this.lists, this.index);
  485. }
  486. });
  487. task.onProgressUpdate(res => {
  488. if (res.progress > 0) {
  489. this.lists[index].progress = res.progress;
  490. this.$emit('on-progress', res, index, this.lists, this.index);
  491. }
  492. });
  493. },
  494. // 上传失败
  495. uploadError(index, err) {
  496. this.lists[index].progress = 0;
  497. this.lists[index].error = true;
  498. this.lists[index].response = null;
  499. this.$emit('on-error', err, index, this.lists, this.index);
  500. this.showToast('上传失败,请重试');
  501. },
  502. // 删除一个图片
  503. deleteItem(index) {
  504. uni.showModal({
  505. title: '提示',
  506. content: '您确定要删除此项吗?',
  507. success: async (res) => {
  508. if (res.confirm) {
  509. // 先检查是否有定义before-remove移除前钩子
  510. // 执行before-remove钩子
  511. if(this.beforeRemove && typeof(this.beforeRemove) === 'function') {
  512. // 此处钩子执行 原理同before-remove参数,见上方注释
  513. let beforeResponse = this.beforeRemove.bind(this.$u.$parent.call(this))(index, this.lists);
  514. // 判断是否返回了promise
  515. if (!!beforeResponse && typeof beforeResponse.then === 'function') {
  516. await beforeResponse.then(res => {
  517. // promise返回成功,不进行动作,继续上传
  518. this.handlerDeleteItem(index);
  519. }).catch(err => {
  520. // 如果进入promise的reject,终止删除操作
  521. this.showToast('已终止移除');
  522. })
  523. } else if(beforeResponse === false) {
  524. // 返回false,终止删除
  525. this.showToast('已终止移除');
  526. } else {
  527. // 如果返回true,执行删除操作
  528. this.handlerDeleteItem(index);
  529. }
  530. } else {
  531. // 如果不存在before-remove钩子,
  532. this.handlerDeleteItem(index);
  533. }
  534. }
  535. }
  536. });
  537. },
  538. // 执行移除图片的动作,上方代码只是判断是否可以移除
  539. handlerDeleteItem(index) {
  540. // 如果文件正在上传中,终止上传任务,进度在0 < progress < 100则意味着正在上传
  541. if (this.lists[index].progress < 100 && this.lists[index].progress > 0) {
  542. typeof this.lists[index].uploadTask != 'undefined' && this.lists[index].uploadTask.abort();
  543. }
  544. this.lists.splice(index, 1);
  545. this.$forceUpdate();
  546. this.$emit('on-remove', index, this.lists, this.index);
  547. this.showToast('移除成功');
  548. },
  549. // 用户通过ref手动的形式,移除一张图片
  550. remove(index) {
  551. // 判断索引的合法范围
  552. if (index >= 0 && index < this.lists.length) {
  553. this.lists.splice(index, 1);
  554. this.$emit('on-list-change', this.lists, this.index);
  555. }
  556. },
  557. // 预览图片
  558. doPreviewImage(url, index) {
  559. if (!this.previewFullImage) return;
  560. const images = this.lists.map(item => item.url || item.path);
  561. uni.previewImage({
  562. urls: images,
  563. current: url,
  564. success: () => {
  565. this.$emit('on-preview', url, this.lists, this.index);
  566. },
  567. fail: () => {
  568. uni.showToast({
  569. title: '预览图片失败',
  570. icon: 'none'
  571. });
  572. }
  573. });
  574. },
  575. // 判断文件后缀是否允许
  576. getFileExt(file) {
  577. // 检查是否在允许的后缀中
  578. let noArrowExt = false;
  579. // 获取后缀名
  580. let fileExt = '';
  581. const reg = /.+\./;
  582. // 如果是H5,需要从name中判断
  583. // #ifdef H5
  584. fileExt = file.name.replace(reg, "").toLowerCase();
  585. // #endif
  586. // 非H5,需要从path中读取后缀
  587. // #ifndef H5
  588. fileExt = file.path.replace(reg, "").toLowerCase();
  589. // #endif
  590. // 使用数组的some方法,只要符合limitType中的一个,就返回true
  591. return fileExt;
  592. },
  593. // 判断文件后缀是否允许
  594. checkFileExt(file) {
  595. // 检查是否在允许的后缀中
  596. let noArrowExt = false;
  597. // 获取后缀名
  598. let fileExt = '';
  599. const reg = /.+\./;
  600. // 如果是H5,需要从name中判断
  601. // #ifdef H5
  602. fileExt = file.name.replace(reg, "").toLowerCase();
  603. // #endif
  604. // 非H5,需要从path中读取后缀
  605. // #ifndef H5
  606. fileExt = file.path.replace(reg, "").toLowerCase();
  607. // #endif
  608. // 使用数组的some方法,只要符合limitType中的一个,就返回true
  609. noArrowExt = this.limitType.some(ext => {
  610. // 转为小写
  611. return ext.toLowerCase() === fileExt;
  612. })
  613. if(!noArrowExt) this.showToast(`不允许选择${fileExt}格式的文件`);
  614. return noArrowExt;
  615. }
  616. }
  617. };
  618. </script>
  619. <style lang="scss" scoped>
  620. @import '../../libs/css/style.components.scss';
  621. .u-upload {
  622. @include vue-flex;
  623. flex-wrap: wrap;
  624. width: 100%;
  625. align-items: center;
  626. }
  627. .u-list-item {
  628. width: 200rpx;
  629. height: 200rpx;
  630. overflow: hidden;
  631. margin: 10rpx;
  632. background: rgb(244, 245, 246);
  633. position: relative;
  634. border-radius: 10rpx;
  635. /* #ifndef APP-NVUE */
  636. display: flex;
  637. /* #endif */
  638. align-items: center;
  639. justify-content: center;
  640. }
  641. .u-preview-wrap {
  642. border: 1px solid rgb(235, 236, 238);
  643. }
  644. .u-add-wrap {
  645. flex-direction: column;
  646. color: $u-content-color;
  647. font-size: 26rpx;
  648. }
  649. .u-add-tips {
  650. margin-top: 20rpx;
  651. line-height: 40rpx;
  652. }
  653. .u-add-wrap__hover {
  654. background-color: rgb(235, 236, 238);
  655. }
  656. .u-preview-image {
  657. display: block;
  658. width: 100%;
  659. height: 100%;
  660. border-radius: 10rpx;
  661. }
  662. .u-delete-icon {
  663. position: absolute;
  664. top: 10rpx;
  665. right: 10rpx;
  666. z-index: 10;
  667. background-color: $u-type-error;
  668. border-radius: 100rpx;
  669. width: 44rpx;
  670. height: 44rpx;
  671. @include vue-flex;
  672. align-items: center;
  673. justify-content: center;
  674. }
  675. .u-icon {
  676. @include vue-flex;
  677. align-items: center;
  678. justify-content: center;
  679. }
  680. .u-progress {
  681. position: absolute;
  682. bottom: 10rpx;
  683. left: 8rpx;
  684. right: 8rpx;
  685. z-index: 9;
  686. width: auto;
  687. }
  688. .u-primary-btn {
  689. background-color: #59ba73;
  690. }
  691. .u-warning-btn {
  692. background-color: #e6a23c;
  693. }
  694. .u-error-btn{
  695. background-color: $u-type-error;
  696. }
  697. .u-error-btn2 {
  698. color: #ffffff;
  699. font-size: 20rpx;
  700. padding: 4px 0;
  701. text-align: center;
  702. position: absolute;
  703. bottom: 0;
  704. left: 0;
  705. right: 0;
  706. z-index: 9;
  707. line-height: 1;
  708. }
  709. </style>