uview-pro 0.2.4 → 0.3.0

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.
Files changed (162) hide show
  1. package/changelog.md +29 -0
  2. package/components/u-action-sheet/types.ts +2 -0
  3. package/components/u-action-sheet/u-action-sheet.vue +15 -4
  4. package/components/u-alert-tips/types.ts +2 -0
  5. package/components/u-alert-tips/u-alert-tips.vue +24 -9
  6. package/components/u-avatar/types.ts +2 -0
  7. package/components/u-avatar/u-avatar.vue +15 -5
  8. package/components/u-avatar-cropper/u-avatar-cropper.vue +13 -2
  9. package/components/u-back-top/types.ts +2 -5
  10. package/components/u-back-top/u-back-top.vue +27 -15
  11. package/components/u-badge/types.ts +2 -0
  12. package/components/u-badge/u-badge.vue +33 -15
  13. package/components/u-button/types.ts +2 -2
  14. package/components/u-button/u-button.vue +23 -10
  15. package/components/u-car-keyboard/types.ts +2 -0
  16. package/components/u-car-keyboard/u-car-keyboard.vue +14 -5
  17. package/components/u-card/types.ts +2 -0
  18. package/components/u-card/u-card.vue +25 -10
  19. package/components/u-cell-group/types.ts +2 -0
  20. package/components/u-cell-group/u-cell-group.vue +15 -5
  21. package/components/u-cell-item/types.ts +2 -0
  22. package/components/u-cell-item/u-cell-item.vue +24 -11
  23. package/components/u-checkbox/types.ts +2 -0
  24. package/components/u-checkbox/u-checkbox.vue +12 -13
  25. package/components/u-checkbox-group/types.ts +2 -0
  26. package/components/u-checkbox-group/u-checkbox-group.vue +1 -1
  27. package/components/u-circle-progress/types.ts +2 -0
  28. package/components/u-circle-progress/u-circle-progress.vue +24 -9
  29. package/components/u-city-select/types.ts +2 -0
  30. package/components/u-city-select/u-city-select.vue +16 -4
  31. package/components/u-col/types.ts +2 -0
  32. package/components/u-col/u-col.vue +27 -8
  33. package/components/u-collapse/u-collapse.vue +8 -4
  34. package/components/u-collapse-item/u-collapse-item.vue +32 -27
  35. package/components/u-column-notice/types.ts +2 -0
  36. package/components/u-column-notice/u-column-notice.vue +16 -4
  37. package/components/u-count-down/types.ts +2 -0
  38. package/components/u-count-down/u-count-down.vue +20 -8
  39. package/components/u-count-to/types.ts +2 -0
  40. package/components/u-count-to/u-count-to.vue +25 -7
  41. package/components/u-divider/types.ts +2 -0
  42. package/components/u-divider/u-divider.vue +26 -10
  43. package/components/u-dropdown/types.ts +2 -0
  44. package/components/u-dropdown/u-dropdown.vue +48 -20
  45. package/components/u-dropdown-item/types.ts +2 -0
  46. package/components/u-dropdown-item/u-dropdown-item.vue +33 -41
  47. package/components/u-empty/types.ts +2 -0
  48. package/components/u-empty/u-empty.vue +20 -5
  49. package/components/u-field/types.ts +2 -0
  50. package/components/u-field/u-field.vue +18 -3
  51. package/components/u-form/types.ts +2 -0
  52. package/components/u-form/u-form.vue +20 -26
  53. package/components/u-form-item/types.ts +2 -0
  54. package/components/u-form-item/u-form-item.vue +67 -67
  55. package/components/u-full-screen/types.ts +2 -0
  56. package/components/u-full-screen/u-full-screen.vue +16 -2
  57. package/components/u-gap/types.ts +2 -0
  58. package/components/u-gap/u-gap.vue +15 -5
  59. package/components/u-grid/types.ts +2 -0
  60. package/components/u-grid/u-grid.vue +23 -25
  61. package/components/u-grid-item/types.ts +3 -3
  62. package/components/u-grid-item/u-grid-item.vue +43 -47
  63. package/components/u-icon/types.ts +0 -1
  64. package/components/u-icon/u-icon.vue +5 -3
  65. package/components/u-image/u-image.vue +13 -4
  66. package/components/u-index-anchor/types.ts +3 -3
  67. package/components/u-index-anchor/u-index-anchor.vue +18 -10
  68. package/components/u-index-list/u-index-list.vue +9 -12
  69. package/components/u-input/types.ts +2 -5
  70. package/components/u-input/u-input.vue +15 -6
  71. package/components/u-keyboard/u-keyboard.vue +13 -4
  72. package/components/u-lazy-load/u-lazy-load.vue +13 -2
  73. package/components/u-line/u-line.vue +13 -4
  74. package/components/u-line-progress/u-line-progress.vue +13 -4
  75. package/components/u-link/u-link.vue +13 -4
  76. package/components/u-loading/u-loading.vue +13 -4
  77. package/components/u-loading-popup/u-loading-popup.vue +14 -0
  78. package/components/u-loadmore/u-loadmore.vue +13 -2
  79. package/components/u-mask/types.ts +2 -5
  80. package/components/u-mask/u-mask.vue +21 -14
  81. package/components/u-message-input/u-message-input.vue +13 -2
  82. package/components/u-modal/u-modal.vue +13 -4
  83. package/components/u-navbar/u-navbar.vue +13 -2
  84. package/components/u-no-network/u-no-network.vue +13 -2
  85. package/components/u-notice-bar/u-notice-bar.vue +13 -3
  86. package/components/u-number-box/u-number-box.vue +13 -4
  87. package/components/u-number-keyboard/u-number-keyboard.vue +13 -4
  88. package/components/u-picker/u-picker.vue +13 -4
  89. package/components/u-popup/types.ts +2 -2
  90. package/components/u-popup/u-popup.vue +15 -5
  91. package/components/u-radio/types.ts +2 -0
  92. package/components/u-radio/u-radio.vue +26 -19
  93. package/components/u-radio-group/types.ts +2 -0
  94. package/components/u-radio-group/u-radio-group.vue +20 -32
  95. package/components/u-rate/types.ts +2 -0
  96. package/components/u-rate/u-rate.vue +20 -5
  97. package/components/u-read-more/types.ts +2 -0
  98. package/components/u-read-more/u-read-more.vue +23 -7
  99. package/components/u-root-portal/u-root-portal.vue +3 -1
  100. package/components/u-row/types.ts +2 -0
  101. package/components/u-row/u-row.vue +29 -11
  102. package/components/u-row-notice/types.ts +2 -0
  103. package/components/u-row-notice/u-row-notice.vue +16 -4
  104. package/components/u-safe-bottom/u-safe-bottom.vue +13 -2
  105. package/components/u-search/types.ts +2 -0
  106. package/components/u-search/u-search.vue +16 -5
  107. package/components/u-section/types.ts +2 -0
  108. package/components/u-section/u-section.vue +31 -12
  109. package/components/u-select/types.ts +2 -0
  110. package/components/u-select/u-select.vue +15 -5
  111. package/components/u-skeleton/types.ts +2 -0
  112. package/components/u-skeleton/u-skeleton.vue +14 -3
  113. package/components/u-slider/types.ts +2 -0
  114. package/components/u-slider/u-slider.vue +27 -19
  115. package/components/u-status-bar/u-status-bar.vue +13 -4
  116. package/components/u-steps/types.ts +2 -0
  117. package/components/u-steps/u-steps.vue +15 -3
  118. package/components/u-sticky/types.ts +2 -0
  119. package/components/u-sticky/u-sticky.vue +23 -7
  120. package/components/u-subsection/types.ts +2 -0
  121. package/components/u-subsection/u-subsection.vue +14 -3
  122. package/components/u-swipe-action/types.ts +2 -0
  123. package/components/u-swipe-action/u-swipe-action.vue +19 -3
  124. package/components/u-swiper/types.ts +2 -0
  125. package/components/u-swiper/u-swiper.vue +19 -2
  126. package/components/u-switch/types.ts +2 -0
  127. package/components/u-switch/u-switch.vue +15 -6
  128. package/components/u-tabbar/types.ts +2 -0
  129. package/components/u-tabbar/u-tabbar.vue +20 -3
  130. package/components/u-table/types.ts +2 -0
  131. package/components/u-table/u-table.vue +15 -3
  132. package/components/u-tabs/types.ts +2 -0
  133. package/components/u-tabs/u-tabs.vue +14 -3
  134. package/components/u-tabs-swiper/types.ts +2 -0
  135. package/components/u-tabs-swiper/u-tabs-swiper.vue +15 -3
  136. package/components/u-tag/types.ts +2 -0
  137. package/components/u-tag/u-tag.vue +22 -6
  138. package/components/u-td/types.ts +2 -0
  139. package/components/u-td/u-td.vue +14 -3
  140. package/components/u-text/u-text.vue +4 -2
  141. package/components/u-th/types.ts +2 -0
  142. package/components/u-th/u-th.vue +14 -3
  143. package/components/u-time-line/u-time-line.vue +17 -3
  144. package/components/u-time-line-item/types.ts +2 -0
  145. package/components/u-time-line-item/u-time-line-item.vue +15 -3
  146. package/components/u-toast/types.ts +2 -0
  147. package/components/u-toast/u-toast.vue +15 -8
  148. package/components/u-top-tips/types.ts +2 -0
  149. package/components/u-top-tips/u-top-tips.vue +20 -3
  150. package/components/u-tr/types.ts +4 -1
  151. package/components/u-tr/u-tr.vue +17 -2
  152. package/components/u-upload/types.ts +2 -0
  153. package/components/u-upload/u-upload.vue +14 -5
  154. package/components/u-verification-code/types.ts +2 -0
  155. package/components/u-verification-code/u-verification-code.vue +15 -3
  156. package/components/u-waterfall/types.ts +2 -0
  157. package/components/u-waterfall/u-waterfall.vue +15 -3
  158. package/libs/hooks/index.ts +2 -1
  159. package/libs/hooks/useCompRelation.ts +364 -0
  160. package/libs/index.ts +56 -39
  161. package/package.json +1 -1
  162. package/readme.md +6 -6
