index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <uni-shadow-root class="vant-dialog-index"><van-popup :show="show" :z-index="zIndex" :overlay="overlay" :transition="transition" :custom-class="'van-dialog '+(className)" :custom-style="(widthWithUnit ? 'width: ' + widthWithUnit + ';' : '')+(customStyle)" :overlay-style="overlayStyle" :close-on-click-overlay="closeOnClickOverlay" @close="onClickOverlay">
  3. <view v-if="title || useTitleSlot" :class="'van-dialog__header '+(message || useSlot ? '' : 'van-dialog--isolated')">
  4. <slot v-if="useTitleSlot" name="title"></slot>
  5. <block v-else-if="title"> {{ title }}</block>
  6. </view>
  7. <slot v-if="useSlot"></slot>
  8. <view v-else-if="message" :class="'van-dialog__message '+(title ? 'van-dialog__message--has-title' : '')+' '+(messageAlign ? 'van-dialog__message--' + messageAlign : '')">
  9. <text class="van-dialog__message-text">{{ message }}</text>
  10. </view>
  11. <view class="van-hairline--top van-dialog__footer">
  12. <van-button v-if="showCancelButton" size="large" :loading="loading.cancel" class="van-dialog__button van-hairline--right" custom-class="van-dialog__cancel" :custom-style="'color: '+(cancelButtonColor)" @click="onCancel">
  13. {{ cancelButtonText }}
  14. </van-button>
  15. <van-button v-if="showConfirmButton" size="large" class="van-dialog__button" :loading="loading.confirm" custom-class="van-dialog__confirm" :custom-style="'color: '+(confirmButtonColor)" :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">
  16. {{ confirmButtonText }}
  17. </van-button>
  18. </view>
  19. </van-popup></uni-shadow-root>
  20. </template>
  21. <script>
  22. import VanPopup from '../popup/index.vue'
  23. import VanButton from '../button/index.vue'
  24. global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-button': VanButton}}
  25. global['__wxRoute'] = 'vant/dialog/index'
  26. import { VantComponent } from '../common/component';
  27. import { button } from '../mixins/button';
  28. import { openType } from '../mixins/open-type';
  29. import { addUnit } from '../common/utils';
  30. import { GRAY, BLUE } from '../common/color';
  31. VantComponent({
  32. mixins: [button, openType],
  33. props: {
  34. show: Boolean,
  35. title: String,
  36. message: String,
  37. useSlot: Boolean,
  38. className: String,
  39. customStyle: String,
  40. asyncClose: Boolean,
  41. messageAlign: String,
  42. overlayStyle: String,
  43. useTitleSlot: Boolean,
  44. showCancelButton: Boolean,
  45. closeOnClickOverlay: Boolean,
  46. confirmButtonOpenType: String,
  47. width: {
  48. type: null,
  49. observer: 'setWidthWithUnit'
  50. },
  51. zIndex: {
  52. type: Number,
  53. value: 2000
  54. },
  55. confirmButtonText: {
  56. type: String,
  57. value: '确认'
  58. },
  59. cancelButtonText: {
  60. type: String,
  61. value: '取消'
  62. },
  63. confirmButtonColor: {
  64. type: String,
  65. value: BLUE
  66. },
  67. cancelButtonColor: {
  68. type: String,
  69. value: GRAY
  70. },
  71. showConfirmButton: {
  72. type: Boolean,
  73. value: true
  74. },
  75. overlay: {
  76. type: Boolean,
  77. value: true
  78. },
  79. transition: {
  80. type: String,
  81. value: 'scale'
  82. }
  83. },
  84. data: {
  85. loading: {
  86. confirm: false,
  87. cancel: false
  88. }
  89. },
  90. watch: {
  91. show(show) {
  92. !show && this.stopLoading();
  93. }
  94. },
  95. methods: {
  96. onConfirm() {
  97. this.handleAction('confirm');
  98. },
  99. onCancel() {
  100. this.handleAction('cancel');
  101. },
  102. onClickOverlay() {
  103. this.onClose('overlay');
  104. },
  105. handleAction(action) {
  106. if (this.data.asyncClose) {
  107. this.setData({
  108. [`loading.${action}`]: true
  109. });
  110. }
  111. this.onClose(action);
  112. },
  113. close() {
  114. this.setData({
  115. show: false
  116. });
  117. },
  118. stopLoading() {
  119. this.setData({
  120. loading: {
  121. confirm: false,
  122. cancel: false
  123. }
  124. });
  125. },
  126. onClose(action) {
  127. if (!this.data.asyncClose) {
  128. this.close();
  129. }
  130. this.$emit('close', action);
  131. // 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
  132. this.$emit(action, { dialog: this });
  133. const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
  134. if (callback) {
  135. callback(this);
  136. }
  137. },
  138. setWidthWithUnit(val) {
  139. this.setData({
  140. widthWithUnit: addUnit(val)
  141. });
  142. }
  143. }
  144. });
  145. export default global['__wxComponents']['vant/dialog/index']
  146. </script>
  147. <style platform="mp-weixin">
  148. @import '../common/index.css';.van-dialog{top:45%!important;overflow:hidden;width:320px;width:var(--dialog-width,320px);font-size:16px;font-size:var(--dialog-font-size,16px);border-radius:16px;border-radius:var(--dialog-border-radius,16px);background-color:#fff;background-color:var(--dialog-background-color,#fff)}@media (max-width:321px){.van-dialog{width:90%;width:var(--dialog-small-screen-width,90%)}}.van-dialog__header{text-align:center;padding-top:24px;padding-top:var(--dialog-header-padding-top,24px);font-weight:500;font-weight:var(--dialog-header-font-weight,500);line-height:24px;line-height:var(--dialog-header-line-height,24px)}.van-dialog__header--isolated{padding:24px 0;padding:var(--dialog-header-isolated-padding,24px 0)}.van-dialog__message{overflow-y:auto;text-align:center;-webkit-overflow-scrolling:touch;font-size:14px;font-size:var(--dialog-message-font-size,14px);line-height:20px;line-height:var(--dialog-message-line-height,20px);max-height:60vh;max-height:var(--dialog-message-max-height,60vh);padding:24px;padding:var(--dialog-message-padding,24px)}.van-dialog__message-text{word-wrap:break-word}.van-dialog__message--has-title{padding-top:12px;padding-top:var(--dialog-has-title-message-padding-top,12px);color:#646566;color:var(--dialog-has-title-message-text-color,#646566)}.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-bounce-enter{-webkit-transform:translate3d(-50%,-50%,0) scale(.7);transform:translate3d(-50%,-50%,0) scale(.7);opacity:0}.van-dialog-bounce-leave-active{-webkit-transform:translate3d(-50%,-50%,0) scale(.9);transform:translate3d(-50%,-50%,0) scale(.9);opacity:0}
  149. </style>