From 50d2bd54069dd2a9203f168c883f0cc02e44a72b Mon Sep 17 00:00:00 2001 From: maxmon <541182180@qq.com> Date: Thu, 13 Apr 2023 00:02:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=EF=BC=8C=E5=B9=B6=E8=A7=84=E8=8C=83=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/app/api/v1/files.py | 7 +++++-- be/app/config/setting.py | 2 +- doc/api.md | 4 +--- fe/config/index.js | 4 ++-- fe/src/components/NER/index.vue | 10 ++++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/be/app/api/v1/files.py b/be/app/api/v1/files.py index 3bb6d84..192e411 100644 --- a/be/app/api/v1/files.py +++ b/be/app/api/v1/files.py @@ -10,6 +10,7 @@ from ...entities.entities import ReturnInfo, FileInfo from ...libs.tools import read_json_file, read_txt_file, write_json, get_project_file import threading import time +from urllib.parse import urlencode # api = RedPrint('files') @@ -96,9 +97,11 @@ def get_anno_json(): if not fn.endswith('.json'): continue js.append(read_txt_file(anno_output_dir + '/' + fn)) - anno_json_path = DOWNLOAD_FILE_LOCATION.format(project_name).replace('result.json', 'anno.json') + anno_json_path = DOWNLOAD_FILE_LOCATION.format(project_name) open('app/'+anno_json_path, 'w', encoding='utf-8').write('\n'.join(js)) response = make_response(send_from_directory(directory='', path=anno_json_path, as_attachment=True)) - response.headers["Content-disposition"] = 'attachment; filename=result.json' + filename = project_name + '_' + time.strftime('%Y%m%d_%H%M%S') + '.json' + filename_urlencode = urlencode({'filename': filename}) + response.headers["Content-disposition"] = f'attachment; {filename_urlencode}' return response diff --git a/be/app/config/setting.py b/be/app/config/setting.py index 4c3694d..d8dc50c 100644 --- a/be/app/config/setting.py +++ b/be/app/config/setting.py @@ -17,7 +17,7 @@ PROJECT_PATH = PROJECTS + '/{}/' PROJECT_CONFIG_PATH = PROJECTS + '/' + "{}" + '/config.json' #下载标注结果所在的位置 -DOWNLOAD_FILE_LOCATION = 'projects/{}/result.json' +DOWNLOAD_FILE_LOCATION = 'projects/{}/anno.json' # 标注信息存储路径 ANNO_OUTPUT_PATH = PROJECTS + '/{}/anno/{}.json' diff --git a/doc/api.md b/doc/api.md index 980704f..003f735 100644 --- a/doc/api.md +++ b/doc/api.md @@ -3,7 +3,5 @@ | url | methods | params | return | | -------------------------- | ------- | -------------------------------------------------------- | -------------------------------- | | v1/project/get_zipped_data | POST | projectName:项目名 file:数据集文件(目前只支持.zip格式) | json :errcode表示是否成功导入 | -| v1/files/get_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) | +| v1/files/get_anno_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) | |v1/project/delete_program |GET |projectName:项目名|json:errcode表示是否成功| -| v1/files//get_labels | GET | projectName:项目名 | file(.json格式的数据集标注结果) | - diff --git a/fe/config/index.js b/fe/config/index.js index ba981cb..feaa3f8 100644 --- a/fe/config/index.js +++ b/fe/config/index.js @@ -12,13 +12,13 @@ module.exports = { assetsPublicPath: '/', proxyTable: { '/v1/': { - target: 'http://localhost:9060/', + target: 'http://127.0.0.1:9060/', // target: 'https://tekii.cn/', } }, // Various Dev Server settings - host: '0.0.0.0', // can be overwritten by process.env.HOST + host: '127.0.0.1', // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, diff --git a/fe/src/components/NER/index.vue b/fe/src/components/NER/index.vue index 48a7afc..02ec08a 100644 --- a/fe/src/components/NER/index.vue +++ b/fe/src/components/NER/index.vue @@ -412,6 +412,10 @@ export default { * @param 类型 */ setType: function (type, ev) { + if (!this.nowFile) { + // 如果没有选中文件,就不允许标注 + return false + } if (this.projectType === '命名实体识别') { this.$set(this, 'nowType', type) } else if (this.projectType === '文本分类') { @@ -639,11 +643,9 @@ export default { if (!isLocal) { // 非单机版,就直接通过url下载 if (this.projectType === '命名实体识别') { - window.open(`/v1/files/get_json?projectName=${this.projectName}`, '_self') + window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self') } else if (this.projectType === '文本分类') { - get(`/v1/files/get_labels?projectName=${this.projectName}`, (text) => { - saveAsFile(JSON.stringify(JSON.parse(text)), 'labels.json') - }, {isDirect: true}) + window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self') } else { window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self') }