uview-plus 3.2.8 → 3.2.9

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 (119) hide show
  1. package/changelog.md +5 -0
  2. package/components/u--form/u--form.vue +7 -7
  3. package/components/u--image/u--image.vue +3 -3
  4. package/components/u--input/u--input.vue +9 -9
  5. package/components/u--textarea/u--textarea.vue +3 -3
  6. package/components/u-action-sheet/u-action-sheet.vue +5 -4
  7. package/components/u-album/u-album.vue +9 -7
  8. package/components/u-alert/u-alert.vue +9 -6
  9. package/components/u-avatar/props.js +2 -1
  10. package/components/u-avatar/u-avatar.vue +15 -11
  11. package/components/u-avatar-group/u-avatar-group.vue +9 -5
  12. package/components/u-back-top/u-back-top.vue +9 -8
  13. package/components/u-badge/u-badge.vue +10 -6
  14. package/components/u-button/u-button.vue +13 -9
  15. package/components/u-calendar/header.vue +3 -3
  16. package/components/u-calendar/month.vue +17 -15
  17. package/components/u-calendar/u-calendar.vue +10 -8
  18. package/components/u-car-keyboard/u-car-keyboard.vue +7 -6
  19. package/components/u-cell/u-cell.vue +9 -6
  20. package/components/u-cell-group/u-cell-group.vue +8 -4
  21. package/components/u-checkbox/u-checkbox.vue +13 -11
  22. package/components/u-checkbox-group/u-checkbox-group.vue +3 -3
  23. package/components/u-circle-progress/u-circle-progress.vue +5 -4
  24. package/components/u-code/u-code.vue +3 -3
  25. package/components/u-code-input/u-code-input.vue +9 -8
  26. package/components/u-col/u-col.vue +9 -8
  27. package/components/u-collapse/u-collapse.vue +3 -3
  28. package/components/u-collapse-item/u-collapse-item.vue +32 -15
  29. package/components/u-column-notice/u-column-notice.vue +8 -6
  30. package/components/u-count-down/u-count-down.vue +3 -3
  31. package/components/u-count-to/u-count-to.vue +6 -4
  32. package/components/u-datetime-picker/u-datetime-picker.vue +15 -15
  33. package/components/u-divider/u-divider.vue +7 -5
  34. package/components/u-dropdown/u-dropdown.vue +12 -10
  35. package/components/u-dropdown-item/u-dropdown-item.vue +7 -5
  36. package/components/u-empty/u-empty.vue +12 -8
  37. package/components/u-form/u-form.vue +12 -10
  38. package/components/u-form-item/u-form-item.vue +17 -11
  39. package/components/u-gap/u-gap.vue +3 -3
  40. package/components/u-grid/u-grid.vue +18 -7
  41. package/components/u-grid-item/u-grid-item.vue +14 -9
  42. package/components/u-icon/u-icon.vue +21 -19
  43. package/components/u-image/u-image.vue +18 -16
  44. package/components/u-index-anchor/u-index-anchor.vue +11 -9
  45. package/components/u-index-item/u-index-item.vue +6 -5
  46. package/components/u-index-list/u-index-list.vue +20 -18
  47. package/components/u-input/u-input.vue +12 -11
  48. package/components/u-keyboard/u-keyboard.vue +3 -3
  49. package/components/u-line/u-line.vue +7 -6
  50. package/components/u-line-progress/u-line-progress.vue +11 -8
  51. package/components/u-link/u-link.vue +9 -8
  52. package/components/u-list/u-list.vue +9 -9
  53. package/components/u-list-item/u-list-item.vue +5 -4
  54. package/components/u-loading-icon/u-loading-icon.vue +14 -10
  55. package/components/u-loading-page/u-loading-page.vue +10 -7
  56. package/components/u-loadmore/u-loadmore.vue +12 -10
  57. package/components/u-modal/u-modal.vue +7 -5
  58. package/components/u-navbar/u-navbar.vue +12 -7
  59. package/components/u-no-network/u-no-network.vue +6 -6
  60. package/components/u-notice-bar/u-notice-bar.vue +6 -5
  61. package/components/u-notify/u-notify.vue +19 -15
  62. package/components/u-number-box/u-number-box.vue +8 -7
  63. package/components/u-number-keyboard/u-number-keyboard.vue +7 -7
  64. package/components/u-overlay/u-overlay.vue +5 -5
  65. package/components/u-picker/u-picker.vue +19 -15
  66. package/components/u-picker-column/u-picker-column.vue +3 -3
  67. package/components/u-popup/u-popup.vue +13 -13
  68. package/components/u-radio/u-radio.vue +12 -12
  69. package/components/u-radio-group/u-radio-group.vue +3 -3
  70. package/components/u-rate/u-rate.vue +16 -14
  71. package/components/u-read-more/u-read-more.vue +9 -7
  72. package/components/u-row/u-row.vue +8 -7
  73. package/components/u-row-notice/u-row-notice.vue +14 -12
  74. package/components/u-safe-bottom/u-safe-bottom.vue +5 -4
  75. package/components/u-scroll-list/nvue.js +4 -4
  76. package/components/u-scroll-list/u-scroll-list.vue +13 -10
  77. package/components/u-search/u-search.vue +8 -6
  78. package/components/u-skeleton/u-skeleton.vue +20 -17
  79. package/components/u-slider/mpwxs.js +3 -2
  80. package/components/u-slider/nvue - /345/211/257/346/234/254.js" +2 -2
  81. package/components/u-slider/nvue.js +2 -2
  82. package/components/u-slider/u-slider.vue +8 -5
  83. package/components/u-status-bar/u-status-bar.vue +6 -5
  84. package/components/u-steps/u-steps.vue +5 -4
  85. package/components/u-steps-item/u-steps-item.vue +9 -7
  86. package/components/u-sticky/u-sticky.vue +12 -10
  87. package/components/u-subsection/u-subsection.vue +8 -6
  88. package/components/u-swipe-action/u-swipe-action.vue +3 -3
  89. package/components/u-swipe-action-item/nvue - backup.js +3 -3
  90. package/components/u-swipe-action-item/nvue.js +3 -3
  91. package/components/u-swipe-action-item/u-swipe-action-item.vue +8 -5
  92. package/components/u-swiper/u-swiper.vue +35 -24
  93. package/components/u-swiper-indicator/u-swiper-indicator.vue +10 -7
  94. package/components/u-switch/u-switch.vue +15 -13
  95. package/components/u-tabbar/u-tabbar.vue +6 -5
  96. package/components/u-tabbar-item/u-tabbar-item.vue +7 -5
  97. package/components/u-table/u-table.vue +3 -3
  98. package/components/u-tabs/u-tabs.vue +18 -14
  99. package/components/u-tabs-item/u-tabs-item.vue +3 -3
  100. package/components/u-tag/u-tag.vue +6 -4
  101. package/components/u-td/u-td.vue +3 -3
  102. package/components/u-text/u-text.vue +12 -10
  103. package/components/u-text/value.js +14 -12
  104. package/components/u-textarea/u-textarea.vue +11 -8
  105. package/components/u-toast/u-toast.vue +12 -9
  106. package/components/u-toolbar/u-toolbar.vue +3 -3
  107. package/components/u-tooltip/u-tooltip.vue +18 -17
  108. package/components/u-tr/u-tr.vue +3 -3
  109. package/components/u-transition/transition.js +2 -2
  110. package/components/u-transition/u-transition.vue +6 -5
  111. package/components/u-upload/mixin.js +4 -3
  112. package/components/u-upload/u-upload.vue +20 -17
  113. package/index.js +0 -5
  114. package/libs/function/index.js +27 -20
  115. package/libs/function/throttle.js +2 -2
  116. package/libs/mixin/mixin.js +14 -6
  117. package/libs/mixin/style.js +23 -4
  118. package/libs/util/route.js +6 -6
  119. package/package.json +1 -1
