@hlw-uni/mp-vue 2.3.6 → 2.3.7

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.3.6",
3
+ "version": "2.3.7",
4
4
  "description": "hlw-uni工具集",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view :class="[fontSizeClass, fontFamilyClass]">
2
+ <view :class="[fontSizeClass, fontFamilyClass]" :style="pageStyle">
3
3
  <hlw-nav-bar v-if="props.isNav"
4
4
  :is-back="props.isBack"
5
5
  :title="title"
@@ -41,7 +41,7 @@
41
41
  * ```
42
42
  */
43
43
  import { useTheme } from "@/core";
44
- import { ref } from "vue";
44
+ import { ref, computed } from "vue";
45
45
  const { fontSizeClass, fontFamilyClass } = useTheme();
46
46
 
47
47
  const props = defineProps({
@@ -84,6 +84,27 @@ const props = defineProps({
84
84
  });
85
85
 
86
86
  const title = ref(props.title);
87
+
88
+ const navbarHeight = computed(() => {
89
+ if (!props.isNav) return 0;
90
+ const statusBarHeight = uni.getSystemInfoSync()?.statusBarHeight || 0;
91
+ let headerHeight = 44;
92
+ try {
93
+ const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
94
+ if (menuButtonInfo && typeof menuButtonInfo.bottom === "number" && menuButtonInfo.bottom > 0) {
95
+ headerHeight = menuButtonInfo.bottom - statusBarHeight + 6;
96
+ }
97
+ } catch (e) {
98
+ console.warn(e);
99
+ }
100
+ return statusBarHeight + headerHeight;
101
+ });
102
+
103
+ const pageStyle = computed(() => {
104
+ return {
105
+ "--navbar-height": `${navbarHeight.value}px`,
106
+ };
107
+ });
87
108
  </script>
88
109
 
89
110
  <style lang="scss">
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="hlw-reward-ad" @tap="open">
2
+ <view v-if="unitId" class="hlw-reward-ad" @tap="open">
3
3
  <slot />
4
4
  </view>
5
5
  </template>
@@ -19,7 +19,7 @@ interface Props {
19
19
  const props = defineProps<Props>();
20
20
 
21
21
  const emit = defineEmits<{
22
- (e: "onHandle", res: HlwRewardAdResult): void;
22
+ (e: "close", res: HlwRewardAdResult): void;
23
23
  }>();
24
24
 
25
25
  // 点击锁定状态,防止连续多次点击重复触发广告
@@ -28,6 +28,7 @@ const isClicked = ref(false);
28
28
  async function playRewardAdFlow(): Promise<void> {
29
29
  // 弹出全局模态 Loading 状态
30
30
  let hidden = false;
31
+ // @ts-ignore
31
32
  hlw.$msg.showLoading("正在拉起广告");
32
33
 
33
34
  // 设置 8 秒防超时定时器,如果 8 秒后还没有关闭加载提示,则强制关闭
@@ -39,6 +40,7 @@ async function playRewardAdFlow(): Promise<void> {
39
40
  if (hidden) return;
40
41
  hidden = true;
41
42
  clearTimeout(timer);
43
+ // @ts-ignore
42
44
  hlw.$msg.hideLoading();
43
45
  }
44
46
 
@@ -56,12 +58,12 @@ async function playRewardAdFlow(): Promise<void> {
56
58
  destroyRewardAd(props.unitId);
57
59
 
58
60
  if (res.success && res.isEnded) {
59
- emit("onHandle", {
61
+ emit("close", {
60
62
  success: true,
61
63
  isEnded: true,
62
64
  });
63
65
  } else if (res.err) {
64
- emit("onHandle", {
66
+ emit("close", {
65
67
  success: false,
66
68
  isEnded: false,
67
69
  loadFailed: true,
@@ -74,7 +76,7 @@ async function playRewardAdFlow(): Promise<void> {
74
76
  // 如果用户点击继续观看,递归执行广告流程
75
77
  await playRewardAdFlow();
76
78
  } else {
77
- emit("onHandle", {
79
+ emit("close", {
78
80
  success: false,
79
81
  isEnded: false,
80
82
  });
@@ -84,7 +86,7 @@ async function playRewardAdFlow(): Promise<void> {
84
86
  hide();
85
87
  destroyRewardAd(props.unitId);
86
88
  console.error("[HlwRewardAd] Failed to show reward ad:", e);
87
- emit("onHandle", {
89
+ emit("close", {
88
90
  success: false,
89
91
  isEnded: false,
90
92
  loadFailed: true,
@@ -114,7 +116,7 @@ async function open() {
114
116
  * adRef.value?.open();
115
117
  */
116
118
  defineExpose({
117
- open
119
+ open,
118
120
  });
119
121
 
120
122
  onUnmounted(() => {
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <video
3
+ :src="props.src"
4
+ class="hlw-video-element"
5
+ autoplay
6
+ loop
7
+ muted
8
+ :controls="false"
9
+ :show-play-btn="false"
10
+ :enable-play-gesture="true"
11
+ object-fit="contain"
12
+ :style="{ height: videoHeight }"
13
+ @loadedmetadata="onVideoLoadedMetadata"
14
+ />
15
+ </template>
16
+
17
+ <script setup lang="ts">
18
+ import { ref } from "vue";
19
+
20
+ defineOptions({ name: "HlwVideo" });
21
+
22
+ interface Props {
23
+ /** 视频源 URL */
24
+ src: string;
25
+ }
26
+
27
+ const props = withDefaults(defineProps<Props>(), {
28
+ src: "",
29
+ });
30
+
31
+ const videoHeight = ref("450rpx");
32
+
33
+ function onVideoLoadedMetadata(e: any) {
34
+ const { width, height } = e.detail || {};
35
+ if (width && height) {
36
+ videoHeight.value = `${(height / width) * 750}rpx`;
37
+ }
38
+ }
39
+ </script>
40
+
41
+ <style scoped>
42
+ .hlw-video-element {
43
+ width: 100%;
44
+ display: block;
45
+ }
46
+ </style>