|
| 1 | +<script setup lang="ts"> |
| 2 | +type Site = 'cn' | 'intl' |
| 3 | +interface ItemProps { |
| 4 | + value: Site |
| 5 | + label: string |
| 6 | + description: string |
| 7 | + to: string |
| 8 | +} |
| 9 | +
|
| 10 | +const { t, locale } = useI18n() |
| 11 | +const { docsUrl, docsIntl } = useRuntimeConfig().public |
| 12 | +const langPrefix = locale.value === 'cn' ? '/cn' : '' |
| 13 | +const items = computed<ItemProps[]>(() => [ |
| 14 | + { |
| 15 | + value: 'cn', |
| 16 | + label: t('sites.cn.label'), |
| 17 | + description: t('sites.cn.description'), |
| 18 | + to: docsUrl as string |
| 19 | + }, |
| 20 | + { |
| 21 | + value: 'intl', |
| 22 | + label: t('sites.intl.label'), |
| 23 | + description: t('sites.intl.description'), |
| 24 | + to: docsIntl as string |
| 25 | + } |
| 26 | +]) |
| 27 | +const value = ref<Site>(isIntl() ? 'intl' : 'cn') |
| 28 | +const selected = computed<ItemProps | undefined>(() => items.value.find(item => item.value === value.value)) |
| 29 | +
|
| 30 | +function onClick(item: ItemProps) { |
| 31 | + if (item.value === value.value) { |
| 32 | + return |
| 33 | + } |
| 34 | + value.value = item.value |
| 35 | + navigateTo(`${item.to}${langPrefix}/?site=${item.value}`, { external: true }) |
| 36 | +} |
| 37 | +</script> |
| 38 | + |
| 39 | +<template> |
| 40 | + <UPopover |
| 41 | + mode="hover" |
| 42 | + :content="{ |
| 43 | + align: 'start' |
| 44 | + }" |
| 45 | + :ui="{ |
| 46 | + content: 'min-w-46 p-2 bg-[#192337] border-1 border-white/10' |
| 47 | + }" |
| 48 | + > |
| 49 | + <button |
| 50 | + class="group flex items-center h-7 px-2.5 space-x-1.5 text-[#E2E8F0] text-xs font-medium cursor-pointer border border-slate-600 rounded-md hover:border-slate-100 data-[state=open]:border-slate-100" |
| 51 | + > |
| 52 | + <UIcon |
| 53 | + name="i-ri-earth-line" |
| 54 | + class="size-4" |
| 55 | + /> |
| 56 | + <span>{{ selected?.label }}</span> |
| 57 | + </button> |
| 58 | + <template #content> |
| 59 | + <div |
| 60 | + v-for="item in items" |
| 61 | + :key="item.value" |
| 62 | + class="flex flex-col gap-0.5 p-1.5 hover:bg-white/10 rounded-md cursor-pointer" |
| 63 | + @click="onClick(item)" |
| 64 | + > |
| 65 | + <span class="text-sm leading-5 text-slate-50">{{ item.label }}</span> |
| 66 | + <span class="text-sm leading-5 text-[#6A7584]">{{ item.description }}</span> |
| 67 | + </div> |
| 68 | + </template> |
| 69 | + </UPopover> |
| 70 | +</template> |
0 commit comments