formatDiscriptionBase(form) { const chargeContainModel = this.optionContain[form.chargeContainModel].label; const maxDailyFee = this.dialogForm.maxDailyFee; const chargeType = this.optionTypes[this.dialogForm.chargeType].label; const freeDuration = form.freeDuration; const amountDescriptions = [ "免费时段收费金额+首时段收费金额+超过首时段的收费金额", "首时段收费金额+超过首时段的收费金额", "免费时段收费金额+超过首时段的收费金额", "超过首时段的收费金额", ]; const amount = amountDescriptions[form.chargeContainModel]; const template = `计费包含:${chargeContainModel} 单日最高收费:${maxDailyFee}元 计费设置:${chargeType} 免费时长:${freeDuration}分钟 收费金额:${amount}`; return template; },
时间: 2024-02-15 14:28:51 浏览: 23
] = 0x08; data[1] = 0x00;
I2C_WriteBuffer(I2C2, WM869这段代码看起来像是 Vue.js 中的一个方法,它接收一个参数 `form`,并返回一个字符串模0_I2C_ADDR << 1, data, 2);
data[0] = 0x09; data[1] =板。在模板中,它使用了 `const` 声明了一些变量,这些变量来自于在 0x3F;
I2C_WriteBuffer(I2C2, WM8690_I2C_ADDR << 1, data, Vue.js 组件中定义的一些选项,比如 `optionContain` 和 `optionTypes`。最终模板的内容 2);
data[0] = 0x0A; data[1] = 0x02;
I2C_WriteBuffer包括了计费包含、单日最高收费、计费设置、免费时长和收费金额等信息(I2C2, WM8690_I2C_ADDR << 1, data, 2);
data[0] = 0x。这段代码的作用是将这些选项的值组合成一个易于阅读的字符串模板,供用户查看。
相关问题
formatDiscription() { const chargeContainModel = this.optionContain[this.wholeDayForm.chargeContainModel].label; //24小时计费包含 const maxDailyFee = this.dialogForm.maxDailyFee; const chargeType = this.optionTypes[this.dialogForm.chargeType].label; //计费类型 const freeDuration = this.wholeDayForm.freeDuration; //免费时长 const amountDescriptions = [ "免费时段收费金额+首时段收费金额+超过首时段的收费金额", "首时段收费金额+超过首时段的收费金额", "免费时段收费金额+超过首时段的收费金额", "超过首时段的收费金额", ]; const amount = amountDescriptions[this.wholeDayForm.chargeContainModel]; //计费包含 const template = `计费包含:${chargeContainModel} 收费限额:${maxDailyFee}元 计费设置:${chargeType} 免费时长:${freeDuration}分钟 收费金额:${amount}`; return template; },
这段代码是一个名为`formatDiscription()`的函数,它接收一些表单数据,然后将这些数据格式化成一个字符串模板并返回。具体来说,它会获取`chargeContainModel`(24小时计费包含)、`maxDailyFee`(收费限额)、`chargeType`(计费类型)、`freeDuration`(免费时长)和`amount`(收费金额),并将它们插入到一个字符串模板中,最后返回该模板。
// 获取表单值 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, '');
```
这样可以减少代码量,使代码更加简洁。