refactor(projects): 代码优化

ISSUES CLOSED: \
This commit is contained in:
Soybean
2022-05-28 13:31:33 +08:00
parent 8f6d6ce3cb
commit d28b9039bb
17 changed files with 45 additions and 38 deletions

View File

@ -52,6 +52,7 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
ctx.fillStyle = randomColor(180, 230);
ctx.fillRect(0, 0, width, height);
for (let i = 0; i < 4; i += 1) {
const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)];
imgCode += text;
@ -81,5 +82,6 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
ctx.fillStyle = randomColor(150, 200);
ctx.fill();
}
return imgCode;
}

View File

@ -7,6 +7,7 @@ import useCountDown from './useCountDown';
export default function useSmsCode() {
const { loading, startLoading, endLoading } = useLoading();
const { counts, start, isCounting } = useCountDown(60);
const initLabel = '获取验证码';
const countingLabel = (second: number) => `${second}秒后重新获取`;
const label = computed(() => {
@ -40,6 +41,7 @@ export default function useSmsCode() {
async function getSmsCode(phone: string) {
const valid = isPhoneValid(phone);
if (!valid || loading.value) return;
startLoading();
const { data } = await fetchSmsCode(phone);
if (data) {

View File

@ -13,9 +13,12 @@ export default function useReload() {
async function handleReload(duration = 0) {
setFalse();
await nextTick();
setTimeout(() => {
setTrue();
}, duration);
if (duration > 0) {
setTimeout(() => {
setTrue();
}, duration);
}
}
return {