get-file-system-manager.uvue 45.1 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)
          },
167
          fail: (res : UniError) => {
H
hdx 已提交
168
            if (this.logAble) {
169 170
              this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
171
            console.log('statFileInfoTest fail', res)
杜庆泉's avatar
杜庆泉 已提交
172
            this.lastFailError = res
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
          },
198
          fail: (res : UniError) => {
H
hdx 已提交
199
            if (this.logAble) {
200 201
              this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
202
            console.log('fail', res)
203
            this.lastFailError = res
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)
          },
227
          fail: (res : UniError) => {
H
hdx 已提交
228
            if (this.logAble) {
229 230
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
231
            console.log('fail', res)
232
            this.lastFailError = res
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)
          },
256
          fail: (res : UniError) => {
H
hdx 已提交
257
            if (this.logAble) {
258 259
              this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
260
            console.log('fail', res)
261
            this.lastFailError = res
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
          },
284
          fail: (res : UniError) => {
H
hdx 已提交
285
            if (this.logAble) {
286 287
              this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
            }
288
            console.log('fail', res)
289
            this.lastFailError = res
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)
          },
W
WOSHIMAHAIFENG 已提交
316
          fail: (res : UniError) => {
H
hdx 已提交
317
            if (this.logAble) {
318 319
              this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
320
            console.log('fail')
321
            this.lastFailError = res
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
          },
347
          fail: (res : UniError) => {
H
hdx 已提交
348
            if (this.logAble) {
349 350
              this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
351
            console.log('fail', res)
352
            this.lastFailError = res
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)
          },
375
          fail: (res : UniError) => {
H
hdx 已提交
376
            if (this.logAble) {
377 378
              this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
379
            console.log('fail', res)
380
            this.lastFailError = res
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)
          },
405
          fail: (res : UniError) => {
H
hdx 已提交
406
            if (this.logAble) {
407 408
              this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
409
            console.log('fail', res)
410
            this.lastFailError = res
411
          },
412
          complete: (res : any) => {
413
            if (res instanceof UniError) {
414 415 416
              this.lastCompleteError = res
            }
            this.done = true
417 418 419
            console.log("complete", res)
          }
        } as MkDirOptions)
420

421
      },
422
      accessFileTest: function () {
423
        this.accessFileRet = ''
H
hdx 已提交
424
        const fileManager = uni.getFileSystemManager()
425 426
        fileManager.access({
          path: `${this.basePath}${this.accessFile}`,
427
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
428
            if (this.logAble) {
429 430
              this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
            }
431
            console.log('success', res)
432
            this.accessFileRet = res.errMsg
433
          },
434
          fail: (res : UniError) => {
H
hdx 已提交
435
            if (this.logAble) {
436 437
              this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
438
            console.log('fail', res)
439
            this.lastFailError = res
440
          },
441
          complete: (res : any) => {
442
            if (res instanceof UniError) {
443 444
              this.lastCompleteError = res
            }
445
            console.log("complete", res)
446
            this.done = true
447 448
          }
        } as AccessOptions)
449

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

        fileManager.unlink({
          filePath: `${this.basePath}${this.unlinkFile}`,
456
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
457
            if (this.logAble) {
458 459
              this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
            }
460 461
            console.log('success', res)
          },
462
          fail: (res : UniError) => {
H
hdx 已提交
463
            if (this.logAble) {
464 465
              this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
            }
466
            console.log('fail', res)
467
            this.lastFailError = res
468
          },
469
          complete: (res : any) => {
470
            if (res instanceof UniError) {
471 472
              this.lastCompleteError = res
            }
473
            console.log("complete", res)
474
            this.done = true
475 476 477
          }
        } as UnLinkOptions)
      },
