提交 4ee1b1db 编写于 作者: 杜庆泉's avatar 杜庆泉

手动合并 get-file-system-manager dev分支内容到本地

上级 9d6dffe7
......@@ -30,29 +30,23 @@ describe('ExtApi-FileManagerTest', () => {
let globalUserDataPath = await getData('globalUserDataPath')
await page.setData({
logAble:false,
recursiveVal: true,
copyToBasePath:globalUserDataPath,
basePath: globalUserDataPath,
rmDirFile:'a',
unlinkFile:'a/1.txt'
readDir:'a',
writeFile:'a/1.txt',
readFile:'a/1.txt',
unlinkFile:'a/1.txt',
writeFileContent:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦'
})
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file')
const btnUnLinkFileButton = await page.$('.btn-clear-file')
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/2.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/3.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
// 清除文件夹
const btnRmDirButton = await page.$('.btn-remove-dir')
......@@ -200,17 +194,18 @@ describe('ExtApi-FileManagerTest', () => {
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]")
});
it('TEMP_PATH test', async () => {
// 测试 TEMP_PATH
let globalTempPath = await getData('globalTempPath')
await page.setData({
logAble:false,
recursiveVal: true,
basePath: globalTempPath,
copyToBasePath:globalTempPath,
rmDirFile:'a',
mkdirFile: 'a',
unlinkFile:'a/我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;,/中文路径/张三/name/中文文件.mock'
})
......@@ -220,12 +215,6 @@ describe('ExtApi-FileManagerTest', () => {
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/提前创建的目录/4.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
// 清除文件夹
const btnRmDirButton = await page.$('.btn-remove-dir')
......@@ -244,9 +233,9 @@ describe('ExtApi-FileManagerTest', () => {
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
let fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]")
expect(JSON.stringify(fileListComplete)).toEqual("[]")
let fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]")
expect(JSON.stringify(fileListSuccess)).toEqual("[]")
// 测试 创建多层级文件目录
await page.setData({
......@@ -286,10 +275,8 @@ describe('ExtApi-FileManagerTest', () => {
* 从资源文件中读取图片为base64,测试写入较大文件场景
* 'static/list-mock/safe.png' 注意,依赖这个资源文件,不能删除
*/
let globalAppResourcePath = await getData('globalAppResourcePath')
await page.setData({
basePath: globalAppResourcePath,
basePath: "",
readFile:'static/list-mock/safe.png',
readFileEncoding:'base64'
})
......@@ -434,7 +421,8 @@ describe('ExtApi-FileManagerTest', () => {
expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]")
await page.setData({
unlinkFile:'a/提前创建的目录/4.txt'
unlinkFile:'a/提前创建的目录/4.txt',
rmDirFile:'a/提前创建的目录'
})
await btnUnLinkFileButton.tap()
await isDone()
......@@ -447,12 +435,10 @@ describe('ExtApi-FileManagerTest', () => {
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[]")
});
it('CROSS DIR test', async () => {
/**
* 跨越用户目录和代码资源目录
......@@ -460,6 +446,7 @@ describe('ExtApi-FileManagerTest', () => {
let globalRootPath = await getData('globalRootPath')
await page.setData({
recursiveVal: true,
logAble:false,
basePath: globalRootPath,
readDir:'a',
rmDirFile:'a',
......@@ -470,8 +457,8 @@ describe('ExtApi-FileManagerTest', () => {
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file')
await btnUnLinkFileButton.tap()
const btnClearFileButton = await page.$('.btn-clear-file')
await btnClearFileButton.tap()
await isDone()
......@@ -505,9 +492,8 @@ describe('ExtApi-FileManagerTest', () => {
// 准备从资源目录拷贝png
let globalAppResourcePath = await getData('globalAppResourcePath')
await page.setData({
basePath: globalAppResourcePath,
basePath: "",
unlinkFile:'static/list-mock/safe.png',
accessFile:'static/list-mock/safe.png',
})
......@@ -519,6 +505,7 @@ describe('ExtApi-FileManagerTest', () => {
expect(accessFileRet).toEqual('access:ok')
// 尝试删除资源,期望失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file')
await btnUnLinkFileButton.tap()
await isDone()
......@@ -542,6 +529,7 @@ describe('ExtApi-FileManagerTest', () => {
basePath:globalRootPath,
unlinkFile:'a/从代码目录拷贝的资源.png',
accessFile:'a/从代码目录拷贝的资源.png',
rmDirFile:'a',
})
await btnAccessFileButton.tap()
await isDone()
......@@ -549,6 +537,7 @@ describe('ExtApi-FileManagerTest', () => {
accessFileRet = await getData("accessFileRet")
expect(accessFileRet).toEqual('access:ok')
await btnUnLinkFileButton.tap()
await isDone()
......@@ -558,6 +547,31 @@ describe('ExtApi-FileManagerTest', () => {
accessFileRet = await getData("accessFileRet")
expect(accessFileRet).toEqual('')
// 从页面的按钮触发一次文件复制
const btnCopyStaticFileButton = await page.$('.btn-copyStatic-file')
await btnCopyStaticFileButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"mock.json\"]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"mock.json\"]")
// 从页面的按钮触发一次文件清空
await btnClearFileButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[]")
});
......@@ -568,6 +582,7 @@ describe('ExtApi-FileManagerTest', () => {
let globalTempPath = await getData('globalTempPath')
await page.setData({
recursiveVal: true,
logAble:false,
basePath: globalTempPath,
readDir:'d',
rmDirFile:'d',
......@@ -700,98 +715,172 @@ describe('ExtApi-FileManagerTest', () => {
});
// it('stat and asset test', async () => {
// // 测试 USER_DATA_PATH
// let globalInnerRootPath = await getData('globalInnerRootPath')
// await page.setData({
// recursiveVal: true,
// copyToBasePath:globalInnerRootPath,
// basePath: globalInnerRootPath,
// rmDirFile:'a',
// mkdirFile:'a',
// unlinkFile:'a/1.txt',
// })
// // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
// const btnUnLinkFileButton = await page.$('.btn-unlink-file')
// await btnUnLinkFileButton.tap()
// await isDone()
// await page.setData({
// unlinkFile:'a/2.txt',
// })
// await btnUnLinkFileButton.tap()
// await isDone()
// await page.setData({
// unlinkFile:'a/m/3.txt',
// })
// await btnUnLinkFileButton.tap()
// await isDone()
// // // 清除文件夹
// const btnRmDirButton = await page.$('.btn-remove-dir')
// await btnRmDirButton.tap()
// await isDone()
// // // 重新创建测试目录
// const btnMkdDirButton = await page.$('.btn-mkdir')
// await btnMkdDirButton.tap()
// await isDone()
// const btnReadDirButton = await page.$('.btn-read-dir')
// await btnReadDirButton.tap()
// await isDone()
// // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
// let fileListComplete = await getData('fileListComplete')
// expect(JSON.stringify(fileListComplete)).toEqual('[]')
// let fileListSuccess = await getData('fileListSuccess')
// expect(JSON.stringify(fileListSuccess)).toEqual('[]')
// // 写入一个文件
// await page.setData({
// writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦",
// writeFileEncoding:"utf-8",
// writeFile:'a/1.txt',
// recursiveVal:false,
// statFile:'a/1.txt',
// })
// let lastFailError = await getData('lastFailError')
// console.log(lastFailError)
// // const btnWriteFileButton = await page.$('.btn-write-file')
// // await btnWriteFileButton.tap()
// // await isDone()
// // const btnStatFileButton = await page.$('.btn-stat-file')
// // await btnStatFileButton.tap()
// // await isDone()
// // // 读取单个文件信息
// // let statsRet = await getData('statsRet')
// // console.log(statsRet)
// // expect(statsRet.path).toEqual('')
// // await page.setData({
// // recursiveVal:true,
// // statFile:'a/1.txt',
// // })
// // await btnStatFileButton.tap()
// // await isDone()
// // // 读取单个文件信息
// // statsRet = await getData('statsRet')
// // console.log(statsRet)
// // expect(statsRet.path).toEqual('')
// });
it('stat and asset test', async () => {
// 测试 USER_DATA_PATH //globalTempPath
let globalRootPath = await getData('globalRootPath')
await page.setData({
recursiveVal: true,
copyToBasePath:globalRootPath,
basePath: globalRootPath,
rmDirFile:'a',
mkdirFile:'a',
unlinkFile:'a/1.txt',
})
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file')
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/2.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/m/3.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
// // 清除文件夹
const btnRmDirButton = await page.$('.btn-remove-dir')
await btnRmDirButton.tap()
await isDone()
// // 重新创建测试目录
const btnMkdDirButton = await page.$('.btn-mkdir')
await btnMkdDirButton.tap()
await isDone()
const btnReadDirButton = await page.$('.btn-read-dir')
await btnReadDirButton.tap()
await isDone()
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
let fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual('[]')
let fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual('[]')
// 写入一个文件
await page.setData({
writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦",
writeFileEncoding:"utf-8",
writeFile:'a/1.txt',
recursiveVal:false,
statFile:'a/1.txt',
})
let lastFailError = await getData('lastFailError')
console.log(lastFailError)
const btnWriteFileButton = await page.$('.btn-write-file')
await btnWriteFileButton.tap()
await isDone()
const btnStatFileButton = await page.$('.btn-stat-file')
await btnStatFileButton.tap()
await isDone()
// 读取单个文件信息
let statsRet = await getData('statsRet')
expect(statsRet.length).toEqual(1)
expect(statsRet[0].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/1.txt')
expect(statsRet[0].stats.size).toEqual(69)
/**
* 创建子目录和子目录文件,测试recursive参数
*/
await page.setData({
writeFileContent: "1234567890",
writeFileEncoding:"ascii",
writeFile:'a/2.txt',
basePath: globalRootPath,
recursiveVal:false,
statFile:'a',
mkdirFile:'a/m',
})
await btnWriteFileButton.tap()
await isDone()
// 创建子目录
await btnMkdDirButton.tap()
await isDone()
// 复制一份文件到 /a/m/3.txt
await page.setData({
// asset 只能正式版测试,这里只能模拟返回路径
basePath:'',
copyFromFile:'file:///android_asset/uni-uts/uni-prompt/toast_error.png',
copyToFile:'a/m/3.txt',
})
const btnCopyFileButton = await page.$('.btn-copy-file')
await btnCopyFileButton.tap()
await isDone()
await page.setData({
basePath: globalRootPath,
recursiveVal:true,
statFile:'a',
})
await btnStatFileButton.tap()
await isDone()
// 读取全部文件信息
statsRet = await getData('statsRet')
console.log(statsRet)
expect(statsRet.length).toEqual(5)
expect(statsRet[0].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a')
expect(statsRet[0].stats.size).toEqual(0)
expect(statsRet[2].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/2.txt')
expect(statsRet[2].stats.size).toEqual(10)
expect(statsRet[4].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/m/3.txt')
expect(statsRet[4].stats.size).toEqual(5842)
// 清理文件,避免影响其他测试用例
await page.setData({
unlinkFile:'a/1.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/2.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/m/3.txt',
rmDirFile:'a',
readDir:'a',
recursiveVal:true,
})
await btnUnLinkFileButton.tap()
await isDone()
await btnRmDirButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual('[]')
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual('[]')
});
});
<template>
<scroll-view>
<view>
<button type="primary" @tap="readDirTest" class="btn-read-dir">读取文件夹</button>
<button type="primary" @tap="readFileTest" class="btn-read-file">读取文件</button>
<button type="primary" @tap="rmdirTest" class="btn-remove-dir">删除文件夹</button>
<button type="primary" @tap="unlinkTest" class="btn-unlink-file">删除文件</button>
<button type="primary" @tap="mkdirTest" class="btn-mkdir">创建文件夹</button>
<button type="primary" @tap="writeFileTest" class="btn-write-file">写入文件</button>
<button type="primary" @tap="renameFileTest" class="btn-rename-file">重命名文件</button>
<button type="primary" @tap="copyFileTest" class="btn-copy-file">复制文件</button>
<button type="primary" @tap="accessFileTest" class="btn-access-file">判断文件是否存在</button>
<button type="primary" @tap="getFileInfoTest" class="btn-get-file-info">获取文件信息</button>
<button type="primary" @tap="statFileInfoTest" class="btn-stat-file">获取文件Stats </button>
</view>
</scroll-view>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<text>显示简易操作日志,详细日志需真机运行查看</text><button size="mini" @click="log=''">清空日志</button>
<text style="margin: 2px; padding: 2px; border: 1px solid #000000;" :value="log" />
<button type="primary" @tap="statFileInfoTest" class="btn-stat-file">递归获取目录files的Stats对象{{statFile}}</button>
<button type="primary" @tap="mkdirTest" class="btn-mkdir">创建文件夹{{mkdirFile}}</button>
<button type="primary" @tap="writeFileTest" class="btn-write-file">覆盖写入文件{{writeFile}}</button>
<button type="primary" @tap="readDirTest" class="btn-read-dir">读取文件夹{{readDir}}</button>
<button type="primary" @tap="readFileTest" class="btn-read-file">读取文件{{readFile}}</button>
<button type="primary" @tap="copyFileTest" class="btn-copy-file">复制文件{{copyFromFile}}到{{copyToFile}}</button>
<button type="primary" @tap="renameFileTest"
class="btn-rename-file">重命名文件{{renameFromFile}}到{{renameToFile}}</button>
<button type="primary" @tap="accessFileTest" class="btn-access-file">判断文件{{accessFile}}是否存在</button>
<button type="primary" @tap="getFileInfoTest" class="btn-get-file-info">获取文件信息{{getFileInfoFile}}</button>
<button type="primary" @tap="unlinkTest" class="btn-unlink-file">删除文件{{unlinkFile}}</button>
<button type="primary" @tap="copyStaticToFilesTest" class="btn-copyStatic-file">从static目录复制文件到a目录</button>
<button type="primary" @tap="unlinkAllFileTest" class="btn-clear-file">删除文件夹{{rmDirFile}}下的所有文件</button>
<button type="primary" @tap="rmdirTest" class="btn-remove-dir">删除文件夹{{rmDirFile}}</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
export default {
data() {
return {
fileListSuccess:[] as string[],
fileListComplete:[] as string[],
accessFileRet:'',
lastFailError:UniError("uni-file-manager",1300000,"mock error"),
lastCompleteError:UniError("uni-file-manager",1300000,"mock error"),
readDir:'a',
readFileRet:"",
writeFileContent:"锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦",
getFileInfoAlgorithm:"md5",
getFileInfoSize:-1,
getFileInfoDigest:"",
unlinkFile:'a/1.txt',
accessFile:'a/1.txt',
writeFile:'a/1.txt',
copyFromFile:'a/1.txt',
copyToFile:'a/2.txt',
renameFromFile:'a/2.txt',
renameToFile:'a/3.txt',
getFileInfoFile:'a/1.txt',
statFile:'a/1.txt',
rmDirFile:'a',
mkdirFile:'a',
readFile:'a/1.txt',
recursiveVal:true,
data() {
return {
log: "",
/**
* 自动化测试需要关闭log
*/
logAble:true,
fileListSuccess: [] as string[],
fileListComplete: [] as string[],
accessFileRet: '',
lastFailError: new UniError("uni-file-manager", 1300000, "mock error"),
lastCompleteError: new UniError("uni-file-manager", 1300000, "mock error"),
readDir: 'a',
readFileRet: "",
writeFileContent: "中文 en.\r\n\t换行",
getFileInfoAlgorithm: "md5",
getFileInfoSize: -1,
getFileInfoDigest: "",
unlinkFile: 'a/1.txt',
accessFile: 'a/1.txt',
writeFile: 'a/1.txt',
copyFromFile: 'a/1.txt',
copyToFile: 'a/2.txt',
renameFromFile: 'a/2.txt',
renameToFile: 'a/3.txt',
getFileInfoFile: 'a/1.txt',
statFile: '',
rmDirFile: 'a',
mkdirFile: 'a',
readFile: 'a/1.txt',
recursiveVal: true,
done: false,
writeFileEncoding:"utf-8",
readFileEncoding:"utf-8",
statsRet:[] as Array<FileStats>,
writeFileEncoding: "utf-8",
readFileEncoding: "utf-8",
statsRet: [] as Array<FileStats>,
/**
* 待测试的全局环境变量
*/
basePath: uni.env.USER_DATA_PATH,
copyToBasePath: uni.env.USER_DATA_PATH,
globalTempPath:uni.env.CACHE_PATH,
globalRootPath:uni.env.SANDBOX_PATH,
globalInnerRootPath:uni.env.ANDROID_INTERNAL_SANDBOX_PATH,
globalAppResourcePath:uni.env.APP_RESOURCE_PATH,
globalUserDataPath:uni.env.USER_DATA_PATH
}
},
globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH
}
},
onLoad() {
},
methods: {
methods: {
statFileInfoTest:function(e:any){
let fileManager = uni.getFileSystemManager()
statFileInfoTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.stat({
path:`${this.basePath}${this.statFile}`,
recursive:this.recursiveVal,
success:function(res:StatSuccessResult){
console.log('success',res)
fileManager.stat({
path: `${this.basePath}${this.statFile}`,
recursive: this.recursiveVal,
success: function (res : StatSuccessResult) {
if(this.logAble){
this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('statFileInfoTest success', res)
this.statsRet = res.stats
console.log('this.statsRet',this.statsRet)
},
fail:function(res:any){
console.log('fail',res)
console.log('this.statsRet', this.statsRet)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('statFileInfoTest fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("statFileInfoTest complete", res)
this.done = true
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as StatOptions)
},
getFileInfoTest:function(e:any){
let fileManager = uni.getFileSystemManager()
fileManager.getFileInfo({
filePath:`${this.basePath}${this.getFileInfoFile}`,
digestAlgorithm:this.getFileInfoAlgorithm,
success:function(res:GetFileInfoSuccessResult){
console.log('success',res)
}
} as StatOptions)
},
getFileInfoTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.getFileInfo({
filePath: `${this.basePath}${this.getFileInfoFile}`,
digestAlgorithm: this.getFileInfoAlgorithm,
success: function (res : GetFileInfoSuccessResult) {
if(this.logAble){
this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
this.getFileInfoSize = res.size
this.getFileInfoDigest = res.digest
},
fail:function(res:any){
console.log('fail',res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as GetFileInfoOptions)
},
}
} as GetFileInfoOptions)
},
copyFileTest:function(e:any){
copyFileTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
let fileManager = uni.getFileSystemManager()
fileManager.copyFile({
srcPath:`${this.basePath}${this.copyFromFile}`,
destPath:`${this.copyToBasePath}${this.copyToFile}`,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
},
fail:function(res:any){
console.log('fail',res)
fileManager.copyFile({
srcPath: `${this.basePath}${this.copyFromFile}`,
destPath: `${this.copyToBasePath}${this.copyToFile}`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as CopyFileOptions)
},
}
} as CopyFileOptions)
},
renameFileTest:function(e:any){
renameFileTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
let fileManager = uni.getFileSystemManager()
fileManager.rename({
oldPath:`${this.basePath}${this.renameFromFile}`,
newPath:`${this.basePath}${this.renameToFile}`,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
},
fail:function(res:any){
console.log('fail',res)
fileManager.rename({
oldPath: `${this.basePath}${this.renameFromFile}`,
newPath: `${this.basePath}${this.renameToFile}`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
},
complete: function (res : any) {
this.done = true
console.log("complete",res)
if(res instanceof UniError){
console.log("complete", res)
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as RenameOptions)
},
readDirTest:function(e:any){
let fileManager = uni.getFileSystemManager()
fileManager.readdir({
dirPath:`${this.basePath}${this.readDir}`,
success:function(res:ReadDirSuccessResult){
console.log("success",res)
}
} as RenameOptions)
},
readDirTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.readdir({
dirPath: `${this.basePath}${this.readDir}`,
success: function (res : ReadDirSuccessResult) {
if(this.logAble){
this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
}
console.log("success", res)
this.fileListSuccess = res.files
},
fail:function(res:any){
console.log('fail',res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if(res instanceof ReadDirSuccessResult){
if (res instanceof ReadDirSuccessResult) {
this.fileListComplete = res.files
}
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as ReadDirOptions)
},
}
} as ReadDirOptions)
},
writeFileTest:function(e:any){
let fileManager = uni.getFileSystemManager()
writeFileTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.writeFile({
filePath:`${this.basePath}${this.writeFile}`,
data:this.writeFileContent,
encoding:this.writeFileEncoding,
success:function(res){
console.log('success',res)
},
fail:function(res){
console.log('fail')
fileManager.writeFile({
filePath: `${this.basePath}${this.writeFile}`,
data: this.writeFileContent,
encoding: this.writeFileEncoding,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail')
this.lastFailError = res
},
complete:function(res){
},
complete: function (res : any) {
this.done = true
console.log("complete")
if(res instanceof UniError){
console.log("complete")
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as WriteFileOptions)
}
} as WriteFileOptions)
},
},
readFileTest:function(e:any){
readFileTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
let fileManager = uni.getFileSystemManager()
fileManager.readFile({
filePath:`${this.basePath}${this.readFile}`,
encoding:this.readFileEncoding,
success:function(res:ReadFileSuccessResult){
console.log('success',res)
fileManager.readFile({
filePath: `${this.basePath}${this.readFile}`,
encoding: this.readFileEncoding,
success: function (res : ReadFileSuccessResult) {
if(this.logAble){
this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
this.readFileRet = res.data
},
fail:function(res:any){
console.log('fail',res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as ReadFileOptions)
},
rmdirTest:function(e:any){
let fileManager = uni.getFileSystemManager()
fileManager.rmdir({
dirPath:`${this.basePath}${this.rmDirFile}`,
recursive:this.recursiveVal,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
},
fail:function(res:any){
console.log('fail',res)
}
} as ReadFileOptions)
},
rmdirTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.rmdir({
dirPath: `${this.basePath}${this.rmDirFile}`,
recursive: this.recursiveVal,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
console.log("complete",res)
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if(res instanceof UniError){
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as RmDirOptions)
},
}
} as RmDirOptions)
},
mkdirTest:function(e:any){
mkdirTest: function (e : any) {
// 准备测试数据
let fileManager = uni.getFileSystemManager()
let fileManager = uni.getFileSystemManager()
fileManager.mkdir({
dirPath:`${this.basePath}${this.mkdirFile}`,
recursive:this.recursiveVal,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
},
fail:function(res:any){
console.log('fail',res)
fileManager.mkdir({
dirPath: `${this.basePath}${this.mkdirFile}`,
recursive: this.recursiveVal,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
if(res instanceof UniError){
},
complete: function (res : any) {
if (res instanceof UniError) {
this.lastCompleteError = res
}
this.done = true
console.log("complete",res)
}
} as MkDirOptions)
console.log("complete", res)
}
} as MkDirOptions)
},
accessFileTest:function(e:any){
},
accessFileTest: function (e : any) {
this.accessFileRet = ''
let fileManager = uni.getFileSystemManager()
fileManager.access({
path:`${this.basePath}${this.accessFile}`,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
let fileManager = uni.getFileSystemManager()
fileManager.access({
path: `${this.basePath}${this.accessFile}`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
this.accessFileRet = res.errMsg
},
fail:function(res:UniError){
console.log('fail',res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
if(res instanceof UniError){
},
complete: function (res : any) {
if (res instanceof UniError) {
this.lastCompleteError = res
}
console.log("complete",res)
console.log("complete", res)
this.done = true
}
} as AccessOptions)
}
} as AccessOptions)
},
unlinkTest:function(e:any){
},
unlinkTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
let fileManager = uni.getFileSystemManager()
fileManager.unlink({
filePath:`${this.basePath}${this.unlinkFile}`,
success:function(res:FileManagerSuccessResult){
console.log('success',res)
},
fail:function(res:UniError){
console.log('fail',res)
fileManager.unlink({
filePath: `${this.basePath}${this.unlinkFile}`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete:function(res:any){
if(res instanceof UniError){
},
complete: function (res : any) {
if (res instanceof UniError) {
this.lastCompleteError = res
}
console.log("complete",res)
console.log("complete", res)
this.done = true
}
} as UnLinkOptions)
},
}
}
}
} as UnLinkOptions)
},
unlinkAllFileTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.readdir({
dirPath: `${this.basePath}${this.rmDirFile}`,
success: function (res : ReadDirSuccessResult) {
console.log("success to readdir", res)
res.files.forEach(element => {
console.log(element)
fileManager.unlink({
filePath: `${this.basePath}${this.rmDirFile}/${element}`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success unlink', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail unlink', res)
this.lastFailError = res
},
complete: function (res : any) {
if (res instanceof UniError) {
this.lastCompleteError = res
}
console.log("complete unlink", res)
this.done = true
}
} as UnLinkOptions)
});
},
fail: function (res : UniError) {
this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
console.log('fail to readdir', res)
this.lastFailError = res
},
complete: function (res : any) {
console.log("complete readdir", res)
this.done = true
if (res instanceof ReadDirSuccessResult) {
this.fileListComplete = res.files
}
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as ReadDirOptions)
},
copyStaticToFilesTest: function (e : any) {
let fileManager = uni.getFileSystemManager()
fileManager.copyFile({
srcPath: UTSAndroid.getResourcePath("static/list-mock/mock.json"),
destPath: `${this.copyToBasePath}/a/mock.json`,
success: function (res : FileManagerSuccessResult) {
if(this.logAble){
this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
},
fail: function (res : UniError) {
if(this.logAble){
this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
},
complete: function (res : any) {
console.log("complete", res)
this.done = true
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as CopyFileOptions)
},
}
}
</script>
<style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册