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" 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() { func (this *BlogController) Save() {
blogService := service.BlogService{} blogService := service.BlogService{}
userService := service.UserService{} userService := service.UserService{}

2
controllers/FileController.go

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

2
controllers/UserController.go

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

1
routers/BlogRouter.go

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

12
static/css/common.css

@ -156,12 +156,7 @@ a{
color: #444; color: #444;
font-size: 16px; 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{ .blog-root .blog-detaile h4{
font-size: 20px; font-size: 20px;
@ -556,11 +551,6 @@ img {
visibility: hidden !important; visibility: hidden !important;
} }
.blog-detaile p code{
color: red;
padding: 2px 5px;
}
.search-root{ .search-root{
margin-top: 50px; margin-top: 50px;
} }

2
views/login.html

@ -169,7 +169,7 @@
geometry.setAttribute('scale', new THREE.BufferAttribute(scales, 1)) geometry.setAttribute('scale', new THREE.BufferAttribute(scales, 1))
const material = new THREE.ShaderMaterial({ const material = new THREE.ShaderMaterial({
uniforms: { 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, vertexShader: document.getElementById('vertexshader').textContent,
fragmentShader: document.getElementById('fragmentshader').textContent fragmentShader: document.getElementById('fragmentshader').textContent

3
views/search.html

@ -10,7 +10,7 @@
<div> <div>
<div> <div>
<div class="input-group input-class"> <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> </div>
</div> </div>
@ -32,6 +32,7 @@
el: ".root-container", el: ".root-container",
delimiters: ['${', '}'], delimiters: ['${', '}'],
data: { data: {
searchVal: '',
list: [], list: [],
pageNo: 1, pageNo: 1,
pageSize: 30, pageSize: 30,

95
views/ublogs.html

@ -15,66 +15,63 @@
<a><cite>博客列表</cite></a> <a><cite>博客列表</cite></a>
</span> </span>
</div> </div>
{{range .Page.List}} <el-table :data="tableData" border style="width: 100%" stripe>
<div> <el-table-column prop="Title" label="文章" ></el-table-column>
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p> <el-table-column prop="Ctime" label="时间" width="120" ></el-table-column>
<div> <el-table-column prop="Browses" label="浏览量" width="100" ></el-table-column>
<em>发布时间:{{.Ctime.Format "2006/01/02"}}</em> <el-table-column fixed="right" label="操作" width="135">
<em>浏览量:{{.Browses}}</em> <template slot-scope="scope">
<span style="width: 35px;margin-left: 30px;"><a href="javascript:void(0)" style="color: #F84822" <el-button @click="editClick(scope.row)" type="text" size="small">编辑</el-button>
onclick="del(this,{{.Id}})">删除</a></span> <el-button @click="viewClick(scope.row)" type="text" size="small">查看</el-button>
<span style="width: 35px;margin-left: 10px;"><a href="/blog/edit/{{.Id}}" target="_blank" <el-button @click="deleteClick(scope.row)" type="text" size="small">删除</el-button>
style="color: #F84822">编辑</a></span> </template>
</div> </el-table-column>
</div> </el-table>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/> <div style="margin-top: 10px;text-align: center">
{{end}} <el-pagination
<div style="text-align: center"> background
<nav> layout="prev, pager, next"
<div class="pagination pagination-lg"> :current-page="pageNum"
<ul> :total="totals"
{{if .Page.FirstPage}} @current-change="pageChange">
{{else}} </el-pagination>
<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>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
</body> </body>
<script> <script>
var app = new Vue({ var app = new Vue({
el: ".root-container", el: ".root-container",
delimiters: ['${', '}'], delimiters: ['${', '}'],
data: {}, data: {
pageNum: 1,
totals: 0,
tableData: []
},
created() { 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: { methods: {
del(obj, id) { editClick(row){
window.open('/blog/edit/'+row.Id)
},
viewClick(row){
window.open('/blog/'+row.Id)
},
deleteClick(row){
const _this = this const _this = this
this.$confirm('此操作将永久删除,删除后将无法恢复, 是否继续?', '提示', { this.$confirm('此操作将永久删除,删除后将无法恢复, 是否继续?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
$.post('/api/blog/del/' + id, $.post('/api/blog/del/' + row.Id,
function (data) { function (data) {
if (data.Status == 0) { if (data.Status == 0) {
$(obj).parent().parent().parent().remove() _this.getData()
_this.$message.success("删除成功") _this.$message.success("删除成功")
} else if (data.Status == 401) { } else if (data.Status == 401) {
window.location.href = "/login" window.location.href = "/login"
@ -86,6 +83,24 @@
}, 'json') }, 'json')
}).catch(() => { }).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" .}} {{template "header" .}}
<title>我的资料 - 码农随笔</title> <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> </head>
<body style="background-color: #f9f9f9"> <body style="background-color: #f9f9f9">
<div class="root-container"> <div class="root-container">
@ -17,9 +41,15 @@
</span> </span>
</div> </div>
<div style="display: flex"> <div style="display: flex">
<div style="width: 160px"> <div style="width: 200px;margin-top: 10px">
<img src="{{.HeadImg}}" alt="头像" class="img-circle img-circle-large"> <el-upload
<div id="drop_area" style="margin-top: 15px"></div> 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>
<div class="info-header"> <div class="info-header">
<div style="display: flex"> <div style="display: flex">
@ -29,8 +59,6 @@
<div> <div>
<span>博客 {{.User.BlogCount}}</span> <span>博客 {{.User.BlogCount}}</span>
<span>浏览量 {{.User.BlogBrowes}}</span> <span>浏览量 {{.User.BlogBrowes}}</span>
<span>博客 {{.User.BlogCount}}</span>
<span>博客 {{.User.BlogCount}}</span>
</div> </div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 10px 0 5px 0;"/> <hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 10px 0 5px 0;"/>
<div> <div>
@ -38,54 +66,61 @@
<p style="flex: 1">昵称 :{{.User.NickName}}</p> <p style="flex: 1">昵称 :{{.User.NickName}}</p>
<p><a href="javascript:void(0)" style="text-decoration: none" id="editBtn">修改资料</a></p> <p><a href="javascript:void(0)" style="text-decoration: none" id="editBtn">修改资料</a></p>
</div> </div>
<p>生日 :{{.User.Birthday.Format "2006-01-02"}}</p>
<p>邮箱 :{{.User.Email}}</p> <p>邮箱 :{{.User.Email}}</p>
<p>手机 :{{.User.Mobile}}</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> <p>简介 :{{.User.DescInfo}}</p>
</div> </div>
</div> </div>
</div> </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> </div>
</body> </body>
<script> <script>
var dragImgUpload = new DragImgUpload("#drop_area",{ var app = new Vue({
callback:function (files) { el: ".root-container",
//回调函数,可以传递给后台等等 delimiters: ['${', '}'],
var file = files[0]; data: {
console.log(file.name); dialogFormVisible: false,
imageUrl: '',
form: {
nickName: '',
email: '',
mobile: ''
}
},
created() {
console.log({{.User}})
this.imageUrl = {{.HeadImg}}
},
methods: {
editBtn(){
var formData = new FormData(); },
formData.append("imgfile",file ); handleAvatarSuccess(res, file){
if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name)) if(res.Status === 0){
{ this.imageUrl = res.Data
return false; this.$message.success('上传成功')
}else{ } else if(res.Status === 401){
$.ajax({ window.location.href = "/login"
url: '/himg/upload', } else {
type:'POST', this.$message.error('上传成功')
contentType: false, }
processData: false,
data: formData,
success:function(data,textstatus){
if (data.Status == 0){
this.$message.success("上传成功")
}else{
this.$message.error("上传失败")
}
}
});
} }
} }
}) })
function refresh() { function refresh() {
window.location.href = window.location.href window.location.href = window.location.href
} }

Loading…
Cancel
Save