c-dialog


对话框

示例

  1. <template>
  2. <view class="dialog-page">
  3. <c-dialog show="{{show}}"
  4. type="{{type}}"
  5. c-bind:show="changeShow"
  6. title="{{title}}"
  7. mask="{{mask}}"
  8. content="{{content}}"
  9. show-close="{{showClose}}"
  10. icon-type="{{iconType}}"
  11. icon-style="{{iconStyle}}"
  12. c-bind:close="closeEvent"
  13. c-bind:confirm="confirmEvent"
  14. c-bind:cancel="cancelEvent"
  15. >
  16. </c-dialog>
  17. <button btn-style="{{btnStyle}}" text="alert dialog" c-bind:onclick="showAlert"></button>
  18. <button btn-style="{{btnStyle}}" text="confirm dialog" c-bind:onclick="showConfirm"></button>
  19. <button btn-style="{{btnStyle}}" text="show close dialog" c-bind:onclick="showCloseIcon"></button>
  20. </view>
  21. </template>
  22. <script>
  23. class C_dialog {
  24. data = {
  25. show: false,
  26. mask: true,
  27. showClose: false,
  28. headerTitle: "c-dialog",
  29. headerDesc: "c-dialog",
  30. message: "",
  31. type: "alert",
  32. btnStyle: "margin-bottom: 20cpx",
  33. iconType: "warn",
  34. iconStyle: {
  35. width: "60cpx",
  36. height: "60cpx"
  37. },
  38. title: "我是标题",
  39. content: "我是内容"
  40. }
  41. methods = {
  42. changeShow(e) {
  43. this.show = e.detail.value;
  44. },
  45. showAlert() {
  46. this.type = "alert";
  47. this.title = "我是标题";
  48. this.content = "我是内容";
  49. this.iconType = "warn";
  50. this.showClose = false;
  51. this.show = true;
  52. },
  53. showConfirm() {
  54. this.type = "confirm";
  55. this.title = "确定离开吗";
  56. this.content = "";
  57. this.iconType = "network";
  58. this.showClose = false;
  59. this.show = true;
  60. },
  61. showCloseIcon() {
  62. this.type = "alert";
  63. this.title = "我是标题";
  64. this.content = "我是内容";
  65. this.iconType = "warn";
  66. this.showClose = true;
  67. this.show = true;
  68. },
  69. closeEvent() {},
  70. confirmEvent() {},
  71. cancelEvent() {}
  72. }
  73. };
  74. export default new C_dialog();
  75. </script>
  76. <style scoped>
  77. .dialog-page {
  78. display: flex;
  79. flex-direction: column;
  80. align-items: center;
  81. }
  82. </style>
  83. <script cml-type="json">
  84. {
  85. "base": {
  86. "usingComponents": {
  87. "c-dialog": "cml-ui/components/c-dialog/c-dialog"
  88. }
  89. }
  90. }
  91. </script>