Skip to content

Commit e2e5722

Browse files
committed
feat(API): asset connection
1 parent bcbd05d commit e2e5722

File tree

7 files changed

+164
-24
lines changed

7 files changed

+164
-24
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@vicons/ionicons5": "^0.12.0",
1919
"axios": "^1.7.2",
20+
"crypto-js": "^4.2.0",
2021
"mitt": "^3.0.1",
2122
"naive-ui": "^2.38.2",
2223
"normalize.css": "^8.0.1",
@@ -34,6 +35,7 @@
3435
"@commitlint/cli": "^18.4.3",
3536
"@commitlint/config-conventional": "^18.4.3",
3637
"@commitlint/prompt-cli": "^19.3.1",
38+
"@types/crypto-js": "^4.2.2",
3739
"@types/node": "^20.14.9",
3840
"@typescript-eslint/eslint-plugin": "^7.1.0",
3941
"@typescript-eslint/parser": "^7.1.0",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ConnectionDialog/index.vue

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
:label-style="{ letterSpacing: '0.7px' }"
1616
>
1717
<n-select
18-
v-model:value="model.selectValue"
18+
v-model:value="model.account"
1919
size="medium"
2020
:placeholder="t('Select account')"
21-
:options="assetCount"
21+
:options="accountOptions"
2222
/>
2323
</n-form-item-gi>
2424

