feat: 添加 URL 验证工具函数并优化 area-select 组件的类型定义
parent
f91a2702c9
commit
1cbdf442ee
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* URL 验证
|
||||
* @param path URL 路径
|
||||
*/
|
||||
export function isUrl(path: string): boolean {
|
||||
try {
|
||||
new URL(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue