123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- <template>
- <button
- id="u-wave-btn"
- class="u-btn u-line-1 u-fix-ios-appearance"
- :class="[
- 'u-size-' + size,
- plain ? 'u-btn--' + type + '--plain' : '',
- loading ? 'u-loading' : '',
- shape == 'circle' ? 'u-round-circle' : '',
- hairLine ? showHairLineBorder : 'u-btn--bold-border',
- 'u-btn--' + type,
- disabled ? `u-btn--${type}--disabled` : '',
- ]"
- :hover-start-time="Number(hoverStartTime)"
- :hover-stay-time="Number(hoverStayTime)"
- :disabled="disabled"
- :form-type="formType"
- :open-type="openType"
- :app-parameter="appParameter"
- :hover-stop-propagation="hoverStopPropagation"
- :send-message-title="sendMessageTitle"
- send-message-path="sendMessagePath"
- :lang="lang"
- :data-name="dataName"
- :session-from="sessionFrom"
- :send-message-img="sendMessageImg"
- :show-message-card="showMessageCard"
- @getphonenumber="getphonenumber"
- @getuserinfo="getuserinfo"
- @error="error"
- @opensetting="opensetting"
- @launchapp="launchapp"
- :style="[customStyle, {
- overflow: ripple ? 'hidden' : 'visible'
- }]"
- @tap.stop="click($event)"
- :hover-class="getHoverClass"
- :loading="loading"
- >
- <slot></slot>
- <view
- v-if="ripple"
- class="u-wave-ripple"
- :class="[waveActive ? 'u-wave-active' : '']"
- :style="{
- top: rippleTop + 'px',
- left: rippleLeft + 'px',
- width: fields.targetWidth + 'px',
- height: fields.targetWidth + 'px',
- 'background-color': rippleBgColor || 'rgba(0, 0, 0, 0.15)'
- }"
- ></view>
- </button>
- </template>
- <script>
- export default {
- name: 'u-button',
- props: {
-
- hairLine: {
- type: Boolean,
- default: true
- },
-
- type: {
- type: String,
- default: 'default'
- },
-
- size: {
- type: String,
- default: 'default'
- },
-
- shape: {
- type: String,
- default: 'square'
- },
-
- plain: {
- type: Boolean,
- default: false
- },
-
- disabled: {
- type: Boolean,
- default: false
- },
-
- loading: {
- type: Boolean,
- default: false
- },
-
-
- openType: {
- type: String,
- default: ''
- },
-
-
- formType: {
- type: String,
- default: ''
- },
-
-
- appParameter: {
- type: String,
- default: ''
- },
-
- hoverStopPropagation: {
- type: Boolean,
- default: false
- },
-
- lang: {
- type: String,
- default: 'en'
- },
-
- sessionFrom: {
- type: String,
- default: ''
- },
-
-
- sendMessageTitle: {
- type: String,
- default: ''
- },
-
-
- sendMessagePath: {
- type: String,
- default: ''
- },
-
-
- sendMessageImg: {
- type: String,
- default: ''
- },
-
-
- showMessageCard: {
- type: Boolean,
- default: false
- },
-
- hoverBgColor: {
- type: String,
- default: ''
- },
-
- rippleBgColor: {
- type: String,
- default: ''
- },
-
- ripple: {
- type: Boolean,
- default: false
- },
-
- hoverClass: {
- type: String,
- default: ''
- },
-
- customStyle: {
- type: Object,
- default() {
- return {};
- }
- },
-
- dataName: {
- type: String,
- default: ''
- },
-
- throttleTime: {
- type: [String, Number],
- default: 1000
- },
-
- hoverStartTime: {
- type: [String, Number],
- default: 20
- },
-
- hoverStayTime: {
- type: [String, Number],
- default: 150
- },
- },
- computed: {
-
- getHoverClass() {
-
- if (this.loading || this.disabled || this.ripple || this.hoverClass) return '';
- let hoverClass = '';
- hoverClass = this.plain ? 'u-' + this.type + '-plain-hover' : 'u-' + this.type + '-hover';
- return hoverClass;
- },
-
- showHairLineBorder() {
- if (['primary', 'success', 'error', 'warning'].indexOf(this.type) >= 0 && !this.plain) {
- return '';
- } else {
- return 'u-hairline-border';
- }
- }
- },
- data() {
- return {
- rippleTop: 0,
- rippleLeft: 0,
- fields: {},
- waveActive: false
- };
- },
- methods: {
-
- click(e) {
-
- this.$u.throttle(() => {
-
- if (this.loading === true || this.disabled === true) return;
-
- if (this.ripple) {
-
- this.waveActive = false;
- this.$nextTick(function() {
- this.getWaveQuery(e);
- });
- }
- this.$emit('click', e);
- }, this.throttleTime);
- },
-
- getWaveQuery(e) {
- this.getElQuery().then(res => {
-
- let data = res[0];
-
- if (!data.width || !data.width) return;
-
-
- data.targetWidth = data.height > data.width ? data.height : data.width;
- if (!data.targetWidth) return;
- this.fields = data;
- let touchesX = '',
- touchesY = '';
-
- touchesX = e.changedTouches[0].clientX;
- touchesY = e.changedTouches[0].clientY;
-
-
- touchesX = e.detail.clientX;
- touchesY = e.detail.clientY;
-
-
- touchesX = e.touches[0].clientX;
- touchesY = e.touches[0].clientY;
-
-
-
-
- this.rippleTop = touchesY - data.top - data.targetWidth / 2;
- this.rippleLeft = touchesX - data.left - data.targetWidth / 2;
- this.$nextTick(() => {
- this.waveActive = true;
- });
- });
- },
-
- getElQuery() {
- return new Promise(resolve => {
- let queryInfo = '';
-
-
- queryInfo = uni.createSelectorQuery().in(this);
-
- queryInfo = uni.createSelectorQuery();
-
- queryInfo.select('.u-btn').boundingClientRect();
- queryInfo.exec(data => {
- resolve(data);
- });
- });
- },
-
- getphonenumber(res) {
- this.$emit('getphonenumber', res);
- },
- getuserinfo(res) {
- this.$emit('getuserinfo', res);
- },
- error(res) {
- this.$emit('error', res);
- },
- opensetting(res) {
- this.$emit('opensetting', res);
- },
- launchapp(res) {
- this.$emit('launchapp', res);
- }
- }
- };
- </script>
- <style scoped lang="scss">
- @import '../../libs/css/style.components.scss';
- .u-btn::after {
- border: none;
- }
- .u-btn {
- position: relative;
- border: 0;
-
-
- display: inline-flex;
-
-
- overflow: visible;
- line-height: 1;
- @include vue-flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- padding: 0 40rpx;
- z-index: 1;
- box-sizing: border-box;
- transition: all 0.15s;
-
- &--bold-border {
- border: 1px solid #ffffff;
- }
-
- &--default {
- color: $u-content-color;
- border-color: #c0c4cc;
- background-color: #ffffff;
- }
-
- &--primary {
- color: #ffffff;
- border-color: $u-type-primary;
- background-color: $u-type-primary;
- }
-
- &--success {
- color: #ffffff;
- border-color: $u-type-success;
- background-color: $u-type-success;
- }
-
- &--error {
- color: #ffffff;
- border-color: $u-type-error;
- background-color: $u-type-error;
- }
-
- &--warning {
- color: #ffffff;
- border-color: $u-type-warning;
- background-color: $u-type-warning;
- }
-
- &--default--disabled {
- color: #ffffff;
- border-color: #e4e7ed;
- background-color: #ffffff;
- }
-
- &--primary--disabled {
- color: #ffffff!important;
- border-color: $u-type-primary-disabled!important;
- background-color: $u-type-primary-disabled!important;
- }
-
- &--success--disabled {
- color: #ffffff!important;
- border-color: $u-type-success-disabled!important;
- background-color: $u-type-success-disabled!important;
- }
-
- &--error--disabled {
- color: #ffffff!important;
- border-color: $u-type-error-disabled!important;
- background-color: $u-type-error-disabled!important;
- }
-
- &--warning--disabled {
- color: #ffffff!important;
- border-color: $u-type-warning-disabled!important;
- background-color: $u-type-warning-disabled!important;
- }
-
- &--primary--plain {
- color: $u-type-primary!important;
- border-color: $u-type-primary-disabled!important;
- background-color: $u-type-primary-light!important;
- }
-
- &--success--plain {
- color: $u-type-success!important;
- border-color: $u-type-success-disabled!important;
- background-color: $u-type-success-light!important;
- }
-
- &--error--plain {
- color: $u-type-error!important;
- border-color: $u-type-error-disabled!important;
- background-color: $u-type-error-light!important;
- }
-
- &--warning--plain {
- color: $u-type-warning!important;
- border-color: $u-type-warning-disabled!important;
- background-color: $u-type-warning-light!important;
- }
- }
- .u-hairline-border:after {
- content: ' ';
- position: absolute;
- pointer-events: none;
-
- box-sizing: border-box;
-
- -webkit-transform-origin: 0 0;
- transform-origin: 0 0;
- left: 0;
- top: 0;
- width: 199.8%;
- height: 199.7%;
- -webkit-transform: scale(0.5, 0.5);
- transform: scale(0.5, 0.5);
- border: 1px solid currentColor;
- z-index: 1;
- }
- .u-wave-ripple {
- z-index: 0;
- position: absolute;
- border-radius: 100%;
- background-clip: padding-box;
- pointer-events: none;
- user-select: none;
- transform: scale(0);
- opacity: 1;
- transform-origin: center;
- }
- .u-wave-ripple.u-wave-active {
- opacity: 0;
- transform: scale(2);
- transition: opacity 1s linear, transform 0.4s linear;
- }
- .u-round-circle {
- border-radius: 100rpx;
- }
- .u-round-circle::after {
- border-radius: 100rpx;
- }
- .u-loading::after {
- background-color: hsla(0, 0%, 100%, 0.35);
- }
- .u-size-default {
- font-size: 30rpx;
- height: 80rpx;
- line-height: 80rpx;
- }
- .u-size-medium {
-
- display: inline-flex;
-
- width: auto;
- font-size: 26rpx;
- height: 70rpx;
- line-height: 70rpx;
- padding: 0 80rpx;
- }
- .u-size-mini {
-
- display: inline-flex;
-
- width: auto;
- font-size: 22rpx;
- padding-top: 1px;
- height: 50rpx;
- line-height: 50rpx;
- padding: 0 20rpx;
- }
- .u-primary-plain-hover {
- color: #ffffff !important;
- background: $u-type-primary-dark !important;
- }
- .u-default-plain-hover {
- color: $u-type-primary-dark !important;
- background: $u-type-primary-light !important;
- }
- .u-success-plain-hover {
- color: #ffffff !important;
- background: $u-type-success-dark !important;
- }
- .u-warning-plain-hover {
- color: #ffffff !important;
- background: $u-type-warning-dark !important;
- }
- .u-error-plain-hover {
- color: #ffffff !important;
- background: $u-type-error-dark !important;
- }
- .u-info-plain-hover {
- color: #ffffff !important;
- background: $u-type-info-dark !important;
- }
- .u-default-hover {
- color: $u-type-primary-dark !important;
- border-color: $u-type-primary-dark !important;
- background-color: $u-type-primary-light !important;
- }
- .u-primary-hover {
- background: $u-type-primary-dark !important;
- color: #fff;
- }
- .u-success-hover {
- background: $u-type-success-dark !important;
- color: #fff;
- }
- .u-info-hover {
- background: $u-type-info-dark !important;
- color: #fff;
- }
- .u-warning-hover {
- background: $u-type-warning-dark !important;
- color: #fff;
- }
- .u-error-hover {
- background: $u-type-error-dark !important;
- color: #fff;
- }
- </style>
|