211 lines
7.7 KiB
JavaScript
211 lines
7.7 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_http = require("../../common/http.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
form: {
|
|
shopName: "",
|
|
name: "",
|
|
email: "",
|
|
code: "",
|
|
password: ""
|
|
},
|
|
shopNameFocused: false,
|
|
nameFocused: false,
|
|
emailFocused: false,
|
|
codeFocused: false,
|
|
pwdFocused: false,
|
|
countdown: 0,
|
|
timer: null,
|
|
sending: false
|
|
};
|
|
},
|
|
computed: {
|
|
btnText() {
|
|
if (this.countdown > 0)
|
|
return `${this.countdown}s`;
|
|
if (this.sending)
|
|
return "发送中...";
|
|
return "获取验证码";
|
|
}
|
|
},
|
|
methods: {
|
|
validate() {
|
|
const email = String(this.form.email || "").trim();
|
|
const ok = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(email);
|
|
if (!ok) {
|
|
common_vendor.index.showToast({ title: "请输入正确的邮箱地址", icon: "none" });
|
|
return false;
|
|
}
|
|
if (!/^\d{6}$/.test(String(this.form.code || "").trim())) {
|
|
common_vendor.index.showToast({ title: "验证码格式不正确", icon: "none" });
|
|
return false;
|
|
}
|
|
if (String(this.form.password || "").length < 6) {
|
|
common_vendor.index.showToast({ title: "密码至少6位", icon: "none" });
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
startCountdown(sec) {
|
|
this.countdown = sec;
|
|
if (this.timer)
|
|
clearInterval(this.timer);
|
|
this.timer = setInterval(() => {
|
|
if (this.countdown <= 1) {
|
|
clearInterval(this.timer);
|
|
this.timer = null;
|
|
this.countdown = 0;
|
|
return;
|
|
}
|
|
this.countdown--;
|
|
}, 1e3);
|
|
},
|
|
async sendCode() {
|
|
if (this.sending || this.countdown > 0)
|
|
return;
|
|
const e = String(this.form.email || "").trim();
|
|
const ok = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(e);
|
|
if (!ok)
|
|
return common_vendor.index.showToast({ title: "请输入正确的邮箱地址", icon: "none" });
|
|
this.sending = true;
|
|
try {
|
|
const res = await common_http.post("/api/auth/email/send", { email: e, scene: "login" });
|
|
const cd = Number(res && res.cooldownSec || 60);
|
|
this.startCountdown(cd);
|
|
common_vendor.index.showToast({ title: "验证码已发送", icon: "none" });
|
|
} catch (e2) {
|
|
const msg = e2 && e2.message || "发送失败";
|
|
common_vendor.index.showToast({ title: msg, icon: "none" });
|
|
} finally {
|
|
this.sending = false;
|
|
}
|
|
},
|
|
async onRegister() {
|
|
if (!this.validate())
|
|
return;
|
|
const email = String(this.form.email || "").trim();
|
|
const name = String(this.form.name || "").trim();
|
|
try {
|
|
const data = await common_http.post("/api/auth/email/register", { email, code: String(this.form.code || "").trim(), name, password: String(this.form.password || "") });
|
|
if (data && data.token) {
|
|
common_vendor.index.setStorageSync("TOKEN", data.token);
|
|
if (data.user && data.user.email)
|
|
common_vendor.index.setStorageSync("USER_EMAIL", data.user.email);
|
|
if (name)
|
|
try {
|
|
common_vendor.index.setStorageSync("USER_NAME", name);
|
|
} catch (_) {
|
|
}
|
|
common_vendor.index.showToast({ title: "注册成功", icon: "none" });
|
|
setTimeout(() => {
|
|
common_vendor.index.reLaunch({ url: "/pages/index/index" });
|
|
}, 300);
|
|
}
|
|
} catch (e) {
|
|
const msg = e && e.message || "注册失败";
|
|
common_vendor.index.showToast({ title: msg, icon: "none" });
|
|
}
|
|
},
|
|
onGoLogin() {
|
|
common_vendor.index.navigateTo({
|
|
url: "/pages/auth/login"
|
|
});
|
|
}
|
|
}
|
|
};
|
|
if (!Array) {
|
|
const _component_path = common_vendor.resolveComponent("path");
|
|
const _component_svg = common_vendor.resolveComponent("svg");
|
|
(_component_path + _component_svg)();
|
|
}
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return {
|
|
a: common_vendor.p({
|
|
d: "M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2ZM21 9V7L15 4V6C15 7.66 13.66 9 12 9S9 7.66 9 6V4L3 7V9C3 10.1 3.9 11 5 11V17C5 18.1 5.9 19 7 19H9C9 20.1 9.9 21 11 21H13C14.1 21 15 20.1 15 19H17C18.1 19 19 18.1 19 17V11C20.1 11 21 10.1 21 9Z"
|
|
}),
|
|
b: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
c: common_vendor.p({
|
|
d: "M12,3L2,12H5V20H19V12H22L12,3M12,8.75A2.25,2.25 0 0,1 14.25,11A2.25,2.25 0 0,1 12,13.25A2.25,2.25 0 0,1 9.75,11A2.25,2.25 0 0,1 12,8.75Z"
|
|
}),
|
|
d: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
e: common_vendor.o(($event) => $data.shopNameFocused = true),
|
|
f: common_vendor.o(($event) => $data.shopNameFocused = false),
|
|
g: $data.form.shopName,
|
|
h: common_vendor.o(common_vendor.m(($event) => $data.form.shopName = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
i: $data.shopNameFocused ? 1 : "",
|
|
j: $data.form.shopName ? 1 : "",
|
|
k: common_vendor.p({
|
|
d: "M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z"
|
|
}),
|
|
l: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
m: common_vendor.o(($event) => $data.nameFocused = true),
|
|
n: common_vendor.o(($event) => $data.nameFocused = false),
|
|
o: $data.form.name,
|
|
p: common_vendor.o(common_vendor.m(($event) => $data.form.name = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
q: $data.nameFocused ? 1 : "",
|
|
r: $data.form.name ? 1 : "",
|
|
s: common_vendor.p({
|
|
d: "M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-1 4l-7 4-7-4V6l7 4 7-4v2z"
|
|
}),
|
|
t: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
v: common_vendor.o(($event) => $data.emailFocused = true),
|
|
w: common_vendor.o(($event) => $data.emailFocused = false),
|
|
x: $data.form.email,
|
|
y: common_vendor.o(common_vendor.m(($event) => $data.form.email = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
z: $data.emailFocused ? 1 : "",
|
|
A: $data.form.email ? 1 : "",
|
|
B: common_vendor.p({
|
|
d: "M3 10h18v2H3v-2zm0 6h12v2H3v-2zM3 6h18v2H3V6z"
|
|
}),
|
|
C: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
D: common_vendor.o(($event) => $data.codeFocused = true),
|
|
E: common_vendor.o(($event) => $data.codeFocused = false),
|
|
F: $data.form.code,
|
|
G: common_vendor.o(common_vendor.m(($event) => $data.form.code = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
H: $data.codeFocused ? 1 : "",
|
|
I: $data.form.code ? 1 : "",
|
|
J: common_vendor.p({
|
|
d: "M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z"
|
|
}),
|
|
K: common_vendor.p({
|
|
viewBox: "0 0 24 24"
|
|
}),
|
|
L: common_vendor.o(($event) => $data.pwdFocused = true),
|
|
M: common_vendor.o(($event) => $data.pwdFocused = false),
|
|
N: $data.form.password,
|
|
O: common_vendor.o(common_vendor.m(($event) => $data.form.password = $event.detail.value, {
|
|
trim: true
|
|
})),
|
|
P: $data.pwdFocused ? 1 : "",
|
|
Q: $data.form.password ? 1 : "",
|
|
R: common_vendor.t($options.btnText),
|
|
S: $data.countdown > 0 || $data.sending,
|
|
T: common_vendor.o((...args) => $options.sendCode && $options.sendCode(...args)),
|
|
U: common_vendor.o((...args) => $options.onRegister && $options.onRegister(...args)),
|
|
V: common_vendor.o((...args) => $options.onGoLogin && $options.onGoLogin(...args))
|
|
};
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/auth/register.js.map
|