81 lines
2.0 KiB
Vue
Raw Normal View History

<template>
2025-01-23 14:12:07 +08:00
<div v-show="ads.length" class="ad">
<div class="body" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
2025-01-23 14:12:07 +08:00
<div class="list ccui-scrollbar">
<Banner v-for="(item, index) in ads" :data="item" :key="index"></Banner>
</div>
</div>
</div>
</template>
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { defineComponent, onMounted, onUnmounted, ref, toRaw } from "vue";
2025-01-23 14:12:07 +08:00
import { GA_EventName } from "../../ga/type";
import Banner from "./banner.vue";
import { emitter, Msg } from "./const";
2025-01-23 14:12:07 +08:00
import { AdItem, getAdData } from "./loader";
import { ga } from "./util";
const { CCButton } = ccui.components;
export default defineComponent({
name: "ad",
2025-01-23 14:12:07 +08:00
components: { CCButton, Banner },
setup(props, { emit }) {
onMounted(async () => {
const data = await getAdData();
if (!data) {
console.log(`get ad failed`);
return;
}
if (!data.valid) {
console.log(`set ad forbidden`);
return;
}
if (!data.data.length) {
console.log(`not find any ad`);
return;
}
ads.value = data.data;
console.log("get ads ", toRaw(ads.value));
2025-01-23 14:12:07 +08:00
ga(GA_EventName.ShowAd);
});
2025-01-23 14:12:07 +08:00
onUnmounted(() => {});
function testBanner() {
const data = new AdItem();
data.name = "ad test 11111111111 11111111111 44444444444444 5555555555555 111111111111111111 2222222222222222 33333333333333 444444444444444";
data.store = "http://www.baidu.com";
emitter.emit(Msg.ChangeAd, data);
}
let ads = ref<AdItem[]>([]);
return {
ads,
2025-01-23 14:12:07 +08:00
onMouseEnter() {},
onMouseLeave() {},
};
},
});
</script>
<style lang="less" scoped>
2025-01-23 14:12:07 +08:00
@color-bg: #8d8d8da6;
@color-hover: #f9c04e;
@color-active: #ffaa00;
.ad {
display: flex;
2025-01-23 14:12:07 +08:00
flex-direction: column;
.body {
display: flex;
2025-01-23 14:12:07 +08:00
overflow: hidden;
.list {
flex: 1;
display: flex;
2025-01-23 14:12:07 +08:00
flex-direction: column;
align-items: center;
2025-01-23 14:12:07 +08:00
overflow: auto;
}
}
}
</style>