更新记录
1.0.0(2020-10-29)
首次更新
原生插件通用使用流程:
购买插件,选择该插件绑定的项目。
在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
开发完毕后正式云打包
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
KJ-FileSlice
大文件切片、分块、分段、分片,数据可用于分块上传(ios、android)
引入插件
const KJFileSlice = uni.requireNativePlugin(‘KJ-FileSlice’);
相关代码
图片文件切片
视频文件切片
删掉所有切片数据
{{json}}
export default {
data() {
return {
filePath: ”,
fileName: ”,
json: ”
}
},
onLoad() {
},
methods: {
imgeSlice() {
var _this = this;
uni.chooseImage({
count: 1,
sizeType: [‘original’, ‘compressed’],
sourceType: [‘album’,’camera’],
success: function (res) {
console.log(JSON.stringify(res));
var tempFilePath = res.tempFilePaths[0];
if(tempFilePath.indexOf(“_doc”) != -1) {
tempFilePath = plus.io.convertLocalFileSystemURL(tempFilePath);
}else {
tempFilePath = tempFilePath.replace(“file://”, “”);
}
console.log(tempFilePath);
const KJFileSlice = uni.requireNativePlugin(‘KJ-FileSlice’);
var dic = {
“pathFileName”: tempFilePath,
“savePath”: plus.io.convertLocalFileSystemURL(“_doc/KJ-FileSlice”), //保存切片地址,一定要是_doc目录
“sliceSize”: 100*1024, //切片大小,单位(B)
“sliceSuffixName”: “” //保存切片的后缀名
}
KJFileSlice.start(dic, (res) => {
console.log(“start: ” + JSON.stringify(res));
_this.json = JSON.stringify(res);
});
}
});
},
videoSlice() {
var _this = this;
uni.chooseVideo({
count: 1,
sourceType: [‘camera’, ‘album’],
success: function(res) {
console.log(JSON.stringify(res));
var tempFilePath = res.tempFilePath;
if(tempFilePath.indexOf(“_doc”) != -1) {
tempFilePath = plus.io.convertLocalFileSystemURL(tempFilePath);
}else {
tempFilePath = tempFilePath.replace(“file://”, “”);
}
const KJFileSlice = uni.requireNativePlugin(‘KJ-FileSlice’);
var dic = {
“pathFileName”: tempFilePath,
“savePath”: plus.io.convertLocalFileSystemURL(“_doc/KJ-FileSlice”), //保存切片地址,一定要是_doc目录
“sliceSize”: 1024 * 1024, //切片大小,单位(B)
“sliceSuffixName”: “” //保存切片的后缀名
}
KJFileSlice.start(dic, (res) => {
console.log(“start: ” + JSON.stringify(res));
_this.json = JSON.stringify(res);
});
}
});
},
deleteSliceData() {
var dirPath = ‘_doc/KJ-FileSlice’;
plus.io.resolveLocalFileSystemURL(dirPath, function(entry) {
//读取这个目录对象
var directoryReader = entry.createReader();
//读取这个目录下的所有文件
directoryReader.readEntries(function(entries) {
console.log(entries.length)
//如果有才操作
if (entries.length > 0) {
//删除目录将会删除其下的所有文件及子目录 不能删除根目录,如果操作删除根目录
//将会删除目录下的文件及子目录,不会删除根目录自身。 删除目录成功通过succesCB
//回调返回,失败则通过errorCB返回。
entry.removeRecursively(function(entry) {
console.log(‘删除成功回调’)
}, function(e) {
console.log(e.message + ‘ ?!’);
})
}
}, function(e) {
console.log(‘读取文件失败:’ + e.message)
})
}, function(e) {
console.log(‘读取目录失败:’ + e.message)
})
}
}
}