!333 fix(form-create): 【ele/antd】完成 vue3 review c153ff93 的所有 TODO 修复

Merge pull request !333 from puhui999/master-fix
pull/336/MERGE
芋道源码 2026-03-07 03:23:42 +00:00 committed by Gitee
commit c885c0c71a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 85 additions and 82 deletions

View File

@ -2,18 +2,17 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue';
import { handleTree } from '@vben/utils';
import { Cascader } from 'ant-design-vue';
import { getAreaTree } from '#/api/system/area';
import { AreaLevelEnum } from '@vben/constants';
defineOptions({ name: 'AreaSelect' });
const props = withDefaults(defineProps<Props>(), {
modelValue: undefined,
value: undefined,
level: 3,
level: AreaLevelEnum.DISTRICT,
disabled: false,
placeholder: '请选择省市区',
clearable: true,
@ -41,7 +40,7 @@ interface AreaVO {
interface Props {
modelValue?: number[] | string[];
value?: number[] | string[];
level?: 1 | 2 | 3; // 1- 2- 3-
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
disabled?: boolean;
placeholder?: string;
clearable?: boolean;
@ -121,15 +120,15 @@ function syncSelectedValue(): void {
}
//
if (Array.isArray(newValue)) {
selectedValue.value = newValue as number[];
} else {
selectedValue.value = [newValue as number];
}
selectedValue.value = Array.isArray(newValue)
? (newValue as number[])
: [newValue as number];
}
// modelValue value
watch(() => props.modelValue || props.value, syncSelectedValue, { immediate: true });
watch(() => props.modelValue || props.value, syncSelectedValue, {
immediate: true,
});
//
onMounted(async () => {

View File

@ -1,6 +1,8 @@
<!-- 网页 iframe 组件 (Ant Design Vue 版本) -->
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { computed } from 'vue';
import { isUrl } from '#/utils';
defineOptions({ name: 'IframeComponent' });
@ -16,11 +18,6 @@ const props = withDefaults(defineProps<Props>(), {
sandbox: '',
});
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void;
(e: 'update:value', value: string): void;
}>();
//
interface Props {
modelValue?: string;
@ -36,23 +33,14 @@ interface Props {
}
// URL使 url prop使 value modelValue
const displayUrl = computed(() => props.url || props.value || props.modelValue || '');
const displayUrl = computed(
() => props.url || props.value || props.modelValue || '',
);
//
const showPreview = computed(() => {
return displayUrl.value && isValidUrl(displayUrl.value);
return displayUrl.value && isUrl(displayUrl.value);
});
// URL
function isValidUrl(url: string): boolean {
if (!url || url.trim() === '') return false;
try {
const urlObj = new URL(url);
return urlObj.protocol === 'http:' || urlObj.protocol === 'https:';
} catch {
return false;
}
}
</script>
<template>
@ -104,4 +92,3 @@ function isValidUrl(url: string): boolean {
background-color: #fafafa;
}
</style>

View File

@ -1,9 +1,8 @@
import { cloneDeep } from '@vben/utils';
import {
localeProps,
makeRequiredRule,
} from '#/components/form-create/helpers';
import { AreaLevelEnum } from '@vben/constants';
/** 省市区选择器规则 */
export function useAreaSelectRule() {
@ -31,11 +30,11 @@ export function useAreaSelectRule() {
type: 'select',
field: 'level',
title: '选择层级',
value: 3,
value: AreaLevelEnum.DISTRICT,
options: [
{ label: '省', value: 1 },
{ label: '省/市', value: 2 },
{ label: '省/市/区', value: 3 },
{ label: '省', value: AreaLevelEnum.PROVINCE },
{ label: '省/市', value: AreaLevelEnum.CITY },
{ label: '省/市/区', value: AreaLevelEnum.DISTRICT },
],
info: '限制可选择的地区层级',
},

View File

@ -27,3 +27,16 @@ 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,17 +2,16 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue';
import { handleTree } from '@vben/utils';
import { ElCascader } from 'element-plus';
import { getAreaTree } from '#/api/system/area';
import { AreaLevelEnum } from '@vben/constants';
defineOptions({ name: 'AreaSelect' });
const props = withDefaults(defineProps<Props>(), {
modelValue: undefined,
level: 3,
level: AreaLevelEnum.DISTRICT,
disabled: false,
placeholder: '请选择省市区',
clearable: true,
@ -38,7 +37,7 @@ interface AreaVO {
//
interface Props {
modelValue?: number[] | string[];
level?: 1 | 2 | 3; // 1- 2- 3-
level?: typeof AreaLevelEnum[keyof typeof AreaLevelEnum];
disabled?: boolean;
placeholder?: string;
clearable?: boolean;
@ -118,11 +117,9 @@ function syncSelectedValue(): void {
}
//
if (Array.isArray(newValue)) {
selectedValue.value = newValue as number[];
} else {
selectedValue.value = [newValue as number];
}
selectedValue.value = Array.isArray(newValue)
? (newValue as number[])
: [newValue as number];
}
// modelValue

View File

@ -1,6 +1,8 @@
<!-- 网页 iframe 组件 (Element Plus 版本) -->
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { computed } from 'vue';
import { isUrl } from '#/utils';
defineOptions({ name: 'IframeComponent' });
@ -15,10 +17,6 @@ const props = withDefaults(defineProps<Props>(), {
sandbox: '',
});
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void;
}>();
//
interface Props {
modelValue?: string;
@ -37,19 +35,8 @@ const displayUrl = computed(() => props.url || props.modelValue || '');
//
const showPreview = computed(() => {
return displayUrl.value && isValidUrl(displayUrl.value);
return displayUrl.value && isUrl(displayUrl.value);
});
// URL
function isValidUrl(url: string): boolean {
if (!url || url.trim() === '') return false;
try {
const urlObj = new URL(url);
return urlObj.protocol === 'http:' || urlObj.protocol === 'https:';
} catch {
return false;
}
}
</script>
<template>

View File

@ -1,9 +1,8 @@
import { cloneDeep } from '@vben/utils';
import {
localeProps,
makeRequiredRule,
} from '#/components/form-create/helpers';
import { AreaLevelEnum } from '@vben/constants';
/** 省市区选择器规则 */
export function useAreaSelectRule() {
@ -31,11 +30,11 @@ export function useAreaSelectRule() {
type: 'select',
field: 'level',
title: '选择层级',
value: 3,
value: AreaLevelEnum.DISTRICT,
options: [
{ label: '省', value: 1 },
{ label: '省/市', value: 2 },
{ label: '省/市/区', value: 3 },
{ label: '省', value: AreaLevelEnum.PROVINCE },
{ label: '省/市', value: AreaLevelEnum.CITY },
{ label: '省/市/区', value: AreaLevelEnum.DISTRICT },
],
info: '限制可选择的地区层级',
},

View File

@ -28,3 +28,16 @@ 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

@ -57,3 +57,12 @@ export const SystemUserSocialTypeEnum = {
img: 'https://s1.ax1x.com/2022/05/22/OzMrzn.png',
},
};
/**
*
*/
export const AreaLevelEnum = {
PROVINCE: 1, // 省
CITY: 2, // 市
DISTRICT: 3, // 区
} as const;