diff --git a/src/main/kotlin/team8/fruitable/controller/action/ItemEditor.kt b/src/main/kotlin/team8/fruitable/controller/action/ItemEditor.kt new file mode 100644 index 0000000..ba86270 --- /dev/null +++ b/src/main/kotlin/team8/fruitable/controller/action/ItemEditor.kt @@ -0,0 +1,9 @@ +package team8.fruitable.controller.action + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping + +@Controller +@RequestMapping("/action/edit/item") +class ItemEditor { +} diff --git a/src/main/kotlin/team8/fruitable/controller/action/UserEditor.kt b/src/main/kotlin/team8/fruitable/controller/action/UserEditor.kt new file mode 100644 index 0000000..f78265e --- /dev/null +++ b/src/main/kotlin/team8/fruitable/controller/action/UserEditor.kt @@ -0,0 +1,9 @@ +package team8.fruitable.controller.action + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping + +@Controller +@RequestMapping("/action/edit/user") +class UserEditor { +} diff --git a/src/main/kotlin/team8/fruitable/controller/page/Editor.kt b/src/main/kotlin/team8/fruitable/controller/page/Editor.kt new file mode 100644 index 0000000..6100525 --- /dev/null +++ b/src/main/kotlin/team8/fruitable/controller/page/Editor.kt @@ -0,0 +1,89 @@ +package team8.fruitable.controller.page + +import org.springframework.data.domain.PageRequest +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.ui.set +import org.springframework.web.bind.annotation.CookieValue +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.servlet.mvc.support.RedirectAttributes +import team8.fruitable.controller.util.Util +import team8.fruitable.datebase.entity.User +import team8.fruitable.datebase.repository.AccountRepository +import team8.fruitable.datebase.repository.PagebleAccountRepository + + +@Controller +class Editor( + private val accountRepository: AccountRepository, + private val pagebleAccountRepository: PagebleAccountRepository +) { + private fun getCurrentUser(token: String?): User? { + return token?.let(accountRepository::findByToken) + } + + private fun hasAdminPermissions(user: User?): Boolean { + return user?.isAdmin ?: false + } + + private fun hasAdminPermissions(token: String?): Boolean { + return this.hasAdminPermissions(this.getCurrentUser(token)) + } + + private final val editorTabs: Array> = arrayOf( + "user" to "用户", + "item" to "商品" + ) + + private final val editorSearchTypesForUser: Array> = arrayOf( + "ALL" to "全部", + "ID" to "ID", + "NAME" to "名称", + "CREATE_DATE" to "注册时间", + "LAST_LOGIN_DATE" to "最后登录时间", + "AGE" to "年龄", + "GENDER" to "性别", + "PHONE" to "手机号码", + "EMAIL" to "邮箱", + "ADDRESS" to "地址", + "IS_ADMIN" to "管理员状态" + ) + + private final val editorSearchTypesForItem: Array> = arrayOf( + "ALL" to "全部", + "ID" to "ID", + "NAME" to "名称", + "DESCRIPTION" to "描述", + "PRICE" to "价格" + ) + + @RequestMapping("/editor") + fun editor( + model: Model, + attributes: RedirectAttributes, + @CookieValue("TOKEN", required = false) token: String?, + @RequestParam("use", defaultValue = "user") use: String, + @RequestParam("search_type", required = false) searchType: String?, + @RequestParam("search_content", required = false) searchContent: String?, + @RequestParam("page", required = false) page: Int?, + ): String { + val user = this.getCurrentUser(token) ?: return Util.error(attributes, "更新", "账户未登录", "/login") + if (!this.hasAdminPermissions(user)) return Util.error(attributes, "编辑", "账户无权限编辑网站") + model["tabs"] = editorTabs + if (searchContent != null) model["searching"] = searchContent + when (use) { + "item" -> { + model["useItemEditor"] = true + model["selects"] = editorSearchTypesForItem + } + + else -> { + model["useUserEditor"] = true + model["selects"] = editorSearchTypesForUser + model["data"] = pagebleAccountRepository.findAll(PageRequest.of(page ?: 0, 10)) + } + } + return "editor" + } +} \ No newline at end of file diff --git a/src/main/kotlin/team8/fruitable/controller/page/Pages.kt b/src/main/kotlin/team8/fruitable/controller/page/Pages.kt index dd95415..ae41598 100644 --- a/src/main/kotlin/team8/fruitable/controller/page/Pages.kt +++ b/src/main/kotlin/team8/fruitable/controller/page/Pages.kt @@ -5,6 +5,7 @@ import org.springframework.ui.Model import org.springframework.ui.set import org.springframework.web.bind.annotation.CookieValue import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.servlet.mvc.support.RedirectAttributes import team8.fruitable.controller.util.Util.Companion.error import team8.fruitable.datebase.entity.User @@ -16,10 +17,6 @@ class Pages(private val repository: AccountRepository) { return token?.let(repository::findByToken) } - private fun hasAdminPermissions(token: String?): Boolean { - return this.getCurrentUser(token)?.isAdmin ?: false - } - @RequestMapping("/") fun index( model: Model, @@ -59,7 +56,7 @@ class Pages(private val repository: AccountRepository) { model["isAccount"] = true val user = this.getCurrentUser(token) ?: return error(attributes, "更新", "账户未登录", "/login") when (user.gender) { - "M"-> model["isGenderAsMale"] = true + "M" -> model["isGenderAsMale"] = true "F" -> model["isGenderAsFemale"] = true else -> model["isGenderAsUnknown"] = true } diff --git a/src/main/kotlin/team8/fruitable/datebase/repository/PagebleAccountRepository.kt b/src/main/kotlin/team8/fruitable/datebase/repository/PagebleAccountRepository.kt new file mode 100644 index 0000000..bf79361 --- /dev/null +++ b/src/main/kotlin/team8/fruitable/datebase/repository/PagebleAccountRepository.kt @@ -0,0 +1,10 @@ +package team8.fruitable.datebase.repository + +import org.springframework.data.repository.CrudRepository +import org.springframework.data.repository.PagingAndSortingRepository +import team8.fruitable.datebase.entity.User + +interface PagebleAccountRepository : PagingAndSortingRepository { + fun findByName(name: String): User? + fun findByToken(token: String): User? +} diff --git a/src/main/resources/static/styles/edit.css b/src/main/resources/static/styles/edit.css index bd075c5..cd15a1b 100644 --- a/src/main/resources/static/styles/edit.css +++ b/src/main/resources/static/styles/edit.css @@ -15,14 +15,18 @@ div { } #Contents { - flex-direction: row; + flex-direction: column; width: 100%; height: 500px; } +#Contents > .Title { + justify-content: space-between; +} + #Contents > .Editors { flex: 4 0 0; - flex-direction: column; + flex-direction: row; justify-content: space-between; width: auto; margin: 5px; @@ -32,47 +36,27 @@ div { border-radius: 15px; } -#Contents > .Editors > .Title { - justify-content: space-between; -} - -#Contents > .Editors > .Result { +#Contents > .Editors > .ResultPanel { color: wheat; border: 3px solid skyblue; border-spacing: 0; border-radius: 10px; } -#Contents > .Editors > .Result td { +#Contents > .Editors > .ResultPanel td { white-space: nowrap; border: 1px solid cornflowerblue; } -#Contents > .Editors > .Result > thead { +#Contents > .Editors > .ResultPanel > thead { background-color: #044488; } -#Contents > .Editors > .Result > tbody { +#Contents > .Editors > .ResultPanel > tbody { background-color: #008080; } -#Contents > .Editors > .Pages > * { - color: wheat; - margin-right: 3px; - border: 3px solid skyblue; - border-radius: 10px; - background-color: cadetblue; -} - -#Contents > .Editors > .Pages > *:last-child { - margin-right: inherit; -} - -#Contents > .Editors > .Pages > span { - color: green; -} - -#Contents > .EditPanel { +#Contents > .Editors > .EditPanel { flex: 1 0 0; margin: 5px; padding: 5px; @@ -81,10 +65,26 @@ div { border-radius: 15px; } -#Contents > .EditPanel > .Panel { +#Contents > .Editors > .EditPanel > .Panel { border: 0; } +#Contents > .Pages > * { + color: wheat; + margin-right: 3px; + border: 3px solid skyblue; + border-radius: 10px; + background-color: cadetblue; +} + +#Contents > .Pages > *:last-child { + margin-right: inherit; +} + +#Contents > .Pages > span { + color: green; +} + @media (min-width: 1280px) { #Contents { width: 1280px; diff --git a/src/main/resources/templates/edit.mustache b/src/main/resources/templates/editor.mustache similarity index 55% rename from src/main/resources/templates/edit.mustache rename to src/main/resources/templates/editor.mustache index adabd0a..55a657a 100644 --- a/src/main/resources/templates/edit.mustache +++ b/src/main/resources/templates/editor.mustache @@ -27,17 +27,41 @@
-
- {{# userEditor }} - {{> editor/user }} - {{/ userEditor }} - {{# itemEditor }} - {{> editor/item }} - {{/ itemEditor }} +
+
+ {{# tabs }} + {{ second }} + {{/ tabs }} +
+ + + +
-
- +
+ {{# useUserEditor }} + {{> editor/user }} + {{/ useUserEditor }} + {{# useItemEditor }} + {{> editor/item }} + {{/ useItemEditor }}
diff --git a/src/main/resources/templates/editor/item.mustache b/src/main/resources/templates/editor/item.mustache index d7119e0..651fd6e 100644 --- a/src/main/resources/templates/editor/item.mustache +++ b/src/main/resources/templates/editor/item.mustache @@ -1,37 +1,39 @@ -{{> header }} + + + + + + + + + + + + + + + + {{# Users }} + + + + + + + + + + + + + + {{/ Users }} + +
ID用户名帐户创建时间最后登录时间年龄性别邮箱管理员操作
{{ Id }}{{ UserName }}{{ CreateDate }}{{ LastLoginDate }}{{ Age }}{{ Gender }}{{ Phone }}{{ Email }}{{ Address }}{{ IsAdmin }} + + +
- -
-
-
- 商品图片 -
-
- -
-
-
-
- -
-
-
数量
-
-
 1 
-
 2 
-
 3 
-
 4 
-
 5 
-
 6 
-
-
-
-
- 立即购买 - 加入购物车 -
-
-
+
+
- -{{> footer }} \ No newline at end of file diff --git a/src/main/resources/templates/editor/user.mustache b/src/main/resources/templates/editor/user.mustache index 5740da8..b3ded9d 100644 --- a/src/main/resources/templates/editor/user.mustache +++ b/src/main/resources/templates/editor/user.mustache @@ -1,24 +1,4 @@ -
- - - -
- - +
@@ -27,43 +7,35 @@ + + - {{#Users}} - - - - - - - - - - - + {{# data }} + + + + + + + + + + + - {{/Users}} + {{/ data }}
ID最后登录时间 年龄 性别手机号码 邮箱地址 管理员 操作
{{ Id }}{{ UserName }}{{ CreateDate }}{{ LastLoginDate }}{{ Age }}{{ Gender }}{{ Phone }}{{ Email }}{{ Address }}{{ IsAdmin }}
{{ id }}{{ name }}{{ createTime }}{{ loginTime }}{{# age }}{{ age }}{{/ age }}{{# gender }}{{ gender }}{{/ gender }}{{# phone }}{{ phone }}{{/ phone }}{{# email }}{{ email }}{{/ email }}{{# address }}{{ address }}{{/ address }}{{# isAdmin }}是{{/ isAdmin }}{{^ isAdmin }}否{{/ isAdmin }}
-
- 首页 - - - - - - - - - 尾页 +
+
diff --git a/src/main/resources/templates/footer.mustache b/src/main/resources/templates/footer.mustache index 2c6f3cf..84fc6da 100644 --- a/src/main/resources/templates/footer.mustache +++ b/src/main/resources/templates/footer.mustache @@ -1,7 +1,7 @@