Skip to content

Commit

Permalink
perf: 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 15, 2025
1 parent 41b4bda commit 665515f
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 40 deletions.
6 changes: 3 additions & 3 deletions example/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export default {
'icon',
'divider',
'float-ball',
'rate',
'switch',
'loading'
]
},
Expand All @@ -57,7 +55,9 @@ export default {
'picker',
'cascade-picker',
'date-picker',
'time-picker'
'time-picker',
'rate',
'switch'
]
},
{
Expand Down
11 changes: 7 additions & 4 deletions example/pages/rate/index.mpx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</view>
</view>
<cube-toast
txt="为方便展示,示例中星星数最多为10~"
txt="为方便展示,示例中星星数最多为9~"
wx:ref="toast">
</cube-toast>
</view>
Expand All @@ -71,7 +71,7 @@

createPage({
data: {
value: 4.5,
value: 3.3,
max: '5',
customize: false,
justify: false,
Expand All @@ -92,9 +92,9 @@
updateMaxLength (e) {
const { value } = e.detail
this.max = value
if (value >= 10) {
if (value > 9) {
this.$refs.toast.show()
this.max = '10'
this.max = '9'
}
},
updateJustify (e) {
Expand Down Expand Up @@ -156,6 +156,9 @@
.cube-rate-item_active
.rate-item-demo
background-color: orange
.cube-rate-item_half_active
.rate-item-demo
background-color: blue
</style>

<script type="application/json">
Expand Down
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module.exports = {
testEnvironment: 'jsdom',
collectCoverage: false,
testMatch: [
// '**/__tests__/**/*.spec.js'
'**/__tests__/**/rate.spec.js'
'**/__tests__/**/*.spec.js'
],
collectCoverageFrom: ['/packages/mpx-cube-ui/src/components/**/*.{js,mpx,ts}'],
coverageDirectory: 'test/coverage',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"docs:prod": "npm run example:build && NODE_ENV=production npm run docs:build && cp -r ./example/dist/web ./docs/.vuepress/dist/example",
"example:build": "cd example && npm run build:web",
"example:dev": "cd example && npm run watch:web",
"example:mp:dev": "cd example && npm run watch:ali",
"example:mp:dev": "cd example && npm run watch:mp",
"fix": "eslint --fix --ext .js,.ts,.mpx packages/",
"lint": "eslint --ext .js,.ts,.mpx packages/",
"prepare": "husky install",
Expand Down
2 changes: 1 addition & 1 deletion packages/mpx-cube-ui/src/components/loading/index.mpx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<view class="cube-single-loading">
<text class="cube-loading-spinners" wx:style="{{style}}">
<text class="cube-loading-spinner" wx:for="{{balde}}"></text>
<text class="cube-loading-spinner" wx:for="{{line}}"></text>
</text>
</view>
</template>
Expand Down
2 changes: 1 addition & 1 deletion packages/mpx-cube-ui/src/components/loading/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ createComponent({
}
},
data: {
balde: 12
line: 12
},
computed: {
style() {
Expand Down
2 changes: 1 addition & 1 deletion packages/mpx-cube-ui/src/components/rate/index.mpx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<view class="cube-rate-items" id="cube-rate-items" wx:class="{{rateClass}}" >
<slot wx:if="{{isCustomize}}"></slot>
<block wx:else>
<rate-item wx:for="{{max}}" wx:key="item" index="{{item}}" value="{{value}}" isCustomize="{{false}}"/>
<rate-item wx:for="{{max}}" wx:key="item" index="{{item}}" value="{{value}}"/>
</block>
</view>
</view>
Expand Down
27 changes: 8 additions & 19 deletions packages/mpx-cube-ui/src/components/rate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,22 @@ createComponent({
handleMove(e) {
e.preventDefault && e.preventDefault()
if (this.disabled) return

if (!isMouseEvent(e)) {
this.computeTempValue(e.touches[0])
} else if (this.mousePressed) {
this.computeTempValue(e)
}
this.computeTempValue(isMouseEvent(e) ? e : e.touches[0])
},
handleEnd(e) {
if (this.disabled) return
if ((!isMouseEvent(e) || this.mousePressed)) {
if (isMouseEvent(e)) {
this.mousePressed = false
document.removeEventListener('mouseup', this.handleEnd)
document.removeEventListener('mousemove', this.handleMove)
}
this.computeTempValue(isMouseEvent(e) ? e : e.changedTouches[0])
this.triggerEvent(EVENT_INPUT, { value: this.tempValue })
if (isMouseEvent(e)) {
this.mousePressed = false
document.removeEventListener('mouseup', this.handleEnd)
document.removeEventListener('mousemove', this.handleMove)
}
this.computeTempValue(isMouseEvent(e) ? e : e.changedTouches[0])
this.triggerEvent(EVENT_INPUT, { value: this.tempValue })
},
handleNum(num) {
if (this.allowHalf) {
const baseNum = Math.ceil(num) - 0.5
if (this.disabled) {
num = num < baseNum ? baseNum - 0.5 : baseNum
} else {
num = num <= baseNum ? baseNum : baseNum + 0.5
}
num = num <= baseNum ? baseNum : baseNum + 0.5
} else {
num = Math.ceil(num)
}
Expand Down
4 changes: 0 additions & 4 deletions packages/mpx-cube-ui/src/components/rate/rate-item-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ createComponent({
value: {
type: Number,
value: 0
},
isCustomize: {
type: Boolean,
value: true
}
},
computed: {
Expand Down
4 changes: 1 addition & 3 deletions packages/mpx-cube-ui/src/components/switch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ createComponent({
computed: {
switchClass() {
return {
'cube-switch': true,
'cube-switch-on': this.isOn,
[`cube-switch-${this.themeType}`]: this.themeType
'cube-switch-on': this.isOn
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 665515f

Please sign in to comment.