yangyin
2024-07-23 0e91f622ec33a28b47a46204996462a2b7643fe1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
var Constant = require('../../utils/constant.js');
var app = getApp();
 
Page({
  data: {
    phone: '',
    password: '',
    checked: false,
    imageWidth: 100,
    imageHeight:500,
    inputViewWidth: 100,
    inputViewHeight: 100,
    inputWidth: 100,
    inputHeight: 100,
 
    userInfo: {},
 
    jsCode: null,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
 
    LogoUrl: Constant.Assets.Login.LogoUrl,
    BackgroupImageUrl: Constant.Assets.Login.BackgroupImageUrl,
 
    isShowPwd: false, //是否显示密码
    m_SoftWareVersion: Constant.SoftWareVersion
  },
 
  // 打电话
  call: function () {
    wx.makePhoneCall({
      phoneNumber: "021-34306562"
    })
  },
  // 获取输入密码
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },
  // 记住密码框
  rememberPwd(e) {
    this.setData({
      checked: e.detail.value.includes('1')
    })
  },
  // 获取输入电话号码
  phoneInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  //清除账号
  clearnAccount() {
    this.setData({
      phone: ""
    })
  },
  //显示密码
  changePwdView() {
    if (this.data.password == "") {
      return
    }
    this.data.isShowPwd = !this.data.isShowPwd
    this.setData({
      isShowPwd: this.data.isShowPwd
    })
  },
  //获取用户登录信息
  getWxUserLoginCodeCb() {
    let promise = new Promise((resolve, reject) => {
      wx.login({
        success: function (res) {
          // console.log(res,48)
          if (res.code) {
            resolve(res);
          } else {
            wx.showModal({
              content: '登录失败',
              showCancel: false,
              confirmColor: "#39b5de"
            });
          }
        },
        fail: function (err) {
          reject(err)
        }
      })
    })
    return promise;
  },
  //演示账户 
  loginByDemo: function (jsCode) {
    let that = this;
 
    var userInfo = this.data.userInfo;
    userInfo.EmployeeID = Constant.Assets.Login.DemoEmployeeID; //演示账户
    userInfo.CorpID = Constant.CorpID;
    userInfo.RealName = "演示账户(JT)";
    userInfo.WxUserCode = "";
    userInfo.LoginUserID = Constant.Assets.Login.DemoUserID;
    userInfo.Telphone = "";
    // 
    that.loginSuccessCb(userInfo);
  },
 
  //真实用户
  loginByReal: function (jsCode) {
    let that = this;
    var userInfo = this.data.userInfo;
    var sysInfo = app.globalData.sysInfo;
    // console.log('打印userInfo', userInfo)
    wx.showToast({
      title: '登录中',
      icon: "loading",
      duration: 3000
    });
    // let data={
    //   SoftType:Constant.SoftType,
    //   SoftTag:Constant.SoftTag,
    //   LoginName: this.data.phone,
    //   LoginPwd: this.data.password,
    //   CorpID: Constant.CorpID,
    //   WxCode: jsCode,
    //   UJsCode: jsCode, //是否就是jsCode有待确认
    //   UAvatarUrl: userInfo == null ? "" : userInfo.avatarUrl,
    //   UCity: userInfo == null ? "" : userInfo.city,
    //   UProvince: userInfo == null ? "" : userInfo.province,
    //   UNickName: userInfo == null ? "" : userInfo.nickName,
    //   UGender: userInfo == null ? "" : userInfo.gender + "",
    //   SBrand: sysInfo.brand,
    //   SModel: sysInfo.model,
    //   SPlatform: sysInfo.platform,
    //   SVersion: sysInfo.version
    // }
    let data = {
      LoginName: that.data.phone,
      LoginPwd: that.data.password,
      Software: Constant.Software
    }
    // console.log(JSON.stringify(data),110)
    var post_url = Constant.BASE_AUTH_URL + "Auth/User/Login/LoginSoftwareStandardBySystemAccount@V1.0";
    wx.request({
      url: post_url,
      method: 'POST',
      data: data,
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) { //请求失败
        wx.hideToast();
        wx.showModal({
          content: err,
          showCancel: false,
          confirmColor: "#39b5de"
        });
      },
      success: function (res) {
        //  console.log(res,123)
 
        wx.hideToast();
 
        var result = res.data;
        // console.log(result);
        if (result.Code != 0) {
          wx.showModal({
            content: "账号密码不正确",
            showCancel: false,
            confirmColor: "#39b5de"
          });
          return;
        }
 
        var return_data = result.Data;
        if (return_data.Status != 0) {
          wx.showModal({
            content: "账号密码不匹配",
            showCancel: false,
            confirmColor: "#39b5de"
          });
          return;
        }
        let Token = return_data.AccessToken
        let RefreshToken = return_data.RefreshToken
        let isNeedToken = false //是否需要Token 当Token失效的时候 判断是否跳转登录
        if (Token) {
          isNeedToken = true
        }
 
        let Checked = {}
        if (that.data.checked) {
          Checked = {
            phone: that.data.phone,
            password: that.data.password,
            checked: that.data.checked
          }
        }
        let ExpreTime = new Date().getTime() //获取当前时间戳
        wx.setStorageSync('AccountInfo', Checked)
        wx.setStorageSync('AccessToken', {
          Token: Token,
          RefreshToken: RefreshToken,
          ExpreTime: ExpreTime,
          isNeedToken: isNeedToken,
        })
 
        var return_user = return_data.User;
        //console.log(return_user);
 
        userInfo.ID = return_user.ID
        // userInfo.WxUserCode = return_user.LastLoginWxUserCode;
        userInfo.EmployeeID = return_user.EmployeeID; //使用员工ID
        userInfo.CorpID = return_user.LoginAccount.ID;
        userInfo.RealName = return_user.Name;
        // userInfo.Telphone = return_user.Telphone;
        //console.log(userInfo);
 
        that.loginSuccessCb(userInfo);
      }
    });
  },
  //登录成功
  loginSuccessCb: function (userInfo) {
    var that = this;
    //console.log(userInfo,184)
    that.setData({
      userInfo: userInfo
    });
    //
    //if (wx.getStorageSync("LoginUserInfo")) {
    //  app.globalData.userInfo = userInfo;
    //}
    wx.setStorageSync("LoginUserInfo", userInfo);
    app.globalData.userInfo = userInfo;
    wx.showToast({
      title: '正在跳转',
      icon: 'loading',
      duration: 1000
    })
  
    wx.switchTab({
      url: '../../workDesktop/index/index',
    })
    app.onStartAlarm()
 
    // var pages = getCurrentPages();
    // if (pages.length >= 2) {
    //   //var currPage = pages[pages.length - 1];   //当前页面
    //   var prevPage = pages[pages.length - 2]; //返回上一个页面
    //   //console.log(prevPage.route)
    //   if (prevPage) {
    //     var fn = prevPage.refreshUserInfo;
    //     if (typeof fn == "function")
    //       fn();
    //     wx.navigateBack();
    //   } else {
    //     wx.navigateTo({
    //       url: "/workDestop/index/index"
    //     });
    //   }
    // } else {
    //   wx.navigateBack();
    // }
  },
  //点击真实用户登录按钮
  tapBindUserReal: function (e) {
    // console.log(e)
 
    let that = this;
 
    if (this.data.phone.length < 0 || this.data.password.length < 0) {
      wx.showToast({
        title: '用户名或密码不能为空够!',
        icon: 'none',
        duration: 2000
      });
      return;
    }
 
    if (this.data.phone.length < 2 || this.data.password.length < 5) {
      wx.showToast({
        title: '用户名密码长度不够!',
        icon: 'none',
        duration: 2000
      });
      return;
    }
 
    wx.getUserProfile({
      desc: '用于登录验证', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        // console.log(res)
        if (res.errMsg == 'getUserProfile:fail auth deny') { //判断用户是否取消了授权
          wx.showToast({
            title: '已取消授权',
            icon: 'none',
            duration: 2000
          })
          return;
        }
        if (res.errMsg == 'getUserProfile:ok') { //判断用户是否授权
          wx.showToast({
            title: '已确定授权',
            icon: 'none',
            duration: 2000
          })
          that.setData({
            userInfo: res.userInfo,
          })
 
          that.getWxUserLoginCodeCb().then((loginParas) => {
            // console.log(loginParas.code)
            var jsCode = loginParas.code;
            if (e.detail.userInfo == undefined || e.detail.userInfo == null) {
              wx.showToast({
                title: '授权失败请重新授权',
              })
            }
            that.loginByReal(jsCode);
          });
        }
      }
    })
  },
  //点击演示账户登录按钮
  tapBindUserDemo: function (e) {
    let that = this;
    wx.getUserProfile({
      desc: '用于演示登录', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        // console.log(res)
        if (res.errMsg == 'getUserProfile:fail auth deny') { //判断用户是否取消了授权
          wx.showToast({
            title: '已取消授权',
            icon: 'none',
            duration: 2000
          })
          return;
        }
        if (res.errMsg == 'getUserProfile:ok') { //判断用户是否授权
          wx.showToast({
            title: '已确定授权',
            icon: 'none',
            duration: 2000
          })
          that.setData({
            userInfo: res.userInfo,
          })
 
          that.getWxUserLoginCodeCb().then((loginParas) => {
            // console.log('jsCode', loginParas)
            var jsCode = loginParas.code;
            that.loginByDemo(jsCode);
          });
        }
      }
    })
 
  },
 
 
 
 
 
  // 加载
  onLoad: function () {
    var that = this;
    var screenSize = app.globalData.screenSize;
 
    var screenWidth = screenSize.width;
    var screenHight = screenSize.height;
    var screenWidthScale = screenSize.width / 750;
    var screenHightScale = screenSize.height / 1334;
    if (wx.getStorageSync('AccountInfo') && wx.getStorageSync('AccountInfo').checked) {
      let getPhone = wx.getStorageSync('AccountInfo').phone
      let getPassword = wx.getStorageSync('AccountInfo').password
      that.setData({
        phone: getPhone,
        password: getPassword,
        checked: wx.getStorageSync('AccountInfo').checked
      })
    }
    that.setData({
      imageWidth: screenWidth,
      imageHeight: screenHightScale * 520 + 10,
      // imageHeight: screenHightScale * 520,
      inputViewWidth: screenWidth,
      inputViewHeight: screenHightScale * 88,
      inputWidth: screenWidth,
      inputHeight: screenHightScale * 177,
    });
    console.log(111)
    // app.onReset()
  },
 
  onShareAppMessage: function () {
    return Constant.Share;
  },
})