update
This commit is contained in:
		
							parent
							
								
									61a685dfe2
								
							
						
					
					
						commit
						0511c97302
					
				@ -40,7 +40,7 @@ const props = withDefaults(defineProps<InputProps>(), {
 | 
			
		||||
  password: false,
 | 
			
		||||
  modelValue: "",
 | 
			
		||||
  size: "md",
 | 
			
		||||
  qfw: false
 | 
			
		||||
  qfw: false,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
interface InputEmits {
 | 
			
		||||
@ -81,15 +81,14 @@ const formatMoney = function (s: string) {
 | 
			
		||||
      t += l[i] + ""; //加上空格
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  let z:any = (noNegative ? "" : "-") + t.split("").reverse().join("");
 | 
			
		||||
  let z: any = (noNegative ? "" : "-") + t.split("").reverse().join("");
 | 
			
		||||
  // z = isNaN(z) ? 0 : z;
 | 
			
		||||
  if(r){
 | 
			
		||||
    return  z+ "." + r;
 | 
			
		||||
 | 
			
		||||
  }else{
 | 
			
		||||
  if (r) {
 | 
			
		||||
    return z + "." + r;
 | 
			
		||||
  } else {
 | 
			
		||||
    return isNaN(parseInt(z)) ? 0 : z;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
watch(
 | 
			
		||||
  () => props.type,
 | 
			
		||||
@ -97,15 +96,15 @@ watch(
 | 
			
		||||
    type.value = props.type;
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
const input:any = ref<Element>()
 | 
			
		||||
const input: any = ref<Element>();
 | 
			
		||||
 | 
			
		||||
watch(
 | 
			
		||||
  () => props.modelValue,
 | 
			
		||||
  () => {
 | 
			
		||||
    console.log(input)
 | 
			
		||||
    if(!(input.value == document.activeElement) && props.qfw){
 | 
			
		||||
    console.log(input);
 | 
			
		||||
    if (!(input.value == document.activeElement) && props.qfw) {
 | 
			
		||||
      currentValue.value = formatMoney(props.modelValue.toString());
 | 
			
		||||
      return
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    currentValue.value = String(
 | 
			
		||||
      props.modelValue == null ? "" : props.modelValue
 | 
			
		||||
@ -119,7 +118,7 @@ const onInput = function (event: Event) {
 | 
			
		||||
  emit("input", value);
 | 
			
		||||
  if (composing.value) return;
 | 
			
		||||
  if (props.qfw) {
 | 
			
		||||
    value = value.replace(/,/g, "")
 | 
			
		||||
    value = value.replace(/,/g, "");
 | 
			
		||||
  }
 | 
			
		||||
  emit("update:modelValue", value);
 | 
			
		||||
};
 | 
			
		||||
@ -130,7 +129,7 @@ const onClear = () => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const onFocus = (event: Event) => {
 | 
			
		||||
  currentValue.value = new String(props.modelValue).replace(/,/g, "")
 | 
			
		||||
  currentValue.value = new String(props.modelValue).replace(/,/g, "");
 | 
			
		||||
  emit("focus", event);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -138,7 +137,7 @@ const onChange = (event: Event) => {
 | 
			
		||||
  const inputElement = event.target as HTMLInputElement;
 | 
			
		||||
  let value = inputElement.value;
 | 
			
		||||
  if (props.qfw) {
 | 
			
		||||
    value = value.replace(/,/g, "")
 | 
			
		||||
    value = value.replace(/,/g, "");
 | 
			
		||||
  }
 | 
			
		||||
  emit("change", value);
 | 
			
		||||
};
 | 
			
		||||
@ -148,18 +147,16 @@ const onBlur = (event: Event) => {
 | 
			
		||||
    onNumberBlur(event);
 | 
			
		||||
  }
 | 
			
		||||
  if (props.qfw) {
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      let reg = /\d{1,3}(?=(\d{3})+$)/g;
 | 
			
		||||
      // new String(props.modelValue).replace(reg, '$&,');
 | 
			
		||||
      console.log("添加,", formatMoney(props.modelValue.toString()))
 | 
			
		||||
      console.log("添加,", formatMoney(props.modelValue.toString()));
 | 
			
		||||
      currentValue.value = formatMoney(props.modelValue.toString());
 | 
			
		||||
    } catch {
 | 
			
		||||
      currentValue.value = "输入错误"
 | 
			
		||||
      currentValue.value = "输入错误";
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  emit("blur", event);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -172,7 +169,7 @@ const onNumberBlur = (event: Event) => {
 | 
			
		||||
    if (props.min && props.min > Number(value)) value = props.min.toString();
 | 
			
		||||
  }
 | 
			
		||||
  if (props.qfw) {
 | 
			
		||||
    value = value.replace(/,/g, "")
 | 
			
		||||
    value = value.replace(/,/g, "");
 | 
			
		||||
  }
 | 
			
		||||
  emit("update:modelValue", value);
 | 
			
		||||
};
 | 
			
		||||
@ -210,22 +207,53 @@ const showPassword = () => {
 | 
			
		||||
    <div class="layui-input-wrapper">
 | 
			
		||||
      <span class="layui-input-prefix" v-if="slots.prefix || props.prefixIcon">
 | 
			
		||||
        <slot name="prefix" v-if="slots.prefix"></slot>
 | 
			
		||||
        <lay-icon v-else :type="props.prefixIcon" class="layui-input-prefix-icon"></lay-icon>
 | 
			
		||||
        <lay-icon
 | 
			
		||||
          v-else
 | 
			
		||||
          :type="props.prefixIcon"
 | 
			
		||||
          class="layui-input-prefix-icon"
 | 
			
		||||
        ></lay-icon>
 | 
			
		||||
      </span>
 | 
			
		||||
      <input :type="type" :name="name" :disabled="disabled" :placeholder="placeholder" :autofocus="autofocus"
 | 
			
		||||
        :autocomplete="autocomplete" :maxlength="maxlength" :max="max" :min="min" :readonly="readonly"
 | 
			
		||||
        :value="currentValue" @input="onInput" @change="onChange" @focus="onFocus" @blur="onBlur"
 | 
			
		||||
        @compositionstart="onCompositionstart" @compositionend="onCompositionend" ref="input" />
 | 
			
		||||
      <span class="layui-input-password" @click="showPassword" v-if="password && hasContent">
 | 
			
		||||
      <input
 | 
			
		||||
        :type="type"
 | 
			
		||||
        :name="name"
 | 
			
		||||
        :disabled="disabled"
 | 
			
		||||
        :placeholder="placeholder"
 | 
			
		||||
        :autofocus="autofocus"
 | 
			
		||||
        :autocomplete="autocomplete"
 | 
			
		||||
        :maxlength="maxlength"
 | 
			
		||||
        :max="max"
 | 
			
		||||
        :min="min"
 | 
			
		||||
        :readonly="readonly"
 | 
			
		||||
        :value="currentValue"
 | 
			
		||||
        @input="onInput"
 | 
			
		||||
        @change="onChange"
 | 
			
		||||
        @focus="onFocus"
 | 
			
		||||
        @blur="onBlur"
 | 
			
		||||
        @compositionstart="onCompositionstart"
 | 
			
		||||
        @compositionend="onCompositionend"
 | 
			
		||||
        ref="input"
 | 
			
		||||
      />
 | 
			
		||||
      <span
 | 
			
		||||
        class="layui-input-password"
 | 
			
		||||
        @click="showPassword"
 | 
			
		||||
        v-if="password && hasContent"
 | 
			
		||||
      >
 | 
			
		||||
        <password-icon v-if="isPassword"></password-icon>
 | 
			
		||||
        <un-password-icon v-else></un-password-icon>
 | 
			
		||||
      </span>
 | 
			
		||||
      <span class="layui-input-clear" v-if="allowClear && hasContent && !disabled">
 | 
			
		||||
      <span
 | 
			
		||||
        class="layui-input-clear"
 | 
			
		||||
        v-if="allowClear && hasContent && !disabled"
 | 
			
		||||
      >
 | 
			
		||||
        <lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon>
 | 
			
		||||
      </span>
 | 
			
		||||
      <span class="layui-input-suffix" v-if="slots.suffix || props.suffixIcon">
 | 
			
		||||
        <slot name="suffix" v-if="slots.suffix"></slot>
 | 
			
		||||
        <lay-icon v-else :type="props.suffixIcon" class="layui-input-suffix-icon"></lay-icon>
 | 
			
		||||
        <lay-icon
 | 
			
		||||
          v-else
 | 
			
		||||
          :type="props.suffixIcon"
 | 
			
		||||
          class="layui-input-suffix-icon"
 | 
			
		||||
        ></lay-icon>
 | 
			
		||||
      </span>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="layui-input-append" v-if="slots.append">
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user