gtsoft-snail-job-admin/src/layouts/modules/namespace-select/index.vue

56 lines
1.4 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2024-04-10 10:29:36 +08:00
import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
2024-04-10 10:29:36 +08:00
import { $t } from '@/locales';
import { localStg } from '@/utils/storage';
2024-04-10 10:29:36 +08:00
import { useAppStore } from '@/store/modules/app';
const router = useRouter();
2024-04-10 10:29:36 +08:00
const appStore = useAppStore();
const namespaceId = ref<string>(localStg.get('namespaceId')!);
const userInfo = localStg.get('userInfo');
2024-04-10 10:29:36 +08:00
const selectOptions = computed(() =>
userInfo?.namespaceIds.map(item => {
return { label: item.name, value: item.uniqueId };
})
);
2024-04-10 10:29:36 +08:00
const dropOptions = computed(() =>
userInfo?.namespaceIds.map(item => {
return { label: item.name, key: item.uniqueId };
})
);
const onChange = (value: string) => {
2024-04-10 10:29:36 +08:00
namespaceId.value = value;
localStg.set('namespaceId', value);
2024-03-22 11:22:07 +08:00
router.go(0);
};
</script>
<template>
2024-04-10 10:29:36 +08:00
<NDropdown v-if="appStore.isMobile" :value="namespaceId" :options="dropOptions" trigger="hover" @select="onChange">
<div>
2024-04-23 14:31:09 +08:00
<ButtonIcon :tooltip-content="$t('icon.namespace')" tooltip-placement="left">
2024-04-10 10:29:36 +08:00
<SvgIcon icon="oui:app-spaces" />
</ButtonIcon>
</div>
</NDropdown>
<NSelect
v-else
v-model:value="namespaceId"
class="namespace-select"
:options="selectOptions"
@update:value="onChange"
/>
</template>
<style lang="scss" scoped>
.namespace-select {
width: 150px;
:deep(.n-base-selection) {
border-radius: 32px !important;
}
}
</style>