Commit 26e2a9fd authored by chenghong_tao's avatar chenghong_tao

add embed.js userId参数

parent ec9da121
...@@ -23,9 +23,9 @@ npm run build ...@@ -23,9 +23,9 @@ npm run build
### 注意事项 ### 注意事项
1. 使用embed模式时,引入embed.js文件时需要带URL参数 1. 使用embed模式时,引入embed.js文件时需要带URL参数
```html ```html
<script src="/embed.min.js?url=当前前端所在的IP或域名地址"></script> <script src="/embed.min.js?url=当前前端所在的IP或域名地址&userId=用户名"></script>
``` ```
如:在本地运行前端时,引入embed.js文件时,参数则为url=http://127.0.0.1:3000 如:在本地运行前端时,引入embed.js文件时,参数则为url=http://127.0.0.1:3000
```html ```html
<script src="/embed.min.js?url=http://127.0.0.1:3000"></script> <script src="/embed.min.js?url=http://127.0.0.1:3000&userId=admin"></script>
``` ```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat iframe test</title>
</head>
<body>
<script src="http://10.82.13.89:8080/embed.min.js?url=http://10.82.13.89:8080&userId=张三"></script>
</body>
</html>
\ No newline at end of file
...@@ -7,10 +7,14 @@ ...@@ -7,10 +7,14 @@
return; return;
} }
let baseUrl = ''; let baseUrl = '';
let userId = '';
// 获取当前时间戳
const timestamp = Date.now();
try { try {
// 处理相对路径(如 src="./embed.js") // 处理相对路径(如 src="./embed.js")
const scriptUrl = new URL(currentScript.src, location.href); const scriptUrl = new URL(currentScript.src, location.href);
baseUrl = scriptUrl.searchParams.get('url'); baseUrl = scriptUrl.searchParams.get('url');
userId = scriptUrl.searchParams.get('userId');
if (!baseUrl) { if (!baseUrl) {
console.error('未找到URL参数'); console.error('未找到URL参数');
...@@ -100,7 +104,7 @@ ...@@ -100,7 +104,7 @@
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
// 获取URL // 获取URL
iframe.src = baseUrl; // 替换为你的聊天窗口页面地址 iframe.src = baseUrl + '?userId=' + userId + '&timestamp=' + timestamp; // 替换为你的聊天窗口页面地址
iframe.style.width = '100%'; iframe.style.width = '100%';
iframe.style.height = '100%'; iframe.style.height = '100%';
iframe.style.border = 'none'; iframe.style.border = 'none';
......
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