uview-plus 3.8.125 → 3.8.127

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## 3.8.127
2
+ fix: 修复抖音小程序 tabbar-item / steps-item 因父子生命周期顺序导致的崩溃
3
+
4
+ 抖音小程序中,子组件的 created 可能早于父组件的 created 执行,此时父组件实例已可通过 $parent 找到,但父组件的 children 数组尚未初始化(u-tabbar / u-steps / u-list 都在自己的 created 里才赋值 children=[])。子组件 init() 直接访问 this.parent.children.indexOf(this) 时 children 仍为 undefined,抛出 TypeError: Cannot read properties of undefined (reading 'indexOf'),并伴随「up-tabbar-item必须搭配up-tabbar组件使用」的误报警告(该分支只 log 未 return,继续执行才崩溃)。对照 u-radio / u-checkbox:它们在 mounted() 调 init() 且不访问 parent.children,所以不受影响。
5
+
6
+ - u-tabbar-item:init() 在 error() 后补 return,并加 !this.parent.children 守卫;mounted() 新增 init() 补偿重试(created 阶段被跳过时补齐激活态);clickHandler() 补 this.parent / children 守卫
7
+ - u-steps-item:init() 加 !this.parent.children 守卫;mounted() 新增 init() 补偿重试,确保自身已注册进父组件 children
8
+ - u-list-item:init() 加 !this.parent / !this.parent.children 守卫,避免 $parent 返回 false 时报错
9
+ - 共享 mixin getParentData():访问 children 前先判断 this.parent 存在,避免 $parent 返回 false 时读取 false.children 崩溃,影响所有父子联动组件
10
+
11
+ ## 3.8.126
12
+ feat: 新增 u-flex 通用弹性布局容器组件
13
+
14
+ 新增 u-flex(up-flex)通用 flexbox 容器组件,跨端同名同默认,作为页面 view 之上的一层弹性布局落点,免去每处手写 display:flex 与各类对齐样式,让行列布局在 H5、小程序、App 各端保持一致表现。
15
+
16
+ - 支持 direction 主轴方向 row / column / row-reverse / column-reverse(默认 row)
17
+ - 支持 justify 主轴对齐 flex-start / flex-end / center / space-between / space-around / space-evenly,并兼容 start / end 简写
18
+ - 支持 align 交叉轴对齐 flex-start / flex-end / center / stretch / baseline(默认 stretch)
19
+ - 支持 wrap 是否换行(默认 false)与 gap 子元素间距(任意单位,自动 addUnit 处理)
20
+ - 支持 customStyle 外部样式深合并,暴露 click 点击事件
21
+
1
22
  ## 3.8.125
2
23
  fix: 修复签名组件在 App 端无法绘制、笔迹画出后闪退的问题
3
24
 
@@ -0,0 +1,10 @@
1
+ export default {
2
+ // flex
3
+ flex: {
4
+ direction: 'row',
5
+ justify: 'flex-start',
6
+ align: 'stretch',
7
+ wrap: false,
8
+ gap: 0
9
+ }
10
+ }
@@ -0,0 +1,34 @@
1
+ import { defineMixin } from '../../libs/vue'
2
+ import FlexDefaultProps from './flex'
3
+ import { registerComponentProps } from '../../libs/config/props.js'
4
+
5
+ const defProps = registerComponentProps(FlexDefaultProps)
6
+ export const props = defineMixin({
7
+ props: {
8
+ // 主轴方向 row/column/row-reverse/column-reverse
9
+ direction: {
10
+ type: String,
11
+ default: () => defProps.flex.direction
12
+ },
13
+ // 主轴对齐 flex-start/flex-end/center/space-between/space-around/space-evenly(兼容 start/end)
14
+ justify: {
15
+ type: String,
16
+ default: () => defProps.flex.justify
17
+ },
18
+ // 交叉轴对齐 flex-start/flex-end/center/stretch/baseline
19
+ align: {
20
+ type: String,
21
+ default: () => defProps.flex.align
22
+ },
23
+ // 是否换行
24
+ wrap: {
25
+ type: Boolean,
26
+ default: () => defProps.flex.wrap
27
+ },
28
+ // 子元素间距,单位任意
29
+ gap: {
30
+ type: [String, Number],
31
+ default: () => defProps.flex.gap
32
+ }
33
+ }
34
+ })
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <view
3
+ class="u-flex"
4
+ :style="[flexStyle]"
5
+ @tap="clickHandler"
6
+ >
7
+ <slot />
8
+ </view>
9
+ </template>
10
+
11
+ <script>
12
+ import { props } from './props';
13
+ import { mpMixin } from '../../libs/mixin/mpMixin';
14
+ import { mixin } from '../../libs/mixin/mixin';
15
+ import { addUnit, addStyle, deepMerge } from '../../libs/function/index';
16
+ /**
17
+ * Flex 通用弹性布局容器
18
+ * @description 通用 flexbox 容器,跨端同名同默认,作为页面 view 的原生落点
19
+ * @property {String} direction 主轴方向 row/column/row-reverse/column-reverse (默认 'row')
20
+ * @property {String} justify 主轴对齐 (默认 'flex-start')
21
+ * @property {String} align 交叉轴对齐 (默认 'stretch')
22
+ * @property {Boolean} wrap 是否换行 (默认 false)
23
+ * @property {String | Number} gap 子元素间距,单位任意 (默认 0)
24
+ * @property {Object} customStyle 定义需要用到的外部样式
25
+ * @event {Function} click 组件被点击
26
+ * @example <up-flex direction="column" gap="16">...</up-flex>
27
+ */
28
+ export default {
29
+ name: "u-flex",
30
+ mixins: [mpMixin, mixin, props],
31
+ emits: ["click"],
32
+ computed: {
33
+ uJustify() {
34
+ if (this.justify === 'start' || this.justify === 'end') return 'flex-' + this.justify
35
+ return this.justify
36
+ },
37
+ flexStyle() {
38
+ const style = {
39
+ display: 'flex',
40
+ flexDirection: this.direction,
41
+ justifyContent: this.uJustify,
42
+ alignItems: this.align,
43
+ flexWrap: this.wrap ? 'wrap' : 'nowrap'
44
+ }
45
+ if (this.gap && Number(this.gap) !== 0) {
46
+ style.gap = addUnit(this.gap)
47
+ }
48
+ return deepMerge(style, addStyle(this.customStyle))
49
+ }
50
+ },
51
+ methods: {
52
+ clickHandler() {
53
+ this.$emit('click')
54
+ }
55
+ }
56
+ }
57
+ </script>
58
+
59
+ <style lang="scss" scoped>
60
+ .u-flex {
61
+ display: flex;
62
+ }
63
+ </style>
@@ -73,6 +73,10 @@
73
73
  init() {
74
74
  // 初始化数据
75
75
  this.updateParentData()
76
+ // 父组件未找到或 children 尚未初始化时跳过,避免 indexOf 报错
77
+ if (!this.parent || !this.parent.children) {
78
+ return
79
+ }
76
80
  this.index = this.parent.children.indexOf(this)
77
81
  this.resize()
78
82
  },
