游湖阿代码

This commit is contained in:
java110 2022-01-01 13:57:13 +08:00
parent cf5777bc02
commit ad0846b50b

View File

@ -1,4 +1,4 @@
(function (vc) { (function(vc) {
var photoUrl = '/callComponent/download/getFile/file'; var photoUrl = '/callComponent/download/getFile/file';
@ -17,54 +17,54 @@
watch: { watch: {
uploadImageInfo: { uploadImageInfo: {
deep: true, deep: true,
handler: function () { handler: function() {
vc.emit($props.callBackListener, $props.callBackFunction, this.uploadImageInfo.photos); vc.emit($props.callBackListener, $props.callBackFunction, this.uploadImageInfo.photos);
} }
} }
}, },
_initMethod: function () { _initMethod: function() {
let _imageCount = $props.imageCount; let _imageCount = $props.imageCount;
if (_imageCount != 99) { if (_imageCount != 99) {
this.uploadImageInfo.imageCount = _imageCount; this.uploadImageInfo.imageCount = _imageCount;
} }
}, },
_initEvent: function () { _initEvent: function() {
vc.on('uploadImage', 'openAddApplicationKeyModal', function () { vc.on('uploadImage', 'openAddApplicationKeyModal', function() {
}); });
vc.on('uploadImage', 'clearImage', function () { vc.on('uploadImage', 'clearImage', function() {
this.uploadImageInfo = { this.uploadImageInfo = {
photos: [], photos: [],
imageCount: 99 imageCount: 99
} }
}); });
vc.on('uploadImage', 'notifyPhotos', function (_photos) { vc.on('uploadImage', 'notifyPhotos', function(_photos) {
let _imageCount = this.uploadImageInfo.imageCount; let _imageCount = this.uploadImageInfo.imageCount;
this.uploadImageInfo = { this.uploadImageInfo = {
photos: [], photos: [],
imageCount: _imageCount imageCount: _imageCount
}; };
_photos.forEach(function (_photo) { _photos.forEach(function(_photo) {
//?objId=772019092507000013&communityId=7020181217000001&fileTypeCd=10000 //?objId=772019092507000013&communityId=7020181217000001&fileTypeCd=10000
if (_photo.indexOf('base64,') > -1) { if (_photo.indexOf('base64,') > -1) {
this.uploadImageInfo.photos.push(_photo); this.uploadImageInfo.photos.push(_photo);
return; return;
} }
if (_photo.indexOf("https") > -1 || _photo.indexOf("http") > -1) { if (_photo.indexOf("https") > -1 || _photo.indexOf("http") > -1) {
vc.urlToBase64(_photo, function (_base64Data) { vc.urlToBase64(_photo, function(_base64Data) {
this.uploadImageInfo.photos.push(_base64Data); this.uploadImageInfo.photos.push(_base64Data);
}); });
return; return;
} }
if (_photo.indexOf(photoUrl) > -1) { if (_photo.indexOf(photoUrl) > -1) {
vc.urlToBase64(_photo, function (_base64Data) { vc.urlToBase64(_photo, function(_base64Data) {
this.uploadImageInfo.photos.push(_base64Data); this.uploadImageInfo.photos.push(_base64Data);
}); });
return; return;
} }
vc.urlToBase64(photoUrl + "?fileId=" + _photo + "&communityId=" + vc.getCurrentCommunity().communityId + "&time=" + new Date(), function (_base64Data) { vc.urlToBase64(photoUrl + "?fileId=" + _photo + "&communityId=-1&time=" + new Date(), function(_base64Data) {
this.uploadImageInfo.photos.push(_base64Data); this.uploadImageInfo.photos.push(_base64Data);
}) })
}); });
@ -72,27 +72,27 @@
}, },
methods: { methods: {
_uploadPhoto: function (event) { _uploadPhoto: function(event) {
$("#uploadImage").trigger("click") $("#uploadImage").trigger("click")
}, },
_choosePhoto: function (event) { _choosePhoto: function(event) {
var photoFiles = event.target.files; var photoFiles = event.target.files;
if (photoFiles && photoFiles.length > 0) { if (photoFiles && photoFiles.length > 0) {
// 获取目前上传的文件 // 获取目前上传的文件
var file = photoFiles[0];// 文件大小校验的动作 var file = photoFiles[0]; // 文件大小校验的动作
if (file.size > 1024 * 1024 * 2) { if (file.size > 1024 * 1024 * 2) {
vc.toast("图片大小不能超过 2MB!") vc.toast("图片大小不能超过 2MB!")
return false; return false;
} }
var reader = new FileReader(); //新建FileReader对象 var reader = new FileReader(); //新建FileReader对象
reader.readAsDataURL(file); //读取为base64 reader.readAsDataURL(file); //读取为base64
reader.onloadend = function (e) { reader.onloadend = function(e) {
this.uploadImageInfo.photos.push(reader.result); this.uploadImageInfo.photos.push(reader.result);
} }
} }
event.target.value = null; event.target.value = null;
}, },
_removeImage: function (_photo) { _removeImage: function(_photo) {
var _tmpPhotos = this.uploadImageInfo.photos; var _tmpPhotos = this.uploadImageInfo.photos;
this.uploadImageInfo.photos = []; this.uploadImageInfo.photos = [];
for (var _photoIndex = 0; _photoIndex < _tmpPhotos.length; _photoIndex++) { for (var _photoIndex = 0; _photoIndex < _tmpPhotos.length; _photoIndex++) {