import { Tag, Space, Badge, Modal, Select, Avatar as AntdAvatar } from 'antd'; import React, { useCallback, useEffect, useState } from 'react'; import { useModel } from 'umi'; import Avatar from './AvatarDropdown'; import styles from './index.less'; import { exitFullScreen, requestFullScreen, isFull } from '@/utils/fullScreen' import { BellOutlined, UserOutlined } from '@ant-design/icons'; import { getAppListApi } from '@/services/iaaData'; import { useAjax } from '@/Hook/useAjax'; export type SiderTheme = 'light' | 'dark'; const GlobalHeaderRight: React.FC<{}> = () => { const [left, setLeft] = useState(0) const { initialState, setInitialState } = useModel('@@initialState'); const { state: { versionsOpen }, dispatch, getversions } = useModel('useOperating.useWxGroupList') if (!initialState || !initialState.settings) { return null; } const [appList, setApplist] = useState<{ label: string, value: string, productType: string; mediaPlatform: string; icon?: string }[]>([]) const getAppList = useAjax(() => getAppListApi()) const [productTypeList, setProductTypeList] = useState<{ label: string, value: string }[]>([]) const [mediaPlatformList, setMediaPlatformList] = useState<{ label: string, value: string }[]>([]) const [productType, setProductType] = useState() const [isJr, setIsJr] = useState(false) const haveTo = (type: 'MEDIA_PLATFORM_TENCENT' | 'MEDIA_PLATFORM_OCENAENGINE') => { let menus = initialState?.menu?.data?.find((item: { path: string; }) => item.path === "/iaaData")?.routes const firstTencent = menus?.find((item: { path: string; }) => item.path === "/iaaData/tencentIaa")?.routes?.[0]?.path const firstOcenaengine = menus?.find((item: { path: string; }) => item.path === "/iaaData/ocenaengineIaa")?.routes?.[0]?.path switch (type) { case 'MEDIA_PLATFORM_TENCENT': if (!location.hash.includes('tencentIaa')) { window.location.href = `/#${firstTencent}` } break case 'MEDIA_PLATFORM_OCENAENGINE': if (!location.hash.includes('ocenaengineIaa')) { window.location.href = `/#${firstOcenaengine}` } break } } useEffect(() => { if (location.hash.includes('/iaaSystem')) { setIsJr(() => true) } }, [location.hash]) useEffect(() => { if (location.hash.includes('/iaaData') && !isJr) { setIsJr(() => true) getAppList.run().then(res => { if (res?.data) { let menus = initialState?.menu?.data?.find((item: { path: string; }) => item.path === "/iaaData")?.routes const firstTencent = menus?.find((item: { path: string; }) => item.path === "/iaaData/tencentIaa")?.routes?.[0]?.path const firstOcenaengine = menus?.find((item: { path: string; }) => item.path === "/iaaData/ocenaengineIaa")?.routes?.[0]?.path const productTypeSet = new Set(); const mediaPlatformSet = new Set(); const data: { label: string, value: string, productType: string; mediaPlatform: string; icon?: string }[] = res?.data?.filter((item: { mediaPlatform: string; }) => (firstTencent && item.mediaPlatform === 'MEDIA_PLATFORM_TENCENT') || (firstOcenaengine && item.mediaPlatform === 'MEDIA_PLATFORM_OCENAENGINE'))?.map((item: { name: string; id: number; productType: string; mediaPlatform: string; icon?: string }) => { productTypeSet.add(item.productType) mediaPlatformSet.add(item.mediaPlatform) return { label: item.name, value: item.id + '||' + item.productType, productType: item.productType, mediaPlatform: item.mediaPlatform, icon: item.icon } }) if (data?.length) { setProductTypeList([{ label: '游戏业务', value: 'PRODUCT_TYPE_GAME' }, { label: '小说业务', value: 'PRODUCT_TYPE_NOVEL' }, { label: '短剧业务', value: 'PRODUCT_TYPE_PLAYLET' }].filter(item => [...productTypeSet].includes(item.value))) setMediaPlatformList([{ label: '腾讯', value: 'MEDIA_PLATFORM_TENCENT' }, { label: '头条', value: 'MEDIA_PLATFORM_OCENAENGINE' }].filter(item => [...mediaPlatformSet].includes(item.value))) const app = initialState?.iaaApp let iaaApp: string; let mediaPlatform: string; const d = data.find(item => item.value === app) if (app && d) { iaaApp = app mediaPlatform = d.mediaPlatform } else { iaaApp = data?.[0].value || undefined as any mediaPlatform = data?.[0].mediaPlatform || undefined as any } const productType = iaaApp ? iaaApp.split('||')?.[1] : undefined haveTo(mediaPlatform as any) sessionStorage.setItem('mediaPlatform', mediaPlatform) setProductType(productType) setInitialState({ ...initialState, iaaApp, mediaPlatform }) setApplist(data) } } }) } }, [location.hash, isJr]) useEffect(() => { setTimeout(() => { let nav: any = document.querySelector('.top-nav-menu') let navLi: any = document.querySelectorAll('.top-nav-menu > li') if (nav && navLi) { let l = nav.offsetLeft let lw = 0 for (const iterator of navLi) { lw += iterator.offsetWidth } setLeft(l + lw - 50) } }, 30) }, []) const { navTheme, layout } = initialState.settings; let className = styles.right; if ((navTheme === 'dark' && layout === 'top') || layout === 'mix') { className = `${styles.right} ${styles.dark}`; } let handleFullScreen = () => { if (isFull()) { exitFullScreen() } else { requestFullScreen() } } //消息弹窗更新 const inform = useCallback(() => { let bdVersions = localStorage.getItem('versions') //本地 getversions.run().then((res) => { let fwqVersions = ''//服务器版本 let content: any = ''//版本更新内容 if (res) { fwqVersions = res?.configValue content =
') }}>
if (fwqVersions && bdVersions !== fwqVersions) {//不一样 //执行逻辑 Modal.confirm({ title: '版本更新!', content, keyboard: false, cancelText: '稍后我自己刷新页面', okText: '现在就去刷新页面', onOk: () => { localStorage.setItem('versions', fwqVersions)//重新设置服务器版本 location?.reload() }, onCancel: () => { dispatch({ type: 'versionsOpen', params: { versionsOpen: true } }) } }) console.log('不一样') } } }) }, []) return (
{location.hash.includes('/iaaData') &&
(option?.label as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0 } onChange={(type) => { let newApplist = appList.filter(item => item.productType === productType).filter(item => item.mediaPlatform === type) sessionStorage.setItem('mediaPlatform', type) haveTo(type as any) setInitialState({ ...initialState, iaaApp: newApplist?.[0]?.value, mediaPlatform: type }) }} value={initialState?.mediaPlatform} options={mediaPlatformList} />
} {versionsOpen &&
} 全屏模式
); }; export default GlobalHeaderRight;