index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <uni-shadow-root class="weapp-lib-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" @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-if="showCancelButton || showConfirmButton" 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'] = 'weapp/lib/dialog/index'
  37. "use strict";
  38. Object.defineProperty(exports, "__esModule", { value: true });
  39. var component_1 = require("../common/component");
  40. var button_1 = require("../mixins/button");
  41. var color_1 = require("../common/color");
  42. var utils_1 = require("../common/utils");
  43. (0, component_1.VantComponent)({
  44. mixins: [button_1.button],
  45. props: {
  46. show: {
  47. type: Boolean,
  48. observer: function (show) {
  49. !show && this.stopLoading();
  50. },
  51. },
  52. title: String,
  53. message: String,
  54. theme: {
  55. type: String,
  56. value: 'default',
  57. },
  58. useSlot: Boolean,
  59. className: String,
  60. customStyle: String,
  61. asyncClose: Boolean,
  62. messageAlign: String,
  63. beforeClose: null,
  64. overlayStyle: String,
  65. useTitleSlot: Boolean,
  66. showCancelButton: Boolean,
  67. closeOnClickOverlay: Boolean,
  68. confirmButtonOpenType: String,
  69. width: null,
  70. zIndex: {
  71. type: Number,
  72. value: 2000,
  73. },
  74. confirmButtonText: {
  75. type: String,
  76. value: '确认',
  77. },
  78. cancelButtonText: {
  79. type: String,
  80. value: '取消',
  81. },
  82. confirmButtonColor: {
  83. type: String,
  84. value: color_1.RED,
  85. },
  86. cancelButtonColor: {
  87. type: String,
  88. value: color_1.GRAY,
  89. },
  90. showConfirmButton: {
  91. type: Boolean,
  92. value: true,
  93. },
  94. overlay: {
  95. type: Boolean,
  96. value: true,
  97. },
  98. transition: {
  99. type: String,
  100. value: 'scale',
  101. },
  102. },
  103. data: {
  104. loading: {
  105. confirm: false,
  106. cancel: false,
  107. },
  108. callback: (function () { }),
  109. },
  110. methods: {
  111. onConfirm: function () {
  112. this.handleAction('confirm');
  113. },
  114. onCancel: function () {
  115. this.handleAction('cancel');
  116. },
  117. onClickOverlay: function () {
  118. this.close('overlay');
  119. },
  120. close: function (action) {
  121. var _this = this;
  122. this.setData({ show: false });
  123. wx.nextTick(function () {
  124. _this.$emit('close', action);
  125. var callback = _this.data.callback;
  126. if (callback) {
  127. callback(action, _this);
  128. }
  129. });
  130. },
  131. stopLoading: function () {
  132. this.setData({
  133. loading: {
  134. confirm: false,
  135. cancel: false,
  136. },
  137. });
  138. },
  139. handleAction: function (action) {
  140. var _a;
  141. var _this = this;
  142. this.$emit(action, { dialog: this });
  143. var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose;
  144. if (!asyncClose && !beforeClose) {
  145. this.close(action);
  146. return;
  147. }
  148. this.setData((_a = {},
  149. _a["loading.".concat(action)] = true,
  150. _a));
  151. if (beforeClose) {
  152. (0, utils_1.toPromise)(beforeClose(action)).then(function (value) {
  153. if (value) {
  154. _this.close(action);
  155. }
  156. else {
  157. _this.stopLoading();
  158. }
  159. });
  160. }
  161. },
  162. },
  163. });
  164. export default global['__wxComponents']['weapp/lib/dialog/index']
  165. </script>
  166. <style platform="mp-weixin">
  167. @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)}
  168. </style>