cl-dialog.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="cl-dialog__wrapper">
  3. <cl-popup
  4. direction="center"
  5. :visible.sync="visible2"
  6. :before-close="beforeClose"
  7. :close-on-click-modal="closeOnClickModal"
  8. :size="width"
  9. :border-radius="16"
  10. :padding="0"
  11. >
  12. <view class="cl-dialog">
  13. <view class="cl-dialog__header" v-if="title">
  14. <text class="cl-dialog__title">{{ title }}</text>
  15. </view>
  16. <view class="cl-dialog__container">
  17. <view class="cl-dialog__message">
  18. <slot></slot>
  19. </view>
  20. </view>
  21. <view class="cl-dialog__footer" v-if="$slots.footer">
  22. <slot name="footer"> </slot>
  23. </view>
  24. <view class="cl-dialog__close" v-if="showCloseBtn" @tap="close">
  25. <text class="cl-icon-close"></text>
  26. </view>
  27. </view>
  28. </cl-popup>
  29. </view>
  30. </template>
  31. <script>
  32. /**
  33. * dialog 对话框
  34. * @description 对话框
  35. * @tutorial https://docs.cool-js.com/uni/components/operate/dialog.html
  36. * @property {Boolean} visible 是否可见
  37. * @property {String} title 标题
  38. * @property {String} width 宽度,默认80%
  39. * @property {Boolean} closeOnClickModal 点击遮罩层是否关闭,默认true
  40. * @property {Function} beforeClose 关闭回调
  41. * @property {Boolean} showCloseBtn 显示关闭按钮
  42. * @example <cl-dialog :visible.sync="visible">Hello !</cl-dialog>
  43. */
  44. export default {
  45. name: "cl-dialog",
  46. props: {
  47. // 是否可见
  48. visible: Boolean,
  49. // 标题
  50. title: String,
  51. // 宽度
  52. width: {
  53. type: String,
  54. default: "80%"
  55. },
  56. // 点击遮罩层是否关闭
  57. closeOnClickModal: {
  58. type: Boolean,
  59. default: true
  60. },
  61. // 关闭回调
  62. beforeClose: Function,
  63. // 显示关闭按钮
  64. showCloseBtn: Boolean
  65. },
  66. data() {
  67. return {
  68. visible2: this.visible
  69. };
  70. },
  71. watch: {
  72. visible: {
  73. handler(val) {
  74. this.visible2 = val;
  75. if (val) {
  76. this.$emit("open");
  77. } else {
  78. this.$emit("close", "close");
  79. }
  80. }
  81. },
  82. visible2(val) {
  83. this.$emit("update:visible", val);
  84. }
  85. },
  86. methods: {
  87. close() {
  88. this.visible2 = false;
  89. }
  90. }
  91. };
  92. </script>