BaseInput.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <script setup>
  2. import { ref, computed } from 'vue';
  3. import { NInputNumber } from 'naive-ui';
  4. const props = defineProps({
  5. placeholder: {
  6. type: String,
  7. default: () => ""
  8. },
  9. size: {
  10. type: String,
  11. default: ''
  12. },
  13. type: {
  14. type: String,
  15. default: 'default'
  16. },
  17. isActive: {
  18. type: Boolean,
  19. default: false
  20. },
  21. unit: {
  22. type: String,
  23. default: ''
  24. },
  25. isNeedFlotBtn: {
  26. type: Boolean,
  27. default: true
  28. },
  29. isCenter: {
  30. type: Boolean,
  31. default: false
  32. },
  33. isCloseIcon: {
  34. type: Boolean,
  35. default: true
  36. },
  37. readonly: {
  38. type: Boolean,
  39. default: false
  40. },
  41. min: {
  42. type: Number,
  43. default: 0
  44. },
  45. max: {
  46. type: Number,
  47. default: 999999
  48. }
  49. })
  50. let currentVal = '';
  51. const isFocusStatus = ref(false);
  52. const emit = defineEmits(['click:confirm', 'on-input', 'on-blur', 'click:cancel']);
  53. const modelValue = defineModel();
  54. const domClassName = computed(() => {
  55. return [
  56. 'input_wrapper',
  57. {'input_text_center': props.isCenter },
  58. 'input-' + props.type + "_" + props.size,
  59. 'inpit_' + props.size
  60. ]
  61. })
  62. const onFocus = () => {
  63. isFocusStatus.value = true;
  64. }
  65. const onBlur = (e) => {
  66. if ( currentVal !== '' ) {
  67. isFocusStatus.value = false;
  68. emit('on-blur');
  69. }
  70. }
  71. const onInput = (value) => {
  72. emit('on-input', value);
  73. currentVal = value
  74. modelValue.value = value;
  75. }
  76. const handleInpValue = (event, type) => {
  77. if (type === 'confirm') {
  78. emit('click:confirm', modelValue.value);
  79. }
  80. if (type === 'cancel') {
  81. event.preventDefault();
  82. modelValue.value = null;
  83. emit('click:cancel', null);
  84. }
  85. }
  86. </script>
  87. <template>
  88. <div :class="[domClassName, 'base-input-wrapper']">
  89. <NInputNumber
  90. size="small"
  91. round
  92. style="width: 100%;"
  93. :readonly="readonly"
  94. :precision="2"
  95. :max="max"
  96. :min="min"
  97. :placeholder="placeholder"
  98. :show-button="false"
  99. :on-update:value="onInput"
  100. :on-blur="onBlur"
  101. :on-focus="onFocus"
  102. :value="modelValue"
  103. >
  104. <template #suffix>
  105. <div class="unit" v-if="unit">{{ unit }}</div>
  106. </template>
  107. </NInputNumber>
  108. <ul class="inp-flot_group space-x-[4px]" v-show="isFocusStatus && isNeedFlotBtn">
  109. <!-- <li>
  110. <SvgIcon name="control-icon-confirm" size="16" @mousedown="handleInpValue($event, 'confirm')"></SvgIcon>
  111. </li> -->
  112. <!-- <li v-if="isCloseIcon">
  113. <SvgIcon name="control-icon-cancel" size="16" @mousedown="handleInpValue($event, 'cancel')"></SvgIcon>
  114. </li> -->
  115. </ul>
  116. </div>
  117. </template>
  118. <style lang="scss" scoped>
  119. .input_wrapper {
  120. @include flex(x, center, between);
  121. position: relative;
  122. margin-top: 4px;
  123. .inp {
  124. width: 100%;
  125. height: 28px;
  126. padding: 0px 56px 0 10px;
  127. border-radius: 4px 0px 0px 4px;
  128. border: 1px solid #E6EAEE;
  129. background: #fff;
  130. outline: none;
  131. font-size: 12px;
  132. &:focus {
  133. border: 1px solid #2454FF;
  134. }
  135. }
  136. .unit {
  137. flex-shrink: 1;
  138. width: 60px;
  139. height: 28px;
  140. border-radius: 0px 4px 4px 0px;
  141. border: 1px solid #E6EAEE;
  142. border-left: 0;
  143. background: #F0F2F5;
  144. text-align: center;
  145. line-height: 28px;
  146. font-size: 12px;
  147. font-weight: bold;
  148. color: #333;
  149. }
  150. .inp-flot_group {
  151. @include flex(x, center, center);
  152. position: absolute;
  153. right: 66px;
  154. top: 50%;
  155. transform: translateY(-50%);
  156. li {
  157. width: 16px;
  158. height: 16px;
  159. border-radius: 100%;
  160. color: #DFE2E6;
  161. cursor: pointer;
  162. svg,
  163. svg path {
  164. fill: #e0e2e6;
  165. stroke: #e0e2e6;
  166. }
  167. &:hover svg {
  168. fill: #b3c4e3;
  169. stroke: #b3c4e3;
  170. }
  171. }
  172. }
  173. }
  174. </style>
  175. <style lang="scss">
  176. .base-input-wrapper {
  177. .n-input-wrapper {
  178. padding-right: 0px;
  179. border: 1px solid #E6EAEE;
  180. border-radius: 4px;
  181. .n-input__input-el, .n-input__placeholder {
  182. font-size: 12px;
  183. }
  184. }
  185. }
  186. .input_text_center {
  187. .n-input-wrapper {
  188. .n-input__input-el {
  189. padding-right: 10px;
  190. text-align: center;
  191. }
  192. }
  193. }
  194. </style>