useValueTexts.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { computed } from 'vue';
  2. import useMemo from '../../_util/hooks/useMemo';
  3. import shallowequal from '../../_util/shallowequal';
  4. import { formatValue } from '../utils/dateUtil';
  5. export default function useValueTexts(value, _ref) {
  6. let {
  7. formatList,
  8. generateConfig,
  9. locale
  10. } = _ref;
  11. const texts = useMemo(() => {
  12. if (!value.value) {
  13. return [[''], ''];
  14. }
  15. // We will convert data format back to first format
  16. let firstValueText = '';
  17. const fullValueTexts = [];
  18. for (let i = 0; i < formatList.value.length; i += 1) {
  19. const format = formatList.value[i];
  20. const formatStr = formatValue(value.value, {
  21. generateConfig: generateConfig.value,
  22. locale: locale.value,
  23. format
  24. });
  25. fullValueTexts.push(formatStr);
  26. if (i === 0) {
  27. firstValueText = formatStr;
  28. }
  29. }
  30. return [fullValueTexts, firstValueText];
  31. }, [value, formatList], (next, prev) => prev[0] !== next[0] || !shallowequal(prev[1], next[1]));
  32. const fullValueTexts = computed(() => texts.value[0]);
  33. const firstValueText = computed(() => texts.value[1]);
  34. return [fullValueTexts, firstValueText];
  35. }