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.
@@ -1,275 +1,289 @@
1
- <template>
2
- <!-- #ifndef APP-NVUE -->
3
- <button
4
- :hover-start-time="Number(hoverStartTime)"
5
- :hover-stay-time="Number(hoverStayTime)"
6
- :form-type="formType"
7
- :open-type="openType"
8
- :app-parameter="appParameter"
9
- :hover-stop-propagation="hoverStopPropagation"
10
- :send-message-title="sendMessageTitle"
11
- :send-message-path="sendMessagePath"
12
- :lang="lang"
13
- :data-name="dataName"
14
- :session-from="sessionFrom"
15
- :send-message-img="sendMessageImg"
16
- :show-message-card="showMessageCard"
17
- @getphonenumber="getphonenumber"
18
- @getuserinfo="getuserinfo"
19
- @error="error"
20
- @opensetting="opensetting"
21
- @launchapp="launchapp"
22
- @agreeprivacyauthorization="agreeprivacyauthorization"
23
- :hover-class="!disabled && !loading ? 'hy-button--active' : ''"
24
- :style="[baseColor, customStyle]"
25
- @click="clickHandler"
26
- :class="['hy-button', border ? '' : 'hy-button__no-border', bemClass, customClass]"
27
- >
28
- <template v-if="loading">
29
- <HyLoading :mode="loadingMode" :size="loadingSize" :color="loadingColor"></HyLoading>
30
- <text class="hy-button__loading-text" :style="[{ fontSize: textSize + 'px' }]">
31
- {{ loadingText || text }}
32
- </text>
33
- </template>
34
- <template v-else>
35
- <hy-icon
36
- v-if="icon?.name"
37
- :name="icon?.name"
38
- :color="iconColorCom"
39
- :size="icon?.size || textSize * 1.35"
40
- :bold="icon?.bold"
41
- :customPrefix="icon?.customPrefix"
42
- :imgMode="icon?.imgMode"
43
- :width="icon?.width"
44
- :height="icon?.height"
45
- :top="icon?.top"
46
- :stop="icon?.stop"
47
- :round="icon?.round"
48
- :customStyle="icon?.customStyle || { marginRight: '2px' }"
49
- ></hy-icon>
50
- <!-- @slot 插入默认的值 -->
51
- <slot v-if="$slots.default"></slot>
52
- <text v-else class="hy-button__text" :style="[{ fontSize: textSize + 'px' }]">{{
53
- text
54
- }}</text>
55
- </template>
56
- </button>
57
- <!-- #endif -->
58
-
59
- <!-- #ifdef APP-NVUE -->
60
- <view
61
- :hover-start-time="Number(hoverStartTime)"
62
- :hover-stay-time="Number(hoverStayTime)"
63
- class="hy-button"
64
- :hover-class="
65
- !disabled && !loading && !color && (plain || type === 'info')
66
- ? 'hy-button--active--plain'
67
- : !disabled && !loading && !plain
68
- ? 'hy-button--active'
69
- : ''
70
- "
71
- @click="clickHandler"
72
- :class="bemClass"
73
- :style="[baseColor, customStyle]"
74
- >
75
- <template v-if="loading">
76
- <HyLoading :mode="loadingMode" :size="loadingSize" :color="loadingColor"></HyLoading>
77
- <text
78
- class="hy-button__loading-text"
79
- :style="[nvueTextStyle]"
80
- :class="[plain && `hy-button__text--plain--${type}`]"
81
- >
82
- {{ loadingText || text }}
83
- </text>
84
- </template>
85
- <template v-else>
86
- <hy-icon
87
- v-if="icon?.name"
88
- :name="icon?.name"
89
- :color="iconColorCom"
90
- :size="icon?.size || textSize * 1.35"
91
- :bold="icon?.bold"
92
- :customPrefix="icon?.customPrefix"
93
- :imgMode="icon?.imgMode"
94
- :width="icon?.width"
95
- :height="icon?.height"
96
- :top="icon?.top"
97
- :stop="icon?.stop"
98
- :round="icon?.round"
99
- :customStyle="icon?.customStyle || { marginRight: '2px' }"
100
- ></hy-icon>
101
- <text
102
- class="hy-button__text"
103
- :style="[
104
- {
105
- marginLeft: icon ? '2px' : 0
106
- },
107
- nvueTextStyle
108
- ]"
109
- :class="[plain && `hy-button__text--plain--${type}`]"
110
- >
111
- {{ text }}
112
- </text>
113
- </template>
114
- </view>
115
- <!-- #endif -->
116
- </template>
117
-
118
- <script lang="ts">
119
- export default {
120
- name: 'hy-button',
121
- options: {
122
- addGlobalClass: true,
123
- virtualHost: true,
124
- styleIsolation: 'shared'
125
- }
126
- }
127
- </script>
128
-
129
- <script setup lang="ts">
130
- import { computed } from 'vue'
131
- import type { CSSProperties } from 'vue'
132
- import { ColorConfig, bem, throttle } from '../../libs'
133
- import type { IButtonEmits } from './typing'
134
- import buttonProps from '../hy-button/props'
135
- // 组件
136
- import HyIcon from '../hy-icon/hy-icon.vue'
137
- import HyLoading from '../hy-loading/hy-loading.vue'
138
-
139
- /**
140
- * 该组件内部实现以uni-app的基础button组件为基础,进行二次封装
141
- * @displayName hy-button
142
- */
143
- defineOptions({})
144
-
145
- const props = defineProps(buttonProps)
146
- const emit = defineEmits<IButtonEmits>()
147
-
148
- const textColor = (ColorConfig as any)[props.type]
149
-
150
- /**
151
- * @description 生成bem风格的类名
152
- */
153
- const bemClass = computed(() => {
154
- // this.bem为一个computed变量,在mixin中
155
- if (!props.color) {
156
- return bem('button', props, ['type', 'shape', 'size'], ['disabled', 'plain', 'hairline'])
157
- } else {
158
- // 由于nvue的原因,在有color参数时,不需要传入type,否则会生成type相关的类型,影响最终的样式
159
- return bem('button', props, ['shape', 'size'], ['disabled', 'plain', 'hairline'])
160
- }
161
- })
162
-
163
- const loadingColor = computed(() => {
164
- if (props.plain) {
165
- // 如果有设置color值,则用color值,否则使用type主题颜色
166
- return props.color ? props.color : ''
167
- }
168
- if (props.type === 'info') {
169
- return '#c9c9c9'
170
- }
171
- return '#fff'
172
- })
173
-
174
- const iconColorCom = computed((): string => {
175
- // 如果是镂空状态,设置了color就用color值,否则使用主题颜色,
176
- if (props.icon?.color) return props.icon?.color
177
- if (props.plain) {
178
- return props.color ? props.color : ''
179
- } else {
180
- return '#ffffff'
181
- }
182
- })
183
- const baseColor = computed((): CSSProperties => {
184
- let style: CSSProperties = {}
185
- if (props.color) {
186
- // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
187
- style.color = props.plain ? props.color : 'white'
188
- if (!props.plain) {
189
- // 非镂空,背景色使用自定义的颜色
190
- style['background'] = props.color
191
- }
192
- if (props.color.indexOf('gradient') !== -1) {
193
- // 如果自定义的颜色为渐变色,不显示边框,以及通过backgroundImage设置渐变色
194
- // weex文档说明可以写borderWidth的形式,为什么这里需要分开写?
195
- // 因为weex是阿里巴巴为了部门业绩考核而做的你懂的东西,所以需要这么写才有效
196
- style.borderTopWidth = 0
197
- style.borderRightWidth = 0
198
- style.borderBottomWidth = 0
199
- style.borderLeftWidth = 0
200
- if (!props.plain) {
201
- style.backgroundImage = props.color
202
- }
203
- } else {
204
- // 非渐变色,则设置边框相关的属性
205
- style.borderColor = props.color
206
- style.borderWidth = '1px'
207
- style.borderStyle = 'solid'
208
- }
209
- } else {
210
- // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
211
- // style.color = props.plain ? textColor : "";
212
- }
213
- return style
214
- })
215
-
216
- // nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
217
- const nvueTextStyle = computed((): CSSProperties => {
218
- let style: CSSProperties = {}
219
- // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
220
- if (props.type === 'info') {
221
- style.color = '#323233'
222
- }
223
- if (props.color) {
224
- style.color = props.plain ? props.color : 'white'
225
- }
226
- style.fontSize = textSize.value + 'px'
227
- return style
228
- })
229
- /**
230
- * @description 字体大小
231
- * */
232
- const textSize = computed((): number => {
233
- let fontSize = 14
234
- if (props.size === 'large') fontSize = 16
235
- if (props.size === 'medium') fontSize = 14
236
- if (props.size === 'small') fontSize = 12
237
- if (props.size === 'mini') fontSize = 10
238
- return fontSize
239
- })
240
-
241
- const clickHandler = (e: any) => {
242
- // 非禁止并且非加载中,才能点击
243
- if (!props.disabled && !props.loading) {
244
- // 进行节流控制,每this.throttle毫秒内,只在开始处执行
245
- throttle(() => {
246
- emit('click', e)
247
- }, props.throttleTime)
248
- }
249
- // 是否阻止事件传播
250
- props.stop && e.stopPropagation()
251
- }
252
-
253
- const getphonenumber = (e: any) => {
254
- emit('getphonenumber', e)
255
- }
256
- const getuserinfo = (e: any) => {
257
- emit('getuserinfo', e)
258
- }
259
- const error = (e: any) => {
260
- emit('error', e)
261
- }
262
- const opensetting = (e: any) => {
263
- emit('opensetting', e)
264
- }
265
- const launchapp = (e: any) => {
266
- emit('launchapp', e)
267
- }
268
- const agreeprivacyauthorization = (e: any) => {
269
- emit('agreeprivacyauthorization', e)
270
- }
271
- </script>
272
-
273
- <style lang="scss" scoped>
274
- @import './index.scss';
275
- </style>
1
+ <template>
2
+ <!-- #ifndef APP-NVUE -->
3
+ <button
4
+ :hover-start-time="Number(hoverStartTime)"
5
+ :hover-stay-time="Number(hoverStayTime)"
6
+ :form-type="formType"
7
+ :open-type="openType"
8
+ :lang="lang"
9
+ :scope="scope"
10
+ :data-name="dataName"
11
+ :app-parameter="appParameter"
12
+ :hover-stop-propagation="hoverStopPropagation"
13
+ :send-message-title="sendMessageTitle"
14
+ :send-message-path="sendMessagePath"
15
+ :session-from="sessionFrom"
16
+ :send-message-img="sendMessageImg"
17
+ :show-message-card="showMessageCard"
18
+ @getphonenumber="getphonenumber"
19
+ @getuserinfo="getuserinfo"
20
+ @getAuthorize="getAuthorize"
21
+ @error="error"
22
+ @opensetting="opensetting"
23
+ @launchapp="launchapp"
24
+ @agreeprivacyauthorization="agreeprivacyauthorization"
25
+ :hover-class="!disabled && !loading ? 'hy-button--active' : ''"
26
+ :style="[baseColor, customStyle]"
27
+ @click="clickHandler"
28
+ :class="['hy-button', border ? '' : 'hy-button__no-border', bemClass, customClass]"
29
+ >
30
+ <template v-if="loading">
31
+ <HyLoading :mode="loadingMode" :size="loadingSize" :color="loadingColor"></HyLoading>
32
+ <text class="hy-button__loading-text" :style="[{ fontSize: textSize + 'px' }]">
33
+ {{ loadingText || text }}
34
+ </text>
35
+ </template>
36
+ <template v-else>
37
+ <hy-icon
38
+ v-if="icon?.name"
39
+ :name="icon?.name"
40
+ :color="iconColorCom"
41
+ :size="icon?.size || textSize * 1.35"
42
+ :bold="icon?.bold"
43
+ :customPrefix="icon?.customPrefix"
44
+ :imgMode="icon?.imgMode"
45
+ :width="icon?.width"
46
+ :height="icon?.height"
47
+ :top="icon?.top"
48
+ :stop="icon?.stop"
49
+ :round="icon?.round"
50
+ :customStyle="icon?.customStyle || { marginRight: '2px' }"
51
+ ></hy-icon>
52
+ <!-- @slot 插入默认的值 -->
53
+ <slot v-if="$slots.default"></slot>
54
+ <text v-else class="hy-button__text" :style="[{ fontSize: textSize + 'px' }]">{{
55
+ text
56
+ }}</text>
57
+ </template>
58
+ </button>
59
+ <!-- #endif -->
60
+
61
+ <!-- #ifdef APP-NVUE -->
62
+ <view
63
+ :hover-start-time="Number(hoverStartTime)"
64
+ :hover-stay-time="Number(hoverStayTime)"
65
+ class="hy-button"
66
+ :hover-class="
67
+ !disabled && !loading && !color && (plain || type === 'info')
68
+ ? 'hy-button--active--plain'
69
+ : !disabled && !loading && !plain
70
+ ? 'hy-button--active'
71
+ : ''
72
+ "
73
+ @click="clickHandler"
74
+ :class="bemClass"
75
+ :style="[baseColor, customStyle]"
76
+ >
77
+ <template v-if="loading">
78
+ <HyLoading :mode="loadingMode" :size="loadingSize" :color="loadingColor"></HyLoading>
79
+ <text
80
+ class="hy-button__loading-text"
81
+ :style="[nvueTextStyle]"
82
+ :class="[plain && `hy-button__text--plain--${type}`]"
83
+ >
84
+ {{ loadingText || text }}
85
+ </text>
86
+ </template>
87
+ <template v-else>
88
+ <hy-icon
89
+ v-if="icon?.name"
90
+ :name="icon?.name"
91
+ :color="iconColorCom"
92
+ :size="icon?.size || textSize * 1.35"
93
+ :bold="icon?.bold"
94
+ :customPrefix="icon?.customPrefix"
95
+ :imgMode="icon?.imgMode"
96
+ :width="icon?.width"
97
+ :height="icon?.height"
98
+ :top="icon?.top"
99
+ :stop="icon?.stop"
100
+ :round="icon?.round"
101
+ :customStyle="icon?.customStyle || { marginRight: '2px' }"
102
+ ></hy-icon>
103
+ <text
104
+ class="hy-button__text"
105
+ :style="[
106
+ {
107
+ marginLeft: icon ? '2px' : 0
108
+ },
109
+ nvueTextStyle
110
+ ]"
111
+ :class="[plain && `hy-button__text--plain--${type}`]"
112
+ >
113
+ {{ text }}
114
+ </text>
115
+ </template>
116
+ </view>
117
+ <!-- #endif -->
118
+ </template>
119
+
120
+ <script lang="ts">
121
+ export default {
122
+ name: 'hy-button',
123
+ options: {
124
+ addGlobalClass: true,
125
+ virtualHost: true,
126
+ styleIsolation: 'shared'
127
+ }
128
+ }
129
+ </script>
130
+
131
+ <script setup lang="ts">
132
+ import { computed } from 'vue'
133
+ import type { CSSProperties } from 'vue'
134
+ import { ColorConfig, bem, throttle } from '../../libs'
135
+ import type { IButtonEmits } from './typing'
136
+ import buttonProps from '../hy-button/props'
137
+ // 组件
138
+ import HyIcon from '../hy-icon/hy-icon.vue'
139
+ import HyLoading from '../hy-loading/hy-loading.vue'
140
+
141
+ /**
142
+ * 该组件内部实现以uni-app的基础button组件为基础,进行二次封装
143
+ * @displayName hy-button
144
+ */
145
+ defineOptions({})
146
+
147
+ const props = defineProps(buttonProps)
148
+ const emit = defineEmits<IButtonEmits>()
149
+
150
+ const textColor = (ColorConfig as any)[props.type]
151
+
152
+ /**
153
+ * @description 生成bem风格的类名
154
+ */
155
+ const bemClass = computed(() => {
156
+ // this.bem为一个computed变量,在mixin中
157
+ if (!props.color) {
158
+ return bem('button', props, ['type', 'shape', 'size'], ['disabled', 'plain', 'hairline'])
159
+ } else {
160
+ // 由于nvue的原因,在有color参数时,不需要传入type,否则会生成type相关的类型,影响最终的样式
161
+ return bem('button', props, ['shape', 'size'], ['disabled', 'plain', 'hairline'])
162
+ }
163
+ })
164
+
165
+ const loadingColor = computed(() => {
166
+ if (props.plain) {
167
+ // 如果有设置color值,则用color值,否则使用type主题颜色
168
+ return props.color ? props.color : ''
169
+ }
170
+ if (props.type === 'info') {
171
+ return '#c9c9c9'
172
+ }
173
+ return '#fff'
174
+ })
175
+
176
+ const iconColorCom = computed((): string => {
177
+ // 如果是镂空状态,设置了color就用color值,否则使用主题颜色,
178
+ if (props.icon?.color) return props.icon?.color
179
+ if (props.plain) {
180
+ return props.color ? props.color : ''
181
+ } else {
182
+ return '#ffffff'
183
+ }
184
+ })
185
+ const baseColor = computed((): CSSProperties => {
186
+ let style: CSSProperties = {}
187
+ if (props.color) {
188
+ // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
189
+ style.color = props.plain ? props.color : 'white'
190
+ if (!props.plain) {
191
+ // 非镂空,背景色使用自定义的颜色
192
+ style['background'] = props.color
193
+ }
194
+ if (props.color.indexOf('gradient') !== -1) {
195
+ // 如果自定义的颜色为渐变色,不显示边框,以及通过backgroundImage设置渐变色
196
+ // weex文档说明可以写borderWidth的形式,为什么这里需要分开写?
197
+ // 因为weex是阿里巴巴为了部门业绩考核而做的你懂的东西,所以需要这么写才有效
198
+ style.borderTopWidth = 0
199
+ style.borderRightWidth = 0
200
+ style.borderBottomWidth = 0
201
+ style.borderLeftWidth = 0
202
+ if (!props.plain) {
203
+ style.backgroundImage = props.color
204
+ }
205
+ } else {
206
+ // 非渐变色,则设置边框相关的属性
207
+ style.borderColor = props.color
208
+ style.borderWidth = '1px'
209
+ style.borderStyle = 'solid'
210
+ }
211
+ } else {
212
+ // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
213
+ // style.color = props.plain ? textColor : "";
214
+ }
215
+ return style
216
+ })
217
+
218
+ // nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
219
+ const nvueTextStyle = computed((): CSSProperties => {
220
+ let style: CSSProperties = {}
221
+ // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
222
+ if (props.type === 'info') {
223
+ style.color = '#323233'
224
+ }
225
+ if (props.color) {
226
+ style.color = props.plain ? props.color : 'white'
227
+ }
228
+ style.fontSize = textSize.value + 'px'
229
+ return style
230
+ })
231
+ /**
232
+ * 字体大小
233
+ * */
234
+ const textSize = computed((): number => {
235
+ let fontSize = 14
236
+ if (props.size === 'large') fontSize = 16
237
+ if (props.size === 'medium') fontSize = 14
238
+ if (props.size === 'small') fontSize = 12
239
+ if (props.size === 'mini') fontSize = 10
240
+ return fontSize
241
+ })
242
+
243
+ const clickHandler = (e: any) => {
244
+ // 非禁止并且非加载中,才能点击
245
+ if (!props.disabled && !props.loading) {
246
+ // 进行节流控制,每this.throttle毫秒内,只在开始处执行
247
+ throttle(() => {
248
+ emit('click', e)
249
+ }, props.throttleTime)
250
+ }
251
+ // 是否阻止事件传播
252
+ props.stop && e.stopPropagation()
253
+ }
254
+
255
+ /**
256
+ * 支付宝小程序授权
257
+ * @param e
258
+ */
259
+ function getAuthorize(e: any) {
260
+ if (props.scope === 'phoneNumber') {
261
+ getphonenumber(e)
262
+ } else if (props.scope === 'userInfo') {
263
+ getuserinfo(e)
264
+ }
265
+ }
266
+
267
+ const getphonenumber = (e: any) => {
268
+ emit('getphonenumber', e)
269
+ }
270
+ const getuserinfo = (e: any) => {
271
+ emit('getuserinfo', e)
272
+ }
273
+ const error = (e: any) => {
274
+ emit('error', e)
275
+ }
276
+ const opensetting = (e: any) => {
277
+ emit('opensetting', e)
278
+ }
279
+ const launchapp = (e: any) => {
280
+ emit('launchapp', e)
281
+ }
282
+ const agreeprivacyauthorization = (e: any) => {
283
+ emit('agreeprivacyauthorization', e)
284
+ }
285
+ </script>
286
+
287
+ <style lang="scss" scoped>
288
+ @import './index.scss';
289
+ </style>
@@ -15,8 +15,31 @@
15
15
  /* #endif */
16
16
  flex-direction: row;
17
17
 
18
+ /* 亮光效果 */
19
+ &::before {
20
+ content: '';
21
+ position: absolute;
22
+ top: 0;
23
+ left: -100%;
24
+ width: 100%;
25
+ height: 100%;
26
+ background: linear-gradient(
27
+ 90deg,
28
+ transparent,
29
+ rgba(255, 255, 255, 0.4),
30
+ transparent
31
+ );
32
+ transition: left 0.7s;
33
+ z-index: 1;
34
+ }
35
+ &:active::before {
36
+ left: 100%;
37
+ transition: left 0.2s;
38
+ }
39
+
40
+
18
41
  /* 去除原生按钮边框 */
19
- &:after {
42
+ &::after {
20
43
  border: none !important;
21
44
  }
22
45