????????????????????????app.js onLaunch???????????????????????????onLoad????????????????????????(代码片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了????????????????????????app.js onLaunch???????????????????????????onLoad????????????????????????(代码片相关的知识,希望对你有一定的参考价值。

?????????turn   setting   ????????????   UNC   ??????   tin   ??????   span   detail   

?????? Promise ?????????????????????????????????app.js onLaunch ???????????????????????????

app.js onLaunch ?????????

????????????
  1 "use strict";
  2 Object.defineProperty(exports, "__esModule", {
  3   value: true
  4 });
  5 const http = require(???./utils/http.js???);
  6 const api = require(???./config.js???);
  7 App({
  8   onLaunch: function() {
  9     var _this = this;
 10     _this.GetSystemInfo();
 11     if (!_this.globalData.openid) {
 12       _this.toLogin();
 13     }
 14 
 15 
 16   },
 17   globalData: {
 18     screenWidth: 0, //????????????
 19     screenHeight: 0, //????????????
 20     fontSize: 14, //????????????
 21     openid: ??????,
 22     phone: ??????,
 23     shopid: ??????, //??????openid ??????
 24     logined: false, //??????????????????????????????
 25     nickname: ??????, //??????
 26     photo: ??????, //??????
 27     editJobStorageKey: ???edit-job-storage???, //?????????????????????????????????
 28     isbindrole: false, //???????????????????????????????????????
 29     rolenumber: ??????, //????????????
 30     rolename: ??????, //????????????
 31     shopname: ??????,
 32     branchListStorageKey: ???branch-list-storage???, //????????????
 33     branchCityListStorageKey: ???branch-city-list-storage???, //??????????????????
 34     auth_num: 0, //?????????????????????
 35     productname: ??????, //??????????????????
 36   },
 37   GetSystemInfo: function() {
 38     var _this = this;
 39     const info = wx.getSystemInfoSync();
 40     _this.globalData.screenWidth = info.screenWidth;
 41     _this.globalData.screenHeight = info.screenHeight;
 42     _this.globalData.fontSize = info.fontSizeSetting;
 43   },
 44 
 45 
 46 
 47   //????????????  ?????????shopid
 48   toLogin: function() {
 49     console.log(????????????LOGIN???);
 50     var _this = this;
 51     return new Promise(function(resolve, reject) {
 52       wx.login({
 53         success: function(res) {
 54           var code = res.code;
 55           console.log(res);
 56           var postData = {
 57             code: code,
 58             shopid: _this.globalData.shopid
 59           };
 60           wx.showLoading({
 61             title: ????????????...???,
 62           })
 63           http.httpPost(api.Login, postData, function(result) {
 64             console.log(result);
 65             wx.hideLoading();
 66             if (result.success) {
 67               if (result.result.success) {
 68                 _this.globalData.openid = result.result.data.openid;
 69                 if (result.result.data.phone) {
 70                   _this.globalData.phone = result.result.data.phone;
 71                 }
 72                 if (result.result.data.photo) {
 73                   _this.globalData.photo = result.result.data.photo;
 74                 }
 75                 if (result.result.data.nickname) {
 76                   _this.globalData.nickname = result.result.data.nickname;
 77                 }
 78 
 79                 //????????????????????????
 80                 if (result.result.data.shopidlist && result.result.data.shopidlist.length > 0) {
 81                   //???????????????????????????????????????????????????????????????
 82                   if (result.result.data.shopidlist.length == 1) {
 83                     _this.globalData.shopid = result.result.data.shopidlist[0];
 84                     _this.toGetUserRole();
 85                     _this.toGetShopInfo();
 86                   } else {
 87                     //??????????????????????????????????????????????????????
 88                     wx.redirectTo({
 89                       url: ???../../pages/shoplist/shoplist???,
 90                     })
 91                   }
 92                 } else {
 93                   _this.globalData.isbindrole = false;
 94                   _this.globalData.rolenumber = ??????;
 95                   _this.globalData.rolename = ??????;
 96                 }
 97 
 98                 resolve(result);
 99 
100               } else {
101                 wx.showModal({
102                   title: ????????????,
103                   content: result.success.message,
104                 })
105                 reject(???error???);
106               }
107             } else {
108               wx.showModal({
109                 title: ????????????,
110                 content: ????????????????????? + result.error.message,
111               })
112               reject(???error???);
113             }
114           })
115         }
116       });
117 
118     });
119 
120   },
121 
122   toGetShopInfo: function() {
123     var _this = this;
124     var postData = {
125       ???shopid???: _this.globalData.shopid
126     };
127     http.httpPost(api.GetShopInfo, postData, (res) => {
128       console.log(res);
129       if (res.success) {
130         var _result = res.result;
131         if (_result.success) {
132           _this.globalData.shopname = _result.data.shopname;
133           _this.globalData.productname = _result.data.product;
134           _this.globalData.auth_num = _result.data.auth_num;
135 
136         } else {
137           wx.showModal({
138             title: ????????????,
139             content: ??????,
140           })
141         }
142       } else {
143         wx.showModal({
144           title: ????????????,
145           content: res.error,
146           showCancel: false
147         })
148       }
149 
150     });
151   },
152 
153   //?????????????????????????????????
154   toGetUserRole: function() {
155     var _this = this;
156     var postData = {
157       ???shopid???: _this.globalData.shopid,
158       ???openid???: _this.globalData.openid
159     };
160     http.httpPost(api.ObtainUserRole, postData, function(res) {
161       console.log(res);
162       if (res.success) {
163         var _result = res.result;
164         if (_result.success) {
165           _this.globalData.isbindrole = true;
166           _this.globalData.rolenumber = _result.data.rolenumber;
167           _this.globalData.rolename = _result.data.rolename;
168         } else {
169           _this.globalData.isbindrole = false;
170           _this.globalData.rolenumber = ??????;
171           _this.globalData.rolename = ??????;
172           wx.showModal({
173             title: ????????????,
174             content: _result.message,
175             showCancel: false
176           })
177         }
178       } else {
179         wx.showModal({
180           title: ????????????,
181           content: res.error,
182           showCancel: false
183         })
184       }
185     });
186   }
187 });
View Code

???????????????????????? onlaod?????????????????? Promise ???then?????????

????????????
 1  onLoad: function() {
 2 
 3     var _this = this;
 4     app.toLogin().then(function(res) {
 5       console.log(???????????????);
 6       console.log(res);
 7       if (app.globalData.shopid) {
 8         _this.toGetKanBanData();
 9         _this.toGetSaleDetail();
10         _this.toGuestOrderDetail();
11       }
12     });
13 
14   },
View Code

 

以上是关于????????????????????????app.js onLaunch???????????????????????????onLoad????????????????????????(代码片的主要内容,如果未能解决你的问题,请参考以下文章

a++和++a的区别

逻辑代数

python运算符

运算符

arraylist排序 例如值 a104,a106,a102,a92,a98,a94 结果a92,a94,a98,a102,a104,a106

2.2赋值运算题目分析