@peng_kai/kit 0.2.26 → 0.2.28

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.
@@ -2,9 +2,17 @@
2
2
  import { computed, reactive } from 'vue';
3
3
  import { useInjectedAdminConfig } from '../../provider';
4
4
 
5
- const icons = reactive<Record<string, string>>({});
6
-
7
- const fullback = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDIwIDIwIj48cGF0aCBmaWxsPSIjODQ4YTlkNTUiIGQ9Ik0xMCAyMGExMCAxMCAwIDEgMSAwLTIwIDEwIDEwIDAgMCAxIDAgMjBtMS01aDFhMyAzIDAgMCAwIDAtNkg3Ljk5YTEgMSAwIDAgMSAwLTJIMTRWNWgtM1YzSDl2Mkg4YTMgMyAwIDEgMCAwIDZoNGExIDEgMCAxIDEgMCAySDZ2MmgzdjJoMnoiLz48L3N2Zz4=';
5
+ const presetSymbols = reactive<Record<string, string>>({
6
+ USDT: 'https://api.iconify.design/cryptocurrency-color:usdt.svg',
7
+ TRX: 'https://api.iconify.design/cryptocurrency-color:trx.svg',
8
+ USDC: 'https://api.iconify.design/cryptocurrency-color:usdc.svg',
9
+ ETH: 'https://api.iconify.design/cryptocurrency-color:eth.svg',
10
+ BNB: 'https://api.iconify.design/cryptocurrency-color:bnb.svg',
11
+ BUSD: 'https://api.iconify.design/token-branded:busd.svg',
12
+ MATIC: 'https://api.iconify.design/cryptocurrency-color:matic.svg',
13
+ SOL: 'https://api.iconify.design/cryptocurrency-color:sol.svg',
14
+ });
15
+ const presetTextSymbols = reactive(['¥', '€', '¥', '₱', '$', 'AED', 'ARS', '$', 'BDT', 'R$', '$', 'Fr', '$', 'Kč', 'KR', '£', 'Ft', 'Rp', '₪', '₹', '₩', '$', 'RM', 'NGN', 'KR', '$', 'Rs', 'zł', '₽', 'SAR', 'SEK', 'S$', '฿', '₺', 'NT$', 'UAH', '₫', 'R']);
8
16
  </script>
9
17
 
10
18
  <script setup lang="ts">
@@ -18,17 +26,19 @@ const props = withDefaults(defineProps<{
18
26
  useCdn: true,
19
27
  });
20
28
 
21
- const { cdn } = useInjectedAdminConfig()!;
29
+ const { cdn } = useInjectedAdminConfig() ?? {};
22
30
 
23
31
  const src = computed(() => {
24
32
  const isHttpUrl = props.symbol.startsWith('http');
25
33
 
26
34
  if (isHttpUrl)
27
35
  return props.symbol;
28
- else if (props.useCdn && cdn.value)
36
+ else if (presetTextSymbols.includes(props.symbol))
37
+ return props.symbol;
38
+ else if (props.useCdn && cdn?.value)
29
39
  return `${cdn.value}/currency/${props.symbol}.svg`;
30
40
  else
31
- return icons[props.symbol.toUpperCase()];
41
+ return presetSymbols[props.symbol.toUpperCase()];
32
42
  });
33
43
  </script>
34
44
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { Checkbox } from 'ant-design-vue';
2
+ import { Checkbox, FormItemRest } from 'ant-design-vue';
3
3
  import { computed, triggerRef, watch } from 'vue';
4
4
 
