<script>
	import wsRequest from '@/static/websocket.js'
	export default {
		onLaunch(e) {
			let that = this
			uni.login({
				success(data) {
					let code = data.code
					if (code) {
						that.$tm.request.post('card/login', {
							code
						}).then((res) => {
							uni.setStorageSync('token', res.data.token);
							that.$tm.request.get('user/read').then(res => {
								that.$tm.vx.commit('user/setUserInfo', res.data)
								uni.setStorageSync('card_id', res.data.card_id)
								// websocket开始
								let websocket = new wsRequest("wss://cardoa.platomix.net/chat",
									5000)
								websocket.socketTask.onMessage(
									res => { //onMessage这个监听在封装的js中赋值给了socketTask对象
										let data = JSON.parse(res.data)
										if (data.type !== 'ping') {
											if (data.type == 'init') {
												that.$tm.request.post('chat/bind', {
													'client_id': data.client_id
												})
												// uni.navigateTo({
												// 	url:"/pages/index/detail?card_id=7&isUser=1"
												// })
											} else if (data.type == 'system') {
												// uni.$emit('onSystem', data)
												that.$tm.vx.commit('num/setNum', data.data
													.chat_num)
											} else if (data.type == 'chat') {
												uni.$emit('onMessage', data)
											} else if (data.type == 'track') {
												that.$tm.vx.commit('track/setTrack', data.data)
											}
										}
									})
							})
						})
					}

				}
			});
		},
		onShow: function() {
			let that = this
			// #ifdef MP
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {});
			updateManager.onUpdateReady(function(res) {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，确认重启应用？',
					showCancel: false,
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});

			updateManager.onUpdateFailed(function(res) {
				// 新的版本下载失败
				uni.showModal({
					title: '更新提示',
					content: '新版本更新失败,确认重试',
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});

			// #endif
		},
		onHide: function() {}
	}
</script>
<style lang="scss">
	/** 主题包 **/
	@import './static/theme.scss';

	.shadow-white-25 {
		box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.35) !important;
	}

	/* 弧形背景 */
	.pure_top {
		position: relative;
		width: 100%;
		text-align: center;
	}

	.pure_top::after {
		width: 100%;
		height: 200rpx;
		position: absolute;
		left: 0;
		top: 0;
		z-index: -1;
		content: '';
		border-radius: 0 0 10% 10%;
		background: rgba(59, 92, 240, 1) !important;
	}

	.cu-tabbar-height {
		padding: 0;
		// height: calc(100upx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
	}

	.visitor-items-userInfo {
		color: #7F8AA3;
		font-size: 30rpx;
	}
</style>
<style>
	/*每个页面公共css */
	@import "./tm-vuetify/mian.min.css";
	@import "@/static/main.css";
	/* 主题包 */
	@import "./tm-vuetify/scss/theme.css";

	@import "./tm-vuetify/scss/fonts/fontawesome_base64.css";
</style>