478
      unlinkAllFileTest: function () {
H
hdx 已提交
479
        const fileManager = uni.getFileSystemManager()
W
wanganxp 已提交
480
        fileManager.readdir({
481
          dirPath: `${this.basePath}${this.rmDirFile}`,
482
          success: (res : ReadDirSuccessResult) => {
483
            console.log("success to readdir", res)
W
wanganxp 已提交
484
            res.files.forEach(element => {
485
              console.log(element)
W
WOSHIMAHAIFENG 已提交
486
              let filePath : string
W
WOSHIMAHAIFENG 已提交
487 488 489 490 491
              if (this.rmDirFile.length <= 0) {
                filePath = `${this.basePath}${element}`
              } else {
                filePath = `${this.basePath}${this.rmDirFile}/${element}`
              }
492
              fileManager.unlink({
W
WOSHIMAHAIFENG 已提交
493
                filePath: filePath,
494
                success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
495
                  if (this.logAble) {
496 497
                    this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
                  }
498 499
                  console.log('success unlink', res)
                },
500
                fail: (res : UniError) => {
H
hdx 已提交
501
                  if (this.logAble) {
502 503
                    this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
                  }
504 505 506
                  console.log('fail unlink', res)
                  this.lastFailError = res
                },
W
WOSHIMAHAIFENG 已提交
507
                complete: (res : any) => {
508 509 510 511 512 513 514
                  if (res instanceof UniError) {
                    this.lastCompleteError = res
                  }
                  console.log("complete unlink", res)
                  this.done = true
                }
              } as UnLinkOptions)
W
wanganxp 已提交
515
            });
516
          },
W
WOSHIMAHAIFENG 已提交
517
          fail: (res : UniError) => {
W
WOSHIMAHAIFENG 已提交
518 519 520
            if (this.logAble) {
              this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
521
            console.log('fail to readdir', res)
W
wanganxp 已提交
522
            this.lastFailError = res
523
          },
W
WOSHIMAHAIFENG 已提交
524
          complete: (res : any) => {
525
            console.log("complete readdir", res)
W
wanganxp 已提交
526
            this.done = true
527
            if (res instanceof UniError) {
W
wanganxp 已提交
528
              this.lastCompleteError = res
529 530
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
W
wanganxp 已提交
531
            }
532
          }
W
wanganxp 已提交
533 534
        } as ReadDirOptions)
      },
535
      copyStaticToFilesTest: function () {
H
hdx 已提交
536
        const fileManager = uni.getFileSystemManager()
537 538

        fileManager.copyFile({
539
          srcPath: "/static/list-mock/mock.json",
540
          destPath: `${this.copyToBasePath}/a/mock.json`,
W
WOSHIMAHAIFENG 已提交
541
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
542
            if (this.logAble) {
543 544
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
545 546
            console.log('success', res)
          },
547
          fail: (res : UniError) => {
H
hdx 已提交
548
            if (this.logAble) {
549 550
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
551 552 553
            console.log('fail', res)
            this.lastFailError = res
          },
554
          complete: (res : any) => {
555 556 557 558 559 560 561 562
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 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
      //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)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'appendFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail')
            this.lastFailError = res
          },
          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 已提交
758
            this.done = true
W
WOSHIMAHAIFENG 已提交
759 760 761 762 763
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
764
            console.log('saveFileTest fail', res)
W
WOSHIMAHAIFENG 已提交
765
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
766
            this.done = true
W
WOSHIMAHAIFENG 已提交
767
          },
W
WOSHIMAHAIFENG 已提交
768
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
769 770 771 772 773 774 775 776
            this.done = true
          }
        } as SaveFileOptions)
      },
      saveFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.saveFileSync(
W
WOSHIMAHAIFENG 已提交
777
            `${this.globalTempPath}${this.temFile}`, `${this.basePath}/`)
W
WOSHIMAHAIFENG 已提交
778 779 780 781 782 783
          // filePath:`${this.basePath}local/`,)
          this.done = true

          //todo 后面打开
          // this.saveFileRet=res
        } catch (e) {
W
WOSHIMAHAIFENG 已提交
784
          console.log('saveFileSyncTest:' + e)
W
WOSHIMAHAIFENG 已提交
785 786 787 788
          this.done = true
        }
      },
      unzipFileTest: function (_ : any) {
W
WOSHIMAHAIFENG 已提交
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
        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)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'unzipFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
