index.js 3.14 KB
Newer Older
wanli's avatar
wanli committed
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
import './index.less'
import { Badge, Popover, Icon, Spin, Tabs } from "ant-design-vue";
import classNames from "classnames";
import List from './NoticeList';
const { TabPane } = Tabs
const NoticeIcon = {
    props: ["className", "count", "bell", "locale", "loading"],
    methods: {
        classNames,
        onClear(e) {
            // console.log(e);
            this.$emit('clear',e);
        },
        onTabChange(e) {
            this.$emit('tabChange', e);
        },
        onPopupVisibleChange(e) {
            this.$emit('popupVisibleChange', e);
        },
        onItemClick(item, tabProps) {
            console.log(item);
            this.$emit('itemClick', item, tabProps);
        },
        getNotificationBox() {
            const { $slots, locale = {
                emptyText: '暂无数据',
                clear: '清空',
            }, loading = false } = this;
            const children = $slots.default;
            if (!children) {
                return null;
            }
            const panes = children.map(child => {
                const { list, title, emptyText, emptyImage = 'https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg' } = child.data.attrs
                const tab = list && list.length > 0 ? `${title} (${list.length})` : title
                return (
                    <TabPane tab={tab} key={title}>
                        <List
                            data={list}
                            onClick={item => this.onItemClick(item, child.data.attrs)}
                            onClear={() => this.onClear(title)}
                            title={title}
                            locale={locale}
                            emptyText={emptyText}
                            emptyImage={emptyImage}
                        />
                    </TabPane>
                )
            })
            return (
                <Spin spinning={loading} delay={0}>
                    <Tabs class="tabs" onChange={this.onTabChange}>
                        {panes}
                    </Tabs>
                </Spin>
            )
        }
    },
    render() {
        const { className, bell, count, onPopupVisibleChange } = this
        const noticeButtonClass = classNames(className, 'noticeButton');
        const NoticeBellIcon = bell || <Icon type="bell" class="icon" />;
        const trigger = (
            <span class={noticeButtonClass}>
                <Badge count={count} style={{ boxShadow: 'none' }} class="badge">
                    {NoticeBellIcon}
                </Badge>
            </span>
        );
        const notificationBox = this.getNotificationBox();
        if (!notificationBox) {
            return trigger;
        }
        return (
            <Popover
                placement="bottomRight"
                content={notificationBox}
                overlayClassName="ai-notice-popover"
                trigger="click"
                arrowPointAtCenter={true}
                // popupAlign={popupAlign}
                onVisibleChange={onPopupVisibleChange}
            >
                {trigger}
            </Popover>
        )
    }
}

NoticeIcon.Tab = TabPane

export default NoticeIcon