From cb332237f8e1b1a59a69da0efe0b7a101cbbe200 Mon Sep 17 00:00:00 2001 From: Tony Yang Date: Tue, 4 Jun 2019 14:44:53 +0800 Subject: [PATCH] Add author column in post list --- admin/component/post.js | 20 ++++++++++++++------ ajax/posts.php | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/admin/component/post.js b/admin/component/post.js index aca63d2..49602c8 100644 --- a/admin/component/post.js +++ b/admin/component/post.js @@ -2,7 +2,8 @@ let listData = { page: -1, limit: -1, - allPostCount: -1 + allPostCount: -1, + username: undefined }; async function fetchPost(mode, data) { @@ -10,7 +11,7 @@ method: "GET", url: "../ajax/posts.php" } - + switch (mode) { case "page": queryData.url += `?page=${data}`; @@ -73,7 +74,7 @@ var table = create('table', "ts sortable celled striped table"); let thead = create('thead'); - (["標題", "讚", "留言", "日期", "管理"]).forEach((e, _i) => { + (["標題", "作者", "讚", "留言", "日期", "管理"]).forEach((e, _i) => { let th = create('th'); th.textContent = e; thead.appendChild(th); }) @@ -82,13 +83,15 @@ var tbody = create('tbody'); for (post of data["posts"]) { let tr = create("tr"); - (["title", "likes_count", "comments_count", "time"]).forEach((e, _i) => { + (["title", "author", "likes_count", "comments_count", "time"]).forEach((e, _i) => { let td = create('td'); if (e != "title") td.classList.add("collapsing"); if (e.indexOf("count") != -1) td.classList.add("center", "aligned"); if (e == "title") { td.innerHTML = `${post[e]}`; + } else if (e == "author") { + td.innerHTML = `${post[e]}`; } else { td.textContent = post[e]; } @@ -138,7 +141,7 @@ let content = create('div', "content"); let symbol = create('div', "symbol"); let icon = create('i', `${iconName[e]} icon`); - + content.innerHTML = statTemplate.replace("{{ value }}", data[e]).replace("{{ label }}", statLabel[e]); symbol.appendChild(icon); card.appendChild(content); @@ -187,7 +190,12 @@ }); segment.appendChild(actionsContainer); doc.appendChild(segment); - doc.insertAdjacentHTML("beforeend", ` -1 ? listData["page"] : 1)}" data-navigo>返回列表`); + if (listData.username) { + var backHref = `/post/user/${listData.username}`; + } else { + var backHref = `/post/page/${(listData["page"] > -1 ? listData["page"] : 1)}`; + } + doc.insertAdjacentHTML("beforeend", `返回列表`); } function pagination(all, limit, currentPage) { diff --git a/ajax/posts.php b/ajax/posts.php index 0c7dc41..9f5dd73 100644 --- a/ajax/posts.php +++ b/ajax/posts.php @@ -84,7 +84,7 @@ if (isset($_GET['pid'])) { foreach ($post_list as $_key => $article) { $post = array( - 'username' => $article->author, + 'author' => $article->author, 'name' => $article->name, 'pid' => intval($article->pid), 'title' => $article->title,