chengkun
2025-09-05 4822304b63e1bd6327860af7f3db0133cecf167f
public/static/admin/js/blog/index.js
@@ -2,19 +2,112 @@
    mixins: [sharedMixin],/////共用的方法/////
    data() {
        return {
            list: [],
            blogList: [],
            listCount: 0,
            searchForm: {
                keyword: "",
                page: 1,
                limit: 20,
            },
            ifsubmit: false,
        };
    },
    mounted() {
    },
    created() { },
    created() {
        this.getBlogList();
    },
    methods: {
        index() {
        formatDate(time) {
            return moment(time * 1000).format("YYYY-MM-DD H:m");
        },
        /////改变状态/////
        changeBlogStatus(id) {
            let that = this;
            let url = "/admin/adminmenu/index.html"
            postRequest(url, {}).then(res => {
            let loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            let url = "/admin/blog/change_blog_status.html";
            postRequest(url, { id: id }).then(res => {
                loading.close()
                if (res.data.code == 200) {
                    that.list = res.data.list;
                    that.$message({
                        message: res.data.message,
                        type: 'success',
                        duration: 1000,
                        center: true,
                        onClose: function () {
                            that.getBlogList();
                        }
                    })
                } else {
                    that.$message({
                        message: res.data.message,
                        type: 'error',
                        duration: 2000,
                        center: true
                    });
                }
            })
        },
        /////进入编辑页面/////
        editBlog(id) {
            window.location.href = "/admin/blog/add/id/" + id + ".html";
        },
        /////删除文章/////
        deleteBlog(id) {
            let that = this;
            let loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
            });
            let url = "/admin/blog/delete_blog.html";
            postRequest(url, { id: id }).then(res => {
                loading.close()
                if (res.data.code == 200) {
                    that.$message({
                        message: res.data.message,
                        type: 'success',
                        duration: 1000,
                        center: true,
                        onClose: function () {
                            that.getBlogList();
                        }
                    })
                } else {
                    that.$message({
                        message: res.data.message,
                        type: 'error',
                        duration: 2000,
                        center: true
                    });
                }
            })
        },
        /////获取文章列表/////
        getBlogList(page = 1) {
            let that = this;
            that.searchForm.page = page;
            let loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            let url = "/admin/blog/get_blog_list.html"
            postRequest(url, that.searchForm).then(res => {
                loading.close()
                if (res.data.code == 200) {
                    that.blogList = res.data.data.list;
                    that.listCount = +res.data.data.total;
                }
            });
        },