fix: 🐛 修复web-types可选值/默认值类型识别错误 (#899)

This commit is contained in:
xiaohe0601 2025-02-18 15:11:44 +08:00 committed by GitHub
parent 18cef13bae
commit 8b4d2ed14b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 60 additions and 40 deletions

View File

@ -233,7 +233,7 @@ function handleSwitchChange({ value }) {
| -------- | -------------- | ------- | ------ | ------ | -------- | | -------- | -------------- | ------- | ------ | ------ | -------- |
| title | 分组标题 | string | - | - | - | | title | 分组标题 | string | - | - | - |
| value | 分组右侧内容 | string | - | - | - | | value | 分组右侧内容 | string | - | - | - |
| border | 是否展示边框线 | string | - | - | - | | border | 是否展示边框线 | boolean | - | - | - |
| use-slot | 分组启用插槽 | boolean | - | false | - | | use-slot | 分组启用插槽 | boolean | - | false | - |
## Cell Attributes ## Cell Attributes

View File

@ -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 | | `customClass` | 自定义class | string | - | - | 0.1.19 |
| `customStyle` | 自定义style | string | - | - | 0.1.19 | | `customStyle` | 自定义style | string | - | - | 0.1.19 |
| `size` | 圆环直径,默认单位为 px | number | - | `100` | 0.1.19 | | `size` | 圆环直径,默认单位为 px | number | - | `100` | 0.1.19 |
| `color` | 进度条颜色 | string \| Record<string, string> | - | `#4d80f0` | 0.1.19 | | `color` | 进度条颜色 | string / Record<string, string> | - | `#4d80f0` | 0.1.19 |
| `layerColor` | 轨道颜色 | string | - | `#EBEEF5` | 0.1.19 | | `layerColor` | 轨道颜色 | string | - | `#EBEEF5` | 0.1.19 |
| `fill` | 填充颜色 | string | - | `#ffffff` | 0.1.19 | | `fill` | 填充颜色 | string | - | `#ffffff` | 0.1.19 |
| `speed` | 动画速度(单位为 rate/s | number | - | `50` | 0.1.19 | | `speed` | 动画速度(单位为 rate/s | number | - | `50` | 0.1.19 |
| `text` | 文字 | string | - | - | 0.1.19 | | `text` | 文字 | string | - | - | 0.1.19 |
| `strokeWidth` | 进度条宽度单位px | number | - | `10` | 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 | | `clockwise` | 是否顺时针增加 | boolean | - | `true` | 0.1.19 |

View File

@ -297,7 +297,7 @@ function handleClear() {
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| ----- | -------- | ---------------- | ------ | ------ | -------- | | ----- | -------- | ---------------- | ------ | ------ | -------- |
| index | 索引字符 | string \| number | - | - | - | | index | 索引字符 | string / number | - | - | - |
## IndexAnchor Slots ## IndexAnchor Slots

View File

@ -83,7 +83,7 @@ watch(value, (newVal) => {
| info | 输入框下方文字提示 | string | - | - | - | | info | 输入框下方文字提示 | string | - | - | - |
| error-info | 输入框下方错误提示 | string | - | - | - | | error-info | 输入框下方错误提示 | string | - | - | - |
| length | 密码最大长度 | number | - | 6 | - | | length | 密码最大长度 | number | - | 6 | - |
| gutter | 输入框格子之间的间距,如 20px 2em默认单位为 px | number \| string | - | 0 | - | | gutter | 输入框格子之间的间距,如 20px 2em默认单位为 px | number / string | - | 0 | - |
| mask | 是否隐藏密码内容 | boolean | - | true | - | | mask | 是否隐藏密码内容 | boolean | - | true | - |
| focused | 是否已聚焦,聚焦时会显示光标 | boolean | - | false | - | | focused | 是否已聚焦,聚焦时会显示光标 | boolean | - | false | - |

View File

@ -77,8 +77,8 @@ const percentage = ref<number>(100)
| ---------- | --------------------- | --------------------------------------- | ---------------- | ------ | -------- | | ---------- | --------------------- | --------------------------------------- | ---------------- | ------ | -------- |
| percentage | 进度数值,最大值 100 | `number` | - | 0 | - | | percentage | 进度数值,最大值 100 | `number` | - | 0 | - |
| hide-text | 隐藏进度文字 | `boolean` | - | false | - | | hide-text | 隐藏进度文字 | `boolean` | - | false | - |
| color | 进度条颜色 | `string \| ProgressColor[] \| string[]` | - | - | - | | color | 进度条颜色 | `string / ProgressColor[] / string[]` | - | - | - |
| status | 进度条状态 | `string` | success \| danger \| warning | - | - | | status | 进度条状态 | `string` | success / danger / warning | - | - |
| duration | 进度增加 1%所需毫秒数 | `number` | - | 30 | - | | duration | 进度增加 1%所需毫秒数 | `number` | - | 30 | - |
### ProgressColor ### ProgressColor

View File

@ -142,18 +142,18 @@ function handlePopupShow() {
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| ------------------- | ------------------ | ------------------------------------------- | ------------------------------ | -------- | -------- | | ------------------- | ------------------ | ------------------------------------------- | ------------------------------ | -------- | -------- |
| value/v-model:value | 当前选中的值 | string \| number | - | - | 0.1.23 | | value/v-model:value | 当前选中的值 | string / number | - | - | 0.1.23 |
| disabled | 是否禁用分段器 | boolean | true \| false | `false` | 0.1.23 | | disabled | 是否禁用分段器 | boolean | true / false | `false` | 0.1.23 |
| size | 控件尺寸 | string | `large` \| `middle` \| `small` | `middle` | 0.1.23 | | size | 控件尺寸 | string | `large` / `middle` / `small` | `middle` | 0.1.23 |
| options | 数据集合 | `string[] \| number[] \| SegmentedOption[]` | - | [] | 0.1.23 | | options | 数据集合 | `string[] / number[] / SegmentedOption[]` | - | [] | 0.1.23 |
| vibrateShort | 切换选项时是否振动 | boolean | true \| false | `false` | 0.1.23 | | vibrateShort | 切换选项时是否振动 | boolean | true / false | `false` | 0.1.23 |
### SegmentedOption ### SegmentedOption
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| -------- | -------- | ---------------- | ------------- | ------ | -------- | | -------- | -------- | ---------------- | ------------- | ------ | -------- |
| value | 选中值 | string \| number | - | - | 0.1.23 | | value | 选中值 | string / number | - | - | 0.1.23 |
| disabled | 是否禁用 | boolean | true \| false | - | 0.1.23 | | disabled | 是否禁用 | boolean | true / false | - | 0.1.23 |
| payload | 更多数据 | any | - | - | 0.1.23 | | payload | 更多数据 | any | - | - | 0.1.23 |
## Events ## Events

View File

@ -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 | | before-change | 切换导航项前钩子,可以在切换标签前执行特定的逻辑,接收 { value, resolve } 参数,通过 resolve 继续执行resolve 接收 1 个 boolean 参数 | function | - | - | 1.4.0 |
## Events ## Events
@ -494,9 +494,9 @@ function onScroll(e) {
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| ----------- | ---------------------------------------------------------------------------------------- | -------------------------- | ------ | ------ | -------- | | ----------- | ---------------------------------------------------------------------------------------- | -------------------------- | ------ | ------ | -------- |
| label | 当前选项标题 | string | - | - | 0.1.49 | | label | 当前选项标题 | string | - | - | 0.1.49 |
| value | 当前选项的值,唯一标识 | `number \| string` | - | - | 0.1.49 | | value | 当前选项的值,唯一标识 | `number / string` | - | - | 0.1.49 |
| icon | 图标 | 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 | | isDot | 徽标属性,是否点状徽标 | boolean | - | false | 0.1.49 |
| max | 徽标属性,徽标最大值 | number | - | 99 | 0.1.49 | | max | 徽标属性,徽标最大值 | number | - | 99 | 0.1.49 |
| disabled | 是否禁用 | boolean | - | false | 0.1.49 | | disabled | 是否禁用 | boolean | - | false | 0.1.49 |

View File

@ -78,8 +78,8 @@
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| ------ | ------------------------- | ---------------- | ------ | ------ | -------- | | ------ | ------------------------- | ---------------- | ------ | ------ | -------- |
| height | 图片高度,默认单位为 `px` | string \| number | - | - | 1.2.12 | | height | 图片高度,默认单位为 `px` | string / number | - | - | 1.2.12 |
| width | 图片宽度,默认单位为 `px` | string \| number | - | - | 1.2.12 | | width | 图片宽度,默认单位为 `px` | string / number | - | - | 1.2.12 |
## Slot ## Slot

View File

@ -309,15 +309,15 @@ const isLoop = ref(false)
| displayMultipleItems | 同时显示的滑块数量 | `number` | - | 1 | 0.1.22 | | displayMultipleItems | 同时显示的滑块数量 | `number` | - | 1 | 0.1.22 |
| duration | 滑动动画时长 | `number` | - | 300 | 0.1.22 | | duration | 滑动动画时长 | `number` | - | 300 | 0.1.22 |
| easingFunction | 切换缓动动画类型(微信小程序、快手小程序、京东小程序) | `EasingType` | - | default | 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 | | interval | 轮播间隔时间 | `number` | - | 5000 | 0.1.22 |
| list | 图片列表 | `string[] \| SwiperList[]` | - | - | 0.1.22 | | list | 图片列表 | `string[] / SwiperList[]` | - | - | 0.1.22 |
| loop | 是否循环播放 | `boolean` | - | true | 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 | | 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 | | 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 | | 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 | | autoplayVideo | 视频是否自动播放,默认自动播放 | `boolean` | - | true | 1.3.13 |
| stopPreviousVideo  | 切换轮播项时是否停止上一个视频的播放,默认切换时停止播放上一个视频 | `boolean` | - | true | 1.3.13 | | stopPreviousVideo  | 切换轮播项时是否停止上一个视频的播放,默认切换时停止播放上一个视频 | `boolean` | - | true | 1.3.13 |
@ -325,7 +325,7 @@ const isLoop = ref(false)
| customStyle | 外部自定义样式 | `string` | - | '' | 0.1.22 | | customStyle | 外部自定义样式 | `string` | - | '' | 0.1.22 |
| value-key | 选项对象中value 对应的 key | `string` | - | `value` | 1.3.7 | | value-key | 选项对象中value 对应的 key | `string` | - | `value` | 1.3.7 |
| text-key | 选项对象中,标题 text 对应的 key | `string` | - | `text` | 1.3.13 | | 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 | | adjust-vertical-height | vertical 为 true 时强制使 adjust-height 生效。仅支付宝小程序支持。 | `boolean` | - | `false` | 1.3.13 |
muted | 视频是否静音播放 | `boolean` | - | `true` | 1.6.0 | muted | 视频是否静音播放 | `boolean` | - | `true` | 1.6.0 |
| videoLoop | 视频是否循环播放 | `boolean` | - | `true` | 1.6.0 | | videoLoop | 视频是否循环播放 | `boolean` | - | `true` | 1.6.0 |

View File

@ -122,7 +122,7 @@ const value = ref<string>('')
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
|-------------------------|---------------------------------------------------------------------------------------------------|-------------------|------------------------------------|-----------|----------| |-------------------------|---------------------------------------------------------------------------------------------------|-------------------|------------------------------------|-----------|----------|
| v-model | 绑定值 | string\|number | - | - | - | | v-model | 绑定值 | string / number | - | - | - |
| placeholder | 占位文本 | string | - | 请输入... | - | | placeholder | 占位文本 | string | - | 请输入... | - |
| placeholderStyle | 原生属性,指定 placeholder 的样式 | string | - | - | - | | placeholderStyle | 原生属性,指定 placeholder 的样式 | string | - | - | - |
| placeholderClass | 原生属性,指定 placeholder 的样式类 | string | - | - | - | | placeholderClass | 原生属性,指定 placeholder 的样式类 | string | - | - | - |

View File

@ -43,15 +43,25 @@ const reWebTypesSource: ReWebTypesSource = (title) => {
return { symbol } return { symbol }
} }
// 获取纯净值(移除所有反引号和星号以及首尾的单双引号)
const getPureValue = (value: string) => {
return value
.replace(/[`*]/g, '')
.replace(/^['"]|['"]$/g, '')
.trim()
}
// 重新定义 WebTypes 类型的函数 // 重新定义 WebTypes 类型的函数
const reWebTypesType: ReWebTypesType = (type) => { const reWebTypesType: ReWebTypesType = (type) => {
const isPublicType = isCommonType(type) const _type = getPureValue(type)
const isNumber = /^\d+$/.test(type)
const symbol = getTypeSymbol(type) const isPublicType = isCommonType(_type)
const isNumber = /^\d+$/.test(_type)
const symbol = getTypeSymbol(_type)
const isUnion = isUnionType(symbol) const isUnion = isUnionType(symbol)
const module = findModule(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,7 +82,8 @@ const toKebabCase = (str: string) => {
// 重新定义属性名称的函数 // 重新定义属性名称的函数
const reAttribute: ReAttribute = (value, key, row, title) => { const reAttribute: ReAttribute = (value, key, row, title) => {
if (title.includes('Attributes') && key === '参数') { if (title.includes('Attributes')) {
if (key === '参数') {
if (value.includes('v-model:')) { if (value.includes('v-model:')) {
const part = value.split(/[\s/|]/).find((part) => part.startsWith('v-model:')) const part = value.split(/[\s/|]/).find((part) => part.startsWith('v-model:'))
if (part) { if (part) {
@ -83,6 +94,15 @@ const reAttribute: ReAttribute = (value, key, row, title) => {
return 'v-model' return 'v-model'
} }
return toKebabCase(value.replace(/[^\w\s-]/g, '')) return toKebabCase(value.replace(/[^\w\s-]/g, ''))
} else if (key === '可选值' || key === '默认值') {
const pureValue = getPureValue(value)
if (['', '-', '—'].includes(pureValue)) {
return undefined
} else {
return pureValue
}
}
} }
return value return value
} }