index.vue 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <uni-shadow-root class="vant-dist-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="onGetUserInfo" @contact="onContact" @getphonenumber="onGetPhoneNumber" @error="onError" @launchapp="onLaunchApp" @opensetting="onOpenSetting">
  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="onGetUserInfo" @contact="onContact" @getphonenumber="onGetPhoneNumber" @error="onError" @launchapp="onLaunchApp" @opensetting="onOpenSetting">
  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/dist/dialog/index'
  37. import { VantComponent } from '../common/component';
  38. import { button } from '../mixins/button';
  39. import { GRAY, RED } from '../common/color';
  40. import { toPromise } from '../common/utils';
  41. VantComponent({
  42. mixins: [button],
  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. beforeClose: null,
  62. overlayStyle: String,
  63. useTitleSlot: Boolean,
  64. showCancelButton: Boolean,
  65. closeOnClickOverlay: Boolean,
  66. confirmButtonOpenType: String,
  67. width: null,
  68. zIndex: {
  69. type: Number,
  70. value: 2000,
  71. },
  72. confirmButtonText: {
  73. type: String,
  74. value: '确认',
  75. },
  76. cancelButtonText: {
  77. type: String,
  78. value: '取消',
  79. },
  80. confirmButtonColor: {
  81. type: String,
  82. value: RED,
  83. },
  84. cancelButtonColor: {
  85. type: String,
  86. value: GRAY,
  87. },
  88. showConfirmButton: {
  89. type: Boolean,
  90. value: true,
  91. },
  92. overlay: {
  93. type: Boolean,
  94. value: true,
  95. },
  96. transition: {
  97. type: String,
  98. value: 'scale',
  99. },
  100. },
  101. data: {
  102. loading: {
  103. confirm: false,
  104. cancel: false,
  105. },
  106. callback: (() => { }),
  107. },
  108. methods: {
  109. onConfirm() {
  110. this.handleAction('confirm');
  111. },
  112. onCancel() {
  113. this.handleAction('cancel');
  114. },
  115. onClickOverlay() {
  116. this.close('overlay');
  117. },
  118. close(action) {
  119. this.setData({ show: false });
  120. wx.nextTick(() => {
  121. this.$emit('close', action);
  122. const { callback } = this.data;
  123. if (callback) {
  124. callback(action, this);
  125. }
  126. });
  127. },
  128. stopLoading() {
  129. this.setData({
  130. loading: {
  131. confirm: false,
  132. cancel: false,
  133. },
  134. });
  135. },
  136. handleAction(action) {
  137. this.$emit(action, { dialog: this });
  138. const { asyncClose, beforeClose } = this.data;
  139. if (!asyncClose && !beforeClose) {
  140. this.close(action);
  141. return;
  142. }
  143. this.setData({
  144. [`loading.${action}`]: true,
  145. });
  146. if (beforeClose) {
  147. toPromise(beforeClose(action)).then((value) => {
  148. if (value) {
  149. this.close(action);
  150. }
  151. else {
  152. this.stopLoading();
  153. }
  154. });
  155. }
  156. },
  157. },
  158. });
  159. export default global['__wxComponents']['vant/dist/dialog/index']
  160. </script>
  161. <style platform="mp-weixin">
  162. @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:flex}.van-dialog__footer--round-button{position:relative!important;padding:8px 24px 16px!important}.van-dialog__button{flex:1}.van-dialog__cancel,.van-dialog__confirm{border:0!important}.van-dialog-bounce-enter{transform:translate3d(-50%,-50%,0) scale(.7);opacity:0}.van-dialog-bounce-leave-active{transform:translate3d(-50%,-50%,0) scale(.9);opacity:0}
  163. </style>