prompt.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view>
  3. <view class="popupClick" @click="onPopupShow()"><slot></slot></view>
  4. <view class="popupMask" v-if="popupShow" @click="onPopupHide"></view>
  5. <view class="popupContentBox" v-if="popupShow">
  6. <view class="close" @click="onPopupHide">×</view>
  7. <view class="title">{{ popupConfig.title }}</view>
  8. <view class="popupContent">
  9. <view class="introduce">{{ popupConfig.tips }}</view>
  10. <input
  11. class="input"
  12. :type="popupConfig.inputType"
  13. adjust-position="true"
  14. :password="popupConfig.password"
  15. v-model="popupInput"
  16. :placeholder="popupConfig.placeholder"
  17. :maxlength="popupConfig.maxlength"
  18. focus="true"
  19. placeholder-style="color:#999"
  20. :confirm-type="popupConfig.confirmType"
  21. />
  22. </view>
  23. <view class="popupBut">
  24. <button class="main-bg-color" @click="onConfirm">{{ popupConfig.confirmText }}</button>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. value: {
  33. type: String,
  34. default: function() {
  35. return '';
  36. }
  37. },
  38. options: {
  39. type: Object,
  40. default: function() {
  41. return {};
  42. }
  43. }
  44. },
  45. data() {
  46. return {
  47. popupConfig: {
  48. title: '操作',
  49. tips: "请输入",
  50. confirmText: '确认',
  51. placeholder: '',
  52. password: false,
  53. inputType: 'text',
  54. maxlength: 140,
  55. confirmType: "done"
  56. },
  57. popupInput: '',
  58. popupShow: false
  59. };
  60. },
  61. //第一次加载
  62. created() {
  63. if(this.value){
  64. this.popupInput = this.value;
  65. }
  66. if(this.options && typeof(this.options) == "object"){
  67. this.popupConfig = Object.assign(this.popupConfig, this.options);
  68. }
  69. },
  70. watch:{
  71. value(val){
  72. this.popupInput = val;
  73. },
  74. options(val){
  75. if(val && typeof(val) == "object"){
  76. this.popupConfig = Object.assign(this.popupConfig, val);
  77. }
  78. }
  79. },
  80. //方法
  81. methods: {
  82. //打开弹窗
  83. onPopupShow(value,options) {
  84. if(value){
  85. this.popupInput = value;
  86. }
  87. if(options && typeof(options) == "object"){
  88. this.popupConfig = Object.assign(this.popupConfig, options);
  89. }
  90. this.popupShow = true;
  91. },
  92. //关闭弹窗
  93. onPopupHide() {
  94. this.popupShow = false;
  95. },
  96. onConfirm() {
  97. if (this.popupInput == '') {
  98. uni.showToast({
  99. title: '请输入',
  100. icon: 'none'
  101. });
  102. return;
  103. }
  104. this.$emit('confirm', {
  105. close:() => {
  106. this.popupShow = false;
  107. },
  108. value:this.popupInput
  109. });
  110. }
  111. }
  112. };
  113. </script>
  114. <style scoped>
  115. .popupMask {
  116. position: fixed;
  117. top: 0upx;
  118. left: 0upx;
  119. width: 100%;
  120. height: 100%;
  121. background-color: rgba(0, 0, 0, 0.5);
  122. z-index: 510;
  123. animation: popupMask 0.4s;
  124. }
  125. .popupContentBox {
  126. position: fixed;
  127. top: 30%;
  128. left: 10%;
  129. width: 80%;
  130. transform: translateY(-50%);
  131. background-color: #fff;
  132. z-index: 511;
  133. animation: popupContentBox 0.4s;
  134. }
  135. .popupContentBox .close {
  136. position: absolute;
  137. top: 10upx;
  138. right: 15upx;
  139. color: #999;
  140. font-size: 42upx;
  141. line-height: 40upx;
  142. }
  143. .popupContentBox .title {
  144. text-align: center;
  145. height: 80upx;
  146. line-height: 80upx;
  147. font-size: 34upx;
  148. color: #666;
  149. }
  150. .popupContentBox .popupContent {
  151. padding: 30upx 40upx;
  152. }
  153. .popupContentBox .popupContent .input {
  154. width: 100%;
  155. border-radius: 10upx;
  156. border: 1px solid #eee;
  157. height: 80upx;
  158. font-size: 30upx;
  159. padding: 0 20upx;
  160. box-sizing: border-box;
  161. }
  162. .popupContentBox .popupContent .introduce {
  163. font-size: 28upx;
  164. color: #999;
  165. padding-bottom: 10upx;
  166. }
  167. .popupContentBox .popupBut {
  168. padding: 20upx 20upx 20upx 20upx;
  169. }
  170. .popupContentBox .popupBut button {
  171. color: #fff;
  172. }
  173. @keyframes popupMask {
  174. 0% {
  175. opacity: 0;
  176. }
  177. 100% {
  178. opacity: 1;
  179. }
  180. }
  181. @keyframes popupContentBox {
  182. 0% {
  183. opacity: 0;
  184. transform: translateY(-60%);
  185. }
  186. 100% {
  187. opacity: 1;
  188. transform: translateY(-50%);
  189. }
  190. }
  191. </style>