xiaohaizhao 2 år sedan
förälder
incheckning
4c8c905279
1 ändrade filer med 41 tillägg och 7 borttagningar
  1. 41 7
      app.js

+ 41 - 7
app.js

@@ -1,12 +1,46 @@
 import {
-    ApiModel
+	ApiModel
 } from './utils/Api';
 
 App({
-    onLaunch(options) {},
-    globalData: {
-        http: new ApiModel, //挂载接口文件
-        queryPer: require("./utils/queryPermissions"), //权限查询
-        handleSelect: null, //处理选择结果  函数
-    }
+	onLaunch: function () {
+		wx.getSystemInfo({
+			success: e => {
+				this.globalData.StatusBar = e.statusBarHeight;
+				let custom = wx.getMenuButtonBoundingClientRect();
+				this.globalData.Custom = custom;
+				this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
+			}
+		})
+	},
+	initSocket() {
+		let that = this;
+		this.globalData.SocketTask = wx.connectSocket({
+			url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
+			complete: (res) => {
+				console.log(res)
+			}
+		})
+		this.globalData.SocketTask.onOpen(function (res) {
+			that.globalData.socketEstablish = true;
+		})
+		this.globalData.SocketTask.onMessage(function (res) {
+			that.globalData.socketCallback(res)
+		})
+		this.globalData.SocketTask.onError(function (res) {
+			that.globalData.socketEstablish = false;
+		})
+		this.globalData.SocketTask.onClose(function (res) {
+			that.globalData.socketEstablish = false;
+		})
+	},
+	globalData: {
+		http: new ApiModel, //挂载接口文件
+		queryPer: require("./utils/queryPermissions"), //权限查询
+		handleSelect: null, //处理选择结果函数
+		collectCount: "", //购物车商品数量
+		getCollectCount: null, // 获取购物车数量
+		socketEstablish: false, //是否已经建立socket
+		SocketTask: '', // Socket方法
+	},
 })