feat(文件上传): 添加上传组件功能及样式优化

- 新增上传图标资源文件
- 在utils中添加生成唯一标识符方法
- 重构GatePassInfo组件文件上传功能,支持图片和PDF格式
- 优化BasicsInfo和GatePassInfo组件滚动行为
- 添加上传文件大小和类型校验
- 完善文件列表展示和删除功能
This commit is contained in:
liangbin 2026-01-16 16:59:47 +08:00
parent 7880cb1051
commit c239c25fa4
4 changed files with 125 additions and 8 deletions

View File

@ -319,7 +319,7 @@ const initTiandituMap = () => {
padding: 20rpx; padding: 20rpx;
background-color: #fff; background-color: #fff;
height: 100%; height: 100%;
overflow: hidden; overflow: auto;
} }
.mustBox::after { .mustBox::after {

View File

@ -59,16 +59,34 @@
<view class="FormItem"> <view class="FormItem">
<view class="FormLableBox">附件上传</view> <view class="FormLableBox">附件上传</view>
<view class="FormValueBox"> <view class="FormValueBox">
<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple <up-upload width="100%" @afterRead="afterRead" multiple accept="image/*,application/pdf">
:maxCount="10"></up-upload> <view class="UploadBox">
<view class="UpIcon">
<img src="@/static/icon/upload-icon.png" alt="">
</view>
<view class="UpTitle">点击上传</view>
<view class="UpDesc">支持JPG,PNG,PDF格式上传单个文件大小不超过10MB</view>
</view>
</up-upload>
</view>
<view class="UpFileListBox">
<view v-for="item in fileList1" :key="item.url" class="UpFileItem">
<view>
<view class="UpFileName">{{ item.name }}</view>
<view class="UpFileSize">{{ item.size }}</view>
</view>
<u-button text="删除" type="primary" size="small" @click="deletePic(item.fid)"></u-button>
</view>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script setup> <script setup>
import { generateGuid } from '@/utils/index.js';
import dayjs from "dayjs"; import dayjs from "dayjs";
import { ref, computed, onMounted, defineExpose } from "vue"; import { ref, defineExpose } from "vue";
const props = defineProps({ const props = defineProps({
allData: { allData: {
@ -95,9 +113,7 @@ const CarArr = ref([
type: '轿车', type: '轿车',
code: '京B123456', code: '京B123456',
}, },
]); // ]);
// //
const formData = ref({ const formData = ref({
@ -105,6 +121,46 @@ const formData = ref({
CarList: [], // CarList: [], //
}) })
const fileList1 = ref([]); //
//
const afterRead = (e) => {
console.log('上传的文件:', e);
let fileInfo = e.file[0];
//
if (fileInfo.size > 10 * 1024 * 1024) {
uni.showToast({
title: '文件大小不能超过10MB',
icon: 'none'
});
return;
}
//
if (!fileInfo.name.match(/\.(jpg|png|pdf)$/i)) {
uni.showToast({
title: '请上传JPG,PNG,PDF格式的文件',
icon: 'none'
});
return;
}
let arr = [...fileList1.value];
arr.push({
fid: generateGuid(),
name: fileInfo.name,
size: (fileInfo.size / 1024 / 1024).toFixed(2) + 'MB',
url: fileInfo.url,
});
fileList1.value = arr;
}
//
const deletePic = (fid) => {
console.log('删除文件:', fid);
let arr = [...fileList1.value];
arr = arr.filter(item => item.fid !== fid);
fileList1.value = arr;
}
// //
defineExpose({ defineExpose({
@ -113,6 +169,8 @@ defineExpose({
} }
}) })
// //
const HandleValidTimeConfirm = (e) => { const HandleValidTimeConfirm = (e) => {
const selectedDate = (e.value && dayjs(e.value).isValid()) ? e.value : minTimestamp.value; const selectedDate = (e.value && dayjs(e.value).isValid()) ? e.value : minTimestamp.value;
@ -183,6 +241,53 @@ const HandleDeleteCar = (carId) => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.UploadBox {
width: 100%;
height: 300rpx;
margin: 0 auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20rpx;
padding: 20rpx;
border: 1rpx dashed #e4e7ed;
border-radius: 10rpx;
.UpTitle {
font-size: 30rpx;
font-weight: bold;
color: #333;
}
.UpDesc {
font-size: 24rpx;
color: #666;
}
}
.UpFileListBox {
margin-top: 20rpx;
height: auto;
.UpFileItem {
border: 1rpx solid #e4e7ed;
padding: 20rpx;
border-radius: 10rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
.UpFileName {
font-size: 30rpx;
font-weight: bold;
color: #333;
}
.UpFileSize {
font-size: 24rpx;
color: #666;
}
}
}
.FlexBox { .FlexBox {
display: flex; display: flex;
align-items: center; align-items: center;
@ -200,7 +305,7 @@ const HandleDeleteCar = (carId) => {
padding: 20rpx; padding: 20rpx;
background-color: #fff; background-color: #fff;
height: 100%; height: 100%;
overflow: hidden; overflow: auto;
} }
.mustBox::after { .mustBox::after {

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

View File

@ -1,3 +1,15 @@
export * from './storage' export * from './storage'
export * from './validate' export * from './validate'
export * from './format' export * from './format'
// 生成指定长度的唯一标识符
export function generateGuid(length = 8) {
let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
let guid = '';
for (let i = 0; i < length; i++) {
let randomIndex = Math.floor(Math.random() * arr.length);
guid += arr[randomIndex];
}
return guid;
}