<script>
	export default {
		globalData: {},
		onLaunch: function(lopn) {
			var bggray1 = '#dfdfdf';
			var bggray2 = '#bbbbbb';
			var bgsel1 = '#ffdc72';
			var bgsel2 = '#e65411';
			var app = this;
			app.globalData.scrollcbs = {};
			app.globalData.launchopn = lopn;
			console.log('launchopn', lopn);
			app.launch();

			app.globalData.tabbarArr = [];
			var svg = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M10,515c0,277,225,503,503,503s503-225,503-503l0,0c0-277-225-503-503-503S9,238,10,515L10,515z" fill="{{bg2}}"></path><path d="M777,322L547,178c-28-18-64-18-91,0L226,322c-25,16-40,43-40,73v263c0,76,61,137,137,137h61V633l0,0c0-66,53-119,119-119l0,0c66,0,119,53,119,119v162h61l0,0c76,0,137-61,137-137V395c-1-29-17-56-42-73H777z" fill="{{bg1}}"></path></svg>';
			app.globalData.tabbarArr.push({
				name: 'tabbar.index',
				fullpath: '/pages/main/index',
				selecticon: svg.replaceAll(/{{bg1}}/g, bgsel1).replaceAll(/{{bg2}}/g, bgsel2),
				icon: svg.replaceAll(/{{bg1}}/g, bggray1).replaceAll(/{{bg2}}/g, bggray2)
			});
			// var svg = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M969,956L913,810c51-81,107-209,103-313C1008,230,789,15,522,10C237,5,5,237,9,522c4,274,223,494,497,494c69,0,208-38,265-75L932,997C954,998,972,979,969,956L969,956z" fill="{{bg2}}"></path><path d="M715,299l-22,133c-3,16,3,32,15,43l99,94c20,19,20,49,1,69c-7,7-17,12-28,15l-134,21c-16,3-30,12-37,27l-59,122c-12,25-42,35-65,22c-10-5-17-12-22-22l-62-121c-7-15-21-25-37-27l-134-19c-27-4-46-28-42-55c1-11,6-21,14-28l96-96c11-11,17-27,14-43l-23-134c-5-27,14-52,39-57c11-1,22,0,31,5l121,63c15,7,32,7,46,0l119-64c23-12,54-4,67,20C715,277,716,288,715,299z" fill="{{bg1}}"></path></svg>';
			// app.globalData.tabbarArr.push({
			// 	name: 'tabbar.zh',
			// 	fullpath: '/pages/expo',
			// 	selecticon: svg.replaceAll(/{{bg1}}/g, bgsel1).replaceAll(/{{bg2}}/g, bgsel2),
			// 	icon: svg.replaceAll(/{{bg1}}/g, bggray1).replaceAll(/{{bg2}}/g, bggray2)
			// });
			// var svg = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M788,950h-551c-80,0-144-64-144-144V281h839v524C933,886,869,950,788,950L788,950z" fill="{{bg2}}"></path><path d="M685,842H352c-33,0-60-27-60-60s27-60,60-60h333c33,0,60,27,60,60S718,842,685,842z M946,322H80c-41,0-75-33-75-75V136c0-41,33-75,75-75h866c41,0,75,33,75,75v111C1021,288,988,322,946,322z" fill="{{bg1}}"></path></svg>';
			// app.globalData.tabbarArr.push({
			// 	name: 'tabbar.sq',
			// 	fullpath: '/pages/socg',
			// 	selecticon: svg.replaceAll(/{{bg1}}/g, bgsel1).replaceAll(/{{bg2}}/g, bgsel2),
			// 	icon: svg.replaceAll(/{{bg1}}/g, bggray1).replaceAll(/{{bg2}}/g, bggray2)
			// });
			var svg = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M207,110h614c109,0,197,88,197,197v416c0,109-88,197-197,197H207c-109,0-197-88-197-197V308C9,198,97,110,207,110z" fill="{{bg2}}"></path><path d="M865,819H118c-10,0-19-9-19-19c0-3,1-7,2-10l26-35c3-6,10-9,17-9h748c10,0,19,9,19,19c0,3-1,7-2,10l-26,35C878,815,872,819,865,819z M451,285c0-8-6-14-14-14h-246c-8,0-14,6-14,14v246c0,8,6,14,14,14h246c8,0,14-6,14-14V285z M909,503c0-8-6-14-14-14H562c-8,0-14,6-14,14v25c0,8,6,14,14,14h333c8,0,14-6,14-14V503z" fill="{{bg1}}"></path></svg>';
			app.globalData.tabbarArr.push({
				name: 'tabbar.notify',
				fullpath: '/pages/main/notify',
				selecticon: svg.replaceAll(/{{bg1}}/g, bgsel1).replaceAll(/{{bg2}}/g, bgsel2),
				icon: svg.replaceAll(/{{bg1}}/g, bggray1).replaceAll(/{{bg2}}/g, bggray2)
			});
			var svg = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M706,460c64-38,107-104,107-179c0-118-106-213-237-213c-131,0-237,95-237,213c0,75,43,141,107,179c-181,51-311,206-311,385c0,39,35,70,78,70H938c43,0,78-32,78-70v-5C1017,661,886,511,706,460L706,460z" fill="{{bg1}}"/><path d="M580,472c64-42,107-115,107-197c0-131-106-237-237-237c-131,0-237,106-237,237c0,83,43,155,107,199c-181,57-311,228-311,427c0,43,14,76,57,76l745,1c43,0,78-35,78-78v-6C891,696,761,528,580,472L580,472z" fill="{{bg2}}"/></svg>';
			app.globalData.tabbarArr.push({
				name: 'tabbar.me',
				fullpath: '/pages/main/me',
				selecticon: svg.replaceAll(/{{bg1}}/g, bgsel1).replaceAll(/{{bg2}}/g, bgsel2),
				icon: svg.replaceAll(/{{bg1}}/g, bggray1).replaceAll(/{{bg2}}/g, bggray2)
			});

			app.globalData.errdata = app.getstorage('err');
			if (!(app.globalData.errdata instanceof Array))
				app.globalData.errdata = [];
			app.globalData.mqfunc = [];

			app.globalData.srv = 't';
			app.globalData.jsnajax = 'ambap/';
			app.globalData.jsnurl = {};
			app.globalData.jsnurl.t = 'https://labsci.ciy.cn/';
			app.globalData.demourl = 'https://i.qiboc.cn/app.goc'; //原型图地址
			app.globalData.tokenfield = "ciyap";
			app.globalData.tokensalt = "ast34h$3";
			app.globalData.mainpage = '/pages/main/index';
			app.globalData.sharefirstpage = '';//  /pages/pub/index';
			app.globalData.meid = 0;
			app.globalData.dupsec = 60;
			app.globalData.storselect = '/';
			app.globalData.storlist = {
				'/': 'https://labsci.ciy.cn/ud/',
				'A': 'https://cf5.nyyzsoft.cn/ud/'
			};
			app.globalData.stortransfer = ['/'];

			if (process.env.NODE_ENV === 'development') {
				//#ifdef H5
				app.globalData.jsnurl.t = 'https://labsci.local.ciy.cn/';
				app.globalData.storlist['/'] = 'https://labsci.local.ciy.cn/ud/';

				//golang
				// app.globalData.jsnurl.t = 'http://ciyonhgo.local.ciy.cn/';
				//#endif
			}

			setInterval(() => {
				if (app.globalData._restorage) {
					app.callfunc({
						func: 'login.restorage',
						data: {},
						loadhide: true,
					}).then(retjson => {
						if (retjson.code != 1)
							return;
						console.log('新字典已刷新', retjson);
						var userdata = app.setuserstorage(retjson);
						var ps = getCurrentPages();
						userdata.g = app.getstorage('g', {});
						for (var p = 0; p < ps.length; p++) {
							for (var key in userdata) {
								//#ifdef MP-WEIXIN
								ps[p].$vm[key] = userdata[key];
								//#endif
								//#ifndef MP-WEIXIN
								ps[p][key] = userdata[key];
								//#endif
							}
						}
					});
				}
				app.globalData._restorage = false;
				if (app.globalData.errdata.length > 0) {
					app.callfunc({
						func: 'login.uperr',
						data: {
							meid: app.getme().id,
							err: app.globalData.errdata
						},
						loadhide: true,
					});
					app.globalData.errdata = [];
					app.removestorage('err');
				}
			}, 1000);
			setInterval(async () => {
				if (app.globalData.mqfunc.length > 0) {
					console.log(app.globalData.mqfunc);
					var ret = await app.callfunc({
						func: app.globalData.mqfunc[0].func,
						data: app.globalData.mqfunc[0].data,
						loadhide: true,
					});
					var name = app.globalData.mqfunc[0].name;
					for (var i = app.globalData.mqfunc.length - 1; i >= 0; i--) {
						if (app.globalData.mqfunc[i].name == name) {
							app.globalData.mqfunc[i].callback(ret);
							app.globalData.mqfunc.splice(i, 1);
						}
					}
				}
			}, 200);
			setInterval(() => {
				getnewnotice();
			}, 120000); //2分钟请求一次notice
			getnewnotice();
			//lopn 结合me，将数据上传到平台
			function getnewnotice() {
				return;
				app.callfunc({
					func: 'me.notice_new',
					showload: false,
					success: json => {
						app.setTabbar({
							'index.detail': {
								reddot: false
							}
						});
					}
				});
			}

			//#ifdef MP-WEIXIN
			const accountInfo = uni.getAccountInfoSync();
			app.globalData._wxappid = accountInfo.miniProgram.appId;
			app.globalData._wxenv = accountInfo.miniProgram.envVersion;
			app.globalData._version = accountInfo.miniProgram.version;
			if (!app.globalData._version)
				app.globalData._version = accountInfo.miniProgram.envVersion;
			//#endif
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
				app.globalData._version = widgetInfo.version;
			});
			app.appupdate('app');
			uni.getPushClientId({
				success: (res) => {
					console.log('客户端推送标识:',res);
					app.globalData._appcid = res.cid;
				}
			})
			uni.onPushMessage((res)=>{
				this.alert(JSON.stringify(res));
			})
			// #endif

			var sysinfo = app.globalData._sysinfo;
			// #ifdef APP-PLUS
			if (sysinfo.model == 'k71v1_64_bsp') {
				app.device_rfid = uni.requireNativePlugin("UhfGModule"); // 133左/134枪/135右
				app.device_rfid_gunkey = 134;
			} else if (sysinfo.model == 'k62v1_6c') {
				app.device_rfid = uni.requireNativePlugin(
					"UhfGModule"); //C61型号，手柄按键137，左侧135，右侧是136 F1-F4对应131-134
				app.device_rfid_gunkey = 137;
			}
			console.log('device_rfid', app.device_rfid);
			// #endif
			// #ifndef H5
			app.globalData.dev_bt = {};
			//自动连接蓝牙
			this.info = uni.getStorageInfoSync();
			this.info.kv = {};
			this.info.total = 0;
			for (var i in this.info.keys) {
				var key = this.info.keys[i];
				if (key.indexOf('dev_bt_') !== 0)
					continue;
				var savedev = app.getstorage(key);
				var devup = key.substr(7);
				console.log('auto', savedev, devup);
				if (devup != savedev.devup) {
					console.log('蓝牙自动连接设置错误', devup, savedev.devup);
					continue;
				}
				app.connectbt(savedev.devup, savedev.devtype, savedev.id);
			}

			uni.onBLEConnectionStateChange(res => {
				//设置dev_bt，重连。
				console.log('statechanged', res);
				for (var dup in app.globalData.dev_bt) {
					var devbt = app.globalData.dev_bt[dup];
					if (devbt.deviceid != res.deviceId)
						continue;
					devbt.opened = res.connected ? 10 : 9;
					if (typeof(devbt.onmsg) == 'function')
						devbt.onmsg(res);
					if (res.connected)
						return;
					if (devbt.enableclose)
						return;
					console.log('re devopen' + devbt.deviceid);
					devbt.bt_devopen(devbt.deviceid);
					return;
				}
			});
			uni.onBLECharacteristicValueChange(res => {
				console.log('onBLECharacteristicValueChange', res);
				for (var dup in app.globalData.dev_bt) {
					var devbt = app.globalData.dev_bt[dup];
					if (devbt.deviceid != res.deviceId)
						continue;
					var dat = devbt.convertmsg(res);
					res.data = dat;
					if (typeof(devbt.onmsg) == 'function')
						devbt.onmsg(res);
				}
			});

			// #endif

		},
		onShow: function() {},
		onHide: function() {},
		methods: {}
	}
</script>
<style>
</style>