今天主要实现了两个接口功能:博客删除以及对于用户信息中的邮箱的编辑修改。
首先对于用户个人信息界面,在此进行了页面的布局修改并增加了头像、邮箱修改弹窗,界面布局如下:
关于邮箱的修改功能实现代码如下:
methods:{
open() {
this.$prompt('请输入修改邮箱', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
inputErrorMessage: '邮箱格式不正确'
}).then(({ value }) => {
this.$message({
type: 'success',
message: '你的邮箱是: ' + value,
});
console.log(value)
axios.post("http://47.107.40.143:8080//updateEmail",QS.stringify(
{
uid:sessionStorage.getItem("uid"),
email:value
})).then(res=>{
console.log(res)
window.location.reload()
})
})
.catch(() => {
this.$message({
type: 'info',
message: '取消输入'
});
});
},
其次是博客删除功能
在草稿箱页面以及博客列表页面的删除按钮,之前只是进行了按钮布局,现在完成了博客的删除功能,
DeleteArticle(aid){
axios.get("http://47.107.40.143:8080/deleteArticle",{params:{aid:aid}}).then(res=>{
console.log(res)
window.location.reload()
})
}
在功能实现过程中,主要遇到的问题是如何根据登录确定用户的uid,在反复尝试之后,使用了
sessionStorage
实现:
if (_this.ruleForm.username == resp1.data.data.uid) {
sessionStorage.setItem("uid", resp1.data.data.uid)
sessionStorage.setItem("username", resp1.data.data.username)
_this.$router.push({
name: "Blogs",
})
在登录界面获得用户信息并返回后,其他页面直接调用即可。
由此实现了对数据库相关数据的调用,关于博客列表页面相关代码如下:
<template>
<div>
<Leftbar>
</Leftbar>
<Headers_copy>
</Headers_copy>
<div class="blog">
<el-button type="primary" plain icon="el-icon-edit" >
<el-link href="http://localhost:8081/#/blog/add" style="color: #333333;text-decoration: none">新建博客</el-link>
</el-button>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column type="expand">
<template slot-scope="props">
<el-form label-position="left" inline class="demo-table-expand">
<el-form-item label="博客简介">
<span>{{ props.row.summary }}</span>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column
label="博客名称">
<template slot-scope="props">
<el-button type="text"><span content="name">
{{props.row.title}}
</span></el-button>
</template>
</el-table-column>
<el-table-column
label="编辑时间"
>
<template slot-scope="props">
<span content="time">
{{props.row.editTime}}
</span>
</template>
</el-table-column>
<el-table-column
label="操作">
<template slot-scope="scope">
<el-button-group>
<el-button type="primary"plain icon="el-icon-edit" ></el-button>
<el-button type="primary"plain icon="el-icon-delete" @click="DeleteArticle(scope.row.aid)"></el-button>
</el-button-group>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
import Leftbar from "../components/Leftbar";
import Headers_copy from "@/components/headers_copy";
import request from "../utils/request";
const axios = require('axios');
export default {
name:"Blog",
components: {
Headers_copy,
Leftbar,
},
data() {
return {
uid: sessionStorage.getItem("uid"),
tableData: [],
}
},
created() {
const _this=this
axios.get("http://47.107.40.143:8080/getSpecArticle",{params:{uid:this.uid,state:1}}).then(res =>{
_this.tableData=res.data.data
console.log(res)
})
},
methods: {
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
},
DeleteArticle(aid){
axios.get("http://47.107.40.143:8080/deleteArticle",{params:{aid:aid}}).then(res=>{
console.log(res)
window.location.reload()
})
}
}
}
</script>
<style scoped>
.blog{
margin-left: 250px;
margin-top: 15px;
}
.demo-table-expand {
font-size: 0;
}
.demo-table-expand label {
width: 90px;
color: #99a9bf;
}
.demo-table-expand .el-form-item {
margin-right: 0;
margin-bottom: 0;
width: 50%;
}
</style>
界面内容如下: