Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
4f1c2664
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6071
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4f1c2664
编写于
7月 20, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: filemanager换成extapi的实现
上级
2800e9de
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
7 addition
and
373 deletion
+7
-373
pages/component/list/list.uvue
pages/component/list/list.uvue
+2
-3
pages/component/long-list/long-list.uvue
pages/component/long-list/long-list.uvue
+5
-5
uni_modules/uts-file-manager/changelog.md
uni_modules/uts-file-manager/changelog.md
+0
-0
uni_modules/uts-file-manager/package.json
uni_modules/uts-file-manager/package.json
+0
-81
uni_modules/uts-file-manager/readme.md
uni_modules/uts-file-manager/readme.md
+0
-6
uni_modules/uts-file-manager/utssdk/app-android/index.uts
uni_modules/uts-file-manager/utssdk/app-android/index.uts
+0
-160
uni_modules/uts-file-manager/utssdk/app-ios/index.uts
uni_modules/uts-file-manager/utssdk/app-ios/index.uts
+0
-0
uni_modules/uts-file-manager/utssdk/interface.uts
uni_modules/uts-file-manager/utssdk/interface.uts
+0
-118
未找到文件。
pages/component/list/list.uvue
浏览文件 @
4f1c2664
...
...
@@ -115,13 +115,12 @@
});
},
goDetail(e: Item) {
console.log("eeee",e);
const detail = e;
const post_id = detail.post_id;
const cover = detail.cover;
const title = detail.title;
uni.navigateTo({
url: 'pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
url: '
/
pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
});
},
bannerClick(e:Banner){
...
...
@@ -130,7 +129,7 @@
const cover = detail.cover;
const title = detail.title;
uni.navigateTo({
url: 'pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
url: '
/
pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
});
},
setTime(items: UTSJSONObject): Item[] {
...
...
pages/component/long-list/long-list.uvue
浏览文件 @
4f1c2664
...
...
@@ -20,7 +20,6 @@
</template>
<script>
import { readFile, ReadFileOptions,ReadFileSuccessResult } from '@/uni_modules/uts-file-manager';
type Item = {
title: string
subTitle: string,
...
...
@@ -47,9 +46,10 @@ import { readFile, ReadFileOptions,ReadFileSuccessResult } from '@/uni_modules/u
},
methods: {
getList() {
readFile({
type:'text',
path:'static/list-mock/mock.json',
const fileManager = uni.getFileSystemManager()
fileManager.readFile({
encoding:'utf-8',
filePath:'static/list-mock/mock.json',
success:function(result:ReadFileSuccessResult){
const content = result.content;
if (content != null){
...
...
@@ -86,7 +86,7 @@ import { readFile, ReadFileOptions,ReadFileSuccessResult } from '@/uni_modules/u
},
goDetail(e: Item) {
uni.navigateTo({
url: 'pages/component/long-list/detail/detail?content=' + e.detail
url: '
/
pages/component/long-list/detail/detail?content=' + e.detail
});
},
onRefresherrefresh() {
...
...
uni_modules/uts-file-manager/changelog.md
已删除
100644 → 0
浏览文件 @
2800e9de
uni_modules/uts-file-manager/package.json
已删除
100644 → 0
浏览文件 @
2800e9de
{
"id"
:
"uts-file-manager"
,
"displayName"
:
"uts-file-manager"
,
"version"
:
"1.0.0"
,
"description"
:
"uts-file-manager"
,
"keywords"
:
[
"uts-file-manager"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uts-file-manager/readme.md
已删除
100644 → 0
浏览文件 @
2800e9de
# uts-file-manager
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS API插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
UTS 组件插件
](
https://uniapp.dcloud.net.cn/plugin/uts-component.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts
)
\ No newline at end of file
uni_modules/uts-file-manager/utssdk/app-android/index.uts
已删除
100644 → 0
浏览文件 @
2800e9de
import { ReadFileSuccessResult, ReadFileFailResult, ReadFile,ReadFileOptions } from "../interface.uts"
import { WriteFileSuccessResult, WriteFileFailResult, WriteFile,WriteFileOptions } from "../interface.uts"
import File from "java.io.File"
import UTSAndroid from 'io.dcloud.uts.UTSAndroid';
import Base64 from "android.util.Base64"
import Environment from 'android.os.Environment';
export { ReadFileOptions, WriteFileOptions } from "../interface.uts"
/**
* 获取文件内容
*/
export const readFile : ReadFile = function (options : ReadFileOptions) {
// 判断type 是否合法
if(options.type != 'base64' && options.type != 'text'){
let ret : ReadFileFailResult = {
errCode: -1,
errMsg: "type error.",
errSubject: "uni-getFileContent"
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.fail?.(ret)
options.complete?.(ret)
}, null)
return
}
/**
* 执行真正的加载行为,为了避免阻塞分发到 io任务序列
*/
UTSAndroid.dispatchAsync('io',function(_){
let filePath = UTSAndroid.convert2AbsFullPath(options.path)
let targetFile = new File(filePath)
if (!targetFile.exists()) {
let ret : ReadFileFailResult = {
errCode: -2,
errMsg: "file not found.",
errSubject: "uni-getFileContent"
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.fail?.(ret)
options.complete?.(ret)
}, null)
return
}
if (targetFile.isDirectory()) {
let ret : ReadFileFailResult = {
errCode: -3,
errMsg: "error:file is a Directory.",
errSubject: "uni-getFileContent"
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.fail?.(ret)
options.complete?.(ret)
}, null)
return
}
/**
* 文件超过16M,会超过应用内存
*/
if (targetFile.length() > 16 * 1024 * 1024) {
let ret : ReadFileFailResult = {
errCode: -3,
errMsg: "error:file is bigger than 16M",
errSubject: "uni-getFileContent"
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.fail?.(ret)
options.complete?.(ret)
}, null)
return
}
if(options.type == 'base64'){
// base64
let byteArray = targetFile.readBytes()
let base64Content = Base64.encodeToString(byteArray,Base64.NO_WRAP)
let ret : ReadFileSuccessResult = {
content: base64Content,
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.success?.(ret)
options.complete?.(ret)
}, null)
}else{
// text
let text = targetFile.readText()
let ret : ReadFileSuccessResult = {
content: text
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.success?.(ret)
options.complete?.(ret)
}, null)
}
},null)
}
/**
* 获取文件内容
*/
export const writeFile : WriteFile = function (options : WriteFileOptions) {
// 判断type 是否合法
let nextFile = new File(UTSAndroid.getAppContext()?.getFilesDir(),options.path)
console.log(nextFile.getPath())
if(nextFile.exists() && nextFile.isDirectory()){
// 出错了,目标文件已存在,并且是个目录
let ret : WriteFileFailResult = {
errCode: -2,
errMsg: "file exist and is a directory.",
errSubject: "uni-writeFile"
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.fail?.(ret)
options.complete?.(ret)
}, null)
return
}
UTSAndroid.dispatchAsync('io',function(_){
/**
* 如果上一级目录不存在,创建之
*/
if(!nextFile.parentFile.exists()){
nextFile.parentFile.mkdirs()
}
if(!nextFile.exists()){
nextFile.createNewFile()
}
// 写入文本,暂时只支持覆盖写入
nextFile.writeText(options.content)
let ret : WriteFileSuccessResult = {
filePath: nextFile.getPath()
}
UTSAndroid.dispatchAsync("dom",(_)=>{
options.success?.(ret)
options.complete?.(ret)
}, null)
},null)
}
uni_modules/uts-file-manager/utssdk/app-ios/index.uts
已删除
100644 → 0
浏览文件 @
2800e9de
uni_modules/uts-file-manager/utssdk/interface.uts
已删除
100644 → 0
浏览文件 @
2800e9de
export type ReadFileSuccessResult = {
content : string
}
export type ReadFileFailResult = {
/**
* 错误码
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
}
export type ReadFileSuccessCallback = (res : ReadFileSuccessResult) => void
export type ReadFileFailCallback = (res : ReadFileFailResult) => void
export type ReadFileCompleteCallback = (res : any) => void
export type ReadFileOptions = {
/**
* base64 / text
*/
type : string,
/**
* 文件路径,支持相对地址和绝对地址
*/
path : string,
/**
* 接口调用的回调函数
*/
success : ReadFileSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail : ReadFileFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete : ReadFileCompleteCallback | null
}
/**
* getFileContent
* 获取文件内容,可以选择以 base64形式或者纯文本形式 编码
*/
export type ReadFile = (config : ReadFileOptions) => void;
export type WriteFileSuccessResult = {
filePath : string,
}
export type WriteFileFailResult = {
/**
* 错误码
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
}
export type WriteFileSuccessCallback = (res : WriteFileSuccessResult) => void
export type WriteFileFailCallback = (res : WriteFileFailResult) => void
export type WriteFileCompleteCallback = (res : any) => void
export type WriteFileOptions = {
/**
* 文件路径,只支持绝对地址
*/
path : string,
/**
* 写入的文本内容
*/
content : string,
/**
* 接口调用的回调函数
*/
success : WriteFileSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail : WriteFileFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete : WriteFileCompleteCallback | null
}
/**
* WriteFile
* 写入文本
*/
export type WriteFile = (config : WriteFileOptions) => void;
interface Uni {
readFile:ReadFile,
writeFile:WriteFile
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录