get-file-system-manager.uvue 46.6 KB
Newer Older
1
<template>
2
  <!-- #ifdef APP -->
W
WOSHIMAHAIFENG 已提交
3 4
  <text>显示简易操作日志,详细日志需真机运行查看</text><button size="mini" @click="log=''">清空日志</button>
  <text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
W
WOSHIMAHAIFENG 已提交
5
  <scroll-view style="flex: 1;">
6
  <!-- #endif -->
W
WOSHIMAHAIFENG 已提交
7 8
    <button class="btnstyle" type="primary" @tap="statFileInfoTest"
      id="btn-stat-file">递归获取目录files的Stats对象{{statFile}}</button>
W
WOSHIMAHAIFENG 已提交
9 10 11 12
    <button class="btnstyle" type="primary" @tap="mkdirTest" id="btn-mkdir">创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeFileTest" id="btn-write-file">覆盖写入文件{{writeFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirTest" id="btn-read-dir">读取文件夹{{readDir}}</button>
    <button class="btnstyle" type="primary" @tap="readFileTest" id="btn-read-file">读取文件{{readFile}}</button>
W
WOSHIMAHAIFENG 已提交
13 14 15 16
    <button class="btnstyle" type="primary" @tap="copyFileTest"
      id="btn-copy-file">复制文件{{copyFromFile}}到{{copyToFile}}</button>
    <button class="btnstyle" type="primary" @tap="renameFileTest"
      id="btn-rename-file">重命名文件{{renameFromFile}}到{{renameToFile}}</button>
W
WOSHIMAHAIFENG 已提交
17
    <button class="btnstyle" type="primary" @tap="accessFileTest" id="btn-access-file">判断文件{{accessFile}}是否存在</button>
W
WOSHIMAHAIFENG 已提交
18 19
    <button class="btnstyle" type="primary" @tap="getFileInfoTest"
      id="btn-get-file-info">获取文件信息{{getFileInfoFile}}</button>
W
WOSHIMAHAIFENG 已提交
20
    <button class="btnstyle" type="primary" @tap="unlinkTest" id="btn-unlink-file">删除文件{{unlinkFile}}</button>
W
WOSHIMAHAIFENG 已提交
21 22 23 24
    <button class="btnstyle" type="primary" @tap="copyStaticToFilesTest"
      id="btn-copyStatic-file">从static目录复制文件到a目录</button>
    <button class="btnstyle" type="primary" @tap="unlinkAllFileTest"
      id="btn-clear-file">删除文件夹{{rmDirFile}}下的所有文件</button>
W
WOSHIMAHAIFENG 已提交
25
    <button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button>
W
WOSHIMAHAIFENG 已提交
26 27


W
WOSHIMAHAIFENG 已提交
28 29
    <!-- #ifdef APP-ANDROID -->
    <button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
W
WOSHIMAHAIFENG 已提交
30
      id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
W
WOSHIMAHAIFENG 已提交
31
    <button class="btnstyle" type="primary" @tap="appendFileTest" id="btn-append-file">在文件{{readFile}}结尾追加内容</button>
W
WOSHIMAHAIFENG 已提交
32 33 34 35
    <button class="btnstyle" type="primary" @tap="appendFileSyncTest"
      id="btn-append-file-sync">同步在文件{{readFile}}结尾追加内容</button>
    <button class="btnstyle" type="primary" @tap="writeFileSyncTest"
      id="btn-write-file-sync">同步覆盖写入文件{{writeFile}}</button>
W
WOSHIMAHAIFENG 已提交
36
    <button class="btnstyle" type="primary" @tap="readFileSyncTest" id="btn-read-file-sync">同步读取文件{{readFile}}</button>
W
WOSHIMAHAIFENG 已提交
37 38
    <button class="btnstyle" type="primary" @tap="unlinkSyncTest"
      id="btn-unlink-file-sync">同步删除文件{{unlinkFile}}</button>