@@ -3,9 +3,9 @@
3
3
  <textarea
4
4
  class="u-textarea__field"
5
5
  :value="innerValue"
6
- :style="{ height: $u.addUnit(height) }"
6
+ :style="{ height: addUnit(height) }"
7
7
  :placeholder="placeholder"
8
- :placeholder-style="$u.addStyle(placeholderStyle, 'string')"
8
+ :placeholder-style="addStyle(placeholderStyle, 'string')"
9
9
  :placeholder-class="placeholderClass"
10
10
  :disabled="disabled"
11
11
  :focus="focus"
@@ -44,8 +44,9 @@
44
44
 
45
45
  <script>
46
46
  import props from "./props.js";
47
- import mpMixin from '../../libs/mixin/mpMixin.js';
48
- import mixin from '../../libs/mixin/mixin.js';
47
+ import mpMixin from '../../libs/mixin/mpMixin';
48
+ import mixin from '../../libs/mixin/mixin';
49
+ import { addStyle, addUnit, deepMerge, formValidate, os } from '../../libs/function/index';
49
50
  /**
50
51
  * Textarea 文本域
51
52
  * @description 文本域此组件满足了可能出现的表单信息补充,编辑等实际逻辑的功能,内置了字数校验等
@@ -164,20 +165,22 @@ export default {
164
165
  const style = {};
165
166
  // #ifdef APP-NVUE
166
167
  // 由于textarea在安卓nvue上的差异性,需要额外再调整其内边距
167
- if (uni.$u.os() === "android") {
168
+ if (os() === "android") {
168
169
  style.paddingTop = "6px";
169
170
  style.paddingLeft = "9px";
170
171
  style.paddingBottom = "3px";
171
172
  style.paddingRight = "6px";
172
173
  }
173
174
  // #endif
174
- return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle));
175
+ return deepMerge(style, addStyle(this.customStyle));
175
176
  },
176
177
  },
177
178
  // #ifdef VUE3
178
179
  emits: ['update:modelValue', 'linechange', 'focus', 'blur', 'change', 'confirm', 'keyboardheightchange'],
179
180
  // #endif
180
181
  methods: {
182
+ addStyle,
183
+ addUnit,
181
184
  // 在微信小程序中,不支持将函数当做props参数,故只能通过ref形式调用
182
185
  setFormatter(e) {
183
186
  this.innerFormatter = e
@@ -188,7 +191,7 @@ export default {
188
191
  onBlur(e) {
189
192
  this.$emit("blur", e);
190
193
  // 尝试调用u-form的验证方法
191
- uni.$u.formValidate(this, "blur");
194
+ formValidate(this, "blur");
192
195
  },
193
196
  onLinechange(e) {
194
197
  this.$emit("linechange", e);
@@ -219,7 +222,7 @@ export default {
219
222
  this.changeFromInner = true;
220
223
  this.$emit("change", value);
221
224
  // 尝试调用u-form的验证方法
222
- uni.$u.formValidate(this, "change");
225
+ formValidate(this, "change");
223
226
  });
224
227
  },
225
228
  onConfirm(e) {
@@ -39,8 +39,11 @@
39
39
  </template>
40
40
 
41
41
  <script>
42
- import mpMixin from '../../libs/mixin/mpMixin.js';
43
- import mixin from '../../libs/mixin/mixin.js';
42
+ import mpMixin from '../../libs/mixin/mpMixin';
43
+ import mixin from '../../libs/mixin/mixin';
44
+ import { os, sys, deepMerge, type2icon } from '../../libs/function/index';
45
+ import color from '../../libs/config/color';
46
+ import { hexToRgb } from '../../libs/function/colorGradient';
44
47
  /**
45
48
  * toast 消息提示
46
49
  * @description 此组件表现形式类似uni的uni.showToastAPI,但也有不同的地方。
@@ -90,7 +93,7 @@
90
93
  return '';
91
94
  }
92
95
  if (['error', 'warning', 'success', 'primary'].includes(this.tmpConfig.type)) {
93
- return uni.$u.type2icon(this.tmpConfig.type)
96
+ return type2icon(this.tmpConfig.type)
94
97
  } else {
95
98
  return ''
96
99
  }
@@ -111,24 +114,24 @@
111
114
  style.marginRight = '4px'
112
115
  // #ifdef APP-NVUE
113
116
  // iOSAPP下,图标有1px的向下偏移,这里进行修正
114
- if (uni.$u.os() === 'ios') {
117
+ if (os() === 'ios') {
115
118
  style.marginTop = '-1px'
116
119
  }
117
120
  // #endif
118
121
  return style
119
122
  },
120
123
  loadingIconColor() {
121
- let color = 'rgb(255, 255, 255)'
124
+ let colorTmp = 'rgb(255, 255, 255)'
122
125
  if (['error', 'warning', 'success', 'primary'].includes(this.tmpConfig.type)) {
123
126
  // loading-icon组件内部会对color参数进行一个透明度处理,该方法要求传入的颜色值
124
127
  // 必须为rgb格式的,所以这里做一个处理
125
- color = uni.$u.hexToRgb(uni.$u.color[this.tmpConfig.type])
128
+ colorTmp = hexToRgb(color[this.tmpConfig.type])
126
129
  }
127
- return color
130
+ return colorTmp
128
131
  },
129
132
  // 内容盒子的样式
130
133
  contentStyle() {
131
- const windowHeight = uni.$u.sys().windowHeight, style = {}
134
+ const windowHeight = sys().windowHeight, style = {}
132
135
  let value = 0
133
136
  // 根据top和bottom,对Y轴进行窗体高度的百分比偏移
134
137
  if(this.tmpConfig.position === 'top') {
@@ -153,7 +156,7 @@
153
156
  // 显示toast组件,由父组件通过this.$refs.xxx.show(options)形式调用
154
157
  show(options) {
155
158
  // 不将结果合并到this.config变量,避免多次调用u-toast,前后的配置造成混乱
156
- this.tmpConfig = uni.$u.deepMerge(this.config, options)
159
+ this.tmpConfig = deepMerge(this.config, options)
157
160
  // 清除定时器
158
161
  this.clearTimer()
159
162
  this.isShow = true
@@ -36,9 +36,9 @@
36
36
  </template>
37
37
 
38
38
  <script>
39
- import props from './props.js';
40
- import mpMixin from '../../libs/mixin/mpMixin.js';
41
- import mixin from '../../libs/mixin/mixin.js';
39
+ import props from './props';
40
+ import mpMixin from '../../libs/mixin/mpMixin';
41
+ import mixin from '../../libs/mixin/mixin';
42
42
  /**
43
43
  * Toolbar 工具条
44
44
  * @description
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <view
3
3
  class="u-tooltip"
4
- :style="[$u.addStyle(customStyle)]"
4
+ :style="[addStyle(customStyle)]"
5
5
  >
6
6
  <u-overlay
7
7
  :show="showTooltip && tooltipTop !== -10000 && overlay"
@@ -27,7 +27,7 @@
27
27
  duration="300"
28
28
  :customStyle="{
29
29
  position: 'absolute',
30
- top: $u.addUnit(tooltipTop),
30
+ top: addUnit(tooltipTop),
31
31
  zIndex: zIndex,
32
32
  ...tooltipStyle
33
33
  }"
@@ -42,8 +42,8 @@
42
42
  hover-class="u-tooltip__wrapper__popup__indicator--hover"
43
43
  v-if="showCopy || buttons.length"
44
44
  :style="[indicatorStyle, {
45
- width: $u.addUnit(indicatorWidth),
46
- height: $u.addUnit(indicatorWidth),
45
+ width: addUnit(indicatorWidth),
46
+ height: addUnit(indicatorWidth),
47
47
  }]"
48
48
  >
49
49
  <!-- 由于nvue不支持三角形绘制,这里就做一个四方形,再旋转45deg,得到露出的一个三角 -->
@@ -90,9 +90,10 @@
90
90
  </template>
91
91
 
92
92
  <script>
93
- import props from './props.js';
94
- import mpMixin from '../../libs/mixin/mpMixin.js';
95
- import mixin from '../../libs/mixin/mixin.js';
93
+ import props from './props';
94
+ import mpMixin from '../../libs/mixin/mpMixin';
95
+ import mixin from '../../libs/mixin/mixin';
96
+ import { addStyle, addUnit, getPx, guid, toast, sleep, sys } from '../../libs/function/index';
96
97
  // #ifdef APP-NVUE
97
98
  const dom = uni.requireNativePlugin('dom')
98
99
  // #endif
@@ -123,8 +124,8 @@
123
124
  // 是否展示气泡
124
125
  showTooltip: true,
125
126
  // 生成唯一id,防止一个页面多个组件,造成干扰
126
- textId: uni.$u.guid(),
127
- tooltipId: uni.$u.guid(),
127
+ textId: guid(),
128
+ tooltipId: guid(),
128
129
  // 初始时甚至为很大的值,让其移到屏幕外面,为了计算元素的尺寸
129
130
  tooltipTop: -10000,
130
131
  // 气泡的位置信息
@@ -161,18 +162,16 @@
161
162
  const style = {
162
163
  transform: `translateY(${this.direction === 'top' ? '-100%' : '100%'})`,
163
164
  },
164
- sys = uni.$u.sys(),
165
- getPx = uni.$u.getPx,
166
- addUnit = uni.$u.addUnit
165
+ sysInfo = sys()
167
166
  if (this.tooltipInfo.width / 2 > this.textInfo.left + this.textInfo.width / 2 - this.screenGap) {
168
167
  this.indicatorStyle = {}
169
168
  style.left = `-${addUnit(this.textInfo.left - this.screenGap)}`
170
169
  this.indicatorStyle.left = addUnit(this.textInfo.width / 2 - getPx(style.left) - this.indicatorWidth /
171
170
  2)
172
- } else if (this.tooltipInfo.width / 2 > sys.windowWidth - this.textInfo.right + this.textInfo.width / 2 -
171
+ } else if (this.tooltipInfo.width / 2 > sysInfo.windowWidth - this.textInfo.right + this.textInfo.width / 2 -
173
172
  this.screenGap) {
174
173
  this.indicatorStyle = {}
175
- style.right = `-${addUnit(sys.windowWidth - this.textInfo.right - this.screenGap)}`
174
+ style.right = `-${addUnit(sysInfo.windowWidth - this.textInfo.right - this.screenGap)}`
176
175
  this.indicatorStyle.right = addUnit(this.textInfo.width / 2 - getPx(style.right) - this
177
176
  .indicatorWidth / 2)
178
177
  } else {
@@ -195,6 +194,8 @@
195
194
  },
196
195
  emits: ["click"],
197
196
  methods: {
197
+ addStyle,
198
+ addUnit,
198
199
  init() {
199
200
  this.getElRect()
200
201
  },
@@ -240,7 +241,7 @@
240
241
  // 调用之前,先将指示器调整到屏幕外,方便获取尺寸
241
242
  this.showTooltip = true
242
243
  this.tooltipTop = -10000
243
- uni.$u.sleep(500).then(() => {
244
+ sleep(500).then(() => {
244
245
  this.queryRect(this.tooltipId).then(size => {
245
246
  this.tooltipInfo = size
246
247
  // 获取气泡尺寸之后,将其隐藏,为了让下次切换气泡显示与隐藏时,有淡入淡出的效果
@@ -260,10 +261,10 @@
260
261
  // 优先使用copyText字段,如果没有,则默认使用text字段当做复制的内容
261
262
  data: this.copyText || this.text,
262
263
  success: () => {
263
- this.showToast && uni.$u.toast('复制成功')
264
+ this.showToast && toast('复制成功')
264
265
  },
265
266
  fail: () => {
266
- this.showToast && uni.$u.toast('复制失败')
267
+ this.showToast && toast('复制失败')
267
268
  },
268
269
  complete: () => {
269
270
  this.showTooltip = false
@@ -5,9 +5,9 @@
5
5
  </template>
6
6
 
7
7
  <script>
8
- import props from './props.js';
9
- import mpMixin from '../../libs/mixin/mpMixin.js';
10
- import mixin from '../../libs/mixin/mixin.js';
8
+ import props from './props';
9
+ import mpMixin from '../../libs/mixin/mpMixin';
10
+ import mixin from '../../libs/mixin/mixin';
11
11
  /**
12
12
  * Tr
13
13
  * @description
@@ -23,7 +23,7 @@ const getStyle = (name) => animationMap[name]
23
23
  // #endif
24
24
 
25
25
  import { nextTick } from 'vue'
26
-
26
+ import { sleep } from '../../libs/function/index';
27
27
  export default {
28
28
  methods: {
29
29
  // 组件被点击发出事件
@@ -44,7 +44,7 @@ export default {
44
44
  await nextTick();
45
45
  {
46
46
  // https://github.com/umicro/uView2.0/issues/545
47
- await uni.$u.sleep(20)
47
+ await sleep(20)
48
48
  // 标识动画尚未结束
49
49
  this.$emit('enter')
50
50
  this.transitionEnded = false
@@ -13,9 +13,10 @@
13
13
  </template>
14
14
 
15
15
  <script>
16
- import props from './props.js';
17
- import mpMixin from '../../libs/mixin/mpMixin.js';
18
- import mixin from '../../libs/mixin/mixin.js';
16
+ import props from './props';
17
+ import mpMixin from '../../libs/mixin/mpMixin';
18
+ import mixin from '../../libs/mixin/mixin';
19
+ import { addStyle } from '../../libs/function/index';
19
20
  // 组件的methods方法,由于内容较长,写在外部文件中通过mixin引入
20
21
  import transition from "./transition.js";
21
22
  /**
@@ -58,12 +59,12 @@ export default {
58
59
  transitionTimingFunction: this.timingFunction,
59
60
  // #endif
60
61
  // 避免自定义样式影响到动画属性,所以写在viewStyle前面
61
- ...uni.$u.addStyle(customStyle),
62
+ ...addStyle(customStyle),
62
63
  ...viewStyle
63
64
  }
64
65
  }
65
66
  },
66
- // 将mixin挂在到组件中,uni.$u.mixin实际上为一个vue格式对象
67
+ // 将mixin挂在到组件中,实际上为一个vue格式对象。
67
68
  mixins: [mpMixin, mixin, transition, props],
68
69
  watch: {
69
70
  show: {
@@ -1,3 +1,4 @@
1
+ import { error } from '../../libs/function/index';
1
2
  export default {
2
3
  watch: {
3
4
  // 监听accept的变化,判断是否符合个平台要求
@@ -7,15 +8,15 @@ export default {
7
8
  handler(val) {
8
9
  // #ifndef MP-WEIXIN
9
10
  if (val === 'all' || val === 'media') {
10
- uni.$u.error('只有微信小程序才支持把accept配置为all、media之一')
11
+ error('只有微信小程序才支持把accept配置为all、media之一')
11
12
  }
12
13
  // #endif
13
14
  // #ifndef H5 || MP-WEIXIN
14
15
  if (val === 'file') {
15
- uni.$u.error('只有微信小程序和H5(HX2.9.9)才支持把accept配置为file')
16
+ error('只有微信小程序和H5(HX2.9.9)才支持把accept配置为file')
16
17
  }
17
18
  // #endif
18
19
  }
19
20
  }
20
21
  }
21
- }
22
+ }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="u-upload" :style="[$u.addStyle(customStyle)]">
2
+ <view class="u-upload" :style="[addStyle(customStyle)]">
3
3
  <view class="u-upload__wrap" >
4
4
  <template v-if="previewImage">
5
5
  <view
@@ -14,8 +14,8 @@
14
14
  class="u-upload__wrap__preview__image"
15
15
  @tap="onPreviewImage(item)"
16
16
  :style="[{
17
- width: $u.addUnit(width),
18
- height: $u.addUnit(height)
17
+ width: addUnit(width),
18
+ height: addUnit(height)
19
19
  }]"
20
20
  />
21
21
  <view
@@ -104,8 +104,8 @@
104
104
  @tap="chooseFile"
105
105
  :class="[disabled && 'u-upload__button--disabled']"
106
106
  :style="[{
107
- width: $u.addUnit(width),
108
- height: $u.addUnit(height)
107
+ width: addUnit(width),
108
+ height: addUnit(height)
109
109
  }]"
110
110
  >
111
111
  <u-icon
@@ -129,10 +129,11 @@
129
129
  chooseFile
130
130
  } from './utils';
131
131
  import mixinUp from './mixin.js';
132
- import props from './props.js';
133
- import mpMixin from '../../libs/mixin/mpMixin.js';
134
- import mixin from '../../libs/mixin/mixin.js';
135
-
132
+ import props from './props';
133
+ import mpMixin from '../../libs/mixin/mpMixin';
134
+ import mixin from '../../libs/mixin/mixin';
135
+ import { addStyle, addUnit, toast } from '../../libs/function/index';
136
+ import test from '../../libs/function/test';
136
137
  /**
137
138
  * upload 上传
138
139
  * @description 该组件用于上传图片场景
@@ -192,6 +193,8 @@
192
193
  emits: ['error', 'beforeRead', 'oversize', 'afterRead', 'delete', 'clickPreview'],
193
194
  // #endif
194
195
  methods: {
196
+ addUnit,
197
+ addStyle,
195
198
  formatFileList() {
196
199
  const {
197
200
  fileList = [], maxCount
@@ -199,8 +202,8 @@
199
202
  const lists = fileList.map((item) =>
200
203
  Object.assign(Object.assign({}, item), {
201
204
  // 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
202
- isImage: this.accept === 'image' || uni.$u.test.image(item.url || item.thumb),
203
- isVideo: this.accept === 'video' || uni.$u.test.video(item.url || item.thumb),
205
+ isImage: this.accept === 'image' || test.image(item.url || item.thumb),
206
+ isVideo: this.accept === 'video' || test.video(item.url || item.thumb),
204
207
  deletable: typeof(item.deletable) === 'boolean' ? item.deletable : this.deletable,
205
208
  })
206
209
  );
@@ -218,7 +221,7 @@
218
221
  // 如果用户传入的是字符串,需要格式化成数组
219
222
  let capture;
220
223
  try {
221
- capture = uni.$u.test.array(this.capture) ? this.capture : this.capture.split(',');
224
+ capture = test.array(this.capture) ? this.capture : this.capture.split(',');
222
225
  }catch(e) {
223
226
  capture = [];
224
227
  }
@@ -250,7 +253,7 @@
250
253
  } = this;
251
254
  let res = true
252
255
  // beforeRead是否为一个方法
253
- if (uni.$u.test.func(beforeRead)) {
256
+ if (test.func(beforeRead)) {
254
257
  // 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
255
258
  res = beforeRead(file, this.getDetail());
256
259
  }
@@ -271,7 +274,7 @@
271
274
  if (!res) {
272
275
  return;
273
276
  }
274
- if (uni.$u.test.promise(res)) {
277
+ if (test.promise(res)) {
275
278
  res.then((data) => this.onAfterRead(data || file));
276
279
  } else {
277
280
  this.onAfterRead(file);
@@ -317,10 +320,10 @@
317
320
  if (!item.isImage || !this.previewFullImage) return
318
321
  uni.previewImage({
319
322
  // 先filter找出为图片的item,再返回filter结果中的图片url
320
- urls: this.lists.filter((item) => this.accept === 'image' || uni.$u.test.image(item.url || item.thumb)).map((item) => item.url || item.thumb),
323
+ urls: this.lists.filter((item) => this.accept === 'image' || test.image(item.url || item.thumb)).map((item) => item.url || item.thumb),
321
324
  current: item.url || item.thumb,
322
325
  fail() {
323
- uni.$u.toast('预览图片失败')
326
+ toast('预览图片失败')
324
327
  },
325
328
  });
326
329
  },
@@ -342,7 +345,7 @@
342
345
  ),
343
346
  current: index,
344
347
  fail() {
345
- uni.$u.toast('预览视频失败')
348
+ toast('预览视频失败')
346
349
  },
347
350
  });
348
351
  },
package/index.js CHANGED
@@ -81,11 +81,6 @@ const $u = {
81
81
  uni.$u = $u
82
82
 
83
83
  const install = (Vue) => {
84
- // 时间格式化,同时两个名称,date和timeFormat
85
- // Vue.filter('timeFormat', (timestamp, format) => uni.$u.timeFormat(timestamp, format))
86
- // Vue.filter('date', (timestamp, format) => uni.$u.timeFormat(timestamp, format))
87
- // // 将多久以前的方法,注入到全局过滤器
88
- // Vue.filter('timeFrom', (timestamp, format) => uni.$u.timeFrom(timestamp, format))
89
84
  // 同时挂载到uni和Vue.prototype中
90
85
  // #ifndef APP-NVUE
91
86
  // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
@@ -1,5 +1,10 @@
1
- import test from './test.js'
1
+ import {
2
+ number as testNumber,
3
+ array as testArray,
4
+ empty as testEmpty
5
+ } from './test'
2
6
  import { round } from './digit.js'
7
+ import config from '../config/config';
3
8
  /**
4
9
  * @description 如果value小于min,取min;如果value大于max,取max
5
10
  * @param {number} min
@@ -11,18 +16,18 @@ export function range(min = 0, max = 0, value = 0) {
11
16
  }
12
17
 
13
18
  /**
14
- * @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.upx2px进行转换
19
+ * @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.rpx2px进行转换
15
20
  * @param {number|string} value 用户传递值的px值
16
21
  * @param {boolean} unit
17
22
  * @returns {number|string}
18
23
  */
