<script lang="uts">
	export default {
		onLaunch: function (options: OnLaunchOptions) {
			console.log('App Launch')
			console.log('启动参数:', options)
			uni.onPushMessage((res) => {
				console.log("收到推送消息：",res) //监听推送消息
				if(res.type =='receive'){
					uni.setAppBadgeNumber(0);
					// 安全取出推送数据并强转类型
					const pushData = res.data as UTSJSONObject
					const title = pushData["title"] as string
					const content = pushData["content"] as string
					if (title!=null && content!=null) {
						uni.createPushMessage({
							title: title,
							content: content,
							when: Date.now() + 10000,
							icon: "/static/login/2.png",
							sound: "system",
							success: (res) => {
								console.log('创建推送消息成功', res);
							},
							fail: (err) => {
								console.error('创建推送消息失败', err);
							}
						});
					}
				}
			})
			
			// 清空之前的缓存
			uni.removeStorageSync('emcs_ticket')
			
			// 如果有启动参数，尝试提取apptoken
			if (options != null) {
				// 1. 从query获取
				const query = options.query
				if (query != null) {
					const ticketValue = query['ticket']
					if (ticketValue != null) {
						const ticket = ticketValue as string
						console.log('保存ticket到缓存:', ticket)
						uni.setStorageSync('emcs_ticket', ticket)
					}
				}
			}
			
			uni.setStorageSync("notify_key", "0")
		},
		onShow: function (options: OnShowOptions) {
			console.log('App Show')
		},
		onHide: function () {
			console.log('App Hide')
			// this.startTimer();
		},
		// #ifdef APP-ANDROID
		onLastPageBackPress: function () {
			console.log('App LastPageBackPress')
			// #ifdef APP-ANDROID
				UTSAndroid.getUniActivity()?.moveTaskToBack(true)
			// #endif
			
			// #ifdef APP-HARMONY
				UTSHarmony.getUIAbilityContext().moveAbilityToBackground()
			// #endif
		},
		// #endif
		onExit: function () {
			console.log('App Exit')
		},
		methods:{
			
		}
	}
</script>

<style lang="scss">
	@import './static/css/form.scss';
	/*每个页面公共css */
	
	/* 布局 */
	.uni-row {
		flex-direction: row;
	}

	.uni-column {
		flex-direction: column;
	}
	
	/* 文字颜色 */
	.text-primary {
		color: #333333;
	}
	
	.text-secondary {
		color: #666666;
	}
	
	.text-placeholder {
		color: #999999;
	}
	
	/* 背景色 */
	.bg-white {
		background-color: #ffffff;
	}
	
	.bg-gray {
		background-color: #f5f5f5;
	}
	
	/* 间距 */
	.padding-sm {
		padding: 15rpx;
	}
	
	.padding-md {
		padding: 20rpx;
	}
	
	.padding-lg {
		padding: 30rpx;
	}
	
	.margin-sm {
		margin: 15rpx;
	}
	
	.margin-md {
		margin: 20rpx;
	}
	
	.margin-lg {
		margin: 30rpx;
	}
	
	/* 圆角 */
	.radius-sm {
		border-radius: 4rpx;
	}
	
	.radius-md {
		border-radius: 8rpx;
	}
	
	.radius-lg {
		border-radius: 12rpx;
	}
</style>

<style>
	/* #ifdef APP-HARMONY */
	/* 鸿蒙平台全局样式 */
	.l-input__placeholder {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #999999 !important;
	}

	.l-textarea__placeholder {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #999999 !important;
	}

	.l-input__control {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #131415 !important;
	}

	.l-textarea__control {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #131415 !important;
	}

	.uni-input-input {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #131415 !important;
	}

	.uni-textarea-textarea {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #131415 !important;
	}

	.uni-input-placeholder,
	.uni-textarea-placeholder {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #999999 !important;
	}

	/* #endif */
</style>