cl-button.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <button
  3. class="cl-button"
  4. :class="[classList]"
  5. :size="size"
  6. :type="type"
  7. :disabled="disabled"
  8. :form-type="formType"
  9. :open-type="openType"
  10. :hover-class="hoverClass"
  11. :hover-start-time="hoverStartTime"
  12. :hover-stay-time="hoverStayTime"
  13. :app-parameter="appParameter"
  14. :hover-stop-propagation="hoverStopPropagation"
  15. :lang="lang"
  16. :session-form="sessionForm"
  17. :send-message-title="sendMessageTitle"
  18. :send-message-path="sendMessagePath"
  19. :send-message-img="sendMessageImg"
  20. :show-message-card="showMessageCard"
  21. @getphonenumber="getphonenumber"
  22. @getuserinfo="getuserinfo"
  23. @error="error"
  24. @opensetting="opensetting"
  25. @launchapp="launchapp"
  26. @tap.stop="tap"
  27. >
  28. <view class="cl-button__loading">
  29. <cl-loading
  30. v-if="loading"
  31. :size="16"
  32. :color="type ? '#fff' : ''"
  33. :theme="loadingTheme"
  34. ></cl-loading>
  35. <text class="cl-button__loading-text" v-if="loadingText && loadingMask">{{
  36. loadingText
  37. }}</text>
  38. </view>
  39. <text :class="['cl-button__icon', icon]" v-if="icon"></text>
  40. <view class="cl-button__text">
  41. <slot></slot>
  42. </view>
  43. </button>
  44. </template>
  45. <script>
  46. const { platform } = uni.getSystemInfoSync();
  47. /**
  48. * button 按钮
  49. * @description 该组件基于官方的 button 组件。参数与官方一致,同时添加新的支持。
  50. * @tutorial https://docs.cool-js.com/uni/components/basic/button.html
  51. * @property {String} size 按钮大小
  52. * @property {String} type 按钮类型
  53. * @property {Boolean} plain 是否镂空
  54. * @property {Boolean} disabled 是否禁用
  55. * @property {Boolean} loading 是否加载中
  56. * @property {String} loadingTheme 加载图标主题
  57. * @property {String} loadingMask 加载是否遮罩层模式
  58. * @property {String} loadingText 加载文案
  59. * @property {Boolean} round 是否圆角
  60. * @property {Boolean} shadow 是否阴影
  61. * @property {String} icon 左侧图标
  62. * @property {Boolean} fill 是否水平填充
  63. * @example <cl-button>按钮</cl-button>
  64. */
  65. export default {
  66. name: "cl-button",
  67. props: {
  68. // 按钮大小
  69. size: String,
  70. // 按钮类型
  71. type: String,
  72. // 是否镂空
  73. plain: Boolean,
  74. // 是否禁用
  75. disabled: Boolean,
  76. // 是否加载中
  77. loading: Boolean,
  78. // 加载图标主题
  79. loadingTheme: String,
  80. // 加载是否遮罩层模式
  81. loadingMask: Boolean,
  82. // 加载文案
  83. loadingText: String,
  84. // 是否圆角
  85. round: Boolean,
  86. // 是否阴影
  87. shadow: Boolean,
  88. // 左侧图标
  89. icon: String,
  90. // 是否水平填充
  91. fill: Boolean,
  92. formType: String,
  93. openType: String,
  94. hoverClass: {
  95. type: String,
  96. default: "button-hover",
  97. },
  98. hoverStartTime: {
  99. type: Number,
  100. default: 20,
  101. },
  102. hoverStayTime: {
  103. type: Number,
  104. default: 70,
  105. },
  106. appParameter: String,
  107. hoverStopPropagation: Boolean,
  108. lang: {
  109. type: String,
  110. default: "en",
  111. },
  112. sessionForm: String,
  113. sendMessageTitle: String,
  114. sendMessagePath: String,
  115. sendMessageImg: String,
  116. showMessageCard: Boolean,
  117. },
  118. computed: {
  119. classList() {
  120. let list = [];
  121. if (this.type) {
  122. list.push(`cl-button--${this.type}`);
  123. }
  124. if (this.size) {
  125. list.push(`cl-button--${this.size}`);
  126. }
  127. if (this.platform) {
  128. list.push(`is-${this.platform}`);
  129. }
  130. if (this.round) {
  131. list.push("is-round");
  132. }
  133. if (this.shadow) {
  134. list.push("is-shadow");
  135. }
  136. if (this.loading) {
  137. list.push("is-loading");
  138. }
  139. if (this.loadingMask) {
  140. list.push("is-loading-mask");
  141. }
  142. if (this.plain) {
  143. list.push("is-plain");
  144. }
  145. if (this.fill) {
  146. list.push("is-fill");
  147. }
  148. if (this.disabled) {
  149. list.push("is-disabled");
  150. }
  151. return list.join(" ");
  152. },
  153. },
  154. data() {
  155. return {
  156. platform,
  157. };
  158. },
  159. methods: {
  160. getphonenumber(e) {
  161. this.$emit("getphonenumber", e);
  162. },
  163. getuserinfo(e) {
  164. this.$emit("getuserinfo", e);
  165. },
  166. error(e) {
  167. this.$emit("error", e);
  168. },
  169. opensetting(e) {
  170. this.$emit("opensetting", e);
  171. },
  172. launchapp(e) {
  173. this.$emit("launchapp", e);
  174. },
  175. tap(e) {
  176. if (!this.disabled && !this.loading) {
  177. this.$emit("click", e);
  178. this.$emit("tap", e);
  179. }
  180. },
  181. },
  182. };
  183. </script>