123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- App({
- data: {
- deviceInfo: {},
- },
- onLaunch: function () {
- var that = this;
- that.data.deviceInfo = wx.getSystemInfoSync();
-
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now());
- wx.setStorageSync('logs', logs);
- wx.clearStorage();
-
- wx.getSetting({
- success: function (res) {
- console.log(res);
- if (res.authSetting['scope.userInfo']) {
-
- that.getUserRole();
- }
- }
- })
- },
-
- getUserRole: function (id) {
- var that = this;
- var host = that.globalData.servsers;
- wx.login({
- success: function (res) {
- var code = res.code;
- wx.getUserInfo({
- withCredentials: true,
- success: function (res) {
- that.globalData.userInfo = res.userInfo;
- wx.request({
- url: host + "api/distributeSell/getUserRole",
- data: {
- code: code,
- iv: res.iv,
- encryptedData: res.encryptedData,
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
-
- if (res.data.code == '200') {
- that.globalData.un_id = res.data.data.user_id;
- that.globalData.openid = res.data.data.openid;
- that.globalData.isNewUser = false;
- that.globalData.userRole = res.data.data.userRole;
- that.globalData.userInfo.phone = res.data.data.user_phone
- that.globalData.userInfo.avatarUrl = res.data.data.icon;
- that.globalData.user_id = res.data.data.user_id;
- var name = res.data.data.name;
- name = name.replace(/\?/g, '');
- name = unescape(escape(name).replace(/\%uD.{3}/g, ''));
- that.globalData.userInfo.nickName = name;
- if (that.employIdCallback) {
- that.employIdCallback(res.data.data.user_id);
- }
- if (that.employIdCallback2) {
- that.employIdCallback2(res.data.data.openid);
- }
- if (that.employIdCallbackUser) {
- that.employIdCallbackUser(false);
- }
- if (that.employIdCallbackRole) {
- that.employIdCallbackRole(res.data.data.userRole);
- }
- }else{
- wx.navigateTo({
- url: '/pages/authorize/authorize?link=midAutumn',
- })
- }
-
- if (res.data.data == '') {
- that.globalData.isNewUser = true;
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- },
- fail: function (e) {
- console.log("需重新授权");
- }
- })
- }
- });
- },
-
- insertUser:function(e){
- var that = this;
- var host = that.globalData.servsers;
- wx.login({
- success: function (res) {
- var code = res.code;
- wx.getUserInfo({
- withCredentials: true,
- success: function (res) {
- that.globalData.userInfo = res.userInfo;
- }
- })
- }
- })
- },
-
- globalData: {
- userInfo: [],
- un_id:null,
- open_id: null,
- openid : null,
- user_id:null,
- userRole : '',
- isNewUser : '',
- fromUserId : '',
- fromUserRole : '',
-
- servsers: "https://www.daliangzao.net/",
-
-
- appid: 'wxf9a0ddcb8c70b939',
- secret: 'a009cb3e46c8ecef9c54a50522f11823',
- }
- })
|