|
@@ -1,193 +1,208 @@
|
|
|
<template>
|
|
|
- <view class="container">
|
|
|
- <view class="top-box">
|
|
|
- <u--textarea border='none' v-model="textContent" count placeholder="写下自己的感受分享给更多人"></u--textarea>
|
|
|
- <view class="upload-box">
|
|
|
- <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
|
|
|
- :maxCount="9"></u-upload>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <view class="item-box" @click="handlerGetLocation">
|
|
|
- <view class="item-left">
|
|
|
- <u-icon name="map" size='22'></u-icon>
|
|
|
- <span class="fs-bold">你在哪里</span>
|
|
|
- <span class="left-text">(越详细越容易被推荐噢)</span>
|
|
|
- </view>
|
|
|
- <view class="item-right">
|
|
|
- <u-icon name="arrow-right"></u-icon>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <view class="btn-box">
|
|
|
- <button class="btn" @click="handlerPublishBtn">发布</button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
+ <view class="container">
|
|
|
+ <view class="top-box">
|
|
|
+ <u--textarea
|
|
|
+ border="none"
|
|
|
+ v-model="textContent"
|
|
|
+ count
|
|
|
+ placeholder="写下自己的感受分享给更多人"
|
|
|
+ ></u--textarea>
|
|
|
+ <view class="upload-box">
|
|
|
+ <u-upload
|
|
|
+ :fileList="fileList1"
|
|
|
+ @afterRead="afterRead"
|
|
|
+ @delete="deletePic"
|
|
|
+ name="1"
|
|
|
+ multiple
|
|
|
+ :maxCount="9"
|
|
|
+ ></u-upload>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="item-box" @click="handlerGetLocation">
|
|
|
+ <view class="item-left">
|
|
|
+ <u-icon name="map" size="22"></u-icon>
|
|
|
+ <span class="fs-bold">你在哪里</span>
|
|
|
+ <span class="left-text">(越详细越容易被推荐噢)</span>
|
|
|
+ </view>
|
|
|
+ <view class="item-right">
|
|
|
+ <u-icon name="arrow-right"></u-icon>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="btn-box">
|
|
|
+ <button class="btn" @click="handlerPublishBtn">发 布</button>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import { addClientContent } from '@/api/client/community.js';
|
|
|
- export default {
|
|
|
- data() {
|
|
|
- return {
|
|
|
- textContent: '',
|
|
|
- fileList1: [],
|
|
|
- userId:null
|
|
|
- }
|
|
|
- },
|
|
|
- mounted(){
|
|
|
- this.userId = this.$store.state.user.userMessage.id
|
|
|
+import { addClientContent } from '@/api/client/community.js';
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ textContent: '',
|
|
|
+ fileList1: [],
|
|
|
+ userId: null,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.userId = this.$store.state.user.userMessage.id;
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取当前定位
|
|
|
+ handlerGetLocation() {
|
|
|
+ wx.getLocation({
|
|
|
+ type: 'gcj02',
|
|
|
+ success(res) {
|
|
|
+ console.log('@@@@res', res);
|
|
|
+ },
|
|
|
+ fail(error) {
|
|
|
+ console.log('error', error);
|
|
|
+ },
|
|
|
+ });
|
|
|
},
|
|
|
- methods: {
|
|
|
- // 获取当前定位
|
|
|
- handlerGetLocation() {
|
|
|
- wx.getLocation({
|
|
|
- type: 'gcj02',
|
|
|
- success(res) {
|
|
|
- console.log("@@@@res", res);
|
|
|
- },
|
|
|
- fail(error){
|
|
|
- console.log("error", error);
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- // 点击发布按钮
|
|
|
- handlerPublishBtn(){
|
|
|
- let params = {
|
|
|
- textContent:this.textContent,
|
|
|
- status:0, // 状态:0-正常;1-屏蔽
|
|
|
- type:'PURE_TEXT', // 动态类型:1-纯文字;2-图片;3-视频 允许值: PURE_TEXT, PHOTO, VIDEO
|
|
|
- location:'山东潍坊', // 定位
|
|
|
- userId:this.userId,
|
|
|
- }
|
|
|
- console.log("@@@@params",params);
|
|
|
- addClientContent(params).then(res=>{
|
|
|
- console.log("addClientContent",res);
|
|
|
- // if(res.code == 200){
|
|
|
- // uni.showToast({
|
|
|
- // title:'发布成功',
|
|
|
- // icon:'none'
|
|
|
- // })
|
|
|
- // this.textContent = ''
|
|
|
- // setTimeout(()=>{
|
|
|
- // uni.navigateBack(-1)
|
|
|
- // },1500)
|
|
|
- // }else{
|
|
|
- // uni.showToast({
|
|
|
- // title:res.msg,
|
|
|
- // icon:'none'
|
|
|
- // })
|
|
|
- // return
|
|
|
- // }
|
|
|
- })
|
|
|
- },
|
|
|
- // 删除图片
|
|
|
- deletePic(event) {
|
|
|
- this[`fileList${event.name}`].splice(event.index, 1)
|
|
|
- },
|
|
|
- // 新增图片
|
|
|
- async afterRead(event) {
|
|
|
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
|
|
- let lists = [].concat(event.file)
|
|
|
- let fileListLen = this[`fileList${event.name}`].length
|
|
|
- lists.map((item) => {
|
|
|
- this[`fileList${event.name}`].push({
|
|
|
- ...item,
|
|
|
- status: 'uploading',
|
|
|
- message: '上传中'
|
|
|
- })
|
|
|
- })
|
|
|
- for (let i = 0; i < lists.length; i++) {
|
|
|
- const result = await this.uploadFilePromise(lists[i].url)
|
|
|
- let item = this[`fileList${event.name}`][fileListLen]
|
|
|
- this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
|
|
|
- status: 'success',
|
|
|
- message: '',
|
|
|
- url: result
|
|
|
- }))
|
|
|
- fileListLen++
|
|
|
- }
|
|
|
- },
|
|
|
- uploadFilePromise(url) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let a = uni.uploadFile({
|
|
|
- url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
|
|
|
- filePath: url,
|
|
|
- name: 'file',
|
|
|
- formData: {
|
|
|
- user: 'test'
|
|
|
- },
|
|
|
- success: (res) => {
|
|
|
- setTimeout(() => {
|
|
|
- resolve(res.data.data)
|
|
|
- }, 1000)
|
|
|
- }
|
|
|
- });
|
|
|
- })
|
|
|
- },
|
|
|
- }
|
|
|
- }
|
|
|
+ // 点击发布按钮
|
|
|
+ handlerPublishBtn() {
|
|
|
+ let params = {
|
|
|
+ textContent: this.textContent,
|
|
|
+ status: 0, // 状态:0-正常;1-屏蔽
|
|
|
+ type: 'PURE_TEXT', // 动态类型:1-纯文字;2-图片;3-视频 允许值: PURE_TEXT, PHOTO, VIDEO
|
|
|
+ location: '山东潍坊', // 定位
|
|
|
+ userId: this.userId,
|
|
|
+ };
|
|
|
+ console.log('@@@@params', params);
|
|
|
+ addClientContent(params).then(res => {
|
|
|
+ console.log('addClientContent', res);
|
|
|
+ // if(res.code == 200){
|
|
|
+ // uni.showToast({
|
|
|
+ // title:'发布成功',
|
|
|
+ // icon:'none'
|
|
|
+ // })
|
|
|
+ // this.textContent = ''
|
|
|
+ // setTimeout(()=>{
|
|
|
+ // uni.navigateBack(-1)
|
|
|
+ // },1500)
|
|
|
+ // }else{
|
|
|
+ // uni.showToast({
|
|
|
+ // title:res.msg,
|
|
|
+ // icon:'none'
|
|
|
+ // })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ deletePic(event) {
|
|
|
+ this[`fileList${event.name}`].splice(event.index, 1);
|
|
|
+ },
|
|
|
+ // 新增图片
|
|
|
+ async afterRead(event) {
|
|
|
+ // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
|
|
+ let lists = [].concat(event.file);
|
|
|
+ let fileListLen = this[`fileList${event.name}`].length;
|
|
|
+ lists.map(item => {
|
|
|
+ this[`fileList${event.name}`].push({
|
|
|
+ ...item,
|
|
|
+ status: 'uploading',
|
|
|
+ message: '上传中',
|
|
|
+ });
|
|
|
+ });
|
|
|
+ for (let i = 0; i < lists.length; i++) {
|
|
|
+ const result = await this.uploadFilePromise(lists[i].url);
|
|
|
+ let item = this[`fileList${event.name}`][fileListLen];
|
|
|
+ this[`fileList${event.name}`].splice(
|
|
|
+ fileListLen,
|
|
|
+ 1,
|
|
|
+ Object.assign(item, {
|
|
|
+ status: 'success',
|
|
|
+ message: '',
|
|
|
+ url: result,
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ fileListLen++;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ uploadFilePromise(url) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let a = uni.uploadFile({
|
|
|
+ url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
|
|
|
+ filePath: url,
|
|
|
+ name: 'file',
|
|
|
+ formData: {
|
|
|
+ user: 'test',
|
|
|
+ },
|
|
|
+ success: res => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(res.data.data);
|
|
|
+ }, 1000);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
- .container {
|
|
|
- position: relative;
|
|
|
- background-color: #F5F7F9;
|
|
|
- height: 100vh;
|
|
|
+.container {
|
|
|
+ position: relative;
|
|
|
+ background-color: #f5f7f9;
|
|
|
+ height: 100vh;
|
|
|
|
|
|
- .top-box,
|
|
|
- .item-box {
|
|
|
- padding: 20rpx;
|
|
|
- background-color: #fff;
|
|
|
- border-radius: 20rpx;
|
|
|
+ .top-box,
|
|
|
+ .item-box {
|
|
|
+ padding: 20rpx;
|
|
|
+ background-color: #fff;
|
|
|
+ border-radius: 20rpx;
|
|
|
|
|
|
- .upload-box {
|
|
|
- margin-top: 20rpx;
|
|
|
- }
|
|
|
- }
|
|
|
+ .upload-box {
|
|
|
+ margin-top: 20rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- .item-box {
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- align-items: center;
|
|
|
- margin-top: 20rpx;
|
|
|
+ .item-box {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ margin-top: 20rpx;
|
|
|
|
|
|
- .item-left {
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- }
|
|
|
- }
|
|
|
+ .item-left {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- .btn-box {
|
|
|
- position: absolute;
|
|
|
- bottom: 0;
|
|
|
- background-color: #fff;
|
|
|
- height: 100rpx;
|
|
|
- padding: 20rpx;
|
|
|
- width: 95%;
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
+ .btn-box {
|
|
|
+ position: absolute;
|
|
|
+ bottom: 70rpx;
|
|
|
+ background-color: #fff;
|
|
|
+ height: 100rpx;
|
|
|
+ padding: 20rpx;
|
|
|
+ width: 95%;
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
|
|
|
- .btn {
|
|
|
- width: 80%;
|
|
|
- border-radius: 20rpx;
|
|
|
- font-size: 28rpx;
|
|
|
- color: #000;
|
|
|
- background-color: #FECF4C;
|
|
|
- height: 80rpx;
|
|
|
- line-height: 80rpx;
|
|
|
- }
|
|
|
- }
|
|
|
+ .btn {
|
|
|
+ width: 80%;
|
|
|
+ border-radius: 20rpx;
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #000;
|
|
|
+ background-color: #fecf4c;
|
|
|
+ height: 80rpx;
|
|
|
+ line-height: 80rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- .fs-bold {
|
|
|
- font-weight: bold;
|
|
|
- font-size: 28rpx;
|
|
|
- color: #000;
|
|
|
- margin-left: 10rpx;
|
|
|
- }
|
|
|
+ .fs-bold {
|
|
|
+ font-weight: bold;
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #000;
|
|
|
+ margin-left: 10rpx;
|
|
|
+ }
|
|
|
|
|
|
- .left-text {
|
|
|
- color: #a6a7a8;
|
|
|
- font-size: 28rpx;
|
|
|
- margin-left: 10rpx;
|
|
|
- }
|
|
|
- }
|
|
|
+ .left-text {
|
|
|
+ color: #a6a7a8;
|
|
|
+ font-size: 28rpx;
|
|
|
+ margin-left: 10rpx;
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|