Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
333d04b2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6373
Star
108
Fork
184
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
24
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
24
Issue
24
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
333d04b2
编写于
4月 21, 2025
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化环境变量uni.env示例
(cherry picked from commit
cacc1239
)
上级
f57fead5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
86 addition
and
43 deletion
+86
-43
pages/API/env/env.uvue
pages/API/env/env.uvue
+86
-43
未找到文件。
pages/API/env/env.uvue
浏览文件 @
333d04b2
<template>
<!-- #ifdef APP -->
<text>操作日志</text><button size="mini" @click="log=''">清空日志</button>
<text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
<scroll-view style="flex: 1;">
<!-- #endif -->
<!-- #ifdef APP -->
<button class="btnstyle" type="primary" @tap="geAbsPath(sandboxPath)"
id="btn-path">应用外置沙盒目录uni.env.SANDBOX_PATH</button>
<button class="btnstyle" type="primary" @tap="geAbsPath(cachePath)" id="btn-path">缓存文件目录uni.env.CACHE_PATH</button>
<button class="btnstyle" type="primary" @tap="geAbsPath(userPath)"
id="btn-path">用户文件目录uni.env.USER_DATA_PATH</button>
<template>
<view style="margin:12px">
<page-head title="环境变量 - 文件系统"></page-head>
<button class="button" type="primary" @tap="getDirInfo(userDataPath)">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="btnstyle" type="primary" @tap="geAbsPath(tempPath)"
id="btn-path">用户临时目录uni.env.TEMP_PATH</button>
<!-- #endif -->
<!-- #ifdef APP-ANDROID -->
<button class="btnstyle" type="primary" @tap="geAbsPath(internalSandboxPath)"
id="btn-path">应用内置沙盒目录uni.env.ANDROID_INTERNAL_SANDBOX_PATH</button>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef APP -->
<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>
<!-- #endif -->
</template>
<script>
// #ifdef APP-HARMONY
import { convert2AbsFullPath } from '@/uni_modules/uts-get-native-view'
// #endif
type StatInfo = {
path : string;
size : string;
};
export default {
data() {
return {
log: "",
userPath: uni.env.USER_DATA_PATH,
sandboxPath: uni.env.SANDBOX_PATH,
cachePath: uni.env.CACHE_PATH,
return {
result: '',
error: '',
list: [] as Array<StatInfo>,
recursive: false,
userDataPath: uni.env.USER_DATA_PATH as string,
cachePath: uni.env.CACHE_PATH as string,
sandboxPath: uni.env.SANDBOX_PATH as string,
// #ifdef APP-HARMONY
tempPath: uni.env.TEMP_PATH,
tempPath: uni.env.TEMP_PATH as string,
// #endif
// #ifdef APP-ANDROID
androidInternalSandboxPath: uni.env.ANDROID_INTERNAL_SANDBOX_PATH as string,
// #endif
internalSandboxPath: uni.env.ANDROID_INTERNAL_SANDBOX_PATH,
}
},
methods: {
geAbsPath(path ?: any) {
// #ifdef APP-ANDROID
this.log += UTSAndroid.convert2AbsFullPath(path as string) + '\n'
// #endif
// #ifdef APP-HARMONY
this.log += convert2AbsFullPath(path as string) + '\n'
// #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>
.btnstyle {
margin: 4px;
<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>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录