代码如下图,看起来又像是原生的,但是可读性又很性,给模版的变量都是在["render", function(a, o, t, n, i, r) { return e.e({后定义的,老板拿来的代码,要在这上面二开的,看的头大。。
"use strict";
const e = require("../../common/vendor.js");
var a, o;
const t = getApp(),
n = {
components: {
popWarn: () => "../../components/popWarn/popWarn.js"
},
data: () => ({
imgsrc: `${t.globalData.masterDomain}/static/images/miniprograme/task/`,
imgVersion: t.globalData.imgVersion,
canIUse: !0,
canIUseGetUserProfile: !1,
masterDomain: t.globalData.masterDomain,
fromShare: 0,
userData: {},
warningb: !1,
info: "",
miniProgramBindPhone: "",
agreeb: !1,
privateb: !1,
reqUrl: "",
platText: "",
platcanIUse: !0
}),
beforeCreate() {},
onLoad(e) {
console.log("原生登录"), a = this, -1 == t.globalData.wxprivate ? t.watchG("wxprivate", (function(o) {
a.wxprivate = o, o ? a.privateb = !0 : a.onload(e)
})) : t.globalData.wxprivate ? a.privateb = !0 : a.onload(e)
},
methods: {
onload(o) {
o.wxMiniProgramLogin && 1 == o.wxMiniProgramLogin && (a.wxMiniProgramLogin = 1), (o.path && "" != o
.path || o.url && "" != o.url) && (a.path = o.path || o.url);
let n = t.globalData.platForm;
if ("mp-weixin" == n) {
let e = a.path && "" != a.path ? "&path=" + a.path : "";
this.reqUrl = "include/ajax.php?service=member&action=wxMiniProgramConnect&fromShare=" + a
.fromShare + e, this.platcanIUse = !1
} else if ("mp-toutiao" == n) {
let e = a.path && "" != a.path ? "&path=" + a.path : "",
o = a.wxMiniProgramLogin && "" != a.wxMiniProgramLogin ? "&wxMiniProgramLogin=" + a
.wxMiniProgramLogin : "";
this.reqUrl = "include/ajax.php?service=member&action=byteMiniProgramConnect&fromShare=" + a
.fromShare + e + o, this.platText = "抖音"
}(o.back && 1 == o.back || o.path && "" != o.path) && (a.back = 1), o.authorize && (a.authorize = 1), o
.fromShare && (a.fromShare = o.fromShare);
let i = parseInt(t.globalData.dyConfig.bindphone);
a.miniProgramBindPhone = i, o.authorize || 0 == i && e.index.getStorage({
key: "applyUserInfo"
}), e.index.getUserProfile && (a.canIUseGetUserProfile = !0), e.index.login({
success: e => {
a.code = e.code
}
}), a.redirect = o.url, a.agreeData()
},
warnFn(e = 2e3) {
this.warningb = !0, clearTimeout(o), o = setTimeout((e => {
this.warningb = !1
}), e)
},
backFn() {
e.index.navigateBack({
delta: 1,
fail: a => {
e.index.redirectTo({
url: "/pages/index/index"
})
}
})
},
getUserProfile(o) {
let t = parseInt(a.miniProgramBindPhone);
e.index.login({
success: e => {
e.code, a.code = e.code
}
}), e.index.getUserProfile({
desc: "用于完善会员资料",
success: o => {
let n = {
code: a.code,
iv: o.iv,
encryptedData: o.encryptedData,
redirect: a.redirect,
nickname: o.userInfo.nickName,
photo: o.userInfo.avatarUrl,
city: o.userInfo.city,
province: o.userInfo.province,
gender: o.userInfo.gender
};
a.userData = n, t ? a.request(1) : (a.canIUse = !1, e.index.setStorage({
key: "applyUserInfo",
data: 1
}))
},
fail: a => {
console.log(a), e.index.showToast({
title: "已拒绝小程序获取信息",
icon: "none",
duration: 2e3
})
}
})
},
getPhoneNumber(o) {
let t;
if (!o.detail.encryptedData && !o.detail.iv) return e.index.showToast({
title: "已拒绝小程序授权登录",
icon: "none",
duration: 2e3
}), !1;
a.userData, e.index.login({
success: e => {
t = {
code: e.code,
encryptedData: o.detail.encryptedData,
iv: o.detail.iv
}, a.phoneData = t, a.request()
}
})
},
wxLogin(o) {
let t;
if (!o.detail.encryptedData && !o.detail.iv) return e.index.showToast({
title: "已拒绝小程序授权登录",
icon: "none",
duration: 2e3
}), !1;
e.index.login({
success: e => {
console.log(e,12121)
t = {
code: o.detail.code,
encryptedData: o.detail.encryptedData,
iv: o.detail.iv
}, a.phoneData = t, a.$set(a.userData, "code", e.code), a.request()
}
})
},
checkAgree() {
e.index.showToast({
title: "请先同意并勾选《用户注册协议》和《隐私协议》",
icon: "none",
success: a => {
setTimeout((a => {
e.index.hideToast()
}), 2e3)
}
})
},
agreeData() {
let e = (new Date).valueOf();
a.$ajax.get({
url: "api/appConfig.json?v=" + e
}).then((e => {
a.protocol = e.data.protocol
}))
},
linkTo(o) {
let t = o,
n = "";
"1" == t ? n = a.protocol["用户注册协议"] : "2" == t && (n = a.protocol["隐私政策"]), e.index.navigateTo({
url: "/pages/redirect/index?url=" + encodeURIComponent(n)
})
},
request(o) {
e.index.showLoading({
title: "登录中..."
}), a.$ajax.post({
url: `${a.reqUrl}&base64=1`,
data: `phoneData=${t.base64("encode",unescape(encodeURIComponent(JSON.stringify(a.phoneData))))}&userData=${t.base64("encode",unescape(encodeURIComponent(a.userData?JSON.stringify(a.userData):"")))}`
}).then((o => {
if (o.data) {
let n = o.data;
if (100 == n.state) {
e.index.removeStorageSync("logoutSelf");
let o = "",
i = "",
r = "",
s = n.info.split("?")[1];
o = t.getUrlPara(s, "uid"), i = t.getUrlPara(s, "access_token"), r = t
.getUrlPara(s, "refresh_token"), e.index.setStorageSync("userid", o), e
.index.setStorageSync("access_token", i), e.index.setStorageSync(
"refresh_token", r);
let l = Date.parse(new Date) / 1e3 + 7200 - 20;
if (e.index.setStorageSync("token_expired", l), t.globalData.userid = o, t
.memberInfo(o), t.globalData.access_token = i, t.globalData.refresh_token =
r, t.globalData.token_expired = l, decodeURIComponent(a.path).indexOf(
"/pages/") > -1) e.index.navigateBack({
delta: 1,
fail: function() {
e.index.redirectTo({
url: "/pages/redirect/index?url=" +
encodeURIComponent(n.info)
})
}
});
else {
let o = a.path;
o = o.indexOf("forcelogout&") > -1 ? o.replace("forcelogout&", "") : o
.replace("&forcelogout", "");
let n = t.addUrlParam(o);
e.index.redirectTo({
url: "/pages/redirect/index?url=" + encodeURIComponent(n)
})
}
} else e.index.hideLoading(), e.index.showToast({
title: n.info,
icon: "none",
duration: 2e3
}), a.userData = {}, a.canIUse = !0
} else e.index.hideLoading(), e.index.showToast({
title: "授权失败!",
icon: "none",
duration: 2e3
}), a.userData = {}, a.canIUse = !0
})).catch((o => {
console.log(o), e.index.showToast({
title: "登录失败!",
icon: "none",
duration: 2e3
}), a.userData = {}, a.canIUse = !0
}))
},
loginTo() {
let o = a.path && "" != a.path ? "path=" + a.path : "",
n = a.wxMiniProgramLogin && "" != a.wxMiniProgramLogin ? "&wxMiniProgramLogin=" + a
.wxMiniProgramLogin : "",
i = "/pages/redirect/index?url=" + encodeURIComponent(t.addUrlParam(t.globalData.masterDomain +
"/login.html?from=wxmini&" + o + n, "forcelogout"));
a.back && 1 == a.back ? e.index.navigateTo({
url: i
}) : e.index.navigateBack()
},
agree() {
this.agreeb = !this.agreeb
}
},
watch: {
info(e, a) {
"" != e && (this.warnFn(), setTimeout((e => {
this.info = ""
}), 2200))
}
},
onShareAppMessage(e) {
let a = t.globalData.appConfig;
return {
title: a.share.title,
desc: a.share.description,
path: "/pages/index/index",
imageUrl: t.globalData.masterDomain + "/include/json.php?action=getSystemLogo"
}
},
onShareTimeline: () => ({
title: config.share.title,
imageUrl: t.globalData.masterDomain + "/include/json.php?action=getSystemLogo"
})
};
if (!Array) {
(e.resolveComponent("popWarn") + e.resolveComponent("private_tip"))()
}
Math || ((() => "../../components/popWarn/popWarn.js") + (() => "../../components/private_tip/private_tip.js"))();
const i = e._export_sfc(n, [
["render", function(a, o, t, n, i, r) {
return e.e({
a: i.canIUse && i.platcanIUse
}, i.canIUse && i.platcanIUse ? e.e({
b: i.masterDomain + "/include/json.php?action=getSystemLogo",
c: i.canIUseGetUserProfile
}, i.canIUseGetUserProfile ? {
d: e.t(i.platText),
e: e.o((e => i.agreeb ? r.getUserProfile() : r.checkAgree()))
} : {}, {
f: i.canIUseGetUserProfile && !i.miniProgramBindPhone
}, i.canIUseGetUserProfile && !i.miniProgramBindPhone ? {
g: e.o(((...e) => r.backFn && r.backFn(...e)))
} : {}, {
h: i.miniProgramBindPhone
}, i.miniProgramBindPhone ? {
i: e.o(((...e) => r.loginTo && r.loginTo(...e)))
} : {}) : e.e({
j: i.masterDomain + "/include/json.php?action=getSystemLogo",
k: !i.agreeb
}, i.agreeb ? {
n: e.t(i.platText),
o: e.o((e => i.platcanIUse ? r.getPhoneNumber(e) : r.wxLogin(e)))
} : {
l: e.t(i.platText),
m: e.o(((...e) => r.checkAgree && r.checkAgree(...e)))
}, {
p: i.canIUseGetUserProfile
}, i.canIUseGetUserProfile ? {
q: e.o(((...e) => r.loginTo && r.loginTo(...e)))
} : {}), {
r: e.n("agreebtn " + (i.agreeb ? "checked" : "")),
s: e.o(((...e) => r.agree && r.agree(...e))),
t: e.o((e => r.linkTo(1))),
v: e.o((e => r.linkTo(2))),
w: e.p({
info: i.info,
warningb: i.warningb
}),
x: e.p({
privateShow: i.privateb
})
})
}]
]);
n.__runtimeHooks = 6, wx.createPage(i);
单字母定义变量一般都是编译过的,正常没人这么定义
编译过的