Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.

Commit 598da54

Browse files
committed
perf: 本次性能优化,包的体积从**174kb**降低到了**171kb**,基本上都是几十个字节几十个字节的减少的
1 parent 0988465 commit 598da54

File tree

28 files changed

+98
-1981
lines changed

28 files changed

+98
-1981
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# 更新日志
22

3+
## 3.3.7 (2022-03-09)
4+
5+
- 优化了所有组件的 index.js 文件注册组件代码,降低代码可读性,但是减少了包的体积
6+
- TyhButton 组件的样式有略微的调整
7+
- TyhButton 组件的 icon 更改了渲染方式
8+
- Container 布局容器组件的 `<tyh-container>:外层容器` 做了较大的调整,现在根据其内部的子元素来自动判断容器的排列方向
9+
- 废除了 tyh-container 的 flex 配置项
10+
- 新增 tyh-container 的 direction 配置项
11+
- TyhBackTop 组件的 bottom 和 right 属性现在必须要传递一个`字符串`的指定距离
12+
- TyhDivision 组件的 margin 属性现在必须要传递一个`字符串`的指定距离
13+
- 还有其他若干出代码简化写法
14+
- 本次性能优化,包的体积从**174kb**降低到了**171kb**,基本上都是几十个字节几十个字节的减少的
15+
316
## 3.3.6 (2022-03-08)
417

518
- 修复 TyhDrawer 组件的样式

src/App.vue

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
<template>
2-
<tyh-button icon="tyh-ui-setting-filling">设置</tyh-button>
3-
<tyh-button icon="tyh-ui-tyhui" type="primary">tyh-ui</tyh-button>
4-
<tyh-button icon="tyh-ui-fabulous" type="success"></tyh-button>
5-
<tyh-button icon="tyh-ui-discount" type="danger"></tyh-button>
6-
<tyh-button icon="tyh-ui-chart-bar" type="warning"></tyh-button>
7-
8-
<tyh-button simple icon="tyh-ui-setting-filling">设置</tyh-button>
9-
<tyh-button simple icon="tyh-ui-tyhui" type="primary">tyh-ui</tyh-button>
10-
<tyh-button simple icon="tyh-ui-fabulous" type="success"></tyh-button>
11-
<tyh-button simple icon="tyh-ui-discount" type="danger"></tyh-button>
12-
<tyh-button simple icon="tyh-ui-chart-bar" type="warning"></tyh-button>
13-
<Tiger />
2+
<tyh-division
3+
color="blue"
4+
margin="30px"
5+
>
6+
这是左边文字
7+
</tyh-division>
148
</template>
159

1610
<script setup>
17-
import Tiger from './demo/tiger.vue'
1811
</script>
1912

2013
<style scoped>

src/packages/tyhUi/packages/button/style/index.css src/packages/THEME_STYLE/buttton/style/index.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.tyh-button {
22
min-width: 40px;
33
padding: 0 22px;
4-
height: 35px;
4+
min-height: 35px;
55
border-radius: 5px;
66
cursor: pointer;
77
user-select: none;

src/packages/tyhUi/packages/button/style/index.less src/packages/THEME_STYLE/buttton/style/index.less

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
.tyh-button {
2020
min-width: 40px;
2121
padding: 0 22px;
22-
height: 35px;
22+
min-height: 35px;
2323
border-radius: 5px;
2424
cursor: pointer;
2525
user-select: none;
@@ -184,6 +184,6 @@
184184
border-radius: 0;
185185
}
186186

187-
.tyh-button [class*='tyh-icon'] + span {
187+
.tyh-button [class*='tyh-icon']+span {
188188
margin-left: 5px;
189189
}

src/packages/THEME_STYLE/crumbs-item/style/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
width: 28px;
1212
display: inline-block;
1313
text-align: center;
14+
color: #C0C4CC;
1415
}
1516
.tyh-crumbs-item:last-child .tyh-icon {
1617
display: none;

src/packages/THEME_STYLE/crumbs-item/style/index.less

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
width: 28px;
1212
display: inline-block;
1313
text-align: center;
14+
color: #C0C4CC;
1415
}
1516
}
1617

