Browse Source

feat:[模板管理][yp003]

ouqian
luojie 1 month ago
parent
commit
40df78ab90
2 changed files with 123 additions and 89 deletions
  1. +27
    -15
      src/components/Template/CustomTable.vue
  2. +96
    -74
      src/components/Template/HandleFormItem.vue

+ 27
- 15
src/components/Template/CustomTable.vue View File

@ -110,17 +110,18 @@
</div> </div>
</template> </template>
<template v-else-if="col.bodyType === 'checkboxTag'"> <template v-else-if="col.bodyType === 'checkboxTag'">
<div class="flex flex-wrap"
:class="{ 'row-error-border': hasError(rowIndex, colIndex, col.prop) }">
<HandleFormItem v-for="(tag, tagIndex) in row[col.prop]" :key="tagIndex"
:fieldKey="prefixKey + '_' + col.prop + '_' + rowIndex + '_' + tagIndex"
:fieldItemLabel="fieldItemLabel" type="checkboxTag" :value="tag"
:item="getBodyItem(col, rowIndex)"
@change="onCheckboxTagChange(rowIndex, colIndex,col, tagIndex, $event)"
@deleteTag="onDeleteCheckboxTag(rowIndex, col, tagIndex)" />
</div>
</template>
<div class="flex flex-wrap" :class="{ 'row-error-border': hasError(rowIndex, colIndex, col.prop) }">
<HandleFormItem
:fieldKey="prefixKey + '_' + col.prop + '_' + rowIndex"
:fieldItemLabel="fieldItemLabel" type="checkboxTag"
:value="row[col.prop]"
:item="getBodyItem(col, rowIndex)"
@change="onCheckboxTagChange(rowIndex, colIndex, col, $event)"
@deleteTag="onDeleteCheckboxTag(rowIndex, col, $event)"
:error="hasError(rowIndex, colIndex, col.prop)"
@update:error="onErrorUpdate(rowIndex, colIndex, col.prop, $event)" />
</div>
</template>
</div> </div>
<div v-show="isShowOther(row[col.prop], col)" class="flex flex1"> <div v-show="isShowOther(row[col.prop], col)" class="flex flex1">
@ -324,11 +325,21 @@ export default {
this.$emit("onDeleteTag", rowIndex, col, tagIndex); this.$emit("onDeleteTag", rowIndex, col, tagIndex);
this.justUpdateFilledFormData(); this.justUpdateFilledFormData();
}, },
onCheckboxTagChange(rowIndex, colIndex, col, tagIndex, value) {
onCheckboxTagChange(rowIndex, colIndex, col, value) {
console.log(value,"vvv") console.log(value,"vvv")
this.localDataSource[rowIndex][col.prop][tagIndex] = value;
this.onErrorUpdate(rowIndex, colIndex, col.prop, value?false:true);
this.$emit("onCheckboxTagChange", rowIndex, col, this.localDataSource[rowIndex][col.prop])
// value
this.localDataSource[rowIndex][col.prop] = value;
//
let isValid = false;
if (this.templateFillType === "actFill") {
// actFillcheckedtrue
isValid = value && value.some(tag => tag.checked === true);
} else if (this.templateFillType === "preFill") {
// preFilltagValue
isValid = value && value.every(tag => tag.tagValue && tag.tagValue.trim() !== '');
}
this.onErrorUpdate(rowIndex, colIndex, col.prop, !isValid);
this.$emit("onCheckboxTagChange", rowIndex, col, value)
}, },
handleClickButton(e, data, key, rowIndex, colIndex) { handleClickButton(e, data, key, rowIndex, colIndex) {
this.$emit("clickButton", key, rowIndex, colIndex, e, data,) this.$emit("clickButton", key, rowIndex, colIndex, e, data,)
@ -766,6 +777,7 @@ export default {
this.localDataSource[rowIndex] = { ...this.localDataSource[rowIndex], ...data }; this.localDataSource[rowIndex] = { ...this.localDataSource[rowIndex], ...data };
this.localDataSource = [...this.localDataSource]; this.localDataSource = [...this.localDataSource];
this.checkCompareToOnDataLoad(); this.checkCompareToOnDataLoad();
this.justUpdateFilledFormData();
}, },
// newDataoldDatafalse // newDataoldDatafalse
compareOldAndCurrentFormFields(newData, oldData) { compareOldAndCurrentFormFields(newData, oldData) {

+ 96
- 74
src/components/Template/HandleFormItem.vue View File

@ -87,24 +87,25 @@
<div slot="tip" class="el-upload__tip">支持扩展名.rar .zip .doc .docx .pdf .jpg文件大小不超过2MB</div> <div slot="tip" class="el-upload__tip">支持扩展名.rar .zip .doc .docx .pdf .jpg文件大小不超过2MB</div>
</el-upload> </el-upload>
</template> </template>
<div v-else-if="type === 'checkboxTag'" class="flex1 checkbox-tag-container"
:class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')">
<div class="checkbox-tag-item">
<el-checkbox v-model="checkboxTagChecked" :disabled="getDisabled()"
@change="onCheckboxTagChange"></el-checkbox>
<div class="tag-content blue-border">
<el-input v-if="templateFillType === 'preFill'" v-model="tagValue" ref="tagInput"
:maxlength="item.maxlength || 20" @blur="onTagBlur" @keyup.enter.native="onTagBlur"
placeholder="请输入" size="mini" class="tag-input" />
<el-tag v-else :type="'info'" class="tag-display" :closable="false">
{{ tagValue }}
</el-tag>
<el-popconfirm confirm-button-text='确认' cancel-button-text='取消' icon="el-icon-info"
icon-color="red" title="确认删除当前编号?" @confirm="onDeleteTag">
<i slot="reference" v-if="templateFillType === 'preFill'"
class="el-icon-close delete-icon"></i>
</el-popconfirm>
<div v-else-if="type === 'checkboxTag'" class="flex1 checkbox-tag-wrapper" :class="getFillTypeStyle() + (orangeBg ? ' orange-bg' : '')">
<div v-for="(tag, tagIndex) in checkboxTagList" :key="tagIndex" class="checkbox-tag-container">
<div class="checkbox-tag-item">
<el-checkbox v-model="tag.checked" :disabled="getDisabled()"
@change="onCheckboxTagChange(tagIndex, $event)"></el-checkbox>
<div class="tag-content blue-border">
<el-input v-if="templateFillType === 'preFill'" v-model="tag.tagValue"
:ref="'tagInput_' + tagIndex" :maxlength="item.maxlength || 20"
@blur="onTagBlur(tagIndex)" @keyup.enter.native="onTagBlur(tagIndex)"
placeholder="请输入" size="mini" class="tag-input" />
<el-tag v-else :type="'info'" class="tag-display" :closable="false">
{{ tag.tagValue }}
</el-tag>
<el-popconfirm confirm-button-text='确认' cancel-button-text='取消' icon="el-icon-info"
icon-color="red" title="确认删除当前编号?" @confirm="onDeleteTag(tagIndex)">
<i slot="reference" v-if="templateFillType === 'preFill'"
class="el-icon-close delete-icon"></i>
</el-popconfirm>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -237,7 +238,7 @@ export default {
}, },
data() { data() {
let initialValue = this.value; let initialValue = this.value;
let initialOtherValues = {}, checkboxTagChecked = false, tagValue = '';
let initialOtherValues = {}, checkboxTagList = [];
// checkboxListvalue // checkboxListvalue
if (this.type === 'checkboxList' && this.value && typeof this.value === 'object') { if (this.type === 'checkboxList' && this.value && typeof this.value === 'object') {
@ -245,10 +246,13 @@ export default {
initialOtherValues = this.value.otherValues || {}; initialOtherValues = this.value.otherValues || {};
} else if (this.type === 'checkboxList' && !Array.isArray(this.value)) { } else if (this.type === 'checkboxList' && !Array.isArray(this.value)) {
initialValue = []; initialValue = [];
} else if (this.type === 'checkboxTag' && this.value && typeof this.value === 'object') {
checkboxTagChecked = this.value.checked;
tagValue = this.value.tagValue || '';
}
} else if (this.type === 'checkboxTag' && Array.isArray(this.value)) {
// checkboxTagvalue
checkboxTagList = this.value.map(tag => ({
checked: tag.checked,
tagValue: tag.tagValue || ''
}));
}
return { return {
inputValue: initialValue, inputValue: initialValue,
oldValue: initialValue, // oldValue: initialValue, //
@ -263,9 +267,8 @@ export default {
replyContent: '', // replyContent: '', //
visible: false,// visible: false,//
checkboxValue: this.getChecked(),// checkboxValue: this.getChecked(),//
checkboxTagChecked: checkboxTagChecked, // checkboxTagcheckbox
oldCheckboxTagChecked: checkboxTagChecked, // checkboxTagcheckbox
tagValue: tagValue, // checkboxTagtag
checkboxTagList: checkboxTagList, // checkboxTag
oldCheckboxTagList: JSON.parse(JSON.stringify(checkboxTagList)), // checkboxTagList
uuid: getuuid(), // EventBus uuid: getuuid(), // EventBus
regentType: ['sj', 'gsp', 'mix', 'xj', 'xb', 'gyzj', 'mjy', 'yq', 'jcb', 'qxbd'], //// regentType: ['sj', 'gsp', 'mix', 'xj', 'xb', 'gyzj', 'mjy', 'yq', 'jcb', 'qxbd'], ////
selectRegentInfo: {},//// selectRegentInfo: {},////
@ -276,6 +279,7 @@ export default {
}, },
pendingUploadFile: null, // pendingUploadFile: null, //
pendingRemoveFile: null, // pendingRemoveFile: null, //
currentTagIndex:-1,//checkboxTag
} }
}, },
watch: { watch: {
@ -284,10 +288,13 @@ export default {
if (this.type === 'checkboxList' && newVal && typeof newVal === 'object') { if (this.type === 'checkboxList' && newVal && typeof newVal === 'object') {
this.inputValue = newVal.checkboxValues || []; this.inputValue = newVal.checkboxValues || [];
this.otherValues = newVal.otherValues || {}; this.otherValues = newVal.otherValues || {};
} else if (this.type === 'checkboxTag' && newVal && typeof newVal === 'object') {
this.checkboxTagChecked = newVal.checked || false;
this.tagValue = newVal.tagValue || '';
} else {
} else if (this.type === 'checkboxTag' && Array.isArray(newVal)) {
// checkboxTagvalue
this.checkboxTagList = newVal.map(tag => ({
checked: tag.checked,
tagValue: tag.tagValue || ''
}));
} else {
this.inputValue = this.type === 'checkboxList' && !Array.isArray(newVal) ? [] : newVal; this.inputValue = this.type === 'checkboxList' && !Array.isArray(newVal) ? [] : newVal;
} }
} }
@ -808,30 +815,33 @@ export default {
this.onInputChange(); this.onInputChange();
}, },
// checkboxTagcheckbox // checkboxTagcheckbox
onCheckboxTagChange(e) {
this.checkboxTagChecked = e;
onCheckboxTagChange(tagIndex, e) {
this.currentTagIndex = tagIndex;
this.checkboxTagList[tagIndex].checked = e;
this.emitCheckboxTagValue(); this.emitCheckboxTagValue();
this.onCommonHandleSaveRecord(); this.onCommonHandleSaveRecord();
}, },
// tag // tag
onTagBlur(e) {
const value = e.target.value;
this.tagValue = value;
onTagBlur(tagIndex) {
this.currentTagIndex = tagIndex;
const value = this.checkboxTagList[tagIndex].tagValue;
this.emitCheckboxTagValue(); this.emitCheckboxTagValue();
this.onCommonHandleSaveRecord(this.tagValue);
this.onCommonHandleSaveRecord(value);
}, },
// tag // tag
onDeleteTag() {
this.$emit("deleteTag");
onDeleteTag(tagIndex) {
this.currentTagIndex = tagIndex;
// tag
this.checkboxTagList.splice(tagIndex, 1);
this.emitCheckboxTagValue();
this.$emit("deleteTag", tagIndex);
}, },
// checkboxTag // checkboxTag
emitCheckboxTagValue() { emitCheckboxTagValue() {
const value = {
checked: this.checkboxTagChecked,
tagValue: this.tagValue
};
this.inputValue = value;
//
this.$emit('input', [...this.checkboxTagList]);
this.$emit('change', [...this.checkboxTagList]);
}, },
// //
onBlur(e) { onBlur(e) {
@ -916,8 +926,12 @@ export default {
isSame = this.isEqual(this.oldOtherValues, this.otherValues); isSame = this.isEqual(this.oldOtherValues, this.otherValues);
isOldValueEmpty = this.isValueEmpty(this.oldOtherValues); isOldValueEmpty = this.isValueEmpty(this.oldOtherValues);
} else if (this.type === "checkboxTag") { } else if (this.type === "checkboxTag") {
isSame = this.isEqual(this.oldCheckboxTagChecked, this.checkboxTagChecked);
isOldValueEmpty = this.isValueEmpty(this.oldCheckboxTagChecked);
// checkboxTagtagIndex
const currentTag = this.checkboxTagList[this.currentTagIndex];
const oldTag = this.oldCheckboxTagList[this.currentTagIndex] || {};
isSame = this.isEqual(oldTag.checked, currentTag.checked);
isOldValueEmpty = this.isValueEmpty(oldTag.checked);
}else{ }else{
isSame = this.isEqual(this.oldValue, this.inputValue) isSame = this.isEqual(this.oldValue, this.inputValue)
isOldValueEmpty = this.isValueEmpty(this.oldValue); isOldValueEmpty = this.isValueEmpty(this.oldValue);
@ -942,11 +956,17 @@ export default {
checkboxValues: oldValue.checkboxValues || oldValue, checkboxValues: oldValue.checkboxValues || oldValue,
otherValues: this.oldOtherValues otherValues: this.oldOtherValues
}; };
}else if(this.type === "checkboxTag"){
oldValue = {
checked: this.oldCheckboxTagChecked,
tagValue: this.tagValue,
};
} else if (this.type === "checkboxTag") {
// checkboxTag退tagIndex
if (this.currentTagIndex >= 0 && this.currentTagIndex < this.oldCheckboxTagList.length) {
const oldTag = this.oldCheckboxTagList[this.currentTagIndex];
this.checkboxTagList[this.currentTagIndex] = { ...oldTag };
oldValue = [...this.checkboxTagList];
} else {
// tagIndex退
this.checkboxTagList = JSON.parse(JSON.stringify(this.oldCheckboxTagList));
oldValue = [...this.checkboxTagList];
}
} }
this.inputValue = this.oldValue; this.inputValue = this.oldValue;
this.$emit('input', oldValue); // v-model this.$emit('input', oldValue); // v-model
@ -967,11 +987,15 @@ export default {
this.oldValue = recordData.oldValue; this.oldValue = recordData.oldValue;
this.inputValue = recordData.inputValue; this.inputValue = recordData.inputValue;
} }
let recordOldVlaue = this.oldValue,recordValue = this.inputValue,isModify = !!this.oldValue;
if(this.type === "checkboxTag"){
recordOldVlaue =this.oldValue? `${this.oldValue.tagValue}:${this.oldValue.checked?'勾选':'未勾选'}`:'';
recordValue = `${this.inputValue?.tagValue}:${this.inputValue?.checked?'勾选':'未勾选'}`;
isModify = this.oldValue.checked !== undefined;
let recordOldVlaue = this.oldValue, recordValue = this.inputValue, isModify = !!this.oldValue;
if (this.type === "checkboxTag") {
// checkboxTagtagIndex
const oldTag = this.oldCheckboxTagList[this.currentTagIndex] || {};
const currentTag = this.checkboxTagList[this.currentTagIndex] || {};
recordOldVlaue = `${oldTag.tagValue || ''}:${oldTag.checked ? '勾选' : '未勾选'}`;
recordValue = `${currentTag.tagValue || ''}:${currentTag.checked ? '勾选' : '未勾选'}`;
isModify = oldTag.checked !== undefined
} }
const record = { const record = {
...baseInfo, ...baseInfo,
@ -994,8 +1018,14 @@ export default {
if (this.type === 'checkboxList') { if (this.type === 'checkboxList') {
this.oldValue = [...this.inputValue]; this.oldValue = [...this.inputValue];
this.oldOtherValues = { ...this.otherValues }; this.oldOtherValues = { ...this.otherValues };
}else if(this.type === "checkboxTag"){
this.oldCheckboxTagChecked = this.checkboxTagChecked;
} else if (this.type === "checkboxTag") {
// checkboxTagtagIndex
if (this.currentTagIndex >= 0 && this.currentTagIndex < this.checkboxTagList.length) {
this.oldCheckboxTagList[this.currentTagIndex] = { ...this.checkboxTagList[this.currentTagIndex] };
} else {
// tagIndex
this.oldCheckboxTagList = JSON.parse(JSON.stringify(this.checkboxTagList));
}
} }
let value = this.inputValue; let value = this.inputValue;
if (this.type === 'checkboxList') { if (this.type === 'checkboxList') {
@ -1003,11 +1033,8 @@ export default {
checkboxValues: this.inputValue, checkboxValues: this.inputValue,
otherValues: this.otherValues otherValues: this.otherValues
}; };
}else if(this.type === "checkboxTag"){
value = {
checked: this.checkboxTagChecked,
tagValue: this.tagValue,
};
} else if (this.type === "checkboxTag") {
value = [...this.checkboxTagList];
} }
if (this.type === "button") { if (this.type === "button") {
this.$emit('clickButton', this.item, this.inputValue, data); this.$emit('clickButton', this.item, this.inputValue, data);
@ -1662,16 +1689,15 @@ export default {
} }
// checkboxTag // checkboxTag
.checkbox-tag-wrapper {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 8px;
}
.checkbox-tag-container { .checkbox-tag-container {
border-radius: 4px; border-radius: 4px;
// transition: all 0.3s;
// margin-bottom: 10px;
// margin-right: 10px;
&.error-border {
border-color: #ff5d5d !important;
box-shadow: 0 0 6px #ffc3c3 !important;
}
.checkbox-tag-item { .checkbox-tag-item {
display: flex; display: flex;
@ -1701,12 +1727,8 @@ export default {
position: absolute; position: absolute;
top: 6px; top: 6px;
right: 5px; right: 5px;
// transition: all 0.3s;
// &:hover {
color: red; color: red;
background-color: #f5f5f5; background-color: #f5f5f5;
// }
} }
} }
} }

Loading…
Cancel
Save