| | |
| | | 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) |
| | | deleteQuestion: id => post('/api/admin/question/delete/' + id), |
| | | downloadImportTemplate: () => download('/api/admin/question/download/question/import/temp') |
| | | } |
New file |
| | |
| | | /** |
| | | * 下载文件 |
| | | * @param data 响应数据 |
| | | */ |
| | | export function downloadExcel (data, fileName) { |
| | | // let url = window.URL.createObjectURL(data) // 将二进制文件转化为可访问的url |
| | | let url = window.URL.createObjectURL(new Blob([data])) // 将二进制文件转化为可访问的url |
| | | |
| | | let a = document.createElement('a') |
| | | document.body.appendChild(a) |
| | | a.href = url |
| | | a.download = fileName + '.xlsx' // 文件名 |
| | | a.click() // 模拟点击下载 |
| | | window.URL.revokeObjectURL(url) |
| | | } |
| | |
| | | } |
| | | return request(false, query) |
| | | } |
| | | |
| | | const download = function (url, params) { |
| | | const query = { |
| | | baseURL: process.env.VUE_APP_URL, |
| | | url: url, |
| | | method: 'get', |
| | | withCredentials: true, |
| | | timeout: 30000, |
| | | data: params, |
| | | responseType: 'blob',//关键 |
| | | headers: {'Content-Type': 'application/vnd.ms-excel',}//类型修改为excel |
| | | } |
| | | return request(false, query) |
| | | } |
| | | |
| | | export const down = function (url, params) { |
| | | const query = { |
| | | baseURL: process.env.VUE_APP_URL, |
| | |
| | | postWithOutLoadTip, |
| | | get, |
| | | form, |
| | | |
| | | download |
| | | } |
| | |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <div style="display: flex"> |
| | | <el-button type="primary" @click="submitForm">查询</el-button> |
| | | <el-popover placement="bottom" trigger="click"> |
| | | <el-button class="op-item" type="primary" @click="submitForm">查询</el-button> |
| | | <el-popover class="op-item" placement="bottom" trigger="click"> |
| | | <el-button type="warning" size="mini" v-for="item in editUrlEnum" :key="item.key" |
| | | @click="$router.push({path:item.value})">{{item.name}} |
| | | </el-button> |
| | | <el-button slot="reference" type="primary" class="link-left">添加</el-button> |
| | | <el-button slot="reference" type="primary">添加</el-button> |
| | | |
| | | </el-popover> |
| | | <el-button class="op-item" type="danger" @click="downloadImportTemplate">下载导入模板</el-button> |
| | | <el-upload |
| | | class="upload-demo" |
| | | class="op-item" |
| | | :action="upLoadUrl" |
| | | :with-credentials="true" |
| | | :on-success="handlePreview" |
| | |
| | | import Pagination from '@/components/Pagination' |
| | | import QuestionShow from './components/Show' |
| | | import questionApi from '@/api/question' |
| | | import store from '@/store' |
| | | import {downloadExcel} from '@/utils/download' |
| | | |
| | | import Cookies from 'js-cookie' |
| | | export default { |
| | |
| | | this.subjectFilter = this.subjects |
| | | }, |
| | | methods: { |
| | | // 下载导入模板 |
| | | downloadImportTemplate () { |
| | | questionApi.downloadImportTemplate().then(res => { |
| | | downloadExcel(res, '题目导出') |
| | | }) |
| | | }, |
| | | handlePreview(e){ |
| | | console.log(e) |
| | | if (e.code==1){ |
| | | if (e.code === 1) { |
| | | this.search() |
| | | this.$message.success(e.message) |
| | | }else { |
| | |
| | | } |
| | | </script> |
| | | <style scoped lang="scss"> |
| | | .op-item { |
| | | margin-left: 5px; |
| | | } |
| | | .upload-demo{ |
| | | margin-left: 5px; |
| | | } |