index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 van-dialog--'+(theme)+' '+(className)" :custom-style="'width: '+(utils.addUnit(width))+';'+(customStyle)" :overlay-style="overlayStyle" :close-on-click-overlay="closeOnClickOverlay" @close="onClickOverlay">
  3. <view v-if="title || useTitleSlot" :class="utils.bem('dialog__header', { isolated: !(message || useSlot) })">
  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="utils.bem('dialog__message', [theme, messageAlign, { hasTitle: title }])">
  9. <text class="van-dialog__message-text">{{ message }}</text>
  10. </view>
  11. <van-goods-action v-if="theme === 'round-button'" custom-class="van-dialog__footer--round-button">
  12. <van-goods-action-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-goods-action-button>
  15. <van-goods-action-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-goods-action-button>
  18. </van-goods-action>
  19. <view v-else class="van-hairline--top van-dialog__footer">
  20. <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">
  21. {{ cancelButtonText }}
  22. </van-button>
  23. <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">
  24. {{ confirmButtonText }}
  25. </van-button>
  26. </view>
  27. </van-popup></uni-shadow-root>
  28. </template>
  29. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  30. <script>
  31. import VanPopup from '../popup/index.vue'
  32. import VanButton from '../button/index.vue'
  33. import VanGoodsAction from '../goods-action//index.vue'
  34. import VanGoodsActionButton from '../goods-action-button/index.vue'
  35. global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-button': VanButton,'van-goods-action': VanGoodsAction,'van-goods-action-button': VanGoodsActionButton}}
  36. global['__wxRoute'] = 'vant/dialog/index'
  37. import { VantComponent } from '../common/component';
  38. import { button } from '../mixins/button';
  39. import { openType } from '../mixins/open-type';
  40. import { GRAY, RED } from '../common/color';
  41. VantComponent({
  42. mixins: [button, openType],
  43. props: {
  44. show: {
  45. type: Boolean,
  46. observer(show) {
  47. !show && this.stopLoading();
  48. },
  49. },
  50. title: String,
  51. message: String,
  52. theme: {
  53. type: String,
  54. value: 'default',
  55. },
  56. useSlot: Boolean,
  57. className: String,
  58. customStyle: String,
  59. asyncClose: Boolean,
  60. messageAlign: String,
  61. overlayStyle: String,
  62. useTitleSlot: Boolean,
  63. showCancelButton: Boolean,
  64. closeOnClickOverlay: Boolean,
  65. confirmButtonOpenType: String,
  66. width: null,
  67. zIndex: {
  68. type: Number,
  69. value: 2000,
  70. },
  71. confirmButtonText: {
  72. type: String,
  73. value: '确认',
  74. },
  75. cancelButtonText: {
  76. type: String,
  77. value: '取消',
  78. },
  79. confirmButtonColor: {
  80. type: String,
  81. value: '#1989fa',
  82. },
  83. cancelButtonColor: {
  84. type: String,
  85. value: '#9fa6b5',
  86. },
  87. showConfirmButton: {
  88. type: Boolean,
  89. value: true,
  90. },
  91. overlay: {
  92. type: Boolean,
  93. value: true,
  94. },
  95. transition: {
  96. type: String,
  97. value: 'scale',
  98. },
  99. },
  100. data: {
  101. loading: {
  102. confirm: false,
  103. cancel: false,
  104. },
  105. },
  106. methods: {
  107. onConfirm() {
  108. this.handleAction('confirm');
  109. },
  110. onCancel() {
  111. this.handleAction('cancel');
  112. },
  113. onClickOverlay() {
  114. this.onClose('overlay');
  115. },
  116. handleAction(action) {
  117. if (this.data.asyncClose) {
  118. this.setData({
  119. [`loading.${action}`]: true,
  120. });
  121. }
  122. this.onClose(action);
  123. },
  124. close() {
  125. this.setData({
  126. show: false,
  127. });
  128. },
  129. stopLoading() {
  130. this.setData({
  131. loading: {
  132. confirm: false,
  133. cancel: false,
  134. },
  135. });
  136. },
  137. onClose(action) {
  138. if (!this.data.asyncClose) {
  139. this.close();
  140. }
  141. this.$emit('close', action);
  142. // 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
  143. this.$emit(action, { dialog: this });
  144. const callback = this.data[
  145. action === 'confirm' ? 'onConfirm' : 'onCancel'
  146. ];
  147. if (callback) {
  148. callback(this);
  149. }
  150. },
  151. },
  152. });
  153. export default global['__wxComponents']['vant/dialog/index']
  154. </script>
  155. <style platform="mp-weixin">
  156. @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--hasTitle{padding-top:8px;padding-top:var(--dialog-has-title-message-padding-top,8px);color:#646566;color:var(--dialog-has-title-message-text-color,#646566)}.van-dialog__message--round-button{padding-bottom:16px;color:#323233}.van-dialog__message--left{text-align:left}.van-dialog__message--right{text-align:right}.van-dialog__footer{display:-webkit-flex;display:flex}.van-dialog__footer--round-button{position:relative!important;padding:8px 24px 16px!important}.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}
  157. </style>