Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
50dc7df0
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
50dc7df0
编写于
7月 16, 2021
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(app): add saveFile getSavedFileList getSavedFileInfo removeSavedFile getFileInfo
上级
50291234
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
265 addition
and
0 deletion
+265
-0
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+4
-0
packages/uni-api/src/protocols/file/getSavedFileInfo.ts
packages/uni-api/src/protocols/file/getSavedFileInfo.ts
+21
-0
packages/uni-api/src/protocols/file/getSavedFileList.ts
packages/uni-api/src/protocols/file/getSavedFileList.ts
+2
-0
packages/uni-api/src/protocols/file/removeSavedFile.ts
packages/uni-api/src/protocols/file/removeSavedFile.ts
+19
-0
packages/uni-api/src/protocols/file/saveFile.ts
packages/uni-api/src/protocols/file/saveFile.ts
+18
-0
packages/uni-app-plus/src/service/api/file/getSavedFileInfo.ts
...ges/uni-app-plus/src/service/api/file/getSavedFileInfo.ts
+34
-0
packages/uni-app-plus/src/service/api/file/getSavedFileList.ts
...ges/uni-app-plus/src/service/api/file/getSavedFileList.ts
+72
-0
packages/uni-app-plus/src/service/api/file/removeSavedFile.ts
...ages/uni-app-plus/src/service/api/file/removeSavedFile.ts
+27
-0
packages/uni-app-plus/src/service/api/file/saveFile.ts
packages/uni-app-plus/src/service/api/file/saveFile.ts
+68
-0
未找到文件。
packages/uni-api/src/index.ts
浏览文件 @
50dc7df0
...
...
@@ -36,7 +36,11 @@ export * from './protocols/device/soterAuthentication'
export
*
from
'
./protocols/storage/storage
'
export
*
from
'
./protocols/file/saveFile
'
export
*
from
'
./protocols/file/getSavedFileList
'
export
*
from
'
./protocols/file/removeSavedFile
'
export
*
from
'
./protocols/file/getFileInfo
'
export
*
from
'
./protocols/file/getSavedFileInfo
'
export
*
from
'
./protocols/file/openDocument
'
export
*
from
'
./protocols/keyboard/keyboard
'
...
...
packages/uni-api/src/protocols/file/getSavedFileInfo.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
export
const
API_GET_SAVED_FILE_INFO
=
'
getSavedFileInfo
'
export
type
API_TYPE_GET_SAVED_FILE_INFO
=
typeof
uni
.
getSavedFileInfo
export
const
GetSavedFileInfoOptions
:
ApiOptions
<
API_TYPE_GET_SAVED_FILE_INFO
>
=
{
formatArgs
:
{
filePath
(
filePath
,
params
)
{
params
.
filePath
=
getRealPath
(
filePath
)
},
},
}
export
const
GetSavedFileInfoProtocol
:
ApiProtocol
<
API_TYPE_GET_SAVED_FILE_INFO
>
=
{
filePath
:
{
type
:
String
,
required
:
true
,
},
}
packages/uni-api/src/protocols/file/getSavedFileList.ts
0 → 100644
浏览文件 @
50dc7df0
export
const
API_GET_SAVED_LIST
=
'
getSavedFileList
'
export
type
API_TYPE_GET_SAVED_LIST
=
typeof
uni
.
getSavedFileList
packages/uni-api/src/protocols/file/removeSavedFile.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
export
const
API_REMOVE_SAVED_FILE
=
'
removeSavedFile
'
export
type
API_TYPE_REMOVE_SAVED_FILE
=
typeof
uni
.
removeSavedFile
export
const
RemoveSavedFileOptions
:
ApiOptions
<
API_TYPE_REMOVE_SAVED_FILE
>
=
{
formatArgs
:
{
filePath
(
filePath
,
params
)
{
params
.
filePath
=
getRealPath
(
filePath
)
},
},
}
export
const
RemoveSavedFileProtocol
:
ApiProtocol
<
API_TYPE_REMOVE_SAVED_FILE
>
=
{
filePath
:
{
type
:
String
,
required
:
true
,
},
}
packages/uni-api/src/protocols/file/saveFile.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
export
const
API_SAVE_FILE
=
'
saveFile
'
export
type
API_TYPE_SAVE_FILE
=
typeof
uni
.
saveFile
export
const
SaveFileOptions
:
ApiOptions
<
API_TYPE_SAVE_FILE
>
=
{
formatArgs
:
{
tempFilePath
(
savedFilePath
,
params
)
{
params
.
tempFilePath
=
getRealPath
(
savedFilePath
)
},
},
}
export
const
SaveFileProtocol
:
ApiProtocol
<
API_TYPE_SAVE_FILE
>
=
{
tempFilePath
:
{
type
:
String
,
required
:
true
,
},
}
packages/uni-app-plus/src/service/api/file/getSavedFileInfo.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
defineAsyncApi
,
API_GET_SAVED_FILE_INFO
,
API_TYPE_GET_SAVED_FILE_INFO
,
GetSavedFileInfoProtocol
,
GetSavedFileInfoOptions
,
}
from
'
@dcloudio/uni-api
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
export
const
getSavedFileInfo
=
<
API_TYPE_GET_SAVED_FILE_INFO
>
defineAsyncApi
(
API_GET_SAVED_FILE_INFO
,
({
filePath
},
{
resolve
,
reject
})
=>
{
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
plus
.
io
.
resolveLocalFileSystemURL
(
filePath
,
(
entry
)
=>
{
entry
.
getMetadata
(
(
meta
)
=>
{
resolve
({
createTime
:
meta
.
modificationTime
!
.
getTime
(),
size
:
meta
.
size
!
,
})
},
errorCallback
,
false
)
},
errorCallback
)
},
GetSavedFileInfoProtocol
,
GetSavedFileInfoOptions
)
packages/uni-app-plus/src/service/api/file/getSavedFileList.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
defineAsyncApi
,
API_GET_SAVED_LIST
,
API_TYPE_GET_SAVED_LIST
,
}
from
'
@dcloudio/uni-api
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
const
SAVED_DIR
=
'
uniapp_save
'
function
getSavedFileDir
(
success
:
(
res
:
any
)
=>
void
,
fail
:
(
err
:
any
)
=>
void
)
{
fail
=
fail
||
function
()
{}
plus
.
io
.
requestFileSystem
(
plus
.
io
.
PRIVATE_DOC
,
(
fs
)
=>
{
// 请求_doc fs
fs
.
root
!
.
getDirectory
(
SAVED_DIR
,
{
// 获取文件保存目录对象
create
:
true
,
},
success
,
fail
)
},
fail
)
}
export
const
getSavedFileList
=
<
API_TYPE_GET_SAVED_LIST
>
(
defineAsyncApi
(
API_GET_SAVED_LIST
,
(
_
,
{
resolve
,
reject
})
=>
{
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
getSavedFileDir
((
entry
)
=>
{
var
reader
=
entry
.
createReader
()
var
fileList
:
object
[]
=
[]
reader
.
readEntries
((
entries
:
any
[])
=>
{
if
(
entries
&&
entries
.
length
)
{
entries
.
forEach
((
entry
)
=>
{
entry
.
getMetadata
(
(
meta
:
{
modificationTime
:
{
getTime
:
()
=>
void
}
size
:
any
})
=>
{
fileList
.
push
({
filePath
:
plus
.
io
.
convertAbsoluteFileSystem
(
entry
.
fullPath
),
createTime
:
meta
.
modificationTime
.
getTime
(),
size
:
meta
.
size
,
})
if
(
fileList
.
length
===
entries
.
length
)
{
resolve
({
fileList
,
})
}
},
errorCallback
,
false
)
})
}
else
{
resolve
({
fileList
,
})
}
},
errorCallback
)
},
errorCallback
)
})
)
packages/uni-app-plus/src/service/api/file/removeSavedFile.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
defineAsyncApi
,
API_REMOVE_SAVED_FILE
,
API_TYPE_REMOVE_SAVED_FILE
,
RemoveSavedFileProtocol
,
RemoveSavedFileOptions
,
}
from
'
@dcloudio/uni-api
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
export
const
removeSavedFile
=
<
API_TYPE_REMOVE_SAVED_FILE
>
defineAsyncApi
(
API_REMOVE_SAVED_FILE
,
({
filePath
},
{
resolve
,
reject
})
=>
{
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
plus
.
io
.
resolveLocalFileSystemURL
(
filePath
,
(
entry
)
=>
{
entry
.
remove
(()
=>
{
resolve
()
},
errorCallback
)
},
errorCallback
)
},
RemoveSavedFileProtocol
,
RemoveSavedFileOptions
)
packages/uni-app-plus/src/service/api/file/saveFile.ts
0 → 100644
浏览文件 @
50dc7df0
import
{
defineAsyncApi
,
API_SAVE_FILE
,
API_TYPE_SAVE_FILE
,
SaveFileProtocol
,
SaveFileOptions
,
}
from
'
@dcloudio/uni-api
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
import
{
getExtName
}
from
'
../../../helpers/file
'
let
index
=
0
const
SAVED_DIR
=
'
uniapp_save
'
const
SAVE_PATH
=
`_doc/
${
SAVED_DIR
}
`
function
getSavedFileDir
(
success
:
(
res
:
any
)
=>
void
,
fail
:
(
err
:
any
)
=>
void
)
{
fail
=
fail
||
function
()
{}
plus
.
io
.
requestFileSystem
(
plus
.
io
.
PRIVATE_DOC
,
(
fs
)
=>
{
// 请求_doc fs
fs
.
root
!
.
getDirectory
(
SAVED_DIR
,
{
// 获取文件保存目录对象
create
:
true
,
},
success
,
fail
)
},
fail
)
}
export
const
saveFile
=
<
API_TYPE_SAVE_FILE
>
defineAsyncApi
(
API_SAVE_FILE
,
({
tempFilePath
},
{
resolve
,
reject
})
=>
{
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
const
fileName
=
`
${
Date
.
now
()}${
index
++
}${
getExtName
(
tempFilePath
)}
`
plus
.
io
.
resolveLocalFileSystemURL
(
tempFilePath
,
(
entry
)
=>
{
// 读取临时文件 FileEntry
getSavedFileDir
((
dir
)
=>
{
entry
.
copyTo
(
dir
,
fileName
,
()
=>
{
// 复制临时文件 FileEntry,为了避免把相册里的文件删除,使用 copy,微信中是要删除临时文件的
const
savedFilePath
=
SAVE_PATH
+
'
/
'
+
fileName
resolve
({
savedFilePath
,
})
},
errorCallback
)
},
errorCallback
)
},
errorCallback
)
},
SaveFileProtocol
,
SaveFileOptions
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录