Skip to content

Commit ddd3c5c

Browse files
authored
feat(userhead): 增加移动端头像组件 (#5)
Signed-off-by: MNZhu <[email protected]>
1 parent 9cef0d9 commit ddd3c5c

File tree

2 files changed

+80
-45
lines changed

2 files changed

+80
-45
lines changed

src/user-head/index.js

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
/**
2-
* Copyright (c) 2022 - present TinyVue Authors.
3-
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
*
5-
* Use of this source code is governed by an MIT-style license.
6-
*
7-
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8-
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9-
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10-
*
11-
*/
2+
* Copyright (c) 2022 - present TinyVue Authors.
3+
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
*
5+
* Use of this source code is governed by an MIT-style license.
6+
*
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
11+
*/
1212

13-
export const computedStyle = ({ state, props }) => () => ({
14-
fill: props.color,
15-
color: props.color,
16-
backgroundColor: props.backgroundColor,
17-
backgroundImage: /^(image)$/.test(props.type) && state.internalValue ? `url(${state.internalValue})` : 'none'
18-
})
13+
export const computedStyle =
14+
({ state, props }) =>
15+
() => {
16+
return {
17+
fill: props.color,
18+
color: props.color,
19+
backgroundColor: props.backgroundColor,
20+
backgroundImage: /^(image)$/.test(props.type) && state.internalValue ? `url(${state.internalValue})` : 'none'
21+
}
22+
}
1923

2024
export const computedMessage = (props) => () => {
2125
let result = ''
@@ -32,27 +36,32 @@ export const computedMessage = (props) => () => {
3236
return result
3337
}
3438

35-
export const computedFontSize = ({ props, state }) => () => {
36-
let fontSize = ''
39+
export const computedFontSize =
40+
({ props, state }) =>
41+
() => {
42+
let fontSize = ''
43+
44+
if (props.type === 'label' && state.label && !props.min) {
45+
const length = state.label.length
46+
const sizeMap = {
47+
1: '40px',
48+
2: '30px',
49+
3: '22px',
50+
4: '20px',
51+
5: '18px',
52+
6: '16px'
53+
}
3754

38-
if (props.type === 'label' && state.label && !props.min) {
39-
const length = state.label.length
40-
const sizeMap = {
41-
1: '40px',
42-
2: '30px',
43-
3: '22px',
44-
4: '20px',
45-
5: '18px',
46-
6: '16px'
55+
fontSize = sizeMap[length]
4756
}
4857

49-
fontSize = sizeMap[length]
58+
return { fontSize }
5059
}
5160

52-
return { fontSize }
53-
}
54-
55-
export const computedLabel = ({ state, props }) => () => (props.min ? state.internalValue.substr(0, 2) : state.internalValue.substr(0, 6))
61+
export const computedLabel =
62+
({ state, props }) =>
63+
() =>
64+
props.min ? state.internalValue.substr(0, 2) : state.internalValue.substr(0, 6)
5665

5766
export const getInternalValue = (props) => () => {
5867
if (!props.modelValue) {
@@ -69,3 +78,27 @@ export const getInternalValue = (props) => () => {
6978
return props.modelValue
7079
}
7180
}
81+
82+
export const computedSize =
83+
({ props, state }) =>
84+
() => {
85+
let size = props.size
86+
87+
if (typeof size === 'string') {
88+
switch (size) {
89+
case 'large':
90+
size = 64
91+
break
92+
case 'medium':
93+
size = 40
94+
break
95+
case 'small':
96+
size = 22
97+
break
98+
default:
99+
size = 40
100+
break
101+
}
102+
}
103+
return size
104+
}

src/user-head/vue.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/**
2-
* Copyright (c) 2022 - present TinyVue Authors.
3-
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
*
5-
* Use of this source code is governed by an MIT-style license.
6-
*
7-
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8-
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9-
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10-
*
11-
*/
2+
* Copyright (c) 2022 - present TinyVue Authors.
3+
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
*
5+
* Use of this source code is governed by an MIT-style license.
6+
*
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
11+
*/
1212

13-
import { computedMessage, computedStyle, computedFontSize, computedLabel, getInternalValue } from './index'
13+
import { computedMessage, computedStyle, computedFontSize, computedLabel, getInternalValue, computedSize } from './index'
1414

1515
export const api = ['state']
1616

@@ -24,14 +24,16 @@ export const renderless = (props, { reactive, computed }) => {
2424
label: computed(() => api.computedLabel()),
2525
style: computed(() => api.computedStyle()),
2626
message: computed(() => api.computedMessage()),
27-
fontSize: computed(() => api.computedFontSize())
27+
fontSize: computed(() => api.computedFontSize()),
28+
size: computed(() => api.computedSize())
2829
})
2930

3031
Object.assign(api, {
3132
state,
3233
computedLabel: computedLabel({ state, props }),
3334
computedStyle: computedStyle({ state, props }),
34-
computedFontSize: computedFontSize({ props, state })
35+
computedFontSize: computedFontSize({ props, state }),
36+
computedSize: computedSize({ props, state })
3537
})
3638

3739
return api

0 commit comments

Comments
 (0)