@@ -61,7 +61,7 @@
6161
:name="method.label"
6262
:key="methodIndex"
6363
>
64-
<n-radio-group v-model:value="model.checkedValue">
64+
<n-radio-group v-model:value="model.connect_options">
6565
<n-space>
6666
<n-radio
6767
v-for="(item, indexItem) of method.methods"
@@ -158,12 +158,16 @@ import { computed, reactive, ref } from 'vue';
158158
import { useI18n } from 'vue-i18n';
159159
import { storeToRefs } from 'pinia';
160160
import { ArrowDown, ArrowUp } from '@vicons/ionicons5';
161+
import { useUserStore } from '@/stores/modules/user.ts';
161162
import { useGlobalStore } from '@/stores/modules/global.ts';
162163
164+
// import * as CryptoJS from 'crypto-js/core';
165+
163166
const { t } = useI18n();
167+
const userStore = useUserStore();
164168
const globalStore = useGlobalStore();
165169
const { connectMethods } = storeToRefs(globalStore);
166-
170+
console.log(userStore);
167171
interface Protocol {
168172
name: string;
169173
port: number;
@@ -173,13 +177,59 @@ interface Protocol {
173177
sftp_home: string;
174178
};
175179
}
176-
177180
interface connectMethodItem {
178181
component: string;
179182
endpoint_protocol: string;
180183
label: string;
181184
type: string;
182185
value: string;
186+
disabled?: boolean;
187+
}
188+
interface ConnectData {
189+
asset?: Asset;
190+
account?: Account;
191+
protocol?: Protocol;
192+
manualAuthInfo?: AuthInfo;
193+
connectMethod?: connectMethodItem;
194+
connectOption?: Object;
195+
downloadRDP?: boolean;
196+
autoLogin?: boolean;
197+
}
198+
interface Account {
199+
alias: string;
200+
name: string;
201+
username: string;
202+
has_secret: boolean;
203+
secret: string;
204+
actions: Array<Action>;
205+
}
206+
interface Action {
207+
label: string;
208+
value: string;
209+
}
210+
interface Choice {
211+
label: string;
212+
value: string;
213+
}
214+
interface SpecInfo {
215+
db_name?: string;
216+
}
217+
interface Asset {
218+
id: string;
219+
name: string;
220+
address: string;
221+
comment: string;
222+
type: Choice;
223+
category: Choice;
224+
permed_protocols: Array<Protocol>;
225+
permed_accounts: Array<Account>;
226+
spec_info: SpecInfo;
227+
}
228+
interface AuthInfo {
229+
alias: string;
230+
username: string;
231+
secret: string;
232+
rememberAuth: boolean;
183233
}
184234
185235
const props = defineProps<{
@@ -188,45 +238,51 @@ const props = defineProps<{
188238
permedProtocols: any;
189239
}>();
190240
191-
console.log('props', props);
192-
console.log('connectMethods', connectMethods.value);
241+
const a: ConnectData = {};
242+
console.log(a);
243+
// console.log('props', props);
244+
// console.log('connectMethods', connectMethods.value);
193245
246+
const showAdvanced = ref(false);
194247
const model = reactive({
248+
account: '',
249+
asset: props.id,
250+
connect_options: '',
251+
input_username: '',
252+
protocol: '',
253+
195254
inputValue: '',
196255
selectValue: null,
197256
checkedValue: null,
198-
backspaceAsCtrlH: true
257+
backspaceAsCtrlH: 'true'
199258
});
200259
201-
const showAdvanced = ref(false);
202-
203260
const connectMethodTypes = [
204261
{ value: 'web', label: 'Web', methods: [] },
205262
{ value: 'native', label: t('Native'), methods: [] },
206263
{ value: 'applet', label: t('Applet'), methods: [] },
207264
{ value: 'virtual_app', label: t('VirtualApp'), methods: [] }
208265
];
209266
210-
const assetCount = computed(() => {
211-
//todo)) 类型
212-
const tempArr = [];
213-
props.permedAccounts.forEach((item: any) => {
214-
tempArr.push({
267+
const accountOptions = computed(() => {
268+
return props.permedAccounts.map((item: any) => {
269+
return {
215270
label: item.username,
216271
value: item.username
217-
});
272+
};
218273
});
219-
220-
return tempArr!;
221274
});
275+
276+
// console.log('accountOptions', accountOptions.value);
277+
222278
const backspaceOptions = [
223279
{
224280
label: '',
225-
value: true
281+
value: 'true'
226282
},
227283
{
228284
label: '',
229-
value: false
285+
value: 'false'
230286
}
231287
];
232288
@@ -255,7 +311,58 @@ const handleShowAdvanced = () => {
255311
showAdvanced.value = !showAdvanced.value;
256312
};
257313
258-
console.log('connectConnectTypeComputed', connectConnectTypeComputed);
314+
// const decrypt = (secret: string): string => {
315+
// const secretKey = `${userStore.id}_${userStore.username}`;
316+
//
317+
// try {
318+
// const bytes = CryptoJS.AES.decrypt(secret, secretKey);
319+
// return bytes.toString(CryptoJS.enc.Utf8);
320+
// } catch (e) {
321+
// return '';
322+
// }
323+
// };
324+
// const getAccountLocalAuth = (assetId: string, shouldDecrypt = true) => {
325+
// const key = `JMS_MA_${assetId}`;
326+
// const authString = localStorage.getItem(key);
327+
// const auth = authString ? JSON.parse(authString) : [];
328+
//
329+
// if (!auth || !Array.isArray(auth)) {
330+
// return [];
331+
// }
332+
//
333+
// return auth.map((item: AuthInfo) => {
334+
// const newAuths: AuthInfo = { ...item };
335+
//
336+
// if (shouldDecrypt && newAuths.secret) {
337+
// newAuths.secret = decrypt(newAuths.secret);
338+
// }
339+
//
340+
// return newAuths;
341+
// });
342+
// };
343+
344+
// const getPreConnectData = () => {
345+
// const key = `JMS_PRE_${props.id}`;
346+
// const connectData: ConnectData = JSON.parse(<string>localStorage.getItem(key));
347+
//
348+
// const res = getAccountLocalAuth(props.id);
349+
//
350+
// console.log(res);
351+
//
352+
// if (connectData.account.has_secret) {
353+
// return connectData;
354+
// }
355+
//
356+
// if (connectData.account) {
357+
// getAccountLocalAuth(props.id);
358+
// }
359+
//
360+
// return connectData;
361+
// };
362+
363+
// getPreConnectData();
364+
365+
// console.log('connectConnectTypeComputed', connectConnectTypeComputed);
259366
</script>
260367

261368
<style scoped lang="scss">

src/layouts/components/FileManagement/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
145145
if (id) {
146146
const res = await getTreeDetailById(id as string);
147147
148+
console.log('res', res);
149+
148150
dialog.success({
149151
showIcon: false,
150152
closeOnEsc: false,
@@ -162,7 +164,6 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
162164
}
163165
});
164166
showDialog.value = true;
165-
console.log(res);
166167
}
167168
} catch (e) {
168169
console.log(e);

src/routers/helper/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ export const guard = async (
5050
}
5151

5252
if (profileResult.status === 'fulfilled') {
53-
const { username, avatar_url, email, source } = profileResult.value;
53+
const { name, avatar_url, email, source, username, id } = profileResult.value;
54+
userStore.setUserId(id);
55+
userStore.setName(name);
5456
userStore.setEmail(email);
55-
userStore.setName(username);
57+
userStore.setUserName(username);
5658
userStore.setAvatar(avatar_url);
5759
userStore.setSource(source.label);
5860
}

src/stores/interface/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface OpenSetting {
4444
}
4545

4646
export interface UserState {
47+
id: string;
48+
4749
// 用户头像
4850
avatar_url: string;
4951

@@ -55,6 +57,8 @@ export interface UserState {
5557

5658
// 来源
5759
source: string;
60+
61+
username: string;
5862
}
5963

6064
export interface TreeState {

src/stores/modules/user.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import piniaPersistConfig from '@/stores/helper/persist';
44

55
export const useUserStore = defineStore('user', {
66
state: (): UserState => ({
7+
id: '',
78
name: '',
89
email: '',
910
source: '',
11+
username: '',
1012
avatar_url: ''
1113
}),
1214
actions: {
@@ -21,6 +23,12 @@ export const useUserStore = defineStore('user', {
2123
},
2224
setSource(source: string) {
2325
this.source = source;
26+
},
27+
setUserName(username: string) {
28+
this.username = username;
29+
},
30+
setUserId(id: string) {
31+
this.id = id;
2432
}
2533
},
2634
persist: piniaPersistConfig('user')

0 commit comments

Comments
 (0)