|
@@ -2,7 +2,9 @@
|
|
|
<div class="file-upload-container">
|
|
|
<div class="header">
|
|
|
<h2>文件上传</h2>
|
|
|
- <p>选择文件后提交给小程序</p>
|
|
|
+ <!-- <p>选择文件后提交给小程序</p>
|
|
|
+ <p v-if="type" class="type-info">当前类型: {{ type }}</p>
|
|
|
+ <p v-else class="type-info">未设置类型参数</p> -->
|
|
|
</div>
|
|
|
|
|
|
<div class="upload-area" @click="triggerFileInput">
|
|
@@ -11,7 +13,7 @@
|
|
|
</div>
|
|
|
<div class="upload-text">
|
|
|
<p>点击选择文件</p>
|
|
|
- <p class="upload-hint">支持图片、文档、视频等格式</p>
|
|
|
+ <p class="upload-hint">支持图片、文档、压缩文件、视频/音频等格式</p>
|
|
|
</div>
|
|
|
<input
|
|
|
ref="fileInput"
|
|
@@ -64,7 +66,7 @@
|
|
|
:disabled="uploadedFiles.length === 0"
|
|
|
:loading="submitting"
|
|
|
>
|
|
|
- {{ submitting ? '提交中...' : '提交给小程序' }} ({{ uploadedFiles.length }}个文件)
|
|
|
+ {{ submitting ? '提交中...' : '提交文件' }} ({{ uploadedFiles.length }}个文件)
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -89,9 +91,37 @@ export default {
|
|
|
methods: {
|
|
|
// 从URL获取type参数
|
|
|
getTypeFromUrl() {
|
|
|
- const urlParams = new URLSearchParams(window.location.search)
|
|
|
- this.type = urlParams.get('type') || ''
|
|
|
- console.log('从URL接收的type参数:', this.type)
|
|
|
+ try {
|
|
|
+ // 方法1: 使用URLSearchParams
|
|
|
+ const urlParams = new URLSearchParams(window.location.search)
|
|
|
+ this.type = urlParams.get('type') || ''
|
|
|
+
|
|
|
+ // 如果URLSearchParams获取不到,尝试其他方法
|
|
|
+ if (!this.type) {
|
|
|
+ // 方法2: 使用正则表达式
|
|
|
+ const match = window.location.search.match(/[?&]type=([^&]*)/)
|
|
|
+ if (match) {
|
|
|
+ this.type = decodeURIComponent(match[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 方法3: 使用Vue Router的query参数
|
|
|
+ if (!this.type && this.$route && this.$route.query) {
|
|
|
+ this.type = this.$route.query.type || ''
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('当前URL:', window.location.href)
|
|
|
+ console.log('URL查询参数:', window.location.search)
|
|
|
+ console.log('从URL接收的type参数:', this.type)
|
|
|
+ console.log('Vue Router query:', this.$route ? this.$route.query : '无路由信息')
|
|
|
+
|
|
|
+ // 如果还是没有获取到,显示提示
|
|
|
+ if (!this.type) {
|
|
|
+ console.warn('未找到type参数,请检查URL格式,例如: ?type=image')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取type参数时出错:', error)
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 检查微信环境
|
|
@@ -207,6 +237,13 @@ export default {
|
|
|
this.$message.success('文件已提交给小程序')
|
|
|
this.selectedFiles = []
|
|
|
this.uploadedFiles = []
|
|
|
+
|
|
|
+ // 延迟关闭web-view,让用户看到成功提示
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.miniProgram.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
} else {
|
|
|
// 如果不在小程序web-view中,提示用户
|
|
|
this.$message.error('请在微信小程序中打开此页面')
|
|
@@ -300,6 +337,16 @@ export default {
|
|
|
font-size: 14px;
|
|
|
}
|
|
|
|
|
|
+.type-info {
|
|
|
+ background: #f0f9ff;
|
|
|
+ border: 1px solid #409eff;
|
|
|
+ border-radius: 4px;
|
|
|
+ padding: 8px 12px;
|
|
|
+ margin-top: 10px;
|
|
|
+ font-size: 12px;
|
|
|
+ color: #409eff;
|
|
|
+}
|
|
|
+
|
|
|
.upload-area {
|
|
|
border: 2px dashed #d9d9d9;
|
|
|
border-radius: 8px;
|