新增一体机附件上传

This commit is contained in:
2025-12-17 18:10:06 +08:00
parent 8b9f7890af
commit a30a302e90
5 changed files with 1276 additions and 38 deletions

View File

@@ -241,7 +241,7 @@
</view> </view>
</view> </view>
<PopupFeeBack ref="feeback" @onClose="colseFeeBack" @onSend="confirmFeeBack"></PopupFeeBack> <PopupFeeBack ref="feeback" @onClose="colseFeeBack" @onSend="confirmFeeBack"></PopupFeeBack>
<UploadQrcode ref="qrcodeRef"></UploadQrcode> <UploadQrcode ref="qrcodeRef" @onSend="handleFileSend" :sessionId="chatSessionID"></UploadQrcode>
<MsgTips ref="feeBackTips" content="已收到反馈,感谢您的关注" title="反馈成功" :icon="successIcon"></MsgTips> <MsgTips ref="feeBackTips" content="已收到反馈,感谢您的关注" title="反馈成功" :icon="successIcon"></MsgTips>
</view> </view>
</template> </template>
@@ -463,7 +463,14 @@ function getGuess() {
} }
function isImage(type) { function isImage(type) {
return new RegExp('image').test(type); if (!type || typeof type !== 'string') return false;
const imageTypes = [
'jpg', 'jpeg', 'png', 'gif', 'bmp',
'webp', 'svg', 'tiff', 'tif', 'ico',
'apng', 'avif', 'heic', 'heif', 'jfif'
];
const lowerType = type.toLowerCase();
return imageTypes.includes(lowerType);
} }
function isFile(type) { function isFile(type) {
@@ -543,6 +550,31 @@ function getUploadFile(type = 'camera') {
}); });
} }
const handleFileSend = (rows)=>{
filesList.value = []
try {
rows.map(item=>{
if(isImage(item.fileSuffix)){
filesList.value.push({
url: item.fileUrl,
type: item.fileSuffix,
name: item.fileName,
});
}else{
filesList.value.push({
url: item.fileUrl,
type: item.fileSuffix,
name: item.fileName,
});
}
})
textInput.value = state.uploadFileTips;
} catch (error) {
console.log(error)
}
}
const tipsPermisson = () => { const tipsPermisson = () => {
uni.showToast({ uni.showToast({
title: '需要授权麦克风权限才能使用语音功能', title: '需要授权麦克风权限才能使用语音功能',
@@ -604,7 +636,7 @@ function changeVoice() {
} }
function changeShowFile() { function changeShowFile() {
if(isMachineEnv){ if(isMachineEnv.value){
qrcodeRef.value?.open() qrcodeRef.value?.open()
return return
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<image v-if="type === 'application/pdf'" :src="pdfIcon" class="file-icon" /> <image v-if="type === 'application/pdf' || type === 'pdf'" :src="pdfIcon" class="file-icon" />
<image <image
v-else-if=" v-else-if="
type === 'application/msword' || type === 'application/msword' ||
@@ -11,7 +11,9 @@
<image <image
v-else-if=" v-else-if="
type === 'application/vnd.ms-powerpoint' || type === 'application/vnd.ms-powerpoint' ||
type === 'application/vnd.openxmlformats-officedocument.presentationml.presentation' type === 'application/vnd.openxmlformats-officedocument.presentationml.presentation'||
type === 'ppt' ||
type === 'pptx'
" "
:src="pptIcon" :src="pptIcon"
class="file-icon" class="file-icon"
@@ -22,7 +24,9 @@
<image <image
v-else-if=" v-else-if="
type === 'application/vnd.ms-excel' || type === 'application/vnd.ms-excel' ||
type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'||
type === 'xls' ||
type === 'xlsx'
" "
:src="excelIcon" :src="excelIcon"
class="file-icon" class="file-icon"

View File

@@ -23,6 +23,11 @@ const fileAbbreviation = computed(() => {
'text/markdown': 'MD', 'text/markdown': 'MD',
'text/plain': 'TXT', 'text/plain': 'TXT',
'text/html': 'HTML', 'text/html': 'HTML',
'xls': 'XLS',
'xlsx': 'XLSX',
'pdf': 'PDF',
'ppt': 'PPT',
'pptx': 'PPTX',
}; };
return typeMap[props.type] || 'OTHER'; return typeMap[props.type] || 'OTHER';
}); });

View File

@@ -1,62 +1,176 @@
<template> <template>
<uni-popup <uni-popup ref="popup" type="center" borderRadius="12px 12px 0 0" @change="changePopup">
ref="popup"
type="center"
borderRadius="12px 12px 0 0"
@change="changePopup"
background-color="#F6F6F6"
>
<view class="popup-inner"> <view class="popup-inner">
<view class="title">请扫码上传附件</view> <view class="title">请扫码上传附件</view>
<view class="img-box"> <view class="img-box">
<!-- 加载状态 -->
<view v-if="loading" class="loading-container">
<uni-load-more status="loading" :icon-size="24" :content-text="loadingText" />
</view>
<canvas canvas-id="qrcode" id="qrcode" /> <canvas canvas-id="qrcode" id="qrcode" />
</view> </view>
<view class="tips" v-if="!loading"> 已上传 <span class="num">{{fileCount}}</span> 个文件 </view>
<view class="tips" v-if="!loading"> 请使用手机扫描二维码上传文件 </view>
<view class="close-btn" @click="close"></view> <view class="close-btn" @click="close"></view>
</view> </view>
</uni-popup> </uni-popup>
</template> </template>
<script setup> <script setup>
import { ref, inject, onUnmounted, watch, computed } from 'vue';
import uQRCode from '@/static/js/qrcode'; import uQRCode from '@/static/js/qrcode';
import { ref, inject, getCurrentInstance } from 'vue'; import config from '@/config';
import { onShow, onHide } from '@dcloudio/uni-app';
import { UUID } from '../../../lib/uuid-min';
const props = defineProps({
sessionId: {
type: [Number ,String],
default:'',
},
});
const emit = defineEmits(['onSend', 'onClose']); const emit = defineEmits(['onSend', 'onClose']);
const { $api } = inject('globalFunction'); const { $api } = inject('globalFunction');
const instance = getCurrentInstance();
const popup = ref(null); const popup = ref(null);
const loading = ref(false);
const pollingTimer = ref(null);
const isPolling = ref(false);
const isVisible = ref(false);
const uuid = ref(null);
const fileCount = ref(0);
// 计算加载文本
const loadingText = computed(() => ({
contentdown: '二维码生成中',
contentrefresh: '二维码生成中',
}));
onUnmounted(() => {
stopPolling();
clearResources();
});
function open() { function open() {
uuid.value = UUID.generate()
resetState();
isVisible.value = true;
popup.value.open(); popup.value.open();
makeQrcode(); initQrCode();
} }
function close() { function close() {
isVisible.value = false;
stopPolling();
popup.value.close(); popup.value.close();
resetState();
} }
function changePopup(e) { function changePopup(e) {
if (e.show) { if (e.show) {
} else { } else {
stopPolling();
emit('onClose'); emit('onClose');
} }
} }
// 重置所有状态
function resetState() {
loading.value = false;
stopPolling();
}
async function initQrCode() {
try {
loading.value = true;
// 清除之前的二维码
clearCanvas();
await makeQrcode();
// 二维码生成成功后开始轮询
if (isVisible.value) {
startPolling();
}
} catch (error) {
console.error('生成二维码失败:', error);
uni.showToast({
title: '生成二维码失败,请重试',
icon: 'none',
});
close();
} finally {
loading.value = false;
}
}
function makeQrcode() { function makeQrcode() {
const code = '111' const htmlPath = `${window.location.host}/static/upload.html?sessionId=${uuid.value}&uploadApi=${
config.baseUrl + '/app/kiosk/upload'
}`;
// const htmlPath = `${window.location.host}/static/upload.html?sessionId=${props.sessionId}&uploadApi=${
// config.baseUrl + '/app/kiosk/upload'
// }`;
console.log(htmlPath);
return new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
uQRCode.make({ uQRCode.make({
canvasId: 'qrcode', canvasId: 'qrcode',
text: code, text: htmlPath,
size: uni.upx2px(300), size: uni.upx2px(300),
margin: 0, margin: 0,
backgroundColor: '#ffffff', backgroundColor: '#ffffff',
foregroundColor: '#1677ff', foregroundColor: '#1677ff',
fileType: 'png', fileType: 'png',
correctLevel: uQRCode.defaults.correctLevel, correctLevel: uQRCode.defaults.correctLevel,
success: (res) => {
console.log(res,'++');
},
}); });
resolve();
}, 100); }, 100);
});
}
// 清除画布
function clearCanvas() {
const ctx = uni.createCanvasContext('qrcode');
ctx.clearRect(0, 0, uni.upx2px(300), uni.upx2px(300));
ctx.draw();
}
function startPolling() {
if (isPolling.value) return;
isPolling.value = true;
console.log('开始轮询');
// 轮询检查上传状态
const poll = async () => {
if (!isPolling.value || !isVisible.value) return;
const { data } = await $api.createRequest('/app/kiosk/list',{sessionId:uuid.value});
// const { data } = await $api.createRequest('/app/kiosk/list',{sessionId:props.sessionId});
if (data && data.length) {
// 上传完成,触发事件
fileCount.value = data.length
emit('onSend', data);
}
if (isPolling.value && isVisible.value) {
pollingTimer.value = setTimeout(poll, 2000); // 每2秒轮询一次
}
};
poll();
}
function stopPolling() {
isPolling.value = false;
if (pollingTimer.value) {
clearTimeout(pollingTimer.value);
pollingTimer.value = null;
}
console.log('停止轮询');
}
function clearResources() {
stopPolling();
clearCanvas();
} }
defineExpose({ open, close }); defineExpose({ open, close });
@@ -64,34 +178,82 @@ defineExpose({ open, close });
<style lang="scss" scoped> <style lang="scss" scoped>
.popup-inner { .popup-inner {
padding: 30rpx; padding: 40rpx 30rpx;
padding-bottom: 40rpx; padding-bottom: 50rpx;
width: 400rpx; width: 440rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
position: relative;
border-radius: 20rpx;
background: #fafafa;
} }
.title { .title {
font-size: 30rpx; font-size: 32rpx;
color: #333; color: #333;
margin-bottom: 30rpx; margin-bottom: 30rpx;
font-weight: bold; font-weight: bold;
text-align: center;
} }
.img-box { .img-box {
margin: 0 auto; margin: 0 auto 30rpx;
width: 300rpx; width: 300rpx;
height: 300rpx; height: 300rpx;
background-color: #ffffff;
border-radius: 10rpx;
overflow: hidden;
position: relative;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.3);
padding: 20rpx;
canvas { canvas {
width: 100%; width: 100%;
height: 100%; height: 100%;
transition: opacity 0.3s ease;
} }
} }
.loading-container {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: #ffffff;
}
.tips {
font-size: 24rpx;
color: #666;
text-align: center;
line-height: 1.6;
padding: 0 20rpx;
.num{
color: #4191FE;
font-size: 28rpx;
}
}
.close-btn { .close-btn {
position: absolute; position: absolute;
right: 20rpx; right: 20rpx;
top: 20rpx; top: 20rpx;
width: 56rpx; width: 56rpx;
height: 56rpx; height: 56rpx;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background-color 0.2s;
&:active {
background-color: rgba(0, 0, 0, 0.1);
}
&::before { &::before {
position: absolute; position: absolute;
left: 50%; left: 50%;
@@ -103,6 +265,7 @@ defineExpose({ open, close });
background: #5a5a68; background: #5a5a68;
transform: translate(50%, -50%) rotate(-45deg); transform: translate(50%, -50%) rotate(-45deg);
} }
&::after { &::after {
position: absolute; position: absolute;
left: 50%; left: 50%;

1034
static/upload.html Normal file

File diff suppressed because it is too large Load Diff