提交 b2d5f6b6 编写于 作者: 小刘28's avatar 小刘28 💬

per:优化计算文件大小功能;

上级 70b963f5
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
</view>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title" @click="choose()">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
}
}
export default {
data() {
return {
title: 'Hello'
}
},
onShow() {
},
methods: {
choose(){
uni.chooseFile({
count: 10,
type: 'image',
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFiles
console.log(tempFilePaths);
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
......@@ -9,7 +9,7 @@
export default {
/**
* @Description 获取文件后缀名
* @Date 2022年5月9日08:40:16
* @Date 2022年7月17日11:52:41
* @Param {String} fileURL 文件地址
* @Return {String} 文件后缀名
**/
......@@ -20,5 +20,39 @@ export default {
}
let ext = fileURL.substr(index + 1);
return ext.toLocaleLowerCase();
},
/**
* @Description 获取文件大小
* @Date 2022年7月17日11:52:45
* @Param {Number} fileSize 文件大小
* @Param {String} unit 文件大小计算模式
* @Return {String} 文件后缀名
**/
getFileSize(fileSize = 0,unit = 'B') {
let size = 0;
switch (unit){
case 'b':
size = fileSize*1024;
break;
case 'B':
size = fileSize;
break;
case 'KB':
size = fileSize/1024;
break;
case 'MB':
size = fileSize/1024/1024;
break;
case 'GB':
size = fileSize/1024/1024/1024;
break;
case 'TB':
size = fileSize/1024/1024/1024/1024;
break;
default:
size = fileSize;
break;
}
return size;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册