From 489fd642fbbd1324af327215238970e591e6da44 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Fri, 20 Oct 2023 18:09:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:krosum=E5=BC=B9=E7=AA=97=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=88=86=E6=9E=90=E4=BB=A5=E5=8F=8A=E5=8F=B3=E4=BE=A7table?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B8=B2=E6=9F=93=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Modals/KorsumModal.vue | 86 +++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/src/views/spectrumAnalysis/components/Modals/KorsumModal.vue b/src/views/spectrumAnalysis/components/Modals/KorsumModal.vue index 4186b60..31bd776 100644 --- a/src/views/spectrumAnalysis/components/Modals/KorsumModal.vue +++ b/src/views/spectrumAnalysis/components/Modals/KorsumModal.vue @@ -148,6 +148,7 @@ import ModalMixin from '@/mixins/ModalMixin' import TitleOverBorder from '../TitleOverBorder.vue' import { getAction, postAction } from '@/api/manage' +import * as XLSX from 'xlsx'; const columns = [ { @@ -183,15 +184,18 @@ const columns = [ const outputColumns = [ { title: 'Energy', - dataIndex: 'energy' + dataIndex: 'energy', + customRender: (text) => parseFloat(Number(text).toPrecision(6)) }, { title: 'Correct Factor', - dataIndex: 'correctFactor' + dataIndex: 'correctFactor', + customRender: (text) => parseFloat(Number(text).toPrecision(6)) }, { title: 'Uncertainty(%)', - dataIndex: 'uncertainty' + dataIndex: 'uncertainty', + customRender: (text) => parseFloat(Number(text).toPrecision(6)) } ] export default { @@ -210,7 +214,10 @@ export default { selectedItem: {}, // output中左侧选中的项 outputTableList: [], // output中表格列表数据 - filterWord: '' // 筛选 + filterWord: '', // 筛选 + + fileName: '', // save excel name + analyseData: {} // 分析结果 } }, methods: { @@ -264,6 +271,7 @@ export default { ...this.efficiency, energys: this.list.map(item => item.energy) }) + console.log(success); if (success) { this.list = result } else { @@ -275,8 +283,22 @@ export default { }, // 分析 - handleAnalyze() { + async handleAnalyze() { console.log('%c [ 分析 ]-178', 'font-size:13px; background:pink; color:#bf2c9f;') + try { + this.isLoading = true + const { success, result, message } = await postAction('/gamma/KorSumAnalyse', this.list) + this.isLoading = false + if (success) { + this.analyseData = result + console.log(result); + } else { + this.$message.error(message) + } + } catch (error) { + this.isLoading = false; + console.error(error) + } }, // 退出 @@ -286,12 +308,66 @@ export default { // output栏点击左侧列表 handleOutputItemClick(item) { + if(!this.analyseData) { + this.$message.error("Analyse Fail!") + return false; + } this.selectedItem = item + this.outputTableList = []; + + // 根据核素名获取结果集 + let data = this.analyseData[this.selectedItem] + if(!data || data.energy.length < 1) { + this.$message.error("Analyse Fail!") + return false; + } + + let result = []; + for(let i = 0; i < data.energy.length; i++ ) { + // 将数据进行填充并 + let obj = { + "energy": data.energy[i], + "correctFactor" : data.factor[i], + "uncertainty" : (data.factor[i] - 1) / 10 * 100 + } + result.push(obj); + } + + this.outputTableList = result; }, // 导出到excel handleExport() { console.log('%c [ 导出到excel ]-246', 'font-size:13px; background:pink; color:#bf2c9f;') + let _this = this + this.$confirm({ + title: 'Please enter file name', + content: (h) => , + okText: 'Cancle', + cancelText: 'Save', + okButtonProps: { style: { backgroundColor: '#b98326', color: '#fff', borderColor: 'transparent' } }, + cancelButtonProps: { style: { color: '#fff', backgroundColor: '#31aab0', borderColor: 'transparent' } }, + onOk() { + console.log('Cancel') + }, + onCancel() { + console.log(_this.fileName); + if (_this.fileName) { + // saveAs(blob, `${_this.fileName}`) + // 创建工作簿 + const workbook = XLSX.utils.book_new(); + + // 创建工作表 + const worksheet = XLSX.utils.json_to_sheet(_this.outputTableList); + + // 将工作表添加到工作簿 + XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1'); + + // 导出Excel文件 + XLSX.writeFile(workbook, _this.fileName + ".xlsx"); + } + }, + }) } }, computed: {