重构:管理后台不支持管理员对用户搜索数据进行crud操作
This commit is contained in:
@@ -42,45 +42,4 @@ public class AdminHistoryController {
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallSearchHistory history){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
return ResponseUtil.unsupport();
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, Integer id){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
if(id == null){
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
LitemallSearchHistory history = searchHistoryService.findById(id);
|
||||
return ResponseUtil.ok(history);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallSearchHistory history){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
searchHistoryService.updateById(history);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallSearchHistory history){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
searchHistoryService.deleteById(history.getId());
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,35 +7,3 @@ export function listHistory(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
export function createHistory(data) {
|
||||
return request({
|
||||
url: '/history/create',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function readHistory(data) {
|
||||
return request({
|
||||
url: '/history/read',
|
||||
method: 'get',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function updateHistory(data) {
|
||||
return request({
|
||||
url: '/history/update',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteHistory(data) {
|
||||
return request({
|
||||
url: '/history/delete',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<el-input clearable class="filter-item" style="width: 200px;" placeholder="请输入搜索历史关键字" v-model="listQuery.keyword">
|
||||
</el-input>
|
||||
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
|
||||
<el-button class="filter-item" type="primary" @click="handleCreate" icon="el-icon-edit">添加</el-button>
|
||||
<el-button class="filter-item" type="primary" :loading="downloadLoading" icon="el-icon-download" @click="handleDownload">导出</el-button>
|
||||
</div>
|
||||
|
||||
@@ -40,32 +39,11 @@
|
||||
</el-pagination>
|
||||
</div>
|
||||
|
||||
<!-- 添加或修改对话框 -->
|
||||
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
||||
<el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
|
||||
<el-form-item label="用户ID" prop="userId">
|
||||
<el-input v-model="dataForm.userId"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字" prop="keyword">
|
||||
<el-input v-model="dataForm.keyword"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="添加时间" prop="addTime">
|
||||
<el-date-picker v-model="dataForm.addTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogFormVisible = false">取消</el-button>
|
||||
<el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button>
|
||||
<el-button v-else type="primary" @click="updateData">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listHistory, createHistory, updateHistory, deleteHistory } from '@/api/history'
|
||||
import { listHistory } from '@/api/history'
|
||||
|
||||
export default {
|
||||
name: 'History',
|
||||
@@ -82,26 +60,6 @@ export default {
|
||||
sort: 'add_time',
|
||||
order: 'desc'
|
||||
},
|
||||
dataForm: {
|
||||
id: undefined,
|
||||
userId: '',
|
||||
keyword: '',
|
||||
addTime: undefined
|
||||
},
|
||||
dialogFormVisible: false,
|
||||
dialogStatus: '',
|
||||
textMap: {
|
||||
update: '编辑',
|
||||
create: '创建'
|
||||
},
|
||||
rules: {
|
||||
userId: [
|
||||
{ required: true, message: '用户ID不能为空', trigger: 'blur' }
|
||||
],
|
||||
keyword: [
|
||||
{ required: true, message: '搜索关键字不能为空', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
downloadLoading: false
|
||||
}
|
||||
},
|
||||
@@ -133,80 +91,6 @@ export default {
|
||||
this.listQuery.page = val
|
||||
this.getList()
|
||||
},
|
||||
resetForm() {
|
||||
this.dataForm = {
|
||||
id: undefined,
|
||||
userId: '',
|
||||
goodsId: '',
|
||||
addTime: undefined
|
||||
}
|
||||
},
|
||||
handleCreate() {
|
||||
this.resetForm()
|
||||
this.dialogStatus = 'create'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
createData() {
|
||||
this.$refs['dataForm'].validate(valid => {
|
||||
if (valid) {
|
||||
createHistory(this.dataForm).then(response => {
|
||||
this.list.unshift(response.data.data)
|
||||
this.dialogFormVisible = false
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '创建成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleUpdate(row) {
|
||||
this.dataForm = Object.assign({}, row)
|
||||
this.dialogStatus = 'update'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
updateData() {
|
||||
this.$refs['dataForm'].validate(valid => {
|
||||
if (valid) {
|
||||
updateHistory(this.dataForm).then(() => {
|
||||
for (const v of this.list) {
|
||||
if (v.id === this.dataForm.id) {
|
||||
const index = this.list.indexOf(v)
|
||||
this.list.splice(index, 1, this.dataForm)
|
||||
break
|
||||
}
|
||||
}
|
||||
this.dialogFormVisible = false
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '更新成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleDelete(row) {
|
||||
deleteHistory(row).then(response => {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
const index = this.list.indexOf(row)
|
||||
this.list.splice(index, 1)
|
||||
})
|
||||
},
|
||||
handleDownload() {
|
||||
this.downloadLoading = true
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
|
||||
@@ -32,19 +32,6 @@ public class LitemallSearchHistoryService {
|
||||
searchHistoryMapper.logicalDeleteByExample(example);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
LitemallSearchHistory searchHistory = searchHistoryMapper.selectByPrimaryKey(id);
|
||||
if(searchHistory == null){
|
||||
return;
|
||||
}
|
||||
searchHistory.setDeleted(true);
|
||||
searchHistoryMapper.logicalDeleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void add(LitemallSearchHistory searchHistory) {
|
||||
searchHistoryMapper.insertSelective(searchHistory);
|
||||
}
|
||||
|
||||
public List<LitemallSearchHistory> querySelective(String userId, String keyword, Integer page, Integer size, String sort, String order) {
|
||||
LitemallSearchHistoryExample example = new LitemallSearchHistoryExample();
|
||||
LitemallSearchHistoryExample.Criteria criteria = example.createCriteria();
|
||||
@@ -79,12 +66,4 @@ public class LitemallSearchHistoryService {
|
||||
|
||||
return (int)searchHistoryMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void updateById(LitemallSearchHistory collect) {
|
||||
searchHistoryMapper.updateByPrimaryKeySelective(collect);
|
||||
}
|
||||
|
||||
public LitemallSearchHistory findById(Integer id) {
|
||||
return searchHistoryMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user