@@ -1,11 +1,13 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
2
  import type { ThemeType } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * u-divider 分割线 Props
6
7
  * @description 区隔内容的分割线,一般用于页面底部"没有更多"的提示。
7
8
  */
8
9
  export const DividerProps = {
10
+ ...baseProps,
9
11
  /** 单一边divider横线的宽度(数值),单位rpx。或者百分比 */
10
12
  halfWidth: { type: [Number, String] as PropType<number | string>, default: 150 },
11
13
  /** divider横线的颜色,如设置 */
@@ -1,12 +1,18 @@
1
1
  <template>
2
2
  <view
3
3
  class="u-divider"
4
- :style="{
5
- height: height === 'auto' ? 'auto' : height + 'rpx',
6
- backgroundColor: bgColor,
7
- marginBottom: marginBottom + 'rpx',
8
- marginTop: marginTop + 'rpx'
9
- }"
4
+ :class="customClass"
5
+ :style="
6
+ $u.toStyle(
7
+ {
8
+ height: height === 'auto' ? 'auto' : height + 'rpx',
9
+ backgroundColor: bgColor,
10
+ marginBottom: marginBottom + 'rpx',
11
+ marginTop: marginTop + 'rpx'
12
+ },
13
+ customStyle
14
+ )
15
+ "
10
16
  @tap="onClick"