src/packages/tyhUi/package.json

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1 @@
1-
{
2-
"name": "tyh-ui2",
3-
"version": "3.3.7",
4-
"description": "The next generation ui component library of tyh-ui is based on vue3 Version, fully embrace vue3.",
5-
"main": "src/index.js",
6-
"scripts": {
7-
"test": "npm i tyh-ui2"
8-
},
9-
"keywords": [
10-
"ui",
11-
"tyh",
12-
"tyh-ui",
13-
"tyh-ui2",
14-
"vue",
15-
"vue3",
16-
"setup",
17-
"Composition API",
18-
"component",
19-
"components",
20-
"vue-next",
21-
"css",
22-
"css3",
23-
"less",
24-
"web",
25-
"html",
26-
"javascript",
27-
"element",
28-
"element3",
29-
"element-plus",
30-
"element-ui"
31-
],
32-
"author": {
33-
"name": "tyh2001",
34-
"url": "https://tianyuhao.cn"
35-
},
36-
"license": "ISC",
37-
"bugs": {
38-
"url": "https://github.com/Tyh2001/tyh-ui/issues"
39-
},
40-
"homepage": "https://tianyuhao.cn/v3",
41-
"repository": "https://github.com/Tyh2001/tyh-ui"
42-
}
1+
{"name":"tyh-ui2","version":"3.3.7","description":"The next generation ui component library of tyh-ui is based on vue3 Version, fully embrace vue3.","main":"src/index.js","scripts":{"test":"npm i tyh-ui2"},"keywords":["ui","tyh","tyh-ui","tyh-ui2","vue","vue3","setup","Composition API","component","components","vue-next","css","css3","less","web","html","javascript","element","element3","element-plus","element-ui"],"author":{"name":"tyh2001","url":"https://tianyuhao.cn"},"license":"ISC","bugs":{"url":"https://github.com/Tyh2001/tyh-ui/issues"},"homepage":"https://tianyuhao.cn/v3","repository":"https://github.com/Tyh2001/tyh-ui"}

src/packages/tyhUi/packages/alert/TyhAlert.vue

