123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <template>
- <view style="margin:12px">
- <page-head title="环境变量 - 文件系统"></page-head>
- <button class="button" type="primary" @tap="getDirInfo(uni.env.USER_DATA_PATH)">USER_DATA_PATH</button>
- <button class="button" type="primary" @tap="getDirInfo(cachePath)">CACHE_PATH</button>
- <button class="button" type="primary" @tap="getDirInfo(sandboxPath)">SANDBOX_PATH</button>
- <!-- #ifdef APP-HARMONY -->
- <button class="button" type="primary" @tap="getDirInfo(tempPath)">TEMP_PATH</button>
- <!-- #endif -->
- <!-- #ifdef APP-ANDROID -->
- <button class="button" type="primary" @tap="getDirInfo(androidInternalSandboxPath)">ANDROID_INTERNAL_SANDBOX_PATH</button>
- <!-- #endif -->
- <boolean-data :defaultValue="false" title="是否递归获取" @change="switchRecursive"></boolean-data>
- </view>
- <scroll-view style="flex: 1; padding: 16px 0px;">
- <text class="result">{{result}}</text>
- <text class="error">{{error}}</text>
- <view class="stat" v-for="(stat,index) in list" :key="index" >
- <text class="path">{{stat.path}}</text>
- <text class="size">{{stat.size}}</text>
- </view>
- </scroll-view>
- </template>
- <script>
- type StatInfo = {
- path : string;
- size : string;
- };
- export default {
- data() {
- return {
- result: '',
- error: '',
- list: [] as Array<StatInfo>,
- recursive: false,
- cachePath: uni.env.CACHE_PATH as string,
- sandboxPath: uni.env.SANDBOX_PATH as string,
- // #ifdef APP-HARMONY
- tempPath: uni.env.TEMP_PATH as string,
- // #endif
- // #ifdef APP-ANDROID
- androidInternalSandboxPath: uni.env.ANDROID_INTERNAL_SANDBOX_PATH as string,
- // #endif
- }
- },
- methods: {
- switchRecursive() {
- this.recursive = !this.recursive
- },
- getDirInfo(dirPath:string) {
- const fm = uni.getFileSystemManager()
- this.list = [];
- fm.stat({
- path: dirPath,
- recursive: this.recursive,
- success: (res: StatSuccessResult) => {
- this.result = `获取 "${dirPath}" 成功(success)`
- console.log(this.result)
- res.stats.forEach((item)=>{
- this.list.push({
- path: item.path,
- size: `${item.stats.size} Bytes`
- })
- })
- },
- fail: (err) => {
- this.result = `获取 "${dirPath}" 失败(fail)`
- console.log(this.result)
- this.error = JSON.stringify(err)
- console.log(this.error)
- }
- })
- }
- }
- }
- </script>
- <style>
- .button {
- margin-bottom: 4px;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .result {
- font-size: 18px;
- font-weight: bold;
- text-align: center;
- width: 100%;
- }
- .error {
- color: firebrick;
- }
- .stat {
- padding: 8px 16px;
- }
- .path {
- color: darkgray;
- }
- .size {
- color: darkgrey;
- }
- </style>
|