¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view |
| | | class="u-loading-icon" |
| | | :style="[$u.addStyle(customStyle)]" |
| | | :class="[vertical && 'u-loading-icon--vertical']" |
| | | v-if="show" |
| | | > |
| | | <view |
| | | v-if="!webviewHide" |
| | | class="u-loading-icon__spinner" |
| | | :class="[`u-loading-icon__spinner--${mode}`]" |
| | | ref="ani" |
| | | :style="{ |
| | | color: color, |
| | | width: $u.addUnit(size), |
| | | height: $u.addUnit(size), |
| | | borderTopColor: color, |
| | | borderBottomColor: otherBorderColor, |
| | | borderLeftColor: otherBorderColor, |
| | | borderRightColor: otherBorderColor, |
| | | 'animation-duration': `${duration}ms`, |
| | | 'animation-timing-function': mode === 'semicircle' || mode === 'circle' ? timingFunction : '' |
| | | }" |
| | | > |
| | | <block v-if="mode === 'spinner'"> |
| | | <!-- #ifndef APP-NVUE --> |
| | | <view |
| | | v-for="(item, index) in array12" |
| | | :key="index" |
| | | class="u-loading-icon__dot" |
| | | > |
| | | </view> |
| | | <!-- #endif --> |
| | | <!-- #ifdef APP-NVUE --> |
| | | <!-- æ¤ç»ä»¶å
é¨å¾æ é¨åæ æ³è®¾ç½®å®½é«ï¼å³ä½¿éè¿widthåheighté
ç½®äºä¹æ æ --> |
| | | <loading-indicator |
| | | v-if="!webviewHide" |
| | | class="u-loading-indicator" |
| | | :animating="true" |
| | | :style="{ |
| | | color: color, |
| | | width: $u.addUnit(size), |
| | | height: $u.addUnit(size) |
| | | }" |
| | | /> |
| | | <!-- #endif --> |
| | | </block> |
| | | </view> |
| | | <text |
| | | v-if="text" |
| | | class="u-loading-icon__text" |
| | | :style="{ |
| | | fontSize: $u.addUnit(textSize), |
| | | color: textColor, |
| | | }" |
| | | >{{text}}</text> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | import props from './props.js'; |
| | | // #ifdef APP-NVUE |
| | | const animation = weex.requireModule('animation'); |
| | | // #endif |
| | | /** |
| | | * loading å è½½å¨ç» |
| | | * @description è¦æ¤ç»ä»¶ä¸ºä¸ä¸ªå°å¨ç»ï¼ç®åç¨å¨uViewçloadmoreå è½½æ´å¤åswitchå¼å
³çç»ä»¶çæ£å¨å è½½ç¶æåºæ¯ã |
| | | * @tutorial https://www.uviewui.com/components/loading.html |
| | | * @property {Boolean} show æ¯å¦æ¾ç¤ºç»ä»¶ (é»è®¤ true) |
| | | * @property {String} color å¨ç»æ´»å¨åºåçé¢è²ï¼åªå¯¹ mode = flower æ¨¡å¼ææï¼é»è®¤color['u-tips-color']ï¼ |
| | | * @property {String} textColor æç¤ºææ¬çé¢è²ï¼é»è®¤color['u-tips-color']ï¼ |
| | | * @property {Boolean} vertical æåå徿 æ¯å¦åç´æå (é»è®¤ false ) |
| | | * @property {String} mode 模å¼éæ©ï¼è§å®ç½è¯´æï¼é»è®¤ 'circle' ï¼ |
| | | * @property {String | Number} size å è½½å¾æ ç大å°ï¼åä½px ï¼é»è®¤ 24 ï¼ |
| | | * @property {String | Number} textSize æå大å°ï¼é»è®¤ 15 ï¼ |
| | | * @property {String | Number} text æåå
容 |
| | | * @property {String} timingFunction å¨ç»æ¨¡å¼ ï¼é»è®¤ 'ease-in-out' ï¼ |
| | | * @property {String | Number} duration å¨ç»æ§è¡å¨ææ¶é´ï¼é»è®¤ 1200ï¼ |
| | | * @property {String} inactiveColor mode=circleæ¶çæè¾¹é¢è² |
| | | * @property {Object} customStyle å®ä¹éè¦ç¨å°çå¤é¨æ ·å¼ |
| | | * @example <u-loading mode="circle"></u-loading> |
| | | */ |
| | | export default { |
| | | name: 'u-loading-icon', |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props], |
| | | data() { |
| | | return { |
| | | // Array.formå¯ä»¥éè¿ä¸ä¸ªä¼ªæ°ç»å¯¹è±¡å建æå®é¿åº¦çæ°ç» |
| | | // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/from |
| | | array12: Array.from({ |
| | | length: 12 |
| | | }), |
| | | // è¿ééè¦è®¾ç½®é»è®¤å¼ä¸º360ï¼å¦åå¨å®ånvueä¸ï¼ä¼å»¶è¿ä¸ä¸ªduration卿忿§è¡ |
| | | // å¨iOS nvueä¸ï¼åä¼ä¸å¼å§é»è®¤æ§è¡ä¸¤ä¸ªå¨æçå¨ç» |
| | | aniAngel: 360, // å¨ç»æè½¬è§åº¦ |
| | | webviewHide: false, // çå¬webviewçç¶æï¼å¦æéèäºé¡µé¢ï¼å忢å¨ç»ï¼ä»¥å
æ§è½æ¶è |
| | | loading: false, // æ¯å¦è¿è¡ä¸ï¼é对nvueä½¿ç¨ |
| | | } |
| | | }, |
| | | computed: { |
| | | // å½ä¸ºcircleç±»åæ¶ï¼ç»å
¶å¦å¤ä¸è¾¹è®¾ç½®ä¸ä¸ªæ´è½»ä¸äºçé¢è² |
| | | // 乿以éè¦è¿ä¹åçåå æ¯ï¼æ¯å¦ç¶ç»ä»¶ä¼ äºcolor为红è²ï¼é£ä¹éè¦å¦å¤çä¸ä¸ªè¾¹ä¸ºæµ
çº¢è² |
| | | // èä¸è½æ¯åºå®çæä¸ä¸ªå
¶ä»é¢è²(å 为è¿ä¸ªåºå®çé¢è²å¯è½æµ
èï¼å¯¼è´æææ²¡æé£ä¹ç»è
»è¯å¥½) |
| | | otherBorderColor() { |
| | | const lightColor = uni.$u.colorGradient(this.color, '#ffffff', 100)[80] |
| | | if (this.mode === 'circle') { |
| | | return this.inactiveColor ? this.inactiveColor : lightColor |
| | | } else { |
| | | return 'transparent' |
| | | } |
| | | // return this.mode === 'circle' ? this.inactiveColor ? this.inactiveColor : lightColor : 'transparent' |
| | | } |
| | | }, |
| | | watch: { |
| | | show(n) { |
| | | // nvueä¸ï¼show为trueï¼ä¸ä¸ºéloadingç¶æï¼å°±éæ°æ§è¡å¨ç»æ¨¡å |
| | | // #ifdef APP-NVUE |
| | | if (n && !this.loading) { |
| | | setTimeout(() => { |
| | | this.startAnimate() |
| | | }, 30) |
| | | } |
| | | // #endif |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.init() |
| | | }, |
| | | methods: { |
| | | init() { |
| | | setTimeout(() => { |
| | | // #ifdef APP-NVUE |
| | | this.show && this.nvueAnimate() |
| | | // #endif |
| | | // #ifdef APP-PLUS |
| | | this.show && this.addEventListenerToWebview() |
| | | // #endif |
| | | }, 20) |
| | | }, |
| | | // çå¬webviewçæ¾ç¤ºä¸éè |
| | | addEventListenerToWebview() { |
| | | // webviewçå æ |
| | | const pages = getCurrentPages() |
| | | // å½åé¡µé¢ |
| | | const page = pages[pages.length - 1] |
| | | // å½å页é¢çwebviewå®ä¾ |
| | | const currentWebview = page.$getAppWebview() |
| | | // çå¬webviewçæ¾ç¤ºä¸éèï¼ä»è忢æè
å¼å§å¨ç»(ä¸ºäºæ§è½) |
| | | currentWebview.addEventListener('hide', () => { |
| | | this.webviewHide = true |
| | | }) |
| | | currentWebview.addEventListener('show', () => { |
| | | this.webviewHide = false |
| | | }) |
| | | }, |
| | | // #ifdef APP-NVUE |
| | | nvueAnimate() { |
| | | // nvueä¸ï¼éspinnerç±»åæ¶æéè¦æè½¬ï¼å 为nvueçspinnerç±»åï¼ä½¿ç¨äºweexç |
| | | // loading-indicatorç»ä»¶ï¼èªå¸¦æè½¬åè½ |
| | | this.mode !== 'spinner' && this.startAnimate() |
| | | }, |
| | | // æ§è¡nvueçanimate模åå¨ç» |
| | | startAnimate() { |
| | | this.loading = true |
| | | const ani = this.$refs.ani |
| | | if (!ani) return |
| | | animation.transition(ani, { |
| | | // è¿è¡è§åº¦æè½¬ |
| | | styles: { |
| | | transform: `rotate(${this.aniAngel}deg)`, |
| | | transformOrigin: 'center center' |
| | | }, |
| | | duration: this.duration, |
| | | timingFunction: this.timingFunction, |
| | | // delay: 10 |
| | | }, () => { |
| | | // æ¯æ¬¡å¢å 360degï¼ä¸ºäºè®©å
¶éæ°æè½¬ä¸å¨ |
| | | this.aniAngel += 360 |
| | | // å¨ç»ç»æåï¼ç»§ç»å¾ªç¯æ§è¡å¨ç»ï¼éè¦åæ¶å¤æwebviewHideåé |
| | | // nvueå®åï¼é¡µé¢éèåä¾ç¶ä¼ç»§ç»æ§è¡startAnimateæ¹æ³ |
| | | this.show && !this.webviewHide ? this.startAnimate() : this.loading = false |
| | | }) |
| | | } |
| | | // #endif |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | $u-loading-icon-color: #c8c9cc !default; |
| | | $u-loading-icon-text-margin-left:4px !default; |
| | | $u-loading-icon-text-color:$u-content-color !default; |
| | | $u-loading-icon-text-font-size:14px !default; |
| | | $u-loading-icon-text-line-height:20px !default; |
| | | $u-loading-width:30px !default; |
| | | $u-loading-height:30px !default; |
| | | $u-loading-max-width:100% !default; |
| | | $u-loading-max-height:100% !default; |
| | | $u-loading-semicircle-border-width: 2px !default; |
| | | $u-loading-semicircle-border-color:transparent !default; |
| | | $u-loading-semicircle-border-top-right-radius: 100px !default; |
| | | $u-loading-semicircle-border-top-left-radius: 100px !default; |
| | | $u-loading-semicircle-border-bottom-left-radius: 100px !default; |
| | | $u-loading-semicircle-border-bottom-right-radiu: 100px !default; |
| | | $u-loading-semicircle-border-style: solid !default; |
| | | $u-loading-circle-border-top-right-radius: 100px !default; |
| | | $u-loading-circle-border-top-left-radius: 100px !default; |
| | | $u-loading-circle-border-bottom-left-radius: 100px !default; |
| | | $u-loading-circle-border-bottom-right-radiu: 100px !default; |
| | | $u-loading-circle-border-width:2px !default; |
| | | $u-loading-circle-border-top-color:#e5e5e5 !default; |
| | | $u-loading-circle-border-right-color:$u-loading-circle-border-top-color !default; |
| | | $u-loading-circle-border-bottom-color:$u-loading-circle-border-top-color !default; |
| | | $u-loading-circle-border-left-color:$u-loading-circle-border-top-color !default; |
| | | $u-loading-circle-border-style:solid !default; |
| | | $u-loading-icon-host-font-size:0px !default; |
| | | $u-loading-icon-host-line-height:1 !default; |
| | | $u-loading-icon-vertical-margin:6px 0 0 !default; |
| | | $u-loading-icon-dot-top:0 !default; |
| | | $u-loading-icon-dot-left:0 !default; |
| | | $u-loading-icon-dot-width:100% !default; |
| | | $u-loading-icon-dot-height:100% !default; |
| | | $u-loading-icon-dot-before-width:2px !default; |
| | | $u-loading-icon-dot-before-height:25% !default; |
| | | $u-loading-icon-dot-before-margin:0 auto !default; |
| | | $u-loading-icon-dot-before-background-color:currentColor !default; |
| | | $u-loading-icon-dot-before-border-radius:40% !default; |
| | | |
| | | .u-loading-icon { |
| | | /* #ifndef APP-NVUE */ |
| | | // display: inline-flex; |
| | | /* #endif */ |
| | | flex-direction: row; |
| | | align-items: center; |
| | | justify-content: center; |
| | | color: $u-loading-icon-color; |
| | | |
| | | &__text { |
| | | margin-left: $u-loading-icon-text-margin-left; |
| | | color: $u-loading-icon-text-color; |
| | | font-size: $u-loading-icon-text-font-size; |
| | | line-height: $u-loading-icon-text-line-height; |
| | | } |
| | | |
| | | &__spinner { |
| | | width: $u-loading-width; |
| | | height: $u-loading-height; |
| | | position: relative; |
| | | /* #ifndef APP-NVUE */ |
| | | box-sizing: border-box; |
| | | max-width: $u-loading-max-width; |
| | | max-height: $u-loading-max-height; |
| | | animation: u-rotate 1s linear infinite; |
| | | /* #endif */ |
| | | } |
| | | |
| | | &__spinner--semicircle { |
| | | border-width: $u-loading-semicircle-border-width; |
| | | border-color: $u-loading-semicircle-border-color; |
| | | border-top-right-radius: $u-loading-semicircle-border-top-right-radius; |
| | | border-top-left-radius: $u-loading-semicircle-border-top-left-radius; |
| | | border-bottom-left-radius: $u-loading-semicircle-border-bottom-left-radius; |
| | | border-bottom-right-radius: $u-loading-semicircle-border-bottom-right-radiu; |
| | | border-style: $u-loading-semicircle-border-style; |
| | | } |
| | | |
| | | &__spinner--circle { |
| | | border-top-right-radius: $u-loading-circle-border-top-right-radius; |
| | | border-top-left-radius: $u-loading-circle-border-top-left-radius; |
| | | border-bottom-left-radius: $u-loading-circle-border-bottom-left-radius; |
| | | border-bottom-right-radius: $u-loading-circle-border-bottom-right-radiu; |
| | | border-width: $u-loading-circle-border-width; |
| | | border-top-color: $u-loading-circle-border-top-color; |
| | | border-right-color: $u-loading-circle-border-right-color; |
| | | border-bottom-color: $u-loading-circle-border-bottom-color; |
| | | border-left-color: $u-loading-circle-border-left-color; |
| | | border-style: $u-loading-circle-border-style; |
| | | } |
| | | |
| | | &--vertical { |
| | | flex-direction: column |
| | | } |
| | | } |
| | | |
| | | /* #ifndef APP-NVUE */ |
| | | :host { |
| | | font-size: $u-loading-icon-host-font-size; |
| | | line-height: $u-loading-icon-host-line-height; |
| | | } |
| | | |
| | | .u-loading-icon { |
| | | &__spinner--spinner { |
| | | animation-timing-function: steps(12) |
| | | } |
| | | |
| | | &__text:empty { |
| | | display: none |
| | | } |
| | | |
| | | &--vertical &__text { |
| | | margin: $u-loading-icon-vertical-margin; |
| | | color: $u-content-color; |
| | | } |
| | | |
| | | &__dot { |
| | | position: absolute; |
| | | top: $u-loading-icon-dot-top; |
| | | left: $u-loading-icon-dot-left; |
| | | width: $u-loading-icon-dot-width; |
| | | height: $u-loading-icon-dot-height; |
| | | |
| | | &:before { |
| | | display: block; |
| | | width: $u-loading-icon-dot-before-width; |
| | | height: $u-loading-icon-dot-before-height; |
| | | margin: $u-loading-icon-dot-before-margin; |
| | | background-color: $u-loading-icon-dot-before-background-color; |
| | | border-radius: $u-loading-icon-dot-before-border-radius; |
| | | content: " " |
| | | } |
| | | } |
| | | } |
| | | |
| | | @for $i from 1 through 12 { |
| | | .u-loading-icon__dot:nth-of-type(#{$i}) { |
| | | transform: rotate($i * 30deg); |
| | | opacity: 1 - 0.0625 * ($i - 1); |
| | | } |
| | | } |
| | | |
| | | @keyframes u-rotate { |
| | | 0% { |
| | | transform: rotate(0deg) |
| | | } |
| | | |
| | | to { |
| | | transform: rotate(1turn) |
| | | } |
| | | } |
| | | |
| | | /* #endif */ |
| | | </style> |