W
WOSHIMAHAIFENG 已提交
39 40 41
    <button class="btnstyle" type="primary" @tap="mkdirSyncTest" id="btn-mkdir-sync">同步创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="rmdirSyncTest" id="btn-remove-dir-sync">同步删除文件夹{{rmDirFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirSyncTest" id="btn-read-dir-sync">同步读取文件夹{{readDir}}</button>
W
WOSHIMAHAIFENG 已提交
42 43
    <button class="btnstyle" type="primary" @tap="accessFileSyncTest"
      id="btn-access-file-sync">同步判断文件{{accessFile}}是否存在</button>
W
WOSHIMAHAIFENG 已提交
44
    <button class="btnstyle" type="primary" @tap="renameFileSync"
W
WOSHIMAHAIFENG 已提交
45
      id="btn-rename-file-sync">同步重命名文件{{renameFromFile}}到{{renameToFile}}</button>
W
WOSHIMAHAIFENG 已提交
46
    <button class="btnstyle" type="primary" @tap="copyFileSyncTest"
W
WOSHIMAHAIFENG 已提交
47
      id="btn-copy-file-sync">同步复制文件{{copyFromFile}}到{{copyToFile}}</button>
W
WOSHIMAHAIFENG 已提交
48 49 50 51
    <button class="btnstyle" type="primary" @tap="saveFileTest" id="btn-save-file">保存临时文件到本地</button>
    <button class="btnstyle" type="primary" @tap="saveFileSyncTest" id="btn-save-file-sync">同步保存临时文件到本地</button>
    <button class="btnstyle" type="primary" @tap="removeSavedFileTest" id="btn-remove-saved-file">删除已保存的本地文件</button>
    <button class="btnstyle" type="primary" @tap="unzipFileTest" id="btn-unzip-file-sync">解压文件</button>
W
WOSHIMAHAIFENG 已提交
52 53 54 55 56 57 58 59 60 61
    <button class="btnstyle" type="primary" @tap="getSavedFileListTest"
      id="btn-getsaved-filelist">获取该已保存的本地缓存文件列表</button>
    <button class="btnstyle" type="primary" @tap="truncateFileTest"
      id="btn-truncate-file">对文件{{writeFile}}内容进行截断操作</button>
    <button class="btnstyle" type="primary" @tap="truncateFileSyncTest"
      id="btn-truncate-file-sync">同步对文件{{writeFile}}内容进行截断操作</button>
    <button class="btnstyle" type="primary" @tap="readCompressedFileTest"
      id="btn-compressed-file">读取指定压缩类型的本地文件内容</button>
    <button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest"
      id="btn-compressed-file-sync">同步读取指定压缩类型的本地文件内容</button>
W
WOSHIMAHAIFENG 已提交
62
    <button class="btnstyle" type="primary" @tap="openFileTest" id="btn-open-file">打开文件{{readFile}},返回描述符</button>
W
WOSHIMAHAIFENG 已提交
63
    <button class="btnstyle" type="primary" @tap="openFileSyncTest('r')"
W
WOSHIMAHAIFENG 已提交
64
      id="btn-open-file-sync">同步打开文件{{readFile}},返回描述符</button>
W
WOSHIMAHAIFENG 已提交
65
    <button class="btnstyle" type="primary" @tap="closeTest" id="btn-close-file">通过文件描述符关闭文件{{readFile}}</button>
W
WOSHIMAHAIFENG 已提交
66 67
    <button class="btnstyle" type="primary" @tap="closeSyncTest"
      id="btn-close-file-sync">通过文件描述符同步关闭文件{{readFile}}</button>
W
WOSHIMAHAIFENG 已提交
68
    <button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button>
69
    <button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-write-sync">同步通过文件描述符写入文件{{readFile}}</button>
W
WOSHIMAHAIFENG 已提交
70
    <button class="btnstyle" type="primary" @tap="fstatTest" id="btn-fstat-file">通过文件描述符获取{{statFile}}的状态信息</button>
W
WOSHIMAHAIFENG 已提交
71 72 73 74
    <button class="btnstyle" type="primary" @tap="fstatSyncTest"
      id="btn-fstat-file-sync">同步通过文件描述符获取{{statFile}}的状态信息</button>
    <button class="btnstyle" type="primary" @tap="ftruncateFileTest"
      id="btn-ftruncate-file">通过文件描述符对文件{{writeFile}}内容进行截断</button>
W
WOSHIMAHAIFENG 已提交
75 76 77 78 79
    <button class="btnstyle" type="primary" @tap="ftruncateFileSyncTest"
      id="btn-ftruncate-file-sync">同步通过文件描述符对文件{{writeFile}}内容进行截断</button>
    <button class="btnstyle" type="primary" @tap="readZipEntry" id="btn-readzip-entry">读取压缩包内的文件</button>
    <view style="height: 4px;"></view>
    <!-- #endif -->
80 81 82
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
83 84 85
</template>

<script>
86 87 88 89 90
  export default {

    data() {
      return {
        log: "",
91 92 93
        /**
         * 自动化测试需要关闭log
         */
H
hdx 已提交
94
        logAble: true,
95 96 97
        fileListSuccess: [] as string[],
        fileListComplete: [] as string[],
        accessFileRet: '',
98 99
        lastFailError: new UniError("uni-file-manager", 1300000, "mock error"),
        lastCompleteError: new UniError("uni-file-manager", 1300000, "mock error"),
100 101 102
        readDir: 'a',
        readFileRet: "",
        writeFileContent: "中文 en.\r\n\t换行",
W
WOSHIMAHAIFENG 已提交
103
        appendFileContent: "append content",
104 105 106 107 108 109
        getFileInfoAlgorithm: "md5",
        getFileInfoSize: -1,
        getFileInfoDigest: "",
        unlinkFile: 'a/1.txt',
        accessFile: 'a/1.txt',
        writeFile: 'a/1.txt',
W
WOSHIMAHAIFENG 已提交
110 111 112
        writeData: 'insert data哈哈哈',
        brFile: 'a/1.txt.br',
        temFile: 'a/1.txt',
113 114 115 116 117 118 119 120 121 122
        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,
123
        done: false,
124 125 126
        writeFileEncoding: "utf-8",
        readFileEncoding: "utf-8",
        statsRet: [] as Array<FileStats>,
W
WOSHIMAHAIFENG 已提交
127 128 129 130 131 132 133 134
        unzipFile: 'zip/1.zip',
        targetZip: "unzip",
        renameFileRet: '',
        saveFileRet: '',
        removeSavedFileRet: '',
        fd: '',
        closeFileRet: '',
        bytesWritten: 0,
W
WOSHIMAHAIFENG 已提交
135
        fstat: null as Stats | null,
W
WOSHIMAHAIFENG 已提交
136 137
        ftruncateRet: '',
        readZipFile: 'to.zip',
138
        getSavedFileListRet: '',
139 140 141 142 143
        /**
         * 待测试的全局环境变量
         */
        basePath: uni.env.USER_DATA_PATH,
        copyToBasePath: uni.env.USER_DATA_PATH,
144 145 146 147 148
        globalTempPath: uni.env.CACHE_PATH,
        globalRootPath: uni.env.SANDBOX_PATH,
        globalUserDataPath: uni.env.USER_DATA_PATH
      }
    },
149 150 151
    onLoad() {
    },

152
    methods: {
153
      statFileInfoTest: function (_ : any) {
H
hdx 已提交
154
        const fileManager = uni.getFileSystemManager()
155
        fileManager.stat({
W
wanganxp 已提交
156 157
          // path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
          path: `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
158
          recursive: this.recursiveVal,
159
          success: (res : StatSuccessResult) => {
H
hdx 已提交
160
            if (this.logAble) {
161 162
              this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
163
            console.log('statFileInfoTest success', res)
杜庆泉's avatar
杜庆泉 已提交
164
            this.statsRet = res.stats
165 166
            console.log('this.statsRet', this.statsRet)
          },
M
mahaifeng 已提交
167
          fail: (res:IUniError ) => {
H
hdx 已提交
168
            if (this.logAble) {
169 170
              this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
171
            console.log('statFileInfoTest fail', res)
M
mahaifeng 已提交
172
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
173
          },
174
          complete: (res : any) => {
175
            console.log("statFileInfoTest complete", res)
杜庆泉's avatar
杜庆泉 已提交
176
            this.done = true
177
            if (res instanceof UniError) {
杜庆泉's avatar
杜庆泉 已提交
178 179
              this.lastCompleteError = res
            }
180 181 182 183
          }
        } as StatOptions)
      },

184
      getFileInfoTest: function () {
H
hdx 已提交
185
        const fileManager = uni.getFileSystemManager()
186 187 188 189

        fileManager.getFileInfo({
          filePath: `${this.basePath}${this.getFileInfoFile}`,
          digestAlgorithm: this.getFileInfoAlgorithm,
190
          success: (res : GetFileInfoSuccessResult) => {
H
hdx 已提交
191
            if (this.logAble) {
192 193
              this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
194
            console.log('success', res)
195 196
            this.getFileInfoSize = res.size
            this.getFileInfoDigest = res.digest
197
          },
M
mahaifeng 已提交
198
          fail: (res : IUniError) => {
H
hdx 已提交
199
            if (this.logAble) {
200 201
              this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
202
            console.log('fail', res)
M
mahaifeng 已提交
203
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
204
          },
205
          complete: (res : any) => {
206
            console.log("complete", res)
207
            this.done = true
208
            if (res instanceof UniError) {
209 210
              this.lastCompleteError = res
            }
211 212 213
          }
        } as GetFileInfoOptions)
      },
214

215
      copyFileTest: function () {
H
hdx 已提交
216
        const fileManager = uni.getFileSystemManager()
217

218 219 220
        fileManager.copyFile({
          srcPath: `${this.basePath}${this.copyFromFile}`,
          destPath: `${this.copyToBasePath}${this.copyToFile}`,
221
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
222
            if (this.logAble) {
223 224
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
225 226
            console.log('success', res)
          },
M
mahaifeng 已提交
227
          fail: (res : IUniError) => {
H
hdx 已提交
228
            if (this.logAble) {
229 230
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
231
            console.log('fail', res)
M
mahaifeng 已提交
232
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
233
          },
234
          complete: (res : any) => {
235
            console.log("complete", res)
236
            this.done = true
237
            if (res instanceof UniError) {
238 239
              this.lastCompleteError = res
            }
240 241 242 243
          }
        } as CopyFileOptions)
      },

244
      renameFileTest: function () {
H
hdx 已提交
245
        const fileManager = uni.getFileSystemManager()
246 247 248 249

        fileManager.rename({
          oldPath: `${this.basePath}${this.renameFromFile}`,
          newPath: `${this.basePath}${this.renameToFile}`,
W
WOSHIMAHAIFENG 已提交
250
          success: (res) => {
H
hdx 已提交
251
            if (this.logAble) {
252 253
              this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n'
            }
254 255
            console.log('success', res)
          },
M
mahaifeng 已提交
256
          fail: (res : IUniError) => {
H
hdx 已提交
257
            if (this.logAble) {
258 259
              this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
260
            console.log('fail', res)
M
mahaifeng 已提交
261
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
262
          },
263
          complete: (res : any) => {
264
            this.done = true
265 266
            console.log("complete", res)
            if (res instanceof UniError) {
267 268
              this.lastCompleteError = res
            }
269 270 271 272
          }
        } as RenameOptions)
      },

273
      readDirTest: function () {
H
hdx 已提交
274
        const fileManager = uni.getFileSystemManager()
275 276
        fileManager.readdir({
          dirPath: `${this.basePath}${this.readDir}`,
277
          success: (res : ReadDirSuccessResult) => {
H
hdx 已提交
278
            if (this.logAble) {
279 280
              this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
            }
281
            console.log("success", res)
282
            this.fileListSuccess = res.files
283
          },
M
mahaifeng 已提交
284
          fail: (res : IUniError) => {
H
hdx 已提交
285
            if (this.logAble) {
286 287
              this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
            }
288
            console.log('fail', res)
M
mahaifeng 已提交
289
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
290
          },
291
          complete: (res : any) => {
292
            console.log("complete", res)
293
            this.done = true
294
            if (res instanceof UniError) {
295
              this.lastCompleteError = res
296 297
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
298
            }
299 300 301 302
          }
        } as ReadDirOptions)
      },

303
      writeFileTest: function (_ : any) {
H
hdx 已提交
304
        const fileManager = uni.getFileSystemManager()
305 306 307 308 309

        fileManager.writeFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.writeFileContent,
          encoding: this.writeFileEncoding,
W
WOSHIMAHAIFENG 已提交
310
          success: (res) => {
H
hdx 已提交
311
            if (this.logAble) {
312 313
              this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n'
            }
314 315
            console.log('success', res)
          },
M
mahaifeng 已提交
316
          fail: (res : IUniError) => {
H
hdx 已提交
317
            if (this.logAble) {
318 319
              this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
320
            console.log('fail')
M
mahaifeng 已提交
321
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
322
          },
323
          complete: (res : any) => {
324
            this.done = true
325 326
            console.log("complete")
            if (res instanceof UniError) {
327 328
              this.lastCompleteError = res
            }
W
WOSHIMAHAIFENG 已提交
329

330 331 332
          }
        } as WriteFileOptions)
      },
333

334
      readFileTest: function () {
H
hdx 已提交
335
        const fileManager = uni.getFileSystemManager()
336

337 338 339
        fileManager.readFile({
          filePath: `${this.basePath}${this.readFile}`,
          encoding: this.readFileEncoding,
340
          success: (res : ReadFileSuccessResult) => {
H
hdx 已提交
341
            if (this.logAble) {
342 343
              this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
            }
344
            console.log('success', res)
345
            this.readFileRet = res.data
346
          },
M
mahaifeng 已提交
347
          fail: (res : IUniError) => {
H
hdx 已提交
348
            if (this.logAble) {
349 350
              this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
351
            console.log('fail', res)
M
mahaifeng 已提交
352
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
353
          },
354
          complete: (res : any) => {
355
            console.log("complete", res)
356
            this.done = true
357
            if (res instanceof UniError) {
358 359
              this.lastCompleteError = res
            }
360 361 362 363
          }
        } as ReadFileOptions)
      },

364
      rmdirTest: function () {
H
hdx 已提交
365
        const fileManager = uni.getFileSystemManager()
366 367 368
        fileManager.rmdir({
          dirPath: `${this.basePath}${this.rmDirFile}`,
          recursive: this.recursiveVal,
369
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
370
            if (this.logAble) {
371 372
              this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n'
            }
373 374
            console.log('success', res)
          },
M
mahaifeng 已提交
375
          fail: (res : IUniError) => {
H
hdx 已提交
376
            if (this.logAble) {
377 378
              this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
379
            console.log('fail', res)
M
mahaifeng 已提交
380
            this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)
381
          },
382
          complete: (res : any) => {
383
            console.log("complete", res)
384
            this.done = true
385
            if (res instanceof UniError) {
386 387
              this.lastCompleteError = res
            }
388 389 390
          }
        } as RmDirOptions)
      },
391

392
      mkdirTest: function () {
393
        // 准备测试数据
H
hdx 已提交
394
        const fileManager = uni.getFileSystemManager()
395 396 397 398

        fileManager.mkdir({
          dirPath: `${this.basePath}${this.mkdirFile}`,
          recursive: this.recursiveVal,
399
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
400
            if (this.logAble) {
401 402
              this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n'
            }
403 404
            console.log('success', res)
          },
M
mahaifeng 已提交
405
          fail: (res : IUniError) => {
H
hdx 已提交
406
            if (this.logAble) {
407 408
              this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
409
            console.log('fail', res)
M
mahaifeng 已提交
410 411
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

412
          },
413
          complete: (res : any) => {
414
            if (res instanceof UniError) {
415 416 417
              this.lastCompleteError = res
            }
            this.done = true
418 419 420
            console.log("complete", res)
          }
        } as MkDirOptions)
421

422
      },
423
      accessFileTest: function () {
424
        this.accessFileRet = ''
H
hdx 已提交
425
        const fileManager = uni.getFileSystemManager()
426 427
        fileManager.access({
          path: `${this.basePath}${this.accessFile}`,
428
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
429
            if (this.logAble) {
430 431
              this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
            }
432
            console.log('success', res)
433
            this.accessFileRet = res.errMsg
434
          },
M
mahaifeng 已提交
435
          fail: (res : IUniError) => {
H
hdx 已提交
436
            if (this.logAble) {
437 438
              this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
439
            console.log('fail', res)
M
mahaifeng 已提交
440 441
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

442
          },
443
          complete: (res : any) => {
444
            if (res instanceof UniError) {
445 446
              this.lastCompleteError = res
            }
447
            console.log("complete", res)
448
            this.done = true
449 450
          }
        } as AccessOptions)
451

452
      },
453
      unlinkTest: function () {
H
hdx 已提交
454
        const fileManager = uni.getFileSystemManager()
455 456 457

        fileManager.unlink({
          filePath: `${this.basePath}${this.unlinkFile}`,
458
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
459
            if (this.logAble) {
460 461
              this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
            }
462 463
            console.log('success', res)
          },
M
mahaifeng 已提交
464
          fail: (res : IUniError) => {
H
hdx 已提交
465
            if (this.logAble) {
466 467
              this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
            }
468
            console.log('fail', res)
M
mahaifeng 已提交
469 470
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

471
          },
472
          complete: (res : any) => {
473
            if (res instanceof UniError) {
474 475
              this.lastCompleteError = res
            }
476
            console.log("complete", res)
477
            this.done = true
478 479 480
          }
        } as UnLinkOptions)
      },
481
      unlinkAllFileTest: function () {
H
hdx 已提交
482
        const fileManager = uni.getFileSystemManager()
W
wanganxp 已提交
483
        fileManager.readdir({
484
          dirPath: `${this.basePath}${this.rmDirFile}`,
485
          success: (res : ReadDirSuccessResult) => {
486
            console.log("success to readdir", res)
W
wanganxp 已提交
487
            res.files.forEach(element => {
488
              console.log(element)
W
WOSHIMAHAIFENG 已提交
489
              let filePath : string
W
WOSHIMAHAIFENG 已提交
490 491 492 493 494
              if (this.rmDirFile.length <= 0) {
                filePath = `${this.basePath}${element}`
              } else {
                filePath = `${this.basePath}${this.rmDirFile}/${element}`
              }
495
              fileManager.unlink({
W
WOSHIMAHAIFENG 已提交
496
                filePath: filePath,
497
                success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
498
                  if (this.logAble) {
499 500
                    this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
                  }
501 502
                  console.log('success unlink', res)
                },
M
mahaifeng 已提交
503
                fail: (res : IUniError) => {
H
hdx 已提交
504
                  if (this.logAble) {
505 506
                    this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
                  }
507
                  console.log('fail unlink', res)
M
mahaifeng 已提交
508 509
                              this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

510
                },
W
WOSHIMAHAIFENG 已提交
511
                complete: (res : any) => {
512 513 514 515 516 517 518
                  if (res instanceof UniError) {
                    this.lastCompleteError = res
                  }
                  console.log("complete unlink", res)
                  this.done = true
                }
              } as UnLinkOptions)
W
wanganxp 已提交
519
            });
520
          },
M
mahaifeng 已提交
521
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
522 523 524
            if (this.logAble) {
              this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
525
            console.log('fail to readdir', res)
M
mahaifeng 已提交
526 527
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

528
          },
W
WOSHIMAHAIFENG 已提交
529
          complete: (res : any) => {
530
            console.log("complete readdir", res)
W
wanganxp 已提交
531
            this.done = true
532
            if (res instanceof UniError) {
W
wanganxp 已提交
533
              this.lastCompleteError = res
534 535
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
W
wanganxp 已提交
536
            }
537
          }
W
wanganxp 已提交
538 539
        } as ReadDirOptions)
      },
540
      copyStaticToFilesTest: function () {
H
hdx 已提交
541
        const fileManager = uni.getFileSystemManager()
542 543

        fileManager.copyFile({
544
          srcPath: "/static/list-mock/mock.json",
545
          destPath: `${this.copyToBasePath}/a/mock.json`,
W
WOSHIMAHAIFENG 已提交
546
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
547
            if (this.logAble) {
548 549
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
550 551
            console.log('success', res)
          },
M
mahaifeng 已提交
552
          fail: (res : IUniError) => {
H
hdx 已提交
553
            if (this.logAble) {
554 555
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
556
            console.log('fail', res)
M
mahaifeng 已提交
557 558
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

559
          },
560
          complete: (res : any) => {
561 562 563 564 565 566 567 568
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581
      //start
      appendFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.appendFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.appendFileContent,
          encoding: this.writeFileEncoding,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'appendFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
M
mahaifeng 已提交
582
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
583 584 585 586
            if (this.logAble) {
              this.log += 'appendFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail')
M
mahaifeng 已提交
587 588
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
          },
          complete: (res : any) => {
            this.done = true
            console.log("complete")
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }

          }
        } as AppendFileOptions)
      },
      writeFileSyncTest: function (_ : any) {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.writeFileSync(`${this.basePath}${this.writeFile}`, this.writeFileContent, this.writeFileEncoding)
          if (this.logAble) {
            this.log += 'writeFileSyncTest success:' + '\n\n'
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'writeFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      readFileSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let data = fileManager.readFileSync(
            `${this.basePath}${this.readFile}`,
            this.readFileEncoding)
          if (this.logAble) {
            this.log += 'readFileSyncTest result:' + data + '\n\n'
          }
          this.done = true
          this.readFileRet = data
        } catch (e) {
          if (this.logAble) {
            this.log += 'readFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      unlinkSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.unlinkSync(
            `${this.basePath}${this.unlinkFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'unlinkSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      mkdirSyncTest: function () {
        // 准备测试数据
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, this.recursiveVal)
          this.done = true
        } catch (e) {
          this.done = true
          if (this.logAble) {
            this.log += 'mkdirSyncTest fail:' + e + '\n\n'
          }
        }

      },
      rmdirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.rmdirSync(
            `${this.basePath}${this.rmDirFile}`,
            this.recursiveVal)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      readDirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let res = fileManager.readdirSync(
            `${this.basePath}${this.readDir}`)
          if (this.logAble) {
            this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
          }
          if (res != null) {
            this.fileListSuccess = res
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      accessFileSyncTest: function () {
        this.accessFileRet = ''
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.accessSync(`${this.basePath}${this.accessFile}`)
          this.done = true
          this.accessFileRet = 'access:ok'
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      renameFileSync: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.renameSync(`${this.basePath}${this.renameFromFile}`,
            `${this.basePath}${this.renameToFile}`)
          this.done = true
          this.renameFileRet = "rename:ok"

        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          console.log('renameSync:' + e)
          this.done = true
        }
      },
      copyFileSyncTest: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.copyFileSync(
            `${this.basePath}${this.copyFromFile}`,
            `${this.copyToBasePath}${this.copyToFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      appendFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.appendFileSync(
            `${this.basePath}${this.writeFile}`,
            this.appendFileContent,
            this.writeFileEncoding)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      saveFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.saveFile({
          tempFilePath: `${this.globalTempPath}${this.temFile}`,
          // filePath:`${this.basePath}local/`,
          success: (res : SaveFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.saveFileRet = res.savedFilePath
W
WOSHIMAHAIFENG 已提交
765
            this.done = true
W
WOSHIMAHAIFENG 已提交
766
          },
M
mahaifeng 已提交
767
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
768 769 770
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
771
            console.log('saveFileTest fail', res)
M
mahaifeng 已提交
772 773
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
774
            this.done = true
W
WOSHIMAHAIFENG 已提交
775
          },
W
WOSHIMAHAIFENG 已提交
776
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
777 778 779 780 781 782 783 784
            this.done = true
          }
        } as SaveFileOptions)
      },
      saveFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.saveFileSync(
W
WOSHIMAHAIFENG 已提交
785
            `${this.globalTempPath}${this.temFile}`, `${this.basePath}/`)
W
WOSHIMAHAIFENG 已提交
786 787 788 789 790 791
          // filePath:`${this.basePath}local/`,)
          this.done = true

          //todo 后面打开
          // this.saveFileRet=res
        } catch (e) {
W
WOSHIMAHAIFENG 已提交
792
          console.log('saveFileSyncTest:' + e)
W
WOSHIMAHAIFENG 已提交
793 794 795 796
          this.done = true
        }
      },
      unzipFileTest: function (_ : any) {
W
WOSHIMAHAIFENG 已提交
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.targetZip}`, true)
        } catch (e) {
          console.error(e)
        }
        fileManager.unzip({
          zipFilePath: '/static/filemanager/to.zip',
          targetPath: `${this.basePath}${this.targetZip}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'unzipFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
M
mahaifeng 已提交
812
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
813 814 815 816
            if (this.logAble) {
              this.log += 'unzipFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
817 818
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
819
          },
W
WOSHIMAHAIFENG 已提交
820 821
          complete: (_) => {
            this.done = true
W
WOSHIMAHAIFENG 已提交
822
          }
W
WOSHIMAHAIFENG 已提交
823
        } as UnzipFileOptions)
W
WOSHIMAHAIFENG 已提交
824 825 826 827 828 829 830 831 832
      },

      getSavedFileListTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.getSavedFileList({
          success: (res : GetSavedFileListResult) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
833
            console.log("getSavedFileListTest success", res)
W
WOSHIMAHAIFENG 已提交
834
            this.fileListSuccess = res.fileList
835
            this.getSavedFileListRet = "getSavedFileList:ok"
W
WOSHIMAHAIFENG 已提交
836
          },
M
mahaifeng 已提交
837
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
838 839 840
            if (this.logAble) {
              this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
841
            console.log('getSavedFileListTest fail', res)
M
mahaifeng 已提交
842 843
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
844
            this.getSavedFileListRet = JSON.stringify(res)
W
WOSHIMAHAIFENG 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            } else {
              this.fileListComplete = (res as GetSavedFileListResult).fileList
            }
          }
        } as GetSavedFileListOptions)
      },
      truncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.truncate({
          filePath: `${this.basePath}${this.writeFile}`,
          length: 7,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
864
              this.log += 'truncateFileTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
865 866 867
            }
            console.log("success", res)
          },
M
mahaifeng 已提交
868
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
869
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
870
              this.log += 'truncateFileTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
871 872
            }
            console.log('fail', res)
M
mahaifeng 已提交
873 874
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as TruncateFileOptions)
      },
      truncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.truncateSync(
            `${this.basePath}${this.writeFile}`,
            4)
          this.done = true
        } catch (e) {
          console.log(e)
          this.done = true
        }
      },
      readCompressedFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readCompressedFile({
W
WOSHIMAHAIFENG 已提交
900
          filePath: '/static/filemanager/1.txt.br',
W
WOSHIMAHAIFENG 已提交
901 902 903 904 905 906 907
          compressionAlgorithm: "br",
          success: (res : ReadCompressedFileResult) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
M
mahaifeng 已提交
908
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
909 910 911 912
            if (this.logAble) {
              this.log += 'readCompressedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
913 914
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
915
          },
W
WOSHIMAHAIFENG 已提交
916
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
917 918 919 920 921 922 923 924 925
            this.done = true
          }
        } as ReadCompressedFileOptions)
      },
      readCompressedFileSyncTest() {
        console.log('readCompressedFileSyncTest')
        const fileManager = uni.getFileSystemManager()
        try {
          let data = fileManager.readCompressedFileSync(
W
WOSHIMAHAIFENG 已提交
926
            '/static/filemanager/1.txt.br',
W
WOSHIMAHAIFENG 已提交
927 928 929 930 931 932 933
            "br")
          if (this.logAble) {
            this.log += data
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
934
            this.log += 'readCompressedFileSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
          }
          this.done = true
        }

      },
      removeSavedFileTest() {
        console.log("removeSavedFileTest enter")
        const fileManager = uni.getFileSystemManager()
        fileManager.removeSavedFile({
          filePath: `${this.basePath}${this.writeFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.removeSavedFileRet = res.errMsg
W
WOSHIMAHAIFENG 已提交
950
            console.log("removeSavedFileTest success", res)
W
WOSHIMAHAIFENG 已提交
951
          },
M
mahaifeng 已提交
952
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
953 954 955
            if (this.logAble) {
              this.log += 'removeSavedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
956
            console.log('removeSavedFileTest fail', res)
W
WOSHIMAHAIFENG 已提交
957
          },
W
WOSHIMAHAIFENG 已提交
958
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971
            this.done = true
          }
        } as RemoveSavedFileOptions)
      },

      statFileInfoSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          let res = fileManager.statSync(
            // path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
            `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
            this.recursiveVal)
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
972
            this.log += 'statFileInfoSyncTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
973 974 975 976 977
          }
          this.statsRet = res
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
978
            this.log += 'statFileInfoSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
          }
          this.done = true
        }

      },
      openFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "a",
          success: (res : OpenFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'openFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fd = res.fd
          },
M
mahaifeng 已提交
996
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
997 998 999 1000
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
1001 1002
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1003
          },
W
WOSHIMAHAIFENG 已提交
1004
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1005 1006 1007 1008
            this.done = true
          }
        } as OpenFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
1009
      openFileSyncTest(param : string) : string {
W
WOSHIMAHAIFENG 已提交
1010 1011 1012 1013
        const fileManager = uni.getFileSystemManager()
        try {
          let fd = fileManager.openSync({
            filePath: `${this.basePath}${this.readFile}`,
W
WOSHIMAHAIFENG 已提交
1014
            flag: param,
W
WOSHIMAHAIFENG 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
          } as OpenFileSyncOptions)
          if (this.logAble) {
            this.log += 'openFileSyncTest success:' + fd + '\n\n'
          }
          this.done = true
          this.fd = fd
          return fd
        } catch (e) {
          if (this.logAble) {
            this.log += 'openFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          console.log('fail', e)
          this.done = true
        }
        return ""
      },
      closeSyncTest() {
        console.log('closeSyncTest')
        const fileManager = uni.getFileSystemManager()
1034 1035 1036
        try {
          console.log('closeSync')
          fileManager.closeSync({
W
WOSHIMAHAIFENG 已提交
1037
            fd: this.openFileSyncTest('r')
1038 1039 1040
          } as CloseSyncOptions)
          if (this.logAble) {
            this.log += 'closeSyncTest success:' + '\n\n'
W
WOSHIMAHAIFENG 已提交
1041
          }
1042 1043 1044 1045 1046 1047 1048 1049 1050
          this.done = true
          this.closeFileRet = "close:ok"
        } catch (e) {
          if (this.logAble) {
            this.log += 'closeSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          console.log('fail', e)
          this.done = true
        }
W
WOSHIMAHAIFENG 已提交
1051 1052 1053
      },
      closeTest() {
        const fileManager = uni.getFileSystemManager()
1054
        fileManager.close({
W
WOSHIMAHAIFENG 已提交
1055
          fd: this.openFileSyncTest('r'),
1056 1057 1058
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1059
            }
1060 1061
            this.closeFileRet = res.errMsg
            console.log("success", res)
W
WOSHIMAHAIFENG 已提交
1062
          },
M
mahaifeng 已提交
1063
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1064
            if (this.logAble) {
1065
              this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1066 1067
            }
            console.log('fail', res)
M
mahaifeng 已提交
1068 1069
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

1070 1071
          },
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1072 1073
            this.done = true
          }
1074 1075

        } as CloseOptions)
W
WOSHIMAHAIFENG 已提交
1076 1077 1078
      },
      writeTest() {
        const fileManager = uni.getFileSystemManager()
W
WOSHIMAHAIFENG 已提交
1079 1080 1081 1082 1083
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }
W
WOSHIMAHAIFENG 已提交
1084

W
WOSHIMAHAIFENG 已提交
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
        fileManager.write({
          fd: this.openFileSyncTest('w+'),
          data: this.writeData,
          encoding: "utf-8",
          success: (res : WriteResult) => {
            if (this.logAble) {
              this.log += 'writeTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.bytesWritten = res.bytesWritten
W
WOSHIMAHAIFENG 已提交
1095
          },
M
mahaifeng 已提交
1096
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1097
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1098
              this.log += 'writeTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1099 1100
            }
            console.log('fail', res)
M
mahaifeng 已提交
1101 1102
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1103 1104
          },
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1105 1106
            this.done = true
          }
W
WOSHIMAHAIFENG 已提交
1107 1108

        } as WriteOptions)
W
WOSHIMAHAIFENG 已提交
1109 1110 1111
      },
      writeSyncTest() {
        const fileManager = uni.getFileSystemManager()
W
WOSHIMAHAIFENG 已提交
1112 1113 1114 1115 1116
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }
W
WOSHIMAHAIFENG 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            try {
              let ret = fileManager.writeSync({
                fd: res.fd,
                data: this.writeData,
                encoding: "utf-8"
              } as WriteSyncOptions)
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1133
                this.log += 'writeSyncTest success:' + JSON.stringify(ret) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1134 1135 1136 1137 1138 1139
              }
              console.log("success", ret)
              this.done = true
              this.bytesWritten = ret.bytesWritten
            } catch (e) {
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1140
                this.log += 'writeSyncTest fail:' + JSON.stringify(e) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1141 1142 1143 1144 1145
              }
              console.log('fail', e)
              this.done = true
            }
          },
M
mahaifeng 已提交
1146
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1147 1148 1149 1150
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
1151 1152
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1153 1154 1155 1156 1157 1158 1159 1160
            this.done = true
          }
        } as OpenFileOptions)

      },
      fstatTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.fstat({
W
WOSHIMAHAIFENG 已提交
1161
          fd: this.openFileSyncTest('r'),
W
WOSHIMAHAIFENG 已提交
1162 1163 1164 1165 1166 1167 1168
          success: (res : FStatSuccessResult) => {
            if (this.logAble) {
              this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fstat = res.stats
          },
M
mahaifeng 已提交
1169
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1170 1171 1172 1173
            if (this.logAble) {
              this.log += 'fstatTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
1174 1175
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1176
          },
W
WOSHIMAHAIFENG 已提交
1177
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
            this.done = true
          }

        } as FStatOptions)
      },
      fstatSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          let stat =
            fileManager.fstatSync({
W
WOSHIMAHAIFENG 已提交
1188
              fd: this.openFileSyncTest('r'),
W
WOSHIMAHAIFENG 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
            } as FStatSyncOptions)
          if (this.logAble) {
            this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n'
          }
          this.done = true
          this.fstat = stat
        } catch (e) {
          if (this.logAble) {
            this.log += 'fstatSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
      },
      ftruncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.ftruncate({
W
WOSHIMAHAIFENG 已提交
1205
          fd: this.openFileSyncTest('r+'),
W
WOSHIMAHAIFENG 已提交
1206 1207 1208 1209 1210
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
1211
            this.ftruncateRet = res.errMsg
W
WOSHIMAHAIFENG 已提交
1212
          },
M
mahaifeng 已提交
1213
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1214 1215 1216 1217
            if (this.logAble) {
              this.log += 'ftruncateFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
1218 1219
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as FTruncateFileOptions)
      },
      ftruncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.ftruncateSync({
W
WOSHIMAHAIFENG 已提交
1234
            fd: this.openFileSyncTest('r+'),
W
WOSHIMAHAIFENG 已提交
1235 1236 1237 1238 1239 1240
            length: 4
          } as FTruncateFileSyncOptions)
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest success:' + '\n\n'
          }
          this.done = true
1241
          this.ftruncateRet = 'ftruncate:ok'
W
WOSHIMAHAIFENG 已提交
1242 1243 1244 1245 1246 1247
        } catch (e) {
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
W
WOSHIMAHAIFENG 已提交
1248 1249
      },
      readZipEntry() {
W
WOSHIMAHAIFENG 已提交
1250 1251 1252 1253 1254 1255 1256 1257 1258
        const fileManager = uni.getFileSystemManager()
        fileManager.readZipEntry({
          filePath: '/static/filemanager/to.zip',
          encoding: 'utf-8',
          success: (res : EntriesResult) => {
            if (this.logAble) {
              this.log += 'readZipEntry success:size=' + res.result.size + '\n\n'
            }
            console.log("success", res)
W
WOSHIMAHAIFENG 已提交
1259
          },
M
mahaifeng 已提交
1260
          fail: (res : IUniError) => {
W
WOSHIMAHAIFENG 已提交
1261 1262 1263 1264
            if (this.logAble) {
              this.log += 'readZipEntry fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
M
mahaifeng 已提交
1265 1266
                        this.lastFailError=new UniError(res.errSubject, res.errCode, res.errMsg)

W
WOSHIMAHAIFENG 已提交
1267
          }
W
WOSHIMAHAIFENG 已提交
1268
        } as ReadZipEntryOptions)
W
WOSHIMAHAIFENG 已提交
1269
      },
W
WOSHIMAHAIFENG 已提交
1270 1271 1272

    },

1273
  }
1274 1275 1276
</script>

<style>
W
WOSHIMAHAIFENG 已提交
1277 1278 1279
  .btnstyle {
    margin: 4px;
  }
1280
</style>