index.vue 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <uni-shadow-root class="vant-dialog-index"><van-popup :show="show" :z-index="zIndex" :overlay="overlay" :custom-class="'van-dialog '+(className)" :transition="transition" :custom-style="customStyle" :close-on-click-overlay="closeOnClickOverlay" @close="onClickOverlay">
  3. <view v-if="title" :class="'van-dialog__header '+(message || useSlot ? '' : 'van-dialog--isolated')">
  4. {{ title }}
  5. </view>
  6. <slot v-if="useSlot"></slot>
  7. <view v-else-if="message" :class="'van-dialog__message '+(title ? 'van-dialog__message--has-title' : '')+' '+(messageAlign ? 'van-dialog__message--' + messageAlign : '')">
  8. <text>{{ message }}</text>
  9. </view>
  10. <view class="van-hairline--top van-dialog__footer">
  11. <van-button v-if="showCancelButton" size="large" :loading="loading.cancel" class="van-dialog__button van-hairline--right" custom-class="van-dialog__cancel" @click="onCancel">
  12. {{ cancelButtonText }}
  13. </van-button>
  14. <van-button v-if="showConfirmButton" size="large" class="van-dialog__button" :loading="loading.confirm" custom-class="van-dialog__confirm" :open-type="confirmButtonOpenType" :lang="lang" :business-id="businessId" :session-from="sessionFrom" :send-message-title="sendMessageTitle" :send-message-path="sendMessagePath" :send-message-img="sendMessageImg" :show-message-card="showMessageCard" :app-parameter="appParameter" @click="onConfirm" @getuserinfo="bindGetUserInfo" @contact="bindContact" @getphonenumber="bindGetPhoneNumber" @error="bindError" @launchapp="bindLaunchApp" @opensetting="bindOpenSetting">
  15. {{ confirmButtonText }}
  16. </van-button>
  17. </view>
  18. </van-popup></uni-shadow-root>
  19. </template>
  20. <script>
  21. import VanPopup from '../popup/index.vue'
  22. import VanButton from '../button/index.vue'
  23. global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-button': VanButton}}
  24. global['__wxRoute'] = 'vant/dialog/index'
  25. import { VantComponent } from '../common/component';
  26. import { button } from '../mixins/button';
  27. import { openType } from '../mixins/open-type';
  28. VantComponent({
  29. mixins: [button, openType],
  30. props: {
  31. show: Boolean,
  32. title: String,
  33. message: String,
  34. useSlot: Boolean,
  35. className: String,
  36. customStyle: String,
  37. asyncClose: Boolean,
  38. messageAlign: String,
  39. showCancelButton: Boolean,
  40. closeOnClickOverlay: Boolean,
  41. confirmButtonOpenType: String,
  42. zIndex: {
  43. type: Number,
  44. value: 2000
  45. },
  46. confirmButtonText: {
  47. type: String,
  48. value: '确认'
  49. },
  50. cancelButtonText: {
  51. type: String,
  52. value: '取消'
  53. },
  54. showConfirmButton: {
  55. type: Boolean,
  56. value: true
  57. },
  58. overlay: {
  59. type: Boolean,
  60. value: true
  61. },
  62. transition: {
  63. type: String,
  64. value: 'scale'
  65. }
  66. },
  67. data: {
  68. loading: {
  69. confirm: false,
  70. cancel: false
  71. }
  72. },
  73. watch: {
  74. show(show) {
  75. !show && this.stopLoading();
  76. }
  77. },
  78. methods: {
  79. onConfirm() {
  80. this.handleAction('confirm');
  81. },
  82. onCancel() {
  83. this.handleAction('cancel');
  84. },
  85. onClickOverlay() {
  86. this.onClose('overlay');
  87. },
  88. handleAction(action) {
  89. if (this.data.asyncClose) {
  90. this.set({
  91. [`loading.${action}`]: true
  92. });
  93. }
  94. this.onClose(action);
  95. },
  96. close() {
  97. this.set({
  98. show: false
  99. });
  100. },
  101. stopLoading() {
  102. this.set({
  103. loading: {
  104. confirm: false,
  105. cancel: false
  106. }
  107. });
  108. },
  109. onClose(action) {
  110. if (!this.data.asyncClose) {
  111. this.close();
  112. }
  113. this.$emit('close', action);
  114. // 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
  115. this.$emit(action, { dialog: this });
  116. const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
  117. if (callback) {
  118. callback(this);
  119. }
  120. }
  121. }
  122. });
  123. export default global['__wxComponents']['vant/dialog/index']
  124. </script>
  125. <style platform="mp-weixin">
  126. @import '../common/index.css';.van-dialog{top:45%!important;width:85%;overflow:hidden;font-size:16px;background-color:#fff;border-radius:4px}.van-dialog__header{padding-top:25px;font-weight:500;line-height:24px;text-align:center}.van-dialog__header--isolated{padding:25px 0}.van-dialog__message{max-height:60vh;padding:25px;overflow-y:auto;font-size:14px;line-height:20px;text-align:center;-webkit-overflow-scrolling:touch}.van-dialog__message--has-title{padding-top:12px;color:#7d7e80}.van-dialog__message--left{text-align:left}.van-dialog__message--right{text-align:right}.van-dialog__footer{display:-webkit-flex;display:flex}.van-dialog__button{-webkit-flex:1;flex:1}.van-dialog__cancel,.van-dialog__confirm{border:0!important}.van-dialog__confirm{color:#1989fa!important}.van-dialog-bounce-enter{opacity:0;-webkit-transform:translate3d(-50%,-50%,0) scale(.7);transform:translate3d(-50%,-50%,0) scale(.7)}.van-dialog-bounce-leave-active{opacity:0;-webkit-transform:translate3d(-50%,-50%,0) scale(.9);transform:translate3d(-50%,-50%,0) scale(.9)}
  127. </style>