810
          },
W
WOSHIMAHAIFENG 已提交
811 812
          complete: (_) => {
            this.done = true
W
WOSHIMAHAIFENG 已提交
813
          }
W
WOSHIMAHAIFENG 已提交
814
        } as UnzipFileOptions)
W
WOSHIMAHAIFENG 已提交
815 816 817 818 819 820 821 822 823
      },

      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 已提交
824
            console.log("getSavedFileListTest success", res)
W
WOSHIMAHAIFENG 已提交
825
            this.fileListSuccess = res.fileList
826
            this.getSavedFileListRet = "getSavedFileList:ok"
W
WOSHIMAHAIFENG 已提交
827 828 829 830 831
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
832
            console.log('getSavedFileListTest fail', res)
W
WOSHIMAHAIFENG 已提交
833
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
834
            this.getSavedFileListRet = JSON.stringify(res)
W
WOSHIMAHAIFENG 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
          },
          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 已提交
854
              this.log += 'truncateFileTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
855 856 857 858 859
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
860
              this.log += 'truncateFileTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
            }
            console.log('fail', res)
            this.lastFailError = res
          },
          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 已提交
889
          filePath: '/static/filemanager/1.txt.br',
W
WOSHIMAHAIFENG 已提交
890 891 892 893 894 895 896 897 898 899 900 901 902 903
          compressionAlgorithm: "br",
          success: (res : ReadCompressedFileResult) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
904
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
905 906 907 908 909 910 911 912 913
            this.done = true
          }
        } as ReadCompressedFileOptions)
      },
      readCompressedFileSyncTest() {
        console.log('readCompressedFileSyncTest')
        const fileManager = uni.getFileSystemManager()
        try {
          let data = fileManager.readCompressedFileSync(
W
WOSHIMAHAIFENG 已提交
914
            '/static/filemanager/1.txt.br',
W
WOSHIMAHAIFENG 已提交
915 916 917 918 919 920 921
            "br")
          if (this.logAble) {
            this.log += data
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
922
            this.log += 'readCompressedFileSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
          }
          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 已提交
938
            console.log("removeSavedFileTest success", res)
W
WOSHIMAHAIFENG 已提交
939 940 941 942 943
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
944
            console.log('removeSavedFileTest fail', res)
W
WOSHIMAHAIFENG 已提交
945
          },
W
WOSHIMAHAIFENG 已提交
946
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
947 948 949 950 951 952 953 954 955 956 957 958 959
            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 已提交
960
            this.log += 'statFileInfoSyncTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
961 962 963 964 965
          }
          this.statsRet = res
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
966
            this.log += 'statFileInfoSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
          }
          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
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
991
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
992 993 994 995
            this.done = true
          }
        } as OpenFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
996
      openFileSyncTest(param : string) : string {
W
WOSHIMAHAIFENG 已提交
997 998 999 1000
        const fileManager = uni.getFileSystemManager()
        try {
          let fd = fileManager.openSync({
            filePath: `${this.basePath}${this.readFile}`,
W
WOSHIMAHAIFENG 已提交
1001
            flag: param,
W
WOSHIMAHAIFENG 已提交
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
          } 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()
1021 1022 1023
        try {
          console.log('closeSync')
          fileManager.closeSync({
W
WOSHIMAHAIFENG 已提交
1024
            fd: this.openFileSyncTest('r')
1025 1026 1027
          } as CloseSyncOptions)
          if (this.logAble) {
            this.log += 'closeSyncTest success:' + '\n\n'
W
WOSHIMAHAIFENG 已提交
1028
          }
1029 1030 1031 1032 1033 1034 1035 1036 1037
          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 已提交
1038 1039 1040
      },
      closeTest() {
        const fileManager = uni.getFileSystemManager()
1041
        fileManager.close({
W
WOSHIMAHAIFENG 已提交
1042
          fd: this.openFileSyncTest('r'),
1043 1044 1045
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1046
            }
1047 1048
            this.closeFileRet = res.errMsg
            console.log("success", res)
W
WOSHIMAHAIFENG 已提交
1049 1050 1051
          },
          fail: (res : UniError) => {
            if (this.logAble) {
1052
              this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1053 1054 1055
            }
            console.log('fail', res)
            this.lastFailError = res
1056 1057
          },
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1058 1059
            this.done = true
          }
1060 1061

        } as CloseOptions)
W
WOSHIMAHAIFENG 已提交
1062 1063 1064
      },
      writeTest() {
        const fileManager = uni.getFileSystemManager()
W
WOSHIMAHAIFENG 已提交
1065 1066 1067 1068 1069
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }
W
WOSHIMAHAIFENG 已提交
1070

