fix headers
This commit is contained in:
2025-10-24 19:49:50 +08:00
parent 009d21e42d
commit bfd65d8b82

View File

@@ -10,8 +10,11 @@
<div v-if="validated && !uploading" class="fab-select"> <div v-if="validated && !uploading" class="fab-select">
<button @click="autoOpenFileInput" class="select-trigger" aria-label="Select Photos">Add</button> <button @click="autoOpenFileInput" class="select-trigger" aria-label="Select Photos">Add</button>
</div> </div>
<input type="file" @change="onFileChange" multiple accept="image/*,.png,.jpg,.jpeg,.gif,.bmp,.webp,.heic,.heif,.tif,.tiff" ref="fileInput" style="display: none" /> <input type="file" @change="onFileChange" multiple
<p class="status note" v-if="nonPreviewCount > 0">Selected {{ nonPreviewCount }} images are not previewable (still uploadable).</p> accept="image/*,.png,.jpg,.jpeg,.gif,.bmp,.webp,.heic,.heif,.tif,.tiff" ref="fileInput"
style="display: none"/>
<p class="status note" v-if="nonPreviewCount > 0">Selected {{ nonPreviewCount }} images are not previewable (still
uploadable).</p>
<div v-if="loading" class="screen-mask" role="status" aria-live="polite"> <div v-if="loading" class="screen-mask" role="status" aria-live="polite">
<div class="mask-content">Loading...</div> <div class="mask-content">Loading...</div>
</div> </div>
@@ -20,7 +23,7 @@
</div> </div>
<div class="masonry" v-if="images.length"> <div class="masonry" v-if="images.length">
<div v-for="(image, index) in images" :key="index" class="masonry-item"> <div v-for="(image, index) in images" :key="index" class="masonry-item">
<img :src="image" /> <img :src="image"/>
</div> </div>
</div> </div>
</div> </div>
@@ -52,36 +55,36 @@ export default {
}; };
}, },
mounted() { mounted() {
const { code, machine, store } = this.$route.query || {}; const {code, machine, store} = this.$route.query || {};
this.validateParams({ code, machine, store }) this.validateParams({code, machine, store})
.then((ok) => { .then((ok) => {
if (ok) { if (ok) {
this.validated = true; this.validated = true;
this.validating = false; this.validating = false;
// 验证通过后自动弹出文件选择框 // 验证通过后自动弹出文件选择框
this.$nextTick(() => { this.$nextTick(() => {
setTimeout(() => { setTimeout(() => {
this.autoOpenFileInput(); this.autoOpenFileInput();
}, 0); }, 0);
}); });
} else { } else {
this.validationError = true;
this.validating = false;
// 验证未通过,返回上一页
this.$router.back();
}
})
.catch(() => {
this.validationError = true; this.validationError = true;
this.validating = false; this.validating = false;
// 验证未通过,返回上一页 // 异常情况下也返回上一页
this.$router.back(); this.$router.back();
} });
})
.catch(() => {
this.validationError = true;
this.validating = false;
// 异常情况下也返回上一页
this.$router.back();
});
}, },
methods: { methods: {
validateParams({ code, machine, store }) { validateParams({code, machine, store}) {
const ok = [code, machine, store].every( const ok = [code, machine, store].every(
(v) => typeof v === 'string' && v.trim() !== '' (v) => typeof v === 'string' && v.trim() !== ''
); );
return Promise.resolve(ok); return Promise.resolve(ok);
}, },
@@ -96,7 +99,7 @@ export default {
}, },
onFileChange(e) { onFileChange(e) {
const incoming = Array.from(e.target.files || []); const incoming = Array.from(e.target.files || []);
const allowedExts = ['.png','.jpg','.jpeg','.gif','.bmp','.webp','.heic','.heif','.tif','.tiff']; const allowedExts = ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.heic', '.heif', '.tif', '.tiff'];
const isAllowed = (f) => { const isAllowed = (f) => {
const type = (f.type || '').toLowerCase(); const type = (f.type || '').toLowerCase();
const name = (f.name || '').toLowerCase(); const name = (f.name || '').toLowerCase();
@@ -112,7 +115,7 @@ export default {
this.nonPreviewCount = 0; this.nonPreviewCount = 0;
// 预览仅针对常见可在浏览器直接显示的格式 // 预览仅针对常见可在浏览器直接显示的格式
const previewableExts = ['.png','.jpg','.jpeg','.gif','.bmp','.webp']; const previewableExts = ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'];
const previewableFiles = allowedFiles.filter((f) => { const previewableFiles = allowedFiles.filter((f) => {
const type = (f.type || '').toLowerCase(); const type = (f.type || '').toLowerCase();
const name = (f.name || '').toLowerCase(); const name = (f.name || '').toLowerCase();
@@ -129,12 +132,12 @@ export default {
const promises = previewableFiles.map((file) => this.readFile(file)); const promises = previewableFiles.map((file) => this.readFile(file));
Promise.all(promises) Promise.all(promises)
.then((imgs) => { .then((imgs) => {
this.images = this.images.concat(imgs); this.images = this.images.concat(imgs);
}) })
.finally(() => { .finally(() => {
this.loading = false; this.loading = false;
}); });
}, },
readFile(file) { readFile(file) {
return new Promise((resolve) => { return new Promise((resolve) => {
@@ -146,7 +149,7 @@ export default {
}); });
}, },
upload() { upload() {
const { code, machine, store, baseUrl } = this.$route.query || {}; const {code, machine, store, baseUrl} = this.$route.query || {};
this.uploading = true; this.uploading = true;
const formData = new FormData(); const formData = new FormData();
@@ -157,22 +160,30 @@ export default {
const cleanBase = (baseUrl || '').replace(/\/+$/, ''); const cleanBase = (baseUrl || '').replace(/\/+$/, '');
const endpoint = `${cleanBase}/kiosk-upload/upload`; const endpoint = `${cleanBase}/kiosk-upload/upload`;
const headers = {
'tenant-id': '000000'
// 注意:不要手动设置 'Content-Type',因为使用 FormData 时浏览器会自动设置正确的 boundary
};
fetch(endpoint, { method: 'POST', body: formData }) fetch(endpoint, {
.then((res) => { method: 'POST',
if (!res.ok) throw new Error(`HTTP ${res.status}`); body: formData,
return res.json().catch(() => ({})); headers: headers
}) })
.then(() => { .then((res) => {
this.uploading = false; if (!res.ok) throw new Error(`HTTP ${res.status}`);
this.$router.replace('/complete'); return res.json().catch(() => ({}));
}) })
.catch((err) => { .then(() => {
console.error('Upload failed:', err); this.uploading = false;
this.uploading = false; this.$router.replace('/complete');
// show lightweight toast, keep selected files for retry })
this.showUploadError('Upload failed. Please try again.'); .catch((err) => {
}); console.error('Upload failed:', err);
this.uploading = false;
// show lightweight toast, keep selected files for retry
this.showUploadError('Upload failed. Please try again.');
});
}, },
// toast helpers // toast helpers
showUploadError(message = 'Upload failed. Please try again.') { showUploadError(message = 'Upload failed. Please try again.') {
@@ -351,6 +362,7 @@ export default {
border: none; border: none;
border-radius: 999px; border-radius: 999px;
} }
.error-toast { .error-toast {
position: fixed; position: fixed;
top: 16px; top: 16px;
@@ -370,5 +382,9 @@ export default {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.error-toast span { margin-left: 4px; opacity: 0.9; }
.error-toast span {
margin-left: 4px;
opacity: 0.9;
}
</style> </style>