<commit_before>import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import axios from '../../axios';
import queryString from 'query-string';
import { parseTime } from '../../utils/time';
import { Table, Button, Popconfirm, message, Input, Row, Col, Tag } from 'antd';
import PageHeaderWrapper from '../../components/PageHeaderWrapper';
import styles from './style.module.scss';

class Articles extends Component {
    constructor(props) {
        super(props);
        this.state = {
            articles: [],
            pagination: {},
            selectedRowKeys: [],
            loading: false,
        };
    }
    getTableColums() {
        return [
            {
                title: '缩略图',
                dataIndex: 'screenshot',
                render: (text, record) => (
                    <a href={'/blog/articles/' + record._id} className="thumbnail">
                        <img src={record.screenshot} alt="冷夜流星博客" width="100" height="60" />
                    </a>
                ),
            },
            { title: '文章标题', dataIndex: 'title' },
            {
                title: '创建时间',
                dataIndex: 'createdAt',
                render: (text, record) => parseTime(record.createdAt),
            },
            {
                title: '分类',
                dataIndex: 'category',
                width: 100,
                render: (text, record) => (record.category ? record.category.name : '未分类'),
            },
            {
                title: '浏览次数',
                dataIndex: 'viewsCount',
                width: 90,
            },
            {
                title: '评论数',
                dataIndex: 'commentCount',
                width: 90,
            },
            {
                title: '状态',
                dataIndex: 'isDraft',
                render: (text, record) =>
                    record.isDraft ? <Tag color="red">草稿</Tag> : <Tag color="green">已发布</Tag>,
            },
            {
                title: '操作',
                key: 'operation',
                width: 180,
                render: (text, record) => (
                    <div>
                        <Button
                            type="primary"
                            size="small"
                            title="编辑"
                            onClick={() => this.props.history.push('/content/articles/edit/' + record._id)}
                        >
                            <i className="fa fa-edit fa-fw"></i>
                            编辑
                        </Button>
                        ,
                        <Popconfirm
                            title="确认要删除？"
                            onConfirm={() => this.deleteArticle(record._id)}
                            okText="确定"
                            cancelText="取消"
                        >
                            <Button type="danger" size="small" title="删除">
                                <i className="fa fa-trash-o fa-fw"></i>删除
                            </Button>
                        </Popconfirm>
                    </div>
                ),
            },
        ];
    }
    deleteArticle(_id) {
        axios.delete('/articles/' + _id).then(() => {
            message.success('删除文章成功！');
            this.fetchData();
        });
    }
    batchDeleteArticle() {
        if (this.state.selectedRowKeys.length <= 0) {
            message.info('请选择要删除的文章');
            return;
        }
        axios
            .delete('/articles', {
                data: { articleIds: this.state.selectedRowKeys },
            })
            .then(res => {
                if (res && res.data && res.data.ok === 1 && res.data.deletedCount > 0) {
                    message.success('删除文章成功！');
                    return this.fetchData();
                }
                return message.error('删除文章失败，请重新尝试。');
            });
    }
    fetchData(page = 1, limit = 10) {
        this.setState({ loading: true });
        const query = {
            limit,
            page,
        };
        axios.get('/articles?' + queryString.stringify(query)).then(res => {
            const pagination = { ...this.state.pagination };
            pagination.total = res.data.totalCount;
            this.setState({
                articles: res.data.items,
                loading: false,
                pagination,
            });
        });
    }
    handleTableChange(pagination) {
        const pager = { ...this.state.pagination };
        pager.current = pagination.current;
        this.setState({
            pagination: pager,
        });
        this.fetchData(pagination.current, pagination.pageSize);
    }
    onSelectChange(selectedRowKeys) {
        this.setState({ selectedRowKeys });
    }
    componentDidMount() {
        this.fetchData();
    }
    render() {
        const { selectedRowKeys } = this.state;
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange.bind(this),
        };
        return (
            <PageHeaderWrapper title="文章列表" content="控制台----文章列表">
                <div className="main-content">
                    <div className={styles.panel}>
                        <Row type="flex" justify="space-between" className={styles.moduleControl}>
                            <Col>
                                <Button
                                    type="primary"
                                    onClick={() => this.props.history.push('/content/articles/edit')}
                                >
                                    <i className="fa fa-plus-square fa-fw">&nbsp;</i>
                                    添加文档
                                </Button>
                                <Button type="danger" onClick={() => this.batchDeleteArticle()}>
                                    <i className="fa fa-fw fa-trash-o fa-fw">&nbsp;</i>
                                    批量删除
                                </Button>
                            </Col>
                            <Col style={{ flex: '1 0 auto' }} justify="end">
                                <form action="/admin/manage/contentList" className={styles.searchForm}>
                                    <div className="search-input-group">
                                        <Row type="flex" justify="end">
                                            <Col>
                                                <Input
                                                    type="text"
                                                    name="searchKey"
                                                    placeholder="请输入需要查询的关键字"
                                                />
                                            </Col>
                                            <Col>
                                                <Button type="primary"><commit_msg>feat: add batch delete popconfirm<commit_after>import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import axios from '../../axios';
import queryString from 'query-string';
import { parseTime } from '../../utils/time';
import { Table, Button, Popconfirm, message, Input, Row, Col, Tag } from 'antd';
import PageHeaderWrapper from '../../components/PageHeaderWrapper';
import styles from './style.module.scss';

class Articles extends Component {
    constructor(props) {
        super(props);
        this.state = {
            articles: [],
            pagination: {},
            selectedRowKeys: [],
            loading: false,
        };
    }
    getTableColums() {
        return [
            {
                title: '缩略图',
                dataIndex: 'screenshot',
                render: (text, record) => (
                    <a href={'/blog/articles/' + record._id} className="thumbnail">
                        <img src={record.screenshot} alt="冷夜流星博客" width="100" height="60" />
                    </a>
                ),
            },
            { title: '文章标题', dataIndex: 'title' },
            {
                title: '创建时间',
                dataIndex: 'createdAt',
                render: (text, record) => parseTime(record.createdAt),
            },
            {
                title: '分类',
                dataIndex: 'category',
                width: 100,
                render: (text, record) => (record.category ? record.category.name : '未分类'),
            },
            {
                title: '浏览次数',
                dataIndex: 'viewsCount',
                width: 90,
            },
            {
                title: '评论数',
                dataIndex: 'commentCount',
                width: 90,
            },
            {
                title: '状态',
                dataIndex: 'isDraft',
                render: (text, record) =>
                    record.isDraft ? <Tag color="red">草稿</Tag> : <Tag color="green">已发布</Tag>,
            },
            {
                title: '操作',
                key: 'operation',
                width: 180,
                render: (text, record) => (
                    <div>
                        <Button
                            type="primary"
                            size="small"
                            title="编辑"
                            onClick={() => this.props.history.push('/content/articles/edit/' + record._id)}
                        >
                            <i className="fa fa-edit fa-fw"></i>
                            编辑
                        </Button>
                        ,
                        <Popconfirm
                            title="确认要删除？"
                            onConfirm={() => this.deleteArticle(record._id)}
                            okText="确定"
                            cancelText="取消"
                        >
                            <Button type="danger" size="small" title="删除">
                                <i className="fa fa-trash-o fa-fw"></i>删除
                            </Button>
                        </Popconfirm>
                    </div>
                ),
            },
        ];
    }
    deleteArticle(_id) {
        axios.delete('/articles/' + _id).then(() => {
            message.success('删除文章成功！');
            this.fetchData();
        });
    }
    batchDeleteArticle() {
        if (this.state.selectedRowKeys.length <= 0) {
            message.info('请选择要删除的文章');
            return;
        }
        axios
            .delete('/articles', {
                data: { articleIds: this.state.selectedRowKeys },
            })
            .then(res => {
                if (res && res.data && res.data.ok === 1 && res.data.deletedCount > 0) {
                    message.success('删除文章成功！');
                    return this.fetchData();
                }
                return message.error('删除文章失败，请重新尝试。');
            });
    }
    fetchData(page = 1, limit = 10) {
        this.setState({ loading: true });
        const query = {
            limit,
            page,
        };
        axios.get('/articles?' + queryString.stringify(query)).then(res => {
            const pagination = { ...this.state.pagination };
            pagination.total = res.data.totalCount;
            this.setState({
                articles: res.data.items,
                loading: false,
                pagination,
            });
        });
    }
    handleTableChange(pagination) {
        const pager = { ...this.state.pagination };
        pager.current = pagination.current;
        this.setState({
            pagination: pager,
        });
        this.fetchData(pagination.current, pagination.pageSize);
    }
    onSelectChange(selectedRowKeys) {
        this.setState({ selectedRowKeys });
    }
    componentDidMount() {
        this.fetchData();
    }
    render() {
        const { selectedRowKeys } = this.state;
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange.bind(this),
        };
        return (
            <PageHeaderWrapper title="文章列表" content="控制台----文章列表">
                <div className="main-content">
                    <div className={styles.panel}>
                        <Row type="flex" justify="space-between" className={styles.moduleControl}>
                            <Col>
                                <Button
                                    type="primary"
                                    onClick={() => this.props.history.push('/content/articles/edit')}
                                >
                                    <i className="fa fa-plus-square fa-fw">&nbsp;</i>
                                    添加文档
                                </Button>
                                <Popconfirm
                                    title="确认要删除？"
                                    onConfirm={() => this.batchDeleteArticle()}
                                    okText="确定"
                                    cancelText="取消"
                                >
                                    <Button type="danger">
                                        <i className="fa fa-fw fa-trash-o fa-fw">&nbsp;</i>
                                        批量删除
                                    </Button>
                                </Popconfirm>
                            </Col>
                            <Col style={{ flex: '1 0 auto' }} justify="end">
                                <form action="/admin/manage/contentList" className={styles.searchForm}>
                                    <div className="search-input-group">
                                        <Row type="flex" justify="end">
                                            <Col>
                                                <Input
                                                    type="text"
                                                    name="searchKey"
                                                    placeholder="请输入需要查询的关键字"
                                                />
                                            </Col>
                                            <Col>
                                                <Button type="primary">
{'fraction_non_alphanumeric': 0.11814405407308315, 'fraction_numerical': 0.003238752376258537, 'mean_word_length': 0.9194594594594595, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 65, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '953257', 'n_tokens_mistral': 3452, 'n_tokens_neox': 3402, 'n_words': 600}