Skip to content

Commit

Permalink
新增spinner组件;新增infinite-scroll组件;部分组件代码优化。
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcmaro committed May 21, 2017
1 parent 166814c commit 9e15284
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 58 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
// function括号前面的空格是否必需
'space-before-function-paren': 0,
// 行末分号是否必需
'semi': 0
'semi': 0,
// 允许尾随空格
'no-trailing-spaces': 0
}
}
3 changes: 3 additions & 0 deletions build/bin/build-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const install = function(Vue) {
if (install.installed) return
{{install}}
Vue.use(InfiniteScroll);
}
// auto install
Expand Down Expand Up @@ -65,6 +66,8 @@ componentNames.forEach(name => {
}));

if ([
// directives
'InfiniteScroll'
].indexOf(componentName) === -1) {
installTemplate.push(render(ISNTALL_COMPONENT_TEMPLATE, {
name: componentName,
Expand Down
5 changes: 5 additions & 0 deletions examples/navs.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"path": "/icon",
"name": "Icons",
"icon": "icons"
},
{
"path": "/spinner",
"name": "Spinner",
"icon": "Spinner"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions examples/page-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
<style lang="less">
@import "../src/less/variables.less";
.page-content {
position: relative;
padding: @content-spacing;
}
Expand Down
6 changes: 0 additions & 6 deletions examples/pages/indicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ export default {

<style lang="less" scoped>
.page-content {
width: 100%;
position: absolute;
top: 50%;
transform: translateY(-50%);
margin: 0 !important;
.btn {
margin-top: 15px;
}
Expand Down
77 changes: 77 additions & 0 deletions examples/pages/infinite-scroll.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,87 @@
<template>
<div>
<vui-header fixed>Infinite Scroll</vui-header>
<div class="infinite-scroll-wrapper">
<div v-infinite-scroll="loadMore" :infinite-scroll-disabled="busy" infinite-scroll-distance="20">
<vui-list>
<vui-list-item v-for="item in pager.list">{{item}}</vui-list-item>
</vui-list>
<div class="spinner-wrapper">
<vui-spinner v-if="pager.hasNext" type="spinner2"></vui-spinner>
{{pager.hasNext ? 'Loading...' : '没有更多了...'}}
</div>
</div>
</div>
</div>
</template>

<style lang="less" scoped>
.infinite-scroll-wrapper {
position: absolute;
width: 100%;
left: 0;
top: 44px;
bottom: 0;
overflow-x: hidden;
overflow-y: scroll;
}
.spinner-wrapper {
height: 44px;
line-height: 44px;
background-color: #fff;
color: #999;
text-align: center;
.spinner {
margin-right: 5px;
vertical-align: -4px;
}
}
</style>

<script>
export default {
data: function() {
return {
pager: {
list: [],
loading: false,
page: 1,
pageSize: 20,
totalPage: 5,
hasNext: true
}
}
},
computed: {
busy() {
return this.pager.loading || !this.pager.hasNext
}
},
mounted() {
let pager = this.pager
for (let i = 1; i <= pager.pageSize; i++) {
pager.list.push(i);
}
},
methods: {
loadMore: function() {
console.log('loadMore')
let pager = this.pager
// 把loading设为ture,以屏蔽infinite-scroll绑定的事件
// 避免在加载数据时,上下滚动屏幕而使得loadMore再次触发
pager.loading = true
setTimeout(() => {
let last = pager.list[pager.list.length - 1];
for (let i = 1; i <= pager.pageSize; i++) {
pager.list.push(last + i);
}
pager.page += 1
pager.loading = false
pager.hasNext = pager.page < pager.totalPage
}, 1000);
}
}
}
</script>
32 changes: 32 additions & 0 deletions examples/pages/spinner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div>
<vui-header fixed>Spinner</vui-header>
<page-content>
<vui-list>
<vui-list-item>
spinner<vui-spinner type="spinner" slot="after"></vui-spinner>
</vui-list-item>
<vui-list-item>
spinner1<vui-spinner type="spinner1" slot="after"></vui-spinner>
</vui-list-item>
<vui-list-item>
spinner2<vui-spinner type="spinner2" slot="after"></vui-spinner>
</vui-list-item>
<vui-list-item>
spinner3<vui-spinner type="spinner3" slot="after"></vui-spinner>
</vui-list-item>
</vui-list>
</page-content>
</div>
</template>

<style lang="less" scoped>
.page-content {
padding: 0;
}
</style>

<script>
export default {
}
</script>
6 changes: 0 additions & 6 deletions examples/pages/toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export default {

<style lang="less" scoped>
.page-content {
width: 100%;
position: absolute;
top: 50%;
transform: translateY(-50%);
margin: 0 !important;
.btn {
margin-top: 15px;
}
Expand Down
7 changes: 1 addition & 6 deletions src/components/action-sheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<vui-modal type="actionsheet" transition="slide-up" :show="show">
<slot></slot>
<template slot="footer" v-if="cancelButton">
<vui-action-sheet-button @click="handleCancel">{{cancelButtonText}}</vui-action-sheet-button>
<vui-action-sheet-button @click="$emit('cancel', $event)">{{cancelButtonText}}</vui-action-sheet-button>
</template>
</vui-modal>
</template>
Expand Down Expand Up @@ -31,11 +31,6 @@ export default {
type: String,
default: '取消'
}
},
methods: {
handleCancel($evt) {
this.$emit('cancel', $evt)
}
}
}
</script>
7 changes: 1 addition & 6 deletions src/components/alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>
<slot></slot>
<template slot="footer">
<vui-button size="large" @click="handleClick">{{buttonText}}</vui-button>
<vui-button size="large" @click="$emit('ok', $event)">{{buttonText}}</vui-button>
</template>
</vui-modal>
</template>
Expand Down Expand Up @@ -34,11 +34,6 @@ export default {
type: String,
default: '确定'
}
},
methods: {
handleClick($evt) {
this.$emit('ok', $evt)
}
}
}
</script>
9 changes: 2 additions & 7 deletions src/components/button.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<template>
<button
class="btn"
:class="btnClasses"
:type="nativeType"
:disabled="disabled"
@click="handleClick">
@click="$emit('click', $event)">
<slot></slot>
</button>
</template>
Expand Down Expand Up @@ -42,18 +41,14 @@ export default {
computed: {
btnClasses() {
const classes = {
'btn': true,
[`btn-${this.type}`]: true,
[`btn-${this.size}`]: true,
'btn-plain': this.plain,
'btn-disabled': this.disabled
}
return classes
}
},
methods: {
handleClick(evt) {
this.$emit('click', evt)
}
}
}
</script>
12 changes: 2 additions & 10 deletions src/components/confirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<vui-modal type="confirm" :show="show">
<slot></slot>
<template slot="footer">
<vui-button class="btn-cancel" size="large" @click="onCancel">{{cancelButtonText}}</vui-button>
<vui-button class="btn-ok" size="large" @click="onConfirm">{{confirmButtonText}}</vui-button>
<vui-button class="btn-cancel" size="large" @click="$emit('cancel', $event)">{{cancelButtonText}}</vui-button>
<vui-button class="btn-ok" size="large" @click="$emit('ok', $event)">{{confirmButtonText}}</vui-button>
</template>
</vui-modal>
</template>
Expand Down Expand Up @@ -32,14 +32,6 @@ export default {
type: String,
default: '取消'
}
},
methods: {
onConfirm($evt) {
this.$emit('ok', $evt)
},
onCancel($evt) {
this.$emit('cancel', $evt)
}
}
}
</script>
7 changes: 1 addition & 6 deletions src/components/icon.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<i class="icon" :class="'icon-' + type" @click="handleClick"></i>
<i :class="'icon icon-' + type" @click="$emit('click', $event)"></i>
</template>

<script>
Expand All @@ -10,11 +10,6 @@ export default {
type: String,
required: true
}
},
methods: {
handleClick($evt) {
this.$emit('click', $evt)
}
}
}
</script>
7 changes: 5 additions & 2 deletions src/components/indicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="indicator" :class="{[`indicator-${type}`]: true}" >
<vui-overlay v-show="show" :transparent="true"></vui-overlay>
<vui-toast :show="show" @toggle-visible="toggleVisible">
<vui-icon :type="type === 'loading' ? 'spinner' : type" slot="icon"></vui-icon>
<vui-spinner v-if="type==='loading'" type="spinner" slot="icon"></vui-spinner>
<vui-icon v-else :type="type" slot="icon"></vui-icon>
<slot></slot>
</vui-toast>
</div>
Expand All @@ -12,13 +13,15 @@
import VuiOverlay from './overlay'
import VuiToast from './toast'
import VuiIcon from './icon'
import VuiSpinner from './spinner'
export default {
name: 'vui-indicator',
components: {
VuiOverlay,
VuiToast,
VuiIcon
VuiIcon,
VuiSpinner
},
props: {
show: {
Expand Down
Loading

0 comments on commit 9e15284

Please sign in to comment.