81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../common/vendor.js");
|
||
|
const common_js_util = require("../../common/js/util.js");
|
||
|
const api_index = require("../../api/index.js");
|
||
|
const _sfc_main = {
|
||
|
__name: "getCode",
|
||
|
props: {
|
||
|
// 内容
|
||
|
event: {
|
||
|
type: String,
|
||
|
default: "register"
|
||
|
},
|
||
|
// 倒计时
|
||
|
count: {
|
||
|
type: Number,
|
||
|
default: 60
|
||
|
},
|
||
|
// 手机号
|
||
|
phone: {
|
||
|
type: String,
|
||
|
default: ""
|
||
|
}
|
||
|
},
|
||
|
setup(__props) {
|
||
|
const props = __props;
|
||
|
const time = common_vendor.ref(60);
|
||
|
const timer = common_vendor.ref(null);
|
||
|
const plan = common_vendor.ref(1);
|
||
|
common_vendor.onMounted(() => {
|
||
|
time.value = props.count;
|
||
|
});
|
||
|
common_vendor.onBeforeUnmount(() => {
|
||
|
plan.value = 1;
|
||
|
clearInterval(timer.value);
|
||
|
});
|
||
|
function getCode() {
|
||
|
if (!props.phone.match(common_js_util.util.reg.tel)) {
|
||
|
common_js_util.util.alert("手机号不正确");
|
||
|
return false;
|
||
|
}
|
||
|
if (plan.value == 2) {
|
||
|
common_js_util.util.alert("请稍后获取验证码");
|
||
|
return false;
|
||
|
}
|
||
|
plan.value = 2;
|
||
|
timer.value = setInterval(() => {
|
||
|
if (time.value > 0) {
|
||
|
time.value--;
|
||
|
} else {
|
||
|
plan.value = 3;
|
||
|
time.value = props.count;
|
||
|
clearInterval(timer.value);
|
||
|
}
|
||
|
}, 1e3);
|
||
|
api_index.api.login.getCaptcha({
|
||
|
query: [props.phone, props.event],
|
||
|
path: [props.phone, props.event]
|
||
|
}).then((rs) => {
|
||
|
console.log(rs);
|
||
|
if (rs.code == 200) {
|
||
|
common_js_util.util.alert("验证码已发送");
|
||
|
} else {
|
||
|
common_js_util.util.alert(rs.msg);
|
||
|
plan.value = 3;
|
||
|
clearInterval(timer.value);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
return (_ctx, _cache) => {
|
||
|
return {
|
||
|
a: plan.value == 1,
|
||
|
b: common_vendor.t(time.value),
|
||
|
c: plan.value == 2,
|
||
|
d: plan.value == 3,
|
||
|
e: common_vendor.o$1(getCode)
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
wx.createComponent(_sfc_main);
|