get-file-system-manager.uvue 46.7 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 64
    <button class="btnstyle" type="primary" @tap="openFileSyncTest"
      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 69 70
    <button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-read-file">同步通过文件描述符写入文件{{readFile}}</button>
    <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 486 487
              console.log(element)
              fileManager.unlink({
                filePath: `${this.basePath}${this.rmDirFile}/${element}`,
488
                success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
489
                  if (this.logAble) {
490 491
                    this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
                  }
492 493
                  console.log('success unlink', res)
                },
494
                fail: (res : UniError) => {
H
hdx 已提交
495
                  if (this.logAble) {
496 497
                    this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
                  }
498 499 500
                  console.log('fail unlink', res)
                  this.lastFailError = res
                },
W
WOSHIMAHAIFENG 已提交
501
                complete: (res : any) => {
502 503 504 505 506 507 508
                  if (res instanceof UniError) {
                    this.lastCompleteError = res
                  }
                  console.log("complete unlink", res)
                  this.done = true
                }
              } as UnLinkOptions)
W
wanganxp 已提交
509
            });
510
          },
W
WOSHIMAHAIFENG 已提交
511
          fail: (res : UniError) => {
W
WOSHIMAHAIFENG 已提交
512 513 514
            if (this.logAble) {
              this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
515
            console.log('fail to readdir', res)
W
wanganxp 已提交
516
            this.lastFailError = res
517
          },
W
WOSHIMAHAIFENG 已提交
518
          complete: (res : any) => {
519
            console.log("complete readdir", res)
W
wanganxp 已提交
520
            this.done = true
521
            if (res instanceof UniError) {
W
wanganxp 已提交
522
              this.lastCompleteError = res
523 524
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
W
wanganxp 已提交
525
            }
526
          }
W
wanganxp 已提交
527 528
        } as ReadDirOptions)
      },
529
      copyStaticToFilesTest: function () {
H
hdx 已提交
530
        const fileManager = uni.getFileSystemManager()
531 532

        fileManager.copyFile({
533
          srcPath: "/static/list-mock/mock.json",
534
          destPath: `${this.copyToBasePath}/a/mock.json`,
W
WOSHIMAHAIFENG 已提交
535
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
536
            if (this.logAble) {
537 538
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
539 540
            console.log('success', res)
          },
541
          fail: (res : UniError) => {
H
hdx 已提交
542
            if (this.logAble) {
543 544
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
545 546 547
            console.log('fail', res)
            this.lastFailError = res
          },
548
          complete: (res : any) => {
549 550 551 552 553 554 555 556
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
557 558 559 560 561 562 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
      //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 已提交
752
            this.done = true
W
WOSHIMAHAIFENG 已提交
753 754 755 756 757
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
758
            console.log('saveFileTest fail', res)
W
WOSHIMAHAIFENG 已提交
759
            this.lastFailError = res
W
WOSHIMAHAIFENG 已提交
760
            this.done = true
W
WOSHIMAHAIFENG 已提交
761
          },
W
WOSHIMAHAIFENG 已提交
762
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
            this.done = true
          }
        } as SaveFileOptions)
      },
      saveFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.saveFileSync(
            `${this.globalTempPath}${this.temFile}`, `${this.basePath}local/`)
          // filePath:`${this.basePath}local/`,)
          this.done = true

          //todo 后面打开
          // this.saveFileRet=res
        } catch (e) {
W
WOSHIMAHAIFENG 已提交
778
          console.log('saveFileSyncTest:' + e)
W
WOSHIMAHAIFENG 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
          this.done = true
        }
      },
      unzipFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()

        fileManager.unzip({
          zipFilePath: `${this.basePath}${this.unzipFile}`,
          targetPath: `${this.basePath}${this.targetZip}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
801
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
802 803 804 805 806 807 808 809 810 811 812 813
            this.done = true
          }
        } as UnzipFileOptions)
      },

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

          },
          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)

      },
      closeTest() {
        const fileManager = uni.getFileSystemManager()
        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
            }
            fileManager.close({
              fd: res.fd,
              success: (res : FileManagerSuccessResult) => {
                if (this.logAble) {
                  this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
                }
                this.closeFileRet = res.errMsg
                console.log("success", res)
              },
              fail: (res : UniError) => {
                if (this.logAble) {
                  this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n'
                }
                console.log('fail', res)
                this.lastFailError = res
              },
W
WOSHIMAHAIFENG 已提交
1076
              complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
                this.done = true
              }

            } as CloseOptions)
          },
          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)
      },
      writeTest() {
        const fileManager = uni.getFileSystemManager()
        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
            }
            fileManager.write({
              fd: res.fd,
              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
              },
              fail: (res : UniError) => {
                if (this.logAble) {
                  this.log += 'writeTest fail:' + JSON.stringify(res) + '\n\n'
                }
                console.log('fail', res)
                this.lastFailError = res
              },
W
WOSHIMAHAIFENG 已提交
1121
              complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
                this.done = true
              }

            } as WriteOptions)
          },
          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)
      },
      writeSyncTest() {
        const fileManager = uni.getFileSystemManager()
        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 已提交
1155
                this.log += 'writeSyncTest success:' + JSON.stringify(ret) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1156 1157 1158 1159 1160 1161
              }
              console.log("success", ret)
              this.done = true
              this.bytesWritten = ret.bytesWritten
            } catch (e) {
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1162
                this.log += 'writeSyncTest fail:' + JSON.stringify(e) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
              }
              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({
          fd: this.openFileSyncTest(),
          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 已提交
1197
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
            this.done = true
          }

        } as FStatOptions)
      },
      fstatSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          let stat =
            fileManager.fstatSync({
              fd: this.openFileSyncTest(),
            } 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({
          fd: this.openFileSyncTest(),
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
1231
            this.ftruncateRet = res.errMsg
W
WOSHIMAHAIFENG 已提交
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
          },
          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({
            fd: this.openFileSyncTest(),
            length: 4
          } as FTruncateFileSyncOptions)
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest success:' + '\n\n'
          }
          this.done = true
W
WOSHIMAHAIFENG 已提交
1260
          this.ftruncateRet = ''
W
WOSHIMAHAIFENG 已提交
1261 1262 1263 1264 1265 1266
        } catch (e) {
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
W
WOSHIMAHAIFENG 已提交
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
      },
      readZipEntry() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readZipEntry({
          filePath: `${this.basePath}${this.readZipFile}`,
          encoding: 'utf-8',
          entries: [{
            path: 'kkkk',
            encoding: 'utf-8'
          } as EntryItem,
          {
            path: 'log/log1.txt',
            encoding: 'utf-8'
          } as EntryItem,
          {
            path: 'hello.txt',
            encoding: 'utf-8'
          } as EntryItem],
          success: (res : EntriesResult) => {
            if (this.logAble) {
              this.log += 'readZipEntry success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'readZipEntry fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          }
        } as ReadZipEntryOptions)
      },
W
WOSHIMAHAIFENG 已提交
1300 1301 1302

    },

1303
  }
1304 1305 1306
</script>

<style>
W
WOSHIMAHAIFENG 已提交
1307 1308 1309
  .btnstyle {
    margin: 4px;
  }
1310
</style>