feat: 添加 URL 验证工具函数并优化 area-select 组件的类型定义

pull/338/head
YunaiV 2026-03-07 17:33:02 +08:00
parent f91a2702c9
commit 1cbdf442ee
10 changed files with 33 additions and 36 deletions

View File

@ -2,10 +2,11 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue';
import { AreaLevelEnum } from '@vben/constants';
import { Cascader } from 'ant-design-vue';
import { getAreaTree } from '#/api/system/area';
import { AreaLevelEnum } from '@vben/constants';
defineOptions({ name: 'AreaSelect' });
@ -40,7 +41,7 @@ interface AreaVO {
interface Props {
modelValue?: number[] | string[];
value?: number[] | string[];
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
level?: (typeof AreaLevelEnum)[keyof typeof AreaLevelEnum];
disabled?: boolean;
placeholder?: string;
clearable?: boolean;

View File

@ -72,9 +72,9 @@ const showPreview = computed(() => {
}
.iframe-preview {
overflow: hidden;
border: 1px solid #d9d9d9;
border-radius: 4px;
overflow: hidden;
}
.iframe-content {
@ -87,8 +87,8 @@ const showPreview = computed(() => {
align-items: center;
justify-content: center;
min-height: 200px;
background-color: #fafafa;
border: 1px dashed #d9d9d9;
border-radius: 4px;
background-color: #fafafa;
}
</style>

View File

@ -1,8 +1,9 @@
import { AreaLevelEnum } from '@vben/constants';
import {
localeProps,
makeRequiredRule,
} from '#/components/form-create/helpers';
import { AreaLevelEnum } from '@vben/constants';
/** 省市区选择器规则 */
export function useAreaSelectRule() {

View File

@ -3,6 +3,9 @@ import type { Recordable } from '@vben/types';
export * from './rangePickerProps';
export * from './routerHelper';
// 从共享包导出 URL 工具函数
export { isUrl } from '@vben/utils';
/**
*
* @param {Array} ary
@ -27,16 +30,3 @@ export const findIndex = <T = Recordable<any>>(
});
return index;
};
/**
* URL
* @param path URL
*/
export const isUrl = (path: string): boolean => {
// fix:修复hash路由无法跳转的问题
/* eslint-disable regexp/no-unused-capturing-group, regexp/no-super-linear-backtracking, regexp/no-useless-quantifier */
const reg =
/(((^https?:(?:\/\/)?)(?:[-:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%#/.\w-]*)?\??[-+=&%@.\w]*(?:#\w*)?)?)$/;
return reg.test(path);
/* eslint-enable regexp/no-unused-capturing-group, regexp/no-super-linear-backtracking, regexp/no-useless-quantifier */
};

View File

@ -2,10 +2,11 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue';
import { AreaLevelEnum } from '@vben/constants';
import { ElCascader } from 'element-plus';
import { getAreaTree } from '#/api/system/area';
import { AreaLevelEnum } from '@vben/constants';
defineOptions({ name: 'AreaSelect' });
@ -37,7 +38,7 @@ interface AreaVO {
//
interface Props {
modelValue?: number[] | string[];
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
level?: (typeof AreaLevelEnum)[keyof typeof AreaLevelEnum];
disabled?: boolean;
placeholder?: string;
clearable?: boolean;

View File

@ -68,9 +68,9 @@ const showPreview = computed(() => {
}
.iframe-preview {
overflow: hidden;
border: 1px solid #dcdfe6;
border-radius: 4px;
overflow: hidden;
}
.iframe-content {
@ -83,8 +83,8 @@ const showPreview = computed(() => {
align-items: center;
justify-content: center;
min-height: 200px;
background-color: #fafafa;
border: 1px dashed #dcdfe6;
border-radius: 4px;
background-color: #fafafa;
}
</style>

View File

@ -1,8 +1,9 @@
import { AreaLevelEnum } from '@vben/constants';
import {
localeProps,
makeRequiredRule,
} from '#/components/form-create/helpers';
import { AreaLevelEnum } from '@vben/constants';
/** 省市区选择器规则 */
export function useAreaSelectRule() {

View File

@ -3,6 +3,9 @@ import type { Recordable } from '@vben/types';
export * from './rangePickerProps';
export * from './routerHelper';
// 从共享包导出 URL 工具函数
export { isUrl } from '@vben/utils';
/**
*
* @param {Array} ary
@ -28,16 +31,3 @@ export const findIndex = <T = Recordable<any>>(
});
return index;
};
/**
* URL
* @param path URL
*/
export const isUrl = (path: string): boolean => {
// fix:修复hash路由无法跳转的问题
/* eslint-disable regexp/no-unused-capturing-group, regexp/no-super-linear-backtracking, regexp/no-useless-quantifier */
const reg =
/(((^https?:(?:\/\/)?)(?:[-:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%#/.\w-]*)?\??[-+=&%@.\w]*(?:#\w*)?)?)$/;
return reg.test(path);
/* eslint-enable regexp/no-unused-capturing-group, regexp/no-super-linear-backtracking, regexp/no-useless-quantifier */
};

View File

@ -18,6 +18,7 @@ export * from './tree';
export * from './unique';
export * from './update-css-variables';
export * from './upload';
export * from './url';
export * from './util';
export * from './uuid'; // add by 芋艿:从 vben2.0 复制
export * from './window';

View File

@ -0,0 +1,12 @@
/**
* URL
* @param path URL
*/
export function isUrl(path: string): boolean {
try {
new URL(path);
return true;
} catch {
return false;
}
}