文件上传组件
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@ import {
|
||||
|
||||
|
||||
export const uploadFile = (file, data) => {
|
||||
const url = '/plimg/fileUpload/stuMgrUploadImg';
|
||||
const url = '/traoss/tras3/upload';
|
||||
const base_url = get_base_url(url);
|
||||
const token = getToken();
|
||||
const header = {};
|
||||
@@ -16,7 +16,7 @@ export const uploadFile = (file, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${base_url}${url}`,
|
||||
header: header,
|
||||
header: header,
|
||||
filePath: file,
|
||||
name: 'file',
|
||||
formData: data,
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<template>
|
||||
<view class="components_custom_file_upload_div pic-cell">
|
||||
<view v-for="(item,index) in fileList">
|
||||
<image-preview :imgId="item.fileId"></image-preview>
|
||||
</view>
|
||||
<view @tap="upload">
|
||||
<view class="img-width-height add_icon wh_100">+</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, defineProps, defineEmits, onMounted } from 'vue'
|
||||
import common from '@/common/common'
|
||||
|
||||
import { uploadFile } from '@/api/common'
|
||||
|
||||
// 定义props
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
limit: {
|
||||
type: Number,
|
||||
default: 9
|
||||
},
|
||||
mark: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
|
||||
// 定义emits
|
||||
const emits = defineEmits(['upload_success'])
|
||||
|
||||
// 状态管理
|
||||
const fileList = ref([])
|
||||
|
||||
// 生命周期钩子
|
||||
onMounted(() => {
|
||||
// 初始化逻辑
|
||||
})
|
||||
|
||||
// 方法
|
||||
const upload = () => {
|
||||
uni.chooseImage({
|
||||
count: props.limit,
|
||||
sizeType: ['original', 'compressed'],
|
||||
sourceType: ['camera', 'album'],
|
||||
success: async ({ tempFilePaths }) => {
|
||||
for (const file of tempFilePaths) {
|
||||
try {
|
||||
// 修正:data变量未定义问题
|
||||
const data = { bizScen: 'S3005' }
|
||||
const res = await uploadFile(file, data)
|
||||
console.log('res', res);
|
||||
fileList.value.push(res)
|
||||
} catch (error) {
|
||||
console.error('文件上传失败', error)
|
||||
}
|
||||
}
|
||||
// emits('upload_success', fileList.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -11,7 +11,8 @@
|
||||
<view class="body-content">
|
||||
<view class="picture">
|
||||
<view class="pic-item" v-for="item in 4" :key="item">
|
||||
<image class="w_100" src="/src/static/images/test/touxiang.png" mode="widthFix"></image>
|
||||
<!-- <image class="w_100" src="/src/static/images/test/touxiang.png" mode="widthFix"></image> -->
|
||||
<picture-upload></picture-upload>
|
||||
</view>
|
||||
</view>
|
||||
<view class="tips font_pf">最多可添加4张图片</view>
|
||||
|
||||
Reference in New Issue
Block a user