文件上传组件

This commit is contained in:
田岩
2025-06-25 14:19:51 +08:00
parent c8c4e3285a
commit 49e51eabe3
19 changed files with 92 additions and 4 deletions
@@ -8,7 +8,8 @@
android:label="@string/app_name"
android:largeHeap="true"
android:extractNativeLibs="true"
android:supportsRtl="true">
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|keyboard|navigation"
Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 994 KiB

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/launch_screen" />
</LinearLayout>
@@ -6,4 +6,10 @@
<item name="android:windowBackground">@color/ime_background</item>
<item name="android:forceDarkAllowed">false</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/launch_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
+2 -2
View File
@@ -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>
+2 -1
View File
@@ -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>