Просмотр исходного кода

```
feat(utils): 添加输入框格式校验工具类

- 新增 InputFormatUtil 工具类,包含手机号和QQ号格式校验方法
- 在 auto-imports.d.ts 中注册 InputFormatUtil 全局导入
- 在视频权益提交订单页面引入并使用格式校验功能
- 优化表单验证逻辑,提供更准确的错误提示信息
```

zouzexu 16 часов назад
Родитель
Сommit
777aa96414

+ 2 - 0
src/auto-imports.d.ts

@@ -9,6 +9,7 @@ declare global {
   const Apis: typeof import('./api/index')['Apis']
   const CommonUtil: typeof import('wot-design-uni')['CommonUtil']
   const EffectScope: typeof import('vue')['EffectScope']
+  const InputFormatUtil: typeof import('./utils/index')['InputFormatUtil']
   const OrderStatus: typeof import('./subPack-xsb/utils/order-data')['OrderStatus']
   const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
   const alovaInstance: typeof import('./api/index')['alovaInstance']
@@ -387,6 +388,7 @@ declare module 'vue' {
     readonly Apis: UnwrapRef<typeof import('./api/index')['Apis']>
     readonly CommonUtil: UnwrapRef<typeof import('wot-design-uni')['CommonUtil']>
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
+    readonly InputFormatUtil: UnwrapRef<typeof import('./utils/index')['InputFormatUtil']>
     readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
     readonly alovaInstance: UnwrapRef<typeof import('./api/index')['alovaInstance']>
     readonly api: UnwrapRef<typeof import('./api/index')['default']>

+ 1 - 0
src/config/index.ts

@@ -8,6 +8,7 @@ const mapEnvVersion = {
   // develop: 'http://192.168.1.253:8080',
   // develop: 'http://192.168.0.19:8080',
   // develop: 'http://192.168.0.217:8080', // 黄
+  // develop: 'http://192.168.0.11:8080', // 王
   // develop: 'http://192.168.1.89:8080', // 田
   // develop: 'http://74949mkfh190.vicp.fun', // 付
   // develop: 'http://47.109.84.152:8081',

+ 1 - 1
src/pages/index/index.vue

@@ -89,7 +89,7 @@ onShareAppMessage(() => {
 const showoverlay = ref(false)
 async function getSelectZhUser() {
   const res = await Apis.sys.selectZhUser({})
-  if (res.data.channelId === 54 && !res.data.isClaimed) { // 51测试id,上线需修改
+  if (res.data.channelId === 54 && !res.data.isClaimed) {
     showoverlay.value = true
   }
 }

+ 32 - 2
src/subPack-videoRights/videoRightsSubmitOrder/videoRightsSubmitOrder.vue

@@ -1,4 +1,5 @@
 <script setup lang="ts">
+import { InputFormatUtil } from '../../utils/index'
 import { StaticUrl } from '@/config'
 import router from '@/router'
 
@@ -36,9 +37,38 @@ function selectAccountType(type: number) {
   submitFrom.value.accountType = type
 }
 
+function validateRechargeAccount(formData: Api.videoRightsubmitOrder): {
+  isValid: boolean
+  errorMessage: string | null
+} {
+  if (formData.rechargeAccount === '') {
+    return {
+      isValid: false,
+      errorMessage: '请输入充值账号',
+    }
+  }
+  if (formData.accountType === 1 && !InputFormatUtil.isPhone(formData.rechargeAccount || '')) {
+    return {
+      isValid: false,
+      errorMessage: '请输入正确的手机号',
+    }
+  }
+  if (formData.accountType === 2 && !InputFormatUtil.isQQ(formData.rechargeAccount || '')) {
+    return {
+      isValid: false,
+      errorMessage: '请输入正确的QQ号',
+    }
+  }
+  return {
+    isValid: true,
+    errorMessage: null,
+  }
+}
+
 function submitPay() {
-  if (submitFrom.value.rechargeAccount === '') {
-    useGlobalToast().show({ msg: '请输入充值账号' })
+  const validation = validateRechargeAccount(submitFrom.value)
+  if (!validation.isValid) {
+    useGlobalToast().show({ msg: validation.errorMessage! })
     return
   }
   submitFrom.value.productId = previewGoods.value.id

+ 21 - 0
src/utils/index.ts

@@ -75,3 +75,24 @@ export function calculateCenterPointSpherical(
     lng: toDegrees(centerLng),
   }
 }
+
+/**
+ * 输入框格式校验工具类
+ */
+export class InputFormatUtil {
+  /**
+   * 手机号校验
+   * @param phone
+   */
+  static isPhone(phone: string) {
+    return /^1[3-9]\d{9}$/.test(phone)
+  }
+
+  /**
+   * QQ号校验
+   * @param qq
+   */
+  static isQQ(qq: string) {
+    return /^[1-9]\d{4,10}$/.test(qq)
+  }
+}