u-upload.vue 22 KB

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