TabBar.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { Image } from '@tarojs/components';
  4. import { Tabbar, TabbarItem } from '@antmjs/vantui';
  5. import {
  6. ROLE_INSPECTOR,
  7. ROLE_MANAGER,
  8. ROLE_ORG_USER,
  9. ROLE_ORG_MANAGER,
  10. ROLE_QUERY_PERSON,
  11. ROLE_CITIZEN
  12. } from '@/utils/user';
  13. import homeIcon from '@/assets/tabbar/page.png';
  14. import homeActiveIcon from '@/assets/tabbar/page click.png';
  15. import noticeIcon from '@/assets/tabbar/notice.png';
  16. import noticeActiveIcon from '@/assets/tabbar/notice click.png';
  17. import issueIcon from '@/assets/tabbar/release.png';
  18. import issueActiveIcon from '@/assets/tabbar/release click.png';
  19. import checkIcon from '@/assets/tabbar/evaluation.png';
  20. import checkActiveIcon from '@/assets/tabbar/evaluation click.png';
  21. import mineIcon from '@/assets/tabbar/my.png';
  22. import mineActiveIcon from '@/assets/tabbar/my click.png';
  23. const home = {
  24. name: 'home',
  25. label: '首页',
  26. icon: homeIcon,
  27. activeIcon: homeActiveIcon,
  28. page: '/pages/home/index'
  29. }
  30. const notice = {
  31. name: 'notice',
  32. label: '公告',
  33. icon: noticeIcon,
  34. activeIcon: noticeActiveIcon,
  35. page: '/pages/notice/index'
  36. }
  37. const issue = {
  38. name: 'issue',
  39. label: '发布',
  40. icon: issueIcon,
  41. activeIcon: issueActiveIcon,
  42. page: '/pages/issue/edit/index'
  43. }
  44. const check = {
  45. name: 'check',
  46. label: '测评标准',
  47. icon: checkIcon,
  48. activeIcon: checkActiveIcon,
  49. page: '/pages/checkStand/index'
  50. }
  51. const mine = {
  52. name: 'mine',
  53. label: '我的',
  54. icon: mineIcon,
  55. activeIcon: mineActiveIcon,
  56. page: '/pages/my/index'
  57. }
  58. export default (props) => {
  59. const { active = -1, className, user } = props;
  60. const tabItems = React.useMemo(() => {
  61. if (!user) return [];
  62. if (user.dutyList.indexOf(ROLE_INSPECTOR) > -1 // 督察员
  63. || user.dutyList.indexOf(ROLE_MANAGER) > -1 // 管理员
  64. ) {
  65. return [
  66. home,
  67. notice,
  68. issue,
  69. check,
  70. mine
  71. ]
  72. }
  73. if (user.dutyList.indexOf(ROLE_ORG_USER) > -1) {
  74. return [
  75. home,
  76. notice,
  77. mine,
  78. ]
  79. }
  80. return [];
  81. }, [user]);
  82. const onChange = (e) => {
  83. const url = tabItems.filter(x => x.name === e.detail)[0].page;
  84. Taro.reLaunch({ url })
  85. }
  86. return (
  87. <Tabbar
  88. activeColor="#1A7565"
  89. className={className}
  90. active={active}
  91. onChange={onChange}
  92. >
  93. {
  94. tabItems.map(item => (
  95. <TabbarItem
  96. key={item.name}
  97. name={item.name}
  98. renderIcon={
  99. <Image
  100. src={item.icon}
  101. mode="aspectFit"
  102. style="width: 30px; height: 18px;"
  103. ></Image>
  104. }
  105. renderIconActive={
  106. <Image
  107. src={item.activeIcon}
  108. mode="aspectFit"
  109. style="width: 30px; height: 18px;"
  110. ></Image>
  111. }
  112. >
  113. {item.label}
  114. </TabbarItem>
  115. ))
  116. }
  117. </Tabbar>
  118. )
  119. }