NoticeActionItem.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { defineComponent } from 'vue';
  2. import { Popover, Tabs } from 'ant-design-vue';
  3. import NoticeList from './NoticeList';
  4. import { NoticeTabItem, NoticeListItem, noticeTabListData, noticeListData } from './data';
  5. import './index.less';
  6. const prefixCls = 'notice-popover';
  7. export default defineComponent({
  8. name: 'NoticePopover',
  9. props: {
  10. visible: {
  11. type: Boolean,
  12. default: false,
  13. },
  14. },
  15. setup(props, { attrs }) {
  16. // 渲染卡片内容
  17. function renderContent() {
  18. return (
  19. <Tabs class={`${prefixCls}__tabs`}>
  20. {() => {
  21. return noticeTabListData.map((item: NoticeTabItem) => {
  22. const { key, name } = item;
  23. return (
  24. <Tabs.TabPane key={key} tab={renderTab(key, name)}>
  25. {() => <NoticeList list={getListData(key)} />}
  26. </Tabs.TabPane>
  27. );
  28. });
  29. }}
  30. </Tabs>
  31. );
  32. }
  33. // tab标题渲染
  34. function renderTab(key: string, name: string) {
  35. const list = getListData(key);
  36. const unreadlist = list.filter((item: NoticeListItem) => !item.read);
  37. return (
  38. <div>
  39. {name}
  40. {unreadlist.length > 0 && <span>({unreadlist.length})</span>}
  41. </div>
  42. );
  43. }
  44. // 获取数据
  45. function getListData(type: string) {
  46. return noticeListData.filter((item: NoticeListItem) => item.type === type);
  47. }
  48. return () => {
  49. const { visible } = props;
  50. return (
  51. <Popover
  52. title=""
  53. {...{
  54. ...attrs,
  55. visible,
  56. }}
  57. content={renderContent}
  58. class={prefixCls}
  59. />
  60. );
  61. };
  62. },
  63. });