提交 58ecb8ad 编写于 作者: xuty73419315's avatar xuty73419315

修改fileManager 示例 function改为箭头函数避免js 找不到this报错

上级 26300172
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
fileManager.stat({ fileManager.stat({
path: `${this.basePath}${this.statFile}`, path: `${this.basePath}${this.statFile}`,
recursive: this.recursiveVal, recursive: this.recursiveVal,
success: function (res : StatSuccessResult) { success: (res : StatSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n' this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n'
} }
...@@ -88,14 +88,14 @@ ...@@ -88,14 +88,14 @@
this.statsRet = res.stats this.statsRet = res.stats
console.log('this.statsRet', this.statsRet) console.log('this.statsRet', this.statsRet)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('statFileInfoTest fail', res) console.log('statFileInfoTest fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("statFileInfoTest complete", res) console.log("statFileInfoTest complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
fileManager.getFileInfo({ fileManager.getFileInfo({
filePath: `${this.basePath}${this.getFileInfoFile}`, filePath: `${this.basePath}${this.getFileInfoFile}`,
digestAlgorithm: this.getFileInfoAlgorithm, digestAlgorithm: this.getFileInfoAlgorithm,
success: function (res : GetFileInfoSuccessResult) { success: (res : GetFileInfoSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n' this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n'
} }
...@@ -119,14 +119,14 @@ ...@@ -119,14 +119,14 @@
this.getFileInfoSize = res.size this.getFileInfoSize = res.size
this.getFileInfoDigest = res.digest this.getFileInfoDigest = res.digest
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -142,20 +142,20 @@ ...@@ -142,20 +142,20 @@
fileManager.copyFile({ fileManager.copyFile({
srcPath: `${this.basePath}${this.copyFromFile}`, srcPath: `${this.basePath}${this.copyFromFile}`,
destPath: `${this.copyToBasePath}${this.copyToFile}`, destPath: `${this.copyToBasePath}${this.copyToFile}`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -171,20 +171,20 @@ ...@@ -171,20 +171,20 @@
fileManager.rename({ fileManager.rename({
oldPath: `${this.basePath}${this.renameFromFile}`, oldPath: `${this.basePath}${this.renameFromFile}`,
newPath: `${this.basePath}${this.renameToFile}`, newPath: `${this.basePath}${this.renameToFile}`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
this.done = true this.done = true
console.log("complete", res) console.log("complete", res)
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -198,21 +198,21 @@ ...@@ -198,21 +198,21 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.readdir({ fileManager.readdir({
dirPath: `${this.basePath}${this.readDir}`, dirPath: `${this.basePath}${this.readDir}`,
success: function (res : ReadDirSuccessResult) { success: (res : ReadDirSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n' this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log("success", res) console.log("success", res)
this.fileListSuccess = res.files this.fileListSuccess = res.files
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof ReadDirSuccessResult) { if (res instanceof ReadDirSuccessResult) {
...@@ -232,20 +232,20 @@ ...@@ -232,20 +232,20 @@
filePath: `${this.basePath}${this.writeFile}`, filePath: `${this.basePath}${this.writeFile}`,
data: this.writeFileContent, data: this.writeFileContent,
encoding: this.writeFileEncoding, encoding: this.writeFileEncoding,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail') console.log('fail')
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
this.done = true this.done = true
console.log("complete") console.log("complete")
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -261,21 +261,21 @@ ...@@ -261,21 +261,21 @@
fileManager.readFile({ fileManager.readFile({
filePath: `${this.basePath}${this.readFile}`, filePath: `${this.basePath}${this.readFile}`,
encoding: this.readFileEncoding, encoding: this.readFileEncoding,
success: function (res : ReadFileSuccessResult) { success: (res : ReadFileSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
this.readFileRet = res.data this.readFileRet = res.data
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -290,20 +290,20 @@ ...@@ -290,20 +290,20 @@
fileManager.rmdir({ fileManager.rmdir({
dirPath: `${this.basePath}${this.rmDirFile}`, dirPath: `${this.basePath}${this.rmDirFile}`,
recursive: this.recursiveVal, recursive: this.recursiveVal,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n' this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
...@@ -320,20 +320,20 @@ ...@@ -320,20 +320,20 @@
fileManager.mkdir({ fileManager.mkdir({
dirPath: `${this.basePath}${this.mkdirFile}`, dirPath: `${this.basePath}${this.mkdirFile}`,
recursive: this.recursiveVal, recursive: this.recursiveVal,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n' this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
if (res instanceof UniError) { if (res instanceof UniError) {
this.lastCompleteError = res this.lastCompleteError = res
} }
...@@ -348,21 +348,21 @@ ...@@ -348,21 +348,21 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.access({ fileManager.access({
path: `${this.basePath}${this.accessFile}`, path: `${this.basePath}${this.accessFile}`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
this.accessFileRet = res.errMsg this.accessFileRet = res.errMsg
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
if (res instanceof UniError) { if (res instanceof UniError) {
this.lastCompleteError = res this.lastCompleteError = res
} }
...@@ -377,20 +377,20 @@ ...@@ -377,20 +377,20 @@
fileManager.unlink({ fileManager.unlink({
filePath: `${this.basePath}${this.unlinkFile}`, filePath: `${this.basePath}${this.unlinkFile}`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
if (res instanceof UniError) { if (res instanceof UniError) {
this.lastCompleteError = res this.lastCompleteError = res
} }
...@@ -403,26 +403,26 @@ ...@@ -403,26 +403,26 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.readdir({ fileManager.readdir({
dirPath: `${this.basePath}${this.rmDirFile}`, dirPath: `${this.basePath}${this.rmDirFile}`,
success: function (res : ReadDirSuccessResult) { success: (res : ReadDirSuccessResult) => {
console.log("success to readdir", res) console.log("success to readdir", res)
res.files.forEach(element => { res.files.forEach(element => {
console.log(element) console.log(element)
fileManager.unlink({ fileManager.unlink({
filePath: `${this.basePath}${this.rmDirFile}/${element}`, filePath: `${this.basePath}${this.rmDirFile}/${element}`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success unlink', res) console.log('success unlink', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail unlink', res) console.log('fail unlink', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete : (res : any) => {
if (res instanceof UniError) { if (res instanceof UniError) {
this.lastCompleteError = res this.lastCompleteError = res
} }
...@@ -432,12 +432,12 @@ ...@@ -432,12 +432,12 @@
} as UnLinkOptions) } as UnLinkOptions)
}); });
}, },
fail: function (res : UniError) { fail : (res : UniError) => {
this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
console.log('fail to readdir', res) console.log('fail to readdir', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete : (res : any) => {
console.log("complete readdir", res) console.log("complete readdir", res)
this.done = true this.done = true
if (res instanceof ReadDirSuccessResult) { if (res instanceof ReadDirSuccessResult) {
...@@ -455,20 +455,20 @@ ...@@ -455,20 +455,20 @@
fileManager.copyFile({ fileManager.copyFile({
srcPath: UTSAndroid.getResourcePath("static/list-mock/mock.json"), srcPath: UTSAndroid.getResourcePath("static/list-mock/mock.json"),
destPath: `${this.copyToBasePath}/a/mock.json`, destPath: `${this.copyToBasePath}/a/mock.json`,
success: function (res : FileManagerSuccessResult) { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: function (res : UniError) { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: function (res : any) { complete: (res : any) => {
console.log("complete", res) console.log("complete", res)
this.done = true this.done = true
if (res instanceof UniError) { if (res instanceof UniError) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册