<script>
import Vue from "vue";
import AudioManager from "./common/audio.js";
// 移除全局预览弹窗方法导入

export default {
	data() {
		return {
			isFirstLaunch: true, // 添加标志变量，用于标记是否是首次启动
		}
	},
	onLaunch: function (options) {
		// console.log("App Launch", options, window.location.href);
		var that = this;
		// 在需要检查的地方

		this.$config.init().then(async (data) => {
			console.log('加载抽奖音乐。。。。');
			//加载配置
			let src = await that.$config.getAppSettingAsync("win_audio");
			if (src == null || src == "") {
				src = that.$img("/static/mp3/open.mp3");
			}
			//创建中奖音乐
			const openBgm = uni.createInnerAudioContext();
			Vue.prototype.bgmCtx = {};
			openBgm.src = src;
			openBgm.sessionCategory = "playback";
			openBgm.onPlay(() => {
				console.log('开始播放抽奖弹窗播放');
			});
			openBgm.onPause(() => {
				console.log('播放抽奖弹窗音乐暂停');
			});
			openBgm.onStop(() => {
				console.log('播放抽奖弹窗音乐停止');
			});
			openBgm.onError((res) => {
				console.log('播放抽奖弹窗失败');
				console.log(res.errMsg);
				console.log(res.errCode);
			});
			Vue.prototype.bgmCtx.openBgm = openBgm;
			//抽音效
			let src2 = await that.$config.getAppSettingAsync("win_audio2");
			if (src2 == null || src2 == "") {
				src2 = that.$img("/static/mp3/slot_open.mp3");
			}
			//创建中奖音乐
			const slotBgm = uni.createInnerAudioContext();
			slotBgm.src = src2;
			Vue.prototype.bgmCtx.slotBgm = slotBgm;
			//超神音效
			let src3 = await that.$config.getAppSettingAsync("win_audio3");
			if (src3 == null || src3 == "") {
				src3 = that.$img("/static/mp3/chaoshen.mp3");
			}
			//创建中奖音乐
			const csBgm = uni.createInnerAudioContext();
			// Vue.prototype.bgmCtx = {};
			csBgm.src = src3;
			Vue.prototype.bgmCtx.csBgm = csBgm;

			//宝箱音效
			let src4 = await that.$config.getAppSettingAsync("win_audio4");
			if (src4 == null || src4 == "") {
				src4 = that.$img("/static/mp3/clipchamp.mp3");
			}
			//创建中奖音乐 audio
			const baoXiangBgm = uni.createInnerAudioContext();
			baoXiangBgm.src = src4;
			Vue.prototype.bgmCtx.baoXiangBgm = baoXiangBgm;
			Vue.prototype.audioManager = new AudioManager(openBgm, slotBgm, csBgm, baoXiangBgm);
		});

		// 调用登录记录接口
		this.callLoginRecordApi();

		/* 重置首页公告弹窗状态 */
		uni.setStorageSync("_is_this_show", false);

		/* 清除缓存中的广告id */
		uni.removeStorageSync("_ad_id");
		/* 清除缓存中的click_id */
		uni.removeStorageSync("_click_id");
		// 调用平台启动方法
		this.$platform.AppLaunch(options);


	},

	onShow: function () {
		console.log("App Show");

	},
	onHide: function () {
		console.log("App Hide");
	},
	methods: {
		// 调用登录记录接口的方法
		callLoginRecordApi() {
			// 检查用户是否已登录
			const token = uni.getStorageSync('token');
			if (!token) {
				console.log('用户未登录，不调用登录记录接口');
				return;
			}
			this.req({
				url: 'login_record',
				method: 'POST',
				success: (res) => {
					console.log('登录记录接口调用成功', res);
				},
				fail: (err) => {
					console.log('登录记录接口调用失败', err);
				}
			});
		}
	}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import "./common/animate.css";
@import url("./common/common.css");

uni-tabbar {
	display: block;
	box-sizing: border-box;
	width: 100%;
	z-index: 97 !important;
}

uni-tabbar .uni-tabbar__icon img{
	height: 24px !important;
	width: 24px !important;
}

/* 引入字体 */
@font-face {
	font-family: "YouSheBiaoTiHei";
	src: url($imgurl + "font/YouSheBiaoTiHei.ttf") format("truetype");
}

@font-face {
	font-family: "zihun152hao-jijiachaojihei";
	src: url($imgurl + "font/zihun152hao-jijiachaojihei.TTF") format("truetype");
}

@font-face {
	font-family: "zihun147hao-xingyuanhei";
	src: url($imgurl + "font/zihun147hao-xingyuanhei.TTF") format("truetype");
}

page {
	overflow-x: hidden;

	&:before {
		content: "";
		position: fixed;
		z-index: -1;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: #1c1b20;
	}
}

.ziti {
	font-family: YouSheBiaoTiHei;
}

.flex_center {
	display: flex;
	align-items: center;
}

.hang2 {
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	word-wrap: break-word;
	word-break: break-all;
}

.hang1 {
	overflow: hidden;
	/*超出部分隐藏*/
	white-space: nowrap;
	/*不换行*/
	text-overflow: ellipsis;
	/*超出部分文字以...显示*/
}

.icon {
	display: flex;
	justify-content: center;
	align-items: center;

	image {
		width: 100%;
		height: 100%;
	}
}

.common_bg {
	background-repeat: no-repeat;
	background-position: 0 0;
	background-size: 100% 100%;
}

.relative {
	position: relative;
}

button.hide {
	position: absolute;
	width: 100% !important;
	height: 100% !important;
	left: 0;
	top: 0;
	z-index: 1;
	opacity: 0;
}

/* 重写组件样式 */
::v-deep.uni-noticebar {
	padding: 0 !important;
	margin: 0 !important;
}

::v-deep.mescroll-upwarp {
	box-sizing: border-box;
	min-height: 55px;
	padding: 15px 0;
	text-align: center;
	clear: both;
}

::v-deep.cmd-progress-outer {
	line-height: 0;

	.cmd-progress-bg {
		margin: 0 !important;
	}
}

.uni-tabbar__bd {
	height: 50px !important;
}

.uni-tabbar__icon {
	height: 50px !important;
}

@keyframes m-zoom {
	0% {
		transform: scale(1);
	}

	50% {
		transform: scale(0.9);
	}

	100% {
		transform: scale(1);
	}
}
</style>