Skip to content

Commit

Permalink
chore: 🚀 更新微信ad
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonofweisheng committed Nov 11, 2024
1 parent 3b6c631 commit 2e124b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
39 changes: 35 additions & 4 deletions src/components/page-wraper/page-wraper.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<wd-config-provider :theme="theme" :theme-vars="isRed ? themeVars : {}">
<wd-toast />
<view class="page-wraper">
<wd-cell title="切换暗黑" title-width="240px" center v-if="showDarkMode">
<wd-switch v-model="isDark" />
Expand All @@ -9,9 +8,22 @@
<wd-switch v-model="isRed" />
</wd-cell>
<slot />
<!-- #ifdef MP-WEIXIN -->
<!-- 横幅广告和格子广告可以共存,但插屏广告展示时,不显示横幅广告和格子广告 -->
<template v-if="useWxAd && !showWxAd3">
<ad-custom v-if="showWxAd" unit-id="adunit-06191d6d3d1ddfc4"></ad-custom>
<ad-custom
v-if="showWxAd2"
style="width: 120rpx; height: auto; position: fixed; right: 12rpx; top: 160rpx; z-index: 999"
unit-id="adunit-95aad07aafad3619"
></ad-custom>
</template>
<!-- #endif -->

<wd-gap height="0" v-if="safeAreaInsetBottom" safe-area-bottom></wd-gap>
</view>
<wd-notify />
<wd-toast />
</wd-config-provider>
</template>
<script lang="ts">
Expand All @@ -24,23 +36,32 @@ export default {
}
</script>
<script lang="ts" setup>
import { computed, ref, onMounted } from 'vue'
import { computed, ref, onMounted, nextTick } from 'vue'
import { setNotifyDefaultOptions, type ConfigProviderThemeVars } from '@/uni_modules/wot-design-uni'
import { useDark } from '../../store'
interface Props {
showDarkMode?: boolean
safeAreaInsetBottom?: boolean
useWxAd?: boolean
}
withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
showDarkMode: false,
safeAreaInsetBottom: true
safeAreaInsetBottom: true,
useWxAd: process.env.NODE_ENV === 'development' ? false : true
})
const darkMode = useDark()
const isDark = ref<boolean>(false)
const isRed = ref<boolean>(false)
// #ifdef MP-WEIXIN
// 横幅广告和格子广告可以共存,但插屏广告展示时,不显示横幅广告和格子广告
const showWxAd = ref<boolean>(Math.random() > 0.5) // 横幅广告
const showWxAd2 = ref<boolean>(Math.random() > 0.33) // 格子广告
const showWxAd3 = ref<boolean>(Math.random() > 0.66) // 插屏广告
let interstitialAd: UniApp.InterstitialAdContext | null = null
// #endif
const themeVars: ConfigProviderThemeVars = {
colorTheme: 'red'
Expand All @@ -56,6 +77,16 @@ onMounted(() => {
onClosed: () => console.log('onClosed'),
onOpened: () => console.log('onOpened')
})
// #ifdef MP-WEIXIN
// 微信广告
if (uni.createInterstitialAd && showWxAd3.value && props.useWxAd) {
interstitialAd = uni.createInterstitialAd({ adUnitId: 'adunit-fc8522e2b1185c89' })
nextTick(() => {
console.log(interstitialAd)
interstitialAd && interstitialAd.show()
})
}
// #endif
})
</script>
<style lang="scss" scoped>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index/Index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<page-wraper>
<page-wraper :use-wx-ad="false">
<view class="page">
<view class="page__hd">
<view class="page__title">
Expand Down

0 comments on commit 2e124b2

Please sign in to comment.