From 8b4d2ed14b6340003c63d10e31c02f058bed3ef0 Mon Sep 17 00:00:00 2001 From: xiaohe0601 Date: Tue, 18 Feb 2025 15:11:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Dweb-typ?= =?UTF-8?q?es=E5=8F=AF=E9=80=89=E5=80=BC/=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=AF=86=E5=88=AB=E9=94=99=E8=AF=AF=20(#899)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/component/cell.md | 2 +- docs/component/circle.md | 6 ++--- docs/component/index-bar.md | 2 +- docs/component/password-input.md | 2 +- docs/component/progress.md | 4 +-- docs/component/segmented.md | 14 +++++----- docs/component/sidebar.md | 6 ++--- docs/component/status-tip.md | 4 +-- docs/component/swiper.md | 12 ++++----- docs/component/textarea.md | 2 +- scripts/build-web-types.ts | 46 +++++++++++++++++++++++--------- 11 files changed, 60 insertions(+), 40 deletions(-) diff --git a/docs/component/cell.md b/docs/component/cell.md index 04b4fb89..e34cbbe3 100644 --- a/docs/component/cell.md +++ b/docs/component/cell.md @@ -233,7 +233,7 @@ function handleSwitchChange({ value }) { | -------- | -------------- | ------- | ------ | ------ | -------- | | title | 分组标题 | string | - | - | - | | value | 分组右侧内容 | string | - | - | - | -| border | 是否展示边框线 | string | - | - | - | +| border | 是否展示边框线 | boolean | - | - | - | | use-slot | 分组启用插槽 | boolean | - | false | - | ## Cell Attributes diff --git a/docs/component/circle.md b/docs/component/circle.md index 887cdda7..1491d62f 100644 --- a/docs/component/circle.md +++ b/docs/component/circle.md @@ -67,17 +67,17 @@ const gradientColor = { | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ----------------- | ---------------------------- | --------------------------- | ------------------------------------------ | --------------- | -------- | -| `v-model` \|`modelValue` | 当前进度 | number | - | `0` | 0.1.19 | +| `v-model` / `modelValue` | 当前进度 | number | - | `0` | 0.1.19 | | `customClass` | 自定义class | string | - | - | 0.1.19 | | `customStyle` | 自定义style | string | - | - | 0.1.19 | | `size` | 圆环直径,默认单位为 px | number | - | `100` | 0.1.19 | -| `color` | 进度条颜色 | string \| Record | - | `#4d80f0` | 0.1.19 | +| `color` | 进度条颜色 | string / Record | - | `#4d80f0` | 0.1.19 | | `layerColor` | 轨道颜色 | string | - | `#EBEEF5` | 0.1.19 | | `fill` | 填充颜色 | string | - | `#ffffff` | 0.1.19 | | `speed` | 动画速度(单位为 rate/s) | number | - | `50` | 0.1.19 | | `text` | 文字 | string | - | - | 0.1.19 | | `strokeWidth` | 进度条宽度,单位px | number | - | `10` | 0.1.19 | -| `strokeLinecap` | 进度条端点的形状 | string | `butt` \| `round` \| `square` | `round` | 0.1.19 | +| `strokeLinecap` | 进度条端点的形状 | string | `butt` / `round` / `square` | `round` | 0.1.19 | | `clockwise` | 是否顺时针增加 | boolean | - | `true` | 0.1.19 | diff --git a/docs/component/index-bar.md b/docs/component/index-bar.md index d0991420..d23547cc 100644 --- a/docs/component/index-bar.md +++ b/docs/component/index-bar.md @@ -297,7 +297,7 @@ function handleClear() { | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ----- | -------- | ---------------- | ------ | ------ | -------- | -| index | 索引字符 | string \| number | - | - | - | +| index | 索引字符 | string / number | - | - | - | ## IndexAnchor Slots diff --git a/docs/component/password-input.md b/docs/component/password-input.md index 117178fa..dac315a7 100644 --- a/docs/component/password-input.md +++ b/docs/component/password-input.md @@ -83,7 +83,7 @@ watch(value, (newVal) => { | info | 输入框下方文字提示 | string | - | - | - | | error-info | 输入框下方错误提示 | string | - | - | - | | length | 密码最大长度 | number | - | 6 | - | -| gutter | 输入框格子之间的间距,如 20px 2em,默认单位为 px | number \| string | - | 0 | - | +| gutter | 输入框格子之间的间距,如 20px 2em,默认单位为 px | number / string | - | 0 | - | | mask | 是否隐藏密码内容 | boolean | - | true | - | | focused | 是否已聚焦,聚焦时会显示光标 | boolean | - | false | - | diff --git a/docs/component/progress.md b/docs/component/progress.md index ae8b3150..54a44839 100644 --- a/docs/component/progress.md +++ b/docs/component/progress.md @@ -77,8 +77,8 @@ const percentage = ref(100) | ---------- | --------------------- | --------------------------------------- | ---------------- | ------ | -------- | | percentage | 进度数值,最大值 100 | `number` | - | 0 | - | | hide-text | 隐藏进度文字 | `boolean` | - | false | - | -| color | 进度条颜色 | `string \| ProgressColor[] \| string[]` | - | - | - | -| status | 进度条状态 | `string` | success \| danger \| warning | - | - | +| color | 进度条颜色 | `string / ProgressColor[] / string[]` | - | - | - | +| status | 进度条状态 | `string` | success / danger / warning | - | - | | duration | 进度增加 1%所需毫秒数 | `number` | - | 30 | - | ### ProgressColor diff --git a/docs/component/segmented.md b/docs/component/segmented.md index e9daf58f..b76f7f31 100644 --- a/docs/component/segmented.md +++ b/docs/component/segmented.md @@ -142,18 +142,18 @@ function handlePopupShow() { | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ------------------- | ------------------ | ------------------------------------------- | ------------------------------ | -------- | -------- | -| value/v-model:value | 当前选中的值 | string \| number | - | - | 0.1.23 | -| disabled | 是否禁用分段器 | boolean | true \| false | `false` | 0.1.23 | -| size | 控件尺寸 | string | `large` \| `middle` \| `small` | `middle` | 0.1.23 | -| options | 数据集合 | `string[] \| number[] \| SegmentedOption[]` | - | [] | 0.1.23 | -| vibrateShort | 切换选项时是否振动 | boolean | true \| false | `false` | 0.1.23 | +| value/v-model:value | 当前选中的值 | string / number | - | - | 0.1.23 | +| disabled | 是否禁用分段器 | boolean | true / false | `false` | 0.1.23 | +| size | 控件尺寸 | string | `large` / `middle` / `small` | `middle` | 0.1.23 | +| options | 数据集合 | `string[] / number[] / SegmentedOption[]` | - | [] | 0.1.23 | +| vibrateShort | 切换选项时是否振动 | boolean | true / false | `false` | 0.1.23 | ### SegmentedOption | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | -------- | -------- | ---------------- | ------------- | ------ | -------- | -| value | 选中值 | string \| number | - | - | 0.1.23 | -| disabled | 是否禁用 | boolean | true \| false | - | 0.1.23 | +| value | 选中值 | string / number | - | - | 0.1.23 | +| disabled | 是否禁用 | boolean | true / false | - | 0.1.23 | | payload | 更多数据 | any | - | - | 0.1.23 | ## Events diff --git a/docs/component/sidebar.md b/docs/component/sidebar.md index 2601d849..72f56996 100644 --- a/docs/component/sidebar.md +++ b/docs/component/sidebar.md @@ -467,7 +467,7 @@ function onScroll(e) { | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | ------ | ------ | ---------------- | -| modelValue/v-model | 当前导航项的索引 | string \| number | - | 0 | 0.1.49 | +| modelValue / v-model | 当前导航项的索引 | string / number | - | 0 | 0.1.49 | | before-change | 切换导航项前钩子,可以在切换标签前执行特定的逻辑,接收 { value, resolve } 参数,通过 resolve 继续执行,resolve 接收 1 个 boolean 参数 | function | - | - | 1.4.0 | ## Events @@ -494,9 +494,9 @@ function onScroll(e) { | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ----------- | ---------------------------------------------------------------------------------------- | -------------------------- | ------ | ------ | -------- | | label | 当前选项标题 | string | - | - | 0.1.49 | -| value | 当前选项的值,唯一标识 | `number \| string` | - | - | 0.1.49 | +| value | 当前选项的值,唯一标识 | `number / string` | - | - | 0.1.49 | | icon | 图标 | string | - | - | 0.1.49 | -| badge | 徽标属性,徽标显示值 | `number \| string \| null` | - | - | 0.1.49 | +| badge | 徽标属性,徽标显示值 | `number / string / null` | - | - | 0.1.49 | | isDot | 徽标属性,是否点状徽标 | boolean | - | false | 0.1.49 | | max | 徽标属性,徽标最大值 | number | - | 99 | 0.1.49 | | disabled | 是否禁用 | boolean | - | false | 0.1.49 | diff --git a/docs/component/status-tip.md b/docs/component/status-tip.md index 4dfdda9a..147992e4 100644 --- a/docs/component/status-tip.md +++ b/docs/component/status-tip.md @@ -78,8 +78,8 @@ | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ------ | ------------------------- | ---------------- | ------ | ------ | -------- | -| height | 图片高度,默认单位为 `px` | string \| number | - | - | 1.2.12 | -| width | 图片宽度,默认单位为 `px` | string \| number | - | - | 1.2.12 | +| height | 图片高度,默认单位为 `px` | string / number | - | - | 1.2.12 | +| width | 图片宽度,默认单位为 `px` | string / number | - | - | 1.2.12 | ## Slot diff --git a/docs/component/swiper.md b/docs/component/swiper.md index 7a439c38..e90fcb55 100644 --- a/docs/component/swiper.md +++ b/docs/component/swiper.md @@ -309,15 +309,15 @@ const isLoop = ref(false) | displayMultipleItems | 同时显示的滑块数量 | `number` | - | 1 | 0.1.22 | | duration | 滑动动画时长 | `number` | - | 300 | 0.1.22 | | easingFunction | 切换缓动动画类型(微信小程序、快手小程序、京东小程序) | `EasingType` | - | default | 0.1.22 | -| height | 轮播的高度 | `string \| number` | - | 192 | 0.1.22 | +| height | 轮播的高度 | `string / number` | - | 192 | 0.1.22 | | interval | 轮播间隔时间 | `number` | - | 5000 | 0.1.22 | -| list | 图片列表 | `string[] \| SwiperList[]` | - | - | 0.1.22 | +| list | 图片列表 | `string[] / SwiperList[]` | - | - | 0.1.22 | | loop | 是否循环播放 | `boolean` | - | true | 0.1.22 | -| nextMargin | 后边距 | `string \| number` | - | 0 | 0.1.22 | +| nextMargin | 后边距 | `string / number` | - | 0 | 0.1.22 | | indicatorPosition | 指示器展示位置 | `IndicatorPositionType` | `left, top-left, top, top-right, bottom-left, bottom, bottom-right, right` | bottom | 0.1.22 | -| previousMargin | 前边距 | `string \| number` | - | 0 | 0.1.22 | +| previousMargin | 前边距 | `string / number` | - | 0 | 0.1.22 | | snapToEdge | 边距是否应用到第一个、最后一个元素 | `boolean` | - | false | 0.1.22 | -| indicator | 指示器全部配置 | `SwiperIndicatorProps \| boolean` | - | true | 0.1.22 | +| indicator | 指示器全部配置 | `SwiperIndicatorProps / boolean` | - | true | 0.1.22 | | imageMode | 图片裁剪、缩放的模式 | `string` | 参考官方文档[mode](https://uniapp.dcloud.net.cn/component/image.html#mode-%E6%9C%89%E6%95%88%E5%80%BC) | `aspectFill` | 0.1.55 | | autoplayVideo | 视频是否自动播放,默认自动播放 | `boolean` | - | true | 1.3.13 | | stopPreviousVideo  | 切换轮播项时是否停止上一个视频的播放,默认切换时停止播放上一个视频 | `boolean` | - | true | 1.3.13 | @@ -325,7 +325,7 @@ const isLoop = ref(false) | customStyle | 外部自定义样式 | `string` | - | '' | 0.1.22 | | value-key | 选项对象中,value 对应的 key | `string` | - | `value` | 1.3.7 | | text-key | 选项对象中,标题 text 对应的 key | `string` | - | `text` | 1.3.13 | -| adjust-height | 自动以指定滑块的高度为整个容器的高度。当 vertical 为 true 时,默认不调整,仅支付宝小程序支持。| `string` | `'first' \| 'current' \| 'highest' \| 'none'` | `highest` | 1.3.13 | +| adjust-height | 自动以指定滑块的高度为整个容器的高度。当 vertical 为 true 时,默认不调整,仅支付宝小程序支持。| `string` | `'first' / 'current' / 'highest' / 'none'` | `highest` | 1.3.13 | | adjust-vertical-height | vertical 为 true 时强制使 adjust-height 生效。仅支付宝小程序支持。 | `boolean` | - | `false` | 1.3.13 | | muted | 视频是否静音播放 | `boolean` | - | `true` | 1.6.0 | | videoLoop | 视频是否循环播放 | `boolean` | - | `true` | 1.6.0 | diff --git a/docs/component/textarea.md b/docs/component/textarea.md index f585c0bb..d4d7c221 100644 --- a/docs/component/textarea.md +++ b/docs/component/textarea.md @@ -122,7 +122,7 @@ const value = ref('') | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | |-------------------------|---------------------------------------------------------------------------------------------------|-------------------|------------------------------------|-----------|----------| -| v-model | 绑定值 | string\|number | - | - | - | +| v-model | 绑定值 | string / number | - | - | - | | placeholder | 占位文本 | string | - | 请输入... | - | | placeholderStyle | 原生属性,指定 placeholder 的样式 | string | - | - | - | | placeholderClass | 原生属性,指定 placeholder 的样式类 | string | - | - | - | diff --git a/scripts/build-web-types.ts b/scripts/build-web-types.ts index a3975043..bc369142 100644 --- a/scripts/build-web-types.ts +++ b/scripts/build-web-types.ts @@ -43,15 +43,25 @@ const reWebTypesSource: ReWebTypesSource = (title) => { return { symbol } } +// 获取纯净值(移除所有反引号和星号以及首尾的单双引号) +const getPureValue = (value: string) => { + return value + .replace(/[`*]/g, '') + .replace(/^['"]|['"]$/g, '') + .trim() +} + // 重新定义 WebTypes 类型的函数 const reWebTypesType: ReWebTypesType = (type) => { - const isPublicType = isCommonType(type) - const isNumber = /^\d+$/.test(type) - const symbol = getTypeSymbol(type) + const _type = getPureValue(type) + + const isPublicType = isCommonType(_type) + const isNumber = /^\d+$/.test(_type) + const symbol = getTypeSymbol(_type) const isUnion = isUnionType(symbol) const module = findModule(symbol) - return isPublicType || isNumber || !symbol || isUnion ? type : { name: type, source: { symbol, module } } + return isPublicType || isNumber || !symbol || isUnion ? _type : { name: _type, source: { symbol, module } } } // 查找模块的函数 @@ -72,17 +82,27 @@ const toKebabCase = (str: string) => { // 重新定义属性名称的函数 const reAttribute: ReAttribute = (value, key, row, title) => { - if (title.includes('Attributes') && key === '参数') { - if (value.includes('v-model:')) { - const part = value.split(/[\s/|]/).find((part) => part.startsWith('v-model:')) - if (part) { - const suffix = toKebabCase(part.split(':')[1].split(/[\s\W]/)[0]) - return `v-model:${suffix}` + if (title.includes('Attributes')) { + if (key === '参数') { + if (value.includes('v-model:')) { + const part = value.split(/[\s/|]/).find((part) => part.startsWith('v-model:')) + if (part) { + const suffix = toKebabCase(part.split(':')[1].split(/[\s\W]/)[0]) + return `v-model:${suffix}` + } + } else if (value.includes('v-model')) { + return 'v-model' + } + return toKebabCase(value.replace(/[^\w\s-]/g, '')) + } else if (key === '可选值' || key === '默认值') { + const pureValue = getPureValue(value) + + if (['', '-', '—'].includes(pureValue)) { + return undefined + } else { + return pureValue } - } else if (value.includes('v-model')) { - return 'v-model' } - return toKebabCase(value.replace(/[^\w\s-]/g, '')) } return value }