Explorar o código

修改登录密码校验

yuanmingze hai 4 semanas
pai
achega
6f6398db59

+ 2 - 1
.env.pre

@@ -1,5 +1,6 @@
 VITE_MODE=production_pre
 VITE_APP_TYPE=prod
 VITE_PROJECT_TITLE=要易小助手
-VITE_BASE_API=https://preapi.yaoyi.net
+# VITE_BASE_API=https://preapi.yaoyi.net
+VITE_BASE_API=https://pre1.yaoyi.net
 VITE_WX_APPID=wxd03398e1bff2b241

+ 1 - 1
scripts/build-mp-weixin.ts

@@ -34,7 +34,7 @@ const ENVIRONMENTS: Record<TargetEnvironment, EnvironmentConfig> = {
   },
   pre: {
     appid: ORIGINAL_APPID,
-    baseApi: 'https://preapi.yaoyi.net',
+    baseApi: 'https://pre1.yaoyi.net',
     envFile: '.env.pre',
     label: '预发布',
     viteMode: 'pre',

+ 2 - 2
src/pages/login/index.vue

@@ -114,7 +114,7 @@ import { useCodeCountdown } from '@/composables/useCodeCountdown'
 import { useFormValidator } from '@/composables/useFormValidator'
 import { useUserStore } from '@/stores/modules/user'
 
-import { resetPasswordRules } from '@/validators/authFormRules'
+import { loginRules } from '@/validators/authFormRules'
 
 import AuthInputItem from '@/components/auth/AuthInputItem.vue'
 
@@ -138,7 +138,7 @@ const form = reactive({
 })
 
 const { errors, validate, validateField, clearFieldError } = useFormValidator(
-  resetPasswordRules,
+  loginRules,
   form
 )
 

+ 8 - 5
src/pages/reset-password/index.vue

@@ -43,8 +43,8 @@
         <AuthInputItem
           label="密码"
           v-model="form.password"
-          type="number"
-          :maxlength="11"
+          type="password"
+          :maxlength="16"
           placeholder="请输入密码"
           passwordToggle
           :error="errors.password"
@@ -52,7 +52,7 @@
           @clear="clearFieldError('password')"
         />
         <view class="tips">
-          密码为8~16位包含大小写字母、数字、!#$%^&*@特殊符号,且不能三位连续数字!
+          密码为6~16位包含大小写字母、数字、!#$%^&*@特殊符号,且不能三位连续数字!
         </view>
         <view class="submit">
           <button class="submit-btn" @click.prevent="submit">确定</button>
@@ -75,7 +75,7 @@ import { useCodeCountdown } from '@/composables/useCodeCountdown'
 import { useFormValidator } from '@/composables/useFormValidator'
 import { useUserStore } from '@/stores/modules/user'
 
-import { logingRules } from '@/validators/authFormRules'
+import { resetPasswordRules } from '@/validators/authFormRules'
 
 import AuthInputItem from '@/components/auth/AuthInputItem.vue'
 
@@ -87,7 +87,10 @@ const form = reactive({
   password: '',
 })
 
-const { errors, validate, validateField, clearFieldError } = useFormValidator(logingRules, form)
+const { errors, validate, validateField, clearFieldError } = useFormValidator(
+  resetPasswordRules,
+  form
+)
 
 const handleClickLeft = () => {
   uni.navigateBack()

+ 9 - 8
src/validators/authFormRules.ts

@@ -1,5 +1,5 @@
-// validators/resetPassword.ts
-import type { RuleItem,Rules } from 'async-validator'
+// validators/authFormRules.ts
+import type { RuleItem, Rules } from 'async-validator'
 
 /** 是否开发环境 */
 const isDev = import.meta.env.VITE_MODE === 'development'
@@ -21,8 +21,8 @@ function hasThreeConsecutiveDigits(value: string) {
 const strictPasswordValidator: RuleItem['validator'] = (_rule, value, callback) => {
   const v = String(value ?? '')
 
-  if (v.length < 8 || v.length > 16) {
-    return callback(new Error('密码长度需为 8~16 位'))
+  if (v.length < 6 || v.length > 16) {
+    return callback(new Error('密码长度需为 6~16 位'))
   }
   if (!/[A-Z]/.test(v)) {
     return callback(new Error('必须包含大写字母'))
@@ -43,8 +43,8 @@ const strictPasswordValidator: RuleItem['validator'] = (_rule, value, callback)
   callback()
 }
 
-/** 根据环境生成 password 规则 */
-function createPasswordRules(): RuleItem[] {
+/** 根据环境生成修改密码规则 */
+function createResetPasswordRules(): RuleItem[] {
   // 开发环境:只校验是否存在
   if (isDev) {
     return [{ required: true, message: '密码必填' }]
@@ -61,10 +61,11 @@ export const resetPasswordRules: Rules = {
     { pattern: /^\d{11}$/, message: '账号必须为 11 位纯数字' },
   ],
   code: [{ required: true, message: '验证码必填' }],
-  password: createPasswordRules(),
+  password: createResetPasswordRules(),
 }
 
-export const logingRules: Rules = {
+/** 登录表单校验规则:仅校验密码必填,兼容历史密码 */
+export const loginRules: Rules = {
   username: [
     { required: true, message: '账号必填' },
     { pattern: /^\d{11}$/, message: '账号必须为 11 位纯数字' },