|
@@ -130,9 +130,14 @@ export default {
|
|
loading: false,
|
|
loading: false,
|
|
progress: 0,
|
|
progress: 0,
|
|
isEditing: false,
|
|
isEditing: false,
|
|
|
|
+ focusedInputId: null,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
mounted() {},
|
|
mounted() {},
|
|
|
|
+ // 记得在组件销毁时移除事件监听器
|
|
|
|
+ beforeDestroy() {
|
|
|
|
+ this.$el.removeEventListener("input", this.handleInputChange);
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
async replaceData(data) {
|
|
async replaceData(data) {
|
|
let _this = this;
|
|
let _this = this;
|
|
@@ -172,7 +177,12 @@ export default {
|
|
//文本
|
|
//文本
|
|
data = data.replace(
|
|
data = data.replace(
|
|
"{{" + attrId + "}}",
|
|
"{{" + attrId + "}}",
|
|
- '<input type="text" id="' +
|
|
|
|
|
|
+ /* `<input type="text" class="text-input-box" data-index="${i}" value="${_this.com.attrs[i].content}" @input="updateContent('${_this.com.attrs[i].id}', $event)" id="${attrId}">`, */
|
|
|
|
+ '<input type="text" ref="input_' +
|
|
|
|
+ attrId +
|
|
|
|
+ '" name="' +
|
|
|
|
+ _this.com.attrs[i].name +
|
|
|
|
+ '" id="' +
|
|
attrId +
|
|
attrId +
|
|
'" data-index="' +
|
|
'" data-index="' +
|
|
i +
|
|
i +
|
|
@@ -232,10 +242,10 @@ export default {
|
|
} else if (_this.com.attrs[i].type == "formual") {
|
|
} else if (_this.com.attrs[i].type == "formual") {
|
|
//// console.log('attrs',_this.com.attrs[i]);
|
|
//// console.log('attrs',_this.com.attrs[i]);
|
|
//处理计算公式 不处理
|
|
//处理计算公式 不处理
|
|
- let formual = await _this.analysisFormual(_this.com.attrs[i]);
|
|
|
|
|
|
+ let formual = await _this.analysisFormual(_this.com.attrs[i]);
|
|
|
|
|
|
formual = await _this.getRemote(formual);
|
|
formual = await _this.getRemote(formual);
|
|
- _this.com.attrs[i].content= eval(formual)
|
|
|
|
|
|
+ _this.com.attrs[i].content = eval(formual);
|
|
data = data.replace("{{" + attrId + "}}", eval(formual));
|
|
data = data.replace("{{" + attrId + "}}", eval(formual));
|
|
|
|
|
|
/* let formual = await _this.analysisFormual(_this.com.attrs[i]);
|
|
/* let formual = await _this.analysisFormual(_this.com.attrs[i]);
|
|
@@ -302,8 +312,39 @@ export default {
|
|
data = data.replace("{{" + attrId + "}}", _this.com.attrs[i].content);
|
|
data = data.replace("{{" + attrId + "}}", _this.com.attrs[i].content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.addInputListeners();
|
|
|
|
+ });
|
|
return data;
|
|
return data;
|
|
},
|
|
},
|
|
|
|
+ addInputListeners() {
|
|
|
|
+ // 使用事件委托来处理所有的 .text-input-box 元素
|
|
|
|
+ this.$el.addEventListener("blur", this.handleInputChange, true);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ handleInputChange(event) {
|
|
|
|
+ if (event.target.classList.contains("text-input-box")) {
|
|
|
|
+ const attrId = event.target.id;
|
|
|
|
+ const attrName = event.target.name;
|
|
|
|
+ const dataIndex = parseInt(event.target.dataset.index, 10);
|
|
|
|
+ const newValue = event.target.value;
|
|
|
|
+ // 更新数据
|
|
|
|
+ if (this.com && this.com.attrs && this.com.attrs[dataIndex]) {
|
|
|
|
+ this.$set(this.com.attrs[dataIndex], "content", newValue);
|
|
|
|
+
|
|
|
|
+ this.com.attrs.forEach((el) => {
|
|
|
|
+ if (el.name === attrName) {
|
|
|
|
+ this.$set(el, "content", newValue);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.$emit("onUpdateAttr", this.currentIndex, dataIndex, newValue);
|
|
|
|
+
|
|
|
|
+ // 使用 $nextTick 确保在 DOM 更新后执行
|
|
|
|
+ } else {
|
|
|
|
+ console.warn(`Unable to find attribute at index ${dataIndex}`);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
|
|
bindEvents() {
|
|
bindEvents() {
|
|
let _this = this;
|
|
let _this = this;
|