diff --git a/src/components/Question/QuestionSearch.vue b/src/components/Question/QuestionSearch.vue index a1b99b6..8c75aab 100644 --- a/src/components/Question/QuestionSearch.vue +++ b/src/components/Question/QuestionSearch.vue @@ -177,14 +177,27 @@ export default { const response = await getQuestions(params); + // if (response.data.code === 200) { + // // 包装数据以便传递分页信息 + // const resultData = { + // list: response.data.data.list, + // total: response.data.data.total || [] + // }; + // this.$emit('search-result', resultData); + // this.total = response.data.data.total || 0; + // } else { + // alert('搜索失败:' + response.data.msg); + // } if (response.data.code === 200) { - // 包装数据以便传递分页信息 - const resultData = { - list: response.data.data.list, - total: response.data.data.total || 0 - }; + const list = response.data.data.list || []; + + const totalRaw = response.data.data.total; + const total = Number.isFinite(Number(totalRaw)) ? Number(totalRaw) : 0; + + const resultData = { list, total }; + this.$emit('search-result', resultData); - this.total = response.data.data.total || 0; + this.total = total; } else { alert('搜索失败:' + response.data.msg); } @@ -219,11 +232,20 @@ export default { this.newQuestion.recommendedCourse === '量价时空综合' ? 3 : ''); // 发送请求 - const response = await axios.post('/admin/questions/update', params, { + // const response = await axios.post('/admin/questions/update', params, { + // headers: { + // 'Content-Type': 'application/x-www-form-urlencoded' + // } + // }); + //发送请求 + console.log(params); + const response = await axios.post('http://192.168.40.41:8000/admin/questions/update',params, + { headers: { - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/json' } }); + console.log(response.data); if (response.data.code === 200) { this.closeModal(); @@ -243,10 +265,23 @@ export default { await this.handleSearch(page); }, - exportExcel() { - console.log('执行Excel导出'); + async exportExcel() { + try{ + const response = await axios.post('http://192.168.40.41:8000/admin/questions/export',{},{responseType: 'blob'}); + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', 'question.xlsx'); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + alert('导出成功!'); + }catch (error) { + console.error('导出 Excel 失败:', error); + alert('网络错误,请检查连接!'); + } }, - closeModal() { this.showAddModal = false; this.resetForm(); diff --git a/src/components/Question/QuestionTable.vue b/src/components/Question/QuestionTable.vue index a0001c1..1fb2a23 100644 --- a/src/components/Question/QuestionTable.vue +++ b/src/components/Question/QuestionTable.vue @@ -174,7 +174,7 @@