prepare editor page
Signed-off-by: Puqns67 <me@puqns67.icu>
This commit is contained in:
parent
a541931772
commit
2f8246cfdf
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
89
src/main/kotlin/team8/fruitable/controller/page/Editor.kt
Normal file
89
src/main/kotlin/team8/fruitable/controller/page/Editor.kt
Normal 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"
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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?
|
||||
}
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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> 1 </div>
|
||||
<div class="Option"> 2 </div>
|
||||
<div class="Option"> 3 </div>
|
||||
<div class="Option"> 4 </div>
|
||||
<div class="Option"> 5 </div>
|
||||
<div class="Option"> 6 </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 }}
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user