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

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

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