app_input_all.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class="my-inputBox">
  3. <div class="line"></div>
  4. <div class="my-title">
  5. <slot class="title">
  6. <span>{{title}}</span>
  7. </slot>
  8. <slot name="icon"></slot>
  9. </div>
  10. <div
  11. :class="['my-input',arrowsRight?'isLink':'']">
  12. <slot name="content">
  13. <!-- <textarea
  14. auto-height
  15. v-if="type == 'textarea'"
  16. class="text-line text-textarea"
  17. :disabled="disabled"
  18. ref="input"
  19. :type="type"
  20. v-model="currentValue"
  21. @blur="onBlur"
  22. @input="onChange"
  23. :isFocus="true"
  24. :placeholder="placeholder">
  25. </textarea> -->
  26. <appTextarea
  27. auto-height
  28. v-if="type == 'textarea'"
  29. class="text-line text-textarea"
  30. :disabled="disabled"
  31. ref="input"
  32. :type="type"
  33. v-model="currentValue"
  34. @blur="onBlur"
  35. @input="onChange"
  36. :focus="isFocus"
  37. :placeholder="placeholder"
  38. ></appTextarea>
  39. <input
  40. v-else
  41. class="text-line"
  42. :disabled="disabled"
  43. ref="input"
  44. :type="type"
  45. v-model="currentValue"
  46. @blur="onBlur"
  47. @input="onChange"
  48. :focus="isFocus"
  49. :placeholder="placeholder">
  50. </slot>
  51. <!-- <i class="icon-butongguo" v-show="isClear&&currentValue !== ''" @click="clear"></i> -->
  52. </div>
  53. <div class="my-left">
  54. <slot name="inputRight"></slot>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import appTextarea from './app-textarea'
  60. export default {
  61. name: 'app_input_all',
  62. components: {
  63. appTextarea
  64. },
  65. data() {
  66. return {
  67. currentValue: ''
  68. }
  69. },
  70. props: {
  71. value: {
  72. type: [String, Number]
  73. },
  74. title: {
  75. type: String
  76. },
  77. type: {
  78. type: String,
  79. default: 'text'
  80. },
  81. placeholder: {
  82. type: String
  83. },
  84. isClear: {
  85. type: Boolean,
  86. default: true
  87. },
  88. isFocus: {
  89. type: Boolean,
  90. default: false
  91. },
  92. disabled: {
  93. type: Boolean,
  94. default: false
  95. },
  96. arrowsRight: {
  97. type: Boolean,
  98. default: false
  99. }
  100. },
  101. created() {
  102. this.currentValue = (this.value === undefined || this.value === null) ? '' : this.value
  103. },
  104. mounted() {
  105. if (this.isFocus) {
  106. this.focus()
  107. }
  108. },
  109. methods: {
  110. clear() {
  111. this.currentValue = ''
  112. this.focus()
  113. },
  114. focus() {
  115. this.$refs.input.focus()
  116. },
  117. blur() {
  118. this.$refs.input.blur()
  119. },
  120. onBlur($event) {
  121. this.$emit('on-blur', this.currentValue, $event)
  122. },
  123. onChange(event) {
  124. let val = null
  125. if (this.type == 'text') {
  126. val = event.target.value
  127. } else {
  128. val = event
  129. }
  130. this.$emit('on-change', val)
  131. }
  132. },
  133. watch: {
  134. value(val) {
  135. this.currentValue = val
  136. },
  137. currentValue(val) {
  138. this.$emit('input', val)
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. .my-inputBox{
  145. position: relative;
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. box-sizing: content-box;
  150. padding-bottom: 15upx;
  151. & .line{
  152. position: absolute;
  153. width: 100%;
  154. height: 1upx;
  155. left: 0;
  156. bottom: 0;
  157. border-bottom: 1upx solid #ebedf0;
  158. }
  159. .my-input{
  160. position: relative;
  161. flex: 1;
  162. box-sizing: content-box;
  163. & .text-textarea {
  164. min-height: 150upx;
  165. display: inline-block;
  166. width: 100%;
  167. padding: 20upx 20upx 20upx 10upx;
  168. box-sizing: border-box;
  169. }
  170. & input{
  171. min-height: 88upx;
  172. padding-left: 10upx;
  173. padding-right: 50upx;
  174. }
  175. &.isLink::after{
  176. content: "";
  177. display: inline-block;
  178. width: 15upx;
  179. height: 15upx;
  180. border-width:2upx 2upx 0 0;
  181. border-color:#C8C8CD;
  182. border-style:solid;
  183. position: absolute;
  184. top: 50%;
  185. right: 30upx;
  186. transform: translate(0,-50%) matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
  187. }
  188. }
  189. }
  190. input,textarea{
  191. -webkit-appearance:none;
  192. outline:0;
  193. background-color:transparent;
  194. border:0;
  195. font-size: 28upx;
  196. font-weight: normal;
  197. font-stretch: normal;
  198. letter-spacing: 0upx;
  199. color: #4d4d4d;
  200. display: block;
  201. }
  202. .icon-butongguo{
  203. color: #cccccc;
  204. font-size: 28upx;
  205. position: absolute;
  206. padding: 20upx 10upx 20upx 20upx;
  207. right: 0;
  208. top: 50%;
  209. transform: translate(0,-50%);
  210. }
  211. .my-title {
  212. color: #666;
  213. font-size: 28upx;
  214. width: 180upx;
  215. }
  216. </style>