dataSubmission() { // return const params = { start: this.value2[0] ? moment(this.value2[0]).format("YYYY-MM-DD HH:mm:ss") : "", end: this.value2[1] ? moment(this.value2[1]).format("YYYY-MM-DD HH:mm:ss") : "", patientId: this.patientId, source: this.sourceTypeList .filter((item) => item.choice) .map((item) => { return { machineType: item.machine, sourceList: item.sources .filter((sItem) => sItem.checked) .map((mItem) => mItem.code), }; }), }; console.log(this.sourceTypeList); console.log(params, "params"); bioExport(params) .then((res) => { console.log(res, "ssssss"); const timeName = this.getNowDate(); const name = this.patientName + timeName; console.log(name, 123); this.downFileByStream(res, { type: "xls", name, }); this.value2 = []; if (res.success) { this.$message.success("操作成功"); } this.exportPop = false; }) .catch((err) => { console.log("err", err); this.$message.error(err.message); }); },
时间: 2024-02-10 21:33:28 浏览: 19
这段代码的作用是从前端向后端提交数据,后端根据提交的数据生成Excel文件,前端接收到文件数据后进行下载,并将下载的结果进行提示。
具体实现过程如下:
1. 获取需要提交的参数。在这段代码中,通过获取时间范围、病人ID、设备类型和设备来源等参数。
2. 调用bioExport函数向后端提交数据,并接收后端返回的数据。在这段代码中,调用了bioExport函数,将参数传递给后端,后端根据参数生成Excel文件,并将文件数据返回给前端。
3. 将返回的文件数据进行下载。在这段代码中,通过调用downFileByStream函数实现文件下载,并将下载的文件保存到本地。
4. 提示操作结果。在这段代码中,通过调用this.$message.success和this.$message.error函数,对操作结果进行提示。
需要注意的是,这段代码中使用了一些第三方库或函数,例如moment、bioExport和downFileByStream等。这些库或函数的具体实现需要参照具体的文档或代码进行调用。
相关问题
// 获取表单值 const form = getFieldsValue(); // 条件值的component类型会随着字段的变化发生变化 // 条件值发生变化时获取当前字段列详细数据 const currentFieldData = columnOptions.value.find( (item: Recordable) => item.value === form.field, ) as unknown as Recordable; // 根据字段label const fieldLabel = columnOptions.value.find((item) => item.value === form?.field)?.label; // 判断条件 const conditionType = ARITHMETIC_OPERATOR_BACK.find( (item) => item.value === form?.op, )?.operate; if (form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL) { // 判断条件为空、非空时,清空条件值 conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}; } else { // 字段值和判断条件发生变化 let labelText; // 字段变化 if (key === 'field') { if (currentFieldData?.component !== FormElementEnum.SWITCH) { // 清空条件值 await setFieldsValue({ value: undefined }); labelText = ''; } else { await setFieldsValue({ value: 0 }); labelText = '否'; } } else { // 判断条件和条件值变化 // 当前字段有值集时,component类型为ApiSelect if (currentFieldData?.component === FormElementEnum.API_SELECT) { const fieldVsList = await getVsList(currentFieldData.vsId); labelText = fieldVsList?.find( (item: Recordable) => item.itemValue === form.value, )?.itemText; } else if (currentFieldData?.component === FormElementEnum.SWITCH) { // 当前字段类型为boolean时,component类型为Switch,条件值为开关 labelText = form.value === 1 ? '是' : '否'; } else { // 其他 labelText = form.value; } } conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}${labelText ?? ''}; }简化if语句
可以将 if-else 语句简化为三目运算符,如下所示:
```
conditionName = form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL
? `${fieldLabel ?? ''}${conditionType ?? ''}`
: key === 'field'
? currentFieldData?.component !== FormElementEnum.SWITCH
? (await setFieldsValue({ value: undefined }), '')
: (await setFieldsValue({ value: 0 }), '否')
: currentFieldData?.component === FormElementEnum.API_SELECT
? ((await getVsList(currentFieldData.vsId)), labelText = fieldVsList?.find((item: Recordable) => item.itemValue === form.value)?.itemText)
: currentFieldData?.component === FormElementEnum.SWITCH
? (labelText = form.value === 1 ? '是' : '否')
: (labelText = form.value, '');
```
这样可以减少代码量,使代码更加简洁。
const submitData = async (): Promise<void> => { const result = await formRef?.value?.validate(); const params = { name: formData.value.name || '', type: formData.value.type || '', protemId: formData.value.protemId || '', code: formData.value.code || '', description: formData.value.description || '', planStart: projectDate?.value[0] || '', planEnd: projectDate?.value[1] || '', }; if ( !params?.name || !params?.code || !params?.type || !params?.planStart || !params?.planEnd ) { Message.error('请完整输入项目信息!'); } else
在这段代码中,我们首先通过`formRef?.value?.validate()`来验证表单数据。然后,我们将需要提交的数据存储在`params`对象中。这些数据包括`name`、`type`、`protemId`、`code`、`description`和`planStart`、`planEnd`。接下来,我们通过条件判断语句检查这些数据是否为空。如果有任何一个字段为空,将会显示错误信息"请完整输入项目信息!"。如果所有字段都有值,可以继续执行提交操作。