qb-pc-sdk 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/ad-sdk-wrapper.js +73 -8
- package/src/example-simple.html +11 -8
package/package.json
CHANGED
package/src/ad-sdk-wrapper.js
CHANGED
|
@@ -310,6 +310,21 @@
|
|
|
310
310
|
.q-ad-wrapper.q-ad-small .q-ad-title { font-size: 12px; }
|
|
311
311
|
.q-ad-wrapper.q-ad-small .q-ad-desc { font-size: 10px; margin-bottom: 4px; }
|
|
312
312
|
.q-ad-wrapper.q-ad-small .q-cta-btn { padding: 3px 10px; font-size: 10px; }
|
|
313
|
+
/* Banner样式(横向细长条广告)优化 */
|
|
314
|
+
.q-ad-wrapper.q-ad-banner { flex-direction: row !important; align-items: stretch; }
|
|
315
|
+
.q-ad-wrapper.q-ad-banner .q-media-container { width: auto !important; flex: 0 0 auto !important; min-width: 0; height: 100% !important; max-width: 40% !important; min-width: 120px; position: relative; }
|
|
316
|
+
.q-ad-wrapper.q-ad-banner .q-ad-img, .q-ad-wrapper.q-ad-banner .q-ad-video { width: 100% !important; height: 100% !important; object-fit: cover !important; }
|
|
317
|
+
.q-ad-wrapper.q-ad-banner .q-content-container { flex: 1 !important; padding: 6px 10px !important; justify-content: center !important; min-width: 0; display: flex !important; flex-direction: column !important; width: auto !important; }
|
|
318
|
+
.q-ad-wrapper.q-ad-banner .q-ad-title { font-size: 14px !important; margin: 0 0 3px 0 !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; flex-shrink: 0; }
|
|
319
|
+
.q-ad-wrapper.q-ad-banner .q-ad-desc { font-size: 11px !important; margin: 0 0 4px 0 !important; -webkit-line-clamp: 1 !important; line-height: 1.3 !important; overflow: hidden !important; text-overflow: ellipsis !important; display: -webkit-box !important; -webkit-box-orient: vertical !important; flex-shrink: 0; }
|
|
320
|
+
.q-ad-wrapper.q-ad-banner .q-cta-btn { padding: 4px 12px !important; font-size: 11px !important; align-self: flex-start !important; flex-shrink: 0; margin-top: auto !important; }
|
|
321
|
+
.q-ad-wrapper.q-ad-banner .q-ad-tag { right: auto !important; left: 5px !important; }
|
|
322
|
+
/* 超窄Banner样式(高度小于80px) */
|
|
323
|
+
.q-ad-wrapper.q-ad-banner.q-ad-banner-narrow .q-media-container { max-width: 35% !important; min-width: 100px !important; }
|
|
324
|
+
.q-ad-wrapper.q-ad-banner.q-ad-banner-narrow .q-content-container { padding: 4px 8px !important; }
|
|
325
|
+
.q-ad-wrapper.q-ad-banner.q-ad-banner-narrow .q-ad-title { font-size: 13px !important; margin-bottom: 2px !important; }
|
|
326
|
+
.q-ad-wrapper.q-ad-banner.q-ad-banner-narrow .q-ad-desc { font-size: 10px !important; margin-bottom: 3px !important; display: none !important; }
|
|
327
|
+
.q-ad-wrapper.q-ad-banner.q-ad-banner-narrow .q-cta-btn { padding: 3px 10px !important; font-size: 10px !important; }
|
|
313
328
|
`;
|
|
314
329
|
|
|
315
330
|
class AdSDKWrapper {
|
|
@@ -513,20 +528,70 @@
|
|
|
513
528
|
const adImageWidth = ad.getImageWidth ? ad.getImageWidth() : 0;
|
|
514
529
|
const adImageHeight = ad.getImageHeight ? ad.getImageHeight() : 0;
|
|
515
530
|
|
|
516
|
-
//
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const containerHeight = containerRect.height || this.container.offsetHeight || 120;
|
|
531
|
+
// 获取容器尺寸(优先使用计算样式,确保获取准确)
|
|
532
|
+
let containerWidth = this.container.offsetWidth;
|
|
533
|
+
let containerHeight = this.container.offsetHeight;
|
|
520
534
|
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
535
|
+
// 如果 offsetWidth/offsetHeight 为0,尝试使用 getBoundingClientRect
|
|
536
|
+
if (!containerWidth || !containerHeight) {
|
|
537
|
+
const containerRect = this.container.getBoundingClientRect();
|
|
538
|
+
containerWidth = containerRect.width || containerWidth || 200;
|
|
539
|
+
containerHeight = containerRect.height || containerHeight || 120;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// 如果还是0,尝试从计算样式获取
|
|
543
|
+
if (!containerWidth || !containerHeight) {
|
|
544
|
+
const computedStyle = window.getComputedStyle(this.container);
|
|
545
|
+
containerWidth = parseFloat(computedStyle.width) || 200;
|
|
546
|
+
containerHeight = parseFloat(computedStyle.height) || 120;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// 计算宽高比
|
|
550
|
+
const aspectRatio = containerWidth / containerHeight;
|
|
551
|
+
|
|
552
|
+
// 判断是否为Banner样式(横向细长条):宽高比大于3:1,且高度小于150px
|
|
553
|
+
const isBanner = aspectRatio > 3 && containerHeight < 150;
|
|
554
|
+
const isNarrowBanner = isBanner && containerHeight < 80;
|
|
555
|
+
|
|
556
|
+
// 判断是否为小尺寸广告(宽度或高度小于300px,但不是Banner)
|
|
557
|
+
const isSmallAd = !isBanner && (containerWidth < 300 || containerHeight < 200);
|
|
558
|
+
|
|
559
|
+
// 构建样式类
|
|
560
|
+
let wrapperClass = 'q-ad-wrapper';
|
|
561
|
+
if (isBanner) {
|
|
562
|
+
wrapperClass += ' q-ad-banner';
|
|
563
|
+
if (isNarrowBanner) {
|
|
564
|
+
wrapperClass += ' q-ad-banner-narrow';
|
|
565
|
+
}
|
|
566
|
+
} else if (isSmallAd) {
|
|
567
|
+
wrapperClass += ' q-ad-small';
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// 调试信息(始终输出,便于排查问题)
|
|
571
|
+
console.log('[AdSDK] 容器尺寸检测:', {
|
|
572
|
+
width: containerWidth,
|
|
573
|
+
height: containerHeight,
|
|
574
|
+
aspectRatio: aspectRatio.toFixed(2),
|
|
575
|
+
isBanner: isBanner,
|
|
576
|
+
isNarrowBanner: isNarrowBanner,
|
|
577
|
+
isSmallAd: isSmallAd,
|
|
578
|
+
wrapperClass: wrapperClass
|
|
579
|
+
});
|
|
524
580
|
|
|
525
581
|
// 构建 HTML 结构
|
|
582
|
+
// 如果是Banner样式,计算媒体容器的宽度(基于高度和宽高比)
|
|
583
|
+
let mediaContainerStyle = '';
|
|
584
|
+
if (isBanner) {
|
|
585
|
+
// Banner样式:媒体容器宽度 = 高度 * 宽高比(16:9 或 4:3)
|
|
586
|
+
const mediaAspectRatio = isNarrowBanner ? 4/3 : 16/9;
|
|
587
|
+
const mediaWidth = Math.min(containerHeight * mediaAspectRatio, containerWidth * 0.4);
|
|
588
|
+
mediaContainerStyle = `width: ${mediaWidth}px;`;
|
|
589
|
+
}
|
|
590
|
+
|
|
526
591
|
this.container.innerHTML = `
|
|
527
592
|
<div class="${wrapperClass}">
|
|
528
593
|
<button class="q-ad-close" title="关闭广告" style="position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; background: rgba(0,0,0,0.5); color: #fff; border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; z-index: 10; transition: background 0.2s; flex-shrink: 0; padding: 0; margin: 0; box-sizing: border-box; font-family: Arial, sans-serif; font-weight: bold;">×</button>
|
|
529
|
-
<div class="q-media-container">
|
|
594
|
+
<div class="q-media-container" style="${mediaContainerStyle}">
|
|
530
595
|
<div class="q-ad-video" style="display:none"></div>
|
|
531
596
|
<img class="q-ad-img" style="display:none">
|
|
532
597
|
<span class="q-ad-tag">广告</span>
|
package/src/example-simple.html
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<style>
|
|
8
8
|
body { margin: 0; padding: 20px; font-family: sans-serif; background: #f0f2f5; }
|
|
9
9
|
#ad-slot-1 {
|
|
10
|
-
width:
|
|
11
|
-
height:
|
|
10
|
+
width: 728px;
|
|
11
|
+
height: 60px;
|
|
12
12
|
margin: 20px auto;
|
|
13
13
|
box-sizing: border-box;
|
|
14
14
|
}
|
|
@@ -17,10 +17,13 @@
|
|
|
17
17
|
<body>
|
|
18
18
|
<div id="ad-slot-1"></div>
|
|
19
19
|
|
|
20
|
-
<!--
|
|
21
|
-
<!--
|
|
22
|
-
<script src="https://unpkg.com/qb-pc-sdk
|
|
23
|
-
<!--
|
|
20
|
+
<!-- 测试最新代码:直接引用源文件 -->
|
|
21
|
+
<!-- 先引入底层 SDK -->
|
|
22
|
+
<script src="https://unpkg.com/qb-pc-ad-sdk-origin/dist/qb-pc-ad-sdk.v1.0.0.js"></script>
|
|
23
|
+
<!-- 再引入封装 SDK 源文件(包含最新的 Banner 适配代码) -->
|
|
24
|
+
<script src="ad-sdk-wrapper.js"></script>
|
|
25
|
+
|
|
26
|
+
<!-- 如果使用打包后的文件(可能不包含最新代码),取消下面这行的注释 -->
|
|
24
27
|
<!-- <script src="../qb-pc-sdk.js"></script> -->
|
|
25
28
|
|
|
26
29
|
<script>
|
|
@@ -74,8 +77,8 @@
|
|
|
74
77
|
|
|
75
78
|
// 初始化广告
|
|
76
79
|
const adSDK = new window.AdSDK({
|
|
77
|
-
appId: '
|
|
78
|
-
placementId: '
|
|
80
|
+
appId: '2004088976381599817',
|
|
81
|
+
placementId: '2004089182414200847',
|
|
79
82
|
container: '#ad-slot-1',
|
|
80
83
|
onAdLoaded: (ad, adSDKInstance) => {
|
|
81
84
|
console.log('✅ 广告加载完成');
|