+3-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const props = defineProps({
2020
type: {
2121
type: String,
2222
default: 'default',
23-
validator(v) {
23+
validator (v) {
2424
return ['default', 'primary', 'success', 'danger', 'warning'].includes(v)
2525
}
2626
},
@@ -31,10 +31,8 @@ const props = defineProps({
3131
simple: Boolean
3232
})
3333
const emit = defineEmits(['close'])
34-
3534
const { THEME, isClass, isStyle, isMessageStyle } = _TyhAlert()
36-
37-
function _TyhAlert() {
35+
function _TyhAlert () {
3836
const BACKGROUND_THEME = {
3937
primary: '#e8f4ff',
4038
success: '#e1ffea',
@@ -63,11 +61,6 @@ function _TyhAlert() {
6361
const isMessageStyle = computed(() => {
6462
return [{ color: THEME[props.type] }]
6563
})
66-
return {
67-
THEME,
68-
isClass,
69-
isStyle,
70-
isMessageStyle
71-
}
64+
return { THEME, isClass, isStyle, isMessageStyle }
7265
}
7366
</script>

src/packages/tyhUi/packages/avatar/TyhAvatar.vue

+3-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<tyh-icon size="70" :icon="errorIcon || 'tyh-ui-user'" color="#fff" />
66
</slot>
77
</div>
8-
98
<img
109
v-else
1110
:draggable="draggable"
@@ -30,7 +29,7 @@ const props = defineProps({
3029
},
3130
fit: {
3231
type: String,
33-
validator(v) {
32+
validator (v) {
3433
return ['fill', 'contain', 'cover', 'none', 'scale-down'].includes(v)
3534
}
3635
},
@@ -42,8 +41,7 @@ const props = defineProps({
4241
})
4342
const emit = defineEmits(['error', 'load'])
4443
const { isError, onError, isSize, errorClass, successClass } = _TyhAvatar()
45-
46-
function _TyhAvatar() {
44+
function _TyhAvatar () {
4745
const isError = ref(false)
4846
const onError = () => {
4947
emit('error')
@@ -70,12 +68,6 @@ function _TyhAvatar() {
7068
}
7169
]
7270
})
73-
return {
74-
isError,
75-
onError,
76-
isSize,
77-
errorClass,
78-
successClass
79-
}
71+
return { isError, onError, isSize, errorClass, successClass }
8072
}
8173
</script>

src/packages/tyhUi/packages/back-top/TyhBackTop.vue

+31-29
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div
33
v-show="backShow"
44
class="tyh-back-top"
5-
:style="[{ bottom: `${bottom}px`, right: `${right}px` }]"
6-
@click="backTop"
5+
:style="{ bottom, right }"
6+
@click="toTop"
77
>
88
<slot />
99
</div>
@@ -13,38 +13,40 @@
1313
import { ref, onMounted } from 'vue'
1414
defineProps({
1515
bottom: {
16-
type: [String, Number],
17-
default: '50'
16+
type: String,
17+
default: '50px'
1818
},
1919
right: {
20-
type: [String, Number],
21-
default: '50'
20+
type: String,
21+
default: '50px'
2222
}
2323
})
24-
const backShow = ref(false)
25-
const handleScroll = () => {
26-
let timer = null
27-
return function () {
28-
if (timer !== null) {
29-
clearTimeout(timer)
24+
const { backShow, toTop } = _TyhBackTop()
25+
function _TyhBackTop () {
26+
const backShow = ref(false)
27+
const handleScroll = () => {
28+
let timer = null
29+
return function () {
30+
if (timer !== null) {
31+
clearTimeout(timer)
32+
}
33+
timer = setTimeout(() => {
34+
let scrollTop =
35+
document.documentElement.scrollTop || document.body.scrollTop
36+
scrollTop > 100 ? (backShow.value = true) : (backShow.value = false)
37+
}, 188)
3038
}
31-
timer = setTimeout(() => {
32-
let scrollTop =
33-
document.documentElement.scrollTop || document.body.scrollTop
34-
scrollTop > 100 ? (backShow.value = true) : (backShow.value = false)
35-
}, 188)
3639
}
40+
const toTop = () => {
41+
let top = document.documentElement.scrollTop || document.body.scrollTop
42+
const timeTop = setInterval(() => {
43+
document.body.scrollTop = document.documentElement.scrollTop = top -= 50
44+
if (top <= 0) {
45+
clearInterval(timeTop)
46+
}
47+
}, 11)
48+
}
49+
onMounted(() => window.addEventListener('scroll', handleScroll()))
50+
return { backShow, toTop }
3751
}
38-
const backTop = () => {
39-
let top = document.documentElement.scrollTop || document.body.scrollTop
40-
const timeTop = setInterval(() => {
41-
document.body.scrollTop = document.documentElement.scrollTop = top -= 50
42-
if (top <= 0) {
43-
clearInterval(timeTop)
44-
}
45-
}, 11)
46-
}
47-
onMounted(() => {
48-
window.addEventListener('scroll', handleScroll())
49-
})
5052
</script>

src/packages/tyhUi/packages/button/TyhButton.vue

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<template>
22
<button :class="isClass" :disabled="disabled">
3-
<!-- <tyh-icon v-if="icon" :icon="icon" :color="textColor" size="14" /> -->
4-
<i :class="['tyh-icon', `${icon}`]" />
5-
<span v-if="$slots.default" :style="[{ color: textColor }]">
6-
<slot />
7-
</span>
3+
<i v-if="icon" :class="['tyh-icon', `${icon}`]" :style="{ color }" />
4+
<span v-if="$slots.default" :style="{ color }"><slot /></span>
85
</button>
96
</template>
107

@@ -31,7 +28,7 @@ const props = defineProps({
3128
simple: Boolean
3229
})
3330
34-
const { textColor, isClass } = _TyhButton()
31+
const { color, isClass } = _TyhButton()
3532
function _TyhButton () {
3633
const THEME = {
3734
primary: '#3a6ff4',
@@ -41,7 +38,7 @@ function _TyhButton () {
4138
default: '#3f536e'
4239
}
4340
44-
const textColor = computed(() => {
41+
const color = computed(() => {
4542
if (props.simple) return THEME[props.type]
4643
return props.type === 'default' || !props.type ? '#333' : '#fff'
4744
})
@@ -64,6 +61,6 @@ function _TyhButton () {
6461
]
6562
})
6663
67-
return { textColor, isClass }
64+
return { color, isClass }
6865
}
6966
</script>

src/packages/tyhUi/packages/calendar/TyhCalendar.vue

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class="tyh-calendar-week-item"
2020
v-for="(item, index) in 7"
2121
:key="index"
22-
:style="[{ width: `${cellWidth < 28 ? 28 : cellWidth}px` }]"
22+
:style="{ width: `${cellWidth < 28 ? 28 : cellWidth}px` }"
2323
>
2424
{{ changeWeek(item) }}
2525
</td>
@@ -57,7 +57,6 @@ const props = defineProps({
5757
default: 50
5858
}
5959
})
60-
6160
const {
6261
getMonth,
6362
getYear,
@@ -73,7 +72,7 @@ const {
7372
getDate
7473
} = _TyhCalendar()
7574
76-
function _TyhCalendar() {
75+
function _TyhCalendar () {
7776
const getMonth = ref(props.modelValue.getMonth())
7877
const getYear = ref(props.modelValue.getFullYear())
7978
const getDate = props.modelValue.getDate()
@@ -120,12 +119,10 @@ function _TyhCalendar() {
120119
121120
const nowDateStyle = date => {
122121
if (date + 1 === props.modelValue.getDate()) {
123-
return [
124-
{
125-
backgroundColor: '#3a6ff4',
126-
color: '#fff'
127-
}
128-
]
122+
return [{
123+
backgroundColor: '#3a6ff4',
124+
color: '#fff'
125+
}]
129126
}
130127
}
131128

src/packages/tyhUi/packages/container/TyhAside.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<aside class="tyh-aside" :style="[{ width }]"><slot /></aside>
2+
<aside class="tyh-aside" :style="{ width }"><slot /></aside>
33
</template>
44

55
<script>

src/packages/tyhUi/packages/container/TyhFooter.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<footer class="tyh-footer" :style="[{ height }]"><slot /></footer>
2+
<footer class="tyh-footer" :style="{ height }"><slot /></footer>
33
</template>
44

55
<script>

src/packages/tyhUi/packages/container/TyhHeader.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<header class="tyh-header" :style="[{ height }]"><slot /></header>
2+
<header class="tyh-header" :style="{ height }"><slot /></header>
33
</template>
44

55
<script>

src/packages/tyhUi/packages/crumbs-item/TyhCrumbsItem.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@click="link"
55
>
66
<span class="tyh-crumbs-item-text"><slot /></span>
7-
<tyh-icon color="#C0C4CC" :icon="icon" />
7+
<i :class="['tyh-icon', icon]" />
88
</span>
99
</template>
1010

0 commit comments

Comments
 (0)