更新记录
1.0.0(2022-03-11)
首次更新
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 12.0 | armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
KJ-FileSearch
文件选择器、快速查询文件、自定义路径、完全自定义UI界面、可多选、自定义类型(android)
系统文件选择、支持andorid10、限制文件类型(android):https://ext.dcloud.net.cn/plugin?id=7334 系统文件选取 支持多选单选、是否显示后缀名、模式选择、保存文件到文件管理器(ios):https://ext.dcloud.net.cn/plugin?id=3298
注意事项
需要配置minSdkVersion为21,要不打包会报错
manifest.json -> app-plus -> distribute -> android -> "minSdkVersion" : 21
使用
<template>
<view class="content">
<view class="header">
<text @click="editClick" style="margin-right: 10px;color: #007AFF;">{{isSelectAll?"取消全选":"全选"}}</text>
<text @click="finishClick">完成</text>
</view>
<view class="tab">
<view class="tab-item" :style="bindTabItemStyle(item,index)" v-for="(item,index) in tabs"
@click="tabItemClick(item,index)">
<text>{{item.name}}</text>
</view>
</view>
<!-- 使用recycle-list,防止数据多,页面会卡顿-->
<recycle-list for="(item, index) in json" switch="type">
<cell-slot case="A" class="list-item" @click="itemClick(item,index)">
<view class="left">
<text style="word-wrap:break-word;">{{item.fileName}}</text>
<view class="subText">
<text class="text">{{item.lastModifiedData}}</text>
<text class="text" style="margin-left: 10px;">{{item.size}}</text>
</view>
</view>
<view class="right">
<image class="image"
:src="item.isSelect == true ? '../../static/selected.png' : '../../static/unselected.png'"
mode="aspectFit"></image>
</view>
</cell-slot>
</recycle-list>
</view>
</template>
<script>
const KJFileSearch = uni.requireNativePlugin('KJ-FileSearch');
export default {
data() {
return {
isSelectAll: false,
tabs: [{
"isSelect": true,
"name": "全部",
"supportSuffixNames": ["jpg", "png", "jpeg", "mp4", "mov", "avi", "3gp", "m4v", "png", "doc",
"docx", "xls", "xlsx", "ppt", "pptx", "html"
]
}, {
"isSelect": false,
"name": "图片",
"supportSuffixNames": ["jpg", "png", "jpeg"]
}, {
"isSelect": false,
"name": "文字",
"supportSuffixNames": ["doc", "docx"]
}, {
"isSelect": false,
"name": "表格",
"supportSuffixNames": ["xls", "xlsx"]
}, {
"isSelect": false,
"name": "演示",
"supportSuffixNames": ["ppt", "pptx"]
}, {
"isSelect": false,
"name": "视频",
"supportSuffixNames": ["mp4", "mov", "avi", "3gp", "m4v"]
}, {
"isSelect": false,
"name": "其他",
"supportSuffixNames": ["html","apk"]
}],
json: [],
}
},
onReady() {
this.getData(this.tabs[0].supportSuffixNames);
},
methods: {
getData(extensions) {
uni.showLoading({
title: '加载中...',
mask: true
});
var environment = plus.android.importClass("android.os.Environment");
var File = plus.android.importClass("java.io.File");
var sdRoot = environment.getExternalStorageDirectory();
var sdRootAbsolutePath = plus.android.invoke(sdRoot, "getAbsolutePath");
console.log("SD卡主目录:"+sdRootAbsolutePath);
this.isSelectAll = false;
this.json = [];
var all = [];
var dic = {
"extensions": extensions, //筛选的文件扩展名,为null不限制类型
"isShowHiddenFile": false //是否返回隐藏的文件
}
KJFileSearch.getSDHomeDirectorysAndFiles(dic, (res) => {//获取SD卡首页所有目录和文件
//console.log(JSON.stringify(res))
if (res.success == true) {
var directorys = res.directorys;
var files = res.files;
for (var i = 0; i < files.length; i++) {
var dic = files[i]
if (dic.size != 0) {
dic.isSelect = false;
dic.size = this.readFileSize(dic.size);
all.push(dic)
}
}
var index = 0;
for (var i = 0; i < directorys.length; i++) {
var dic = directorys[i];
if (dic.directoryName != "Andorid") { //限制不读取Android目录
var dic = {
"directory": dic.directoryPath, //设置读取的路径,有些手机Andorid目录是不能读取的,不能直接传SD卡主目录
"extensions": extensions, //筛选的文件扩展名,为null不限制类型
"recursive": true, //是否递归,为true,会读取该文件夹里面的所有子文件夹
"isShowHiddenFile": false //是否返回隐藏的文件
}
KJFileSearch.start(dic, (res) => {
index++
for (var i = 0; i < res.data.length; i++) {
var dic = res.data[i]
if (dic.size != 0) {
dic.isSelect = false;
dic.size = this.readFileSize(dic.size);
all.push(dic)
}
}
if (index == directorys.length) {
this.json = all;
this.$nextTick((res) => {
uni.hideLoading();
})
}
});
}
}
}
})
},
readFileSize(size) {
var fileSizeString;
if (size == 0) {
fileSizeString = "0B";
} else if (size < 1024) {
fileSizeString = size + "B";
} else if (size < 1048576) {
fileSizeString = (size / 1024).toFixed(2) + "KB";
} else if (size < 1073741824) {
fileSizeString = (size / 1048576).toFixed(2) + "MB";
} else {
fileSizeString = (size / 1073741824).toFixed(2) + "GB";
}
return fileSizeString;
},
tabItemClick(item, index) {
console.log(JSON.stringify(index))
for (var i = 0; i < this.tabs.length; i++) {
var tab = this.tabs[i]
if (index == i) {
tab.isSelect = true;
} else {
tab.isSelect = false;
}
}
this.getData(item.supportSuffixNames)
},
bindTabItemStyle(item, index) {
var color = "#000000"
var color2 = "#00000000"
if (item.isSelect == true) {
color = "#126aff"
color2 = color
}
return {
"color": color,
"border-bottom": "3px solid " + color2
}
},
itemClick(item, index) {
//item.isSelect = !item.isSelect
for (var j = 0; j < this.json.length; j++) {
var dic = this.json[j];
if (j == index) {
dic.isSelect = !dic.isSelect;
}
}
},
editClick() {
this.isSelectAll = !this.isSelectAll
for (var j = 0; j < this.json.length; j++) {
var dic = this.json[j];
dic.isSelect = this.isSelectAll;
}
},
finishClick() {
var arr = []
for (var j = 0; j < this.json.length; j++) {
var dic = this.json[j];
if (dic.isSelect == true) {
arr.push(dic);
}
}
console.log(JSON.stringify(arr))
}
}
}
</script>
<style>
.content {
font-size: 15px;
}
.header {
height: 45px;
padding: 0px 20px;
background-color: #FFFFFF;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
justify-content: space-between;
color: #000;
}
.list {
padding: 10px;
width: 750rpx;
position: fixed;
top: 100px;
bottom: 0px;
}
.list-item {
padding: 20rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.list-item .left {
width: 650rpx;
padding-left: 20px;
}
.list-item .right {
width: 100rpx;
}
.list-item .right .image {
width: 20px;
height: 20px;
}
.subText {
margin-top: 10px;
font-size: 12px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
.subText .text {
color: lightgrey;
}
.tab {
width: 750rpx;
height: 44px;
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
justify-content: center;
}
.tab .tab-item {
padding: 10px 0px;
width: 107rpx;
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
justify-content: center;
}
</style>