Browse Source

博客列表完善 & bug修复

master
nelson 3 years ago
parent
commit
52f5544fe2
  1. 25
      controllers/BlogController.go
  2. 2
      controllers/FileController.go
  3. 2
      controllers/UserController.go
  4. 1
      routers/BlogRouter.go
  5. 12
      static/css/common.css
  6. 2
      views/login.html
  7. 3
      views/search.html
  8. 95
      views/ublogs.html
  9. 113
      views/uinfo.html

25
controllers/BlogController.go

@ -35,6 +35,31 @@ func (this *BlogController) EditPage() {
this.TplName = "editblog.html"
}
func (this *BlogController) List() {
blogService := service.BlogService{}
uid := this.GetSession("userid")
if uid == nil {
this.Data["json"] = models.ReurnError(401, "")
this.ServeJSON()
return
}
size := 10
num, _ := this.GetInt("num")
if num <= 0 {
num = 1
}
flag, _ := this.GetInt("flag")
page, err := blogService.MeBlogs(num, size, flag, uid.(int64))
if err != nil {
this.Data["json"] = models.ReurnError(500, "")
this.ServeJSON()
return
}
this.Data["json"] = models.ReurnData("success", page)
this.ServeJSON()
return
}
func (this *BlogController) Save() {
blogService := service.BlogService{}
userService := service.UserService{}

2
controllers/FileController.go

@ -82,7 +82,7 @@ func (this *FileController) HeadImgUpload() {
this.ServeJSON()
return
}
filename := "imgfile"
filename := "file"
f, h, filerr := this.GetFile(filename) //获取上传的文件
if filerr != nil {
fmt.Println("err:", filerr)

2
controllers/UserController.go

@ -62,7 +62,7 @@ func (this *UserController) PersonBlog() {
this.Redirect("/login", 302)
return
}
size := 15
size := 10
num, _ := this.GetInt("num")
if num <= 0 {
num = 1

1
routers/BlogRouter.go

@ -7,6 +7,7 @@ import (
func init() {
beego.Router("/api/blog/new", &controllers.BlogController{}, "post:Save")
beego.Router("/api/blog/list", &controllers.BlogController{}, "get:List")
beego.Router("/api/blog/edit", &controllers.BlogController{}, "post:Edit")
beego.Router("/api/blog/del/:id([0-9]+)", &controllers.BlogController{}, "post:Del")
beego.Router("/blog/edit/:id([0-9]+)", &controllers.BlogController{}, "get:EditPage")

12
static/css/common.css

@ -156,12 +156,7 @@ a{
color: #444;
font-size: 16px;
}
.blog-root .blog-detaile pre{
/*color: #d2e8b9;*/
border: 1px #d2e8b9 solid;
box-shadow:1px 1px 2px 2px #d2e8b9;
margin: 5px 0;
}
.blog-root .blog-detaile h4{
font-size: 20px;
@ -556,11 +551,6 @@ img {
visibility: hidden !important;
}
.blog-detaile p code{
color: red;
padding: 2px 5px;
}
.search-root{
margin-top: 50px;
}

2
views/login.html

@ -169,7 +169,7 @@
geometry.setAttribute('scale', new THREE.BufferAttribute(scales, 1))
const material = new THREE.ShaderMaterial({
uniforms: {
color: {value: new THREE.Color(0.0, 1.0, 1.0, 1.0)}
color: {value: new THREE.Color(1.0, 1.0, 1.0, 1.0)}
},
vertexShader: document.getElementById('vertexshader').textContent,
fragmentShader: document.getElementById('fragmentshader').textContent

3
views/search.html

@ -10,7 +10,7 @@
<div>
<div>
<div class="input-group input-class">
<i-input id="searchVal" search enter-button @on-search="searchHandler" placeholder="请输入关键字"/>
<el-input v-model="searchVal" @change="searchHandler" placeholder="请输入关键字"></el-input>
</div>
</div>
</div>
@ -32,6 +32,7 @@
el: ".root-container",
delimiters: ['${', '}'],
data: {
searchVal: '',
list: [],
pageNo: 1,
pageSize: 30,

95
views/ublogs.html

@ -15,66 +15,63 @@
<a><cite>博客列表</cite></a>
</span>
</div>
{{range .Page.List}}
<div>
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p>
<div>
<em>发布时间:{{.Ctime.Format "2006/01/02"}}</em>
<em>浏览量:{{.Browses}}</em>
<span style="width: 35px;margin-left: 30px;"><a href="javascript:void(0)" style="color: #F84822"
onclick="del(this,{{.Id}})">删除</a></span>
<span style="width: 35px;margin-left: 10px;"><a href="/blog/edit/{{.Id}}" target="_blank"
style="color: #F84822">编辑</a></span>
</div>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
{{end}}
<div style="text-align: center">
<nav>
<div class="pagination pagination-lg">
<ul>
{{if .Page.FirstPage}}
{{else}}
<li class="prev">
<a href="/me/blog?num={{ .Page.PageNo | NAdd -1}}&flag={{.Flag}}">&laquo;</a>
</li>
{{end}}
<li class="active"><a href="javascript:void(0)">{{.Page.PageNo}}</a></li>
{{if .Page.LastPage}}
{{else}}
<li class="next">
<a href="/me/blog?num={{ .Page.PageNo | NAdd +1}}&flag={{.Flag}}">&raquo;</a>
</li>
{{end}}
</ul>
</div>
</nav>
<el-table :data="tableData" border style="width: 100%" stripe>
<el-table-column prop="Title" label="文章" ></el-table-column>
<el-table-column prop="Ctime" label="时间" width="120" ></el-table-column>
<el-table-column prop="Browses" label="浏览量" width="100" ></el-table-column>
<el-table-column fixed="right" label="操作" width="135">
<template slot-scope="scope">
<el-button @click="editClick(scope.row)" type="text" size="small">编辑</el-button>
<el-button @click="viewClick(scope.row)" type="text" size="small">查看</el-button>
<el-button @click="deleteClick(scope.row)" type="text" size="small">删除</el-button>
</template>
</el-table-column>
</el-table>
<div style="margin-top: 10px;text-align: center">
<el-pagination
background
layout="prev, pager, next"
:current-page="pageNum"
:total="totals"
@current-change="pageChange">
</el-pagination>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var app = new Vue({
el: ".root-container",
delimiters: ['${', '}'],
data: {},
data: {
pageNum: 1,
totals: 0,
tableData: []
},
created() {
this.totals = {{.Page.TotalCount}}
const initData = {{.Page.List}}
this.tableData= initData.map(x=> {x.Ctime = x.Ctime.substring(0,x.Ctime.indexOf('T'));return x})
},
methods: {
del(obj, id) {
editClick(row){
window.open('/blog/edit/'+row.Id)
},
viewClick(row){
window.open('/blog/'+row.Id)
},
deleteClick(row){
const _this = this
this.$confirm('此操作将永久删除,删除后将无法恢复, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
$.post('/api/blog/del/' + id,
$.post('/api/blog/del/' + row.Id,
function (data) {
if (data.Status == 0) {
$(obj).parent().parent().parent().remove()
_this.getData()
_this.$message.success("删除成功")
} else if (data.Status == 401) {
window.location.href = "/login"
@ -86,6 +83,24 @@
}, 'json')
}).catch(() => {
})
},
pageChange(page){
this.pageNum = page
this.getData()
},
getData(){
const _this = this
$.get('/api/blog/list',{num: this.pageNum},
function (data) {
if (data.Status == 0) {
debugger
_this.tableData= data.Data.List.map(x=> {x.Ctime = x.Ctime.substring(0,x.Ctime.indexOf('T'));return x})
} else if (data.Status == 401) {
window.location.href = "/login"
} else {
this.$message.error("服务器异常")
}
}, 'json')
}
}
})

113
views/uinfo.html

@ -1,6 +1,30 @@
{{template "header" .}}
<title>我的资料 - 码农随笔</title>
<script type="text/javascript" src="/static/js/upload.js"></script>
<style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>
</head>
<body style="background-color: #f9f9f9">
<div class="root-container">
@ -17,9 +41,15 @@
</span>
</div>
<div style="display: flex">
<div style="width: 160px">
<img src="{{.HeadImg}}" alt="头像" class="img-circle img-circle-large">
<div id="drop_area" style="margin-top: 15px"></div>
<div style="width: 200px;margin-top: 10px">
<el-upload
class="avatar-uploader"
action="/himg/upload"
:show-file-list="false"
:on-success="handleAvatarSuccess">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</div>
<div class="info-header">
<div style="display: flex">
@ -29,8 +59,6 @@
<div>
<span>博客 {{.User.BlogCount}}</span>
<span>浏览量 {{.User.BlogBrowes}}</span>
<span>博客 {{.User.BlogCount}}</span>
<span>博客 {{.User.BlogCount}}</span>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 10px 0 5px 0;"/>
<div>
@ -38,54 +66,61 @@
<p style="flex: 1">昵称 :{{.User.NickName}}</p>
<p><a href="javascript:void(0)" style="text-decoration: none" id="editBtn">修改资料</a></p>
</div>
<p>生日 :{{.User.Birthday.Format "2006-01-02"}}</p>
<p>邮箱 :{{.User.Email}}</p>
<p>手机 :{{.User.Mobile}}</p>
<p>Q Q :{{.User.QQ}}</p>
{{if eq 0 .User.Sex}}
<p>性别 :女</p>
{{else}}
<p>性别 :男</p>
{{end}}
<p>简介 :{{.User.DescInfo}}</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- <el-dialog title="编辑个人信息" :visible.sync="dialogFormVisible">-->
<!-- <el-form :model="form">-->
<!-- <el-form-item label="活动名称" :label-width="150px">-->
<!-- <el-input v-model="form.nickName"></el-input>-->
<!-- </el-form-item>-->
<!-- </el-form>-->
<!-- <div slot="footer" class="dialog-footer">-->
<!-- <el-button @click="dialogFormVisible = false">取 消</el-button>-->
<!-- <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>-->
<!-- </div>-->
<!-- </el-dialog>-->
</div>
</body>
<script>
var dragImgUpload = new DragImgUpload("#drop_area",{
callback:function (files) {
//回调函数,可以传递给后台等等
var file = files[0];
console.log(file.name);
var app = new Vue({
el: ".root-container",
delimiters: ['${', '}'],
data: {
dialogFormVisible: false,
imageUrl: '',
form: {
nickName: '',
email: '',
mobile: ''
}
},
created() {
console.log({{.User}})
this.imageUrl = {{.HeadImg}}
},
methods: {
editBtn(){
var formData = new FormData();
formData.append("imgfile",file );
if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name))
{
return false;
}else{
$.ajax({
url: '/himg/upload',
type:'POST',
contentType: false,
processData: false,
data: formData,
success:function(data,textstatus){
if (data.Status == 0){
this.$message.success("上传成功")
}else{
this.$message.error("上传失败")
}
}
});
},
handleAvatarSuccess(res, file){
if(res.Status === 0){
this.imageUrl = res.Data
this.$message.success('上传成功')
} else if(res.Status === 401){
window.location.href = "/login"
} else {
this.$message.error('上传成功')
}
}
}
})
function refresh() {
window.location.href = window.location.href
}

Loading…
Cancel
Save