11
17
  >
12
18
  <view
@@ -31,13 +37,23 @@
31
37
  </view>
32
38
  </template>
33
39
 
40
+ <script lang="ts">
41
+ export default {
42
+ name: 'u-divider',
43
+ options: {
44
+ addGlobalClass: true,
45
+ // #ifndef MP-TOUTIAO
46
+ virtualHost: true,
47
+ // #endif
48
+ styleIsolation: 'shared'
49
+ }
50
+ };
51
+ </script>
52
+
34
53
  <script setup lang="ts">
35
54
  import { computed } from 'vue';
36
55
  import { DividerProps } from './types';
37
-
38
- defineOptions({
39
- name: 'u-divider'
40
- });
56
+ import { $u } from '../../';
41
57
 
42
58
  /**
43
59
  * divider 分割线
@@ -1,10 +1,12 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
+ import { baseProps } from '../common/props';
2
3
 
3
4
  /**
4
5
  * u-dropdown 下拉菜单 Props
5
6
  * @description 该组件一般用于向下展开菜单,同时可切换多个选项卡的场景
6
7
  */
7
8
  export const DropdownProps = {
9
+ ...baseProps,
8
10
  /** 菜单标题和选项的激活态颜色 */
9
11
  activeColor: { type: String, default: '#2979ff' },
10
12
  /** 菜单标题和选项的未激活态颜色 */
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="u-dropdown">
2
+ <view class="u-dropdown" :style="$u.toStyle(styles, customStyle)" :class="customClass">
3
3
  <view
4
4
  class="u-dropdown__menu"
5
5
  :style="{ height: $u.addUnit(height) }"
@@ -61,13 +61,24 @@
61
61
  </view>
62
62
  </template>
63
63
 
64
+ <script lang="ts">
65
+ export default {
66
+ name: 'u-dropdown',
67
+ options: {
68
+ addGlobalClass: true,
69
+ // #ifndef MP-TOUTIAO
70
+ virtualHost: true,
71
+ // #endif
72
+ styleIsolation: 'shared'
73
+ }
74
+ };
75
+ </script>
76
+
64
77
  <script setup lang="ts">
65
- import { ref, computed, onMounted, getCurrentInstance } from 'vue';
66
- import { $u } from '../..';
78
+ import { ref, computed, onMounted, getCurrentInstance, nextTick } from 'vue';
79
+ import { $u, useParent } from '../..';
67
80
  import { DropdownProps } from './types';
68
81
 
69
- defineOptions({ name: 'u-dropdown' });
70
-
71
82
  /**
72
83
  * dropdown 下拉菜单
73
84
  * @description 该组件一般用于向下展开菜单,同时可切换多个选项卡的场景
@@ -87,14 +98,11 @@ defineOptions({ name: 'u-dropdown' });
87
98
  */
88
99
 
89
100
  const props = defineProps(DropdownProps);
90
-
91
- // emits 定义
92
101
  const emit = defineEmits(['open', 'close']);
93
102
 
103
+ const { children } = useParent('u-dropdown');
94
104
  // 菜单列表
95
105
  const menuList = ref<any[]>([]);
96
- // 是否打开下拉菜单
97
- const showDropdown = ref(true);
98
106
  // 下拉菜单的状态
99
107
  const active = ref(false);
100
108
  // 当前激活菜单索引
@@ -108,9 +116,15 @@ const highlightIndex = ref<number>(99999);
108
116
  // 下拉内容高度
109
117
  const contentHeight = ref<number>(0);
110
118
  // 子组件引用
111
- // 引用所有子组件(u-dropdown-item)的this,不能在data中声明变量,否则在微信小程序会造成循环引用而报错
112
- const children = ref<any[]>([]);
113
119
  const instance = getCurrentInstance();
120
+ // 兼容头条样式
121
+ const styles = computed(() => {
122
+ const style: any = {};
123
+ // #ifdef MP-TOUTIAO
124
+ style.width = '100vw';
125
+ // #endif
126
+ return style;
127
+ });
114
128
 
115
129
  // 下拉出来部分的样式
116
130
  const popupStyle = computed<any>(() => {
@@ -127,9 +141,6 @@ onMounted(() => {
127
141
  getContentHeight();
128
142
  });
129
143
 
130
- // 引用所有子组件(u-dropdown-item)的this,不能在data中声明变量,否则在微信小程序会造成循环引用而报错
131
- children.value = [];
132
-
133
144
  /**
134
145
  * 初始化所有子组件
135
146
  * 当某个子组件内容变化时,触发父组件的init,父组件再让每一个子组件重新初始化一遍
@@ -137,8 +148,11 @@ children.value = [];
137
148
  */
138
149
  function init() {
139
150
  menuList.value = [];
140
- children.value.forEach(child => {
141
- child.init && child.init();
151
+ children.forEach(child => {
152
+ menuList.value.push({
153
+ title: child?.getExposed()?.props.title ?? '',
154
+ disabled: child?.getExposed()?.props.disabled ?? false
155
+ });
142
156
  });
143
157
  }
144
158
 
@@ -154,7 +168,7 @@ function menuClick(index: number) {
154
168
  close();
155
169
  // 等动画结束后,再移除下拉菜单中的内容,否则直接移除,也就没有下拉菜单收起的效果了
156
170
  setTimeout(() => {
157
- if (children.value[index]) children.value[index].active = false;
171
+ if (children[index]) children[index]?.getExposed()?.setActive(false);
158
172
  }, Number(props.duration));
159
173
  return;
160
174
  }
@@ -177,8 +191,8 @@ function open(index: number) {
177
191
  current.value = index;
178
192
  // 历遍所有的子元素,将索引匹配的项标记为激活状态,因为子元素是通过v-if控制切换的
179
193
  // 之所以不是因display: none,是因为nvue没有display这个属性
180
- children.value.forEach((val, idx) => {
181
- val.exposed.setActive && val.exposed.setActive(index == idx ? true : false);
194
+ children.forEach((child, idx) => {
195
+ child?.getExposed()?.setActive(index == idx ? true : false);
182
196
  });
183
197
  emit('open', current.value);
184
198
  }
@@ -230,8 +244,22 @@ function getContentHeight() {
230
244
  });
231
245
  }
232
246
 
247
+ onMounted(() => {
248
+ nextTick(() => {
249
+ init();
250
+ });
251
+ });
252
+
233
253
  // 暴露方法
234
- defineExpose({ init, close, open, highlight, getContentHeight, children, menuList });
254
+ defineExpose({
255
+ init,
256
+ close,
257
+ open,
258
+ highlight,
259
+ getContentHeight,
260
+ children,
261
+ menuList
262
+ });
235
263
  </script>
236
264
 
237
265
  <style scoped lang="scss">
@@ -1,5 +1,6 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
2
  import type { OptionType } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * u-dropdown-item 下拉菜单项 Props
@@ -12,6 +13,7 @@ import type { OptionType } from '../../types/global';
12
13
  */
13
14
 
14
15
  export const DropdownItemProps = {
16
+ ...baseProps,
15
17
  /** 当前选中项的value值 */
16
18
  modelValue: { type: [Number, String, Array] as PropType<number | string | any[]>, default: '' },
17
19
  /** 菜单项标题 */
@@ -1,5 +1,12 @@
1
1
  <template>
2
- <view class="u-dropdown-item" v-if="active" @touchmove.stop.prevent @tap.stop.prevent>
2
+ <view
3
+ v-if="active"
4
+ class="u-dropdown-item"
5
+ :class="customClass"
6
+ :style="$u.toStyle(customStyle)"
7
+ @touchmove.stop.prevent
8
+ @tap.stop.prevent
9
+ >
3
10
  <block v-if="!slots.default && !slots.$default">
4
11
  <scroll-view scroll-y="true" :style="{ height: $u.addUnit(height) }">
5
12
  <view class="u-dropdown-item__options">
@@ -27,13 +34,24 @@
27
34
  </view>
28
35
  </template>
29
36
 
37
+ <script lang="ts">
38
+ export default {
39
+ name: 'u-dropdown-item',
40
+ options: {
41
+ addGlobalClass: true,
42
+ // #ifndef MP-TOUTIAO
43
+ virtualHost: true,
44
+ // #endif
45
+ styleIsolation: 'shared'
46
+ }
47
+ };
48
+ </script>
49
+
30
50
  <script setup lang="ts">
31
- import { ref, computed, onMounted, getCurrentInstance, useSlots, watch } from 'vue';
32
- import { $u } from '../..';
51
+ import { ref, computed, useSlots, watch } from 'vue';
52
+ import { $u, useChildren } from '../..';
33
53
  import { DropdownItemProps } from './types';
34
54
 
35
- defineOptions({ name: 'u-dropdown-item' });
36
-
37
55
  /**
38
56
  * dropdown-item 下拉菜单
39
57
  * @description 该组件一般用于向下展开菜单,同时可切换多个选项卡的场景
@@ -56,49 +74,23 @@ const emit = defineEmits(['update:modelValue', 'change']);
56
74
  // 插槽
57
75
  const slots = useSlots();
58
76
 
77
+ const { parentExposed, emitToParent } = useChildren('u-dropdown-item', 'u-dropdown');
78
+
59
79
  // 当前项是否处于展开状态
60
80
  const active = ref(false);
61
81
  // 激活时左边文字和右边对勾图标的颜色
62
- const activeColor = ref<string>('#2979ff');
82
+ const activeColor = computed(() => parentExposed.value?.activeColor || $u.color.primary);
63
83
  // 未激活时左边文字和右边对勾图标的颜色
64
- const inactiveColor = ref<string>('#606266');
65
- // 父组件实例
66
- const parent = ref<any>(null);
84
+ const inactiveColor = computed(() => parentExposed.value?.inactiveColor || $u.color.contentColor);
67
85
 
68
86
  // 监听props变化,通知父组件重新初始化
69
87
  const propsChange = computed(() => `${props.title}-${props.disabled}`);
70
88
 
71
89
  // 监听propsChange变化,通知父组件重新init
72
90
  watch(propsChange, () => {
73
- if (parent.value && parent.value.init) parent.value.init();
91
+ emitToParent('init');
74
92
  });
75
93
 
76
- /**
77
- * 初始化本组件,注册到父组件
78
- */
79
- function init() {
80
- // 获取父组件u-dropdown
81
- const instance = getCurrentInstance();
82
- if (!instance) return;
83
- const parentComp = $u.$parent('u-dropdown');
84
- if (parentComp && parentComp.proxy) {
85
- const parentProxy = parentComp.proxy as any;
86
- parent.value = parentComp;
87
- // 继承父组件的激活/未激活颜色
88
- activeColor.value = parentProxy.activeColor;
89
- inactiveColor.value = parentProxy.inactiveColor;
90
- // 注册到父组件children
91
- // 将本组件的this,放入到父组件的children数组中,让父组件可以操作本(子)组件的方法和属性
92
- // push进去前,显判断是否已经存在了本实例,因为在子组件内部数据变化时,会通过父组件重新初始化子组件
93
- const exist = parentComp?.exposed?.children.value.find((val: any) => val === instance);
94
- if (!exist) parentComp?.exposed?.children.value.push(instance);
95
- if (parentComp?.exposed?.children.value.length === 1) active.value = true;
96
- // 向父组件menuList注册本项
97
- // 父组件无法监听children的变化,故将子组件的title,传入父组件的menuList数组中
98
- parentComp?.exposed?.menuList.value.push({ title: props.title, disabled: props.disabled });
99
- }
100
- }
101
-
102
94
  /**
103
95
  * cell被点击
104
96
  * @param value 选中值
@@ -107,7 +99,7 @@ function cellClick(value: string | number | any) {
107
99
  // 修改通过v-model绑定的值
108
100
  emit('update:modelValue', value);
109
101
  // 通知父组件(u-dropdown)收起菜单
110
- parent.value?.exposed?.close();
102
+ emitToParent('close');
111
103
  // 发出事件,抛出当前勾选项的value
112
104
  emit('change', value);
113
105
  }
@@ -116,11 +108,11 @@ function setActive(value: boolean) {
116
108
  active.value = value;
117
109
  }
118
110
 
119
- onMounted(() => {
120
- init();
111
+ defineExpose({
112
+ cellClick,
113
+ setActive,
114
+ props
121
115
  });
122
-
123
- defineExpose({ init, cellClick, setActive });
124
116
  </script>
125
117
 
126
118
  <style scoped lang="scss">
@@ -1,9 +1,11 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
+ import { baseProps } from '../common/props';
2
3
 
3
4
  /**
4
5
  * u-empty 组件 Props 类型定义
5
6
  */
6
7
  export const EmptyProps = {
8
+ ...baseProps,
7
9
  /** 图标路径 */
8
10
  src: { type: String, default: '' },
9
11
  /** 提示文字 */
@@ -1,5 +1,10 @@
1
1
  <template>
2
- <view class="u-empty" v-if="show" :style="{ marginTop: marginTop + 'rpx' }">
2
+ <view
3
+ v-if="show"
4
+ class="u-empty"
5
+ :class="customClass"
6
+ :style="$u.toStyle({ marginTop: marginTop + 'rpx' }, customStyle)"
7
+ >
3
8
  <u-icon
4
9
  :name="src ? src : 'empty-' + mode"
5
10
  :custom-style="iconStyle"
@@ -17,12 +22,22 @@
17
22
  </view>
18
23
  </template>
19
24
 
25
+ <script lang="ts">
26
+ export default {
27
+ name: 'u-empty',
28
+ options: {
29
+ addGlobalClass: true,
30
+ // #ifndef MP-TOUTIAO
31
+ virtualHost: true,
32
+ // #endif
33
+ styleIsolation: 'shared'
34
+ }
35
+ };
36
+ </script>
37
+
20
38
  <script setup lang="ts">
21
39
  import { EmptyProps } from './types';
22
-
23
- defineOptions({
24
- name: 'u-empty'
25
- });
40
+ import { $u } from '../../';
26
41
 
27
42
  /**
28
43
  * empty 内容为空
@@ -1,11 +1,13 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
2
  import type { InputAlign, InputConfirmType, InputLabelPosition, InputType } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * u-field 组件 Props 类型定义
6
7
  * @description 表单输入框属性
7
8
  */
8
9
  export const FieldProps = {
10
+ ...baseProps,
9
11
  /** label左边的图标,限uView的图标名称 */
10
12
  icon: String,
11
13
  /** 输入框右边的图标名称,限uView的图标名称(默认false) */
@@ -1,5 +1,9 @@
1
1
  <template>
2
- <view class="u-field" :class="{ 'u-border-top': props.borderTop, 'u-border-bottom': props.borderBottom }">
2
+ <view
3
+ class="u-field"
4
+ :class="[{ 'u-border-top': props.borderTop, 'u-border-bottom': props.borderBottom }, customClass]"
5
+ :style="$u.toStyle(customStyle)"
6
+ >
3
7
  <view
4
8
  class="u-field-inner"
5
9
  :class="[props.type === 'textarea' ? 'u-textarea-inner' : '', 'u-label-postion-' + props.labelPosition]"
@@ -97,13 +101,24 @@
97
101
  </view>
98
102
  </template>
99
103
 
104
+ <script lang="ts">
105
+ export default {
106
+ name: 'u-field',
107
+ options: {
108
+ addGlobalClass: true,
109
+ // #ifndef MP-TOUTIAO
110
+ virtualHost: true,
111
+ // #endif
112
+ styleIsolation: 'shared'
113
+ }
114
+ };
115
+ </script>
116
+
100
117
  <script setup lang="ts">
101
118
  import { FieldProps } from './types';
102
119
  import { ref, computed } from 'vue';
103
120
  import { $u } from '../..';
104
121
 
105
- defineOptions({ name: 'u-field' });
106
-
107
122
  /**
108
123
  * field 输入框
109
124
  * @description 借助此组件,可以实现表单的输入, 有"text"和"textarea"类型的,此外,借助uView的picker和actionSheet组件可以快速实现上拉菜单,时间,地区选择等, 为表单解决方案的利器。
@@ -1,11 +1,13 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
2
  import type { FormRules, InputAlign, FormErrorType, InputLabelPosition } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * u-form 组件 Props 类型定义
6
7
  * @description 表单组件属性
7
8
  */
8
9
  export const FormProps = {
10
+ ...baseProps,
9
11
  /** 当前form的需要验证字段的集合 */
10
12
  model: { type: Object as PropType<Record<string, any>>, default: () => ({}) },
11
13
  /** 表单验证规则 */
@@ -1,15 +1,26 @@
1
1
  <template>
2
- <view class="u-form"><slot /></view>
2
+ <view class="u-form" :class="customClass" :style="$u.toStyle(customStyle)">
3
+ <slot />
4
+ </view>
3
5
  </template>
4
6
 
7
+ <script lang="ts">
8
+ export default {
9
+ name: 'u-form',
10
+ options: {
11
+ addGlobalClass: true,
12
+ // #ifndef MP-TOUTIAO
13
+ virtualHost: true,
14
+ // #endif
15
+ styleIsolation: 'shared'
16
+ }
17
+ };
18
+ </script>
19
+
5
20
  <script setup lang="ts">
6
21
  import { FormProps } from './types';
7
- import { ref, provide } from 'vue';
8
- import { $u } from '../..';
9
-
10
- defineOptions({
11
- name: 'u-form'
12
- });
22
+ import { ref } from 'vue';
23
+ import { $u, useParent } from '../..';
13
24
 
14
25
  /**
15
26
  * form 表单
@@ -28,31 +39,14 @@ defineOptions({
28
39
 
29
40
  const props = defineProps(FormProps);
30
41
 
42
+ useParent('u-form');
43
+
31
44
  // 存储当前form下的所有u-form-item的实例
32
45
  const fields = ref<any[]>([]);
33
46
 
34
47
  // 校验规则
35
48
  const rules = ref<Record<string, any>>(props.rules);
36
49
 
37
- // 提供 uForm 实例给子组件(注册方法供 u-form-item 调用)
38
- const uForm = {
39
- addField(field: any) {
40
- if (!fields.value.includes(field)) fields.value.push(field);
41
- },
42
- removeField(field: any) {
43
- fields.value = fields.value.filter(f => f !== field);
44
- },
45
- // 兼容老用法
46
- setRules,
47
- resetFields,
48
- validate,
49
- fields,
50
- rules,
51
- props,
52
- model: props.model
53
- };
54
- provide('u-form', uForm);
55
-
56
50
  /**
57
51
  * 设置校验规则
58
52
  * @param newRules 校验规则对象
@@ -1,10 +1,12 @@
1
1
  import type { PropType, ExtractPropTypes } from 'vue';
2
2
  import type { InputAlign, InputLabelPosition } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * form-item 表单item Props
6
7
  */
7
8
  export const FormItemProps = {
9
+ ...baseProps,
8
10
  /** input的label提示语 */
9
11
  label: {
10
12
  type: String,