Browse Source

完成了用户后台修改新增题目的接口实现、导出题目和导出用户信息的接口实现

daijiajun/feature-20251107115823-股票知识测评
chenzhen 2 months ago
parent
commit
22b71d1f9f
  1. 57
      src/components/Question/QuestionSearch.vue
  2. 16
      src/components/Question/QuestionTable.vue
  3. 52
      src/components/UserStatistics/UserStatisticsSearch.vue
  4. 2
      src/components/UserStatistics/UserStatisticsTable.vue
  5. 54
      src/components/WrongQuestion/WrongQuestionTable.vue
  6. 4
      src/views/UserStatistics.vue

57
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();

16
src/components/Question/QuestionTable.vue

@ -174,7 +174,7 @@
<div class="modal-content" @click.stop>
<div class="modal-header">
<h3>编辑题目</h3>
<button class="close-btn" @click="closeEditModal">×</button>
<!-- <button class="close-btn" @click="closeEditModal">×</button> -->
</div>
<div class="modal-body">
<div class="form-row">
@ -247,7 +247,7 @@
<div class="delete-modal-content" @click.stop>
<div class="modal-header">
<h3>您确定要删除吗</h3>
<button class="close-btn" @click="closeDeleteModal">×</button>
<!-- <button class="close-btn" @click="closeDeleteModal">×</button> -->
</div>
<div class="modal-footer">
<button class="btn-red" @click="confirmDelete">确定</button>
@ -512,11 +512,19 @@ export default {
this.editingQuestion.recommendedCourse === '价格破译' ? 2 : 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.closeEditModal();

52
src/components/UserStatistics/UserStatisticsSearch.vue

@ -41,9 +41,9 @@
<label>身份</label>
<select v-model="filters.role">
<option value="">全部</option>
<option value="学员">学员</option>
<option value="讲师">讲师</option>
<option value="管理员">管理员</option>
<option value="非网">非网</option>
<option value="半年">半年</option>
<option value="终身">终身</option>
</select>
</div>
@ -56,6 +56,7 @@
</template>
<script>
import axios from 'axios'
export default {
name: 'UserStatisticsSearch',
data() {
@ -66,18 +67,51 @@ export default {
endDate: '',
userName: '',
jingwangId: '',
role: ''
role: '',
questionType: ''
}
}
},
methods: {
searchUserStatistics() {
async searchUserStatistics() {
//
this.$emit('search', {...this.filters});
try{
const params = new URLSearchParams();
const questionType = this.filters.questionType || '';
if(questionType){
console.log(questionType);
params.append('questionType', questionType);
}
const role = {
'非网':1,
'半年':2,
'终身':3
}
if(this.filters.role){
console.log(role[this.filters.role]);
params.append('role', role[this.filters.role]);
}
}catch (error) {
console.error('搜索用户统计失败:', error);
alert('搜索失败!');
}
},
exportToExcel() {
// Excel
console.log('导出Excel')
async exportToExcel() {
try{
const response = await axios.post('http://192.168.40.41:8000/admin/user/export',{},{responseType: 'blob'});
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'user_statistics.xlsx');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
alert('导出成功!');
}catch (error) {
console.error('导出 Excel 失败:', error);
alert('导出失败!');
}
}
}
}

2
src/components/UserStatistics/UserStatisticsTable.vue

@ -90,7 +90,7 @@
<div class="wrong-questions-container">
<div v-for="(item, index) in wrongQuestions" :key="index" class="question-item">
<div class="question-stem">
{{ item.question.stem }}
{{ index + 1 }}. {{ item.question.stem }}
</div>
<div class="options">
<div

54
src/components/WrongQuestion/WrongQuestionTable.vue

@ -215,26 +215,47 @@ export default {
}
},
methods: {
setFilters(filters) {
this.currentFilters = filters;
this.page = 1;
this.fetchWrongQuestions();
setData(data) {
this.wrongQuestions = data.list || [];
this.total = data.total || 0;
this.page = data.page || 1;
},
async fetchWrongQuestions() {
try {
const params = {
Page: this.page,
PageSize: this.pageSize,
question_type_id: this.currentFilters.type ? parseInt(this.currentFilters.type) : undefined,
course_recommendation_id: this.currentFilters.course ? parseInt(this.currentFilters.course) : undefined,
stem: this.currentFilters.questionText || '',
sort_field: this.sortField,
sort_direction: this.sortDirection
const params = new URLSearchParams();
params.append('page', this.page);
params.append('page_size', this.pageSize);
//
const questionTypeIdMap = {
'股票知识': 1,
'企业文化': 2
};
if (this.currentFilters.questionType) {
params.append('question_type_id', questionTypeIdMap[this.currentFilters.questionType]);
}
// 使 getQuestions axios.post
const response = await getQuestions(params)
const courseRecommendationIdMap = {
'量能擒牛': 1,
'价格破译': 2,
'量价时空综合': 3
};
if (this.currentFilters.course) {
params.append('course_recommendation_id', courseRecommendationIdMap[this.currentFilters.course]);
}
if (this.currentFilters.keyword) {
params.append('stem', this.currentFilters.keyword);
}
//
if (this.sortField) {
params.append('sort_field', this.sortField);
params.append('sort_direction', this.sortDirection);
}
const response = await getQuestions(params);
if (response.data.code === 200) {
this.wrongQuestions = response.data.data.list.map(item => ({
@ -242,7 +263,7 @@ export default {
stem: item.stem,
questionTypeName: item.questionTypeName,
errorCount: item.errorCount,
errorRate: `${item.errorRate}%`,
errorRate: item.errorRate, // %
CrName: item.CrName
}))
this.total = response.data.data.total || 0;
@ -252,8 +273,7 @@ export default {
} catch (error) {
console.error('获取错题数据失败:', error)
}
}
,
},
viewUser(item) {
this.$emit('view-user', item)

4
src/views/UserStatistics.vue

@ -46,20 +46,16 @@ export default {
this.page = 1
this.$refs.userStatisticsTable.fetchUserStatistics(1, filters);
},
//
handlePageChanged(page) {
this.page = page;
this.$refs.userStatisticsTable.fetchUserStatistics(page, this.filters);
},
//
handleDataLoaded(data) {
this.userStatistics = data.list;
this.total = data.total;
}
},
async mounted() {

Loading…
Cancel
Save