apiCloud 选择图片,选择视频,压缩图片

选择视频或图片,只需要一个 UIMediaScanner 模板就可以实现,点击链接查看api

https://docs.apicloud.com/Client-API/UI-Layout/UIMediaScanner

textareaClick: [{
   text: '',
   img: [],
   realImg: [],
   realVideo: [],
   video: []
}],

        
        var app = new Vue({
el: "#app",
data: function() {
return {
textareaClick: [{
text: '',
img: [],
realImg: [],
realVideo: [],
video: []
}],
token: ''
}
},
methods: {
          upload_image: function(index) {
            //选择图片与视频
var this_obj = this;
var UIMediaScanner = api.require('UIMediaScanner');
UIMediaScanner.open({
type: 'all', //视频与图片,all(图片和视频)picture(图片)video(视频)
column: ,
classify: true,
max: ,
sort: {
key: 'time',
order: 'desc'
},
texts: {
stateText: '已选择*项',
cancelText: '取消',
finishText: '完成'
},
styles: {
bg: '#fff',
mark: {
icon: '',
position: 'bottom_left',
size:
},
nav: {
bg: '#eee',
stateColor: '#000',
stateSize: ,
cancelBg: 'rgba(0,0,0,0)',
cancelColor: '#000',
cancelSize: ,
finishBg: 'rgba(0,0,0,0)',
finishColor: '#000',
finishSize:
}
},
scrollToBottom: {
intervalTime: -
},
exchange: true,
rotation: true
}, function(ret) {
if (ret) {
if (ret.eventType == 'confirm') {
this_obj.compress_img(ret.list, index);
}
}
});
},
compress_img: function(img_arr, arr_index) {
            //压缩图片
var UIMediaScanner = api.require('UIMediaScanner');
var imageFilter = api.require("imageFilter");
var temp_path1 = img_arr.shift();
temp_path = temp_path1.path;
var filename = Math.random() + '.jpg';
var this_obj = this;
var target_w = ;
var type_play = temp_path1.suffix
if (api.systemType == "ios") {
UIMediaScanner.transPath({
path: temp_path
}, function(res, err) {
if (res.status) {
if (type_play == 'mp4') {
this_obj.textareaClick[arr_index].video.push(res.path);
} else {
imageFilter.getAttr({
path: res.path
}, function(ret, err) {
if (ret.status) {
if (ret.width < target_w) {
target_w = ret.width;
}
var original_w = ret.width;
var original_h = ret.height;
var scale = original_w / target_w;
var target_h = Math.round(original_h / scale);
imageFilter.compress({
img: res.path,
quality: ,
size: {
w: target_w,
h: target_h
},
save: {
album: false,
imgPath: api.cacheDir + '/upload/',
imgName: filename
}
}, function(ret, err) {
if (ret.status) {
this_obj.textareaClick[arr_index].img.push(api.cacheDir + '/upload/' + filename);
if (img_arr.length > ) {
this_obj.compress_img(img_arr, arr_index);
}
}
});
}
});
}
} else {
api.toast({
msg: err
});
}
})
} else {
if (type_play == 'mp4') {
this_obj.textareaClick[arr_index].video.push(temp_path);
} else {
imageFilter.getAttr({
path: temp_path
}, function(ret, err) {
if (ret.status) {
if (ret.width < target_w) {
target_w = ret.width;
}
var original_w = ret.width;
var original_h = ret.height;
var scale = original_w / target_w;
var target_h = Math.round(original_h / scale);
imageFilter.compress({
img: temp_path,
quality: ,
size: {
w: target_w,
h: target_h
},
save: {
album: false,
imgPath: api.cacheDir + '/upload/',
imgName: filename
}
}, function(ret, err) {
if (ret.status) {
this_obj.textareaClick[arr_index].img.push(api.cacheDir + '/upload/' + filename);
if (img_arr.length > ) {
this_obj.compress_img(img_arr, arr_index);
}
}
});
}
});
}
}
} }
})

 

console.log(this_obj.textareaClick)可以查看这个数组

上一篇:swiper 父级元素display:none 之bug


下一篇:httpcomponents-client-4.3.x DOC