提交 f03e7082 编写于 作者: 璃白.'s avatar 璃白. 🌻

feat:添加链接缓存

上级 be6ea1c0
......@@ -306,6 +306,7 @@ export default {
textLength: "",
userList: false,
callUserList: [],
linkList: [],
selectionInfo: {
selectorId: "",
selectionStart: "",
......@@ -452,13 +453,34 @@ export default {
});
},
renderLinksHtml({ vDom, links }) {
const _this = this;
console.log(links);
// 缓存里没有的链接,就发送请求获取信息
const emitList = links.filter(
item => !this.linkList.find(link => link && link.url === item.url)
);
console.log("emit", emitList);
this.$emit("renderLinks", {
links,
callback: function(list) {
list.forEach(item => {
links: emitList,
callback: list => {
// 用原始数组做循环
links.forEach(item => {
const linkItem = this.linkList.find(
link => link && link.url === item.url
);
// 如果
if (!linkItem) {
const returnLink = list.find(
link => link && link.url === item.url
);
if (!returnLink) return;
item.title = returnLink.title;
item.description = returnLink.description;
item.icon = returnLink.icon;
this.linkList.push(returnLink);
} else {
item.title = linkItem.title;
item.description = linkItem.description;
item.icon = linkItem.icon;
}
// item.csdn = true;
const linkEl = vDom.querySelector("#" + item.id);
if (!linkEl) return;
......@@ -472,7 +494,8 @@ export default {
const title = getLinkTitle(linkEl, item);
linkEl.innerHTML = renderLinkCard(title, item);
});
_this.html = vDom.innerHTML;
this.html = vDom.innerHTML;
}
});
}
......
......@@ -395,7 +395,7 @@ export function renderLinkCard(title, item) {
let content;
switch (linkType) {
case "1":
content = `<span class="md_link_url">${item.title}</span>`;
content = `<span class="md_link_url">${title || item.title || ""}</span>`;
break;
case "2":
content = `<span class="md_link_url">${item.url}</span>`;
......
......@@ -43,7 +43,7 @@ export default {
position: {
immediate: true,
handler: function({ left, top }) {
this.left = left + 12;
this.left = left;
this.top = top + 40;
}
}
......
......@@ -2,7 +2,6 @@ import { getPosition, formatText, linkTypeSpiltStr } from "@/assets/js/utils";
export default {
methods: {
handleSelectLinkType(index) {
console.log(index);
const originalText = this.textContent;
const queryInfo = this.queryInfo;
const cursorPosition = getPosition(this.id);
......@@ -71,7 +70,7 @@ export default {
left:
pEl.offsetLeft < frameWidth * (2 / 3)
? pEl.offsetLeft
: pEl.offsetLeft - 140,
: pEl.offsetLeft - 120,
top: pEl.offsetTop - textEl.scrollTop
};
textEl.parentNode.removeChild(hideEl);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册