Dialog对话框

    引入

    在app.json或index.json中引入组件,默认为ES6版本

    1. "usingComponents": {
    2. "vtu-dialog": "/miniprogram_npm/vtuweapp/dialog/vtu-dialog"
    3. }

    代码演示

    普通对话框

    1. <vtu-btn bind:click="alert1" type="primary" custom-class="dialog-btn">普通对话框</vtu-btn>
    2. <vtu-btn bind:click="alert2" type="primary" custom-class="dialog-btn">普通对话框(无取消按钮)</vtu-btn>
    3. <vtu-btn bind:click="alert3" type="danger" custom-class="dialog-btn">确认对话框(开放能力)</vtu-btn>
    4. <vtu-btn bind:click="alert4" type="success" custom-class="dialog-btn">自定义按钮排列</vtu-btn>
    5. <vtu-btn bind:click="alert5" type="warning" custom-class="dialog-btn">点击遮罩关闭</vtu-btn>
    6. <vtu-btn bind:click="alert6" type="success" custom-class="dialog-btn">横向排列</vtu-btn>
    7. <vtu-dialog id="Vtu-Dialog"></vtu-dialog>
    8. import Dialog from "../../../miniprogram_npm/vtuweapp/dialog/vtu-index";
    9. Page({
    10. data: {},
    11. alert1: function() {
    12. Dialog().alert({
    13. title: '普通提示',
    14. content: '显示您要确定的内容信息'
    15. })
    16. },
    17. alert2: function() {
    18. Dialog().alert({
    19. title: '普通提示',
    20. content: '显示您要确定的内容信息',
    21. showCancel: false
    22. })
    23. },
    24. alert3: function() {
    25. Dialog().confirm({
    26. title: '确认对话框',
    27. content: '系统需要您的授权,请登录',
    28. confirmLabel: '登录',
    29. confirmOpenType: 'getUserInfo',
    30. cancelLabel: '不需要',
    31. success: function(e) {
    32. wx.showToast({
    33. title: "已确认",
    34. icon: 'none',
    35. duration: 2000
    36. });
    37. },
    38. fail: function() {
    39. wx.showToast({
    40. title: "已取消",
    41. icon: 'none',
    42. duration: 2000
    43. });
    44. }
    45. })
    46. },
    47. alert4: function() {
    48. Dialog().open({
    49. title: '自定义对话框',
    50. content: '请选择付款方式',
    51. buttons: [
    52. {
    53. type: 'primary',
    54. label: '微信支付(异步)',
    55. async: true,
    56. click: function(e) {
    57. setTimeout(function() {
    58. Dialog().close()
    59. }, 2000)
    60. }
    61. },
    62. {
    63. type: 'danger',
    64. label: '支付宝支付',
    65. click: function(e) {
    66. }
    67. },
    68. {
    69. type: 'default',
    70. label: '取消',
    71. click: function(e) {
    72. Dialog().close()
    73. }
    74. }
    75. ]
    76. })
    77. },
    78. alert5: function() {
    79. Dialog().confirm({
    80. title: '确认对话框',
    81. content: '系统需要您的授权,请登录',
    82. confirmLabel: '登录',
    83. confirmAsync: true,
    84. confirmOpenType: 'getUserInfo',
    85. cancelLabel: '不需要',
    86. closeOnClickOverlay: true,
    87. success: function(e) {
    88. setTimeout(function() {
    89. Dialog().close()
    90. }, 2000)
    91. },
    92. fail: function() {
    93. wx.showToast({
    94. title: "已取消",
    95. icon: 'none',
    96. duration: 2000
    97. });
    98. }
    99. })
    100. },
    101. alert6: function() {
    102. Dialog().open({
    103. title: '自定义对话框',
    104. content: '请选择付款方式',
    105. verticalButtons: false,
    106. buttons: [
    107. {
    108. type: 'primary',
    109. label: '微信支付',
    110. icon: "iconfont icon-share",
    111. click: function(e) {
    112. setTimeout(function() {
    113. Dialog().close()
    114. }, 2000)
    115. }
    116. },
    117. {
    118. type: 'danger',
    119. label: '支付宝支付',
    120. click: function(e) {
    121. }
    122. },
    123. {
    124. type: 'default',
    125. label: '取消',
    126. click: function(e) {
    127. Dialog().close()
    128. }
    129. }
    130. ]
    131. })
    132. },
    133. closeCustomDialog: function() {
    134. Dialog("Vtu-Custom-Dialog").close()
    135. }
    136. });
    137.  

    自定义对话框

    1. <vtu-btn bind:click="alert7" type="primary" custom-class="dialog-btn">自定义对话框</vtu-btn>
    2. <vtu-dialog id="Vtu-Custom-Dialog" show="{{show}}" title="自定义对话框内容" user-content-slot>
    3. <view class="Vtu-Custom-Center">
    4. <vtu-radio-group model="1" align="right">
    5. <vtu-radio value="1" label="北京" icon="iconfont icon-biaoxing" ></vtu-radio>
    6. <vtu-radio value="2" label="上海" icon="iconfont icon-xihuan" ></vtu-radio>
    7. <vtu-radio value="3" label="深圳" icon="iconfont icon-sousuo"></vtu-radio>
    8. <vtu-radio value="4" label="南京" icon="iconfont icon-shangchuan"></vtu-radio>
    9. </vtu-radio-group>
    10. </view>
    11. <view class="Vtu-Custom-Btn">
    12. <vtu-btn type="primary" inlineBlock custom-class="dialog-custom-btn">确定</vtu-btn>
    13. <vtu-btn bind:click="closeCustomDialog" inlineBlock custom-class="dialog-custom-btn">取消</vtu-btn>
    14. </view>
    15. </vtu-dialog>
    16. import Dialog from "../../../miniprogram_npm/vtuweapp/dialog/vtu-index";
    17. Page({
    18. data: {
    19. show: false
    20. },
    21. alert7: function() {
    22. this.setData({
    23. show: true
    24. })
    25. },
    26. closeCustomDialog: function() {
    27. Dialog("Vtu-Custom-Dialog").close()
    28. }
    29. });
    30.  

    组件参数

    Dialog 对话框 - 图1