/** * 弹窗组件 * 使用方法: * 1. 引入此JS文件 * 2. 调用 PopupManager.init() 初始化 * 3. 调用 PopupManager.show() 显示弹窗 * 4. 调用 PopupManager.hide() 隐藏弹窗 */ (function(window) { 'use strict'; // 表单管理器 const FormManager = { // 配置选项 config: { // 弹窗模式配置 scrollThreshold: 0.6, // 滚动阈值 autoShow: true, // 是否自动显示 overlayClose: false, // 点击遮罩层是否关闭 confirmClose: false, // 关闭时是否确认 // 内嵌模式配置 containerId: '', // 内嵌容器ID // 成功提示配置 successPromptAutoHide: false, // 是否自动隐藏成功提示 successPromptDuration: 3000 // 成功提示显示时长(毫秒) }, // 状态管理 state: { popupShown: false, popupInitialized: false, inlineInitialized: false }, // DOM元素 elements: { // 弹窗元素 popupContainer: null, popupOverlay: null, popupForm: null, // 内嵌元素 inlineContainer: null, inlineForm: null }, // CSS样式 styles: ` /* 弹窗样式 */ .popup-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 99998; display: none; opacity: 0; transition: opacity 0.3s ease; } .popup-overlay.show { display: block; opacity: 1; } .popup-container { background: white; border-radius: 16px; width: 100%; max-width: 800px; padding-top: 30px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 99999; margin: auto; display: none; opacity: 0; transition: opacity 0.3s ease; } .popup-container.show { display: block; opacity: 1; } /* 内嵌样式 */ #inhtm-form-box{ background: white; } .inline-form-container { background: white; width: 100%; max-width: 1200px; padding: 30px; margin: 20px auto; box-sizing: border-box; } .inline-form-container .form-content{ max-height: 100%; overflow: hidden; } /* 通用样式 */ .form-content { padding: 30px; max-height: 80vh; overflow-y: auto; } .form-header { text-align: center; margin-bottom: 32px; position: relative; } .form-main-title { font-size: 21px; font-weight: bold; color: #000; margin-bottom: 8px; } .form-subtitle { font-size: 13px; color: #697990; } .popup-close-btn { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 1px solid #000; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #000; } .popup-close-btn::after{ content:''; width:50%; height:1px; background:#000; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; transform: rotate(45deg); } .popup-close-btn::before{ content:''; width:50%; height:1px; background:#000; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; transform: rotate(-45deg); } .form-group { margin-bottom: 12px; } .form-label { display: block; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-weight: 400; font-size: 12px; color: #0D1414; margin-bottom: 8px; } .form-input { width: 100%; padding: 12px 16px; border: 1px solid rgba(112,124,141,0.5216); border-radius: 8px; font-size: 12px; background: white; box-sizing: border-box; } .form-input:focus { outline: none; border-color: #0066FF; } .form-input::placeholder { color: #999; } .form-select { width: 100%; padding: 12px 16px; border: 1px solid rgba(112,124,141,0.5216); border-radius: 8px; font-size: 12px; background: white; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.762L10.825 4z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; cursor: pointer; box-sizing: border-box; } .form-select:focus { outline: none; border-color: #0066FF; } .form-radio-group, .form-checkbox-group { display: flex; flex-wrap: wrap; gap: 10px; } .form-radio-item, .form-checkbox-item { min-width:calc(50% - 10px); display: flex; align-items: center; cursor: pointer; } .form-radio-input, .form-checkbox-input { background-color: transparent; -webkit-appearance: none; width:0; hieght:0; margin:0; } .form-radio-input::before, .form-checkbox-input::before{ content: ''; position: absolute; left: 0; top: 0; width: 17px; height: 17px; border: 1px solid #687C9B; border-radius: 50%; background: white; } .form-radio-label, .form-checkbox-label { position: relative; padding-left: 28px; cursor: pointer; font-size: 12px; color: #000; line-height: 20px; } .form-radio-input:checked::before{ border-color: #0066FF; } .form-checkbox-input:checked::before{ border-color: #0066FF; background: #0066FF; } .form-radio-input:checked::after{ content: ''; position: absolute; left: 5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: #0066FF; } .form-checkbox-input:checked::after { content: ''; position: absolute; left: 6px; top: 3px; width: 5px; height: 9px; border-radius: 0 0 3px 0; border: 2px solid #fff; border-width: 0 2px 2px 0; transition: all 0.3s ease; transform: rotate(45deg); } .form-textarea { width: 100%; padding: 5px 10px; border: 1px solid rgba(112,124,141,0.5216); border-radius: 8px; font-size: 12px; background: white; resize: none; min-height: 100px; font-family: inherit; box-sizing: border-box; } .form-textarea:focus { outline: none; border-color: #0066FF; } .form-submit-btn { width: 100%; padding: 16px; background: #141421; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background-color 0.3s; } .form-submit-btn:hover { background: #141421; } .form-submit-btn:active { transform: translateY(1px); } /* 移动端样式 */ @media (max-width: 768px) { .popup-container { position: fixed; bottom: 0; left: 0; top: auto; transform: none; max-width: 100%; border-radius: 16px 16px 0 0; margin: 0; } .form-content { padding: 17px; } .popup-close-btn { top: 10px; right: 10px; width: 18px; height: 18px; font-size: 18px; } .inline-form-container { // margin: 10px; padding: 17px; } } /* PC端样式 */ @media (min-width: 769px) { .form-content{ padding-left:5%; padding-right:5%; } .form-main-title { font-size: 24px; margin-bottom: 12px; } .form-submit-btn{ max-width:400px; margin:0 auto; display:block; } .form-subtitle { font-size: 14px; } .popup-close-btn { top: 15px; right: 15px; width: 24px; height: 24px; font-size: 20px; } .form-group { margin-bottom: 20px; display: flex; align-items: center; } .form-label { margin-right: 15px; width: 100px; flex-shrink: 0; text-align: right; word-wrap:break-word; } .form-input, .form-select, .form-textarea { flex: 1; } .form-radio-group, .form-checkbox-group { flex: 1; gap: 10px; } .form-radio-item, .form-checkbox-item { min-width:calc(25% - 10px); } .inline-form-container{ padding-left:5%; padding-right:5%; } } /* 去除默认样式 */ .form-input, .form-select, .form-textarea { -webkit-appearance: none; -moz-appearance: none; appearance: none; } .form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; } .form-textarea { resize: none; } /* 去除移动端点击高亮 */ .popup-container *, .inline-form-container * { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .form-input, .form-textarea { -webkit-user-select: text; -khtml-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text; } .banner{ width: 100%; position: relative; } .banner img{ display: block; width: 100%; border-radius: 16px; } .prompt-q{ position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index:100000; display:none; } .prompt-q .prompt-box{ width: 100%; height:100%; display: flex; align-items: center; justify-content: center; } .prompt-q .prompt-box .prompt{ position: relative; width: 248px; // height: 154px; padding:30px 10px; background: #FFFFFF; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-direction: column; font-family: MiSans, MiSans; font-weight: 400; font-size: 12px; color: #A7AEBD; } .prompt-q .prompt-box .prompt-icon{ width: 40px; height: 40px; border-radius: 50%; background: #00D483; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; position: relative; } .prompt-q .prompt-box .prompt-icon::after{ content:''; width:25%; height:50%; border-color:#fff; border-style: solid; border-width: 0 4px 4px 0; transform: rotate(45deg); margin-top:-5px } .prompt-q .prompt-box .prompt-icon.error{ background:rgba(241, 61, 61,1); } .prompt-q .prompt-box .prompt-icon.error::before{ content:''; width:3px; height:50%; border-width: 0; background:#fff; transform: rotate(45deg); position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; } .prompt-q .prompt-box .prompt-icon.error::after{ content:''; width:3px; height:50%; border-width:0; background:#fff; transform: rotate(-45deg); position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; } .prompt-q .prompt-box .close-btn { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 1px solid #000; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #000; } .prompt-q .prompt-box .close-btn::after{ content:''; width:50%; height:1px; background:#000; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; transform: rotate(45deg); } .prompt-q .prompt-box .close-btn::before{ content:''; width:50%; height:1px; background:#000; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; transform: rotate(-45deg); } /* 文件上传样式 */ .form-upload-item { display: flex; flex-wrap: wrap; gap: 10px; flex:1; height:148px; } .form-upload-label { flex:1; padding: 8px 16px; border: 1px solid rgba(112,124,141,0.5216); background:#fff; border-radius: 6px; cursor: pointer; font-size: 12px; color: #666; transition: all 0.3s ease; min-width: 80px; display: flex; align-items: center; justify-content: center; flex-direction: column; position: relative; } .form-upload-input { display: none; } .form-upload-label .upload-text{ padding-top:30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M21 15V19C21 19.5304 20.7893 20.0391 20.4142 20.4142C20.0391 20.7893 19.5304 21 19 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V15' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M17 8L12 3L7 8' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M12 3V15' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: top 0 center; background-size: 24px 24px; font-family: MiSans, MiSans; font-weight: 400; font-size: 14px; color: #0B1426; } .form-upload-label .upload-des{ font-family: MiSans, MiSans; font-weight: 400; font-size: 12px; color: #A7AEBD; } /* 拖拽状态样式 */ .form-upload-label.drag-over { border-color: #0066FF; background-color: rgba(0, 102, 255, 0.1); color: #0066FF; } .form-upload-label.drag-over .upload-text { color: #0066FF; } .form-upload-label.drag-over .upload-text { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M21 15V19C21 19.5304 20.7893 20.0391 20.4142 20.4142C20.0391 20.7893 19.5304 21 19 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V15' stroke='%230066FF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M17 8L12 3L7 8' stroke='%230066FF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M12 3V15' stroke='%230066FF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); } .upload-preview { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; border-radius: 6px; z-index: 1; } .upload-preview-item { position: relative; width: 120px; height: 120px; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; background: #f9f9f9; } .upload-preview-item img, .upload-preview-item video { width: 100%; height: 100%; object-fit: cover; } .upload-preview-item video { position: relative; } .upload-preview-item video::-webkit-media-controls-play-button { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 60px; height: 60px; background: rgba(0, 0, 0, 0.7); border-radius: 50%; border: none; outline: none; } .upload-preview-item video::-webkit-media-controls-play-button:before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 0; height: 0; border-left: 20px solid white; border-top: 12px solid transparent; border-bottom: 12px solid transparent; margin-left: 4px; } /* 禁止视频播放的样式 */ .upload-preview-item video { pointer-events: none; cursor: default; } .upload-preview-item video::-webkit-media-controls { display: none !important; } .upload-preview-item video::-webkit-media-controls-panel { display: none !important; } .upload-preview-item video::-webkit-media-controls-play-button { display: none !important; } .upload-preview-item video::-webkit-media-controls-start-playback-button { display: none !important; } .upload-preview-item .remove-btn { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; background: rgba(0, 0, 0, 0.6); color: white; border: none; border-radius: 50%; cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; } .upload-preview-item .remove-btn:hover { background: rgba(255, 0, 0, 0.8); } .upload-preview-item .file-info { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0, 0, 0, 0.7); color: white; font-size: 10px; padding: 2px 4px; text-align: center; } .upload-preview-item .file-icon { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 24px; color: #999; } `, // HTML模板 template: `