index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 v-if="!isMutipleLine" class="prompt-input" :style="inputStyle" type="text" :placeholder="placeholder" v-model="value">
  7. <textarea v-else class="prompt-input" :style="inputStyle" type="text" :placeholder="placeholder" v-model="value"></textarea>
  8. </view>
  9. <slot></slot>
  10. <view class="prompt-buttons">
  11. <button class="prompt-cancle" :style="'color:' + mainColor" @click="close">取消</button>
  12. <button class="prompt-confirm" :style="'background:' + mainColor" @click="confirm">确定</button>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. visible: {
  21. type: Boolean,
  22. default: false,
  23. required: true,
  24. },
  25. title: {
  26. type: String,
  27. default: '提示',
  28. },
  29. placeholder: {
  30. type: String,
  31. default: '请输入内容',
  32. },
  33. mainColor: {
  34. type: String,
  35. default: '#e74a39',
  36. },
  37. defaultValue: {
  38. type: String,
  39. default: '',
  40. },
  41. inputStyle: {
  42. type: String,
  43. default: '',
  44. },
  45. // 是否多行输入的textarea
  46. isMutipleLine: {
  47. type: Boolean,
  48. default: false,
  49. }
  50. },
  51. data() {
  52. return {
  53. value: '',
  54. }
  55. },
  56. watch: {
  57. visible(val) {
  58. if(val) {
  59. this.value = this.defaultValue
  60. }
  61. }
  62. },
  63. mounted() {
  64. this.value = this.defaultValue === 'true' ? '' : this.defaultValue
  65. },
  66. methods: {
  67. close() {
  68. this.$emit('update:visible', false)
  69. },
  70. confirm() {
  71. this.$emit('confirm', this.value)
  72. this.value = ''
  73. },
  74. }
  75. }
  76. </script>
  77. <style scoped>
  78. view,
  79. button,
  80. input {
  81. box-sizing: border-box;
  82. }
  83. .prompt-box {
  84. position: fixed;
  85. left: 0;
  86. top: 0;
  87. display: flex;
  88. justify-content: center;
  89. align-items: center;
  90. width: 100%;
  91. height: 100vh;
  92. background: rgba(0, 0, 0, .2);
  93. transition: opacity .2s linear;
  94. }
  95. .prompt {
  96. position: relative;
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: space-between;
  100. align-items: center;
  101. width: 600upx;
  102. min-height: 300upx;
  103. background: white;
  104. border-radius: 20upx;
  105. overflow: hidden;
  106. }
  107. .prompt-top {
  108. display: flex;
  109. flex-direction: column;
  110. align-items: center;
  111. width: 100%;
  112. }
  113. .prompt-title {
  114. margin: 20upx 0;
  115. color: #333;
  116. }
  117. .prompt-input {
  118. width: 520upx;
  119. min-height: 72upx;
  120. padding: 8upx 16upx;
  121. border: 2upx solid #ddd;
  122. border-radius: 8upx;
  123. font-size: 28upx;
  124. text-align: left;
  125. }
  126. .prompt-buttons {
  127. display: flex;
  128. width: 100%;
  129. box-shadow: 0 0 2upx 2upx #eee;
  130. }
  131. .prompt-buttons button:after {
  132. border-radius: 0;
  133. }
  134. button {
  135. width: 50%;
  136. background: white;
  137. border-radius: 0;
  138. }
  139. .prompt-cancle {
  140. background: white;
  141. }
  142. .prompt-confirm {
  143. color: white;
  144. }
  145. </style>