信管1171 02 曾燃亮
今天学习了对背景图片的自适应每个手机的宽和高、在背景图片上添加用户的头像和名称、对地图添加细节、获取用户的权限。对于今天的内容已经大概掌握了,并在作业种进行了实践。
1.FieldSystemManager wx.getFileSystemManager()
获取全局唯一的文件管理器
返回值
FieldSystemManager
文件管理器
2.wx.getFileInfo(Object object)
获取文件信息
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
filePath | string | 是 | 本地文件路径 | |
digestAlgorithm | string | 'md5' | 否 | 计算文件摘要的算法 |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.digestAlgorithm 的合法值
值 | 说明 | 最低版本 |
---|---|---|
md5 | md5 算法 | |
sha1 | sha1 算法 |
object.success 回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
size | number | 文件大小,以字节为单位 |
digest | string | 按照传入的 digestAlgorithm 计算得出的的文件摘要 |
3.FileSystemManager.access(Object object)
判断文件/目录是否存在
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
path | string | 是 | 要判断是否存在的文件/目录路径 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.fail 回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
errMsg | string | 错误信息 |
res.errMsg 的合法值
值 | 说明 | 最低版本 |
---|---|---|
fail no such file or directory ${path} | 文件/目录不存在 |
4.作业
js
Page({
data: {
mobileModel: '',
windowWidth: '',
windowHeight: '',
screenWidth: '',
screenHeight: '',
system: '',
userInfo: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
mobileModel: res.model,
windowWidth: res.windowWidth,
windowHeight: res.windowHeight,
screenWidth: res.screenWidth,
screenHeight: res.screenHeight,
system: res.system
})
}
})
},
wxml
<view class='bg'>
<view class="userinfo">
<open-data type="userAvatarUrl"></open-data>
</view>
<view class="nickname">
<open-data type="userNickName"></open-data>
</view>
</view>
<view class="container1">
<view>手机型号:{{mobileModel}}</view>
<view>窗口宽度:{{windowWidth}}</view>
<view>窗口高度:{{windowHeight}}</view>
<view>可使用窗口宽度:{{screenWidth}}</view>
<view>可使用窗口高度:{{screenHeight}}</view>
<view>手机系统:{{system}}</view>
</view>
wxss
.container0-1{
height: 20%;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
align-content: center;
}
.nickname {
color: #aaa;
display: flex;
justify-content: center;
align-items: flex-end;
}
.container1 {
display: flex; /**指定flex 布局*/
flex-direction:column; /**主轴 方向*/
}
.container1>view{
width:100%; /**宽度*/
height:75rpx; /**高度指定*/
background-color: whitesmoke;
text-align: center; /**文字居中*/
line-height: 100rpx; /**文字居中*/
}
.userinfo{
width: 150rpx;
height:150rpx;
border-radius:50%;
display: flex;
overflow: hidden;
justify-content: center;
}
.usericon{
height:200rpx;
width:200rpx;
border-radius:50%;
}
.bg{
width:100%;
height:350rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background:url('') no-repeat 0 0;
background-size: 100% 100%;
}