zhengyiming
3 天以前 9453bef1fc4a3121b28ffa6617f0fbfc81d9f634
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
<template>
  <div class="dashboard-item-wrapper">
    <div class="dashboard-item-title-wrapper">
      <img class="dashboard-item-title-icon" :src="icon" />
      <div class="dashboard-item-title">{{ title }}</div>
    </div>
    <div class="dashboard-item-value-wrapper">
      <div class="dashboard-item-symbol" v-if="needSymbol" v-html="showSymbol"></div>
      <div class="dashboard-item-value">{{ value }}</div>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { computed } from 'vue';
 
defineOptions({
  name: 'DashboardItem',
});
 
type Props = {
  icon?: string;
  title?: string;
  value?: string | number;
  needSymbol?: boolean;
  symbol?: string;
};
 
const props = withDefaults(defineProps<Props>(), {
  needSymbol: false,
  symbol: '&yen;',
});
 
const replaceSpecialChar = (url: string) => {
  url = url.replace(/&quot;/g, '"');
  url = url.replace(/&amp;/g, '&');
  url = url.replace(/&lt;/g, '<');
  url = url.replace(/&gt;/g, '>');
  url = url.replace(/&nbsp;/g, ' ');
  url = url.replace(/&yen;/g, '¥');
  return url;
};
 
const showSymbol = computed(() => {
  const symbol = props.needSymbol ? replaceSpecialChar(props.symbol) : '';
  return symbol;
});
</script>