uview-plus 3.5.5 → 3.5.15

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.
@@ -1,138 +1,156 @@
1
1
  import { defineMixin } from '../../libs/vue'
2
2
  import defProps from '../../libs/config/props.js'
3
+
3
4
  export const props = defineMixin({
4
- props: {
5
- // 搜索框形状,round-圆形,square-方形
6
- shape: {
7
- type: String,
8
- default: () => defProps.search.shape
9
- },
10
- // 搜索框背景色,默认值#f2f2f2
11
- bgColor: {
12
- type: String,
13
- default: () => defProps.search.bgColor
14
- },
15
- // 占位提示文字
16
- placeholder: {
17
- type: String,
18
- default: () => defProps.search.placeholder
19
- },
20
- // 是否启用清除控件
21
- clearabled: {
22
- type: Boolean,
23
- default: () => defProps.search.clearabled
24
- },
25
- // 是否自动聚焦
26
- focus: {
27
- type: Boolean,
28
- default: () => defProps.search.focus
29
- },
30
- // 是否在搜索框右侧显示取消按钮
31
- showAction: {
32
- type: Boolean,
33
- default: () => defProps.search.showAction
34
- },
35
- // 右边控件的样式
36
- actionStyle: {
37
- type: Object,
38
- default: () => defProps.search.actionStyle
39
- },
40
- // 取消按钮文字
41
- actionText: {
42
- type: String,
43
- default: () => defProps.search.actionText
44
- },
45
- // 输入框内容对齐方式,可选值为 left|center|right
46
- inputAlign: {
47
- type: String,
48
- default: () => defProps.search.inputAlign
49
- },
50
- // input输入框的样式,可以定义文字颜色,大小等,对象形式
51
- inputStyle: {
52
- type: Object,
53
- default: () => defProps.search.inputStyle
54
- },
55
- // 是否启用输入框
56
- disabled: {
57
- type: Boolean,
58
- default: () => defProps.search.disabled
59
- },
60
- // 边框颜色
61
- borderColor: {
62
- type: String,
63
- default: () => defProps.search.borderColor
64
- },
65
- // 搜索图标的颜色,默认同输入框字体颜色
66
- searchIconColor: {
67
- type: String,
68
- default: () => defProps.search.searchIconColor
69
- },
70
- // 输入框字体颜色
71
- color: {
72
- type: String,
73
- default: () => defProps.search.color
74
- },
75
- // placeholder的颜色
76
- placeholderColor: {
77
- type: String,
78
- default: () => defProps.search.placeholderColor
79
- },
80
- // 左边输入框的图标,可以为uView图标名称或图片路径
81
- searchIcon: {
82
- type: String,
83
- default: () => defProps.search.searchIcon
84
- },
85
- searchIconSize: {
86
- type: [Number, String],
87
- default: () => defProps.search.searchIconSize
88
- },
89
- // 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px"、"30px 20px"等写法
90
- margin: {
91
- type: String,
92
- default: () => defProps.search.margin
93
- },
94
- // 开启showAction时,是否在input获取焦点时才显示
95
- animation: {
96
- type: Boolean,
97
- default: () => defProps.search.animation
98
- },
99
- // 输入框的初始化内容
100
- modelValue: {
101
- type: String,
102
- default: () => defProps.search.value
103
- },
5
+ props: {
6
+ // #ifdef VUE3
7
+ // 绑定的值
8
+ modelValue: {
9
+ type: [String, Number],
10
+ default: () => defProps.search.value
11
+ },
12
+ // #endif
13
+ // #ifdef VUE2
14
+ // 绑定的值
104
15
  value: {
105
- type: String,
106
- default: () => defProps.search.value
107
- },
108
- // 输入框最大能输入的长度,-1为不限制长度(来自uniapp文档)
109
- maxlength: {
110
- type: [String, Number],
111
- default: () => defProps.search.maxlength
112
- },
113
- // 搜索框高度,单位px
114
- height: {
115
- type: [String, Number],
116
- default: () => defProps.search.height
117
- },
118
- // 搜索框左侧文本
119
- label: {
120
- type: [String, Number, null],
121
- default: () => defProps.search.label
122
- },
123
- // 键盘弹起时,是否自动上推页面
124
- adjustPosition: {
125
- type: Boolean,
126
- default: () => true
127
- },
128
- // 键盘收起时,是否自动失去焦点
129
- autoBlur: {
130
- type: Boolean,
131
- default: () => false
132
- },
133
- iconPosition: {
134
- type: String,
135
- default: () => defProps.search.iconPosition
136
- }
137
- }
138
- })
16
+ type: [String, Number],
17
+ default: () => defProps.search.value
18
+ },
19
+ // #endif
20
+ // 搜索框形状,round-圆形,square-方形
21
+ shape: {
22
+ type: String,
23
+ default: () => defProps.search.shape
24
+ },
25
+ // 搜索框背景色
26
+ bgColor: {
27
+ type: String,
28
+ default: () => defProps.search.bgColor
29
+ },
30
+ // 占位提示文字
31
+ placeholder: {
32
+ type: String,
33
+ default: () => defProps.search.placeholder
34
+ },
35
+ // 是否启用清除控件
36
+ clearabled: {
37
+ type: Boolean,
38
+ default: () => defProps.search.clearabled
39
+ },
40
+ // 是否仅聚焦时显示清除控件
41
+ onlyClearableOnFocused: {
42
+ type: Boolean,
43
+ default: true
44
+ },
45
+ // 是否自动聚焦
46
+ focus: {
47
+ type: Boolean,
48
+ default: () => defProps.search.focus
49
+ },
50
+ // 是否在搜索框右侧显示取消按钮
51
+ showAction: {
52
+ type: Boolean,
53
+ default: () => defProps.search.showAction
54
+ },
55
+ // 右侧取消按钮文字
56
+ actionText: {
57
+ type: String,
58
+ default: () => defProps.search.actionText
59
+ },
60
+ // 搜索框左侧文本
61
+ label: {
62
+ type: [String, Number, null],
63
+ default: () => defProps.search.label
64
+ },
65
+ // 输入框内容对齐方式,可选值为:left|center|right
66
+ inputAlign: {
67
+ type: String,
68
+ default: () => defProps.search.inputAlign
69
+ },
70
+ // 是否启用输入框
71
+ disabled: {
72
+ type: Boolean,
73
+ default: () => defProps.search.disabled
74
+ },
75
+ // 开启showAction时,是否在input获取焦点时才显示
76
+ animation: {
77
+ type: Boolean,
78
+ default: () => defProps.search.animation
79
+ },
80
+ // 边框颜色,只要配置了颜色,才会有边框
81
+ borderColor: {
82
+ type: String,
83
+ default: () => defProps.search.borderColor
84
+ },
85
+ // 搜索图标的颜色,默认同输入框字体颜色
86
+ searchIconColor: {
87
+ type: String,
88
+ default: () => defProps.search.searchIconColor
89
+ },
90
+ // 搜索图标的大小
91
+ searchIconSize: {
92
+ type: [Number, String],
93
+ default: () => defProps.search.searchIconSize
94
+ },
95
+ // 输入框字体颜色
96
+ color: {
97
+ type: String,
98
+ default: () => defProps.search.color
99
+ },
100
+ // placeholder的颜色
101
+ placeholderColor: {
102
+ type: String,
103
+ default: () => defProps.search.placeholderColor
104
+ },
105
+ // 左边输入框的图标,可以为uView图标名称或图片路径
106
+ searchIcon: {
107
+ type: String,
108
+ default: () => defProps.search.searchIcon
109
+ },
110
+ // 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px"
111
+ margin: {
112
+ type: String,
113
+ default: () => defProps.search.margin
114
+ },
115
+ // 应该是uView-plus版本新增的,用于控制搜索图标的插槽位置
116
+ iconPosition: {
117
+ type: String,
118
+ default: () => defProps.search.iconPosition
119
+ },
120
+ // 输入框最大能输入的长度,-1为不限制长度
121
+ maxlength: {
122
+ type: [String, Number],
123
+ default: () => defProps.search.maxlength
124
+ },
125
+ // 输入框高度,单位px
126
+ height: {
127
+ type: [String, Number],
128
+ default: () => defProps.search.height
129
+ },
130
+ // 键盘弹起时,是否自动上推页面
131
+ adjustPosition: {
132
+ type: Boolean,
133
+ default: () => defProps.search.adjustPosition
134
+ },
135
+ // 键盘收起时,是否自动失去焦点
136
+ autoBlur: {
137
+ type: Boolean,
138
+ default: () => defProps.search.autoBlur
139
+ },
140
+ // 输入框的样式,对象形式
141
+ inputStyle: {
142
+ type: Object,
143
+ default: () => defProps.search.inputStyle
144
+ },
145
+ // 右侧控件的样式,对象形式
146
+ actionStyle: {
147
+ type: Object,
148
+ default: () => defProps.search.actionStyle
149
+ },
150
+ // 自定义样式,对象形式
151
+ customStyle: {
152
+ type: Object,
153
+ default: () => defProps.search.customStyle
154
+ }
155
+ }
156
+ })
@@ -55,7 +55,7 @@
55
55
  />
