diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/views/business/lab/excelEdit/bindForm.ts b/src/views/business/lab/excelEdit/bindForm.ts new file mode 100644 index 0000000..481d8a8 --- /dev/null +++ b/src/views/business/lab/excelEdit/bindForm.ts @@ -0,0 +1,47 @@ +import GC from '@grapecity-software/spread-sheets' +import dayjs from 'dayjs' +const certTypeMap: { [key: string]: string } = { + 1: '校准证书' +} + +/** + * 处理表单数据字段的对应 + * @param type 模板类型 + * @param data 要处理的数据 + */ +const solveFormData = (type: string, data: any) => { + let result: any + switch (type) { + case '校准证书': + result = { + ...data, + certificateNo: data.certificateReportCode, // 证书编号 + yearD: data.deliverTime ? dayjs(data.deliverTime).year() : '', // 接收日期年 + monthD: data.deliverTime ? dayjs(data.deliverTime).month() : '', // 接收日期月 + dayD: data.deliverTime ? dayjs(data.deliverTime).day() : '', // 接收日期日 + yearC: data.calibrationTime ? dayjs(data.calibrationTime).year() : '', // 校准日期年 + monthC: data.calibrationTime ? dayjs(data.calibrationTime).month() : '', // 校准日期月 + dayC: data.calibrationTime ? dayjs(data.calibrationTime).day() : '', // 校准日期日 + } + break + default: + break + } + + return result +} + +/** + * 表单绑定 + * @param spread + * @param data + */ +export default function bindForm(spread: any, data: any, type = '校准证书') { + const solvedData = solveFormData(type, data) + const seetCount = spread.getSheetCount() + for (let i = 0; i < seetCount; i++) { + const source = new GC.Spread.Sheets.Bindings.CellBindingSource(solvedData) + const sheet = spread.getSheet(i) // 获取第几个sheet页 + sheet.setDataSource(source) + } +} diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/views/business/lab/excelEdit/bindForm.ts b/src/views/business/lab/excelEdit/bindForm.ts new file mode 100644 index 0000000..481d8a8 --- /dev/null +++ b/src/views/business/lab/excelEdit/bindForm.ts @@ -0,0 +1,47 @@ +import GC from '@grapecity-software/spread-sheets' +import dayjs from 'dayjs' +const certTypeMap: { [key: string]: string } = { + 1: '校准证书' +} + +/** + * 处理表单数据字段的对应 + * @param type 模板类型 + * @param data 要处理的数据 + */ +const solveFormData = (type: string, data: any) => { + let result: any + switch (type) { + case '校准证书': + result = { + ...data, + certificateNo: data.certificateReportCode, // 证书编号 + yearD: data.deliverTime ? dayjs(data.deliverTime).year() : '', // 接收日期年 + monthD: data.deliverTime ? dayjs(data.deliverTime).month() : '', // 接收日期月 + dayD: data.deliverTime ? dayjs(data.deliverTime).day() : '', // 接收日期日 + yearC: data.calibrationTime ? dayjs(data.calibrationTime).year() : '', // 校准日期年 + monthC: data.calibrationTime ? dayjs(data.calibrationTime).month() : '', // 校准日期月 + dayC: data.calibrationTime ? dayjs(data.calibrationTime).day() : '', // 校准日期日 + } + break + default: + break + } + + return result +} + +/** + * 表单绑定 + * @param spread + * @param data + */ +export default function bindForm(spread: any, data: any, type = '校准证书') { + const solvedData = solveFormData(type, data) + const seetCount = spread.getSheetCount() + for (let i = 0; i < seetCount; i++) { + const source = new GC.Spread.Sheets.Bindings.CellBindingSource(solvedData) + const sheet = spread.getSheet(i) // 获取第几个sheet页 + sheet.setDataSource(source) + } +} diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue new file mode 100644 index 0000000..5f89fd9 --- /dev/null +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -0,0 +1,142 @@ + + + + + + diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/views/business/lab/excelEdit/bindForm.ts b/src/views/business/lab/excelEdit/bindForm.ts new file mode 100644 index 0000000..481d8a8 --- /dev/null +++ b/src/views/business/lab/excelEdit/bindForm.ts @@ -0,0 +1,47 @@ +import GC from '@grapecity-software/spread-sheets' +import dayjs from 'dayjs' +const certTypeMap: { [key: string]: string } = { + 1: '校准证书' +} + +/** + * 处理表单数据字段的对应 + * @param type 模板类型 + * @param data 要处理的数据 + */ +const solveFormData = (type: string, data: any) => { + let result: any + switch (type) { + case '校准证书': + result = { + ...data, + certificateNo: data.certificateReportCode, // 证书编号 + yearD: data.deliverTime ? dayjs(data.deliverTime).year() : '', // 接收日期年 + monthD: data.deliverTime ? dayjs(data.deliverTime).month() : '', // 接收日期月 + dayD: data.deliverTime ? dayjs(data.deliverTime).day() : '', // 接收日期日 + yearC: data.calibrationTime ? dayjs(data.calibrationTime).year() : '', // 校准日期年 + monthC: data.calibrationTime ? dayjs(data.calibrationTime).month() : '', // 校准日期月 + dayC: data.calibrationTime ? dayjs(data.calibrationTime).day() : '', // 校准日期日 + } + break + default: + break + } + + return result +} + +/** + * 表单绑定 + * @param spread + * @param data + */ +export default function bindForm(spread: any, data: any, type = '校准证书') { + const solvedData = solveFormData(type, data) + const seetCount = spread.getSheetCount() + for (let i = 0; i < seetCount; i++) { + const source = new GC.Spread.Sheets.Bindings.CellBindingSource(solvedData) + const sheet = spread.getSheet(i) // 获取第几个sheet页 + sheet.setDataSource(source) + } +} diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue new file mode 100644 index 0000000..5f89fd9 --- /dev/null +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -0,0 +1,142 @@ + + + + + + diff --git a/src/views/business/lab/excelEdit/index.ts b/src/views/business/lab/excelEdit/index.ts new file mode 100644 index 0000000..f95ae65 --- /dev/null +++ b/src/views/business/lab/excelEdit/index.ts @@ -0,0 +1,65 @@ +/** 这里定义一些工作表基础使用方法 */ +import * as GC from '@grapecity-software/spread-sheets' +/** + * 导入xlsx、ssjson、csv + * @param spread sprad实例 + * @param file 文件 + */ +export function importFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + console.log('spread', spread) + console.log('file', file) + return new Promise((resolve) => { + spread.import( + file, + () => { + console.log('spread:导入文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传文件发生错误', e) + }, + { + fileType: GC.Spread.Sheets.FileType.excel, + }, + ) + }) +} + +/** + * 导入ssj + * @param spread sprad实例 + * @param file 文件 + */ +export function importSjsFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + return new Promise((resolve) => { + spread.open( + file, + () => { + console.log('spread:导入sjs文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传sjs文件发生错误', e) + }, + ) + }) +} + +/** + * 导入(方法来源于视频)---暂时不用 + * @param spread sprad实例 + * @param file 文件 + */ +export function excelIOimportFile(excelIO: any, file: File) { + excelIO.open( + file, + () => { + console.log('excelIO:导入文件成功') // 错误回调函数 + }, + (e: any) => { + console.log('excelIO:上传文件发生错误', e) // 错误回调函数 + }, + ) +} diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/views/business/lab/excelEdit/bindForm.ts b/src/views/business/lab/excelEdit/bindForm.ts new file mode 100644 index 0000000..481d8a8 --- /dev/null +++ b/src/views/business/lab/excelEdit/bindForm.ts @@ -0,0 +1,47 @@ +import GC from '@grapecity-software/spread-sheets' +import dayjs from 'dayjs' +const certTypeMap: { [key: string]: string } = { + 1: '校准证书' +} + +/** + * 处理表单数据字段的对应 + * @param type 模板类型 + * @param data 要处理的数据 + */ +const solveFormData = (type: string, data: any) => { + let result: any + switch (type) { + case '校准证书': + result = { + ...data, + certificateNo: data.certificateReportCode, // 证书编号 + yearD: data.deliverTime ? dayjs(data.deliverTime).year() : '', // 接收日期年 + monthD: data.deliverTime ? dayjs(data.deliverTime).month() : '', // 接收日期月 + dayD: data.deliverTime ? dayjs(data.deliverTime).day() : '', // 接收日期日 + yearC: data.calibrationTime ? dayjs(data.calibrationTime).year() : '', // 校准日期年 + monthC: data.calibrationTime ? dayjs(data.calibrationTime).month() : '', // 校准日期月 + dayC: data.calibrationTime ? dayjs(data.calibrationTime).day() : '', // 校准日期日 + } + break + default: + break + } + + return result +} + +/** + * 表单绑定 + * @param spread + * @param data + */ +export default function bindForm(spread: any, data: any, type = '校准证书') { + const solvedData = solveFormData(type, data) + const seetCount = spread.getSheetCount() + for (let i = 0; i < seetCount; i++) { + const source = new GC.Spread.Sheets.Bindings.CellBindingSource(solvedData) + const sheet = spread.getSheet(i) // 获取第几个sheet页 + sheet.setDataSource(source) + } +} diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue new file mode 100644 index 0000000..5f89fd9 --- /dev/null +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -0,0 +1,142 @@ + + + + + + diff --git a/src/views/business/lab/excelEdit/index.ts b/src/views/business/lab/excelEdit/index.ts new file mode 100644 index 0000000..f95ae65 --- /dev/null +++ b/src/views/business/lab/excelEdit/index.ts @@ -0,0 +1,65 @@ +/** 这里定义一些工作表基础使用方法 */ +import * as GC from '@grapecity-software/spread-sheets' +/** + * 导入xlsx、ssjson、csv + * @param spread sprad实例 + * @param file 文件 + */ +export function importFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + console.log('spread', spread) + console.log('file', file) + return new Promise((resolve) => { + spread.import( + file, + () => { + console.log('spread:导入文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传文件发生错误', e) + }, + { + fileType: GC.Spread.Sheets.FileType.excel, + }, + ) + }) +} + +/** + * 导入ssj + * @param spread sprad实例 + * @param file 文件 + */ +export function importSjsFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + return new Promise((resolve) => { + spread.open( + file, + () => { + console.log('spread:导入sjs文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传sjs文件发生错误', e) + }, + ) + }) +} + +/** + * 导入(方法来源于视频)---暂时不用 + * @param spread sprad实例 + * @param file 文件 + */ +export function excelIOimportFile(excelIO: any, file: File) { + excelIO.open( + file, + () => { + console.log('excelIO:导入文件成功') // 错误回调函数 + }, + (e: any) => { + console.log('excelIO:上传文件发生错误', e) // 错误回调函数 + }, + ) +} diff --git a/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs b/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs new file mode 100644 index 0000000..e395d36 --- /dev/null +++ b/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs Binary files differ diff --git a/src/components.d.ts b/src/components.d.ts index a720b59..57b4d35 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -38,7 +38,7 @@ DetailPage: typeof import('./components/DetailPage/index.vue')['default'] Editor: typeof import('./components/Editor/index.vue')['default'] ErrorDialog: typeof import('./components/dialog/errorDialog.vue')['default'] - ExcelEdit: typeof import('./components/excelEdit/index.vue')['default'] + ExcelEdit: typeof import('./components/excelEdit/excelEditDialog.vue')['default'] ExcelOreview: typeof import('./components/filePreview/excelOreview.vue')['default'] FilePreview: typeof import('./components/filePreview/filePreview.vue')['default'] FilePreviewDialog: typeof import('./components/filePreview/filePreviewDialog.vue')['default'] diff --git a/src/components/excelEdit/index.ts b/src/components/excelEdit/index.ts deleted file mode 100644 index 192b68e..0000000 --- a/src/components/excelEdit/index.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** 这里定义一些工作表基础使用方法 */ -import * as GC from '@grapecity-software/spread-sheets' -/** - * 导入 - * @param spread sprad实例 - * @param file 文件 - */ -export function importFile(spread: any, file: File) { - console.log('spread:开始执行文件导入') - console.log('spread', spread) - console.log('file', file) - return new Promise((resolve) => { - spread.import( - file, - () => { - console.log('spread:导入文件成功') - resolve('') - }, - (e: any) => { - console.log('spread:上传文件发生错误', e) - }, - { - fileType: GC.Spread.Sheets.FileType.excel, - }, - ) - }) -} - -/** - * 导入(方法来源于视频)---暂时不用 - * @param spread sprad实例 - * @param file 文件 - */ -export function excelIOimportFile(excelIO: any, file: File) { - excelIO.open( - file, - () => { - console.log('excelIO:导入文件成功') // 错误回调函数 - }, - (e: any) => { - console.log('excelIO:上传文件发生错误', e) // 错误回调函数 - }, - ) -} diff --git a/src/components/excelEdit/index.vue b/src/components/excelEdit/index.vue deleted file mode 100644 index 2996951..0000000 --- a/src/components/excelEdit/index.vue +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - diff --git a/src/views/business/lab/excelEdit/bindForm.ts b/src/views/business/lab/excelEdit/bindForm.ts new file mode 100644 index 0000000..481d8a8 --- /dev/null +++ b/src/views/business/lab/excelEdit/bindForm.ts @@ -0,0 +1,47 @@ +import GC from '@grapecity-software/spread-sheets' +import dayjs from 'dayjs' +const certTypeMap: { [key: string]: string } = { + 1: '校准证书' +} + +/** + * 处理表单数据字段的对应 + * @param type 模板类型 + * @param data 要处理的数据 + */ +const solveFormData = (type: string, data: any) => { + let result: any + switch (type) { + case '校准证书': + result = { + ...data, + certificateNo: data.certificateReportCode, // 证书编号 + yearD: data.deliverTime ? dayjs(data.deliverTime).year() : '', // 接收日期年 + monthD: data.deliverTime ? dayjs(data.deliverTime).month() : '', // 接收日期月 + dayD: data.deliverTime ? dayjs(data.deliverTime).day() : '', // 接收日期日 + yearC: data.calibrationTime ? dayjs(data.calibrationTime).year() : '', // 校准日期年 + monthC: data.calibrationTime ? dayjs(data.calibrationTime).month() : '', // 校准日期月 + dayC: data.calibrationTime ? dayjs(data.calibrationTime).day() : '', // 校准日期日 + } + break + default: + break + } + + return result +} + +/** + * 表单绑定 + * @param spread + * @param data + */ +export default function bindForm(spread: any, data: any, type = '校准证书') { + const solvedData = solveFormData(type, data) + const seetCount = spread.getSheetCount() + for (let i = 0; i < seetCount; i++) { + const source = new GC.Spread.Sheets.Bindings.CellBindingSource(solvedData) + const sheet = spread.getSheet(i) // 获取第几个sheet页 + sheet.setDataSource(source) + } +} diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue new file mode 100644 index 0000000..5f89fd9 --- /dev/null +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -0,0 +1,142 @@ + + + + + + diff --git a/src/views/business/lab/excelEdit/index.ts b/src/views/business/lab/excelEdit/index.ts new file mode 100644 index 0000000..f95ae65 --- /dev/null +++ b/src/views/business/lab/excelEdit/index.ts @@ -0,0 +1,65 @@ +/** 这里定义一些工作表基础使用方法 */ +import * as GC from '@grapecity-software/spread-sheets' +/** + * 导入xlsx、ssjson、csv + * @param spread sprad实例 + * @param file 文件 + */ +export function importFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + console.log('spread', spread) + console.log('file', file) + return new Promise((resolve) => { + spread.import( + file, + () => { + console.log('spread:导入文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传文件发生错误', e) + }, + { + fileType: GC.Spread.Sheets.FileType.excel, + }, + ) + }) +} + +/** + * 导入ssj + * @param spread sprad实例 + * @param file 文件 + */ +export function importSjsFile(spread: any, file: File) { + console.log('spread:开始执行文件导入') + return new Promise((resolve) => { + spread.open( + file, + () => { + console.log('spread:导入sjs文件成功') + resolve('') + }, + (e: any) => { + console.log('spread:上传sjs文件发生错误', e) + }, + ) + }) +} + +/** + * 导入(方法来源于视频)---暂时不用 + * @param spread sprad实例 + * @param file 文件 + */ +export function excelIOimportFile(excelIO: any, file: File) { + excelIO.open( + file, + () => { + console.log('excelIO:导入文件成功') // 错误回调函数 + }, + (e: any) => { + console.log('excelIO:上传文件发生错误', e) // 错误回调函数 + }, + ) +} diff --git a/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs b/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs new file mode 100644 index 0000000..e395d36 --- /dev/null +++ b/src/views/business/lab/excelEdit/templateFiles/calibrationCert.sjs Binary files differ diff --git a/src/views/business/lab/measureData/measureDataDetail.vue b/src/views/business/lab/measureData/measureDataDetail.vue index c914b81..8043647 100644 --- a/src/views/business/lab/measureData/measureDataDetail.vue +++ b/src/views/business/lab/measureData/measureDataDetail.vue @@ -21,8 +21,8 @@ import { SCHEDULE } from '@/utils/scheduleDict' import { UploadFile } from '@/api/measure/file' import { updateSample } from '@/api/customer/sampleList' -import ExcelEdit from '@/components/excelEdit/index.vue' -import { importFile } from '@/components/excelEdit/index.ts' +import ExcelEdit from '@/views/business/lab/excelEdit/excelEditDialog.vue' +import { importFile, importSjsFile } from '@/views/business/lab/excelEdit' import { getStaffList } from '@/api/measure/person' // import ApprovalDialog from '@/components/Approval/ApprovalDialogByProcess.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' @@ -886,20 +886,20 @@ // downLoadTemplate(params).then((res) => { // if (res.data) { - // // const fileName = `${form.value.certificateReportName}${form.value.templateName}.xlsx` - // // const file = new File([res.data], fileName) // loading.close() - // // importFile(spread, file) - // // excelEditRef.value.handleImportFile(res.data) + // excelEditRef.value.handleImportFile(res.data, form) // } // else { // console.log('未获取到模板文件') // } // }).catch(() => { - // loading.close() + // loading.close() // }) - // const res = await fetch('http://111.198.10.15:21408/test/压力表-新_1741080567308.xlsx') - // const file = await res.blob() + const res = await getPhotoUrl(form.value.certificateReportFile) + const certUrl = await fetch(res.data) + const file = await certUrl.blob() + excelEditRef.value.handleImportFile(file, form.value) + loading.close() // importFile(spread, file) }