W
WOSHIMAHAIFENG 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
        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 已提交
1081 1082 1083
          },
          fail: (res : UniError) => {
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1084
              this.log += 'writeTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1085 1086 1087
            }
            console.log('fail', res)
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
1088 1089
          },
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1090 1091
            this.done = true
          }
W
WOSHIMAHAIFENG 已提交
1092 1093

        } as WriteOptions)
W
WOSHIMAHAIFENG 已提交
1094 1095 1096
      },
      writeSyncTest() {
        const fileManager = uni.getFileSystemManager()
W
WOSHIMAHAIFENG 已提交
1097 1098 1099 1100 1101
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }
W
WOSHIMAHAIFENG 已提交
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
        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 已提交
1118
                this.log += 'writeSyncTest success:' + JSON.stringify(ret) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1119 1120 1121 1122 1123 1124
              }
              console.log("success", ret)
              this.done = true
              this.bytesWritten = ret.bytesWritten
            } catch (e) {
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1125
                this.log += 'writeSyncTest fail:' + JSON.stringify(e) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
              }
              console.log('fail', e)
              this.done = true
            }
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
            this.done = true
          }
        } as OpenFileOptions)

      },
      fstatTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.fstat({
W
WOSHIMAHAIFENG 已提交
1145
          fd: this.openFileSyncTest('r'),
W
WOSHIMAHAIFENG 已提交
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
          success: (res : FStatSuccessResult) => {
            if (this.logAble) {
              this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fstat = res.stats
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'fstatTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
1160
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
            this.done = true
          }

        } as FStatOptions)
      },
      fstatSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          let stat =
            fileManager.fstatSync({
W
WOSHIMAHAIFENG 已提交
1171
              fd: this.openFileSyncTest('r'),
W
WOSHIMAHAIFENG 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
            } 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 已提交
1188
          fd: this.openFileSyncTest('r+'),
W
WOSHIMAHAIFENG 已提交
1189 1190 1191 1192 1193
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
1194
            this.ftruncateRet = res.errMsg
W
WOSHIMAHAIFENG 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
          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 已提交
1216
            fd: this.openFileSyncTest('r+'),
W
WOSHIMAHAIFENG 已提交
1217 1218 1219 1220 1221 1222
            length: 4
          } as FTruncateFileSyncOptions)
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest success:' + '\n\n'
          }
          this.done = true
1223
          this.ftruncateRet = 'ftruncate:ok'
W
WOSHIMAHAIFENG 已提交
1224 1225 1226 1227 1228 1229
        } catch (e) {
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
W
WOSHIMAHAIFENG 已提交
1230 1231
      },
      readZipEntry() {
W
WOSHIMAHAIFENG 已提交
1232 1233 1234 1235 1236 1237 1238 1239 1240
        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 已提交
1241
          },
W
WOSHIMAHAIFENG 已提交
1242 1243 1244 1245 1246 1247
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'readZipEntry fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
1248
          }
W
WOSHIMAHAIFENG 已提交
1249
        } as ReadZipEntryOptions)
W
WOSHIMAHAIFENG 已提交
1250
      },
W
WOSHIMAHAIFENG 已提交
1251 1252 1253

    },

1254
  }
1255 1256 1257
</script>

<style>
W
WOSHIMAHAIFENG 已提交
1258 1259 1260
  .btnstyle {
    margin: 4px;
  }
1261
</style>