BaseInput.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script setup>
  2. import { ref, computed } from 'vue';
  3. import { SvgIcon } from '@/components';
  4. const props = defineProps({
  5. size: {
  6. type: String,
  7. default: ''
  8. },
  9. type: {
  10. type: String,
  11. default: 'default'
  12. },
  13. isActive: {
  14. type: Boolean,
  15. default: false
  16. },
  17. unit: {
  18. type: String,
  19. default: ''
  20. },
  21. isNeedFlotBtn: {
  22. type: Boolean,
  23. default: true
  24. }
  25. })
  26. const inpRef = ref(null);
  27. const inpValue = ref('');
  28. const isFocusStatus = ref(false);
  29. const activeIndex = ref(0);
  30. const domClassName = computed(() => {
  31. return [
  32. 'input_wrapper',
  33. 'input-' + props.type + "_" + props.size,
  34. 'inpit_' + props.size
  35. ]
  36. })
  37. const onFocus = () => {
  38. isFocusStatus.value = true;
  39. }
  40. const onBlur = () => {
  41. isFocusStatus.value = false;
  42. }
  43. const handleInpValue = (event, type) => {
  44. if ( type === 'confirm' ) {
  45. }
  46. if ( type === 'cancel' ) {
  47. event.preventDefault();
  48. inpValue.value = '';
  49. }
  50. }
  51. </script>
  52. <template>
  53. <div :class="domClassName">
  54. <input
  55. ref="inpRef"
  56. v-model="inpValue"
  57. type="text"
  58. class="inp"
  59. @focus="onFocus"
  60. @blur="onBlur"
  61. >
  62. <div class="unit" v-if="unit">{{ unit }}</div>
  63. <ul class="inp-flot_group space-x-[4px]" v-show="isFocusStatus && isNeedFlotBtn">
  64. <li>
  65. <SvgIcon name="control-icon-confirm" size="16" @click="handleInpValue($event, 'confirm')"></SvgIcon>
  66. </li>
  67. <li>
  68. <SvgIcon name="control-icon-cancel" size="16" @mousedown="handleInpValue($event, 'cancel')"></SvgIcon>
  69. </li>
  70. </ul>
  71. </div>
  72. </template>
  73. <style lang="scss" scoped>
  74. .input_wrapper {
  75. @include flex(x, center, between);
  76. position: relative;
  77. margin-top: 4px;
  78. .inp {
  79. width: 100%;
  80. height: 28px;
  81. padding: 0px 56px 0 10px;
  82. border-radius: 4px 0px 0px 4px;
  83. border: 1px solid #E6EAEE;
  84. background: #fff;
  85. outline: none;
  86. font-size: 12px;
  87. &:focus {
  88. border: 1px solid #2454FF;
  89. }
  90. }
  91. .unit {
  92. flex-shrink: 1;
  93. width: 60px;
  94. height: 28px;
  95. border-radius: 0px 4px 4px 0px;
  96. border: 1px solid #E6EAEE;
  97. border-left: 0;
  98. background: #F0F2F5;
  99. text-align: center;
  100. line-height: 28px;
  101. font-size: 12px;
  102. font-weight: bold;
  103. }
  104. .inp-flot_group {
  105. @include flex(x, center, center);
  106. position: absolute;
  107. right: 50px;
  108. top: 50%;
  109. transform: translateY(-50%);
  110. li {
  111. width: 16px;
  112. height: 16px;
  113. border-radius: 100%;
  114. color: #DFE2E6;
  115. cursor: pointer;
  116. svg,
  117. svg path {
  118. fill: #e0e2e6;
  119. stroke: #e0e2e6;
  120. }
  121. &:hover svg {
  122. fill: #b3c4e3;
  123. stroke: #b3c4e3;
  124. }
  125. }
  126. }
  127. }
  128. .inpit_small, .input-text_small {
  129. width: 112px;
  130. .inp {
  131. text-align: center;
  132. padding: 0 10px;
  133. }
  134. }
  135. .input-text_small {
  136. .inp {
  137. border-radius: 4px;
  138. }
  139. }
  140. </style>