u-upload-file.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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: 52
  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: true
  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. // 显示已上传的文件列表
  181. fileList: {
  182. type: Array,
  183. default() {
  184. return [];
  185. }
  186. },
  187. // 上传区域的提示文字
  188. uploadText: {
  189. type: String,
  190. default: '图片/视频'
  191. },
  192. // 是否自动上传
  193. autoUpload: {
  194. type: Boolean,
  195. default: true
  196. },
  197. // 是否显示toast消息提示
  198. showTips: {
  199. type: Boolean,
  200. default: true
  201. },
  202. // 是否通过slot自定义传入选择图标的按钮
  203. customBtn: {
  204. type: Boolean,
  205. default: false
  206. },
  207. // 内部预览图片区域和选择图片按钮的区域宽度
  208. width: {
  209. type: [String, Number],
  210. default: 200
  211. },
  212. // 内部预览图片区域和选择图片按钮的区域高度
  213. height: {
  214. type: [String, Number],
  215. default: 200
  216. },
  217. // 右上角关闭按钮的背景颜色
  218. delBgColor: {
  219. type: String,
  220. default: '#fa3534'
  221. },
  222. // 右上角关闭按钮的叉号图标的颜色
  223. delColor: {
  224. type: String,
  225. default: '#ffffff'
  226. },
  227. // 右上角删除图标名称,只能为uView内置图标
  228. delIcon: {
  229. type: String,
  230. default: 'close'
  231. },
  232. // 如果上传后的返回值为json字符串,是否自动转json
  233. toJson: {
  234. type: Boolean,
  235. default: true
  236. },
  237. // 上传前的钩子,每个文件上传前都会执行
  238. beforeUpload: {
  239. type: Function,
  240. default: null
  241. },
  242. // 移除文件前的钩子
  243. beforeRemove: {
  244. type: Function,
  245. default: null
  246. },
  247. // 允许上传的图片后缀
  248. limitType:{
  249. type: Array,
  250. default() {
  251. // 支付宝小程序真机选择图片的后缀为"image"
  252. // https://opendocs.alipay.com/mini/api/media-image
  253. return ['png', 'jpg', 'jpeg', 'webp', 'gif', 'image','mp4'];
  254. }
  255. },
  256. // 在各个回调事件中的最后一个参数返回,用于区别是哪一个组件的事件
  257. index: {
  258. type: [Number, String],
  259. default: ''
  260. }
  261. },
  262. mounted() {},
  263. data() {
  264. return {
  265. lists: [],
  266. isInCount: true,
  267. uploading: false
  268. };
  269. },
  270. watch: {
  271. fileList: {
  272. immediate: true,
  273. handler(val) {
  274. val.map(value => {
  275. // 首先检查内部是否已经添加过这张图片,因为外部绑定了一个对象给fileList的话(对象引用),进行修改外部fileList
  276. // 时,会触发watch,导致重新把原来的图片再次添加到this.lists
  277. // 数组的some方法意思是,只要数组元素有任意一个元素条件符合,就返回true,而另一个数组的every方法的意思是数组所有元素都符合条件才返回true
  278. let tmp = this.lists.some(val => {
  279. return val.url == value.url;
  280. })
  281. // 如果内部没有这个图片(tmp为false),则添加到内部
  282. !tmp && this.lists.push({ url: value.url, error: false, progress: 100 });
  283. });
  284. }
  285. },
  286. // 监听lists的变化,发出事件
  287. lists(n) {
  288. this.$emit('on-list-change', n, this.index);
  289. }
  290. },
  291. methods: {
  292. // 清除列表
  293. clear() {
  294. this.lists = [];
  295. },
  296. // 重新上传队列中上传失败的所有文件
  297. reUpload() {
  298. this.uploadFile();
  299. },
  300. // 选择图片
  301. selectFile() {
  302. if (this.disabled) return;
  303. const { name = '', maxCount, multiple, maxSize, sizeType, lists, camera, compressed, maxDuration, sourceType } = this;
  304. let chooseFile = null;
  305. const newMaxCount = maxCount - lists.length;
  306. // 设置为只选择图片的时候使用 chooseImage 来实现
  307. chooseFile = new Promise((resolve, reject) => {
  308. uni.chooseFile({
  309. count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1,
  310. sourceType: sourceType,
  311. sizeType,
  312. extension:this.limitType,
  313. success: resolve,
  314. fail: reject
  315. });
  316. });
  317. chooseFile
  318. .then(res => {
  319. let file = null;
  320. let listOldLength = this.lists.length;
  321. res.tempFiles.map((val, index) => {
  322. // 检查文件后缀是否允许,如果不在this.limitType内,就会返回false
  323. if(!this.checkFileExt(val)) return ;
  324. // 如果是非多选,index大于等于1或者超出最大限制数量时,不处理
  325. if (!multiple && index >= 1) return;
  326. if (val.size > maxSize) {
  327. this.$emit('on-oversize', val, this.lists, this.index);
  328. this.showToast('超出允许的文件大小'+(maxSize/1024/1024)+"M");
  329. } else {
  330. if (maxCount <= lists.length) {
  331. this.$emit('on-exceed', val, this.lists, this.index);
  332. this.showToast('超出最大允许的文件个数');
  333. return;
  334. }
  335. lists.push({
  336. url: val.path,
  337. progress: 0,
  338. error: false,
  339. data:null,
  340. response:null,
  341. file: val,
  342. fileType:val.type
  343. });
  344. }
  345. });
  346. // 每次图片选择完,抛出一个事件,并将当前内部选择的图片数组抛出去
  347. this.$emit('on-choose-complete', this.lists, this.index);
  348. if (this.autoUpload) this.uploadFile(listOldLength);
  349. })
  350. .catch(error => {
  351. this.$emit('on-choose-fail', error);
  352. });
  353. },
  354. // 提示用户消息
  355. showToast(message, force = false) {
  356. if (this.showTips || force) {
  357. uni.showToast({
  358. title: message,
  359. icon: 'none'
  360. });
  361. }
  362. },
  363. // 该方法供用户通过ref调用,手动上传
  364. upload() {
  365. this.uploadFile();
  366. },
  367. // 对失败的图片重新上传
  368. retry(index) {
  369. this.lists[index].progress = 0;
  370. this.lists[index].error = false;
  371. this.lists[index].response = null;
  372. uni.showLoading({
  373. title: '重新上传'
  374. });
  375. this.uploadFile(index);
  376. },
  377. // 上传图片
  378. async uploadFile(index = 0) {
  379. if (this.disabled) return;
  380. if (this.uploading) return;
  381. // 全部上传完成
  382. if (index >= this.lists.length) {
  383. this.$emit('on-uploaded', this.lists, this.index);
  384. return;
  385. }
  386. // 检查是否是已上传或者正在上传中
  387. if (this.lists[index].progress == 100) {
  388. if (this.autoUpload == false) this.uploadFile(index + 1);
  389. return;
  390. }
  391. // 执行before-upload钩子
  392. if(this.beforeUpload && typeof(this.beforeUpload) === 'function') {
  393. // 执行回调,同时传入索引和文件列表当作参数
  394. // 在微信,支付宝等环境(H5正常),会导致父组件定义的customBack()函数体中的this变成子组件的this
  395. // 通过bind()方法,绑定父组件的this,让this.customBack()的this为父组件的上下文
  396. // 因为upload组件可能会被嵌套在其他组件内,比如u-form,这时this.$parent其实为u-form的this,
  397. // 非页面的this,所以这里需要往上历遍,一直寻找到最顶端的$parent,这里用了this.$u.$parent.call(this)
  398. // 明白意思即可,无需纠结this.$u.$parent.call(this)的细节
  399. let beforeResponse = this.beforeUpload.bind(this.$u.$parent.call(this))(index, this.lists);
  400. // 判断是否返回了promise
  401. if (!!beforeResponse && typeof beforeResponse.then === 'function') {
  402. await beforeResponse.then(res => {
  403. // promise返回成功,不进行动作,继续上传
  404. }).catch(err => {
  405. // 进入catch回调的话,继续下一张
  406. return this.uploadFile(index + 1);
  407. })
  408. } else if(beforeResponse === false) {
  409. // 如果返回false,继续下一张图片的上传
  410. return this.uploadFile(index + 1);
  411. } else {
  412. // 此处为返回"true"的情形,这里不写代码,就跳过此处,继续执行当前的上传逻辑
  413. }
  414. }
  415. // 检查上传地址
  416. if (!this.action) {
  417. this.showToast('请配置上传地址', true);
  418. return;
  419. }
  420. this.lists[index].error = false;
  421. this.uploading = true;
  422. // 创建上传对象
  423. const task = uni.uploadFile({
  424. timeout:60*1000*3,
  425. url: this.action,
  426. filePath: this.lists[index].url,
  427. name: this.name,
  428. formData: this.formData,
  429. header: this.header,
  430. // #ifdef MP-ALIPAY
  431. fileType:'image',
  432. // #endif
  433. success: res => {
  434. // 判断是否json字符串,将其转为json格式
  435. let data = this.toJson && this.$u.test.jsonString(res.data) ? JSON.parse(res.data) : res.data;
  436. if (![200, 201, 204].includes(res.statusCode)) {
  437. this.uploadError(index, data);
  438. } else {
  439. if(data.result){
  440. // 上传成功
  441. this.lists[index].response = data;
  442. this.lists[index].progress = 100;
  443. this.lists[index].error = false;
  444. this.$emit('on-success', data, index, this.lists, this.index);
  445. }else{
  446. this.uploadError(index, data.message);
  447. }
  448. }
  449. },
  450. fail: e => {
  451. this.uploadError(index, e);
  452. },
  453. complete: res => {
  454. uni.hideLoading();
  455. this.uploading = false;
  456. this.uploadFile(index + 1);
  457. this.$emit('on-change', res, index, this.lists, this.index);
  458. }
  459. });
  460. task.onProgressUpdate(res => {
  461. if (res.progress > 0) {
  462. this.lists[index].progress = res.progress;
  463. this.$emit('on-progress', res, index, this.lists, this.index);
  464. }
  465. });
  466. },
  467. // 上传失败
  468. uploadError(index, err) {
  469. this.lists[index].progress = 0;
  470. this.lists[index].error = true;
  471. this.lists[index].response = null;
  472. this.$emit('on-error', err, index, this.lists, this.index);
  473. this.showToast('上传失败,请重试');
  474. },
  475. // 删除一个图片
  476. deleteItem(index) {
  477. uni.showModal({
  478. title: '提示',
  479. content: '您确定要删除此项吗?',
  480. success: async (res) => {
  481. if (res.confirm) {
  482. // 先检查是否有定义before-remove移除前钩子
  483. // 执行before-remove钩子
  484. if(this.beforeRemove && typeof(this.beforeRemove) === 'function') {
  485. // 此处钩子执行 原理同before-remove参数,见上方注释
  486. let beforeResponse = this.beforeRemove.bind(this.$u.$parent.call(this))(index, this.lists);
  487. // 判断是否返回了promise
  488. if (!!beforeResponse && typeof beforeResponse.then === 'function') {
  489. await beforeResponse.then(res => {
  490. // promise返回成功,不进行动作,继续上传
  491. this.handlerDeleteItem(index);
  492. }).catch(err => {
  493. // 如果进入promise的reject,终止删除操作
  494. this.showToast('已终止移除');
  495. })
  496. } else if(beforeResponse === false) {
  497. // 返回false,终止删除
  498. this.showToast('已终止移除');
  499. } else {
  500. // 如果返回true,执行删除操作
  501. this.handlerDeleteItem(index);
  502. }
  503. } else {
  504. // 如果不存在before-remove钩子,
  505. this.handlerDeleteItem(index);
  506. }
  507. }
  508. }
  509. });
  510. },
  511. // 执行移除图片的动作,上方代码只是判断是否可以移除
  512. handlerDeleteItem(index) {
  513. // 如果文件正在上传中,终止上传任务,进度在0 < progress < 100则意味着正在上传
  514. if (this.lists[index].progress < 100 && this.lists[index].progress > 0) {
  515. typeof this.lists[index].uploadTask != 'undefined' && this.lists[index].uploadTask.abort();
  516. }
  517. this.lists.splice(index, 1);
  518. this.$forceUpdate();
  519. this.$emit('on-remove', index, this.lists, this.index);
  520. this.showToast('移除成功');
  521. },
  522. // 用户通过ref手动的形式,移除一张图片
  523. remove(index) {
  524. // 判断索引的合法范围
  525. if (index >= 0 && index < this.lists.length) {
  526. this.lists.splice(index, 1);
  527. this.$emit('on-list-change', this.lists, this.index);
  528. }
  529. },
  530. // 预览图片
  531. doPreviewImage(url, index) {
  532. if (!this.previewFullImage) return;
  533. const images = this.lists.map(item => item.url || item.path);
  534. uni.previewImage({
  535. urls: images,
  536. current: url,
  537. success: () => {
  538. this.$emit('on-preview', url, this.lists, this.index);
  539. },
  540. fail: () => {
  541. uni.showToast({
  542. title: '预览图片失败',
  543. icon: 'none'
  544. });
  545. }
  546. });
  547. },
  548. // 判断文件后缀是否允许
  549. checkFileExt(file) {
  550. // 检查是否在允许的后缀中
  551. let noArrowExt = false;
  552. // 获取后缀名
  553. let fileExt = '';
  554. const reg = /.+\./;
  555. // 如果是H5,需要从name中判断
  556. // #ifdef H5
  557. fileExt = file.name.replace(reg, "").toLowerCase();
  558. // #endif
  559. // 非H5,需要从path中读取后缀
  560. // #ifndef H5
  561. fileExt = file.path.replace(reg, "").toLowerCase();
  562. // #endif
  563. // 使用数组的some方法,只要符合limitType中的一个,就返回true
  564. noArrowExt = this.limitType.some(ext => {
  565. // 转为小写
  566. return ext.toLowerCase() === fileExt;
  567. })
  568. if(!noArrowExt) this.showToast(`不允许选择${fileExt}格式的文件`);
  569. return noArrowExt;
  570. }
  571. }
  572. };
  573. </script>
  574. <style lang="scss" scoped>
  575. @import '../../libs/css/style.components.scss';
  576. .u-upload {
  577. @include vue-flex;
  578. flex-wrap: wrap;
  579. width: 100%;
  580. align-items: center;
  581. }
  582. .u-list-item {
  583. width: 200rpx;
  584. height: 200rpx;
  585. overflow: hidden;
  586. margin: 10rpx;
  587. background: rgb(244, 245, 246);
  588. position: relative;
  589. border-radius: 10rpx;
  590. /* #ifndef APP-NVUE */
  591. display: flex;
  592. /* #endif */
  593. align-items: center;
  594. justify-content: center;
  595. }
  596. .u-preview-wrap {
  597. border: 1px solid rgb(235, 236, 238);
  598. }
  599. .u-add-wrap {
  600. flex-direction: column;
  601. color: $u-content-color;
  602. font-size: 26rpx;
  603. }
  604. .u-add-tips {
  605. margin-top: 20rpx;
  606. line-height: 40rpx;
  607. }
  608. .u-add-wrap__hover {
  609. background-color: rgb(235, 236, 238);
  610. }
  611. .u-preview-image {
  612. display: block;
  613. width: 100%;
  614. height: 100%;
  615. border-radius: 10rpx;
  616. }
  617. .u-delete-icon {
  618. position: absolute;
  619. top: 10rpx;
  620. right: 10rpx;
  621. z-index: 10;
  622. background-color: $u-type-error;
  623. border-radius: 100rpx;
  624. width: 44rpx;
  625. height: 44rpx;
  626. @include vue-flex;
  627. align-items: center;
  628. justify-content: center;
  629. }
  630. .u-icon {
  631. @include vue-flex;
  632. align-items: center;
  633. justify-content: center;
  634. }
  635. .u-progress {
  636. position: absolute;
  637. bottom: 10rpx;
  638. left: 8rpx;
  639. right: 8rpx;
  640. z-index: 9;
  641. width: auto;
  642. }
  643. .u-primary-btn {
  644. background-color: #59ba73;
  645. }
  646. .u-warning-btn {
  647. background-color: #e6a23c;
  648. }
  649. .u-error-btn{
  650. background-color: $u-type-error;
  651. }
  652. .u-error-btn2 {
  653. color: #ffffff;
  654. font-size: 20rpx;
  655. padding: 4px 0;
  656. text-align: center;
  657. position: absolute;
  658. bottom: 0;
  659. left: 0;
  660. right: 0;
  661. z-index: 9;
  662. line-height: 1;
  663. }
  664. </style>