feat: 添加 URL 验证工具函数并优化 area-select 组件的类型定义
parent
f91a2702c9
commit
1cbdf442ee
|
|
@ -2,10 +2,11 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { AreaLevelEnum } from '@vben/constants';
|
||||||
|
|
||||||
import { Cascader } from 'ant-design-vue';
|
import { Cascader } from 'ant-design-vue';
|
||||||
|
|
||||||
import { getAreaTree } from '#/api/system/area';
|
import { getAreaTree } from '#/api/system/area';
|
||||||
import { AreaLevelEnum } from '@vben/constants';
|
|
||||||
|
|
||||||
defineOptions({ name: 'AreaSelect' });
|
defineOptions({ name: 'AreaSelect' });
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ interface AreaVO {
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue?: number[] | string[];
|
modelValue?: number[] | string[];
|
||||||
value?: number[] | string[];
|
value?: number[] | string[];
|
||||||
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
|
level?: (typeof AreaLevelEnum)[keyof typeof AreaLevelEnum];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
clearable?: boolean;
|
clearable?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,9 @@ const showPreview = computed(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
.iframe-preview {
|
.iframe-preview {
|
||||||
|
overflow: hidden;
|
||||||
border: 1px solid #d9d9d9;
|
border: 1px solid #d9d9d9;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.iframe-content {
|
.iframe-content {
|
||||||
|
|
@ -87,8 +87,8 @@ const showPreview = computed(() => {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
|
background-color: #fafafa;
|
||||||
border: 1px dashed #d9d9d9;
|
border: 1px dashed #d9d9d9;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background-color: #fafafa;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { AreaLevelEnum } from '@vben/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
localeProps,
|
localeProps,
|
||||||
makeRequiredRule,
|
makeRequiredRule,
|
||||||
} from '#/components/form-create/helpers';
|
} from '#/components/form-create/helpers';
|
||||||
import { AreaLevelEnum } from '@vben/constants';
|
|
||||||
|
|
||||||
/** 省市区选择器规则 */
|
/** 省市区选择器规则 */
|
||||||
export function useAreaSelectRule() {
|
export function useAreaSelectRule() {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ import type { Recordable } from '@vben/types';
|
||||||
export * from './rangePickerProps';
|
export * from './rangePickerProps';
|
||||||
export * from './routerHelper';
|
export * from './routerHelper';
|
||||||
|
|
||||||
|
// 从共享包导出 URL 工具函数
|
||||||
|
export { isUrl } from '@vben/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找数组对象的某个下标
|
* 查找数组对象的某个下标
|
||||||
* @param {Array} ary 查找的数组
|
* @param {Array} ary 查找的数组
|
||||||
|
|
@ -27,16 +30,3 @@ export const findIndex = <T = Recordable<any>>(
|
||||||
});
|
});
|
||||||
return index;
|
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>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { AreaLevelEnum } from '@vben/constants';
|
||||||
|
|
||||||
import { ElCascader } from 'element-plus';
|
import { ElCascader } from 'element-plus';
|
||||||
|
|
||||||
import { getAreaTree } from '#/api/system/area';
|
import { getAreaTree } from '#/api/system/area';
|
||||||
import { AreaLevelEnum } from '@vben/constants';
|
|
||||||
|
|
||||||
defineOptions({ name: 'AreaSelect' });
|
defineOptions({ name: 'AreaSelect' });
|
||||||
|
|
||||||
|
|
@ -37,7 +38,7 @@ interface AreaVO {
|
||||||
// 接受父组件参数
|
// 接受父组件参数
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue?: number[] | string[];
|
modelValue?: number[] | string[];
|
||||||
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
|
level?: (typeof AreaLevelEnum)[keyof typeof AreaLevelEnum];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
clearable?: boolean;
|
clearable?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ const showPreview = computed(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
.iframe-preview {
|
.iframe-preview {
|
||||||
|
overflow: hidden;
|
||||||
border: 1px solid #dcdfe6;
|
border: 1px solid #dcdfe6;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.iframe-content {
|
.iframe-content {
|
||||||
|
|
@ -83,8 +83,8 @@ const showPreview = computed(() => {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
|
background-color: #fafafa;
|
||||||
border: 1px dashed #dcdfe6;
|
border: 1px dashed #dcdfe6;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background-color: #fafafa;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { AreaLevelEnum } from '@vben/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
localeProps,
|
localeProps,
|
||||||
makeRequiredRule,
|
makeRequiredRule,
|
||||||
} from '#/components/form-create/helpers';
|
} from '#/components/form-create/helpers';
|
||||||
import { AreaLevelEnum } from '@vben/constants';
|
|
||||||
|
|
||||||
/** 省市区选择器规则 */
|
/** 省市区选择器规则 */
|
||||||
export function useAreaSelectRule() {
|
export function useAreaSelectRule() {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ import type { Recordable } from '@vben/types';
|
||||||
export * from './rangePickerProps';
|
export * from './rangePickerProps';
|
||||||
export * from './routerHelper';
|
export * from './routerHelper';
|
||||||
|
|
||||||
|
// 从共享包导出 URL 工具函数
|
||||||
|
export { isUrl } from '@vben/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找数组对象的某个下标
|
* 查找数组对象的某个下标
|
||||||
* @param {Array} ary 查找的数组
|
* @param {Array} ary 查找的数组
|
||||||
|
|
@ -28,16 +31,3 @@ export const findIndex = <T = Recordable<any>>(
|
||||||
});
|
});
|
||||||
return index;
|
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 './unique';
|
||||||
export * from './update-css-variables';
|
export * from './update-css-variables';
|
||||||
export * from './upload';
|
export * from './upload';
|
||||||
|
export * from './url';
|
||||||
export * from './util';
|
export * from './util';
|
||||||
export * from './uuid'; // add by 芋艿:从 vben2.0 复制
|
export * from './uuid'; // add by 芋艿:从 vben2.0 复制
|
||||||
export * from './window';
|
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