@hlw-uni/mp-vue 2.1.55 → 2.1.56

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.1.55",
3
+ "version": "2.1.56",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -3,7 +3,7 @@
3
3
  ------------------------------------------------------------------
4
4
  用法(业务方从自己的接口配置取对应 unit_id 传入):
5
5
  hlw-ad type="banner" :unit-id="config.banner_unit_id"
6
- hlw-ad type="grid" :unit-id="config.grid_unit_id"
6
+ hlw-ad type="grid" :unit-id="config.grid_unit_id" placement="right-middle"
7
7
  hlw-ad type="custom" :unit-id="config.custom_unit_id"
8
8
 
9
9
  渲染分支:
@@ -17,8 +17,8 @@
17
17
  <template>
18
18
  <view
19
19
  v-if="visible"
20
- :class="['hlw-ad', `hlw-ad--${type}`, customClass]"
21
- :style="customStyle"
20
+ :class="['hlw-ad', `hlw-ad--${type}`, type === 'grid' ? `hlw-ad--${placement}` : '', customClass]"
21
+ :style="style"
22
22
  >
23
23
  <ad
24
24
  v-if="type === 'banner'"
@@ -41,11 +41,15 @@ import { computed } from "vue";
41
41
 
42
42
  defineOptions({ name: "HlwAd" });
43
43
 
44
+ type GridPlacement = "left-top" | "right-top" | "left-middle" | "right-middle" | "left-bottom" | "right-bottom" | "center";
45
+
44
46
  interface Props {
45
47
  /** 广告类型 — 仅展示型(banner / grid / custom) */
46
48
  type: "banner" | "grid" | "custom";
47
49
  /** 微信广告单元 id;空字符串 → 不渲染 */
48
50
  unitId: string;
51
+ /** grid 广告悬浮位置 */
52
+ placement?: GridPlacement;
49
53
  /** 自定义样式(合并到根元素) */
50
54
  customStyle?: string;
51
55
  /** 自定义 class */
@@ -53,6 +57,7 @@ interface Props {
53
57
  }
54
58
 
55
59
  const props = withDefaults(defineProps<Props>(), {
60
+ placement: "right-middle",
56
61
  customStyle: "",
57
62
  customClass: "",
58
63
  });
@@ -64,6 +69,17 @@ const emit = defineEmits<{
64
69
 
65
70
  /** 有 unit_id 才渲染 */
66
71
  const visible = computed(() => !!props.unitId);
72
+ const style = computed(() => [props.type === "grid" ? styleMap[props.placement] : "", props.customStyle].filter(Boolean).join(";"));
73
+ const safe = "24rpx";
74
+ const styleMap: Record<GridPlacement, string> = {
75
+ "left-top": `top:${safe};left:${safe};right:auto;bottom:auto;transform:none;`,
76
+ "right-top": `top:${safe};right:${safe};left:auto;bottom:auto;transform:none;`,
77
+ "left-middle": `top:50%;left:${safe};right:auto;bottom:auto;transform:translateY(-50%);`,
78
+ "right-middle": `top:50%;right:${safe};left:auto;bottom:auto;transform:translateY(-50%);`,
79
+ "left-bottom": `left:${safe};bottom:200rpx;right:auto;top:auto;transform:none;`,
80
+ "right-bottom": `right:${safe};bottom:200rpx;left:auto;top:auto;transform:none;`,
81
+ center: "top:50%;left:50%;right:auto;bottom:auto;transform:translate(-50%, -50%);",
82
+ };
67
83
 
68
84
  function onLoad(event: any) {
69
85
  emit("load", event);
@@ -81,13 +97,10 @@ function onError(event: any) {
81
97
  background: var(--surface-card, #ffffff);
82
98
  }
83
99
 
84
- /* 格子广告:默认右侧居中悬浮;微信硬性规则要求 wrapper 透明无圆角,customStyle 可覆盖 */
100
+ /* 格子广告:默认居中悬浮;微信硬性规则要求 wrapper 透明无圆角,customStyle 可覆盖 */
85
101
  .hlw-ad--grid {
86
102
  position: fixed;
87
- top: 50%;
88
- right: 0;
89
103
  z-index: 99;
90
- transform: translateY(-50%);
91
104
  border-radius: 0;
92
105
  overflow: visible;
93
106
  background: transparent;