JMApp/pages/register/register.js
XiaoMo 1af84dc1ee refactor: 统一API请求路径并优化请求逻辑
将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
2025-04-10 19:01:02 +08:00

111 lines
3.5 KiB
JavaScript

var t = getApp(), o = require("../../utils/login.js");
Page({
data: {
type: "login",
issubmit: !1,
info: {
mobile: "",
smscode: ""
},
token: "",
provision: {},
tips: [],
showTips: !1,
approve: !0
},
onLoad: function (a) {
var e = this;
this.setData({
type: a.type || "login"
}), o.pageStart(t).then(function (o) {
console.log(t.globalData), e.setData({
protocol: t.globalData.protocol
});
});
},
input: function (t) {
this.data.info[t.currentTarget.dataset.name] = t.detail.value, this.setData({
info: this.data.info
});
},
bindsubmit: function (t) {
if (console.log(t.detail.formId), this.data.issubmit) return !1;
this.setData({
issubmit: !0
}), wx.showLoading({
title: ""
});
var o = this;
"reset" == this.data.type ? this.submitForm() : wx.login({
success: function (t) {
console.log(t.code), wx.getUserInfo({
success: function (a) {
o.submitForm(t.code, a);
},
fail: function () {
o.submitForm(t.code);
}
});
},
fail: function (t) { }
});
},
submitForm: function (a, e) {
var i = this, n = {};
Object.assign(n, e, {
token: this.data.token,
smscode: this.data.info.smscode,
code: a
}), console.log(n), o.request(t.globalData.config.verify[i.data.type], n, !0).then(function (o) {
return wx.hideLoading(), i.setData({
issubmit: !1
}), 200 == o.code && (i.setData({
countdowntime: 0
}), "login" == i.data.type && wx.setStorageSync("session", o.data.session), wx.showToast({
title: o.message,
icon: "none"
}), t.globalData.isneedUpload = !0, t.globalData.needJumpUrl ? (wx.redirectTo({
url: t.globalData.needJumpUrl
}), t.globalData.needJumpUrl = !1, !1) : void wx.navigateBack({
delta: 1
}));
}).catch(function (t) {
i.setData({
issubmit: !1
});
});
},
sendMsg: function () {
if ("" == this.data.info.mobile.trim()) return wx.showModal({
title: "提示",
content: "请输入手机号码~"
}), !1;
var a = this;
o.request('/miniprogram/verify/sms', {
mobile: a.data.info.mobile,
type: a.data.type
}, !0).then(function (t) {
console.log("daa", t), wx.showToast({
title: "验证码已发送~",
icon: "none"
}), a.setData({
token: t.data.token,
countdowntime: t.data.countdowntime
}, function () {
a.timer = setInterval(function () {
if (0 == a.data.countdowntime) return clearInterval(a.timer), !1;
a.data.countdowntime--, a.setData({
countdowntime: a.data.countdowntime
});
}, 1e3);
});
}).catch(function (t) { });
},
timer: null,
showprovision: function () {
this.setData({
showTips: !this.data.showTips
});
}
});