From e2e572260ae70c23c4fd089248bfd5da4ff21ba9 Mon Sep 17 00:00:00 2001 From: zhaojisen <1301338853@qq.com> Date: Wed, 17 Jul 2024 11:54:29 +0800 Subject: [PATCH] feat(API): asset connection --- package.json | 2 + pnpm-lock.yaml | 16 ++ src/components/ConnectionDialog/index.vue | 149 +++++++++++++++--- .../components/FileManagement/index.vue | 3 +- src/routers/helper/index.ts | 6 +- src/stores/interface/index.ts | 4 + src/stores/modules/user.ts | 8 + 7 files changed, 164 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index cd536c2b..b65cd5a9 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@vicons/ionicons5": "^0.12.0", "axios": "^1.7.2", + "crypto-js": "^4.2.0", "mitt": "^3.0.1", "naive-ui": "^2.38.2", "normalize.css": "^8.0.1", @@ -34,6 +35,7 @@ "@commitlint/cli": "^18.4.3", "@commitlint/config-conventional": "^18.4.3", "@commitlint/prompt-cli": "^19.3.1", + "@types/crypto-js": "^4.2.2", "@types/node": "^20.14.9", "@typescript-eslint/eslint-plugin": "^7.1.0", "@typescript-eslint/parser": "^7.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b515edf1..3307bd6b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: axios: specifier: ^1.7.2 version: 1.7.2 + crypto-js: + specifier: ^4.2.0 + version: 4.2.0 mitt: specifier: ^3.0.1 version: 3.0.1 @@ -60,6 +63,9 @@ importers: '@commitlint/prompt-cli': specifier: ^19.3.1 version: 19.3.1(@types/node@20.14.10)(typescript@5.5.3) + '@types/crypto-js': + specifier: ^4.2.2 + version: 4.2.2 '@types/node': specifier: ^20.14.9 version: 20.14.10 @@ -632,6 +638,9 @@ packages: '@types/conventional-commits-parser@5.0.0': resolution: {integrity: sha512-loB369iXNmAZglwWATL+WRe+CRMmmBPtpolYzIebFaX4YA3x+BEfLqhUAV9WanycKI3TG1IMr5bMJDajDKLlUQ==} + '@types/crypto-js@4.2.2': + resolution: {integrity: sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==} + '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} @@ -1129,6 +1138,9 @@ packages: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} + crypto-js@4.2.0: + resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==} + css-functions-list@3.2.2: resolution: {integrity: sha512-c+N0v6wbKVxTu5gOBBFkr9BEdBWaqqjQeiJ8QvSRIJOf+UxlJh930m8e6/WNeODIK0mYLFkoONrnj16i2EcvfQ==} engines: {node: '>=12 || >=16'} @@ -3823,6 +3835,8 @@ snapshots: dependencies: '@types/node': 20.14.10 + '@types/crypto-js@4.2.2': {} + '@types/estree@1.0.5': {} '@types/katex@0.16.7': {} @@ -4390,6 +4404,8 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 + crypto-js@4.2.0: {} + css-functions-list@3.2.2: {} css-render@0.15.14: diff --git a/src/components/ConnectionDialog/index.vue b/src/components/ConnectionDialog/index.vue index 9a0d4eeb..afcefe7c 100644 --- a/src/components/ConnectionDialog/index.vue +++ b/src/components/ConnectionDialog/index.vue @@ -15,10 +15,10 @@ :label-style="{ letterSpacing: '0.7px' }" > @@ -61,7 +61,7 @@ :name="method.label" :key="methodIndex" > - + ; +} +interface Action { + label: string; + value: string; +} +interface Choice { + label: string; + value: string; +} +interface SpecInfo { + db_name?: string; +} +interface Asset { + id: string; + name: string; + address: string; + comment: string; + type: Choice; + category: Choice; + permed_protocols: Array; + permed_accounts: Array; + spec_info: SpecInfo; +} +interface AuthInfo { + alias: string; + username: string; + secret: string; + rememberAuth: boolean; } const props = defineProps<{ @@ -188,18 +238,25 @@ const props = defineProps<{ permedProtocols: any; }>(); -console.log('props', props); -console.log('connectMethods', connectMethods.value); +const a: ConnectData = {}; +console.log(a); +// console.log('props', props); +// console.log('connectMethods', connectMethods.value); +const showAdvanced = ref(false); const model = reactive({ + account: '', + asset: props.id, + connect_options: '', + input_username: '', + protocol: '', + inputValue: '', selectValue: null, checkedValue: null, - backspaceAsCtrlH: true + backspaceAsCtrlH: 'true' }); -const showAdvanced = ref(false); - const connectMethodTypes = [ { value: 'web', label: 'Web', methods: [] }, { value: 'native', label: t('Native'), methods: [] }, @@ -207,26 +264,25 @@ const connectMethodTypes = [ { value: 'virtual_app', label: t('VirtualApp'), methods: [] } ]; -const assetCount = computed(() => { - //todo)) 类型 - const tempArr = []; - props.permedAccounts.forEach((item: any) => { - tempArr.push({ +const accountOptions = computed(() => { + return props.permedAccounts.map((item: any) => { + return { label: item.username, value: item.username - }); + }; }); - - return tempArr!; }); + +// console.log('accountOptions', accountOptions.value); + const backspaceOptions = [ { label: '是', - value: true + value: 'true' }, { label: '否', - value: false + value: 'false' } ]; @@ -255,7 +311,58 @@ const handleShowAdvanced = () => { showAdvanced.value = !showAdvanced.value; }; -console.log('connectConnectTypeComputed', connectConnectTypeComputed); +// const decrypt = (secret: string): string => { +// const secretKey = `${userStore.id}_${userStore.username}`; +// +// try { +// const bytes = CryptoJS.AES.decrypt(secret, secretKey); +// return bytes.toString(CryptoJS.enc.Utf8); +// } catch (e) { +// return ''; +// } +// }; +// const getAccountLocalAuth = (assetId: string, shouldDecrypt = true) => { +// const key = `JMS_MA_${assetId}`; +// const authString = localStorage.getItem(key); +// const auth = authString ? JSON.parse(authString) : []; +// +// if (!auth || !Array.isArray(auth)) { +// return []; +// } +// +// return auth.map((item: AuthInfo) => { +// const newAuths: AuthInfo = { ...item }; +// +// if (shouldDecrypt && newAuths.secret) { +// newAuths.secret = decrypt(newAuths.secret); +// } +// +// return newAuths; +// }); +// }; + +// const getPreConnectData = () => { +// const key = `JMS_PRE_${props.id}`; +// const connectData: ConnectData = JSON.parse(localStorage.getItem(key)); +// +// const res = getAccountLocalAuth(props.id); +// +// console.log(res); +// +// if (connectData.account.has_secret) { +// return connectData; +// } +// +// if (connectData.account) { +// getAccountLocalAuth(props.id); +// } +// +// return connectData; +// }; + +// getPreConnectData(); + +// console.log('connectConnectTypeComputed', connectConnectTypeComputed);