From 85d4d412bac4d5cf9d797b54ec6ab674e07ee2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=95=A6C=E6=A2=A6?= <15709267061@163.com> Date: Fri, 13 Jun 2025 10:35:17 +0800 Subject: [PATCH] update --- src/pages/register/index.vue | 11 ++++++++++- src/utils/uils.js | 14 ++++++++++++++ vite.config.js | 6 +++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/pages/register/index.vue b/src/pages/register/index.vue index 275e0db..1104aa9 100644 --- a/src/pages/register/index.vue +++ b/src/pages/register/index.vue @@ -5,7 +5,7 @@ import BulletChat from "../login/BulletChat.vue"; import XInput from "../../components/XInput.vue"; import SendMsg from "../../components/SendMsg.vue"; import Api from "../../api/index.js"; -import {showToast} from "../../utils/uils.js"; +import {showToast, verifyForm} from "../../utils/uils.js"; const form = reactive({ mobile: null, @@ -15,7 +15,16 @@ const form = reactive({ invite: null, }); +const rules = { + mobile: { + reg: /^1[3-9]\d{9}$/, + msg: '手机号错误' + }, + wechat: {} +}; + const success = async () => { + verifyForm(form, rules); const {msg} = await Api.system.register(form); showToast(msg); } diff --git a/src/utils/uils.js b/src/utils/uils.js index b033a79..7f8b192 100644 --- a/src/utils/uils.js +++ b/src/utils/uils.js @@ -173,3 +173,17 @@ export const uploadFile = ({count}) => { }); }); } + +export const verifyForm = (model, rules) => { + Object.entries(model).forEach(([key, value]) => { + console.log(rules[key], key) + if (rules[key] && !rules[key].reg.test(value)) { + showToast({ + icon: 'error', + mask: true, + title: rules[key].msg, + }); + throw new Error(rules[key].msg); + } + }); +} diff --git a/vite.config.js b/vite.config.js index cc22007..8982362 100644 --- a/vite.config.js +++ b/vite.config.js @@ -10,9 +10,9 @@ export default defineConfig({ defineModel: true, } }), - UnifiedViteWeappTailwindcssPlugin({ - rem2rpx: true, - }) + // UnifiedViteWeappTailwindcssPlugin({ + // rem2rpx: true, + // }) ], css: { postcss: {