56
56
  <view
57
57
  class="u-search__content__icon u-search__content__close"
58
- v-if="keyword && clearabled && focused"
58
+ v-if="isShowClear"
59
59
  @click="clear"
60
60
  >
61
61
  <up-icon
@@ -111,6 +111,7 @@
111
111
  * @property {String | Number} label 搜索框左边显示内容
112
112
  * @property {Boolean} adjustPosition 键盘弹起时,是否自动上推页面
113
113
  * @property {Boolean} autoBlur 键盘收起时,是否自动失去焦点
114
+ * @property {Boolean} onlyClearableOnFocused 是否仅在聚焦时显示清除控件(默认 true )
114
115
  * @property {Object} customStyle 定义需要用到的外部样式
115
116
  *
116
117
  * @event {Function} change 输入框内容发生变化时触发
@@ -125,7 +126,6 @@
125
126
  data() {
126
127
  return {
127
128
  keyword: '',
128
- showClear: false, // 是否显示右边的清除图标
129
129
  show: false,
130
130
  // 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件
131
131
  focused: this.focus
@@ -165,6 +165,18 @@
165
165
  computed: {
166
166
  showActionBtn() {
167
167
  return !this.animation && this.showAction
168
+ },
169
+ // 是否显示清除控件
170
+ isShowClear() {
171
+ const { clearabled, focused, keyword, onlyClearableOnFocused } = this;
172
+ if (!clearabled) {
173
+ return false;
174
+ }
175
+ if (onlyClearableOnFocused) {
176
+ return !!focused && keyword !== "";
177
+ } else {
178
+ return keyword !== "";
179
+ }
168
180
  }
169
181
  },
170
182
  emits: ['clear', 'search', 'custom', 'focus', 'blur', 'click', 'clickIcon', 'update:modelValue', 'change'],