index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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-class'" :custom-style="'width: '+(utils.addUnit(width))+';'+(customStyle)" :overlay-style="overlayStyle" :close-on-click-overlay="closeOnClickOverlay" :root-portal="rootPortal" @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 cancle-button-class" :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 confirm-button-class" :custom-style="'color: '+(confirmButtonColor)" :button-id="confirmButtonId" :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" @agreeprivacyauthorization="onAgreePrivacyAuthorization" @getRealTimePhoneNumber="onGetRealTimePhoneNumber" @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-if="showCancelButton || showConfirmButton" class="van-hairline--top van-dialog__footer">
  20. <block v-if="showCancelButton">
  21. <slot v-if="useCancelButtonSlot" name="cancel-button"></slot>
  22. <van-button v-else size="large" :loading="loading.cancel" class="van-dialog__button van-hairline--right" custom-class="van-dialog__cancel cancle-button-class" :custom-style="'color: '+(cancelButtonColor)" @click="onCancel">
  23. {{ cancelButtonText }}
  24. </van-button>
  25. </block>
  26. <block v-if="showConfirmButton">
  27. <slot v-if="useConfirmButtonSlot" name="confirm-button"></slot>
  28. <van-button v-else size="large" class="van-dialog__button" :loading="loading.confirm" custom-class="van-dialog__confirm confirm-button-class" :custom-style="'color: '+(confirmButtonColor)" :button-id="confirmButtonId" :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" @agreeprivacyauthorization="onAgreePrivacyAuthorization" @getRealTimePhoneNumber="onGetRealTimePhoneNumber" @click="onConfirm" @getuserinfo="onGetUserInfo" @contact="onContact" @getphonenumber="onGetPhoneNumber" @error="onError" @launchapp="onLaunchApp" @opensetting="onOpenSetting">
  29. {{ confirmButtonText }}
  30. </van-button>
  31. </block>
  32. </view>
  33. </van-popup></uni-shadow-root>
  34. </template>
  35. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  36. <script>
  37. import VanPopup from '../popup/index.vue'
  38. import VanButton from '../button/index.vue'
  39. import VanGoodsAction from '../goods-action/index.vue'
  40. import VanGoodsActionButton from '../goods-action-button/index.vue'
  41. global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-button': VanButton,'van-goods-action': VanGoodsAction,'van-goods-action-button': VanGoodsActionButton}}
  42. global['__wxRoute'] = 'vant/dialog/index'
  43. import { VantComponent } from '../common/component';
  44. import { button } from '../mixins/button';
  45. import { GRAY, RED } from '../common/color';
  46. import { toPromise } from '../common/utils';
  47. VantComponent({
  48. mixins: [button],
  49. classes: ['cancle-button-class', 'confirm-button-class'],
  50. props: {
  51. show: {
  52. type: Boolean,
  53. observer(show) {
  54. !show && this.stopLoading();
  55. },
  56. },
  57. title: String,
  58. message: String,
  59. theme: {
  60. type: String,
  61. value: 'default',
  62. },
  63. confirmButtonId: String,
  64. className: String,
  65. customStyle: String,
  66. asyncClose: Boolean,
  67. messageAlign: String,
  68. beforeClose: null,
  69. overlayStyle: String,
  70. useSlot: Boolean,
  71. useTitleSlot: Boolean,
  72. useConfirmButtonSlot: Boolean,
  73. useCancelButtonSlot: Boolean,
  74. showCancelButton: Boolean,
  75. closeOnClickOverlay: Boolean,
  76. confirmButtonOpenType: String,
  77. width: null,
  78. zIndex: {
  79. type: Number,
  80. value: 2000,
  81. },
  82. confirmButtonText: {
  83. type: String,
  84. value: '确认',
  85. },
  86. cancelButtonText: {
  87. type: String,
  88. value: '取消',
  89. },
  90. confirmButtonColor: {
  91. type: String,
  92. value: RED,
  93. },
  94. cancelButtonColor: {
  95. type: String,
  96. value: GRAY,
  97. },
  98. showConfirmButton: {
  99. type: Boolean,
  100. value: true,
  101. },
  102. overlay: {
  103. type: Boolean,
  104. value: true,
  105. },
  106. transition: {
  107. type: String,
  108. value: 'scale',
  109. },
  110. rootPortal: {
  111. type: Boolean,
  112. value: false,
  113. },
  114. },
  115. data: {
  116. loading: {
  117. confirm: false,
  118. cancel: false,
  119. },
  120. callback: (() => { }),
  121. },
  122. methods: {
  123. onConfirm() {
  124. this.handleAction('confirm');
  125. },
  126. onCancel() {
  127. this.handleAction('cancel');
  128. },
  129. onClickOverlay() {
  130. this.close('overlay');
  131. },
  132. close(action) {
  133. this.setData({ show: false });
  134. wx.nextTick(() => {
  135. this.$emit('close', action);
  136. const { callback } = this.data;
  137. if (callback) {
  138. callback(action, this);
  139. }
  140. });
  141. },
  142. stopLoading() {
  143. this.setData({
  144. loading: {
  145. confirm: false,
  146. cancel: false,
  147. },
  148. });
  149. },
  150. handleAction(action) {
  151. this.$emit(action, { dialog: this });
  152. const { asyncClose, beforeClose } = this.data;
  153. if (!asyncClose && !beforeClose) {
  154. this.close(action);
  155. return;
  156. }
  157. this.setData({
  158. [`loading.${action}`]: true,
  159. });
  160. if (beforeClose) {
  161. toPromise(beforeClose(action)).then((value) => {
  162. if (value) {
  163. this.close(action);
  164. }
  165. else {
  166. this.stopLoading();
  167. }
  168. });
  169. }
  170. },
  171. },
  172. });
  173. export default global['__wxComponents']['vant/dialog/index']
  174. </script>
  175. <style platform="mp-weixin">
  176. @import '../common/index.css';.van-dialog{background-color:var(--dialog-background-color,#fff);border-radius:var(--dialog-border-radius,16px);font-size:var(--dialog-font-size,16px);overflow:hidden;top:45%!important;width:var(--dialog-width,320px)}@media (max-width:321px){.van-dialog{width:var(--dialog-small-screen-width,90%)}}.van-dialog__header{font-weight:var(--dialog-header-font-weight,500);line-height:var(--dialog-header-line-height,24px);padding-top:var(--dialog-header-padding-top,24px);text-align:center}.van-dialog__header--isolated{padding:var(--dialog-header-isolated-padding,24px 0)}.van-dialog__message{-webkit-overflow-scrolling:touch;font-size:var(--dialog-message-font-size,14px);line-height:var(--dialog-message-line-height,20px);max-height:var(--dialog-message-max-height,60vh);overflow-y:auto;padding:var(--dialog-message-padding,24px);text-align:center}.van-dialog__message-text{word-wrap:break-word}.van-dialog__message--hasTitle{color:var(--dialog-has-title-message-text-color,#646566);padding-top:var(--dialog-has-title-message-padding-top,8px)}.van-dialog__message--round-button{color:#323233;padding-bottom:16px}.van-dialog__message--left{text-align:left}.van-dialog__message--right{text-align:right}.van-dialog__message--justify{text-align:justify}.van-dialog__footer{display:flex}.van-dialog__footer--round-button{padding:8px 24px 16px!important;position:relative!important}.van-dialog__button{flex:1}.van-dialog__cancel,.van-dialog__confirm{border:0!important}.van-dialog-bounce-enter{opacity:0;transform:translate3d(-50%,-50%,0) scale(.7)}.van-dialog-bounce-leave-active{opacity:0;transform:translate3d(-50%,-50%,0) scale(.9)}
  177. </style>