5
5
  interface TTree {
@@ -9,19 +9,6 @@ interface TTree {
9
9
  children?: TTree[]
10
10
  }
11
11
 
12
- export function treeToIds(tree: TTree[]) {
13
- const ids = [] as number[];
14
-
15
- const isCheckedFn = (node: TTree) => {
16
- node.checked && ids.push(node.id);
17
- node.children?.length && node.children.forEach(isCheckedFn);
18
- };
19
-
20
- tree.forEach(isCheckedFn);
21
-
22
- return ids;
23
- }
24
-
25
12
  function treeToTable(tree: TTree[]) {
26
13
  interface TD {
27
14
  id: number
@@ -79,47 +66,36 @@ function treeToStates(tree: TTree[]) {
79
66
 
80
67
  tree.forEach(assId);
81
68
 
82
- // for (const id in ids) {
83
- // const state = states[id];
84
- // state.indet = isIndet(state.children.map(cid => states[cid].checked));
85
- // state.children.forEach(cid => states[cid].checked = state.checked);
86
- // [...state.parents].reverse().forEach((pid) => {
87
- // const checks = states[pid].children.map(cid => states[cid].checked);
88
- // state.indet = isIndet(checks);
89
- // state.checked = checks.every(checked => checked);
90
- // });
91
- // }
92
-
93
- // Object.keys(states)
94
- // [...ids].forEach((id) => {
95
- // const state = states[id];
96
- // state.checked = true;
97
- // state.children.forEach((cid) => {
98
- // states[cid].checked = true;
99
- // states[cid].indet = false;
100
- // });
101
- // });
102
-
103
69
  return states;
104
70
  }
105
71
 
106
72
  function updateStates(states: ReturnType<typeof treeToStates>, id: number, checked: boolean) {
107
73
  const state = states[id];
74
+
75
+ if (!state)
76
+ return;
77
+
108
78
  state.checked = checked;
109
79
  state.indet = false;
110
80
  state.children.forEach((cid) => {
111
- states[cid].checked = checked;
112
- states[cid].indet = false;
81
+ const cState = states[cid];
82
+ if (cState) {
83
+ cState.checked = checked;
84
+ cState.indet = false;
85
+ }
113
86
  });
114
- [...state.parents].reverse().forEach((pid) => {
115
- const checks = states[pid].children.map(pid => states[pid].checked);
116
- states[pid].indet = isIndet(checks);
117
- states[pid].checked = checks.every(checked => checked);
87
+ [...state.parents].forEach((pid) => {
88
+ const pState = states[pid];
89
+ if (pState) {
90
+ const checks = pState.children.map(cid => states[cid]?.checked);
91
+ pState.indet = isIndet(checks);
92
+ pState.checked = checks.every(checked => checked);
93
+ }
118
94
  });
119
95
  }
120
96
 
121
97
  function statesToIds(states: ReturnType<typeof treeToStates>) {
122
- return Object.keys(states).map(Number).filter(id => states[id].checked);
98
+ return Object.keys(states).map(Number).filter(id => states[id]?.checked);
123
99
  }
124
100
 
125
101
  function findAllParents(tree: any[], id: number, path: any[] = []): any[] | undefined {
@@ -157,60 +133,71 @@ function isIndet(arr: boolean[]) {
157
133
 
158
134
  <script setup lang="ts">
159
135
  const props = defineProps<{
160
- treeData: TTree[]
136
+ treeData: TTree[] | null | undefined
161
137
  }>();
162
138
  const ids = defineModel<number[]>('value', { default: [] });
163
- const tableData = computed(() => treeToTable(props.treeData));
164
- const stateMap = computed(() => treeToStates(props.treeData));
139
+ const tableData = computed(() => props.treeData && treeToTable(props.treeData));
140
+ const stateMap = computed(() => props.treeData && treeToStates(props.treeData));
165
141
 
166
142
  watch(ids, (newV, oldV) => {
167
- if (newV === oldV)
143
+ if (newV === oldV || !stateMap.value)
168
144
  return;
169
145
 
170
- newV.forEach(id => updateStates(stateMap.value, id, true));
146
+ newV.forEach(id => updateStates(stateMap.value!, id, true));
171
147
  triggerRef(stateMap);
172
148
  }, { immediate: true });
173
149
 
150
+ watch(stateMap, (newV) => {
151
+ if (newV) {
152
+ ids.value.forEach(id => updateStates(newV, id, true));
153
+ triggerRef(stateMap);
154
+ }
155
+ });
156
+
174
157
  function onCheckChange(id: number) {
175
- const checked = !ids.value.includes(id);
176
- updateStates(stateMap.value, id, checked);
177
- ids.value = statesToIds(stateMap.value);
158
+ if (stateMap.value) {
159
+ const checked = !ids.value.includes(id);
160
+ updateStates(stateMap.value, id, checked);
161
+ ids.value = statesToIds(stateMap.value);
162
+ }
178
163
  }
179
164
  </script>
180
165
 
181
166
  <template>
182
167
  <table class="w-full border-collapse border-$antd-colorBorderSecondary" border>
183
- <tr v-for="(row, ri) of tableData" :key="ri">
184
- <!-- 模块 -->
185
- <td v-if="row[0]" class="w-[6em] px-[1em] py-0.5em" :rowspan="row[0].span">
186
- <Checkbox
187
- :checked="stateMap[row[0].id].indet ? false : stateMap[row[0].id].checked"
188
- :indeterminate="stateMap[row[0].id].indet" @change="onCheckChange(row[0].id)"
189
- >
190
- {{ row[0].label }}{{ row[0].id }}
191
- </Checkbox>
192
- </td>
193
- <!-- 页面 -->
194
- <td v-if="row[1]" class="w-[9em] px-[1em] py-0.5em">
195
- <Checkbox
196
- :checked="stateMap[row[1].id].indet ? false : stateMap[row[1].id].checked"
197
- :indeterminate="stateMap[row[1].id].indet" @change="onCheckChange(row[1].id)"
198
- >
199
- {{ row[1].label }}
200
- </Checkbox>
201
- </td>
202
- <!-- 功能 -->
203
- <td v-if="row[2]" class="px-[1em] py-0.5em">
204
- <div class="feat-list">
168
+ <FormItemRest>
169
+ <tr v-for="(row, ri) of tableData" :key="ri">
170
+ <!-- 模块 -->
171
+ <td v-if="row[0]" class="w-[6em] px-[1em] py-0.5em" :rowspan="row[0].span">
172
+ <Checkbox
173
+ :checked="stateMap?.[row[0].id].indet ? false : stateMap?.[row[0].id].checked"
174
+ :indeterminate="stateMap?.[row[0].id].indet" @change="onCheckChange(row[0].id)"
175
+ >
176
+ {{ row[0].label }}{{ row[0].id }}
177
+ </Checkbox>
178
+ </td>
179
+ <!-- 页面 -->
180
+ <td v-if="row[1]" class="w-[9em] px-[1em] py-0.5em">
205
181
  <Checkbox
206
- v-for="fItem of row[2]" :key="fItem?.id" :checked="stateMap[fItem.id].checked"
207
- @change="onCheckChange(fItem.id)"
182
+ :checked="stateMap?.[row[1].id].indet ? false : stateMap?.[row[1].id].checked"
183
+ :indeterminate="stateMap?.[row[1].id].indet" @change="onCheckChange(row[1].id)"
208
184
  >
209
- {{ fItem.label }}
185
+ {{ row[1].label }} {{ row[1].id }}
210
186
  </Checkbox>
211
- </div>
212
- </td>
213
- </tr>
187
+ </td>
188
+ <!-- 功能 -->
189
+ <td v-if="row[2]" class="px-[1em] py-0.5em">
190
+ <div class="feat-list">
191
+ <Checkbox
192
+ v-for="fItem of row[2]" :key="fItem?.id" :checked="stateMap?.[fItem.id].checked"
193
+ @change="onCheckChange(fItem.id)"
194
+ >
195
+ {{ fItem.label }} {{ fItem.id }}
196
+ </Checkbox>
197
+ </div>
198
+ </td>
199
+ </tr>
200
+ </FormItemRest>
214
201
  </table>
215
202
  </template>
216
203
 
@@ -1 +1 @@
1
- export { default as PermissionTreeCheckbox, treeToIds } from './PermissionTree.vue';
1
+ export { default as PermissionTreeCheckbox } from './PermissionTree.vue';
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { computed, reactive } from 'vue';
2
+ import { computed } from 'vue';
3
3
  import bigNumber from 'bignumber.js';
4
4
  import isNil from 'lodash-es/isNil';
5
5
  import { CurrencyIcon } from '../../currency';
@@ -8,15 +8,6 @@ export const config = {
8
8
  aboveColor: '#52c41a',
9
9
  belowColor: '#ff4d4f',
10
10
  };
11
-
12
- /**
13
- * 当 symbol 为以下值时,使用预设的 Logo
14
- */
15
- const presetTextSymbols = reactive(['$', '¥']);
16
-
17
- export function setConfig(textSymbols: string[]) {
18
- presetTextSymbols.concat(textSymbols);
19
- }
20
11
  </script>
21
12
 
22
13
  <script setup lang="ts">
@@ -75,15 +66,10 @@ const amountColor = computed(() => {
75
66
  <div class="amount-wrapper" :style="{ '--amount-color': amountColor }">
76
67
  <!-- 约等于 -->
77
68
  <span v-if="props.approx" class="color-$amount-color">≈</span>
78
-
79
- <!-- 文本符号,如法定币种符号(¥、$) -->
80
- <span v-if="!symbol || presetTextSymbols.includes(symbol)" class="color-$amount-color">{{ symbol }}</span>
81
- <!-- 图片符号 -->
69
+ <!-- 符号 -->
82
70
  <CurrencyIcon v-else class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
83
-
84
71
  <!-- 金额 -->
85
72
  <span class="color-$amount-color amount">{{ amountText }}</span>
86
-
87
73
  <!-- 单位 -->
88
74
  <span v-if="props.unit" class="unit">{{ props.unit }}</span>
89
75
  </div>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.26",
4
+ "version": "0.2.28",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",