dialog.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view style="width:680rpx">
  3. <view class="modal-box " :class="isVisibility?'show':''" @touchmove.stop.prevent="moveHandleStop">
  4. <view class="dialog">
  5. <view class="simple-bar justify-end has-borderb" v-if="title != '' ">
  6. <view class='content'>{{title}}</view>
  7. </view>
  8. <view :class="contentClass" v-bind:style="'text-align:'+messageAlign">{{message}}</view>
  9. <view class="simple-bar has-bordert">
  10. <view class='action has-mg-0 flex-sub text-green' v-if="showCancelButton == true" @tap='handleClose'>{{cancelButtonText}}</view>
  11. <view class='action has-mg-0 flex-sub has-borderl' v-if="showConfirmButton == true" @tap='handleConfirm'>{{confirmButtonText}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. /**
  19. * 弹窗插件
  20. * 使用方法:
  21. * 1.引入组件:import simpleDialog from '@/components/simple-pro/dialog.vue';
  22. * 2.定义:components ,simpleDialog
  23. * 3.页面使用:<simpleDialog ref="simpleDialog2"></simpleDialog>
  24. * 4.指定方法 this.$refs.simpleDialog2.func();
  25. *
  26. * 自定义方法:
  27. * 1. alert() ; 支持在方法中传入 object 更改内容 该方法仅弹出一个按钮 (如果传入了object参数 其中的参数值优先级最高)
  28. * 2. confirm(); 同理 可传入object参数 该方法支持确定、取消 按钮 (如果传入了object参数 其中的参数值优先级最高)
  29. */
  30. export default {
  31. props: {
  32. title: {
  33. type: String,
  34. default: ''
  35. },
  36. message: {
  37. type: String,
  38. default: '你怎么会看到我^_^'
  39. },
  40. contentClass:{
  41. type :String,
  42. default:'has-pd-50 has-bg-white',
  43. },
  44. // 内容对齐方式 center | left | right
  45. messageAlign: {
  46. type: String,
  47. default: 'center'
  48. },
  49. // 是否显示确认按钮
  50. showConfirmButton: {
  51. type: Boolean,
  52. default: true
  53. },
  54. // 是否显示取消按钮
  55. showCancelButton: {
  56. type: Boolean,
  57. default: false
  58. },
  59. // 确定按钮的文案
  60. confirmButtonText: {
  61. type: String,
  62. default: '确定'
  63. },
  64. // 取消按钮的文案
  65. cancelButtonText: {
  66. type: String,
  67. default: '取消'
  68. }
  69. },
  70. data() {
  71. return {
  72. isVisibility: false
  73. };
  74. },
  75. methods: {
  76. __show() {
  77. this.isVisibility = true;
  78. },
  79. __close() {
  80. this.isVisibility = false;
  81. },
  82. __setconfig(options){
  83. if(options != undefined && (typeof options == "object") ){
  84. if (options['title']!=undefined) this.title = options['title']
  85. if (options['message']!=undefined) this.message = options['message']
  86. if (options['contentClass']!=undefined) this.contentClass = options['contentClass']
  87. if (options['messageAlign']!=undefined) this.messageAlign = options['messageAlign']
  88. if (options['showConfirmButton']!=undefined) this.showConfirmButton = options['showConfirmButton']
  89. if (options['showCancelButton']!=undefined) this.showCancelButton = options['showCancelButton']
  90. if (options['confirmButtonText']!=undefined) this.confirmButtonText = options['confirmButtonText']
  91. if (options['cancelButtonText']!=undefined) this.cancelButtonText = options['cancelButtonText']
  92. }
  93. },
  94. alert(options) {
  95. // <simpleDialog ref="simpleDialog"></simpleDialog>
  96. // this.$refs.simpleDialog.alert();
  97. this.__setconfig(options);
  98. this.__show();
  99. },
  100. confirm(options) {
  101. this.showCancelButton = true;
  102. this.__setconfig(options);
  103. this.__show();
  104. },
  105. handleClose() {
  106. this.__close();
  107. this.$emit('cancelButton');
  108. },
  109. handleConfirm() {
  110. this.__close();
  111. this.$emit('confirmButton');
  112. },
  113. moveHandleStop:function(){
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. </style>