fix: 参数配置值类型为字符串http判断

This commit is contained in:
TsMask
2023-12-25 20:55:59 +08:00
parent e79d054ceb
commit 864be2ba3b
2 changed files with 58 additions and 3 deletions

View File

@@ -28,7 +28,8 @@ export const regExpUserName = /^[a-zA-Z][a-z0-9A-Z]{4,}$/;
*
* 密码至少包含大小写字母、数字、特殊符号且不少于6位
*/
export const regExpPasswd = /^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{6,}$/;
export const regExpPasswd =
/^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{6,}$/;
/**
* 有效手机号格式
@@ -63,6 +64,44 @@ export function validHttp(link: string): boolean {
return regExpHttp.test(link);
}
/**
* 判断是否有效URL地址
* @param str 网络链接
* @returns true | false
*/
export function validURL(str: string) {
if (
str === '' ||
str.length >= 2083 ||
str.length <= 3 ||
str.startsWith('.')
) {
return false;
}
let strTemp = str;
if (str.includes(':') && !str.includes('://')) {
// support no indicated urlscheme but with colon for port number
// http:// is appended so url.Parse will succeed, strTemp used so it does not impact rxURL.MatchString
strTemp = 'http://' + str;
}
debugger;
try {
new URL(strTemp);
} catch (error) {
return false;
}
const u = new URL(strTemp);
if (u.host.startsWith('.')) {
return false;
}
if (u.host === '' && u.pathname !== '' && !u.pathname.includes('.')) {
return false;
}
// 正则表达式模式(rxURL)未提供,无法进行具体判断
return true;
}
/**
* 判断是否为有效手机号格式
* @param mobile 手机号字符串

View File

@@ -13,7 +13,7 @@ import {
addParamConfigInfo,
} from '@/api/configManage/configParam';
import useNeInfoStore from '@/store/modules/neinfo';
import { regExpIPv4, regExpIPv6 } from '@/utils/regular-utils';
import { regExpIPv4, regExpIPv6, validURL } from '@/utils/regular-utils';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { DataNode } from 'ant-design-vue/lib/tree';
const neInfoStore = useNeInfoStore();
@@ -933,7 +933,6 @@ function ruleVerification(row: Record<string, any>): (string | boolean)[] {
if (row.optional === 'true' && !value) {
return result;
}
switch (type) {
case 'int':
if (filter && filter.indexOf('~') !== -1) {
@@ -1003,6 +1002,7 @@ function ruleVerification(row: Record<string, any>): (string | boolean)[] {
}
break;
case 'string':
// 字符串长度判断
if (filter && filter.indexOf('~') !== -1) {
try {
const filterArr = filter.split('~');
@@ -1021,12 +1021,28 @@ function ruleVerification(row: Record<string, any>): (string | boolean)[] {
console.error(error);
}
}
// 字符串http判断
if (value.startsWith('http')) {
try {
if (!validURL(value)) {
return [
false,
t('views.configManage.configParamForm.requireString', {
display,
}),
];
}
} catch (error) {
console.error(error);
}
}
break;
case 'regex':
if (filter) {
try {
let regex = new RegExp(filter);
console.log(regex, regex.test(value));
if (!regex.test(value)) {
return [
false,