hy-app 0.2.6 → 0.2.8
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.
- package/common/shakeService.ts +0 -2
- package/components/hy-address-picker/hy-address-picker.vue +75 -91
- package/components/hy-avatar/hy-avatar.vue +64 -73
- package/components/hy-button/hy-button.vue +2 -2
- package/components/hy-float-button/hy-float-button.vue +115 -37
- package/components/hy-float-button/props.ts +3 -3
- package/components/hy-float-button/typing.d.ts +20 -7
- package/components/hy-icon/hy-icon.vue +1 -1
- package/components/hy-image/hy-image.vue +69 -104
- package/components/hy-image/index.scss +21 -5
- package/components/hy-image/props.ts +11 -10
- package/components/hy-image/typing.d.ts +23 -19
- package/components/hy-modal/index.scss +1 -1
- package/components/hy-popover/hy-popover.vue +200 -0
- package/components/hy-popover/index.scss +83 -0
- package/components/hy-popover/props.ts +13 -0
- package/components/hy-popover/typing.d.ts +56 -0
- package/components/hy-qrcode/hy-qrcode.vue +44 -45
- package/components/hy-rate/props.ts +6 -6
- package/components/hy-transition/hy-transition.vue +64 -72
- package/components/hy-transition/typing.d.ts +10 -6
- package/composables/index.ts +4 -2
- package/composables/usePopover.ts +221 -0
- package/composables/useQueue.ts +52 -0
- package/libs/css/mixin.scss +88 -0
- package/package.json +2 -2
- package/utils/inside.ts +96 -108
package/common/shakeService.ts
CHANGED
|
@@ -17,7 +17,6 @@ export function useShakeService(shakeThreshold: number = 30) {
|
|
|
17
17
|
shakeCallback.value = callback
|
|
18
18
|
uni.startAccelerometer({
|
|
19
19
|
success: () => {
|
|
20
|
-
console.log('加速度传感器启动成功')
|
|
21
20
|
uni.onAccelerometerChange(handleShake)
|
|
22
21
|
},
|
|
23
22
|
fail: (err: any) => {
|
|
@@ -29,7 +28,6 @@ export function useShakeService(shakeThreshold: number = 30) {
|
|
|
29
28
|
const stopShakeListener = (): void => {
|
|
30
29
|
uni.stopAccelerometer().then(
|
|
31
30
|
(res) => {
|
|
32
|
-
console.log('加速度传感器关闭成功', res)
|
|
33
31
|
uni.offAccelerometerChange(handleShake)
|
|
34
32
|
},
|
|
35
33
|
(err) => console.error('加速度传感器关闭失败', err.errMsg),
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-datetime-picker">
|
|
3
|
-
<view
|
|
4
|
-
v-if="hasInput"
|
|
5
|
-
class="u-datetime-picker__has-input"
|
|
6
|
-
@tap="onShowByClickInput"
|
|
7
|
-
>
|
|
3
|
+
<view v-if="hasInput" class="u-datetime-picker__has-input" @tap="onShowByClickInput">
|
|
8
4
|
<slot name="trigger" :value="inputValue">
|
|
9
5
|
<HyInput
|
|
10
6
|
v-model="inputValue"
|
|
@@ -21,9 +17,7 @@
|
|
|
21
17
|
:placeholder="input?.placeholder || '请选择地址'"
|
|
22
18
|
:placeholderStyle="input?.placeholderStyle"
|
|
23
19
|
:placeholderClass="input?.placeholderClass"
|
|
24
|
-
:customStyle="
|
|
25
|
-
Object.assign({ 'pointer-events': 'none' }, input?.customStyle)
|
|
26
|
-
"
|
|
20
|
+
:customStyle="Object.assign({ 'pointer-events': 'none' }, input?.customStyle)"
|
|
27
21
|
></HyInput>
|
|
28
22
|
<view class="input-cover"></view>
|
|
29
23
|
</slot>
|
|
@@ -56,7 +50,7 @@
|
|
|
56
50
|
</slot>
|
|
57
51
|
</template>
|
|
58
52
|
<template #toolbar-bottom>
|
|
59
|
-
<slot name="toolbar-bottom"
|
|
53
|
+
<slot name="toolbar-bottom"></slot>
|
|
60
54
|
</template>
|
|
61
55
|
</HyPicker>
|
|
62
56
|
</view>
|
|
@@ -68,112 +62,103 @@ export default {
|
|
|
68
62
|
options: {
|
|
69
63
|
addGlobalClass: true,
|
|
70
64
|
virtualHost: true,
|
|
71
|
-
styleIsolation: 'shared'
|
|
72
|
-
}
|
|
65
|
+
styleIsolation: 'shared',
|
|
66
|
+
},
|
|
73
67
|
}
|
|
74
68
|
</script>
|
|
75
69
|
|
|
76
70
|
<script setup lang="ts">
|
|
77
|
-
import { onMounted, ref, toRefs } from
|
|
78
|
-
import defaultProps from
|
|
79
|
-
import type IProps from
|
|
80
|
-
import address from
|
|
71
|
+
import { onMounted, ref, toRefs } from 'vue'
|
|
72
|
+
import defaultProps from './props'
|
|
73
|
+
import type IProps from './typing'
|
|
74
|
+
import address from '../../utils/address.json'
|
|
81
75
|
|
|
82
76
|
// 组件
|
|
83
|
-
import HyInput from
|
|
84
|
-
import HyPicker from
|
|
85
|
-
|
|
86
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
87
|
-
const { show, modelValue, hasInput, input, separator, closeOnClickOverlay } =
|
|
88
|
-
|
|
89
|
-
const emit = defineEmits([
|
|
90
|
-
"close",
|
|
91
|
-
"cancel",
|
|
92
|
-
"confirm",
|
|
93
|
-
"change",
|
|
94
|
-
"update:modelValue",
|
|
95
|
-
]);
|
|
77
|
+
import HyInput from '../hy-input/hy-input.vue'
|
|
78
|
+
import HyPicker from '../hy-picker/hy-picker.vue'
|
|
79
|
+
|
|
80
|
+
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
81
|
+
const { show, modelValue, hasInput, input, separator, closeOnClickOverlay } = toRefs(props)
|
|
82
|
+
const emit = defineEmits(['close', 'cancel', 'confirm', 'change', 'update:modelValue'])
|
|
96
83
|
|
|
97
84
|
// 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
|
|
98
|
-
const inputValue = ref<string>(
|
|
99
|
-
const showByClickInput = ref<boolean>(false)
|
|
100
|
-
const columns = ref<any[]>([])
|
|
101
|
-
const uPickerRef = ref<InstanceType<typeof HyPicker> | null>()
|
|
102
|
-
const defaultIndex = ref<number[]>([])
|
|
85
|
+
const inputValue = ref<string>('') // 表单显示值
|
|
86
|
+
const showByClickInput = ref<boolean>(false) // 是否在hasInput模式下显示日期选择
|
|
87
|
+
const columns = ref<any[]>([])
|
|
88
|
+
const uPickerRef = ref<InstanceType<typeof HyPicker> | null>()
|
|
89
|
+
const defaultIndex = ref<number[]>([])
|
|
103
90
|
|
|
104
91
|
function normalizeCityName(city: string) {
|
|
105
92
|
// 定义常见的后缀
|
|
106
|
-
const suffixes = [
|
|
93
|
+
const suffixes = ['市', '省', '自治区', '特别行政区', '县', '区']
|
|
107
94
|
suffixes.forEach((suffix) => {
|
|
108
95
|
if (city.endsWith(suffix)) {
|
|
109
|
-
city = city.slice(0, -suffix.length)
|
|
96
|
+
city = city.slice(0, -suffix.length)
|
|
110
97
|
}
|
|
111
|
-
})
|
|
112
|
-
return city
|
|
98
|
+
})
|
|
99
|
+
return city
|
|
113
100
|
}
|
|
114
101
|
/**
|
|
115
102
|
* @description 判断城市是否相等
|
|
116
103
|
* */
|
|
117
104
|
const areCitiesEqual = (city1: string, city2: string) => {
|
|
118
|
-
const normalizedCity1 = normalizeCityName(city1)
|
|
119
|
-
const normalizedCity2 = normalizeCityName(city2)
|
|
120
|
-
return normalizedCity1 === normalizedCity2
|
|
121
|
-
}
|
|
105
|
+
const normalizedCity1 = normalizeCityName(city1)
|
|
106
|
+
const normalizedCity2 = normalizeCityName(city2)
|
|
107
|
+
return normalizedCity1 === normalizedCity2
|
|
108
|
+
}
|
|
122
109
|
/**
|
|
123
110
|
* @description 更新各列的值
|
|
124
111
|
* */
|
|
125
112
|
const updateColumnValue = (value: string) => {
|
|
126
|
-
let provinceIndex, cityIndex, countyIndex
|
|
113
|
+
let provinceIndex, cityIndex, countyIndex
|
|
127
114
|
// 判断是初始化有数据就找到对应索引,无数据默认索引为0
|
|
128
115
|
if (value) {
|
|
129
|
-
const addressArr = value.split(separator.value)
|
|
116
|
+
const addressArr = value.split(separator.value)
|
|
130
117
|
// 查出省索引
|
|
131
|
-
provinceIndex = address.findIndex((item) =>
|
|
132
|
-
areCitiesEqual(item.name, addressArr[0]),
|
|
133
|
-
);
|
|
118
|
+
provinceIndex = address.findIndex((item) => areCitiesEqual(item.name, addressArr[0]))
|
|
134
119
|
// 查出市索引
|
|
135
120
|
cityIndex = address[provinceIndex].areas.findIndex((item) =>
|
|
136
121
|
areCitiesEqual(item.name, addressArr[1]),
|
|
137
|
-
)
|
|
122
|
+
)
|
|
138
123
|
|
|
139
124
|
// 查出县/区索引
|
|
140
|
-
countyIndex = address[provinceIndex].areas[cityIndex].areas.findIndex(
|
|
141
|
-
|
|
142
|
-
)
|
|
125
|
+
countyIndex = address[provinceIndex].areas[cityIndex].areas.findIndex((item) =>
|
|
126
|
+
areCitiesEqual(item.name, addressArr[2]),
|
|
127
|
+
)
|
|
143
128
|
} else {
|
|
144
|
-
provinceIndex = 0
|
|
145
|
-
cityIndex = 0
|
|
146
|
-
countyIndex = 0
|
|
129
|
+
provinceIndex = 0
|
|
130
|
+
cityIndex = 0
|
|
131
|
+
countyIndex = 0
|
|
147
132
|
}
|
|
148
133
|
// 省级数组
|
|
149
134
|
const provinceData = address.map((item) => ({
|
|
150
135
|
name: item.name,
|
|
151
136
|
code: item.code,
|
|
152
|
-
}))
|
|
137
|
+
}))
|
|
153
138
|
// 市级数组
|
|
154
139
|
const cityData = address[provinceIndex].areas.map((item) => ({
|
|
155
140
|
name: item.name,
|
|
156
141
|
code: item.code,
|
|
157
|
-
}))
|
|
142
|
+
}))
|
|
158
143
|
// 县/区级数组
|
|
159
|
-
const areaData = address[provinceIndex].areas[cityIndex].areas
|
|
144
|
+
const areaData = address[provinceIndex].areas[cityIndex].areas
|
|
160
145
|
|
|
161
146
|
// 默认索引
|
|
162
|
-
defaultIndex.value = [provinceIndex, cityIndex, countyIndex]
|
|
147
|
+
defaultIndex.value = [provinceIndex, cityIndex, countyIndex]
|
|
163
148
|
// 列表
|
|
164
|
-
columns.value = [provinceData, cityData, areaData]
|
|
165
|
-
}
|
|
149
|
+
columns.value = [provinceData, cityData, areaData]
|
|
150
|
+
}
|
|
166
151
|
|
|
167
152
|
const init = () => {
|
|
168
153
|
// 获取当前值
|
|
169
|
-
inputValue.value = modelValue.value
|
|
154
|
+
inputValue.value = modelValue.value
|
|
170
155
|
// 更新列表
|
|
171
|
-
updateColumnValue(modelValue.value)
|
|
172
|
-
}
|
|
156
|
+
updateColumnValue(modelValue.value)
|
|
157
|
+
}
|
|
173
158
|
|
|
174
159
|
onMounted(() => {
|
|
175
|
-
init()
|
|
176
|
-
})
|
|
160
|
+
init()
|
|
161
|
+
})
|
|
177
162
|
|
|
178
163
|
/**
|
|
179
164
|
* @description 关闭选择器
|
|
@@ -181,75 +166,74 @@ onMounted(() => {
|
|
|
181
166
|
const close = () => {
|
|
182
167
|
if (closeOnClickOverlay.value) {
|
|
183
168
|
if (hasInput.value) {
|
|
184
|
-
showByClickInput.value = false
|
|
169
|
+
showByClickInput.value = false
|
|
185
170
|
}
|
|
186
|
-
emit(
|
|
171
|
+
emit('close')
|
|
187
172
|
}
|
|
188
|
-
}
|
|
173
|
+
}
|
|
189
174
|
|
|
190
175
|
/**
|
|
191
176
|
* @description 点击工具栏的取消按钮
|
|
192
177
|
* */
|
|
193
178
|
const cancel = () => {
|
|
194
179
|
if (hasInput.value) {
|
|
195
|
-
showByClickInput.value = false
|
|
180
|
+
showByClickInput.value = false
|
|
196
181
|
}
|
|
197
|
-
emit(
|
|
198
|
-
}
|
|
182
|
+
emit('cancel')
|
|
183
|
+
}
|
|
199
184
|
|
|
200
185
|
/**
|
|
201
186
|
* @description 点击工具栏的确定按钮
|
|
202
187
|
* */
|
|
203
188
|
const confirm = ({ value }: { value: Record<string, any>[] }) => {
|
|
204
|
-
inputValue.value = value.map((item) => item.name).join(separator.value)
|
|
189
|
+
inputValue.value = value.map((item) => item.name).join(separator.value)
|
|
205
190
|
|
|
206
|
-
showByClickInput.value = false
|
|
207
|
-
emit(
|
|
208
|
-
emit(
|
|
191
|
+
showByClickInput.value = false
|
|
192
|
+
emit('update:modelValue', inputValue.value)
|
|
193
|
+
emit('confirm', {
|
|
209
194
|
value: inputValue.value,
|
|
210
|
-
})
|
|
211
|
-
}
|
|
195
|
+
})
|
|
196
|
+
}
|
|
212
197
|
|
|
213
198
|
/**
|
|
214
199
|
* @description 列发生变化时触发
|
|
215
200
|
* */
|
|
216
201
|
const change = (e: any) => {
|
|
217
|
-
const { columnIndex, index, indexs } = e
|
|
202
|
+
const { columnIndex, index, indexs } = e
|
|
218
203
|
//如果改变的是第一列
|
|
219
204
|
if (columnIndex === 0) {
|
|
220
205
|
const children1 = address[index].areas.map((item) => {
|
|
221
|
-
return { name: item.name, code: item.code }
|
|
222
|
-
})
|
|
223
|
-
uPickerRef.value?.setColumnValues(1, children1)
|
|
206
|
+
return { name: item.name, code: item.code }
|
|
207
|
+
})
|
|
208
|
+
uPickerRef.value?.setColumnValues(1, children1)
|
|
224
209
|
//更换 第二列数据
|
|
225
210
|
const children2 = address[index].areas[indexs[1]].areas.map((item) => ({
|
|
226
211
|
...item,
|
|
227
|
-
}))
|
|
228
|
-
uPickerRef.value?.setColumnValues(2, children2)
|
|
212
|
+
}))
|
|
213
|
+
uPickerRef.value?.setColumnValues(2, children2)
|
|
229
214
|
//更换 第三列数据
|
|
230
215
|
}
|
|
231
216
|
if (columnIndex === 1) {
|
|
232
217
|
//如果改变的是第二列
|
|
233
218
|
const children3 = address[indexs[0]].areas[indexs[1]].areas.map((item) => ({
|
|
234
219
|
...item,
|
|
235
|
-
}))
|
|
236
|
-
uPickerRef.value?.setColumnValues(2, children3)
|
|
220
|
+
}))
|
|
221
|
+
uPickerRef.value?.setColumnValues(2, children3)
|
|
237
222
|
}
|
|
238
223
|
|
|
239
224
|
// 发出change时间,value为当前选中的时间戳
|
|
240
|
-
emit(
|
|
225
|
+
emit('change', {
|
|
241
226
|
...e,
|
|
242
|
-
})
|
|
243
|
-
}
|
|
227
|
+
})
|
|
228
|
+
}
|
|
244
229
|
|
|
245
230
|
const onShowByClickInput = () => {
|
|
246
|
-
console.log(input.value?.disabled);
|
|
247
231
|
if (!input.value?.disabled) {
|
|
248
|
-
showByClickInput.value = !showByClickInput.value
|
|
232
|
+
showByClickInput.value = !showByClickInput.value
|
|
249
233
|
}
|
|
250
|
-
}
|
|
234
|
+
}
|
|
251
235
|
</script>
|
|
252
236
|
|
|
253
237
|
<style lang="scss" scoped>
|
|
254
|
-
@import
|
|
238
|
+
@import './index.scss';
|
|
255
239
|
</style>
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view
|
|
3
|
-
class="hy-avatar"
|
|
4
|
-
:class="avatarClass"
|
|
5
|
-
:style="avatarStyle"
|
|
6
|
-
@tap="clickHandler"
|
|
7
|
-
>
|
|
2
|
+
<view class="hy-avatar" :class="avatarClass" :style="avatarStyle" @tap="clickHandler">
|
|
8
3
|
<slot>
|
|
9
4
|
<!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU -->
|
|
10
5
|
<open-data
|
|
@@ -21,12 +16,7 @@
|
|
|
21
16
|
<!-- #ifndef MP-WEIXIN && MP-QQ && MP-BAIDU -->
|
|
22
17
|
<template v-if="mpAvatar && allowMp"></template>
|
|
23
18
|
<!-- #endif -->
|
|
24
|
-
<HyIcon
|
|
25
|
-
v-else-if="icon"
|
|
26
|
-
:name="icon"
|
|
27
|
-
:size="fontSize"
|
|
28
|
-
:color="color"
|
|
29
|
-
></HyIcon>
|
|
19
|
+
<HyIcon v-else-if="icon" :name="icon" :size="fontSize" :color="color"></HyIcon>
|
|
30
20
|
<text
|
|
31
21
|
v-else-if="text"
|
|
32
22
|
:style="{
|
|
@@ -35,8 +25,9 @@
|
|
|
35
25
|
color: color,
|
|
36
26
|
fontSize: fontSize,
|
|
37
27
|
}"
|
|
38
|
-
>{{ text }}</text
|
|
39
28
|
>
|
|
29
|
+
{{ text }}
|
|
30
|
+
</text>
|
|
40
31
|
<image
|
|
41
32
|
class="hy-avatar__image"
|
|
42
33
|
v-else
|
|
@@ -55,21 +46,21 @@ export default {
|
|
|
55
46
|
options: {
|
|
56
47
|
addGlobalClass: true,
|
|
57
48
|
virtualHost: true,
|
|
58
|
-
styleIsolation: 'shared'
|
|
59
|
-
}
|
|
49
|
+
styleIsolation: 'shared',
|
|
50
|
+
},
|
|
60
51
|
}
|
|
61
52
|
</script>
|
|
62
53
|
|
|
63
54
|
<script setup lang="ts">
|
|
64
|
-
import { computed, type CSSProperties, toRefs, ref, watch } from
|
|
65
|
-
import defaultProps from
|
|
66
|
-
import type IProps from
|
|
67
|
-
import { addUnit, random } from
|
|
55
|
+
import { computed, type CSSProperties, toRefs, ref, watch } from 'vue'
|
|
56
|
+
import defaultProps from './props'
|
|
57
|
+
import type IProps from './typing'
|
|
58
|
+
import { addUnit, random } from '../../utils'
|
|
68
59
|
|
|
69
60
|
// 组件
|
|
70
|
-
import HyIcon from
|
|
61
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
71
62
|
|
|
72
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
63
|
+
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
73
64
|
const {
|
|
74
65
|
src,
|
|
75
66
|
defaultUrl,
|
|
@@ -82,48 +73,48 @@ const {
|
|
|
82
73
|
shape,
|
|
83
74
|
name,
|
|
84
75
|
customStyle,
|
|
85
|
-
} = toRefs(props)
|
|
86
|
-
const emit = defineEmits([
|
|
76
|
+
} = toRefs(props)
|
|
77
|
+
const emit = defineEmits(['click'])
|
|
87
78
|
|
|
88
79
|
const base64Avatar =
|
|
89
|
-
|
|
80
|
+
'data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZ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AAAAAAAAAAAAAAAAf//Z'
|
|
90
81
|
// 如果配置randomBgColor参数为true,在图标或者文字的模式下,会随机从中取出一个颜色值当做背景色
|
|
91
82
|
const colors = ref<string[]>([
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
])
|
|
113
|
-
const avatarUrl = ref(src.value)
|
|
114
|
-
const allowMp = ref<boolean>(false)
|
|
83
|
+
'#ffb34b',
|
|
84
|
+
'#f2bba9',
|
|
85
|
+
'#f7a196',
|
|
86
|
+
'#f18080',
|
|
87
|
+
'#88a867',
|
|
88
|
+
'#bfbf39',
|
|
89
|
+
'#89c152',
|
|
90
|
+
'#94d554',
|
|
91
|
+
'#f19ec2',
|
|
92
|
+
'#afaae4',
|
|
93
|
+
'#e1b0df',
|
|
94
|
+
'#c38cc1',
|
|
95
|
+
'#72dcdc',
|
|
96
|
+
'#9acdcb',
|
|
97
|
+
'#77b1cc',
|
|
98
|
+
'#448aca',
|
|
99
|
+
'#86cefa',
|
|
100
|
+
'#98d1ee',
|
|
101
|
+
'#73d1f1',
|
|
102
|
+
'#80a7dc',
|
|
103
|
+
])
|
|
104
|
+
const avatarUrl = ref(src.value)
|
|
105
|
+
const allowMp = ref<boolean>(false)
|
|
115
106
|
|
|
116
107
|
watch(
|
|
117
108
|
() => src.value,
|
|
118
109
|
(newVal) => {
|
|
119
|
-
avatarUrl.value = newVal
|
|
110
|
+
avatarUrl.value = newVal
|
|
120
111
|
// 如果没有传src,则主动触发error事件,用于显示默认的头像,否则src为''空字符等的时候,会无内容展示
|
|
121
112
|
if (!newVal) {
|
|
122
|
-
errorHandler()
|
|
113
|
+
errorHandler()
|
|
123
114
|
}
|
|
124
115
|
},
|
|
125
116
|
{ immediate: true },
|
|
126
|
-
)
|
|
117
|
+
)
|
|
127
118
|
|
|
128
119
|
const avatarStyle = computed<CSSProperties>(() => {
|
|
129
120
|
const style: CSSProperties = {
|
|
@@ -132,53 +123,53 @@ const avatarStyle = computed<CSSProperties>(() => {
|
|
|
132
123
|
? randomBgColor.value
|
|
133
124
|
? colors.value[colorIndex.value ? colorIndex.value : random(0, 19)]
|
|
134
125
|
: bgColor.value
|
|
135
|
-
:
|
|
136
|
-
}
|
|
137
|
-
if (typeof size.value ===
|
|
138
|
-
style.width = addUnit(size.value)
|
|
139
|
-
style.height = addUnit(size.value)
|
|
126
|
+
: 'transparent',
|
|
127
|
+
}
|
|
128
|
+
if (typeof size.value === 'number') {
|
|
129
|
+
style.width = addUnit(size.value)
|
|
130
|
+
style.height = addUnit(size.value)
|
|
140
131
|
}
|
|
141
132
|
|
|
142
|
-
return Object.assign(style, customStyle.value)
|
|
143
|
-
})
|
|
133
|
+
return Object.assign(style, customStyle.value)
|
|
134
|
+
})
|
|
144
135
|
const avatarClass = computed<string[]>(() => {
|
|
145
|
-
const classes: string[] = [`hy-avatar--${shape.value}`]
|
|
146
|
-
if (typeof size.value ===
|
|
147
|
-
classes.push(`hy-avatar--${size.value}`)
|
|
136
|
+
const classes: string[] = [`hy-avatar--${shape.value}`]
|
|
137
|
+
if (typeof size.value === 'string') {
|
|
138
|
+
classes.push(`hy-avatar--${size.value}`)
|
|
148
139
|
}
|
|
149
140
|
|
|
150
|
-
return classes
|
|
151
|
-
})
|
|
141
|
+
return classes
|
|
142
|
+
})
|
|
152
143
|
|
|
153
144
|
const init = () => {
|
|
154
145
|
// 目前只有这几个小程序平台具有open-data标签
|
|
155
146
|
// 其他平台可以通过uni.getUserInfo类似接口获取信息,但是需要弹窗授权(首次),不合符组件逻辑
|
|
156
147
|
// 故目前自动获取小程序头像只支持这几个平台
|
|
157
148
|
// #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU
|
|
158
|
-
allowMp.value = true
|
|
149
|
+
allowMp.value = true
|
|
159
150
|
// #endif
|
|
160
|
-
}
|
|
161
|
-
init()
|
|
151
|
+
}
|
|
152
|
+
init()
|
|
162
153
|
|
|
163
154
|
/**
|
|
164
155
|
* @description 判断传入的name属性,是否图片路径,只要带有"/"均认为是图片形式
|
|
165
156
|
* */
|
|
166
157
|
const isImg = () => {
|
|
167
|
-
return src.value.indexOf(
|
|
168
|
-
}
|
|
158
|
+
return src.value.indexOf('/') !== -1
|
|
159
|
+
}
|
|
169
160
|
// 图片加载时失败时触发
|
|
170
|
-
|
|
171
|
-
avatarUrl.value = defaultUrl.value || base64Avatar
|
|
172
|
-
}
|
|
161
|
+
function errorHandler() {
|
|
162
|
+
avatarUrl.value = defaultUrl.value || base64Avatar
|
|
163
|
+
}
|
|
173
164
|
|
|
174
165
|
/**
|
|
175
166
|
* @description 点击头像
|
|
176
167
|
* */
|
|
177
168
|
const clickHandler = (e: Event) => {
|
|
178
|
-
emit(
|
|
179
|
-
}
|
|
169
|
+
emit('click', name.value, e)
|
|
170
|
+
}
|
|
180
171
|
</script>
|
|
181
172
|
|
|
182
173
|
<style lang="scss" scoped>
|
|
183
|
-
@import
|
|
174
|
+
@import './index.scss';
|
|
184
175
|
</style>
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
@agreeprivacyauthorization="agreeprivacyauthorization"
|
|
23
23
|
:hover-class="!disabled && !loading ? 'hy-button--active' : ''"
|
|
24
24
|
:style="[baseColor, customStyle]"
|
|
25
|
-
@
|
|
25
|
+
@click="clickHandler"
|
|
26
26
|
:class="['hy-button', 'hy-reset-button', bemClass, customClass]"
|
|
27
27
|
>
|
|
28
28
|
<template v-if="loading">
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
? 'hy-button--active'
|
|
67
67
|
: ''
|
|
68
68
|
"
|
|
69
|
-
@
|
|
69
|
+
@click="clickHandler"
|
|
70
70
|
:class="bemClass"
|
|
71
71
|
:style="[baseColor, customStyle]"
|
|
72
72
|
>
|