export question

This commit is contained in:
caoqianming 2020-07-30 08:57:42 +08:00
parent aa9a6852bb
commit dcd77ce65b
5 changed files with 24 additions and 6 deletions

View File

@ -115,3 +115,10 @@ export function importQuestion(data) {
data data
}) })
} }
export function exportQuestion(query) {
return request({
url: '/question/question/export/',
method: 'get',
params: query
})
}

View File

@ -66,6 +66,7 @@
<el-button slot="reference">Excel导入</el-button> <el-button slot="reference">Excel导入</el-button>
</el-popover> </el-popover>
<el-button type="primary" icon="el-icon-download" @click="exportQuestion">导出Excel</el-button>
</div> </div>
</div> </div>
<el-table <el-table
@ -153,7 +154,8 @@ import {
getQuestioncatAll, getQuestioncatAll,
getQuestionList, getQuestionList,
deleteQuestion, deleteQuestion,
importQuestion importQuestion,
exportQuestion
} from "@/api/question"; } from "@/api/question";
import { genTree, deepClone } from "@/utils"; import { genTree, deepClone } from "@/utils";
import checkPermission from "@/utils/permission"; import checkPermission from "@/utils/permission";
@ -291,6 +293,15 @@ export default {
// console.error(err); // console.error(err);
}); });
}, },
exportQuestion() {
const loading = this.$loading({
text:'正在准备..'
});
exportQuestion(this.listQuery).then(response => {
loading.close()
window.open(response.data.path, "_blank");
}).catch(e=>{loading.close()});
},
} }
}; };
</script> </script>

View File

@ -57,9 +57,9 @@ App({
globalData: { globalData: {
userInfo: {}, userInfo: {},
userinfo: {}, // 服务器传回的消费者信息 userinfo: {}, // 服务器传回的消费者信息
//host: 'https://apitest.ahctc.cn', host: 'https://apitest.ahctc.cn',
mediahost: 'https://apitest.ahctc.cn', mediahost: 'https://apitest.ahctc.cn',
host: 'http://127.0.0.1:8011', //host: 'http://127.0.0.1:8011',
//mediahost: 'http://127.0.0.1:8000', //mediahost: 'http://127.0.0.1:8000',
token : '', token : '',
} }

View File

@ -2,7 +2,7 @@ from openpyxl.workbook import Workbook
from django.conf import settings from django.conf import settings
from datetime import datetime from datetime import datetime
from openpyxl.styles import Font, Fill from openpyxl.styles import Font, Fill
import json
BASE_DIR = settings.BASE_DIR BASE_DIR = settings.BASE_DIR
@ -22,7 +22,7 @@ def export_question(questions):
# options='' # options=''
# for key in i.options: # for key in i.options:
# pass # pass
ws1.append([i.questioncat.name, i.type, i.name, i.options, i.right, i.resolution]) ws1.append([i.questioncat.name, i.type, i.name, json.dumps(i.options, ensure_ascii=False), ''.join(sorted(i.right)), i.resolution])
filename = 'questions' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx' filename = 'questions' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx'
path = '/media/export/' + filename path = '/media/export/' + filename
wb.save((BASE_DIR + path).replace('\\', '/')) wb.save((BASE_DIR + path).replace('\\', '/'))

View File

@ -16,7 +16,7 @@ from crm.models import PaySubject
from examtest.models import WorkScope from examtest.models import WorkScope
from server import settings from server import settings
from utils.custom import CommonPagination from utils.custom import CommonPagination
from exports import export_question from .exports import export_question
from .models import Question, Questioncat from .models import Question, Questioncat