Commit 3b31c7d8 authored by 黄奎's avatar 黄奎

页面修改

parent 5a7bc4ce
<template>
<div class="edit_div" :contenteditable="canEdit" v-html="innerText" @focus="isLocked = true" @blur="isLocked = false"
@input="changeText">
<div :data-name="isLocked" class="edit_div" :contenteditable="canEdit" v-html="innerText" @focus="isLocked = true"
@blur="isLocked = false" @input="changeText">
</div>
</template>
<script>
......@@ -21,7 +21,6 @@
},
methods: {
changeText: function () {
var that = this;
let sel = window.getSelection();
let offset = sel.anchorOffset;
if (this.textLength && this.$el.innerText.length > this.textLength) {
......@@ -29,55 +28,14 @@
}
this.$emit("input", this.$el.innerText);
setTimeout(() => {
try {
var range = sel.getRangeAt(0);
var textNode = range.startContainer;
var textNodeName = textNode.nodeName;
if (textNodeName == "#text") {
range.setStart(textNode, offset);
sel.removeAllRanges();
sel.addRange(range);
} else {
that.setCaretPosition(that.$el, offset);
}
} catch (err) {
console.log(err);
}
}, 0);
},
//重置div光标位置
setCaretPosition(element, offset) {
var range = document.createRange();
var sel = window.getSelection();
//select appropriate node
var currentNode = null;
var previousNode = null;
for (var i = 0; i < element.childNodes.length; i++) {
//save previous node
previousNode = currentNode;
//get current node
currentNode = element.childNodes[i];
//if we get span or something else then we should get child node
while (currentNode.childNodes.length > 0) {
currentNode = currentNode.childNodes[0];
}
//calc offset in current node
if (previousNode != null) {
offset -= previousNode.length;
}
//check whether current node has enough length
if (offset <= currentNode.length) {
break;
}
}
//move caret to specified offset
if (currentNode != null) {
range.setStart(currentNode, offset);
range.collapse(true);
var range = sel.getRangeAt(0);
var textNode = range.startContainer;
range.setStart(textNode, offset);
sel.removeAllRanges();
sel.addRange(range);
}
}
}, 0);
},
}
};
......
<template>
<div id="newFeatureBox3">
<div id="newFeatureBox3" v-if="RenderingOk">
<!-- UpgradedVersion-homebj 首页、介绍、食、宿、景 UpgradedVersion-otherBj 餐介绍 -->
<div class="UpgradedVersion-box UpgradedVersion-homebj relative"
:class="{'UpgradedVersion-otherBj':item.pageType==3}" v-for="(item,index) in pageList" :key="index+1000">
......@@ -114,6 +114,7 @@
dinner2: "http://imgfile.oytour.com/Static/NewTripFeature/dinner2.jpg",
dinner3: "http://imgfile.oytour.com/Static/NewTripFeature/dinner3.jpg",
dinner4: "https://imgfile.oytour.com/Static/NewTripFeature/dinner4.jpg",
RenderingOk: false,
};
},
methods: {
......@@ -194,6 +195,7 @@
"";
if (oldJson && oldJson.length > 0) {
this.pageList = oldJson;
this.RenderingOk = true;
} else {
var tripObj = this.getTripData();
this.pageList.forEach(pItem => {
......@@ -227,6 +229,7 @@
}
pItem.dataObj = newObj;
});
this.RenderingOk = true;
}
},
//首页数据渲染
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment