Skip to content

Commit 05d9b58

Browse files
committed
Star组件实现vuepress文档撰写
1 parent 401c173 commit 05d9b58

File tree

4 files changed

+123
-15
lines changed

4 files changed

+123
-15
lines changed

docs/guide/components/star.md

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Star 星级评分
22

3-
## Star组件逻辑分析
3+
## 逻辑分析
44
要整理`Star`组件的实现逻辑,我们从以下几个方面开始:
55
* `props`入参:对于每一个参数的类型,默认值以及用户的整理。
66
* 组件`event`事件:组件自身的事件,例如`click``mouseenter`等等。
@@ -11,7 +11,7 @@
1111
<br/>
1212
![Star组件逻辑分析](../../images/xmind/star.png)
1313

14-
## Star组件开发
14+
## 组件开发
1515
根据以上逻辑分析,我们将`Star`组件分为两步来实现:
1616
* 基础实现:先实现`Star`组件最主要的功能,例如`v-model/value`属性的实现。
1717
* 组件完善:按思维导图,详细完善`Star`组件的相关逻辑。
@@ -99,7 +99,7 @@ Vue.use(Mooc)
9999

100100
在以上步骤都正确完成后,我们在任意已经路由注册过的页面,使用`mooc-star`组件,当出现`star`文本内容即意味着`Star`组件已经全局注册成功了。
101101

102-
### Star组件基础实现
102+
### 基础实现
103103
::: tip
104104
项目中使用到的图标字体为`iconfont`,请根据自己需要引入对应的字体。
105105
:::
@@ -314,13 +314,125 @@ export default {
314314

315315
![Star组件测试结果](../../images/star-result2.gif)
316316

317-
### Star组件完善
318-
`Star`组件实现了基础功能后,我们就完成了我们预定的`Star`组件大部分功能,接下来我们将对`Star`组件进一步完善。
317+
### 组件完善
318+
`Star`组件实现了基础功能后就完成了我们预定的`Star`组件大部分功能,接下来我们将对`Star`组件进一步完善。
319+
320+
`props`入参:
321+
* `size`: 星级评分的大小。
322+
* `texts`: 评分的内容。
323+
* `showText`: 是否显示评分的内容。
324+
* `textColor`: 评分内容的颜色。
325+
326+
完善后的`html`代码(改动为高亮部分):
327+
```html {14,15,16,17,18,19,23,24,25,26,27,28}
328+
<div class="mooc-star">
329+
<span
330+
v-for="n in max"
331+
:key="n"
332+
class="mooc-star-item"
333+
:class="{
334+
'is-disabled': disabled
335+
}"
336+
@mouseenter="handleMouseEnter(n)"
337+
@mouseleave="handleMouseLeave"
338+
@click="handleStarClick(n)"
339+
>
340+
<i
341+
class="iconfont iconxingxing"
342+
:class="iconClass"
343+
:style="{
344+
'font-size': `${ size }px`,
345+
'color': getIconColor(n)
346+
}"
347+
></i>
348+
</span>
349+
<span
350+
v-if="showValue || showText"
351+
class="mooc-star-text"
352+
:style="{
353+
'color': textColor,
354+
'font-size': `${ size }px`
355+
}"
356+
>
357+
{{ text }}
358+
</span>
359+
</div>
360+
```
361+
完善后的`javascript`代码如下(仅改动部分):
362+
```js
363+
export default {
364+
// ... 省略其它部分
365+
props: {
366+
size: {
367+
type: Number,
368+
default: 14
369+
},
370+
textColor: {
371+
type: String,
372+
default: '#ff9900'
373+
},
374+
showText: {
375+
type: Boolean,
376+
default: false
377+
},
378+
texts: {
379+
type: Array,
380+
default () {
381+
return ['极差', '失望', '一般', '满意', '惊喜']
382+
}
383+
},
384+
iconClass: String
385+
},
386+
computed: {
387+
text () {
388+
let result = ''
389+
if (this.showValue) {
390+
result = this.currentValue
391+
} else if (this.showText) {
392+
result = this.texts[this.currentValue - 1]
393+
}
394+
return result
395+
}
396+
}
397+
}
398+
```
399+
400+
在我们完善`Star`组件后,我们需要进行一些必要的测试工作,我们使用如下的代码来进行测试:
401+
```html
402+
<div class="home">
403+
<mooc-star
404+
v-model="starVal"
405+
:size="30"
406+
icon-class="iconbanxing"
407+
:show-text="true"
408+
></mooc-star>
409+
</div>
410+
```
411+
```js
412+
export default {
413+
name: 'home',
414+
data () {
415+
return {
416+
starVal: 3
417+
}
418+
}
419+
}
420+
```
421+
422+
测试结果如下图所示:
423+
424+
![Star测试结果](../../images/star-result3.gif)
425+
319426

320427

321-
## Star组件未来计划
428+
## 未来计划
429+
正如你所看到的那样,虽然我们支持`v-model`,但并不支持表单,也同样不支持半星等等问题,因为我们是以业务为导向,根据业务来逐步完善我们代码的,所以我们对未来做了一些`Star`组件的迭代计划:
430+
1. 支持`form`表单。
431+
2. 支持半星。
432+
3. 支持未激活时,星星的颜色。
433+
4. 支持未激活时,文字的颜色。
322434

323-
## Star组件文档
435+
## 组件文档
324436
在以上`Star`组件完善以后,我们将得到一个比较完整的星级评分组件,但仅仅只是有组件对我们来说并不是十分足够的,我们还需要撰写一份关于`Star`组件的使用文档,组件文档结构按照以下内容来撰写:
325437
* 用法:`Star`组件的用法以及对应的案例。
326438
* 属性:`Star`组件每一个`props`属性的描述,包含类型,默认值以及说明。

docs/images/star-result3.gif

87.4 KB
Loading

src/assets/theme/mixin/step-mixin.styl

Whitespace-only changes.

src/base/star/star.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="mooc-star">
33
<span
4-
v-for="(item, index) in max"
5-
:key="index"
4+
v-for="item in max"
5+
:key="item"
66
class="mooc-star-item"
77
:class="{
88
'is-disabled': disabled
@@ -11,9 +11,8 @@
1111
@mouseleave="handleMouseLeave"
1212
@click="handleStarClick(item)"
1313
>
14-
1514
<i
16-
class="iconfont"
15+
class="iconfont iconxingxing"
1716
:class="iconClass"
1817
:style="{
1918
'font-size': size + 'px',
@@ -57,10 +56,7 @@ export default {
5756
type: String,
5857
default: '#ff9900'
5958
},
60-
iconClass: {
61-
type: String,
62-
default: 'iconxingxing'
63-
},
59+
iconClass: String,
6460
disabled: {
6561
type: Boolean,
6662
default: false

0 commit comments

Comments
 (0)