@peng_kai/kit 0.2.30 → 0.2.32

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.
@@ -1,8 +1,15 @@
1
1
  <script lang="ts">
2
- import { computed, reactive } from 'vue';
2
+ import { computed, reactive, ref, toValue } from 'vue';
3
3
  import { useInjectedAdminConfig } from '../../provider';
4
4
 
5
- const presetSymbols = reactive<Record<string, string>>({
5
+ export interface CurrencyIconProps {
6
+ symbol?: string
7
+ size?: string
8
+ cdn?: string
9
+ useCdn?: boolean
10
+ }
11
+
12
+ const imgIcons = ref<Record<string, string>>({
6
13
  USDT: 'https://api.iconify.design/cryptocurrency-color:usdt.svg',
7
14
  TRX: 'https://api.iconify.design/cryptocurrency-color:trx.svg',
8
15
  USDC: 'https://api.iconify.design/cryptocurrency-color:usdc.svg',
@@ -12,45 +19,62 @@ const presetSymbols = reactive<Record<string, string>>({
12
19
  MATIC: 'https://api.iconify.design/cryptocurrency-color:matic.svg',
13
20
  SOL: 'https://api.iconify.design/cryptocurrency-color:sol.svg',
14
21
  });
15
- const presetTextSymbols = reactive(['¥', '€', '¥', '₱', '$', 'AED', 'ARS', '$', 'BDT', 'R$', '$', 'Fr', '$', 'Kč', 'KR', '£', 'Ft', 'Rp', '₪', '₹', '₩', '$', 'RM', 'NGN', 'KR', '$', 'Rs', 'zł', '₽', 'SAR', 'SEK', 'S$', '฿', '₺', 'NT$', 'UAH', '₫', 'R']);
22
+ const textIcons = ref(['¥', '€', '¥', '₱', '$', 'AED', 'ARS', '$', 'BDT', 'R$', '$', 'Fr', '$', 'Kč', 'KR', '£', 'Ft', 'Rp', '₪', '₹', '₩', '$', 'RM', 'NGN', 'KR', '$', 'Rs', 'zł', '₽', 'SAR', 'SEK', 'S$', '฿', '₺', 'NT$', 'UAH', '₫', 'R']);
23
+ const fullback = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDIwIDIwIj48cGF0aCBmaWxsPSIjODQ4YTlkNTUiIGQ9Ik0xMCAyMGExMCAxMCAwIDEgMSAwLTIwIDEwIDEwIDAgMCAxIDAgMjBtMS01aDFhMyAzIDAgMCAwIDAtNkg3Ljk5YTEgMSAwIDAgMSAwLTJIMTRWNWgtM1YzSDl2Mkg4YTMgMyAwIDEgMCAwIDZoNGExIDEgMCAxIDEgMCAySDZ2MmgzdjJoMnoiLz48L3N2Zz4=';
24
+
25
+ const checkHttpUrl = (value: unknown) => String(value).startsWith('http');
26
+ const checkBase64 = (value: unknown) => String(value).startsWith('data:image');
16
27
  </script>
17
28
 
18
29
  <script setup lang="ts">
19
- const props = withDefaults(defineProps<{
20
- symbol?: string
21
- size?: string
22
- useCdn?: boolean
23
- }>(), {
30
+ defineOptions({
31
+ inheritAttrs: false,
32
+ });
33
+ const props = withDefaults(defineProps<CurrencyIconProps>(), {
24
34
  size: '1.1em',
25
35
  symbol: '',
26
36
  useCdn: true,
27
37
  });
28
38
 
29
- const { cdn } = useInjectedAdminConfig() ?? {};
30
-
39
+ const { cdn: cdnCtx } = useInjectedAdminConfig() ?? {};
40
+ const cdn = computed(() => props.useCdn ? (props.cdn || toValue(cdnCtx)) : '');
31
41
  const src = computed(() => {
32
- const isHttpUrl = props.symbol.startsWith('http');
33
-
34
- if (isHttpUrl)
42
+ if (checkHttpUrl(props.symbol) || checkBase64(props.symbol))
35
43
  return props.symbol;
36
- else if (presetTextSymbols.includes(props.symbol))
44
+ else if (textIcons.value?.includes(props.symbol))
37
45
  return props.symbol;
38
- else if (props.useCdn && cdn?.value)
46
+ else if (cdn.value)
39
47
  return `${cdn.value}/currency/${props.symbol}.svg`;
40
48
  else
41
- return presetSymbols[props.symbol.toUpperCase()];
49
+ return (imgIcons.value[props.symbol.toUpperCase()] ?? fullback);
42
50
  });
51
+
52
+ function onError(ev: Event) {
53
+ const $img = ev.target as HTMLImageElement;
54
+ $img.src = fullback;
55
+ }
43
56
  </script>
44
57
 
45
58
  <template>
46
59
  <img
47
- class="h-[1em] w-[1em] rounded-full bg-sys-layer-c text-inherit"
60
+ v-if="checkHttpUrl(src) || checkBase64(src)"
61
+ v-bind="$attrs"
62
+ class="currency-icon"
48
63
  :src="src"
49
64
  :alt="props.symbol"
50
65
  :style="{ fontSize: $props.size }"
66
+ @error="onError"
51
67
  >
68
+ <span v-else v-bind="$attrs">{{ src }}</span>
52
69
  </template>
53
70
 
71
+ <style lang="scss" scoped>
72
+ img.currency-icon {
73
+ width: 1em;
74
+ height: 1em;
75
+ }
76
+ </style>
77
+
54
78
  <!--
55
79
  透明图片
56
80
  data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
@@ -65,9 +65,9 @@ const amountColor = computed(() => {
65
65
  <template>
66
66
  <div class="amount-wrapper" :style="{ '--amount-color': amountColor }">
67
67
  <!-- 约等于 -->
68
- <span v-if="props.approx" class="color-$amount-color">≈</span>
68
+ <span v-if="props.approx">≈</span>
69
69
  <!-- 符号 -->
70
- <CurrencyIcon v-else class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
70
+ <CurrencyIcon class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
71
71
  <!-- 金额 -->
72
72
  <span class="color-$amount-color amount">{{ amountText }}</span>
73
73
  <!-- 单位 -->
@@ -80,10 +80,8 @@ const amountColor = computed(() => {
80
80
  display: flex;
81
81
  align-items: center;
82
82
 
83
- .symbol-logo {
83
+ img.symbol-logo {
84
84
  display: block;
85
- width: 1.1em;
86
- height: 1.1em;
87
85
  margin-right: 0.2em;
88
86
  }
89
87
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.30",
4
+ "version": "0.2.32",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -25,7 +25,7 @@ export class LocaleManager {
25
25
  public constructor(loaders: ILoaders) {
26
26
  this.metaLoaders = mapKeys(loaders.meta, (_, path) => path.match(metaPathRE)?.[1] ?? path);
27
27
  this.messageLoaders = mapKeys(loaders.message, (_, path) => path.match(messagePathRE)?.[1] ?? path);
28
- this._locale = this.defaultLocale;
28
+ this.locale = this.defaultLocale;
29
29
  }
30
30
 
31
31
  /** 当前区域 */
@@ -58,6 +58,7 @@ export class LocaleManager {
58
58
  const localeTargets = [searchParams.get('locale'), searchParams.get('lang'), this.getStorageLocale(), navigator.language]
59
59
  .filter(locale => !!locale)
60
60
  .map(locale => locale!.replace('_', '-'));
61
+ // 区域代码矩阵,2级数组的第1项是这个区域的标识(也是这个语言对应的文件名:en-US.json),后面是这个区域的代码
61
62
  const codeMatrix = this.localesAvailable.map(locale => [locale, ...this.localeMetas[locale].codes]);
62
63
  let localeFinal = '';
63
64
 
@@ -8,7 +8,7 @@ function useHistory(initialValue: string[] = []) {
8
8
  const history = ref([...initialValue]);
9
9
  const current = computed(() => history.value[history.value.length - 1]);
10
10
  const isFirst = computed(() => history.value.length === 1);
11
- const lastOperation = ref<'to' | 'back' | 'replace'>('to');
11
+ const lastOperation = ref<'to' | 'back' | 'replace'>('replace');
12
12
 
13
13
  const to = (name: string) => {
14
14
  lastOperation.value = 'to';