Browse Source

feat:[模板管理][update]

lkf
luojie 2 months ago
parent
commit
f04e3f1a45
6 changed files with 141 additions and 35 deletions
  1. +5
    -5
      src/components/Template/HandleFormItem.vue
  2. +130
    -28
      src/components/Template/mixins/formPackageMixins.js
  3. +1
    -0
      src/lang/en/template/commonTemplate.js
  4. +1
    -0
      src/lang/zh/template/commonTemplate.js
  5. +1
    -0
      src/views/business/comps/template/TemplateTable.vue
  6. +3
    -2
      src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue

+ 5
- 5
src/components/Template/HandleFormItem.vue View File

@ -190,11 +190,11 @@ export default {
value(newVal) { value(newVal) {
this.inputValue = newVal; this.inputValue = newVal;
// typeclickable // typeclickable
if (this.item.type === 'clickable') {
this.$nextTick(() => {
this.onCommonHandleSaveRecord(newVal);
});
}
// if (this.item.type === 'clickable') {
// this.$nextTick(() => {
// this.onCommonHandleSaveRecord(newVal);
// });
// }
} }
}, },
filters: { filters: {

+ 130
- 28
src/components/Template/mixins/formPackageMixins.js View File

@ -1,7 +1,10 @@
import { isEqual } from "@/utils/index.js";
import _ from "lodash"; import _ from "lodash";
import { getuuid, isEqual } from "@/utils/index.js";
import { EventBus } from "@/utils/eventBus";
import moment from "moment";
export default { export default {
watch: {
inject: ["getZdxgjl", "updateZdxgjl"],
watch: {
formData: { formData: {
immediate: true, immediate: true,
deep: true, // 深度监听,以便检测嵌套对象变化 deep: true, // 深度监听,以便检测嵌套对象变化
@ -16,7 +19,7 @@ export default {
deep: true, // 深度监听,以便检测嵌套对象变化 deep: true, // 深度监听,以便检测嵌套对象变化
handler(v) { handler(v) {
if (v) { if (v) {
console.log(v,"fieldItemLabel")
console.log(v, "fieldItemLabel")
} }
} }
}, },
@ -28,15 +31,62 @@ export default {
} }
} }
}, },
data() {
return {
uuid: getuuid(),
}
},
mounted() { mounted() {
this.handleFormField(); this.handleFormField();
EventBus.$on('onEditSignCallback', this.handleEditSignCallback);
EventBus.$on('onFormEditSignCancel', this.handleEditSignCancel);
}, },
unmounted() { unmounted() {
this.formFields = {};//清空当前填写的数据 this.formFields = {};//清空当前填写的数据
EventBus.$off('onEditSignCallback', this.handleEditSignCallback);
EventBus.$off('onFormEditSignCancel', this.handleEditSignCancel);
}, },
methods: { methods: {
handleClickButton(key){
getRecords() {
const records = [];
const { nickName, name } = this.$store.getters;
const { oldFormFields, formFields, allFieldsConfig, prefixKey, fieldItemLabel } = this;
Object.keys(oldFormFields).forEach(key => {
const item = allFieldsConfig[key];
const { label } = item;
const oldValue = oldFormFields[key];;
const newValue = formFields[key];
let fieldLabelCn = this.$i18n.t(label, "zh_CN"), fieldLabelEn = this.$i18n.t(label, "en_US");
if (!isEqual(oldValue, newValue)) {
const record = {
userNameCn: nickName,
userNameEn: name,
key: prefixKey + "_" + key,
fieldCn: `${this.$i18n.t(fieldItemLabel, "zh_CN")}` + (fieldLabelCn ? ("-" + fieldLabelCn) : ""),
fieldEn: `${this.$i18n.t(fieldItemLabel, "en_US")}` + (fieldLabelEn ? ("-" + fieldLabelEn) : ""),
oldValue: oldValue,
value: newValue,
title: oldValue ? "修改" : "提交",
time: moment().format("YYYY-MM-DD HH:mm:ss"),
}
this.updateZdxgjl(record);
records.push(record);
}
})
return records;
},
handleEditSignCancel(data) {
if (data.uuid === this.uuid) {
this.resetRecord();
}
},
handleEditSignCallback(data) {
if (data.uuid === this.uuid) {
this.updateRecord();
}
},
handleClickButton(key) {
this.$emit("clickButton", key) this.$emit("clickButton", key)
}, },
getFillType(type) { getFillType(type) {
@ -54,32 +104,84 @@ export default {
this.$set(this.errors, key, false); this.$set(this.errors, key, false);
} }
}, },
//批量更新表单数据
batchUpdateFormData(data) {
const cloneFormFields = JSON.parse(JSON.stringify(this.formFields));
Object.keys(data).forEach(key => {
this.oldFormFields[key] = cloneFormFields[key];
this.formFields[key] = data[key];
// 清除该表单项的错误状态
if (this.errors[key]) {
this.$set(this.errors, key, false);
}
})
this.showEditSignDialog();
},
//更新表单数据 //更新表单数据
updateFormData(key, value) { updateFormData(key, value) {
// 深拷贝当前表单数据,避免直接修改原数据 // 深拷贝当前表单数据,避免直接修改原数据
const cloneFormFields = JSON.parse(JSON.stringify(this.formFields)); const cloneFormFields = JSON.parse(JSON.stringify(this.formFields));
this.oldFormFields[key] = cloneFormFields[key]; this.oldFormFields[key] = cloneFormFields[key];
this.updateRecord();
this.showEditSignDialog();
this.formFields[key] = value; this.formFields[key] = value;
// 清除该表单项的错误状态 // 清除该表单项的错误状态
if (this.errors[key]) { if (this.errors[key]) {
this.$set(this.errors, key, false); this.$set(this.errors, key, false);
} }
}, },
updateRecord:_.debounce(function(){
console.log(this.oldFormFields,"oldFormFields")
updateRecord() {
const records = this.getRecords();
const params = {
type: "fieldChanged",
newRecord: records,
resourceList: this.getZdxgjl(),
}
setTimeout(() => {
EventBus.$emit('onModifyRecord', params,)
}, 0);
},
//更新记录
showEditSignDialog: _.debounce(function () {
//如果oldFormFields中存在空值,说明是第一次填写,直接更新记录
const flag = Object.values(this.oldFormFields).some(item => !item);
if (flag) {
this.updateRecord();
}else{
const diff = this.compareOldAndCurrentFormFields();
if (!diff) {
setTimeout(() => {//延迟200ms打开弹窗,避免弹窗打开时,会有闪烁
EventBus.$emit('showEditSignDialog', { uuid: this.uuid });
}, 200);
}
}
}, 100), }, 100),
//批量更新表单数据
batchUpdateFormData(data) {
Object.keys(data).forEach(key => {
this.formFields[key] = data[key];
// 清除该表单项的错误状态
if (this.errors[key]) {
this.$set(this.errors, key, false);
// 比较oldFormFields和formFields的值是否相等,只要有一对不相等就返回false
compareOldAndCurrentFormFields() {
// 遍历oldFormFields,检查每个键值对
for (const key in this.oldFormFields) {
if (this.oldFormFields.hasOwnProperty(key)) {
const oldValue = this.oldFormFields[key];
const currentValue = this.formFields[key];
// 检查当前formFields中是否也包含此key,且值是否相等
if (this.formFields.hasOwnProperty(key)) {
// 比较值是否相等
if (JSON.stringify(oldValue) !== JSON.stringify(currentValue)) {
return false;
}
} else {
// 如果formFields中没有此key,说明不相等
return false;
}
} }
})
}
return true;
}, },
handleClickable(sItem, event) { handleClickable(sItem, event) {
if (this.templateFillType !== 'actFill') { if (this.templateFillType !== 'actFill') {
return return
@ -170,13 +272,13 @@ export default {
} }
config[subKey] = { label: currentConfig.label, subKey, type: currentConfig.subType, fillType: currentConfig.subFillType || currentConfig.fillType, selectTo: currentConfig.selectTo } config[subKey] = { label: currentConfig.label, subKey, type: currentConfig.subType, fillType: currentConfig.subFillType || currentConfig.fillType, selectTo: currentConfig.selectTo }
} }
// 检查compareTo字段 // 检查compareTo字段
if (currentConfig.compareTo && formData[currentConfig.compareTo] && result[key]) { if (currentConfig.compareTo && formData[currentConfig.compareTo] && result[key]) {
const compareToValue = formData[currentConfig.compareTo]; const compareToValue = formData[currentConfig.compareTo];
const currentValue = result[key]; const currentValue = result[key];
this.compareFieldsIsEqual(currentValue,compareToValue,key)
this.compareFieldsIsEqual(currentValue, compareToValue, key)
} }
}); });
@ -191,10 +293,10 @@ export default {
this.allFieldsConfig = config; this.allFieldsConfig = config;
}, },
//比较值是否相等 //比较值是否相等
compareFieldsIsEqual(currentValue,compareToValue,key) {
if(!currentValue || !compareToValue) return;
compareFieldsIsEqual(currentValue, compareToValue, key) {
if (!currentValue || !compareToValue) return;
// 如果当前值与compareTo字段的值不相等,则设置橙色背景 // 如果当前值与compareTo字段的值不相等,则设置橙色背景
if (isEqual(currentValue,compareToValue)) {
if (isEqual(currentValue, compareToValue)) {
// 如果相等,移除橙色背景(如果之前设置了的话) // 如果相等,移除橙色背景(如果之前设置了的话)
this.$set(this.orangeBgFields, key, false); this.$set(this.orangeBgFields, key, false);
} else { } else {
@ -245,7 +347,7 @@ export default {
continue continue
} }
//span的字段不校验 //span的字段不校验
if (o.type === "span" || o.type ==="text" || o.type === "button") {
if (o.type === "span" || o.type === "text" || o.type === "button") {
continue continue
} }
if (o.fillType === this.templateFillType && !o.disabled) { if (o.fillType === this.templateFillType && !o.disabled) {
@ -267,7 +369,7 @@ export default {
} }
} }
} }
console.log(errors,"errors")
console.log(errors, "errors")
return { return {
valid: errors.length === 0, valid: errors.length === 0,
errors: errors errors: errors
@ -317,13 +419,13 @@ export default {
if (currentFieldConfig && currentFieldConfig.fillType === "actFill" && (currentFieldConfig.compareTo || compKey)) { if (currentFieldConfig && currentFieldConfig.fillType === "actFill" && (currentFieldConfig.compareTo || compKey)) {
const compareToKey = compKey || currentFieldConfig.compareTo; const compareToKey = compKey || currentFieldConfig.compareTo;
const compareToValue = this.formFields[compareToKey]; const compareToValue = this.formFields[compareToKey];
this.compareFieldsIsEqual(val,compareToValue,key);
this.compareFieldsIsEqual(val, compareToValue, key);
} }
}, },
onSelectChange(key, val, type) { onSelectChange(key, val, type) {
// 获取对应的配置 // 获取对应的配置
const currentConfig = this.allFieldsConfig[key]; const currentConfig = this.allFieldsConfig[key];
if(currentConfig.selectTo){
if (currentConfig.selectTo) {
this.formFields[currentConfig.selectTo] = val; this.formFields[currentConfig.selectTo] = val;
} }
this.onValueChangeCompareTo(key, val); this.onValueChangeCompareTo(key, val);
@ -342,8 +444,8 @@ export default {
this.onBlur(key, formFields[key]); this.onBlur(key, formFields[key]);
} }
}, },
resetRecord(key){
this.formFields = {...this.formFields, ...this.oldFormFields};
resetRecord(key) {
this.formFields = { ...this.formFields, ...this.oldFormFields };
this.oldFormFields = {}; this.oldFormFields = {};
this.$emit("resetRecord"); this.$emit("resetRecord");
}, },

