index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <Header :class="getHeaderClass">
  3. <!-- left start -->
  4. <div :class="`${prefixCls}-left`">
  5. <!-- logo -->
  6. <AppLogo v-if="getShowHeaderLogo || getIsMobile" :class="`${prefixCls}-logo`" :theme="getHeaderTheme"
  7. :style="getLogoWidth" />
  8. <LayoutTrigger v-if="(getShowContent && getShowHeaderTrigger && !getSplit && !getIsMixSidebar) || getIsMobile
  9. " :theme="getHeaderTheme" :sider="false" />
  10. <LayoutBreadcrumb v-if="getShowContent && getShowBread" :theme="getHeaderTheme" />
  11. </div>
  12. <!-- left end -->
  13. <!-- menu start -->
  14. <div :class="`${prefixCls}-menu`" v-if="getShowTopMenu && !getIsMobile">
  15. <LayoutMenu :isHorizontal="true" :theme="getHeaderTheme" :splitType="getSplitType" :menuMode="getMenuMode" />
  16. </div>
  17. <!-- menu-end -->
  18. <!-- action -->
  19. <div :class="`${prefixCls}-action`">
  20. <!-- <AppSearch :class="`${prefixCls}-action__item `" v-if="getShowSearch" /> -->
  21. <ErrorAction v-if="getUseErrorHandle" :class="`${prefixCls}-action__item error-action`" />
  22. <Notify v-if="getShowNotice" :class="`${prefixCls}-action__item notify-item`" />
  23. <HelpDoc />
  24. <div class="header-tips">
  25. <div @click="openTips" class="tips-icon">
  26. <div class="icon"></div>
  27. <div class="msg-num">{{ tipsNum }}</div>
  28. </div>
  29. <div id="tips-container" class="tips-container" v-show="ifShowTips"></div>
  30. </div>
  31. <!-- <SettingDrawer v-if="getShowSetting" :class="`${prefixCls}-action__item`" /> -->
  32. <div class="header-setting" @click="gotoSysManage">
  33. <img :src="settingImg" style="width: 26px;height: 26px;">
  34. </div>
  35. <!-- <AppLocalePicker v-if="getShowLocalePicker" :reload="true" :showText="false" :class="`${prefixCls}-action__item`" /> -->
  36. <AppLocalePicker v-if="getShowLocalePicker" :reload="true" :showText="false"/>
  37. <UserDropDown :theme="getHeaderTheme" />
  38. <img :src="outSys" alt="" srcset="" class="outSys" @click="outSysWay">
  39. <FullScreen v-if="getShowFullScreen" :class="`${prefixCls}-action__item fullscreen-item`" />
  40. </div>
  41. </Header>
  42. </template>
  43. <script lang="ts">
  44. import { defineComponent, ref, unref, computed, onMounted, watch, onBeforeUnmount } from 'vue';
  45. import { propTypes } from '/@/utils/propTypes';
  46. import { Layout } from 'ant-design-vue';
  47. import { AppLogo } from '/@/components/Application';
  48. import LayoutMenu from '../menu/index.vue';
  49. import LayoutTrigger from '../trigger/index.vue';
  50. import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  51. import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  52. import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  53. import { useUserStore } from '/@/store/modules/user';
  54. import { useAppStore } from '/@/store/modules/app';
  55. import { useRouter } from 'vue-router';
  56. import { MenuModeEnum, MenuSplitTyeEnum } from '/@/enums/menuEnum';
  57. import { SettingButtonPositionEnum } from '/@/enums/appEnum';
  58. import { AppLocalePicker } from '/@/components/Application';
  59. import { UserDropDown, LayoutBreadcrumb, FullScreen, Notify, ErrorAction } from './components';
  60. import { useAppInject } from '/@/hooks/web/useAppInject';
  61. import { useDesign } from '/@/hooks/web/useDesign';
  62. import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  63. import { useLocale } from '/@/locales/useLocale';
  64. import HelpDoc from './components/HelpDoc.vue';
  65. import outSys from "/@/assets/images/outSys.svg";
  66. import Tips from '/@/views/tips/index.vue';
  67. import { createApp } from 'vue';
  68. import settingImg from '/@/assets/images/headerSet.svg';
  69. import eventBus from '/@/utils/eventBus';
  70. import { getSmsByUserId } from '/@/api/sys/tips';
  71. export default defineComponent({
  72. name: 'LayoutHeader',
  73. components: {
  74. Header: Layout.Header,
  75. AppLogo,
  76. LayoutTrigger,
  77. LayoutBreadcrumb,
  78. LayoutMenu,
  79. UserDropDown,
  80. AppLocalePicker,
  81. FullScreen,
  82. Notify,
  83. ErrorAction,
  84. SettingDrawer: createAsyncComponent(() => import('/@/layouts/default/setting/index.vue'), {
  85. loading: true,
  86. }),
  87. HelpDoc,
  88. },
  89. props: {
  90. fixed: propTypes.bool,
  91. },
  92. setup(props) {
  93. const smsTimer = ref(null)
  94. const { prefixCls } = useDesign('layout-header');
  95. const {
  96. getShowTopMenu,
  97. getShowHeaderTrigger,
  98. getSplit,
  99. getIsMixMode,
  100. getMenuWidth,
  101. getIsMixSidebar,
  102. } = useMenuSetting();
  103. const { getUseErrorHandle, getShowSettingButton, getSettingButtonPosition } =
  104. useRootSetting();
  105. const {
  106. getHeaderTheme,
  107. getShowFullScreen,
  108. getShowNotice,
  109. getShowContent,
  110. getShowBread,
  111. getShowHeaderLogo,
  112. getShowHeader,
  113. getShowSearch,
  114. } = useHeaderSetting();
  115. const router = useRouter();
  116. const gotoSysManage = () => {
  117. router.push('/system/structure');
  118. eventBus.emit('userSysRemove');
  119. }
  120. const { getShowLocalePicker } = useLocale();
  121. const { getIsMobile } = useAppInject();
  122. const getHeaderClass = computed(() => {
  123. const theme = unref(getHeaderTheme);
  124. return [
  125. prefixCls,
  126. {
  127. [`${prefixCls}--fixed`]: props.fixed,
  128. [`${prefixCls}--mobile`]: unref(getIsMobile),
  129. [`${prefixCls}--${theme}`]: theme,
  130. },
  131. ];
  132. });
  133. const getShowSetting = ref(true)
  134. // const getShowSetting = computed(() => {
  135. // if (!unref(getShowSettingButton)) {
  136. // return false;
  137. // }
  138. // const settingButtonPosition = unref(getSettingButtonPosition);
  139. // if (settingButtonPosition === SettingButtonPositionEnum.AUTO) {
  140. // return unref(getShowHeader);
  141. // }
  142. // return settingButtonPosition === SettingButtonPositionEnum.HEADER;
  143. // });
  144. const getLogoWidth = computed(() => {
  145. if (!unref(getIsMixMode) || unref(getIsMobile)) {
  146. return {};
  147. }
  148. const width = unref(getMenuWidth) < 180 ? 280 : unref(getMenuWidth);//sjl,之前是180,
  149. return { width: `${width}px` };
  150. });
  151. const getSplitType = computed(() => {
  152. return unref(getSplit) ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE;
  153. });
  154. const getMenuMode = computed(() => {
  155. return unref(getSplit) ? MenuModeEnum.HORIZONTAL : null;
  156. });
  157. const userStore = useUserStore();
  158. function outSysWay() {
  159. userStore.confirmLoginOut();
  160. }
  161. const appStore = useAppStore();
  162. const ifShowTips = ref(appStore.tipsShowFlag)
  163. const tipsNum = ref('0')
  164. const getSmsNum = () => {
  165. let params = {
  166. keyStr: "",
  167. page: 1,
  168. rows: 1000000
  169. }
  170. //消息接口循环
  171. getSmsByUserId(params).then(res => {
  172. if (res.datas?.records?.length) {
  173. let todoNum = 0;
  174. let msgNum = 0;
  175. res.datas.records.forEach(item => {
  176. // 待办
  177. if (item.message.indexOf('请及时处理') > -1) {
  178. todoNum += 1
  179. }
  180. // 消息
  181. else {
  182. item.status == 0 && (msgNum += 1)
  183. }
  184. })
  185. let totalNum = todoNum + msgNum
  186. tipsNum.value = totalNum <= 99 ? totalNum === 0 ? '0' : totalNum + '' : `99+`
  187. }
  188. })
  189. }
  190. watch(
  191. () => appStore.tipsShowFlag,
  192. (val) => {
  193. ifShowTips.value = val
  194. if (val) {
  195. smsTimer.value && clearInterval(smsTimer.value)
  196. smsTimer.value = null
  197. } else {
  198. getSmsNum()
  199. smsTimer.value = setInterval(() => {
  200. // getSmsNum()
  201. }, 5000)
  202. }
  203. },
  204. {
  205. immediate: true
  206. }
  207. )
  208. // watch(
  209. // () => appStore.tipsTotalNum,
  210. // (val) => {
  211. // tipsNum.value = val
  212. // },
  213. // {
  214. // immediate: true
  215. // }
  216. // )
  217. const openTips = () => {
  218. appStore.setTipsShowFlag(!ifShowTips.value)
  219. }
  220. onMounted(() => {
  221. const tips = createApp(Tips)
  222. // 挂载消息提示组件
  223. tips.mount('#tips-container')
  224. })
  225. onBeforeUnmount(() => {
  226. smsTimer.value && clearInterval(smsTimer.value)
  227. smsTimer.value = null
  228. })
  229. return {
  230. settingImg,
  231. appStore,
  232. ifShowTips,
  233. tipsNum,
  234. openTips,
  235. outSysWay,
  236. outSys,
  237. prefixCls,
  238. getHeaderClass,
  239. getShowHeaderLogo,
  240. getHeaderTheme,
  241. getShowHeaderTrigger,
  242. getIsMobile,
  243. getShowBread,
  244. getShowContent,
  245. getSplitType,
  246. getSplit,
  247. getMenuMode,
  248. getShowTopMenu,
  249. getShowLocalePicker,
  250. getShowFullScreen,
  251. getShowNotice,
  252. getUseErrorHandle,
  253. getLogoWidth,
  254. getIsMixSidebar,
  255. getShowSettingButton,
  256. getShowSetting,
  257. getShowSearch,
  258. gotoSysManage
  259. };
  260. },
  261. });
  262. </script>
  263. <style lang="less">
  264. @import './index.less';
  265. .outSys {
  266. cursor: pointer;
  267. border-left: solid 1px #74AFEA;
  268. padding-left: 15px;
  269. padding-right: 15px;
  270. margin-left: 6px;
  271. }
  272. </style>
  273. <style lang="less" scoped>
  274. .header-tips {
  275. height: 48px;
  276. width: 48px;
  277. // margin: 0 10px 0;
  278. overflow: hidden;
  279. font-size: 12px;
  280. cursor: pointer;
  281. &:hover {
  282. background-color: #1580ec;
  283. }
  284. .tips-icon {
  285. position: relative;
  286. height: 48px;
  287. width: 48px;
  288. .icon {
  289. position: absolute;
  290. left: 50%;
  291. top: 50%;
  292. transform: translate(-50%, -50%);
  293. width: 26px;
  294. height: 26px;
  295. background: url('/@/assets/images/tip-in-header.png') no-repeat;
  296. background-size: 100% 100%;
  297. }
  298. .msg-num {
  299. position: absolute;
  300. top: 4px;
  301. right: 0px;
  302. // width: 25px;
  303. min-width: 15px;
  304. // height: 23px;
  305. color: #fff;
  306. background-color: #f72a2a;
  307. font-family: Source Han Sans CN;
  308. font-size: 12px;
  309. line-height: 15px;
  310. text-align: center;
  311. border-radius: 10px;
  312. border: 1px solid #fff;
  313. box-sizing: border-box;
  314. }
  315. }
  316. .tips-container {
  317. transform: translate(-50%, 0);
  318. position: absolute;
  319. z-index: 9999;
  320. }
  321. }
  322. .header-setting {
  323. height: 48px;
  324. width: 48px;
  325. // margin: 0 10px 0;
  326. cursor: pointer;
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. &:hover {
  331. background-color: #1580ec;
  332. }
  333. }
  334. </style>