1
0

u-upload.vue 21 KB

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