| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <template>
- <view class="order-file-upload">
- <view class="upload-section">
- <view class="upload-title">
- <text class="title-text">{{ title }}</text>
- <text class="upload-btn" @click="handleUpload">上传文件</text>
- </view>
- <view class="file-list" v-if="fileList.length > 0">
- <view class="file-item" v-for="(item, index) in fileList" :key="index">
- <pictureViewer @delete="handleDelete(index)" :src="item.fileUrl" @needPreviewPic="needPreviewPic">
- </pictureViewer>
- <view class="file-actions">
- <!-- <text class="delete-btn" @click="handleDelete(index)">x</text> -->
- </view>
- </view>
- </view>
- <view class="upload-tip" v-else>
- <text class="tip-text">{{ tipText }}</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import upload from '../../mixins/upload';
- import pictureViewer from '../picture-viewer/picture-viewer.vue'
- export default {
- name: 'OrderFileUpload',
- mixins: [upload],
- components: {
- pictureViewer
- },
- props: {
- title: {
- type: String,
- default: '文件上传'
- },
- orderFileType: {
- type: String,
- required: true
- },
- fileList: {
- type: Array,
- default: () => []
- },
- tipText: {
- type: String,
- default: '点击上传文件'
- },
- fileType: {
- type: String,
- default: 'all',
- desc: '文件选择类型:all(所有)、image(图片)、video(视频)、audio(音频)、document(文档)等'
- },
- },
- data() {
- return {
- }
- },
- watch: {
- fileList: {
- handler(newVal) {
- this.uploadList = [...newVal];
- },
- immediate: true
- }
- },
- methods: {
- handleUploadSuccess() {
- uni.$u.toast("上传成功");
- },
- // 删除文件
- handleDelete(index) {
- uni.showModal({
- title: '提示',
- content: '确定要删除该文件吗?',
- success: (res) => {
- if (res.confirm) {
- this.uploadList.splice(index, 1);
- this.$emit('update:fileList', this.uploadList);
- this.$emit('change', {
- type: this.orderFileType,
- fileList: this.uploadList
- });
- }
- }
- });
- },
- needPreviewPic(url) {
- uni.previewImage({
- urls: this.fileList.map(item => item.fileUrl),
- current: url
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .order-file-upload {
- .upload-section {
- background: #fff;
- margin-bottom: 20rpx;
- border-radius: 16rpx;
- overflow: hidden;
- }
- .upload-title {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx 40rpx;
- border-bottom: 1rpx solid #f5f5f5;
- .title-text {
- font-size: 32rpx;
- font-weight: 500;
- color: #333;
- }
- .upload-btn {
- padding: 12rpx 24rpx;
- background: #007aff;
- color: #fff;
- border-radius: 8rpx;
- font-size: 28rpx;
- }
- }
- .file-list {
- padding: 20rpx 20rpx;
- display: grid;
- //一行三个
- grid-template-columns: repeat(3, 1fr);
- gap: 20rpx;
- }
- .file-item {
- padding: 0rpx 0;
- &:last-child {
- border-bottom: none;
- }
- }
- .file-info {
- flex: 1;
- min-width: 0; // 防止flex子元素溢出
- .file-name {
- display: block;
- font-size: 30rpx;
- color: #333;
- margin-bottom: 8rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- max-width: 400rpx; // 设置最大宽度防止过长
- }
- .file-size {
- font-size: 26rpx;
- color: #999;
- }
- }
- .file-actions {
- .delete-btn {
- padding: 12rpx 24rpx;
- background: #ff4757;
- color: #fff;
- border-radius: 8rpx;
- font-size: 26rpx;
- }
- }
- .upload-tip {
- padding: 40rpx;
- text-align: center;
- .tip-text {
- font-size: 28rpx;
- color: #999;
- }
- }
- }
- </style>
|