ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<script lang="ts" setup>
import { computed, ref, unref, watch } from 'vue';
 
import { useAttrs, useTextMask } from '@jnpf/hooks';
 
import { useDebounceFn } from '@vueuse/core';
import { Input } from 'ant-design-vue';
 
import { inputProps } from './props';
 
defineOptions({ inheritAttrs: false, name: 'JnpfInput' });
const props = defineProps(inputProps);
const emit = defineEmits(['update:value', 'change']);
const InputPassword = Input.Password;
const attrs = useAttrs({ excludeDefaultKeys: false });
const innerValue = ref('');
const maskedValue = ref('');
const Comp = props.showPassword ? InputPassword : Input;
const debounceOnChange = useDebounceFn((value) => {
  emit('change', value);
}, 200);
 
const getBindValue = computed(() => ({ ...unref(attrs) }));
 
watch(
  () => unref(props.value),
  (val) => {
    setValue(val);
  },
  { immediate: true },
);
 
function setValue(value) {
  innerValue.value = value;
  if (!props.useMask) return (maskedValue.value = value);
  const { getMaskedText } = useTextMask(props.maskConfig);
  maskedValue.value = getMaskedText(value);
}
function onChange(e) {
  emit('update:value', e.target.value);
  debounceOnChange(e.target.value);
}
</script>
 
<template>
  <component :is="Comp" class="jnpf-input" v-bind="getBindValue" v-if="!detailed" v-model:value="innerValue" @change="onChange">
    <template v-for="item in Object.keys($slots)" #[item]="data"><slot :name="item" v-bind="data || {}"></slot></template>
    <template v-if="prefixIcon" #prefix>
      <i :class="prefixIcon"></i>
    </template>
    <template v-if="suffixIcon" #suffix>
      <i :class="suffixIcon"></i>
    </template>
  </component>
  <p v-else :class="{ ellipsis: showOverflow }" :title="showOverflow ? maskedValue : ''" class="detail-text break-all">
    <span v-if="$attrs.addonBefore">{{ $attrs.addonBefore }}</span>
    {{ maskedValue }}
    <span v-if="$attrs.addonAfter">{{ $attrs.addonAfter }}</span>
  </p>
</template>
<style lang="scss" scoped>
.jnpf-input {
  :deep(.ant-input-prefix),
  :deep(.ant-input-suffix) {
    i {
      line-height: 20px;
      color: var(--text-color-help-dark);
    }
  }
}
 
.ant-table,
.jnpf-vxe-table {
  .detail-text {
    line-height: 22px !important;
    white-space: pre-wrap;
 
    &.ellipsis {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>