var e = getApp(), n = require("../../utils/core.js"); var f = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/typeof")); const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'; Page({ data: { avatarUrl: defaultAvatarUrl, nickname:'', active:0, shop_logo: "", shop_name: "", canIUseGetUserProfile: !1, sessionInfo: !1, userInfo:"" }, onLoad: function(e) { var o = this, s = !1, t = wx.getSystemInfoSync().SDKVersion; wx.getUserProfile && this.compareVersion(t, "2.16.0") >= 0 ? (s = !0, this.getSession()) : s = !1, n.get("wxAppSetting", {}, function(e) { var n = e.sysset; o.setData({ shop_logo: n.shoplogo, shop_name: n.shopname, canIUseGetUserProfile: s }); }); }, onChooseAvatar(e) { const { avatarUrl } = e.detail this.setData({ avatarUrl, active:1, }) }, getSession: function() { wx.showLoading({ title: "加载中" }), this.wxLogin(); }, wxLogin: function(e) { var o = this; wx.showLoading({ title: "加载中" }), wx.login({ success: function(s) { console.warn("wx.login", s), n.post("wxapp/login", { code: s.code }, function(s) { if (console.warn("post wxapp/login", s), s.error) return n.alert("获取用户登录态失败:" + s.message), !1; "function" == typeof e && e(s.session_key), o.setData({ sessionInfo: s }); }); }, fail: function() { n.alert("获取用户信息失败(wx.login)"); }, complete: function() { wx.hideLoading(); } }); }, getAuth: function(o, s, t, i,b) { var a = this; n.get("wxapp/auth", { data: o, iv: s, sessionKey: t, authOpenid: i ? i.openId : this.data.sessionInfo.openid, userinfo:a.data.userInfo }, function(o) { if (console.log([ 3, o ]), 1 === o.isblack && wx.showModal({ title: "无法访问", content: "您在商城的黑名单中,无权访问!", success: function(n) { n.confirm && e.close(), n.cancel && e.close(); } }), i || (i = o), a.data.sessionInfo && a.data.sessionInfo.openid && a.data.sessionInfo.openid !== o.openId) n.alert("数据错误,可能传输中丢失"); else { i.openid = o.openId, i.id = o.id, i.uniacid = o.uniacid; var s = e.setCache("userinfo", i), r = e.setCache("userinfo_openid", i.openid), c = e.setCache("userinfo_id", o.id); console.log(e.getCache("userinfo")), console.log(e.getCache("userinfo_openid")), console.log(e.getCache("userinfo_id")); var l = e.setCache("login_session_key", t); !1 !== s && !1 !== r && !1 !== c && !1 !== l || n.alert("获取用户信息失败!"), console.log(e.getCache("login_session_key")), e.getSet(), e.scanCarts(), wx.navigateBack({ changed: !0 }); } }); }, compareVersion: function(e, n) { e = e.split("."), n = n.split("."); for (var o = Math.max(e.length, n.length); e.length < o; ) e.push("0"); for (;n.length < o; ) n.push("0"); for (var s = 0; s < o; s++) { var t = parseInt(e[s]), i = parseInt(n[s]); if (t > i) return 1; if (t < i) return -1; } return 0; }, getUserProfile: function(e) { var o = this; console.log(o.data.avatarUrl,'000') if (this.data.sessionInfo && this.data.sessionInfo.session_key) return wx.getUserProfile({ desc: "用于完善会员资料", lang: "zh_CN", success: function(e) { console.log(e,'909090'); e.userInfo['nickName']=o.data.nickname e.userInfo['avatarUrl']=o.data.avatarUrl console.warn("wx.getUserProfile", e), e.encryptedData && e.iv ? o.getAuth(e.encryptedData, e.iv, o.data.sessionInfo.session_key) : n.alert("获取用户信息失败(当前微信版本不支持)!"); }, fail: function(e) { console.error("wx.getUserProfile:fail", e), n.alert("获取用户信息失败(getProfile)!"); } }), !1; n.alert("获取用户信息失败,请重新进入"); }, bindGetUserInfo: function(e) { var t = this; if(t.data.active==0){ wx.showToast({ title: '请点击灰色头像并上传头像', icon: 'none', duration: 2000 }) return false; } if(t.data.nickname==''){ wx.showToast({ title: '请属于您的昵称', icon: 'none', duration: 2000 }) return false; } var url = n.getUrl("util/uploader/upload", { file: "file" }) wx.uploadFile({ url:url, filePath:t.data.avatarUrl, name: "file", success (res){ var data = JSON.parse(res.data); var avatarUrl=data.files[0].url e.detail.userInfo['nickName']=t.data.nickname e.detail.userInfo['avatarUrl']=avatarUrl t.setData({ avatarUrl: avatarUrl, userInfo: e.detail }) t.wxLogin(function(o) { t.getAuth(e.detail.encryptedData, e.detail.iv, o, e.detail|| !1); }); } }) }, navigateBack: function() { wx.navigateBack({ changed: !0 }); }, close: function() { wx.navigateBack({ delta: 0 }); } });