hy-app 0.5.11 → 0.5.13

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.
@@ -9,8 +9,7 @@
9
9
  color: $hy-text-color;
10
10
 
11
11
  @include e(border) {
12
- /* TODO: 先这样写,因为在某些pda中写$hy-border-line,边框不显示,后续排除问题 */
13
- border: 1px solid #e8e8e8;
12
+ border: $hy-border-line;
14
13
  }
15
14
 
16
15
  @include e(radius, square) {
@@ -1,186 +1,186 @@
1
- import type { CSSProperties, PropType } from 'vue'
2
- import type { InputConfirmType } from '@uni-helper/uni-types'
3
- import type { HyIconProps } from '../hy-icon/typing'
4
-
5
- const inputProps = {
6
- /** 输入的值 */
7
- modelValue: {
8
- type: [String, Number],
9
- required: true
10
- },
11
- /**
12
- * 输入框类型,见上方说明
13
- * @values text,idcard,number,digit,safe-password,tel,nickname
14
- * */
15
- type: {
16
- type: String,
17
- default: 'text'
18
- },
19
- /** 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true,兼容性:微信小程序、百度小程序、字节跳动小程序、QQ小程序 */
20
- fixed: {
21
- type: Boolean,
22
- default: false
23
- },
24
- /** 是否禁用输入框 */
25
- disabled: {
26
- type: Boolean,
27
- default: false
28
- },
29
- /** 禁用状态时的背景色 */
30
- disabledColor: {
31
- type: String,
32
- default: ''
33
- },
34
- /** 是否显示清除控件 */
35
- clearable: {
36
- type: Boolean,
37
- default: false
38
- },
39
- /** 是否密码类型 */
40
- password: {
41
- type: Boolean,
42
- default: false
43
- },
44
- /** 最大输入长度,设置为 -1 的时候不限制最大长度 */
45
- maxlength: {
46
- type: Number,
47
- default: -1
48
- },
49
- /** 输入框为空时的占位符 */
50
- placeholder: String,
51
- /** 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ */
52
- placeholderClass: {
53
- type: String,
54
- default: 'input-placeholder'
55
- },
56
- /** 指定placeholder的样式,字符串/对象形式,如"color: red;" */
57
- placeholderStyle: {
58
- type: Object as PropType<CSSProperties>,
59
- default: () => ({})
60
- },
61
- /** 是否显示输入字数统计,只在 type ="text"或type ="textarea"时有效 */
62
- showWordLimit: {
63
- type: Boolean,
64
- default: false
65
- },
66
- /** 设置右下角按钮的文字,兼容性详见uni-app文档 */
67
- confirmType: {
68
- type: String as PropType<InputConfirmType>,
69
- default: 'done'
70
- },
71
- /** 点击键盘右下角按钮时是否保持键盘不收起,H5无效 */
72
- confirmHold: {
73
- type: Boolean,
74
- default: false
75
- },
76
- /** focus时,点击页面的时候不收起键盘,微信小程序有效 */
77
- holdKeyboard: {
78
- type: Boolean,
79
- default: false
80
- },
81
- /** 自动获取焦点,在 H5 平台能否聚焦以及软键盘是否跟随弹出,取决于当前浏览器本身的实现。nvue 页面不支持,需使用组件的 focus()、blur() 方法控制焦点 */
82
- focus: {
83
- type: Boolean,
84
- default: false
85
- },
86
- /** 键盘收起时,是否自动失去焦点,目前仅App3.0.0+有效 */
87
- autoBlur: {
88
- type: Boolean,
89
- default: false
90
- },
91
- /** 是否去掉 iOS 下的默认内边距,仅微信小程序,且type=textarea时有效 */
92
- disableDefaultPadding: {
93
- type: Boolean,
94
- default: false
95
- },
96
- /** 指定focus时光标的位置 */
97
- cursor: {
98
- type: Number,
99
- default: 140
100
- },
101
- /** 输入框聚焦时底部与键盘的距离 */
102
- cursorSpacing: {
103
- type: Number,
104
- default: 30
105
- },
106
- /** 光标起始位置,自动聚集时有效,需与selection-end搭配使用 */
107
- selectionStart: {
108
- type: Number,
109
- default: -1
110
- },
111
- /** 光标结束位置,自动聚集时有效,需与selection-start搭配使用 */
112
- selectionEnd: {
113
- type: Number,
114
- default: -1
115
- },
116
- /** 键盘弹起时,是否自动上推页面 */
117
- adjustPosition: {
118
- type: Boolean,
119
- default: true
120
- },
121
- /**
122
- * 输入框内容对齐方式
123
- * @values left,center,right
124
- * */
125
- inputAlign: {
126
- type: String,
127
- default: 'left'
128
- },
129
- /** 输入框字体的大小 */
130
- fontSize: {
131
- type: [String, Number],
132
- default: '15px'
133
- },
134
- /** 输入框字体颜色 */
135
- color: {
136
- type: String,
137
- default: ''
138
- },
139
- /** 输入框前置图标 */
140
- prefixIcon: {
141
- type: Object as PropType<HyIconProps>,
142
- default: () => {}
143
- },
144
- /** 输入框后置图标 */
145
- suffixIcon: {
146
- type: Object as PropType<HyIconProps>,
147
- default: () => {}
148
- },
149
- /**
150
- * 边框类型
151
- * @values surround,bottom,none
152
- * */
153
- border: {
154
- type: String,
155
- default: 'surround'
156
- },
157
- /** 是否只读,与disabled不同之处在于disabled会置灰组件,而readonly则不会 */
158
- readonly: {
159
- type: Boolean,
160
- default: false
161
- },
162
- /**
163
- * 输入框形状
164
- * @values circle,square
165
- * */
166
- shape: {
167
- type: String,
168
- default: 'square'
169
- },
170
- /** 是否忽略组件内对文本合成系统事件的处理 */
171
- ignoreCompositionEvent: {
172
- type: Boolean,
173
- default: false
174
- },
175
- /** 内容式化函数 */
176
- formatter: Function,
177
- /** 定义需要用到的外部样式 */
178
- customStyle: {
179
- type: Object as PropType<CSSProperties>,
180
- default: () => {}
181
- },
182
- /** 自定义外部类名 */
183
- customClass: String
184
- } as const
185
-
186
- export default inputProps
1
+ import type { CSSProperties, PropType } from 'vue'
2
+ import type { InputConfirmType } from '@uni-helper/uni-types'
3
+ import type { HyIconProps } from '../hy-icon/typing'
4
+
5
+ const inputProps = {
6
+ /** 输入的值 */
7
+ modelValue: {
8
+ type: [String, Number],
9
+ required: true
10
+ },
11
+ /**
12
+ * 输入框类型,见上方说明
13
+ * @values test,idcard,number,digit,safe-password,tel,nickname
14
+ * */
15
+ type: {
16
+ type: String,
17
+ default: 'text'
18
+ },
19
+ /** 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true,兼容性:微信小程序、百度小程序、字节跳动小程序、QQ小程序 */
20
+ fixed: {
21
+ type: Boolean,
22
+ default: false
23
+ },
24
+ /** 是否禁用输入框 */
25
+ disabled: {
26
+ type: Boolean,
27
+ default: false
28
+ },
29
+ /** 禁用状态时的背景色 */
30
+ disabledColor: {
31
+ type: String,
32
+ default: ''
33
+ },
34
+ /** 是否显示清除控件 */
35
+ clearable: {
36
+ type: Boolean,
37
+ default: false
38
+ },
39
+ /** 是否密码类型 */
40
+ password: {
41
+ type: Boolean,
42
+ default: false
43
+ },
44
+ /** 最大输入长度,设置为 -1 的时候不限制最大长度(注:支付宝不支持-1,需要设置其他任意值) */
45
+ maxlength: {
46
+ type: Number,
47
+ default: -1
48
+ },
49
+ /** 输入框为空时的占位符 */
50
+ placeholder: String,
51
+ /** 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ */
52
+ placeholderClass: {
53
+ type: String,
54
+ default: 'input-placeholder'
55
+ },
56
+ /** 指定placeholder的样式,字符串/对象形式,如"color: red;" */
57
+ placeholderStyle: {
58
+ type: Object as PropType<CSSProperties>,
59
+ default: () => ({})
60
+ },
61
+ /** 是否显示输入字数统计,只在 type ="test"或type ="textarea"时有效 */
62
+ showWordLimit: {
63
+ type: Boolean,
64
+ default: false
65
+ },
66
+ /** 设置右下角按钮的文字,兼容性详见uni-app文档 */
67
+ confirmType: {
68
+ type: String as PropType<InputConfirmType>,
69
+ default: 'done'
70
+ },
71
+ /** 点击键盘右下角按钮时是否保持键盘不收起,H5无效 */
72
+ confirmHold: {
73
+ type: Boolean,
74
+ default: false
75
+ },
76
+ /** focus时,点击页面的时候不收起键盘,微信小程序有效 */
77
+ holdKeyboard: {
78
+ type: Boolean,
79
+ default: false
80
+ },
81
+ /** 自动获取焦点,在 H5 平台能否聚焦以及软键盘是否跟随弹出,取决于当前浏览器本身的实现。nvue 页面不支持,需使用组件的 focus()、blur() 方法控制焦点 */
82
+ focus: {
83
+ type: Boolean,
84
+ default: false
85
+ },
86
+ /** 键盘收起时,是否自动失去焦点,目前仅App3.0.0+有效 */
87
+ autoBlur: {
88
+ type: Boolean,
89
+ default: false
90
+ },
91
+ /** 是否去掉 iOS 下的默认内边距,仅微信小程序,且type=textarea时有效 */
92
+ disableDefaultPadding: {
93
+ type: Boolean,
94
+ default: false
95
+ },
96
+ /** 指定focus时光标的位置 */
97
+ cursor: {
98
+ type: Number,
99
+ default: 140
100
+ },
101
+ /** 输入框聚焦时底部与键盘的距离 */
102
+ cursorSpacing: {
103
+ type: Number,
104
+ default: 30
105
+ },
106
+ /** 光标起始位置,自动聚集时有效,需与selection-end搭配使用 */
107
+ selectionStart: {
108
+ type: Number,
109
+ default: -1
110
+ },
111
+ /** 光标结束位置,自动聚集时有效,需与selection-start搭配使用 */
112
+ selectionEnd: {
113
+ type: Number,
114
+ default: -1
115
+ },
116
+ /** 键盘弹起时,是否自动上推页面 */
117
+ adjustPosition: {
118
+ type: Boolean,
119
+ default: true
120
+ },
121
+ /**
122
+ * 输入框内容对齐方式
123
+ * @values left,center,right
124
+ * */
125
+ inputAlign: {
126
+ type: String,
127
+ default: 'left'
128
+ },
129
+ /** 输入框字体的大小 */
130
+ fontSize: {
131
+ type: [String, Number],
132
+ default: '15px'
133
+ },
134
+ /** 输入框字体颜色 */
135
+ color: {
136
+ type: String,
137
+ default: ''
138
+ },
139
+ /** 输入框前置图标 */
140
+ prefixIcon: {
141
+ type: Object as PropType<HyIconProps>,
142
+ default: () => {}
143
+ },
144
+ /** 输入框后置图标 */
145
+ suffixIcon: {
146
+ type: Object as PropType<HyIconProps>,
147
+ default: () => {}
148
+ },
149
+ /**
150
+ * 边框类型
151
+ * @values surround,bottom,none
152
+ * */
153
+ border: {
154
+ type: String,
155
+ default: 'surround'
156
+ },
157
+ /** 是否只读,与disabled不同之处在于disabled会置灰组件,而readonly则不会 */
158
+ readonly: {
159
+ type: Boolean,
160
+ default: false
161
+ },
162
+ /**
163
+ * 输入框形状
164
+ * @values circle,square
165
+ * */
166
+ shape: {
167
+ type: String,
168
+ default: 'square'
169
+ },
170
+ /** 是否忽略组件内对文本合成系统事件的处理 */
171
+ ignoreCompositionEvent: {
172
+ type: Boolean,
173
+ default: false
174
+ },
175
+ /** 内容式化函数 */
176
+ formatter: Function,
177
+ /** 定义需要用到的外部样式 */
178
+ customStyle: {
179
+ type: Object as PropType<CSSProperties>,
180
+ default: () => {}
181
+ },
182
+ /** 自定义外部类名 */
183
+ customClass: String
184
+ } as const
185
+
186
+ export default inputProps
@@ -1,121 +1,121 @@
1
- <template>
2
- <view class="hy-notice" @tap="clickHandler">
3
- <slot name="icon">
4
- <view class="hy-notice__left-icon" v-if="icon">
5
- <hy-icon :name="icon" :color="color" size="19"></hy-icon>
6
- </view>
7
- </slot>
8
- <view class="hy-notice__content" ref="hy-notice__content">
9
- <view
10
- ref="hy-notice__content--text"
11
- class="hy-notice__content--text"
12
- :style="animationStyle"
13
- >
14
- <text v-for="(item, index) in innerText" :key="index" :style="textStyle">{{
15
- item
16
- }}</text>
17
- </view>
18
- </view>
19
- <view class="hy-notice__right-icon" v-if="['link', 'closable'].includes(mode)">
20
- <hy-icon
21
- v-if="mode === 'link'"
22
- :name="IconConfig.RIGHT"
23
- :size="17"
24
- :color="color"
25
- ></hy-icon>
26
- <hy-icon
27
- v-if="mode === 'closable'"
28
- @click="close"
29
- :name="IconConfig.CLOSE"
30
- :size="16"
31
- :color="color"
32
- ></hy-icon>
33
- </view>
34
- </view>
35
- </template>
36
-
37
- <script setup lang="ts">
38
- import { ref, watch, toRefs, computed, type CSSProperties, getCurrentInstance } from 'vue'
39
- import noticeBarProps from './props'
40
- import { addUnit, getRect, sleep, IconConfig } from '../../libs'
41
- // 组件
42
- import HyIcon from '../hy-icon/hy-icon.vue'
43
-
44
- const props = defineProps(noticeBarProps)
45
- const { text, speed, fontSize, color } = toRefs(props)
46
- const emit = defineEmits(['click', 'close'])
47
-
48
- const instance = getCurrentInstance()
49
- const animationDuration = ref<string>('0') // 动画执行时间
50
- const animationPlayState = ref<string>('paused') // 动画的开始和结束执行
51
- const initValue = ref<string>('')
52
-
53
- watch(
54
- () => text.value,
55
- async (newValue) => {
56
- initValue.value = Array.isArray(newValue) ? newValue.join('') : newValue
57
- let boxWidth = 0,
58
- textWidth = 0
59
- // 进行一定的延时
60
- await sleep()
61
- // 查询盒子和文字的宽度
62
- textWidth = (await getRect('.hy-notice__content--text', false, instance)).width
63
- boxWidth = (await getRect('.hy-notice__content', false, instance)).width
64
- // 根据t=s/v(时间=路程/速度),这里为何不需要加上#u-notice-box的宽度,因为中设置了.u-notice-content样式中设置了padding-left: 100%
65
- // 恰巧计算出来的结果中已经包含了#u-notice-box的宽度
66
- animationDuration.value = `${textWidth / speed.value}s`
67
- // 这里必须这样开始动画,否则在APP上动画速度不会改变
68
- animationPlayState.value = 'paused'
69
- await sleep(10)
70
- animationPlayState.value = 'running'
71
- },
72
- { immediate: true }
73
- )
74
-
75
- /**
76
- * @description 文字内容的样式
77
- * */
78
- const textStyle = computed<CSSProperties>(() => {
79
- let style: CSSProperties = {}
80
- style.whiteSpace = 'nowrap !important'
81
- style.color = color.value
82
- style.fontSize = addUnit(fontSize.value)
83
- return style
84
- })
85
- /**
86
- * @description 动画的样式
87
- * */
88
- const animationStyle = computed<CSSProperties>(() => {
89
- let style: CSSProperties = {}
90
- style.animationDuration = animationDuration.value
91
- style.animationPlayState = animationPlayState.value
92
- return style
93
- })
94
- // 内部对用户传入的数据进一步分割,放到多个text标签循环,否则如果用户传入的字符串很长(100个字符以上)
95
- // 放在一个text标签中进行滚动,在低端安卓机上,动画可能会出现抖动现象,需要分割到多个text中可解决此问题
96
- const innerText = computed(() => {
97
- let result = [],
98
- // 每组text标签的字符长度
99
- len = 20
100
- const textArr = initValue.value.split('')
101
- for (let i = 0; i < textArr.length; i += len) {
102
- // 对拆分的后的text进行slice分割,得到的为数组再进行join拼接为字符串
103
- result.push(textArr.slice(i, i + len).join(''))
104
- }
105
- return result
106
- })
107
-
108
- // 点击通告栏
109
- const clickHandler = (index: number) => {
110
- emit('click', index)
111
- }
112
-
113
- // 点击关闭按钮
114
- const close = () => {
115
- emit('close')
116
- }
117
- </script>
118
-
119
- <style lang="scss" scoped>
120
- @import './index.scss';
121
- </style>
1
+ <template>
2
+ <view class="hy-notice" @tap="clickHandler">
3
+ <slot name="icon">
4
+ <view class="hy-notice__left-icon" v-if="icon">
5
+ <hy-icon :name="icon" :color="color" size="19"></hy-icon>
6
+ </view>
7
+ </slot>
8
+ <view class="hy-notice__content" ref="hy-notice__content">
9
+ <view
10
+ ref="hy-notice__content--text"
11
+ class="hy-notice__content--text"
12
+ :style="animationStyle"
13
+ >
14
+ <text v-for="(item, index) in innerText" :key="index" :style="textStyle">{{
15
+ item
16
+ }}</text>
17
+ </view>
18
+ </view>
19
+ <view class="hy-notice__right-icon" v-if="['link', 'closable'].includes(mode)">
20
+ <hy-icon
21
+ v-if="mode === 'link'"
22
+ :name="IconConfig.RIGHT"
23
+ :size="17"
24
+ :color="color"
25
+ ></hy-icon>
26
+ <hy-icon
27
+ v-if="mode === 'closable'"
28
+ @click="close"
29
+ :name="IconConfig.CLOSE"
30
+ :size="16"
31
+ :color="color"
32
+ ></hy-icon>
33
+ </view>
34
+ </view>
35
+ </template>
36
+
37
+ <script setup lang="ts">
38
+ import { ref, watch, toRefs, computed, type CSSProperties, getCurrentInstance } from 'vue'
39
+ import noticeBarProps from './props'
40
+ import { addUnit, getRect, sleep, IconConfig } from '../../libs'
41
+ // 组件
42
+ import HyIcon from '../hy-icon/hy-icon.vue'
43
+
44
+ const props = defineProps(noticeBarProps)
45
+ const { text, speed, fontSize, color } = toRefs(props)
46
+ const emit = defineEmits(['click', 'close'])
47
+
48
+ const instance = getCurrentInstance()
49
+ const animationDuration = ref<string>('0') // 动画执行时间
50
+ const animationPlayState = ref<string>('paused') // 动画的开始和结束执行
51
+ const initValue = ref<string>('')
52
+
53
+ watch(
54
+ () => text.value,
55
+ async (newValue) => {
56
+ initValue.value = Array.isArray(newValue) ? newValue.join('') : newValue
57
+ let boxWidth = 0,
58
+ textWidth = 0
59
+ // 进行一定的延时
60
+ await sleep()
61
+ // 查询盒子和文字的宽度
62
+ textWidth = (await getRect('.hy-notice__content--test', false, instance)).width
63
+ boxWidth = (await getRect('.hy-notice__content', false, instance)).width
64
+ // 根据t=s/v(时间=路程/速度),这里为何不需要加上#u-notice-box的宽度,因为中设置了.u-notice-content样式中设置了padding-left: 100%
65
+ // 恰巧计算出来的结果中已经包含了#u-notice-box的宽度
66
+ animationDuration.value = `${textWidth / speed.value}s`
67
+ // 这里必须这样开始动画,否则在APP上动画速度不会改变
68
+ animationPlayState.value = 'paused'
69
+ await sleep(10)
70
+ animationPlayState.value = 'running'
71
+ },
72
+ { immediate: true }
73
+ )
74
+
75
+ /**
76
+ * @description 文字内容的样式
77
+ * */
78
+ const textStyle = computed<CSSProperties>(() => {
79
+ let style: CSSProperties = {}
80
+ style.whiteSpace = 'nowrap !important'
81
+ style.color = color.value
82
+ style.fontSize = addUnit(fontSize.value)
83
+ return style
84
+ })
85
+ /**
86
+ * @description 动画的样式
87
+ * */
88
+ const animationStyle = computed<CSSProperties>(() => {
89
+ let style: CSSProperties = {}
90
+ style.animationDuration = animationDuration.value
91
+ style.animationPlayState = animationPlayState.value
92
+ return style
93
+ })
94
+ // 内部对用户传入的数据进一步分割,放到多个text标签循环,否则如果用户传入的字符串很长(100个字符以上)
95
+ // 放在一个text标签中进行滚动,在低端安卓机上,动画可能会出现抖动现象,需要分割到多个text中可解决此问题
96
+ const innerText = computed(() => {
97
+ let result = [],
98
+ // 每组text标签的字符长度
99
+ len = 20
100
+ const textArr = initValue.value.split('')
101
+ for (let i = 0; i < textArr.length; i += len) {
102
+ // 对拆分的后的text进行slice分割,得到的为数组再进行join拼接为字符串
103
+ result.push(textArr.slice(i, i + len).join(''))
104
+ }
105
+ return result
106
+ })
107
+
108
+ // 点击通告栏
109
+ const clickHandler = (index: number) => {
110
+ emit('click', index)
111
+ }
112
+
113
+ // 点击关闭按钮
114
+ const close = () => {
115
+ emit('close')
116
+ }
117
+ </script>
118
+
119
+ <style lang="scss" scoped>
120
+ @import './index.scss';
121
+ </style>