123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- <template>
- <view>
- <sjs src="../wxs/utils.sjs" module="utils" />
- <button
- :id="id"
- :class="
- 'custom-class ' +
- utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]) +
- ' ' +
- (hairline ? 'van-hairline--surround' : '')
- "
- hover-class="van-button--active hover-class"
- :lang="lang"
- :style="style + ' ' + customStyle"
- :open-type="openType"
- :business-id="businessId"
- :session-from="sessionFrom"
- :send-message-title="sendMessageTitle"
- :send-message-path="sendMessagePath"
- :send-message-img="sendMessageImg"
- :show-message-card="showMessageCard"
- :app-parameter="appParameter"
- :aria-label="ariaLabel"
- @tap="onClick"
- @getuserinfo="bindGetUserInfo"
- @contact="bindContact"
- @getphonenumber="bindGetPhoneNumber"
- @error="bindError"
- @launchapp="bindLaunchApp"
- @opensetting="bindOpenSetting"
- >
- <block :wx:if="loading">
- <van-loading custom-class="loading-class" :size="loadingSize" :type="loadingType" :color="type === 'default' ? '#c9c9c9' : 'white'" />
- <view :wx:if="loadingText" class="van-button__loading-text">
- {{ loadingText }}
- </view>
- </block>
- <block wx:else>
- <van-icon :wx:if="icon" size="1.2em" :name="icon" class="van-button__icon" custom-style="line-height: inherit;" />
- <view class="van-button__text">
- <slot />
- </view>
- </block>
- </button>
- </view>
- </template>
- <script>
- import { VantComponent } from '../common/component';
- import { button } from '../mixins/button';
- import { openType } from '../mixins/open-type';
- export default {
- data() {
- return {
- style: '',
- id: '',
- lang: '',
- openType: '',
- businessId: '',
- sessionFrom: '',
- sendMessageTitle: '',
- sendMessagePath: '',
- sendMessageImg: '',
- showMessageCard: '',
- appParameter: '',
- ariaLabel: ''
- };
- },
- mixins: [button, openType],
- classes: ['hover-class', 'loading-class'],
- props: {
- icon: String,
- plain: Boolean,
- block: Boolean,
- round: Boolean,
- square: Boolean,
- loading: Boolean,
- hairline: Boolean,
- disabled: Boolean,
- loadingText: String,
- customStyle: String,
- loadingType: {
- type: String,
- default: 'circular'
- },
- type: {
- type: String,
- default: 'default'
- },
- size: {
- type: String,
- default: 'normal'
- },
- loadingSize: {
- type: String,
- default: '20px'
- },
- color: {
- type: String
- }
- },
- methods: {
- onClick() {
- if (!this.disabled && !this.loading) {
- this.$emit('click');
- }
- },
- bindGetUserInfo() {
- console.log('占位:函数 bindGetUserInfo 未声明');
- },
- bindContact() {
- console.log('占位:函数 bindContact 未声明');
- },
- bindGetPhoneNumber() {
- console.log('占位:函数 bindGetPhoneNumber 未声明');
- },
- bindError() {
- console.log('占位:函数 bindError 未声明');
- },
- bindLaunchApp() {
- console.log('占位:函数 bindLaunchApp 未声明');
- },
- bindOpenSetting() {
- console.log('占位:函数 bindOpenSetting 未声明');
- }
- },
- watch: {
- color: {
- handler: function (color) {
- let style = '';
- if (color) {
- style += `color: ${this.plain ? color : 'white'};`;
- if (!this.plain) {
- // Use background instead of backgroundColor to make linear-gradient work
- style += `background: ${color};`;
- }
- // hide border when color is linear-gradient
- if (color.indexOf('gradient') !== -1) {
- style += 'border: 0;';
- } else {
- style += `border-color: ${color};`;
- }
- }
- if (style !== this.style) {
- this.setData({
- style
- });
- }
- },
- immediate: true
- }
- }
- };
- </script>
- <style>
- @import '../common/index.ttss';
- .van-button {
- position: relative;
- display: -webkit-inline-flex;
- display: inline-flex;
- -webkit-align-items: center;
- align-items: center;
- -webkit-justify-content: center;
- justify-content: center;
- box-sizing: border-box;
- padding: 0;
- line-height: 20px;
- text-align: center;
- vertical-align: middle;
- -webkit-appearance: none;
- -webkit-text-size-adjust: 100%;
- height: 44px;
- height: var(--button-default-height, 44px);
- font-size: 16px;
- font-size: var(--button-default-font-size, 16px);
- transition: opacity 0.2s;
- transition: opacity var(--animation-duration-fast, 0.2s);
- border-radius: 2px;
- border-radius: var(--button-border-radius, 2px);
- }
- .van-button:before {
- position: absolute;
- top: 50%;
- left: 50%;
- width: 100%;
- height: 100%;
- border: inherit;
- border-radius: inherit;
- -webkit-transform: translate(-50%, -50%);
- transform: translate(-50%, -50%);
- opacity: 0;
- content: ' ';
- background-color: #000;
- background-color: var(--black, #000);
- border-color: #000;
- border-color: var(--black, #000);
- }
- .van-button:after {
- border-width: 0;
- }
- .van-button--active:before {
- opacity: 0.15;
- }
- .van-button--unclickable:after {
- display: none;
- }
- .van-button--default {
- color: #323233;
- color: var(--button-default-color, #323233);
- background-color: #fff;
- background-color: var(--button-default-background-color, #fff);
- border: 1px solid #ebedf0;
- border: 1px solid var(--button-default-border-color, #ebedf0);
- }
- .van-button--primary {
- color: #fff;
- color: var(--button-primary-color, #fff);
- background-color: #07c160;
- background-color: var(--button-primary-background-color, #07c160);
- border: 1px solid #07c160;
- border: 1px solid var(--button-primary-border-color, #07c160);
- }
- .van-button--info {
- color: #fff;
- color: var(--button-info-color, #fff);
- background-color: #1989fa;
- background-color: var(--button-info-background-color, #1989fa);
- border: 1px solid #1989fa;
- border: 1px solid var(--button-info-border-color, #1989fa);
- }
- .van-button--danger {
- color: #fff;
- color: var(--button-danger-color, #fff);
- background-color: #ee0a24;
- background-color: var(--button-danger-background-color, #ee0a24);
- border: 1px solid #ee0a24;
- border: 1px solid var(--button-danger-border-color, #ee0a24);
- }
- .van-button--warning {
- color: #fff;
- color: var(--button-warning-color, #fff);
- background-color: #ff976a;
- background-color: var(--button-warning-background-color, #ff976a);
- border: 1px solid #ff976a;
- border: 1px solid var(--button-warning-border-color, #ff976a);
- }
- .van-button--plain {
- background-color: #fff;
- background-color: var(--button-plain-background-color, #fff);
- }
- .van-button--plain.van-button--primary {
- color: #07c160;
- color: var(--button-primary-background-color, #07c160);
- }
- .van-button--plain.van-button--info {
- color: #1989fa;
- color: var(--button-info-background-color, #1989fa);
- }
- .van-button--plain.van-button--danger {
- color: #ee0a24;
- color: var(--button-danger-background-color, #ee0a24);
- }
- .van-button--plain.van-button--warning {
- color: #ff976a;
- color: var(--button-warning-background-color, #ff976a);
- }
- .van-button--large {
- width: 100%;
- height: 50px;
- height: var(--button-large-height, 50px);
- }
- .van-button--normal {
- padding: 0 15px;
- font-size: 14px;
- font-size: var(--button-normal-font-size, 14px);
- }
- .van-button--small {
- min-width: 60px;
- min-width: var(--button-small-min-width, 60px);
- height: 30px;
- height: var(--button-small-height, 30px);
- padding: 0 8px;
- padding: 0 var(--padding-xs, 8px);
- font-size: 12px;
- font-size: var(--button-small-font-size, 12px);
- }
- .van-button--mini {
- display: inline-block;
- min-width: 50px;
- min-width: var(--button-mini-min-width, 50px);
- height: 22px;
- height: var(--button-mini-height, 22px);
- font-size: 10px;
- font-size: var(--button-mini-font-size, 10px);
- }
- .van-button--mini + .van-button--mini {
- margin-left: 5px;
- }
- .van-button--block {
- display: -webkit-flex;
- display: flex;
- width: 100%;
- }
- .van-button--round {
- border-radius: 999px;
- border-radius: var(--button-round-border-radius, 999px);
- }
- .van-button--square {
- border-radius: 0;
- }
- .van-button--disabled {
- opacity: 0.5;
- opacity: var(--button-disabled-opacity, 0.5);
- }
- .van-button__text {
- display: inline;
- }
- .van-button__icon + .van-button__text:not(:empty),
- .van-button__loading-text {
- margin-left: 4px;
- }
- .van-button__icon {
- min-width: 1em;
- line-height: inherit !important;
- vertical-align: top;
- }
- .van-button--hairline {
- padding-top: 1px;
- border-width: 0;
- }
- .van-button--hairline:after {
- border-color: inherit;
- border-width: 1px;
- border-radius: 4px;
- border-radius: calc(var(--button-border-radius, 2px) * 2);
- }
- .van-button--hairline.van-button--round:after {
- border-radius: 999px;
- border-radius: var(--button-round-border-radius, 999px);
- }
- .van-button--hairline.van-button--square:after {
- border-radius: 0;
- }
- </style>
|