Browse Source

feat:[模板管理][组件抽离ing]

master
luojie 1 week ago
parent
commit
505c41b4fc
7 changed files with 55 additions and 66 deletions
  1. +0
    -4
      src/components/Template/BaseInfoFormPcakge.vue
  2. +6
    -2
      src/components/Template/CustomTable.vue
  3. +39
    -50
      src/components/Template/DecimalInput.vue
  4. +1
    -1
      src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue
  5. +1
    -1
      src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue
  6. +1
    -1
      src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue
  7. +7
    -7
      src/views/business/comps/template/mixins/templateMixin.js

+ 0
- 4
src/components/Template/BaseInfoFormPcakge.vue View File

@ -182,10 +182,6 @@ export default {
return typeObj[type] || "" return typeObj[type] || ""
}, },
onInputNumberChange(key, val){ onInputNumberChange(key, val){
if(val === 0){
this.formFields[key] = null;
return;
}
this.formFields[key] = val; this.formFields[key] = val;
}, },
updateFormData(key, value){ updateFormData(key, value){

+ 6
- 2
src/components/Template/CustomTable.vue View File

@ -44,7 +44,7 @@
</div> </div>
<div class="m-l-5"> <div class="m-l-5">
<template v-if="col.bodySubType === 'inputNumber' && col.showBodySub"> <template v-if="col.bodySubType === 'inputNumber' && col.showBodySub">
<HandleFormItem type="inputNumber" @copy = "onCopy(rowIndex, col)" :item="getBodySubItem(col)"
<HandleFormItem type="inputNumber" @blur = "onSubBlur(rowIndex, col.bodySubKey, $event)" @copy = "onCopy(rowIndex, col)" :item="getBodySubItem(col)"
v-model="row[col.bodySubKey]" @change="onBodySubValueChange(rowIndex, colIndex, $event)" /> v-model="row[col.bodySubKey]" @change="onBodySubValueChange(rowIndex, colIndex, $event)" />
</template> </template>
<template v-else> <template v-else>
@ -262,7 +262,8 @@ export default {
options: col.bodySubOptions, options: col.bodySubOptions,
maxlength: col.bodySubMaxlength || 10, maxlength: col.bodySubMaxlength || 10,
label: "", label: "",
placeholder:col.bodySubPlaceholder||"请输入"
placeholder:col.bodySubPlaceholder||"请输入",
precision: col.subPrecision || 0,
} }
if(col.bodySubDisabled){ if(col.bodySubDisabled){
item.disabled = col.bodySubDisabled; item.disabled = col.bodySubDisabled;
@ -285,6 +286,9 @@ export default {
console.log(this.localDataSource,"this.localDataSource") console.log(this.localDataSource,"this.localDataSource")
this.localDataSource = [...this.localDataSource]; this.localDataSource = [...this.localDataSource];
}, },
onSubBlur(rowIndex, colKey, value) {
this.$emit("blur", {rowIndex, colKey, value,item:this.localDataSource[rowIndex]});
},
onBlur(rowIndex, colKey) { onBlur(rowIndex, colKey) {
const value = this.localDataSource[rowIndex][colKey]; const value = this.localDataSource[rowIndex][colKey];
this.$emit("blur", {rowIndex, colKey, value,item:this.localDataSource[rowIndex]}); this.$emit("blur", {rowIndex, colKey, value,item:this.localDataSource[rowIndex]});

+ 39
- 50
src/components/Template/DecimalInput.vue View File

@ -1,5 +1,6 @@
<template> <template>
<el-input v-bind="$attrs" v-model="internalValue" @input="handleInput" @blur="handleBlur" :placeholder="placeholder" :disabled="disabled" type="text" >
<el-input v-bind="$attrs" v-model="internalValue" @input="handleInput" @blur="handleBlur" :placeholder="placeholder"
:disabled="disabled" type="text">
<template slot="prepend" v-if="prepend"> <template slot="prepend" v-if="prepend">
{{ prepend }} {{ prepend }}
@ -40,6 +41,7 @@ export default {
watch: { watch: {
value(newVal) { value(newVal) {
// //
console.log(newVal,"newVal")
if (newVal === '' || newVal == null) { if (newVal === '' || newVal == null) {
this.internalValue = ''; this.internalValue = '';
} else { } else {
@ -49,85 +51,72 @@ export default {
}, },
methods: { methods: {
handleInput(val) { handleInput(val) {
console.log(val,"val")
if (val === '') { if (val === '') {
this.internalValue = ''; this.internalValue = '';
this.$emit('input', ''); this.$emit('input', '');
return; return;
} }
// 1.
// 1.
let cleaned = val let cleaned = val
.replace(/[^\d.-]/g, '') .replace(/[^\d.-]/g, '')
.replace(/^(-)\1+/, '$1'); //
.replace(/^(-)\1+/, '$1'); //
// 2.
const dotIndex = cleaned.indexOf('.');
if (dotIndex !== -1) {
const beforeDot = cleaned.slice(0, dotIndex);
const afterDot = cleaned.slice(dotIndex + 1).replace(/\./g, ''); //
cleaned = beforeDot + '.' + afterDot;
// 2.
const firstDotIndex = cleaned.indexOf('.');
if (firstDotIndex !== -1) {
const before = cleaned.slice(0, firstDotIndex);
const after = cleaned.slice(firstDotIndex + 1).replace(/\./g, '');
cleaned = before + '.' + after;
} }
// 3.
// 3.
if (this.decimalDigits > 0 && cleaned.includes('.')) { if (this.decimalDigits > 0 && cleaned.includes('.')) {
const parts = cleaned.split('.');
let integerPart = parts[0];
let decimalPart = parts[1] || '';
//
if (decimalPart.length > this.decimalDigits) {
decimalPart = decimalPart.slice(0, this.decimalDigits);
}
// 使 decimalPart "1."
cleaned = integerPart + '.' + decimalPart;
const [intPart, decPart = ''] = cleaned.split('.');
cleaned = intPart + '.' + decPart.slice(0, this.decimalDigits);
} else if (this.decimalDigits === 0) { } else if (this.decimalDigits === 0) {
//
cleaned = cleaned.split('.')[0];
cleaned = cleaned.split('.')[0]; //
} }
// 4. . -.
if (cleaned === '.') {
cleaned = '0.';
} else if (cleaned === '-.') {
cleaned = '-0.';
} else if (cleaned.startsWith('.')) {
cleaned = '0' + cleaned;
} else if (cleaned.startsWith('-.')) {
cleaned = '-0.' + cleaned.slice(2);
}
// 4. . -.
if (cleaned === '.') cleaned = '0.';
else if (cleaned === '-.') cleaned = '-0.';
else if (cleaned.startsWith('.')) cleaned = '0' + cleaned;
else if (cleaned.startsWith('-.')) cleaned = '-0.' + cleaned.slice(2);
// 5. 0 -0
// 5. 0
if (cleaned.includes('.')) { if (cleaned.includes('.')) {
// 0 -0
const parts = cleaned.split('.');
let intPart = parts[0];
if (intPart === '' || intPart === '-') {
intPart = intPart + '0';
} else if (/^-?0+\d/.test(intPart)) {
// -0012 -120012 12
intPart = intPart.replace(/^-?0+(\d)/, '$1');
//
const [int, dec] = cleaned.split('.');
// -0012 -1200 00 0-0 0 -0
let newInt = int;
if (/^-?0+\d/.test(int)) {
newInt = int.replace(/^-?0+(\d)/, '$1');
} else if (int === '' || int === '-') {
newInt = int + '0';
} else if (int === '00' || /^-00+$/.test(int)) {
newInt = int.startsWith('-') ? '-0' : '0';
} }
cleaned = intPart + '.' + parts[1];
cleaned = newInt + '.' + dec;
} else { } else {
// //
if (/^-?0+\d/.test(cleaned)) { if (/^-?0+\d/.test(cleaned)) {
cleaned = cleaned.replace(/^-?0+(\d)/, '$1'); cleaned = cleaned.replace(/^-?0+(\d)/, '$1');
} else if (cleaned === '00' || /^-00+$/.test(cleaned)) {
cleaned = cleaned.startsWith('-') ? '-0' : '0';
} }
// '0' ''
} }
this.internalValue = cleaned; this.internalValue = cleaned;
// emit '-'
// emit
if (cleaned === '' || cleaned === '-') { if (cleaned === '' || cleaned === '-') {
this.$emit('input', cleaned === '-' ? '-' : ''); this.$emit('input', cleaned === '-' ? '-' : '');
} else { } else {
const num = parseFloat(cleaned); const num = parseFloat(cleaned);
if (!isNaN(num)) {
this.$emit('input', num);
} else {
this.$emit('input', '');
}
console.log(num,isNaN(num),"num")
this.$emit('input', isNaN(num) ? '' : num);
} }
}, },

+ 1
- 1
src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue View File

@ -479,7 +479,7 @@ export default {
const stepFormData = await this.$refs.stepFormPackageRef.getFormData(); const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepDataFormData = await this.$refs.stepTableRef.getFormData(); const stepDataFormData = await this.$refs.stepTableRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData(); const stepData = await this.$refs.stepRef.getFormData();
if (!stepData.length) {
if (!stepData.stepData.length) {
this.$message.error("请添加步骤"); this.$message.error("请添加步骤");
return; return;
} }

+ 1
- 1
src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue View File

@ -261,7 +261,7 @@ export default {
const conditionData = await this.$refs.storageConditionRef.getFormData(); const conditionData = await this.$refs.storageConditionRef.getFormData();
const stepFormData = await this.$refs.stepFormPackageRef.getFormData(); const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData(); const stepData = await this.$refs.stepRef.getFormData();
if (!stepData.length) {
if (!stepData.stepData.length) {
this.$message.error("请添加步骤"); this.$message.error("请添加步骤");
return; return;
} }

+ 1
- 1
src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue View File

@ -275,7 +275,7 @@ export default {
const conditionData = await this.$refs.storageConditionRef.getFormData(); const conditionData = await this.$refs.storageConditionRef.getFormData();
const stepFormData = await this.$refs.stepFormPackageRef.getFormData(); const stepFormData = await this.$refs.stepFormPackageRef.getFormData();
const stepData = await this.$refs.stepRef.getFormData(); const stepData = await this.$refs.stepRef.getFormData();
if (!stepData.length) {
if (!stepData.stepData.length) {
this.$message.error(this.$t('template.common.addStepError')); this.$message.error(this.$t('template.common.addStepError'));
return; return;
} }

+ 7
- 7
src/views/business/comps/template/mixins/templateMixin.js View File

@ -84,21 +84,21 @@ export default {
}, },
onHandleTableBlur(params){ onHandleTableBlur(params){
const {rowIndex, colKey, value,item} = params; const {rowIndex, colKey, value,item} = params;
if(colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration"){//预设起始溶液体积:(目标溶液预计浓度 乘以 目标溶液预计体积)除以 起始溶液浓度
console.log(rowIndex, colKey, value,item, "params")
if(colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration" || colKey === "targetStartSolutionVolumePrecision" || colKey === "targetDiluentVolumePrecision"){//预设起始溶液体积:(目标溶液预计浓度 乘以 目标溶液预计体积)除以 起始溶液浓度
const volume = this.$refs.stepFormPackageRef.getFormDataByKey("targetStartSolution") || 0; const volume = this.$refs.stepFormPackageRef.getFormDataByKey("targetStartSolution") || 0;
const precision = item.targetStartSolutionVolumePrecision || 0; const precision = item.targetStartSolutionVolumePrecision || 0;
if(volume){ if(volume){
const concentration = item.targetSolutionConcentration || 0; const concentration = item.targetSolutionConcentration || 0;
const targetVolume = item.targetSolutionVolume || 0; const targetVolume = item.targetSolutionVolume || 0;
const result = ((concentration * targetVolume) / volume).toFixed(precision); const result = ((concentration * targetVolume) / volume).toFixed(precision);
console.log(result,"reee")
this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetStartSolutionVolume:result}); this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetStartSolutionVolume:result});
if(targetVolume){//预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
const precision1 = item.targetDiluentVolumePrecision || 0;
const result1 = (targetVolume - result).toFixed(precision1);
this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetDiluentVolume:result1});
}
} }
}else if(colKey ==="targetSolutionVolume" || colKey === "targetDiluentVolume"){//预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
// const targetVolume = item.targetSolutionVolume || 0;
// const targetDiluentVolume = item.targetDiluentVolume || 0;
// const result = (targetVolume - targetDiluentVolume).toFixed(precision);
// this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex,{targetDiluentVolume:result});
} }
} }

Loading…
Cancel
Save