|
|
|
@ -22,36 +22,37 @@
|
|
|
|
|
<el-input v-model="form.content" type="textarea" placeholder="有什么新鲜事..." rows=4 />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<el-upload action="#" list-type="picture" :auto-upload="false" :limit="1" :on-exceed="handleExceed" ref="postimage"
|
|
|
|
|
style="position: fixed; left: 12%;display: flex; align-items: center;" @change="handleFileChange" >
|
|
|
|
|
<!-- @success="handleUploadSuccess" -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-icon size="30px">
|
|
|
|
|
<Picture />
|
|
|
|
|
</el-icon>图片
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<el-radio-group v-model="radio" fill="#FE4E96" size="small" >
|
|
|
|
|
<el-radio-button label="日常动态" ></el-radio-button>
|
|
|
|
|
<el-radio-button label="家族故事" ></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<el-upload action="#" list-type="picture" :auto-upload="false" :limit="1" :on-exceed="handleExceed"
|
|
|
|
|
ref="postimage" style="position: fixed; left: 12%;display: flex; align-items: center;"
|
|
|
|
|
@change="handleFileChange">
|
|
|
|
|
<!-- @success="handleUploadSuccess" -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-icon size="30px">
|
|
|
|
|
<Picture />
|
|
|
|
|
</el-icon>图片
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<el-radio-group v-model="radio" fill="#FE4E96" size="small">
|
|
|
|
|
<el-radio-button label="日常动态"></el-radio-button>
|
|
|
|
|
<el-radio-button label="家族故事"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="button-container">
|
|
|
|
|
<el-button type="primary" @click="submitPost" :disabled="!form.content.trim()"
|
|
|
|
|
style="position:fixed; right:11% ;background-color:#FE4E96">发布</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="button-container">
|
|
|
|
|
<el-button type="primary" @click="submitPost" :disabled="!form.content.trim()"
|
|
|
|
|
style="position:fixed; right:11% ;background-color:#FE4E96">发布</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
@ -62,18 +63,18 @@
|
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
|
import axios from '@/utils/axiosConfig';
|
|
|
|
|
import {getUserId} from '@/token/auth';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'PostForm',
|
|
|
|
|
components: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
userid:1,
|
|
|
|
|
userid: getUserId(),
|
|
|
|
|
showForm: false, // 控制表单是否显示
|
|
|
|
|
radio: '日常动态',
|
|
|
|
|
form: {
|
|
|
|
@ -81,20 +82,25 @@
|
|
|
|
|
},
|
|
|
|
|
fileList: [],
|
|
|
|
|
imageUrl: '',
|
|
|
|
|
loadurl:'',
|
|
|
|
|
componentHeight: '3%'
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleFileChange(file) {
|
|
|
|
|
// 当文件被选中时触发
|
|
|
|
|
if (file.raw) {
|
|
|
|
|
// 创建预览图片的URL
|
|
|
|
|
async handleFileChange(file) {
|
|
|
|
|
// 当文件被选中时触发
|
|
|
|
|
this.file = file;
|
|
|
|
|
if (file.raw) {
|
|
|
|
|
// 创建预览图片的URL
|
|
|
|
|
|
|
|
|
|
this.imageUrl = URL.createObjectURL(file.raw);
|
|
|
|
|
if (file.raw.size / 1024 / 1024 > 2) {
|
|
|
|
|
this.$message.error('成本有限 只能上传1mb以内的照片')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.imageUrl = URL.createObjectURL(file.raw);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleExceed()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleExceed() {
|
|
|
|
|
this.$message.error("目前仅支持添加一张图片");
|
|
|
|
|
},
|
|
|
|
|
// 切换表单显示/隐藏
|
|
|
|
@ -112,10 +118,11 @@
|
|
|
|
|
}
|
|
|
|
|
return isImage;
|
|
|
|
|
},
|
|
|
|
|
handleUploadSuccess(response, file, fileList) {
|
|
|
|
|
|
|
|
|
|
async handleUploadSuccess(response, file, fileList) {
|
|
|
|
|
|
|
|
|
|
this.imageUrl = URL.createObjectURL(file.raw); // 创建临时 URL 以预览图片
|
|
|
|
|
this.$message("创建图片"+this.imageUrl);
|
|
|
|
|
|
|
|
|
|
this.$message("创建图片" + this.imageUrl);
|
|
|
|
|
this.fileList = fileList;
|
|
|
|
|
},
|
|
|
|
|
handleRemove(file, fileList) {
|
|
|
|
@ -128,49 +135,72 @@
|
|
|
|
|
this.$message.error('内容不能为空');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
|
|
formData.append('file', this.file.raw);
|
|
|
|
|
// 使用 axios 来发送请求
|
|
|
|
|
|
|
|
|
|
const response = await axios.post('/posts/addphoto', formData, {
|
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.loadurl=response;
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.$message.error("图片上传失败");
|
|
|
|
|
console.log(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newPost = {
|
|
|
|
|
userid:getUserId(),
|
|
|
|
|
userid: getUserId(),
|
|
|
|
|
username: '用户',
|
|
|
|
|
avatarurl: 'https://via.placeholder.com/50',
|
|
|
|
|
timestamp: new Date().toLocaleString(),
|
|
|
|
|
content: this.form.content,
|
|
|
|
|
imageurl: this.imageUrl,
|
|
|
|
|
imageurl: this.loadurl,
|
|
|
|
|
likecount: 0,
|
|
|
|
|
commentcount: 0,
|
|
|
|
|
isfamilystory: this.radio === '家族故事' ? true : false,
|
|
|
|
|
postid:999,
|
|
|
|
|
postid: 999,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.post('/posts/addpost', newPost, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
const response = await axios.post('/posts/addpost', newPost, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (response.startsWith("增加动态成功!")) {
|
|
|
|
|
const postid = response.replace("增加动态成功!", '').trim();
|
|
|
|
|
this.$message.success("增加动态成功!");
|
|
|
|
|
newPost.postid = postid;
|
|
|
|
|
newPost.imageurl=this.imageUrl;
|
|
|
|
|
this.$emit('post-submitted', newPost);
|
|
|
|
|
|
|
|
|
|
this.form.content = '';
|
|
|
|
|
this.imageUrl = '';
|
|
|
|
|
this.fileList = [];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.error(response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(response.startsWith("增加动态成功!"))
|
|
|
|
|
{
|
|
|
|
|
const postid = response.replace("增加动态成功!", '').trim();
|
|
|
|
|
this.$message.success("增加动态成功!");
|
|
|
|
|
newPost.postid=postid;
|
|
|
|
|
this.$emit('post-submitted', newPost);
|
|
|
|
|
|
|
|
|
|
this.form.content = '';
|
|
|
|
|
this.imageUrl = '';
|
|
|
|
|
this.fileList = [];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
console.error(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('发布动态失败:', error);
|
|
|
|
|
this.$message.error('发布动态失败,请刷新后再试');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('发布动态失败:', error);
|
|
|
|
|
this.$message.error('发布动态失败,请刷新后再试');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -180,22 +210,23 @@
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
/* 覆盖选中时的颜色 */
|
|
|
|
|
.el-radio.is-checked .el-radio__inner {
|
|
|
|
|
border-color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio.is-checked .el-radio__label {
|
|
|
|
|
color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio .el-radio__inner {
|
|
|
|
|
border-color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio .el-radio__label {
|
|
|
|
|
color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
/* 覆盖选中时的颜色 */
|
|
|
|
|
.el-radio.is-checked .el-radio__inner {
|
|
|
|
|
border-color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio.is-checked .el-radio__label {
|
|
|
|
|
color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio .el-radio__inner {
|
|
|
|
|
border-color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-radio .el-radio__label {
|
|
|
|
|
color: #FE4E96 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
@ -239,8 +270,9 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.animate-card__layer {
|
|
|
|
|
height: 5%;
|
|
|
|
|
width: 5%;
|
|
|
|
|
height: 16px;
|
|
|
|
|
width: 7%;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
background-color: #FE4E96;
|
|
|
|
|
border: none;
|
|
|
|
|
}
|
|
|
|
|