This commit is contained in:
linfeng 2022-09-25 10:45:30 +08:00
parent 0f654e23bb
commit 148965f985

View File

@ -1,19 +1,12 @@
<template> <template>
<view class="container"> <view class="container">
<input v-model="form.title" class="title-input" placeholder="标题" /> <input v-model="form.title" class="title-input" placeholder="标题" />
<textarea placeholder="说些什么叭..." :auto-height="true" maxlength="-1" v-model="form.content" class="content-display"></textarea> <textarea placeholder="说些什么叭..." :auto-height="true" maxlength="-1" v-model="form.content"
class="content-display"></textarea>
<!-- 上传图片 --> <!-- 上传图片 -->
<block v-if="form.type == 1"> <block v-if="form.type == 1">
<u-upload <u-upload ref="uUpload" :size-type="['original']" name="Image" :max-count="4" :header="header"
ref="uUpload" :action="uploadImgUrl" @on-uploaded="submit" :auto-upload="false"></u-upload>
:size-type="['original']"
name="Image"
:max-count="4"
:header="header"
:action="uploadImgUrl"
@on-uploaded="submit"
:auto-upload="false"
></u-upload>
</block> </block>
<!-- 分类 --> <!-- 分类 -->
<view @click="chooseClass" class="choose-item"> <view @click="chooseClass" class="choose-item">
@ -34,145 +27,154 @@
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
btnStyle: { btnStyle: {
color: "#fff", color: "#fff",
backgroundColor: '#333333' backgroundColor: '#333333'
}, },
uploadImgUrl: this.$c.domain + 'common/upload', uploadImgUrl: this.$c.domain + 'common/upload',
form: { form: {
title: '', title: '',
type: 1, type: 1,
topicId: 2, topicId: 2,
discussId: '', discussId: '',
content: '', content: '',
media: [], media: [],
longitude: 0, longitude: 0,
latitude: 0, latitude: 0,
address: '', address: '',
cut: 0,//id cut: 0, //id
pay: '', pay: '',
}, },
cateName:'', cateName: '',
header: { header: {
token: uni.getStorageSync('token') token: uni.getStorageSync('token')
}, },
}; };
},
onLoad(options) {
this.form.longitude = location.longitude;
this.form.latitude = location.latitude;
},
methods: {
chooseClass(){
uni.navigateTo({
url:"category"
})
}, },
uploadImg() { onLoad(options) {
this.form.longitude = location.longitude;
if (!this.form.content) { this.form.latitude = location.latitude;
this.$u.toast('内容不能为空');
return;
}
if (!this.form.title) {
this.$u.toast('标题不能为空');
return;
}
uni.showLoading({
mask: true,
title: '发布中'
});
this.$refs.uUpload.upload();
}, },
chooseLocation() { methods: {
let that = this; chooseClass() {
uni.chooseLocation({ uni.navigateTo({
success: function(res) { url: "category"
that.form.address = res.name; })
that.form.latitude = res.latitude; },
that.form.longitude = res.longitude; uploadImg() {
if (!this.form.content) {
this.$u.toast('内容不能为空');
return;
} }
}); if (!this.form.title) {
}, this.$u.toast('标题不能为空');
submit(e) { return;
uni.showLoading({
mask: true,
title: '发布中'
});
let mediaList = [];
e.forEach(function(item, index) {
mediaList.push(item.response.result);
});
this.form.media = mediaList;
this.$H.post('post/addPost', this.form).then(res => {
if (res.code == 0) {
uni.redirectTo({
url: '/pages/post/post?id=' + res.result
});
} }
uni.hideLoading();
}); uni.showLoading({
mask: true,
title: '发布中'
});
this.$refs.uUpload.upload();
},
chooseLocation() {
let that = this;
uni.chooseLocation({
success: function(res) {
that.form.address = res.name;
that.form.latitude = res.latitude;
that.form.longitude = res.longitude;
}
});
},
submit(e) {
uni.showLoading({
mask: true,
title: '发布中'
});
let mediaList = [];
e.forEach(function(item, index) {
mediaList.push(item.response.result);
});
this.form.media = mediaList;
this.$H.post('post/addPost', this.form).then(res => {
if (res.code == 0) {
uni.redirectTo({
url: '/pages/post/post?id=' + res.result
});
}
uni.hideLoading();
});
}
} }
} };
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.title-input{ .title-input {
border-bottom: 1px solid #F5F5F5; border-bottom: 1px solid #F5F5F5;
margin: 20rpx 0; margin: 20rpx 0;
padding: 20rpx 0; padding: 20rpx 0;
}
.content-display {
width: 100%;
padding: 20rpx 0;
min-height: 300rpx;
}
.choose-item{
display: flex;
align-items: center;
padding: 20rpx;
border-bottom: 1px solid #F5F5F5;
&:last-child{
border: 0;
}
.txt{
margin-left: 20rpx;
}
.sw{
margin-left: 300rpx;
}
.inputStyle{
margin-left: 60rpx;
width: 400rpx;
}
.radio{
margin-left: 320rpx;
}
.icon{
width: 40rpx;
height: 40rpx;
}
.u-icon{
margin-left: auto;
color: #999;
} }
.add-icon{ .content-display {
margin-left: 0; width: 100%;
padding: 20rpx 0;
min-height: 300rpx;
}
.choose-item {
display: flex;
align-items: center;
padding: 20rpx;
border-bottom: 1px solid #F5F5F5;
&:last-child {
border: 0;
}
.txt {
margin-left: 20rpx;
}
.sw {
margin-left: 300rpx;
}
.inputStyle {
margin-left: 60rpx;
width: 400rpx;
}
.radio {
margin-left: 320rpx;
}
.icon {
width: 40rpx;
height: 40rpx;
}
.u-icon {
margin-left: auto;
color: #999;
}
.add-icon {
margin-left: 0;
}
}
.button-style {
margin-top: 50rpx;
color: #F4F4F5;
} }
}
.button-style{
margin-top: 50rpx;
color: #F4F4F5;
}
</style> </style>