11 lines
9.2 KiB
JavaScript
11 lines
9.2 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["tuniao-ui/components/tn-image-upload/tn-image-upload"],{"113f":function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"c",(function(){return o})),n.d(t,"a",(function(){return s}));var s={tnLineProgress:function(){return n.e("tuniao-ui/components/tn-line-progress/tn-line-progress").then(n.bind(null,"d277"))}},i=function(){var e=this,t=e.$createElement,n=(e._self._c,e.showUploadList?e.__map(e.lists,(function(t,n){var s=e.__get_orig(t),i=e.$tn.string.getLengthUnitValue(e.width),o=e.$tn.string.getLengthUnitValue(e.height);return{$orig:s,g0:i,g1:o}})):null);e.$initSSP();var s=e.lists.length,i=e.maxCount>s&&!e.customBtn?e.$tn.string.getLengthUnitValue(e.width):null,o=e.maxCount>s&&!e.customBtn?e.$tn.string.getLengthUnitValue(e.height):null;e.$mp.data=Object.assign({},{$root:{l0:n,g2:s,g3:i,g4:o}}),"augmented"===e.$scope.data.scopedSlotsCompiler&&e.$setSSP("file",{file:e.lists}),e.$callSSP()},o=[]},"79e9":function(e,t,n){"use strict";n.r(t);var s=n("7df7"),i=n.n(s);for(var o in s)["default"].indexOf(o)<0&&function(e){n.d(t,e,(function(){return s[e]}))}(o);t["default"]=i.a},"7df7":function(e,t,n){"use strict";(function(e,s){var i=n("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o=i(n("2eee")),a=i(n("c973")),r={name:"tn-image-upload",props:{fileList:{type:Array,default:function(){return[]}},isUniCloud:{type:Boolean,default:!1},action:{type:String,default:""},name:{type:String,default:"file"},header:{type:Object,default:function(){return{}}},formData:{type:Object,default:function(){return{}}},disabled:{type:Boolean,default:!1},autoUpload:{type:Boolean,default:!0},maxCount:{type:Number,default:9},showUploadList:{type:Boolean,default:!0},imageMode:{type:String,default:"aspectFill"},previewFullImage:{type:Boolean,default:!0},showProgress:{type:Boolean,default:!0},deleteable:{type:Boolean,default:!0},deleteIcon:{type:String,default:"close"},deleteBackgroundColor:{type:String,default:""},deleteColor:{type:String,default:""},uploadText:{type:String,default:"选择图片"},showTips:{type:Boolean,default:!0},customBtn:{type:Boolean,default:!1},width:{type:Number,default:200},height:{type:Number,default:200},sizeType:{type:Array,default:function(){return["original","compressed"]}},sourceType:{type:Array,default:function(){return["album","camera"]}},multiple:{type:Boolean,default:!0},maxSize:{type:Number,default:10485760},limitType:{type:Array,default:function(){return["png","jpg","jpeg","webp","gif","image"]}},toJson:{type:Boolean,default:!0},beforeUpload:{type:Function,default:null},beforeRemove:{type:Function,default:null},index:{type:[Number,String],default:""}},computed:{},data:function(){return{lists:[],uploading:!1}},watch:{fileList:{handler:function(e){var t=this;e.map((function(e){var n=t.lists.some((function(t){return t.url===e.url}));!n&&t.lists.push({url:e.url,error:!1,progress:100})}))},immediate:!0},lists:function(e){this.$emit("on-list-change",e,this.index)}},methods:{clear:function(){this.lists=[]},reUpload:function(){this.uploadFile()},selectFile:function(){var t=this;if(!this.disabled){this.name;var n=this.maxCount,s=this.multiple,i=this.maxSize,o=this.sizeType,a=this.lists,r=(this.camera,this.compressed,this.sourceType),l=null,u=n-a.length;l=new Promise((function(t,n){e.chooseImage({count:s?u>9?9:u:1,sourceType:r,sizeType:o,success:t,fail:n})})),l.then((function(e){var o=a.length;e.tempFiles.map((function(e,o){if(t.checkFileExt(e)&&(s||!(o>=1)))if(e.size>i)t.$emit("on-oversize",e,a,t.index),t.showToast("超出可允许文件大小");else{if(n<=a.length)return t.$emit("on-exceed",e,a,t.index),void t.showToast("超出最大允许的文件数");a.push({url:e.path,progress:0,error:!1,file:e,extension:e.path.substring(e.path.lastIndexOf("."))})}})),t.$emit("on-choose-complete",t.lists,t.index),t.autoUpload&&t.uploadFile(o)})).catch((function(e){t.$emit("on-choose-fail",e)}))}},showToast:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];(this.showTips||t)&&this.$tn.message.toast(e)},upload:function(){this.uploadFile()},retry:function(e){this.lists[e].progress=0,this.lists[e].error=!1,this.lists[e].response=null,this.$tn.message.loading("重新上传"),this.uploadFile(e)},uploadFile:function(){var t=arguments,n=this;return(0,a.default)(o.default.mark((function i(){var a,r,l,u,d;return o.default.wrap((function(i){while(1)switch(i.prev=i.next){case 0:if(a=t.length>0&&void 0!==t[0]?t[0]:0,r=n,!n.disabled){i.next=4;break}return i.abrupt("return");case 4:if(!n.uploading){i.next=6;break}return i.abrupt("return");case 6:if(!(a>=n.lists.length)){i.next=9;break}return n.$emit("on-uploaded",n.lists,n.index),i.abrupt("return");case 9:if(100!==n.lists[a].progress){i.next=13;break}return n.lists[a].uploadTask=null,n.autoUpload&&n.uploadFile(a+1),i.abrupt("return");case 13:if(!n.beforeUpload||"function"!==typeof n.beforeUpload){i.next=24;break}if(l=n.beforeUpload.bind(n.$tn.$parent.call(n))(a,n.lists),!l||"function"!==typeof l.then){i.next=20;break}return i.next=18,l.then((function(e){})).catch((function(e){return n.uploadFile(a+1)}));case 18:i.next=24;break;case 20:if(!1!==l){i.next=24;break}return i.abrupt("return",n.uploadFile(a+1));case 24:if(!n.isUniCloud){i.next=31;break}n.lists[a].error=!1,n.uploading=!0,u=s.uploadFile({filePath:r.lists[a].url,cloudPath:r.$tn.uuid()+r.lists[a].extension,onUploadProgress:function(e){e.loaded>0&&(r.lists[a].progress=Math.round(100*e.loaded/e.total),r.$emit("on-progress",e,a,r.lists,r.index))},success:function(e){e.success?(r.lists[a].response=e,r.lists[a].progress=100,r.lists[a].error=!1,r.$emit("success",e,a,r.lists,r.index)):r.uploadError(a,e)},fail:function(e){r.uploadError(a,e)},complete:function(e){r.uploading=!1,r.uploadFile(a+1),r.$emit("on-change",e,a,r.lists,r.index)}}),r.lists[a].uploadTask=u,i.next=39;break;case 31:if(n.action){i.next=34;break}return n.showToast("请配置上传地址",!0),i.abrupt("return");case 34:n.lists[a].error=!1,n.uploading=!0,d=e.uploadFile({url:n.action,filePath:n.lists[a].url,name:n.name,formData:n.formData,header:n.header,success:function(e){var t=n.toJson&&n.$tn.test.jsonString(e.data)?JSON.parse(e.data):e.data;[200,201,204].includes(e.statusCode)?(n.lists[a].response=t,n.lists[a].progress=100,n.lists[a].error=!1,n.$emit("on-success",t,a,n.lists,n.index)):n.uploadError(a,t)},fail:function(e){n.uploadError(a,e)},complete:function(e){n.$tn.message.closeLoading(),n.uploading=!1,n.uploadFile(a+1),n.$emit("on-change",e,a,n.lists,n.index)}}),n.lists[a].uploadTask=d,d.onProgressUpdate((function(e){e.progress>0&&(n.lists[a].progress=e.progress,n.$emit("on-progress",e,a,n.lists,n.index))}));case 39:case"end":return i.stop()}}),i)})))()},uploadError:function(e,t){this.lists[e].progress=0,this.lists[e].error=!0,this.lists[e].response=null,this.showToast("上传失败,请重试"),this.$emit("on-error",t,e,this.lists,this.index)},deleteItem:function(e){var t=this;this.deleteable&&this.$tn.message.modal("提示","您确定要删除吗?",(0,a.default)(o.default.mark((function n(){var s;return o.default.wrap((function(n){while(1)switch(n.prev=n.next){case 0:if(!t.beforeRemove||"function"!==typeof t.beforeRemove){n.next=10;break}if(s=t.beforeRemove.bind(t.$tn.$parent.call(t))(e,t.lists),!s||"function"!==typeof s.then){n.next=7;break}return n.next=5,s.then((function(n){t.handlerDeleteItem(e)})).catch((function(e){t.showToast("删除操作被中断")}));case 5:n.next=8;break;case 7:!1===s?t.showToast("删除操作被中断"):t.handlerDeleteItem(e);case 8:n.next=11;break;case 10:t.handlerDeleteItem(e);case 11:case"end":return n.stop()}}),n)}))),!0)},handlerDeleteItem:function(e){this.lists[e].progress<100&&this.lists[e].progress>0&&"undefined"!==typeof this.lists[e].uploadTask&&this.lists[e].uploadTask.abort(),this.lists.splice(e,1),this.$forceUpdate(),this.$emit("on-remove",e,this.lists,this.index),this.showToast("删除成功")},remove:function(e){this.deleteable&&e>=0&&e<this.lists.length&&this.lists.splice(e,1)},doPreviewImage:function(t,n){var s=this;if(this.previewFullImage){var i=this.lists.map((function(e){return e.url||e.path}));e.previewImage({urls:i,current:t,success:function(){s.$emit("on-preview",t,s.lists,s.index)},fail:function(){s.showToast("预览图片失败")}})}},checkFileExt:function(e){var t,n;return n=e.path.replace(/.+\./,"").toLowerCase(),t=this.limitType.some((function(e){return e.toLowerCase()===n})),t||this.showToast("不支持".concat(n,"格式的文件")),t}}};t.default=r}).call(this,n("543d")["default"],n("a9ff")["default"])},"8be7":function(e,t,n){"use strict";n.r(t);var s=n("113f"),i=n("79e9");for(var o in i)["default"].indexOf(o)<0&&function(e){n.d(t,e,(function(){return i[e]}))}(o);n("d581");var a=n("f0c5"),r=Object(a["a"])(i["default"],s["b"],s["c"],!1,null,"ee581f36",null,!1,s["a"],void 0);t["default"]=r.exports},ac87:function(e,t,n){},d581:function(e,t,n){"use strict";var s=n("ac87"),i=n.n(s);i.a}}]);
|
|
;(global["webpackJsonp"] = global["webpackJsonp"] || []).push([
|
|
'tuniao-ui/components/tn-image-upload/tn-image-upload-create-component',
|
|
{
|
|
'tuniao-ui/components/tn-image-upload/tn-image-upload-create-component':(function(module, exports, __webpack_require__){
|
|
__webpack_require__('543d')['createComponent'](__webpack_require__("8be7"))
|
|
})
|
|
},
|
|
[['tuniao-ui/components/tn-image-upload/tn-image-upload-create-component']]
|
|
]);
|