perf: rename ad to ds

This commit is contained in:
ibuler 2025-04-07 19:10:33 +08:00
parent a45d86c568
commit 0a7704c06c
12 changed files with 97 additions and 112 deletions

View File

@ -148,6 +148,7 @@ export default {
type: Boolean, type: Boolean,
default: true default: true
}, },
// target for ad connect btn, if not has, ad account should be select one
target: { target: {
type: Object, type: Object,
default: null default: null
@ -186,7 +187,7 @@ export default {
}, },
columnsMeta: { columnsMeta: {
name: { name: {
minWidth: '120px', minWidth: '60px',
formatterArgs: { formatterArgs: {
can: () => vm.$hasPerm('accounts.view_account'), can: () => vm.$hasPerm('accounts.view_account'),
getRoute: ({ row }) => ({ getRoute: ({ row }) => ({
@ -212,15 +213,9 @@ export default {
width: '80px', width: '80px',
formatter: AccountConnectFormatter, formatter: AccountConnectFormatter,
formatterArgs: { formatterArgs: {
buttonIcon: 'fa fa-desktop',
url: '/api/v1/assets/assets/{id}',
can: () => this.currentUserIsSuperAdmin, can: () => this.currentUserIsSuperAdmin,
connectUrlTemplate: (row) => `/luna/direct_connect/${row.id}/${row.username}/${row.asset.id}/${row.asset.name}/`, connectUrlTemplate: (row) => {
setMapItem: (id, protocol) => {
this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', {
key: id,
value: protocol
})
} }
} }
}, },
@ -238,7 +233,7 @@ export default {
} }
}, },
username: { username: {
minWidth: '120px', minWidth: '60px',
formatter: function(row) { formatter: function(row) {
if (row.ad_domain) { if (row.ad_domain) {
return `${row.username}@${row.ad_domain}` return `${row.username}@${row.ad_domain}`

View File

@ -1,24 +1,32 @@
<template> <template>
<div> <div>
<el-dropdown <el-dropdown
v-if="hasPerm" :disabled="!hasPerm"
:show-timeout="500"
class="action-connect"
size="small" size="small"
trigger="hover" trigger="hover"
:show-timeout="500" type="primary"
@command="handleCommand" @command="handleProtocolConnect"
@visible-change="visibleChange" @visible-change="visibleChange"
> >
<el-button <el-button
plain plain
size="mini" size="mini"
type="primary" type="primary"
@click="handlePamConnect" @click="handleBtnConnect"
> >
<i :class="IButtonIcon" /> <i :class="iButtonIcon" />
</el-button> </el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="Title" disabled> <el-dropdown-menu v-if="!isClick" slot="dropdown">
{{ ITitleText }} <el-dropdown-item command="title" disabled>
<div v-if="getProtocolsLoading">
{{ $t('Loading') }}
</div>
<div v-else>
{{ dropdownTitle }}
</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item divided /> <el-dropdown-item divided />
<el-dropdown-item <el-dropdown-item
@ -30,16 +38,6 @@
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<el-button
v-else
plain
size="mini"
type="primary"
:disabled="!hasPerm"
>
<i :class="IButtonIcon" style="color: #fff" />
</el-button>
</div> </div>
</template> </template>
@ -50,85 +48,70 @@ export default {
name: 'AccountConnectFormatter', name: 'AccountConnectFormatter',
extends: BaseFormatter, extends: BaseFormatter,
props: { props: {
buttonIcon: { formatterArgsDefault: {
type: String, type: Object,
default: 'fa fa-desktop' default() {
}, return {
titleText: { can: () => true,
type: String, getConnectUrl: (row, protocol) => {
default: '' return `/luna/admin-connect/?
}, asset=${row.asset.id}
url: { &account=${row.id}
type: String, &protocol=${protocol}
default: '' `.replace(/\s+/g, '')
},
assetUrl: '/api/v1/assets/assets/{id}/',
buttonIcon: 'fa fa-desktop'
}
}
} }
}, },
data() { data() {
return { return {
hasPerm: false, formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs),
protocols: [] protocols: [],
isClick: false,
getProtocolsLoading: false,
dropdownTitle: this.$t('Protocols')
} }
}, },
computed: { computed: {
IButtonIcon() { iButtonIcon() {
return this.buttonIcon return this.formatterArgs.buttonIcon
}, },
ITitleText() { hasPerm() {
return this.titleText || this.$t('SelectProtocol') return this.formatterArgs.can(this.row, this.cellValue)
} }
}, },
mounted() {
this.hasPerm = this.formatterArgs.can()
},
methods: { methods: {
handleCommand(protocol) { handleProtocolConnect(protocol) {
if (protocol === 'Title') return const url = this.formatterArgs.getConnectUrl(this.row, protocol)
window.open(url, '_blank')
this.formatterArgs.setMapItem(this.row.id, protocol)
this.handleWindowOpen(this.row, protocol)
}, },
visibleChange(visible) { visibleChange(visible) {
if (visible) { if (visible) {
this.getProtocols(this.row.asset.id) this.getProtocols(this.row.asset.id)
} }
}, },
handleWindowOpen(row, protocol) { async handleBtnConnect() {
const url = this.formatterArgs.connectUrlTemplate(row) + `${protocol}` this.isClick = true
if (this.protocols === 0) {
this.$nextTick(() => { await this.getProtocols(this.row.asset.id)
window.open(url, '_blank')
})
},
async handlePamConnect() {
const protocolMap = this.$store.getters.protocolMap
if (protocolMap.has(this.row.id)) {
//
const protocol = protocolMap.get(this.row.id)
this.handleWindowOpen(this.row, protocol)
} else {
try {
const url = this.formatterArgs.url.replace('{id}', this.row.asset.id)
const res = await this.$axios.get(url)
if (res && res.protocols.length > 0) {
const protocol = res.protocols[0]
this.formatterArgs.setMapItem(this.row.id, protocol.name)
this.handleWindowOpen(this.row, protocol.name)
}
} catch (e) {
throw new Error(`Error getting protocols: ${e}`)
}
} }
if (this.protocols.length > 0) {
this.handleProtocolConnect(this.protocols[0].name)
}
setTimeout(() => {
this.isClick = false
}, 1000)
}, },
async getProtocols(assetId) { async getProtocols(assetId) {
if (this.protocols.length > 0) return
try { try {
const url = this.formatterArgs.url.replace('{id}', assetId) const url = this.formatterArgs.assetUrl.replace('{id}', assetId)
const res = await this.$axios.get(url) const res = await this.$axios.get(url)
this.protocols = res.protocols || []
// SFTP
if (res) this.protocols = res.protocols
} catch (e) { } catch (e) {
throw new Error(`Error getting protocols: ${e}`) throw new Error(`Error getting protocols: ${e}`)
} }
@ -137,7 +120,7 @@ export default {
} }
</script> </script>
<style scoped lang="scss"> <style lang="scss" scoped>
.el-dropdown-menu__item.is-disabled { .el-dropdown-menu__item.is-disabled {
font-weight: 500; font-weight: 500;
color: var(--el-text-color-secondary); color: var(--el-text-color-secondary);

View File

@ -12,7 +12,7 @@ export default {
return { return {
url: '/api/v1/assets/directories/', url: '/api/v1/assets/directories/',
addFields: [ addFields: [
[this.$t('Domain name'), ['domain_name'], 1] [this.$t('DomainName'), ['domain_name'], 1]
] ]
} }
} }

View File

@ -114,7 +114,7 @@ export default {
}, },
async genConfig() { async genConfig() {
const { addFields, addFieldsMeta, defaultConfig } = this const { addFields, addFieldsMeta, defaultConfig } = this
defaultConfig.fieldsMeta = assetFieldsMeta(this, this.$route.query.type) defaultConfig.fieldsMeta = assetFieldsMeta(this)
let url = this.url let url = this.url
const id = this.$route.params.id const id = this.$route.params.id
if (!id) { if (!id) {

View File

@ -12,7 +12,7 @@ export default {
data() { data() {
return { return {
tableConfig: { tableConfig: {
category: 'ad', category: 'ds',
url: '/api/v1/assets/directories/' url: '/api/v1/assets/directories/'
} }
} }

View File

@ -144,7 +144,7 @@ export default {
'cloud': () => import('@/views/assets/Asset/AssetCreateUpdate/CloudCreateUpdate.vue'), 'cloud': () => import('@/views/assets/Asset/AssetCreateUpdate/CloudCreateUpdate.vue'),
'device': () => import('@/views/assets/Asset/AssetCreateUpdate/DeviceCreateUpdate.vue'), 'device': () => import('@/views/assets/Asset/AssetCreateUpdate/DeviceCreateUpdate.vue'),
'database': () => import('@/views/assets/Asset/AssetCreateUpdate/DatabaseCreateUpdate.vue'), 'database': () => import('@/views/assets/Asset/AssetCreateUpdate/DatabaseCreateUpdate.vue'),
'ad': () => import('@/views/assets/Asset/AssetCreateUpdate/ADCreateUpdate.vue') 'ds': () => import('@/views/assets/Asset/AssetCreateUpdate/ADCreateUpdate.vue')
}, },
createProps: {}, createProps: {},
showPlatform: false, showPlatform: false,

View File

@ -5,7 +5,7 @@
:show-confirm="false" :show-confirm="false"
:title="$tc('SelectPlatform')" :title="$tc('SelectPlatform')"
:visible.sync="iVisible" :visible.sync="iVisible"
size="600px" size="700px"
top="1vh" top="1vh"
> >
<template #title> <template #title>
@ -61,6 +61,7 @@ import { loadPlatformIcon } from '@/utils/jms'
export default { export default {
name: 'PlatformDrawer', name: 'PlatformDrawer',
components: {},
props: { props: {
visible: { visible: {
type: Boolean, type: Boolean,

View File

@ -57,10 +57,10 @@ export default {
component: () => import('@/views/assets/Asset/AssetList/WebList.vue') component: () => import('@/views/assets/Asset/AssetList/WebList.vue')
}, },
{ {
icon: 'fa-comment', icon: 'fa-vcard-o',
name: 'ad', name: 'ds',
hidden: true, hidden: true,
component: () => import('@/views/assets/Asset/AssetList/ADList.vue') component: () => import('@/views/assets/Asset/AssetList/DSList.vue')
}, },
{ {
icon: 'fa-comment', icon: 'fa-comment',

View File

@ -50,7 +50,7 @@ export default {
]], ]],
[this.$t('Config'), [ [this.$t('Config'), [
'protocols', 'su_enabled', 'su_method', 'protocols', 'su_enabled', 'su_method',
'domain_enabled', 'ad_enabled', 'ad', 'domain_enabled', 'ds_enabled', 'ds',
'charset' 'charset'
]], ]],
[this.$t('Automations'), ['automation']], [this.$t('Automations'), ['automation']],
@ -155,16 +155,20 @@ export default {
}) })
this.fieldsMeta.protocols.el.choices = protocols this.fieldsMeta.protocols.el.choices = protocols
const fieldsCheck = ['domain_enabled', 'su_enabled', 'ad_enabled'] const fieldsCheck = ['domain_enabled', 'su_enabled']
for (const field of fieldsCheck) { for (const field of fieldsCheck) {
const disabled = constraints[field] === false const disabled = constraints[field] === false
this.initial[field] = !disabled this.initial[field] = !disabled
_.set(this.fieldsMeta, `${field}.el.disabled`, disabled) _.set(this.fieldsMeta, `${field}.el.disabled`, disabled)
} }
if (constraints['charset_enabled'] === false) { const fieldsHidden = ['charset_enabled', 'ds_enabled']
this.fieldsMeta.charset.hidden = () => true for (const field of fieldsHidden) {
if (constraints[field] === false) {
this.fieldsMeta[field].hidden = () => true
}
} }
await setAutomations(this) await setAutomations(this)
await this.updateSuMethods(constraints) await this.updateSuMethods(constraints)
} }

View File

@ -115,7 +115,11 @@ export default {
canUpdate: ({ row }) => !row.internal && vm.$hasPerm('assets.change_platform'), canUpdate: ({ row }) => !row.internal && vm.$hasPerm('assets.change_platform'),
canDelete: ({ row }) => !row.internal && vm.$hasPerm('assets.delete_platform'), canDelete: ({ row }) => !row.internal && vm.$hasPerm('assets.delete_platform'),
onUpdate({ row, col }) { onUpdate({ row, col }) {
vm.$refs.genericListTable.onUpdate({ row, col, query: { type: row.type.value, category: row.category.value }}) vm.$refs.genericListTable.onUpdate({
row,
col,
query: { type: row.type.value, category: row.category.value }
})
} }
} }
} }
@ -169,14 +173,10 @@ export default {
const types = this.$store.state.assets.assetCategoriesDropdown.filter(item => { const types = this.$store.state.assets.assetCategoriesDropdown.filter(item => {
return item.category === this.tab.activeMenu return item.category === this.tab.activeMenu
}).map(item => { }).map(item => {
if (!item.group) { if (item.group && !item.group.includes(this.$t('Type'))) {
return item item.group += this.$t('WordSep') + this.$t('Type')
} else {
return {
...item,
group: item.group + this.$t('WordSep') + this.$t('Type')
}
} }
return item
}) })
this.headerActions.moreCreates.dropdown = types this.headerActions.moreCreates.dropdown = types
}, },
@ -188,7 +188,7 @@ export default {
cloud: 'fa-cloud', cloud: 'fa-cloud',
web: 'fa-globe', web: 'fa-globe',
gpt: 'fa-comment', gpt: 'fa-comment',
ad: 'fa-comment', ds: 'fa-id-card-o',
custom: 'fa-cube' custom: 'fa-cube'
} }
const state = await this.$store.dispatch('assets/getAssetCategories') const state = await this.$store.dispatch('assets/getAssetCategories')

View File

@ -81,18 +81,18 @@ export const platformFieldsMeta = (vm) => {
disabled: false disabled: false
} }
}, },
ad_enabled: { ds_enabled: {
el: { el: {
disabled: false disabled: false
} }
}, },
ad: { ds: {
el: { el: {
multiple: false, multiple: false,
url: '/api/v1/assets/directories/', url: '/api/v1/assets/directories/',
disabled: false disabled: false
}, },
hidden: (formValue) => !formValue['ad_enabled'] hidden: (formValue) => !formValue['ds_enabled']
}, },
protocols: { protocols: {
label: i18n.t('SupportedProtocol'), label: i18n.t('SupportedProtocol'),

View File

@ -48,7 +48,9 @@ function updatePlatformProtocols(vm, platformType, updateForm, platformChanged =
}), 100) }), 100)
} }
export const assetFieldsMeta = (vm, platformType) => { export const assetFieldsMeta = (vm, category, type) => {
const platformCategory = category || vm.$route.query.category
const platformType = type || vm.$route.query.type
const platformProtocols = [] const platformProtocols = []
const secretTypes = [] const secretTypes = []
const asset = { address: 'https://jumpserver:330' } const asset = { address: 'https://jumpserver:330' }
@ -92,7 +94,7 @@ export const assetFieldsMeta = (vm, platformType) => {
el: { el: {
multiple: false, multiple: false,
ajax: { ajax: {
url: `/api/v1/assets/platforms/?type=${platformType}`, url: `/api/v1/assets/platforms/?category=${platformCategory}&type=${platformType}`,
transformOption: (item) => { transformOption: (item) => {
return { label: item.name, value: item.id } return { label: item.name, value: item.id }
} }