From dcd77ce65bbcffaf63b8e7a2abe6c986daccd218 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 30 Jul 2020 08:57:42 +0800 Subject: [PATCH] export question --- test_client/src/api/question.js | 7 +++++++ test_client/src/views/question/question.vue | 13 ++++++++++++- test_mini/app.js | 4 ++-- test_server/question/exports.py | 4 ++-- test_server/question/views.py | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/test_client/src/api/question.js b/test_client/src/api/question.js index b728fcf..3f6cd50 100644 --- a/test_client/src/api/question.js +++ b/test_client/src/api/question.js @@ -114,4 +114,11 @@ export function importQuestion(data) { method: 'post', data }) +} +export function exportQuestion(query) { + return request({ + url: '/question/question/export/', + method: 'get', + params: query + }) } \ No newline at end of file diff --git a/test_client/src/views/question/question.vue b/test_client/src/views/question/question.vue index 0a51055..3f0c099 100644 --- a/test_client/src/views/question/question.vue +++ b/test_client/src/views/question/question.vue @@ -66,6 +66,7 @@ Excel导入 +导出Excel { + loading.close() + window.open(response.data.path, "_blank"); + }).catch(e=>{loading.close()}); + }, } }; diff --git a/test_mini/app.js b/test_mini/app.js index cf82f03..1320ac0 100644 --- a/test_mini/app.js +++ b/test_mini/app.js @@ -57,9 +57,9 @@ App({ globalData: { userInfo: {}, userinfo: {}, // 服务器传回的消费者信息 - //host: 'https://apitest.ahctc.cn', + host: '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', token : '', } diff --git a/test_server/question/exports.py b/test_server/question/exports.py index daf68f6..f2ca039 100644 --- a/test_server/question/exports.py +++ b/test_server/question/exports.py @@ -2,7 +2,7 @@ from openpyxl.workbook import Workbook from django.conf import settings from datetime import datetime from openpyxl.styles import Font, Fill - +import json BASE_DIR = settings.BASE_DIR @@ -22,7 +22,7 @@ def export_question(questions): # options='' # for key in i.options: # 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' path = '/media/export/' + filename wb.save((BASE_DIR + path).replace('\\', '/')) diff --git a/test_server/question/views.py b/test_server/question/views.py index ecaa2cd..132006e 100644 --- a/test_server/question/views.py +++ b/test_server/question/views.py @@ -16,7 +16,7 @@ from crm.models import PaySubject from examtest.models import WorkScope from server import settings from utils.custom import CommonPagination -from exports import export_question +from .exports import export_question from .models import Question, Questioncat