zz-prompt.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="prompt-box" v-if="visible" @touchmove="true">
  3. <view class="prompt">
  4. <view class="prompt-top">
  5. <text class="prompt-title">{{title}}</text>
  6. <input class="prompt-input" type="text" :placeholder="placeholder" v-model="value">
  7. </view>
  8. <slot></slot>
  9. <view class="prompt-buttons" :style="'background:' + mainColor">
  10. <button class="prompt-cancle" :style="'color:' + mainColor" @click="close">取消</button>
  11. <button @click="$emit('confirm', value)">确定</button>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. visible: {
  20. type: Boolean,
  21. default: false,
  22. required: true,
  23. },
  24. title: {
  25. type: String,
  26. default: '提示',
  27. },
  28. placeholder: {
  29. type: String,
  30. default: '请输入内容',
  31. },
  32. mainColor: {
  33. type: String,
  34. default: '#e74a39',
  35. },
  36. defaultValue: {
  37. type: String,
  38. }
  39. },
  40. data() {
  41. return {
  42. value: '',
  43. }
  44. },
  45. mounted() {
  46. this.value = this.defaultValue
  47. },
  48. methods: {
  49. close() {
  50. this.$emit('update:visible', false)
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. view, button, input {
  57. box-sizing: border-box;
  58. }
  59. .prompt-box {
  60. position: fixed;
  61. left: 0;
  62. top: 0;
  63. display: flex;
  64. justify-content: center;
  65. align-items: center;
  66. width: 100%;
  67. height: 100vh;
  68. background: rgba(0, 0, 0, .2);
  69. transition: opacity .2s linear;
  70. }
  71. .prompt {
  72. position: relative;
  73. display: flex;
  74. flex-direction: column;
  75. justify-content: space-between;
  76. align-items: center;
  77. width: 600upx;
  78. min-height: 300upx;
  79. background: white;
  80. border-radius: 20upx;
  81. overflow: hidden;
  82. }
  83. .prompt-top {
  84. display: flex;
  85. flex-direction: column;
  86. align-items: center;
  87. width: 100%;
  88. }
  89. .prompt-title {
  90. margin: 20upx 0;
  91. color: #333;
  92. }
  93. .prompt-input {
  94. width: 520upx;
  95. height: 80upx;
  96. font-size: 28upx;
  97. border-radius: 8upx;
  98. border: 1px solid #ccc;
  99. padding: 5upx 10upx;
  100. }
  101. .prompt-buttons {
  102. display: flex;
  103. width: 100%;
  104. box-shadow: 0 0 2upx 2upx #eee;
  105. }
  106. button {
  107. width: 50%;
  108. border-radius: 0;
  109. }
  110. .prompt-cancle {
  111. background: white;
  112. }
  113. </style>