button


按钮

示例

  1. <template>
  2. <view class="container">
  3. <scroller
  4. height = "{{-1}}"
  5. >
  6. <view class="section-title">
  7. <text class="section-title-text">类型样式</text>
  8. </view>
  9. <view class="button-list">
  10. <text class="button-text">default/blue</text>
  11. <button c-bind:onclick='testclick' ></button>
  12. <text class="button-text">disabled</text>
  13. <button
  14. type="blue"
  15. text="确定"
  16. disabled="{{true}}"
  17. c-bind:onclick='testclick'
  18. >
  19. </button>
  20. <text class="button-text">orange</text>
  21. <button
  22. type="orange"
  23. text="确定"
  24. c-bind:onclick='testclick'
  25. >
  26. </button>
  27. <text class="button-text">red && disabled</text>
  28. <button
  29. type="red"
  30. text="确定"
  31. disabled="{{true}}"
  32. c-bind:onclick='testclick'
  33. >
  34. </button>
  35. <text class="button-text">green</text>
  36. <button
  37. type="green"
  38. text="确定"
  39. c-bind:onclick='testclick'
  40. >
  41. </button>
  42. </view>
  43. <view class="section-title">
  44. <text class="section-title-text">尺寸</text>
  45. </view>
  46. <view class="button-list">
  47. <text class="button-text">big</text>
  48. <button c-bind:onclick='testclick' ></button>
  49. <text class="button-text">medium</text>
  50. <button
  51. type="orange"
  52. text="确定"
  53. size="medium"
  54. c-bind:onclick='testclick' >
  55. </button>
  56. <text class="button-text">small</text>
  57. <button
  58. type="red"
  59. text="确定"
  60. size="small"
  61. disabled="{{true}}"
  62. c-bind:onclick='testclick'
  63. >
  64. </button>
  65. </view>
  66. <view class="section-title">
  67. <text class="section-title-text">微信开放能力</text>
  68. </view>
  69. <view>
  70. <text class="button-text">进入客服会话</text>
  71. <button
  72. open-type="contact"
  73. session-from="{{sessionFrom}}"
  74. send-message-title="{{messageTitle}}"
  75. send-message-path="{{messagePath}}"
  76. send-message-img="{{messageImg}}"
  77. show-message-card="{{true}}"
  78. c-bind:contact="bindcontact"
  79. c-bind:onclick='testclick'
  80. >
  81. </button>
  82. <text class="button-text">触发用户转发</text>
  83. <button
  84. open-type="share"
  85. c-bind:onclick='testclick'
  86. >
  87. </button>
  88. <text class="button-text">获取用户信息</text>
  89. <button
  90. open-type="getUserInfo"
  91. lang="zh_CN"
  92. c-bind:getuserinfo="bindgetuserinfo"
  93. c-bind:onclick='testclick'
  94. >
  95. </button>
  96. <text class="button-text">获取用户手机号</text>
  97. <button
  98. open-type="getPhoneNumber"
  99. c-bind:getphonenumber="bindgetphonenumber"
  100. c-bind:onclick='testclick'
  101. >
  102. </button>
  103. <text class="button-text">打开APP</text>
  104. <button
  105. open-type="launchApp"
  106. app-parameter="wechat"
  107. c-bind:error="binderror"
  108. c-bind:onclick='testclick'
  109. >
  110. </button>
  111. <text class="button-text">打开授权设置页</text>
  112. <button
  113. open-type="openSetting"
  114. c-bind:opensetting="bindopensetting"
  115. c-bind:onclick='testclick'
  116. >
  117. </button>
  118. <text class="button-text">打开“意见反馈页面”</text>
  119. <button
  120. open-type="feedback"
  121. c-bind:onclick='testclick'
  122. >
  123. </button>
  124. </view>
  125. </scroller>
  126. </view>
  127. </template>
  128. <script>
  129. import cml from 'chameleon-api'
  130. class Button {
  131. data = {
  132. sessionFrom: '会话来源',
  133. messageTitle: '标题',
  134. messagePath: '路径',
  135. messageImg: '图片',
  136. contactPath: '',
  137. contactQuery: {},
  138. errMsg: '',
  139. iv: '',
  140. encryptedData: '',
  141. appErrMsg: ''
  142. }
  143. methods = {
  144. testclick(e) {
  145. let type = e.detail.type
  146. cml.showToast({
  147. message: type + ' button'
  148. })
  149. },
  150. bindcontact(e) {
  151. this.contactPath = e.path;
  152. this.contactQuery = e.query;
  153. },
  154. bindgetuserinfo(e) {
  155. console.log(e.detail);
  156. },
  157. bindgetphonenumber(e) {
  158. this.errMsg = e.detail.errMsg;
  159. this.iv = e.detail.iv;
  160. this.encryptedData = e.detail.encryptedData;
  161. },
  162. binderror(e) {
  163. this.appErrMsg = e.detail.errMsg;
  164. },
  165. bindopensetting(e) {
  166. console.log(e);
  167. }
  168. }
  169. }
  170. export default new Button();
  171. </script>
  172. <style scoped>
  173. .container {
  174. position: absolute;
  175. top:0;
  176. left: 0;
  177. right: 0;
  178. bottom: 0;
  179. padding-bottom: 60cpx;
  180. font-size: 32cpx;
  181. font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
  182. }
  183. .button-list {
  184. display: flex;
  185. flex-direction: column;
  186. align-items: center;
  187. }
  188. .section-title {
  189. margin-top: 60cpx;
  190. display: flex;
  191. flex-direction: row;
  192. justify-content: center;
  193. }
  194. .section-title-text {
  195. color: #fc9153;
  196. font-size: 40cpx;
  197. }
  198. .button-text {
  199. display: block;
  200. color: #999;
  201. margin-top: 40cpx;
  202. margin-left: 8cpx;
  203. margin-bottom: 16cpx;
  204. }
  205. </style>
  206. <script cml-type="json">
  207. {
  208. "base": {}
  209. }
  210. </script>