Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion example/pages/indicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<mt-button @click.native="openIndicator" size="large">点击弹出 Indicator</mt-button>
<mt-button @click.native="openIndicatorWithSpinner" size="large">可配置 spinner</mt-button>
<mt-button @click.native="openIndicatorWithText" size="large">点击弹出带有文字的 Indicator</mt-button>
<mt-button @click.native="openIndicatorWithTimer" size="large">点击弹出带有定时回调的 Indicator</mt-button>
</div>
</div>
</template>
Expand Down Expand Up @@ -43,9 +44,12 @@
openIndicatorWithText() {
Indicator.open('加载中...');
setTimeout(() => Indicator.close(), 2000);
},

openIndicatorWithTimer() {
Indicator.open({ duration: 3000, closeFn: () => alert('Indicator 定时回调成功') });
}
},

beforeDestroy() {
Indicator.close();
}
Expand Down
6 changes: 4 additions & 2 deletions packages/indicator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Indicator.open('Loading...');

Open an indicator with an object:
```Javascript
Indicator.open({ text:'Loading...', spinnerType: 'fading-circle' });
Indicator.open({ text:'Loading...', spinnerType: 'fading-circle', duration: 10000, closeFn: () => alert('success') });
```
&emsp;&emsp;If you have duration, it will close automatically

Then close it:
```Javascript
Expand All @@ -42,6 +43,7 @@ Indicator.close();
|-------------|----------------|-------------------------------------------------------------|---------|
| text | indicator text | String | |
| spinnerType | spinner type | 'snake', 'fading-circle', 'double-bounce', 'triple-bounce' | 'snake' |

| duration | duration time | Number, Number of milliseconds | |
| closeFn | callback function | Function | |
# License
MIT
9 changes: 8 additions & 1 deletion packages/indicator/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue';

const Indicator = Vue.extend(require('./src/indicator.vue'));
let instance;
let instance, timerId;

export default {
open(options = {}) {
Expand All @@ -17,12 +17,19 @@ export default {

Vue.nextTick(() => {
instance.visible = true;
if (options.duration && options.duration > 0) {
timerId = setTimeout(() => {
if (instance.visible) instance.visible = false;
if (typeof options.closeFn === 'function') options.closeFn();
}, options.duration);
}
});
},

close() {
if (instance) {
instance.visible = false;
timerId && clearTimeout(timerId);
}
}
};