@@ -187,6 +187,9 @@
187
187
  }
188
188
  },
189
189
  mounted() {
190
+ // 抖音小程序等平台子组件 created 可能在父组件 created 之前执行,
191
+ // 此时 parent.children 尚未初始化,init 被跳过,此处补偿重试
192
+ this.init()
190
193
  this.parent && this.parent.updateFromChild()
191
194
  sleep().then(() => {
192
195
  this.getStepsItemRect()
@@ -199,6 +202,12 @@
199
202
  if (!this.parent) {
200
203
  return error('u-steps-item必须要搭配u-steps组件使用')
201
204
  }
205
+ // 抖音小程序等平台子组件 created 可能在父组件 created 之前执行,
206
+ // 此时 parent.children 尚未初始化(u-steps 在 created 中才赋值 children=[]),
207
+ // 跳过本次初始化,由 mounted 钩子补偿重试
208
+ if (!this.parent.children) {
209
+ return
210
+ }
202
211
  this.index = this.parent.children.indexOf(this)
203
212
  this.childLength = this.parent.children.length
204
213
  },
@@ -239,6 +239,9 @@
239
239
  this.init()
240
240
  },
241
241
  mounted() {
242
+ // 抖音小程序等平台子组件 created 可能在父组件 created 之前执行,
243
+ // 此时 parent.children 尚未初始化,init 被跳过,此处补偿重试
244
+ this.init()
242
245
  this.scheduleMidButtonBorderMeasure()
243
246
  },
244
247
  watch: {
@@ -260,6 +263,13 @@
260
263
  this.updateParentData()
261
264
  if (!this.parent) {
262
265
  error('up-tabbar-item必须搭配up-tabbar组件使用')
266
+ return
267
+ }
268
+ // 抖音小程序等平台子组件 created 可能在父组件 created 之前执行,
269
+ // 此时 parent.children 尚未初始化(u-tabbar 在 created 中才赋值 children=[]),
270
+ // 跳过本次初始化,由 mounted 钩子补偿重试
271
+ if (!this.parent.children) {
272
+ return
263
273
  }
264
274
  // 本子组件在u-tabbar的children数组中的索引
265
275
  const index = this.parent.children.indexOf(this)
@@ -299,10 +309,11 @@
299
309
  },
300
310
  clickHandler() {
301
311
  this.$nextTick(() => {
312
+ if (!this.parent || !this.parent.children) return
302
313
  const index = this.parent.children.indexOf(this)
303
314
  const name = this.name || index
304
315
  // 点击的item为非激活的item才发出change事件
305
- if (name !== this.parent.value) {
316
+ if (this.parent && name !== this.parent.value) {
306
317
  this.parent.$emit('change', name)
307
318
  }
308
319
  this.$emit('click', name)
@@ -42,6 +42,7 @@ const componentKeys = [
42
42
  'dropdown',
43
43
  'dropdownItem',
44
44
  'empty',
45
+ 'flex',
45
46
  'form',
46
47
  'formItem',
47
48
  'gap',
@@ -227,7 +227,7 @@ export const mixin = defineMixin({
227
227
  // 之所以需要这么做,是因为所有端中,头条小程序不支持通过this.parent.xxx去监听父组件参数的变化
228
228
  // 此处并不会自动更新子组件的数据,而是依赖父组件u-radio-group去监听data的变化,手动调用更新子组件的方法去重新获取
229
229
  this.parent = $parent.call(this, parentName)
230
- if (this.parent.children) {
230
+ if (this.parent && this.parent.children) {
231
231
  // 如果父组件的children不存在本组件的实例,才将本实例添加到父组件的children中
232
232
  this.parent.children.indexOf(this) === -1 && this.parent.children.push(this)
233
233
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "uview-plus",
3
3
  "name": "uview-plus",
4
4
  "displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙跨端移动组件库,组件丰富维护更新稳定。",
5
- "version": "3.8.125",
5
+ "version": "3.8.127",
6
6
  "description": "零云®uview-plus已兼容vue3支持多语言,120+全面的组件和便捷的工具会让您信手拈来。近期新增拖动排序、条码、图片裁剪、下拉刷新、虚拟列表、签名、Markdown等。",
7
7
  "keywords": [
8
8
  "uview",