Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit c545f89

Browse files
author
pengshanglong
committed
feat: 添加 基础& 视图组件
1 parent 7418141 commit c545f89

File tree

22 files changed

+1374
-73
lines changed

22 files changed

+1374
-73
lines changed

project.config.json

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
"newFeature": true
1212
},
1313
"compileType": "miniprogram",
14+
"simulatorType": "wechat",
15+
"simulatorPluginLibVersion": {},
1416
"condition": {}
1517
}

src/app.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import store from './store'
33
import './app.scss'
4+
import './utils/vue-prototype'
45
// Vue.config.productionTip = false
56

67
const App = new Vue({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import classNames from 'classnames'
2+
import Loading from '../loading/index.jsx'
3+
4+
export default {
5+
name: 'ActivityIndicator',
6+
props: {
7+
size: {
8+
type: Number,
9+
default: 0,
10+
},
11+
mode: {
12+
type: String,
13+
default: 'normal',
14+
},
15+
color: {
16+
type: String,
17+
default: '',
18+
},
19+
content: {
20+
type: String,
21+
default: '',
22+
},
23+
className: {
24+
type: [Array, String],
25+
default: () => '',
26+
},
27+
isOpened: {
28+
type: Boolean,
29+
default: true,
30+
},
31+
},
32+
render() {
33+
const { color, size, mode, content, isOpened, className } = this
34+
35+
const rootClass = classNames(
36+
'at-activity-indicator',
37+
{
38+
'at-activity-indicator--center': mode === 'center',
39+
'at-activity-indicator--isopened': isOpened,
40+
},
41+
className
42+
)
43+
44+
return (
45+
<view class={rootClass}>
46+
<view class="at-activity-indicator__body">
47+
<Loading size={size} color={color} />
48+
</view>
49+
{content && <text class="at-activity-indicator__content">{content}</text>}
50+
</view>
51+
)
52+
},
53+
}

src/components/avatar/index.jsx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import classNames from 'classnames'
2+
3+
const SIZE_CLASS = {
4+
large: 'large',
5+
normal: 'normal',
6+
small: 'small',
7+
}
8+
9+
export default {
10+
name: 'Avatar',
11+
props: {
12+
size: {
13+
type: String,
14+
default: 'normal',
15+
validator: (val) => ['large', 'normal', 'small'].includes(val),
16+
},
17+
circle: {
18+
type: Boolean,
19+
default: false,
20+
},
21+
text: {
22+
type: String,
23+
default: '',
24+
},
25+
image: {
26+
type: String,
27+
default: '',
28+
},
29+
openData: {
30+
type: Object,
31+
default: () => {},
32+
},
33+
customStyle: {
34+
type: [Object, String],
35+
default: () => {},
36+
},
37+
className: {
38+
type: [Array, String],
39+
default: () => '',
40+
},
41+
},
42+
43+
render() {
44+
const { size, circle, image, text, openData, customStyle, className } = this
45+
const rootClassName = ['at-avatar']
46+
const iconSize = SIZE_CLASS[size || 'normal']
47+
const classObject = {
48+
[`at-avatar--${iconSize}`]: iconSize,
49+
'at-avatar--circle': circle,
50+
}
51+
52+
let letter = ''
53+
if (text) letter = text[0]
54+
55+
let elem
56+
if (openData && openData.type === 'userAvatarUrl' && this.$isWEAPP()) {
57+
// TODO OpenData Component
58+
elem = <OpenData type={openData.type}></OpenData>
59+
} else if (image) {
60+
elem = <image class="at-avatar__img" src={image} />
61+
} else {
62+
elem = <text class="at-avatar__text">{letter}</text>
63+
}
64+
65+
return (
66+
<view class={classNames(rootClassName, classObject, className)} style={customStyle}>
67+
{elem}
68+
</view>
69+
)
70+
},
71+
}

src/components/badge/index.jsx

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import classNames from 'classnames'
2+
import Taro from '@tarojs/taro'
3+
4+
/**
5+
* formatValue
6+
* @param {string | number | undefined} value
7+
* @param {number} maxValue
8+
* @return string | number
9+
*/
10+
const formatValue = (value, maxValue) => {
11+
if (value === '' || value === null || value === undefined) return ''
12+
const numValue = +value
13+
if (Number.isNaN(numValue)) {
14+
return value
15+
}
16+
return numValue > maxValue ? `${maxValue}+` : numValue
17+
}
18+
19+
export default {
20+
name: 'Badge',
21+
props: {
22+
dot: {
23+
type: Boolean,
24+
default: false,
25+
},
26+
value: {
27+
type: [String, Number],
28+
default: '',
29+
},
30+
maxValue: {
31+
type: Number,
32+
default: 99,
33+
},
34+
customStyle: {
35+
type: [String, Object],
36+
default: () => {},
37+
},
38+
className: {
39+
type: [String, Array],
40+
default: '',
41+
},
42+
},
43+
44+
render() {
45+
const { dot, customStyle, className, maxValue, value } = this
46+
const rootClassName = ['at-badge']
47+
48+
const val = formatValue(value, maxValue)
49+
return (
50+
<view class={classNames(rootClassName, className)} style={customStyle}>
51+
{this.$slots.default}
52+
{dot ? (
53+
<view class="at-badge__dot"></view>
54+
) : (
55+
val !== '' && <view class="at-badge__num">{val}</view>
56+
)}
57+
</view>
58+
)
59+
},
60+
}

0 commit comments

Comments
 (0)