flat: bug修复2

This commit is contained in:
Apcallover
2025-12-17 21:12:26 +08:00
parent a10fd29440
commit 606b6104bb
3 changed files with 198 additions and 188 deletions

View File

@@ -1,6 +1,6 @@
export default { export default {
baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网 // baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网
// baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试 baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试
// baseUrl: 'http://192.168.3.29:8081', // baseUrl: 'http://192.168.3.29:8081',
// baseUrl: 'http://10.213.6.207:19010/api', // baseUrl: 'http://10.213.6.207:19010/api',
// 语音转文字 // 语音转文字

View File

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

View File

@@ -39,6 +39,7 @@ const useLocationStore = defineStore("location", () => {
type: 'gcj02', type: 'gcj02',
highAccuracyExpireTime: 3000, highAccuracyExpireTime: 3000,
isHighAccuracy: true, isHighAccuracy: true,
timeout: 2000,
success: function(data) { success: function(data) {
longitudeVal.value = Number(data.longitude) longitudeVal.value = Number(data.longitude)
latitudeVal.value = Number(data.latitude) latitudeVal.value = Number(data.latitude)