@peng_kai/kit 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export { default as CurrencyIcon } from './src/CurrencyIcon.vue';
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import { computed, reactive } from 'vue';
3
+ import { useInjectedAdminConfig } from '../../provider';
4
+
5
+ const icons = reactive<Record<string, string>>({});
6
+
7
+ const fullback = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDIwIDIwIj48cGF0aCBmaWxsPSIjODQ4YTlkNTUiIGQ9Ik0xMCAyMGExMCAxMCAwIDEgMSAwLTIwIDEwIDEwIDAgMCAxIDAgMjBtMS01aDFhMyAzIDAgMCAwIDAtNkg3Ljk5YTEgMSAwIDAgMSAwLTJIMTRWNWgtM1YzSDl2Mkg4YTMgMyAwIDEgMCAwIDZoNGExIDEgMCAxIDEgMCAySDZ2MmgzdjJoMnoiLz48L3N2Zz4=';
8
+ </script>
9
+
10
+ <script setup lang="ts">
11
+ const props = withDefaults(defineProps<{
12
+ symbol?: string
13
+ size?: string
14
+ useCdn?: boolean
15
+ }>(), {
16
+ size: '1.1em',
17
+ symbol: '',
18
+ useCdn: true,
19
+ });
20
+
21
+ const { cdn } = useInjectedAdminConfig()!;
22
+
23
+ const src = computed(() => {
24
+ const isHttpUrl = props.symbol.startsWith('http');
25
+
26
+ if (isHttpUrl)
27
+ return props.symbol;
28
+ else if (props.useCdn && cdn.value)
29
+ return `${cdn.value}/currency/${props.symbol}.svg`;
30
+ else
31
+ return icons[props.symbol.toUpperCase()];
32
+ });
33
+ </script>
34
+
35
+ <template>
36
+ <img
37
+ class="h-[1em] w-[1em] rounded-full bg-sys-layer-c text-inherit"
38
+ :src="src"
39
+ :alt="props.symbol"
40
+ :style="{ fontSize: $props.size }"
41
+ >
42
+ </template>
43
+
44
+ <!--
45
+ 透明图片
46
+ data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
47
+ -->
@@ -0,0 +1 @@
1
+ export { default as AdminProvider, useInjectedAdminConfig, useProvidingAdminConfig } from './src/AdminProvider.vue';
@@ -0,0 +1,22 @@
1
+ <script lang="ts">
2
+ import { createInjectionState } from '@vueuse/core';
3
+ import type { MaybeRefOrGetter } from 'vue';
4
+ import { toRef } from 'vue';
5
+
6
+ interface AdminConfig {
7
+ cdn: MaybeRefOrGetter<string | undefined | null>
8
+ }
9
+
10
+ export const [useProvidingAdminConfig, useInjectedAdminConfig] = createInjectionState((adminConfig: AdminConfig) => {
11
+ const cdn = toRef(adminConfig.cdn);
12
+
13
+ return { cdn };
14
+ }, { injectionKey: 'TTADMIN-PROVIDER-KEY' });
15
+ </script>
16
+
17
+ <script setup lang="ts">
18
+ </script>
19
+
20
+ <template>
21
+ <slot />
22
+ </template>
@@ -2,6 +2,7 @@
2
2
  import { computed, reactive } from 'vue';
3
3
  import bigNumber from 'bignumber.js';
4
4
  import isNil from 'lodash-es/isNil';
5
+ import { CurrencyIcon } from '../../currency';
5
6
 
6
7
  export const config = {
7
8
  aboveColor: '#52c41a',
@@ -11,19 +12,10 @@ export const config = {
11
12
  /**
12
13
  * 当 symbol 为以下值时,使用预设的 Logo
13
14
  */
14
- const presetSymbols: Record<string, string> = reactive({
15
- USDT: 'https://api.iconify.design/cryptocurrency-color:usdt.svg',
16
- TRX: 'https://api.iconify.design/cryptocurrency-color:trx.svg',
17
- USDC: 'https://api.iconify.design/cryptocurrency-color:usdc.svg',
18
- ETH: 'https://api.iconify.design/cryptocurrency-color:eth.svg',
19
- BNB: 'https://api.iconify.design/cryptocurrency-color:bnb.svg',
20
- BUSD: 'https://assets.coingecko.com/coins/images/9576/large/BUSD.png',
21
- MATIC: 'https://api.iconify.design/cryptocurrency-color:matic.svg',
22
- SOL: 'https://api.iconify.design/cryptocurrency-color:sol.svg',
23
- });
15
+ const presetTextSymbols = reactive(['$', '¥']);
24
16
 
25
- export function setConfig(symbols: Record<string, string>) {
26
- Object.assign(presetSymbols, symbols);
17
+ export function setConfig(textSymbols: string[]) {
18
+ presetTextSymbols.concat(textSymbols);
27
19
  }
28
20
  </script>
29
21
 
@@ -46,11 +38,13 @@ const props = withDefaults(
46
38
  colorful?: boolean
47
39
  /** 是否是大约数 */
48
40
  approx?: boolean
41
+ useCdn?: boolean
49
42
  }>(),
50
43
  {
51
44
  padZero: false,
52
45
  fractionDigits: 18,
53
46
  colorful: false,
47
+ useCdn: true,
54
48
  },
55
49
  );
56
50
 
@@ -75,7 +69,6 @@ const amountColor = computed(() => {
75
69
 
76
70
  return num > 0 ? config.aboveColor : (num < 0 ? config.belowColor : '');
77
71
  });
78
- const symbol = computed(() => presetSymbols[props.symbol!] ?? props.symbol ?? '');
79
72
  </script>
80
73
 
81
74
  <template>
@@ -83,11 +76,10 @@ const symbol = computed(() => presetSymbols[props.symbol!] ?? props.symbol ?? ''
83
76
  <!-- 约等于 -->
84
77
  <span v-if="props.approx" class="color-$amount-color">≈</span>
85
78
 
86
- <!-- 符号 -->
87
- <img v-if="symbol.startsWith('http')" class="symbol-logo" :src="symbol">
88
-
89
- <!-- 图片Logo -->
90
- <span v-else class="color-$amount-color">{{ symbol }}</span> <!-- 文本Logo,如法定币种符号(¥、$) -->
79
+ <!-- 文本符号,如法定币种符号(¥、$) -->
80
+ <span v-if="!symbol || presetTextSymbols.includes(symbol)" class="color-$amount-color">{{ symbol }}</span>
81
+ <!-- 图片符号 -->
82
+ <CurrencyIcon v-else class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
91
83
 
92
84
  <!-- 金额 -->
93
85
  <span class="color-$amount-color amount">{{ amountText }}</span>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.21",
4
+ "version": "0.2.23",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",