+ 1
- 0
src/lang/en/template/commonTemplate.js View File

@ -9,6 +9,7 @@ export default {
storageCondition: 'Storage Conditions', storageCondition: 'Storage Conditions',
operationSteps: 'Operation Workflow', operationSteps: 'Operation Workflow',
remark: 'Comments', remark: 'Comments',
step: 'Step',
// 字段标签 // 字段标签
storageConditionLabel: 'Storage Condition', storageConditionLabel: 'Storage Condition',

+ 1
- 0
src/lang/zh/template/commonTemplate.js View File

@ -8,6 +8,7 @@ export default {
instrumentInfo: '仪器使用信息', instrumentInfo: '仪器使用信息',
storageCondition: '存储条件', storageCondition: '存储条件',
operationSteps: '操作步骤', operationSteps: '操作步骤',
step: '步骤',
remark: '备注', remark: '备注',
// 字段标签 // 字段标签

+ 1
- 0
src/views/business/comps/template/TemplateTable.vue View File

@ -209,6 +209,7 @@ export default {
handleEditSignCancel() { handleEditSignCancel() {
if (this.currentEditSignUuid) { if (this.currentEditSignUuid) {
EventBus.$emit('onEditSignCancel', { uuid: this.currentEditSignUuid }); EventBus.$emit('onEditSignCancel', { uuid: this.currentEditSignUuid });
EventBus.$emit('onFormEditSignCancel', { uuid: this.currentEditSignUuid });
this.currentEditSignUuid = null; this.currentEditSignUuid = null;
} }
}, },

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

@ -15,6 +15,7 @@
<LineLabel label="template.common.operationSteps" /> <LineLabel label="template.common.operationSteps" />
<div class="template-form-item"> <div class="template-form-item">
<BaseInfoFormPackage @clickable="handleClickable" ref="stepFormPackageRef" <BaseInfoFormPackage @clickable="handleClickable" ref="stepFormPackageRef"
fieldItemLabel="template.common.operationSteps"
@resetRecord="resetRecord" :formConfig="stepFormConfig" @blur="onHandleBlur" @resetRecord="resetRecord" :formConfig="stepFormConfig" @blur="onHandleBlur"
:formData="formData" /> :formData="formData" />
<CustomTable fieldItemLabel="template.common.operationSteps" @blur="onHandleTableBlur" <CustomTable fieldItemLabel="template.common.operationSteps" @blur="onHandleTableBlur"
@ -28,7 +29,7 @@
</template> </template>
</CustomTable> </CustomTable>
</div> </div>
<Step ref="stepRef" :formData="formData.stepData"></Step>
<Step ref="stepRef" fieldItemLabel="template.common.step" :formData="formData.stepData"></Step>
<BaseInfoFormPackage fieldItemLabel="template.common.remark" label="template.common.remark" <BaseInfoFormPackage fieldItemLabel="template.common.remark" label="template.common.remark"
ref="remarkRef" :formConfig="remarkConig" :formData="formData" /> ref="remarkRef" :formConfig="remarkConig" :formData="formData" />
@ -517,8 +518,8 @@ export default {
this.$refs.stepFormPackageRef.updateFormData("targetAcSolution", row.nd); this.$refs.stepFormPackageRef.updateFormData("targetAcSolution", row.nd);
this.updateStepTableData(row); this.updateStepTableData(row);
} }
this.$refs.stepFormPackageRef.updateFormData(this.currentSubKey, code);
this.$refs.selectReagentDialogRef.onCancel() this.$refs.selectReagentDialogRef.onCancel()
this.$refs.stepFormPackageRef.updateFormData(this.currentSubKey, code);
}, },
//table //table
updateStepTableData(row) { updateStepTableData(row) {

Loading…
Cancel
Save