u-drawer-input.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="u-drawer " :class="visible ? 'u-drawer-open' : ''">
  3. <view class="u-drawer-mask" @click="cancel" />
  4. <view class="u-drawer-content">
  5. <view class="header u-flex">
  6. <view class="cancel" @click="cancel">取消</view>
  7. <view v-if="config.title" class="title">{{config.title}}</view>
  8. <view class="u-button" @click="sumbit">完成</view>
  9. </view>
  10. <slot></slot>
  11. <uni-easyinput :focus="true" v-model="inputValue" :placeholder="config.placeholder"></uni-easyinput>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import formChecker from '@/common/formChecker.js'
  17. export default {
  18. name: "u-drawer-input",
  19. props: {
  20. visible: {
  21. type: Boolean,
  22. default: false
  23. },
  24. config: {
  25. type: Object,
  26. default: () => {
  27. return {}
  28. }
  29. },
  30. },
  31. data() {
  32. return {
  33. inputValue: ''
  34. }
  35. },
  36. watch: {
  37. visible: {
  38. handler() {
  39. this.visible && this.init()
  40. },
  41. deep: true,
  42. immediate: true
  43. }
  44. },
  45. methods: {
  46. init() {
  47. this.inputValue = this.config.value || ''
  48. },
  49. cancel() {
  50. !Boolean(this.$listeners['click']) && this.$emit('update:visible', false)
  51. },
  52. sumbit() {
  53. //定义表单规则
  54. var rule = this.config.rule || []
  55. //进行表单检查
  56. var checkRes = formChecker.check({
  57. value: this.inputValue
  58. }, rule);
  59. if (!checkRes) {
  60. uni.showToast({
  61. title: formChecker.error,
  62. icon: "none"
  63. });
  64. return
  65. }
  66. this.$emit('sumbit', this.inputValue)
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .input-container {}
  73. .u-drawer>* {
  74. transition: transform .3s cubic-bezier(.7, .3, .1, 1), box-shadow .3s cubic-bezier(.7, .3, .1, 1);
  75. }
  76. .u-drawer {
  77. position: fixed;
  78. z-index: 99;
  79. left: 0;
  80. bottom: 0;
  81. width: 100%;
  82. height: 0%;
  83. }
  84. .u-drawer-mask {
  85. position: absolute;
  86. top: 0;
  87. left: 0;
  88. bottom: 0;
  89. right: 0;
  90. background-color: rgba(0, 0, 0, .45);
  91. display: none;
  92. // pointer-events: none;
  93. }
  94. .u-drawer-open {
  95. height: 100%;
  96. .u-drawer-content,
  97. .u-drawer-mask {
  98. display: inherit;
  99. transform: translateY(0);
  100. }
  101. }
  102. .u-drawer-content {
  103. position: absolute;
  104. width: 100%;
  105. bottom: 0;
  106. top: 0;
  107. // box-shadow: 0 -2px 8px rgb(0 0 0 / 15%);
  108. padding: 28rpx 32rpx;
  109. min-height: 100rpx;
  110. background: #FFFFFF;
  111. border-radius: 28rpx 28rpx 0px 0px;
  112. // display: none;
  113. transform: translateY(100%);
  114. // animation: mymove 0.3s;
  115. // animation-iteration-count: 1;
  116. .header {
  117. margin-bottom: 50rpx;
  118. height: auto;
  119. .title {
  120. font-size: 36rpx;
  121. font-weight: bold;
  122. color: #333333;
  123. }
  124. .cancel {
  125. min-width: 150rpx;
  126. padding: 12rpx 0;
  127. font-size: 28rpx;
  128. font-weight: 400;
  129. color: #333333;
  130. cursor: pointer;
  131. }
  132. }
  133. }
  134. </style>