prepare editor page

Signed-off-by: Puqns67 <me@puqns67.icu>
This commit is contained in:
Puqns67 2023-09-16 00:47:01 +08:00
parent a541931772
commit 2f8246cfdf
Signed by: Puqns67
GPG Key ID: 9669DF042554F536
10 changed files with 237 additions and 134 deletions

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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<Pair<String, String>> = arrayOf(
"user" to "用户",
"item" to "商品"
)
private final val editorSearchTypesForUser: Array<Pair<String, String>> = 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<Pair<String, String>> = 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"
}
}

View File

@ -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
}

View File

@ -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<User, Long> {
fun findByName(name: String): User?
fun findByToken(token: String): User?
}

View File

@ -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;

View File

@ -27,17 +27,41 @@
<!-- 页面内容 -->
<div id="Contents">
<div class="Editors">
{{# userEditor }}
{{> editor/user }}
{{/ userEditor }}
{{# itemEditor }}
{{> editor/item }}
{{/ itemEditor }}
<div class="Title">
<div class="Tabs">
{{# tabs }}
<a href="/editor?use={{ first }}">{{ second }}</a>
{{/ tabs }}
</div>
<form class="Search" action="/editor" method="post">
<input type="hidden" name="use" value="user"/>
<label>
<select name="search_type">
{{# selects }}
<option value="{{ first }}">{{ second }}</option>
{{/ selects }}
</select>
搜索
</label>
<label>
<input name="search_content" placeholder="请在此处输入你想要搜索的内容..."
{{# searching }}value="{{ searching }}"{{/ searching }}/>
</label>
<button type="submit">搜索</button>
</form>
<button onclick="location.reload();">刷新</button>
</div>
<div class="EditPanel">
<iframe id="Panel" class="Panel" name="panel"></iframe>
<div class="Editors">
{{# useUserEditor }}
{{> editor/user }}
{{/ useUserEditor }}
{{# useItemEditor }}
{{> editor/item }}
{{/ useItemEditor }}
</div>
</div>

View File

@ -1,37 +1,39 @@
{{> header }}
<table class="ResultPanel">
<thead>
<tr>
<td>ID</td>
<td>用户名</td>
<td>帐户创建时间</td>
<td>最后登录时间</td>
<td>年龄</td>
<td>性别</td>
<td>邮箱</td>
<td>管理员</td>
<td>操作</td>
</tr>
</thead>
<tbody>
{{# Users }}
<tr id="{{ Id }}">
<td>{{ Id }}</td>
<td>{{ UserName }}</td>
<td>{{ CreateDate }}</td>
<td>{{ LastLoginDate }}</td>
<td>{{ Age }}</td>
<td>{{ Gender }}</td>
<td>{{ Phone }}</td>
<td>{{ Email }}</td>
<td>{{ Address }}</td>
<td>{{ IsAdmin }}</td>
<td>
<button class="update">编辑</button>
<button class="remove">删除</button>
</td>
</tr>
{{/ Users }}
</tbody>
</table>
<!-- 页面内容 -->
<div id="Contents">
<div class="Item">
<div class="Picture">
<img alt="商品图片" src=""/>
</div>
<div class="Infos">
<span class="Title"></span>
<div class="Prices">
<div class="VipPrice"></div>
<div class="Price"></div>
</div>
<span class="Description"></span>
<div class="Options">
<div class="Option">
<div class="Title">数量</div>
<div class="Contents">
<div class="Option" selected>&nbsp;1&nbsp;</div>
<div class="Option">&nbsp;2&nbsp;</div>
<div class="Option">&nbsp;3&nbsp;</div>
<div class="Option">&nbsp;4&nbsp;</div>
<div class="Option">&nbsp;5&nbsp;</div>
<div class="Option">&nbsp;6&nbsp;</div>
</div>
</div>
</div>
<div class="Buttons">
<span class="Button">立即购买</span>
<span class="Button">加入购物车</span>
</div>
</div>
</div>
<div class="EditPanel">
<!-- <iframe id="Panel" class="Panel" name="panel"></iframe>-->
</div>
{{> footer }}

View File

@ -1,24 +1,4 @@
<div class="Title">
<form class="Search" action="edit" method="post">
<input type="hidden" name="edit" value="user"/>
{{!
list="#{'ALL': '搜索全部', 'ID': '以ID搜索', 'USERNAME': '以用户名搜索', 'CREATE_DATE': '以帐户注册时间搜索', 'LAST_LOGIN_DATE': '以最后登录时间搜索', 'AGE': '以年龄搜索', 'GENDER': '以性别搜索', 'EMAIL': '以邮箱搜索', 'IS_ADMIN': '以管理员状态搜索'}"
}}
<select name="type">
{{#Editor.Selects}}
<option value="{{key}}">{{value}}</option>
{{/Editor.Selects}}
</select>
<label>
<input name="search" placeholder="请在此处输入你想要搜索的内容..." value="{{Editor.Searching}}"/>
</label>
<button type="submit">搜索</button>
</form>
<button onclick="location.reload();">刷新</button>
</div>
<table class="Result">
<table class="ResultPanel">
<thead>
<tr>
<td>ID</td>
@ -27,43 +7,35 @@
<td>最后登录时间</td>
<td>年龄</td>
<td>性别</td>
<td>手机号码</td>
<td>邮箱</td>
<td>地址</td>
<td>管理员</td>
<td>操作</td>
</tr>
</thead>
<tbody>
{{#Users}}
<tr id="{{ Id }}">
<td>{{ Id }}</td>
<td>{{ UserName }}</td>
<td>{{ CreateDate }}</td>
<td>{{ LastLoginDate }}</td>
<td>{{ Age }}</td>
<td>{{ Gender }}</td>
<td>{{ Phone }}</td>
<td>{{ Email }}</td>
<td>{{ Address }}</td>
<td>{{ IsAdmin }}</td>
{{# data }}
<tr id="{{ id }}">
<td>{{ id }}</td>
<td>{{ name }}</td>
<td>{{ createTime }}</td>
<td>{{ loginTime }}</td>
<td>{{# age }}{{ age }}{{/ age }}</td>
<td>{{# gender }}{{ gender }}{{/ gender }}</td>
<td>{{# phone }}{{ phone }}{{/ phone }}</td>
<td>{{# email }}{{ email }}{{/ email }}</td>
<td>{{# address }}{{ address }}{{/ address }}</td>
<td>{{# isAdmin }}是{{/ isAdmin }}{{^ isAdmin }}否{{/ isAdmin }}</td>
<td>
<button class="update">编辑</button>
<button class="remove">删除</button>
</td>
</tr>
{{/Users}}
{{/ data }}
</tbody>
</table>
<div class="Pages">
<a href="edit?page=0">首页</a>
<s:iterator begin="%{#EditInfo.StartPage}" end="%{#EditInfo.StopPage}" var="PageNumber">
<s:if test="%{#PageNumber == #EditInfo.NowPageStr}">
<span>第 <s:property value="%{#PageNumber + 1}" 页</span>
</s:if>
<s:else>
<a href=" edit.jsp?page=<s:property value="%{#PageNumber} }}">第 <s:property
value="%{#PageNumber + 1}"/> 页</a>
</s:else>
</s:iterator>
<a href="edit.jsp?page=<s:property value=" %{#EditInfo.EndPage} }}">尾页</a>
<div class="EditPanel">
<!-- <iframe id="Panel" class="Panel" name="panel"></iframe>-->
</div>

View File

@ -1,7 +1,7 @@
<!-- 页尾内容 -->
<div id="Footer">
<div class="Infos">
<div class="Icon"><img alt="图标" src="images/icon.svg" /></div>
<div class="Icon"><img alt="图标" src="images/icon.svg"/></div>
<div class="Title">果蔬销售商城</div>
<div class="Contents">
<span>只做高质量商品销售~</span>
@ -17,14 +17,5 @@
<div id="Floater">
<!-- 回到顶层 -->
<div class="TOP"></div>
<canvas
class="fireworks"
style="
position: fixed;
left: 0;
top: 0;
z-index: 1;
pointer-events: none;
"
></canvas>
<canvas class="fireworks" style="position: fixed; left: 0; top: 0; z-index: 1; pointer-events: none;"></canvas>
</div>