xiaolongmr commited on
Commit
ecf6886
·
1 Parent(s): ce96411

普通用户画图页加入客服聊天挂件

Browse files

在 web/src/app/image/page.tsx 用 useEffect 注入 //dh.z-l.top/chat.js,
保留原样的 async 与 fold 属性(next/script 会剥掉非标准属性故手动注入),
仅 role=normal 的普通用户加载,管理员/内部账号不挂载。

Files changed (1) hide show
  1. web/src/app/image/page.tsx +14 -0
web/src/app/image/page.tsx CHANGED
@@ -1270,6 +1270,20 @@ function ImagePageContent({ session }: { session: StoredAuthSession }) {
1270
  conversationsRef.current = conversations;
1271
  }, [conversations]);
1272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1273
  useEffect(() => {
1274
  let cancelled = false;
1275
 
 
1270
  conversationsRef.current = conversations;
1271
  }, [conversations]);
1272
 
1273
+ // 普通用户的画图页挂客服聊天挂件(dh.z-l.top/chat.js)。管理员/内部账号不加载。
1274
+ // 用 useEffect 注入而不是 next/script,是为了原样保留 async + fold 两个属性
1275
+ // (next/script 会剥掉非标准属性),并避免重复挂载。
1276
+ useEffect(() => {
1277
+ if (!isNormalUser || typeof window === "undefined") return;
1278
+ if (document.querySelector('script[data-chat-widget="dh.z-l.top"]')) return;
1279
+ const chatScript = document.createElement("script");
1280
+ chatScript.src = "//dh.z-l.top/chat.js";
1281
+ chatScript.async = true;
1282
+ chatScript.setAttribute("fold", "");
1283
+ chatScript.setAttribute("data-chat-widget", "dh.z-l.top");
1284
+ document.body.appendChild(chatScript);
1285
+ }, [isNormalUser]);
1286
+
1287
  useEffect(() => {
1288
  let cancelled = false;
1289