19
24
  export function getPx(value, unit = false) {
20
- if (test.number(value)) {
25
+ if (testNumber(value)) {
21
26
  return unit ? `${value}px` : Number(value)
22
27
  }
23
28
  // 如果带有rpx,先取出其数值部分,再转为px值
24
29
  if (/(rpx|upx)$/.test(value)) {
25
- return unit ? `${uni.upx2px(parseInt(value))}px` : Number(uni.upx2px(parseInt(value)))
30
+ return unit ? `${uni.rpx2px(parseInt(value))}px` : Number(uni.rpx2px(parseInt(value)))
26
31
  }
27
32
  return unit ? `${parseInt(value)}px` : parseInt(value)
28
33
  }
@@ -133,7 +138,7 @@ export function $parent(name = undefined) {
133
138
  */
134
139
  export function addStyle(customStyle, target = 'object') {
135
140
  // 字符串转字符串,对象转对象情形,直接返回
136
- if (test.empty(customStyle) || typeof(customStyle) === 'object' && target === 'object' || target === 'string' &&
141
+ if (testEmpty(customStyle) || typeof(customStyle) === 'object' && target === 'object' || target === 'string' &&
137
142
  typeof(customStyle) === 'string') {
138
143
  return customStyle
139
144
  }
@@ -156,10 +161,12 @@ export function addStyle(customStyle, target = 'object') {
156
161
  }
157
162
  // 这里为对象转字符串形式
158
163
  let string = ''
159
- for (const i in customStyle) {
160
- // 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
161
- const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
162
- string += `${key}:${customStyle[i]};`
164
+ if (typeof customStyle === 'object') {
165
+ customStyle.forEach((val, i) => {
166
+ // 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
167
+ const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
168
+ string += `${key}:${val};`
169
+ })
163
170
  }
164
171
  // 去除两端空格
165
172
  return trim(string)
@@ -172,11 +179,11 @@ export function addStyle(customStyle, target = 'object') {
172
179
  */
173
180
  export function addUnit(value = 'auto', unit = '') {
174
181
  if (!unit) {
175
- unit = uni.$u.config.unit || 'px'
182
+ unit = config.unit || 'px'
176
183
  }
177
184
  value = String(value)
178
185
  // 用uView内置验证规则中的number判断是否为数值
179
- return test.number(value) ? `${value}${unit}` : value
186
+ return testNumber(value) ? `${value}${unit}` : value
180
187
  }
181
188
 
182
189
  /**
@@ -191,7 +198,7 @@ export function deepClone(obj) {
191
198
  // 原始类型直接返回
192
199
  return obj
193
200
  }
194
- const o = test.array(obj) ? [] : {}
201
+ const o = testArray(obj) ? [] : {}
195
202
  for (const i in obj) {
196
203
  if (obj.hasOwnProperty(i)) {
197
204
  o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
@@ -206,8 +213,8 @@ export function deepClone(obj) {
206
213
  * @param {object} source 拷贝的来源对象
207
214
  * @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
208
215
  */
209
- export function deepMerge(target = {}, source = {}) {
210
- target = deepClone(target)
216
+ export function deepMerge(targetOrigin = {}, source = {}) {
217
+ let target = deepClone(targetOrigin)
211
218
  if (typeof target !== 'object' || typeof source !== 'object') return false
212
219
  for (const prop in source) {
213
220
  if (!source.hasOwnProperty(prop)) continue
@@ -591,8 +598,8 @@ export function padZero(value) {
591
598
  * @param {*} event
592
599
  */
593
600
  export function formValidate(instance, event) {
594
- const formItem = uni.$u.$parent.call(instance, 'u-form-item')
595
- const form = uni.$u.$parent.call(instance, 'u-form')
601
+ const formItem = $parent.call(instance, 'u-form-item')
602
+ const form = $parent.call(instance, 'u-form')
596
603
  // 如果发生变化的input或者textarea等,其父组件中有u-form-item或者u-form等,就执行form的validate方法
597
604
  // 同时将form-item的pros传递给form,让其进行精确对象验证
598
605
  if (formItem && form) {
@@ -607,9 +614,9 @@ export function formValidate(instance, event) {
607
614
  * @returns {*}
608
615
  */
609
616
  export function getProperty(obj, key) {
610
- if (!obj) {
611
- return
612
- }
617
+ if (typeof obj !== 'object' || null == obj) {
618
+ return ''
619
+ }
613
620
  if (typeof key !== 'string' || key === '') {
614
621
  return ''
615
622
  }
@@ -634,7 +641,7 @@ export function getProperty(obj, key) {
634
641
  * @param {string} value 设置的值
635
642
  */
636
643
  export function setProperty(obj, key, value) {
637
- if (!obj) {
644
+ if (typeof obj !== 'object' || null == obj) {
638
645
  return
639
646
  }
640
647
  // 递归赋值
@@ -1,5 +1,5 @@
1
- let timer; let
2
- flag
1
+ let timer;
2
+ let flag;
3
3
  /**
4
4
  * 节流原理:在一定时间内,只能触发一次
5
5
  *
@@ -1,3 +1,6 @@
1
+ import { deepMerge, $parent } from '../function/index';
2
+ import test from '../function/test';
3
+ import route from '../util/route';
1
4
  export default {
2
5
  // 定义每个组件都可能需要用到的外部样式以及类名
3
6
  props: {
@@ -39,7 +42,7 @@ export default {
39
42
  $u() {
40
43
  // #ifndef APP-NVUE
41
44
  // 在非nvue端,移除props,http,mixin等对象,避免在小程序setData时数据过大影响性能
42
- return uni.$u.deepMerge(uni.$u, {
45
+ return deepMerge(uni.$u, {
43
46
  props: undefined,
44
47
  http: undefined,
45
48
  mixin: undefined
@@ -90,7 +93,7 @@ export default {
90
93
  if (url) {
91
94
  // h5官方回应:发行h5会自动摇树优化,所有使用uni的地方,都会被直接转换成具体的API调用 https://ask.dcloud.net.cn/question/161523?notification_id-1201922__rf-false__item_id-226372
92
95
  // 使用封装的 route 进行跳转(直接调用方法),不使用 uni 对象
93
- this.$u.route({ type: this.linkType, url })
96
+ route({ type: this.linkType, url })
94
97
  // 执行类似uni.navigateTo的方法
95
98
  // uni[this.linkType]({
96
99
  // url
@@ -122,7 +125,7 @@ export default {
122
125
  // 将父组件this中对应的参数,赋值给本组件(u-radio的this)的parentData对象中对应的属性
123
126
  // 之所以需要这么做,是因为所有端中,头条小程序不支持通过this.parent.xxx去监听父组件参数的变化
124
127
  // 此处并不会自动更新子组件的数据,而是依赖父组件u-radio-group去监听data的变化,手动调用更新子组件的方法去重新获取
125
- this.parent = uni.$u.$parent.call(this, parentName)
128
+ this.parent = $parent.call(this, parentName)
126
129
  if (this.parent.children) {
127
130
  // 如果父组件的children不存在本组件的实例,才将本实例添加到父组件的children中
128
131
  this.parent.children.indexOf(this) === -1 && this.parent.children.push(this)
@@ -145,11 +148,16 @@ export default {
145
148
  },
146
149
  onReachBottom() {
147
150
  uni.$emit('uOnReachBottom')
148
- },
149
- beforeUnmount() {
151
+ },
152
+ // #ifdef VUE2
153
+ beforeDestroy() {
154
+ // #endif
155
+ // #ifdef VUE3
156
+ beforeUnmount() {
157
+ // #endif
150
158
  // 判断当前页面是否存在parent和chldren,一般在checkbox和checkbox-group父子联动的场景会有此情况
151
159
  // 组件销毁时,移除子组件在父组件children数组中的实例,释放资源,避免数据混乱
152
- if (this.parent && uni.$u.test.array(this.parent.children)) {
160
+ if (this.parent && test.array(this.parent.children)) {
153
161
  // 组件销毁时,移除父组件中的children数组中对应的实例
154
162
  const childrenList = this.parent.children
155
163
  childrenList.map((child, index) => {