|
455 | 455 | fetch(url) |
456 | 456 | .then((response) => response.json()) |
457 | 457 | .then((res) => { |
| 458 | + if (!res.data) { |
| 459 | + throw new Error(res) |
| 460 | + } |
458 | 461 | const data = res.data |
459 | 462 | const config_json = data.configuration |
460 | 463 | let tempData = Object.assign(defaultData, { id, domain_url }) |
|
472 | 475 | // postMessage the certificate to iframe |
473 | 476 | } |
474 | 477 | }) |
| 478 | + .catch((e) => { |
| 479 | + showMsg('嵌入失败', e.message) |
| 480 | + }) |
475 | 481 | } |
476 | 482 | function getDomain(src) { |
477 | 483 | return src.substring(0, src.indexOf('/assistant.js')) |
|
493 | 499 | expposeGlobalMethods(id) |
494 | 500 | }) |
495 | 501 | } |
| 502 | + |
| 503 | + function showMsg(title, content) { |
| 504 | + // 检查并创建容器(如果不存在) |
| 505 | + let container = document.getElementById('messageContainer') |
| 506 | + if (!container) { |
| 507 | + container = document.createElement('div') |
| 508 | + container.id = 'messageContainer' |
| 509 | + container.style.position = 'fixed' |
| 510 | + container.style.bottom = '20px' |
| 511 | + container.style.right = '20px' |
| 512 | + container.style.zIndex = '1000' |
| 513 | + document.body.appendChild(container) |
| 514 | + } else { |
| 515 | + // 如果容器已存在,先移除旧弹窗 |
| 516 | + const oldMessage = container.querySelector('div') |
| 517 | + if (oldMessage) { |
| 518 | + oldMessage.style.transform = 'translateX(120%)' |
| 519 | + oldMessage.style.opacity = '0' |
| 520 | + setTimeout(() => { |
| 521 | + container.removeChild(oldMessage) |
| 522 | + }, 300) |
| 523 | + } |
| 524 | + } |
| 525 | + |
| 526 | + // 创建弹窗元素 |
| 527 | + const messageBox = document.createElement('div') |
| 528 | + messageBox.style.width = '240px' |
| 529 | + messageBox.style.minHeight = '100px' |
| 530 | + messageBox.style.background = 'linear-gradient(135deg, #ff6b6b, #ff8e8e)' |
| 531 | + messageBox.style.borderRadius = '8px' |
| 532 | + messageBox.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.15)' |
| 533 | + messageBox.style.padding = '15px' |
| 534 | + messageBox.style.color = 'white' |
| 535 | + messageBox.style.fontFamily = 'Arial, sans-serif' |
| 536 | + messageBox.style.display = 'flex' |
| 537 | + messageBox.style.flexDirection = 'column' |
| 538 | + messageBox.style.transform = 'translateX(120%)' |
| 539 | + messageBox.style.transition = 'transform 0.3s ease-out' |
| 540 | + messageBox.style.opacity = '0' |
| 541 | + messageBox.style.transition = 'opacity 0.3s ease, transform 0.3s ease' |
| 542 | + messageBox.style.overflow = 'hidden' |
| 543 | + |
| 544 | + // 创建标题元素 |
| 545 | + const titleElement = document.createElement('div') |
| 546 | + titleElement.style.fontSize = '18px' |
| 547 | + titleElement.style.fontWeight = 'bold' |
| 548 | + titleElement.style.marginBottom = '10px' |
| 549 | + titleElement.style.borderBottom = '1px solid rgba(255, 255, 255, 0.3)' |
| 550 | + titleElement.style.paddingBottom = '8px' |
| 551 | + titleElement.textContent = title |
| 552 | + |
| 553 | + // 创建内容元素 |
| 554 | + const contentElement = document.createElement('div') |
| 555 | + contentElement.style.fontSize = '14px' |
| 556 | + contentElement.style.flexGrow = '1' |
| 557 | + contentElement.style.overflow = 'auto' |
| 558 | + contentElement.textContent = content |
| 559 | + |
| 560 | + // 组装元素 |
| 561 | + messageBox.appendChild(titleElement) |
| 562 | + messageBox.appendChild(contentElement) |
| 563 | + |
| 564 | + // 添加到容器 |
| 565 | + container.appendChild(messageBox) |
| 566 | + |
| 567 | + // 触发显示动画 |
| 568 | + setTimeout(() => { |
| 569 | + messageBox.style.transform = 'translateX(0)' |
| 570 | + messageBox.style.opacity = '1' |
| 571 | + }, 10) |
| 572 | + |
| 573 | + // 3秒后自动隐藏 |
| 574 | + setTimeout(() => { |
| 575 | + messageBox.style.transform = 'translateX(120%)' |
| 576 | + messageBox.style.opacity = '0' |
| 577 | + setTimeout(() => { |
| 578 | + container.removeChild(messageBox) |
| 579 | + // 如果容器是空的,也移除容器 |
| 580 | + if (container.children.length === 0) { |
| 581 | + document.body.removeChild(container) |
| 582 | + } |
| 583 | + }, 300) |
| 584 | + }, 5000) |
| 585 | + } |
| 586 | + |
| 587 | + /* function hideMsg() { |
| 588 | + const container = document.getElementById('messageContainer'); |
| 589 | + if (container) { |
| 590 | + const messageBox = container.querySelector('div'); |
| 591 | + if (messageBox) { |
| 592 | + messageBox.style.transform = 'translateX(120%)'; |
| 593 | + messageBox.style.opacity = '0'; |
| 594 | + setTimeout(() => { |
| 595 | + container.removeChild(messageBox); |
| 596 | + // 如果容器是空的,也移除容器 |
| 597 | + if (container.children.length === 0) { |
| 598 | + document.body.removeChild(container); |
| 599 | + } |
| 600 | + }, 300); |
| 601 | + } |
| 602 | + } |
| 603 | + } */ |
| 604 | + |
496 | 605 | function updateParam(target_url, key, newValue) { |
497 | 606 | try { |
498 | 607 | const url = new URL(target_url) |
|
0 commit comments