From f7fba7469eb458c000bdad97a2c130a9e9ea212b Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期四, 11 七月 2024 09:45:29 +0800
Subject: [PATCH] feat:题目导入
---
src/views/exam/paper/list.vue | 4 ++--
vue.config.js | 4 ++--
src/views/exam/question/list.vue | 41 +++++++++++++++++++++++++++++++++++++++++
src/api/question.js | 5 +++--
4 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/src/api/question.js b/src/api/question.js
index ca143bb..a8d584a 100644
--- a/src/api/question.js
+++ b/src/api/question.js
@@ -1,9 +1,10 @@
-import { post } from '@/utils/request'
+import { post, download } from '@/utils/request'
export default {
pageList: query => post('/api/admin/question/page', query),
edit: query => post('/api/admin/question/edit', query),
select: id => post('/api/admin/question/select/' + id),
deleteQuestion: id => post('/api/admin/question/delete/' + id),
- updateStatus: query => post('/api/admin/question/status', query)
+ updateStatus: query => post('/api/admin/question/status', query),
+ downloadImportTemplate: () => download('/api/admin/question/download/importTemplate'),
}
diff --git a/src/views/exam/paper/list.vue b/src/views/exam/paper/list.vue
index e8c34ef..057b6d8 100644
--- a/src/views/exam/paper/list.vue
+++ b/src/views/exam/paper/list.vue
@@ -9,7 +9,7 @@
<router-link :to="{ path: '/exam/paper/edit' }" class="link-left">
<el-button type="primary" >娣诲姞</el-button>
</router-link>
- <el-button class="link-left" type="danger" @click="downloadImportTemplate">涓嬭浇瀵煎叆妯℃澘</el-button>
+ <el-button class="link-left" type="danger" @click="downloadImportTemplate">涓嬭浇妯℃澘</el-button>
<router-link :to="{ path: '/exam/paper/import' }" class="link-left">
<el-button type="success">瀵煎叆</el-button>
</router-link>
@@ -75,7 +75,7 @@
// 涓嬭浇瀵煎叆妯℃澘
downloadImportTemplate() {
examPaperApi.downloadImportTemplate().then(res => {
- downloadExcel(res, '棰樼洰瀵煎叆妯℃澘')
+ downloadExcel(res, '璇曞嵎瀵煎叆妯℃澘')
})
},
submitForm() {
diff --git a/src/views/exam/question/list.vue b/src/views/exam/question/list.vue
index 512f167..a2c39fc 100644
--- a/src/views/exam/question/list.vue
+++ b/src/views/exam/question/list.vue
@@ -28,6 +28,18 @@
</el-button>
<el-button slot="reference" type="primary" class="link-left">娣诲姞</el-button>
</el-popover>
+ <el-button class="link-left" type="danger" @click="downloadImportTemplate">涓嬭浇妯℃澘</el-button>
+ <el-upload
+ style="display: inline;"
+ class="op-item link-left"
+ action="/api/admin/question/import"
+ :with-credentials="true"
+ :on-success="handlePreview"
+ accept=".xls,.xlsx"
+ :show-file-list="false"
+ :before-upload="beforeAvatarUpload">
+ <el-button v-loading="importLoading" type="primary">瀵煎叆</el-button>
+ </el-upload>
</el-form-item>
</el-form>
<el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
@@ -73,11 +85,13 @@
import Pagination from '@/components/Pagination'
import QuestionShow from './components/Show'
import questionApi from '@/api/question'
+import { downloadExcel } from '@/utils/download'
export default {
components: { Pagination, QuestionShow },
data() {
return {
+ importLoading: '',
queryParam: {
id: null,
questionType: null,
@@ -103,6 +117,33 @@
this.search()
},
methods: {
+ handlePreview (e) {
+ this.importLoading = false
+ if (e.code === 1) {
+ this.search()
+ this.$message.success(e.message)
+ } else {
+ this.$message.error(e.message)
+ }
+ },
+ beforeAvatarUpload (file) {
+ this.importLoading = true
+ let legalName = ['xlsx', 'xls']
+ // 鎷垮埌鍚庣紑鍚�
+ let name = file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length)
+ if (legalName.includes(name)) {
+ // console.log(legalName.includes(name));
+ } else {
+ this.$message.warning('璇蜂笂浼爔ls銆亁lsx鏂囦欢')
+ return false
+ }
+ },
+ // 涓嬭浇瀵煎叆妯℃澘
+ downloadImportTemplate() {
+ questionApi.downloadImportTemplate().then(res => {
+ downloadExcel(res, '棰樼洰瀵煎叆妯℃澘')
+ })
+ },
statusQuestion(row) {
let question = {
id: row.id,
diff --git a/vue.config.js b/vue.config.js
index cc6f74c..7978686 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -19,8 +19,8 @@
hotOnly: false,
proxy: {
'/api': {
- // target: 'http://localhost:8000',
- target: 'http://192.168.3.64:8000',
+ target: 'http://localhost:8000',
+ // target: 'http://192.168.3.64:8000',
changeOrigin: true
}
}
--
Gitblit v1.8.0