ConfirmDialog.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view
  3. v-if="show"
  4. class="confirm-dialog"
  5. @touchmove.stop.prevent="noop"
  6. >
  7. <view class="confirm-dialog__mask" @click="onCancel" />
  8. <view class="confirm-dialog__panel">
  9. <view class="confirm-dialog__body">
  10. <view class="confirm-dialog__title">{{ title }}</view>
  11. <view class="confirm-dialog__content">
  12. <slot>{{ content }}</slot>
  13. </view>
  14. </view>
  15. <view class="confirm-dialog__actions">
  16. <view
  17. class="confirm-dialog__btn confirm-dialog__btn--cancel"
  18. @click="onCancel"
  19. >
  20. {{ cancelText }}
  21. </view>
  22. <!-- 微信 getPhoneNumber 必须由用户点击 button 触发,不可编程唤起 -->
  23. <button
  24. v-if="confirmOpenType"
  25. class="confirm-dialog__btn confirm-dialog__btn--confirm confirm-dialog__btn--native"
  26. hover-class="none"
  27. :open-type="confirmOpenType"
  28. @getphonenumber="onConfirmPhone"
  29. >
  30. {{ confirmText }}
  31. </button>
  32. <view
  33. v-else
  34. class="confirm-dialog__btn confirm-dialog__btn--confirm"
  35. @click="onConfirm"
  36. >
  37. {{ confirmText }}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. name: 'ConfirmDialog',
  46. props: {
  47. show: { type: Boolean, default: false },
  48. title: { type: String, default: '请先同意协议' },
  49. content: { type: String, default: '' },
  50. cancelText: { type: String, default: '取消' },
  51. confirmText: { type: String, default: '同意并登录' },
  52. /** 如 getPhoneNumber:确认键渲染为原生 button,同一次点击可拉起微信授权 */
  53. confirmOpenType: { type: String, default: '' }
  54. },
  55. methods: {
  56. noop() {},
  57. onCancel() {
  58. this.$emit('update:show', false)
  59. this.$emit('cancel')
  60. },
  61. onConfirm() {
  62. this.$emit('update:show', false)
  63. this.$emit('confirm')
  64. },
  65. onConfirmPhone(e) {
  66. this.$emit('update:show', false)
  67. this.$emit('confirm')
  68. this.$emit('getphonenumber', e)
  69. }
  70. }
  71. }
  72. </script>