feat: 🚀 div标签解析
This commit is contained in:
@@ -15,6 +15,35 @@ const hasIdRecursive = (data: any, targetId: any) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const htmlDecode = (html: any) => {
|
||||
let e: any = document.createElement("div");
|
||||
e.innerHTML = html;
|
||||
|
||||
// 关键:在解码后添加样式处理
|
||||
const detailAllElements = e.querySelectorAll(".o_detail_all");
|
||||
detailAllElements.forEach((detailAll: HTMLElement) => {
|
||||
// 为文字类子元素添加居中样式
|
||||
let textElements: any = [
|
||||
...Array.from(detailAll.querySelectorAll<HTMLElement>(".o_detail_text")),
|
||||
...Array.from(detailAll.querySelectorAll<HTMLElement>(".o_detail_small")),
|
||||
...Array.from(detailAll.querySelectorAll<HTMLElement>(".o_detail_title"))
|
||||
];
|
||||
|
||||
textElements.forEach((el: any) => {
|
||||
// 保留原有样式,追加居中样式(避免覆盖已有样式)
|
||||
el.style.textAlign = "center";
|
||||
// 如果需要强制覆盖,可添加 !important
|
||||
// el.style.textAlign = 'center !important';
|
||||
});
|
||||
});
|
||||
|
||||
if (e.childNodes.length > 1) {
|
||||
return e.innerHTML;
|
||||
} else {
|
||||
return e.childNodes[0].innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
//将参数分离
|
||||
export const initDetailParams = (dataStore: any, data: any, editorRef: any) => {
|
||||
let is = hasIdRecursive(dataStore.options, data.category_id);
|
||||
@@ -40,14 +69,14 @@ export const initDetailParams = (dataStore: any, data: any, editorRef: any) => {
|
||||
stock_qty: data.stock_qty,
|
||||
id: data.id
|
||||
});
|
||||
console.log(data.detail, "=======detail========");
|
||||
|
||||
//详情
|
||||
if (!data.detail) {
|
||||
dataStore.detail = "";
|
||||
editorRef?.value?.clearEditor(); // 调用子组件的清空方法
|
||||
} else {
|
||||
dataStore.detail = data.detail;
|
||||
dataStore.detail = htmlDecode(data.detail); //htmlDecode(data.detail);
|
||||
console.log(data.detail, "=======detail========");
|
||||
}
|
||||
|
||||
//图片
|
||||
|
||||
Reference in New Issue
Block a user