78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
form: { phone: "", password: "" },
|
|
showPwd: false,
|
|
submitting: false
|
|
};
|
|
},
|
|
methods: {
|
|
validatePhone(p) {
|
|
return /^1\d{10}$/.test(String(p || ""));
|
|
},
|
|
validate() {
|
|
if (!this.validatePhone(this.form.phone)) {
|
|
common_vendor.index.showToast({ title: "请输入有效手机号", icon: "none" });
|
|
return false;
|
|
}
|
|
if (!this.form.password) {
|
|
common_vendor.index.showToast({ title: "请输入密码", icon: "none" });
|
|
return false;
|
|
}
|
|
if (this.form.password.length < 6) {
|
|
common_vendor.index.showToast({ title: "密码至少6位", icon: "none" });
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
submit() {
|
|
if (this.submitting)
|
|
return;
|
|
if (!this.validate())
|
|
return;
|
|
this.submitting = true;
|
|
try {
|
|
common_vendor.index.setStorageSync("LOGIN_STATUS", "logged_in");
|
|
common_vendor.index.setStorageSync("LOGIN_PHONE", this.form.phone);
|
|
try {
|
|
const uid = common_vendor.index.getStorageSync("DEFAULT_USER_ID") || "";
|
|
const enable = common_vendor.index.getStorageSync("ENABLE_DEFAULT_USER") || "";
|
|
if (!enable)
|
|
common_vendor.index.setStorageSync("ENABLE_DEFAULT_USER", "true");
|
|
if (!uid)
|
|
common_vendor.index.setStorageSync("DEFAULT_USER_ID", "2");
|
|
} catch (e) {
|
|
}
|
|
common_vendor.index.showToast({ title: "登录成功(本地)", icon: "none" });
|
|
setTimeout(() => {
|
|
common_vendor.index.reLaunch({ url: "/pages/index/index" });
|
|
}, 500);
|
|
} finally {
|
|
this.submitting = false;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return {
|
|
a: $data.form.phone,
|
|
b: common_vendor.o(common_vendor.m(($event) => $data.form.phone = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
c: !$data.showPwd,
|
|
d: $data.form.password,
|
|
e: common_vendor.o(common_vendor.m(($event) => $data.form.password = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
f: common_vendor.t($data.showPwd ? "隐藏" : "显示"),
|
|
g: common_vendor.o(($event) => $data.showPwd = !$data.showPwd),
|
|
h: $data.submitting,
|
|
i: common_vendor.o((...args) => $options.submit && $options.submit(...args))
|
|
};
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/password-login.js.map
|