刘光辉
5 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<script lang="ts" setup>
import type { DropMenu } from '@jnpf/ui';
 
import { computed, unref } from 'vue';
 
import { useGo } from '@jnpf/hooks';
import { Dropdown } from '@jnpf/ui';
import { openWindow } from '@jnpf/utils';
 
import { preferences } from '@vben/preferences';
import { useUserStore } from '@vben/stores';
 
import { VbenIconButton } from '@vben-core/shadcn-ui';
 
import { Tooltip } from 'ant-design-vue';
 
import { $t } from '#/locales';
import { APP_BACKEND_PREFIX, APP_PREFIX } from '#/utils/constants';
import { getJnpfAppEnCode, getRealJnpfAppEnCode } from '#/utils/jnpf';
 
const userStore = useUserStore();
const go = useGo();
 
const getUserInfo: any = computed(() => userStore.getUserInfo || {});
const getIsBackend = computed(() => getJnpfAppEnCode() !== getRealJnpfAppEnCode());
const getShowSystemMenu = computed(() => unref(getIsBackend) || !!unref(getUserInfo).isAdministrator);
const getMenuList = computed<DropMenu[]>(() => {
  if (unref(getIsBackend)) return [{ event: 'toFrontend', text: '进入应用前台' }];
  const menuList = [{ event: 'toMain', text: '进入控制台' }];
  if (unref(getUserInfo)?.hasBackend) menuList.push({ event: 'toBackend', text: '进入应用后台' });
  return menuList;
});
 
function handleMenuEvent(menu: DropMenu) {
  let url = window.location.origin;
  if (menu.event !== 'toMain') {
    const appEnCode = getRealJnpfAppEnCode();
    url = `${url}/${APP_PREFIX + (unref(getIsBackend) ? '' : APP_BACKEND_PREFIX) + appEnCode}`;
  }
  openWindow(url);
}
 
function goHome() {
  go(preferences.app.defaultHomePath);
}
</script>
 
<template>
  <Tooltip :mouse-enter-delay="0.5" :title="$t('layout.header.tooltipNotify')" placement="bottom" />
  <Dropdown v-if="getShowSystemMenu" :drop-menu-list="getMenuList" :trigger="['hover']" placement="bottom" @menu-event="handleMenuEvent">
    <VbenIconButton class="global-header-icon ml-[-4px] w-auto rounded-md !px-[6px]">
      <i class="icon-ym icon-ym-nav-home text-foreground text-[18px]"></i>
    </VbenIconButton>
  </Dropdown>
  <Tooltip v-else :mouse-enter-delay="0.5" :title="$t('routes.basic.home', '首页')" placement="bottom">
    <VbenIconButton class="global-header-icon ml-[-4px] w-auto rounded-md !px-[6px]" @click="goHome">
      <i class="icon-ym icon-ym-nav-home text-foreground text-[18px]"></i>
    </VbenIconButton>
  </Tooltip>
</template>