|
|
@@ -13,14 +13,37 @@
|
|
|
|
|
|
<!-- 图片视频上传展示区域 -->
|
|
|
<view class="upload" :style="{ paddingTop: statusBarH * 2 + customBarH * 2 + 'rpx' }">
|
|
|
- <view class="upload_img" @click="handleImage">
|
|
|
+ <view v-if="subImgList.length < maxImgCount && !subVideo" class="upload_img" @click="handleImage">
|
|
|
<img src="../../static/index/upload-img.png" />
|
|
|
添加图片
|
|
|
</view>
|
|
|
- <view class="upload_video" @click="handleVideo">
|
|
|
+ <view v-if="!subImgList.length && !subVideo" class="upload_video" @click="handleVideo">
|
|
|
<img src="../../static/index/upload-video.png" />
|
|
|
添加视频
|
|
|
</view>
|
|
|
+
|
|
|
+ <!-- 图片展示区域 -->
|
|
|
+ <view class="upload_imgBox" v-for="(item, index) in subImgList" :key="index">
|
|
|
+ <img mode="aspectFill" :src="item" @click="handleLookImg(subImgList, index)" />
|
|
|
+ <view class="icon" @click="handleDelete(index)">
|
|
|
+ <img src="../../static/index/close2.png" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 视频展示区域 -->
|
|
|
+ <view v-if="subVideo" class="upload_VideoBox">
|
|
|
+ <video
|
|
|
+ id="myVideo"
|
|
|
+ :show-fullscreen-btn="false"
|
|
|
+ :show-play-btn="false"
|
|
|
+ :src="subVideo"
|
|
|
+ @fullscreenchange="fullscreenchange"
|
|
|
+ @click="handleClickVideo('myVideo')"
|
|
|
+ ></video>
|
|
|
+ <view class="icon" @click="handleDeleteVideo">
|
|
|
+ <img src="../../static/index/close2.png" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
|
|
|
<!-- 标题输入区域 -->
|
|
|
@@ -36,14 +59,14 @@
|
|
|
</view>
|
|
|
|
|
|
<!-- 添加地点区域 -->
|
|
|
- <view class="add_place" @click="handleGoPage('/pages/addPlace/addPlace')">
|
|
|
+ <view class="add_place" @click="handleGoPage">
|
|
|
<img class="img" src="../../static/index/send-address.png" />
|
|
|
添加地点
|
|
|
<img class="img2" src="../../static/index/send-right.png" />
|
|
|
</view>
|
|
|
|
|
|
<!-- 关联民宿区域 -->
|
|
|
- <view class="and">
|
|
|
+ <view class="and" v-if="andList.length">
|
|
|
<img class="img" src="../../static/index/send-binding.png" />
|
|
|
关联民宿
|
|
|
</view>
|
|
|
@@ -64,10 +87,26 @@
|
|
|
<view class="btn" @click="handleClickLook">查看推文</view>
|
|
|
</view>
|
|
|
</uni-popup>
|
|
|
+
|
|
|
+ <!-- 用于图片压缩的canvas画布 -->
|
|
|
+ <canvas
|
|
|
+ :style="{
|
|
|
+ width: cw + 'px',
|
|
|
+ height: cw + 'px',
|
|
|
+ position: 'absolute',
|
|
|
+ zIndex: -1,
|
|
|
+ left: '-10000rpx',
|
|
|
+ top: '-10000rpx'
|
|
|
+ }"
|
|
|
+ canvas-id="zipCanvas3"
|
|
|
+ ></canvas>
|
|
|
+ <!--画布结束-->
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+// 图片压缩方法
|
|
|
+import getLessLimitSizeImage from '@/util/imageCompress.js'
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -83,7 +122,17 @@ export default {
|
|
|
contentValue: '',
|
|
|
// activeIndex: null,
|
|
|
// 关联民宿列表
|
|
|
- andList: []
|
|
|
+ andList: [],
|
|
|
+ // 上传的图片数据
|
|
|
+ subImgList: [],
|
|
|
+ // 最大上传图片张图
|
|
|
+ maxImgCount: 9,
|
|
|
+ // 上传的视频数据
|
|
|
+ subVideo: '',
|
|
|
+ // video 上下文 videoContext 对象
|
|
|
+ videoContext: null,
|
|
|
+ // 是否是全屏状态
|
|
|
+ isFullScreen: false
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
@@ -112,32 +161,136 @@ export default {
|
|
|
// 切换关联民宿回调
|
|
|
handleChange(item) {
|
|
|
item.is_collect_hotel = !item.is_collect_hotel
|
|
|
- // this.activeIndex = index
|
|
|
},
|
|
|
// 点击添加图片回调
|
|
|
handleImage() {
|
|
|
uni.chooseMedia({
|
|
|
- count: 9,
|
|
|
+ count: this.maxImgCount - this.subImgList.length,
|
|
|
mediaType: ['image'],
|
|
|
+ sizeType: ['compressed'],
|
|
|
success: (res) => {
|
|
|
- console.log(res.tempFiles)
|
|
|
+ res.tempFiles.forEach((ele) => {
|
|
|
+ //这里的id和页面中写的html代码的canvas的id要一致
|
|
|
+ let canvasId = 'zipCanvas3'
|
|
|
+ //原图的路径
|
|
|
+ let imagePath = ele.tempFilePath
|
|
|
+ //大小限制1024kb
|
|
|
+ let limitSize = 1024 * 3
|
|
|
+ //初始绘画区域是画布自身的宽度也就是屏幕宽度
|
|
|
+ let drawWidth = uni.getSystemInfoSync().windowWidth
|
|
|
+ // 图片过大压缩
|
|
|
+ getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
|
|
|
+ this.handleUploadMini(resPath, 1)
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// 点击添加视频回调
|
|
|
handleVideo() {
|
|
|
uni.chooseMedia({
|
|
|
- count: 9,
|
|
|
+ count: 1,
|
|
|
mediaType: ['video'],
|
|
|
success: (res) => {
|
|
|
- console.log(res.tempFiles)
|
|
|
+ res.tempFiles.forEach((ele) => {
|
|
|
+ if (ele.size > 1024 * 1024 * 5) {
|
|
|
+ // 视频过大压缩
|
|
|
+ uni.compressVideo({
|
|
|
+ src: ele.tempFilePath,
|
|
|
+ quality: 'low',
|
|
|
+ success: (res) => {
|
|
|
+ // console.log('压缩后', res)
|
|
|
+ this.handleUploadMini(res.tempFilePath, 2)
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ // console.log(err)
|
|
|
+ uni.showToast(
|
|
|
+ {
|
|
|
+ title: '视频压缩失败',
|
|
|
+ icon: 'none'
|
|
|
+ },
|
|
|
+ 2000
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.handleUploadMini(ele.tempFilePath, 2)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 上传请求
|
|
|
+ handleUploadMini(ele, type) {
|
|
|
+ // 开始上传
|
|
|
+ uni.showLoading({
|
|
|
+ title: '上传中'
|
|
|
+ })
|
|
|
+ uni.uploadFile({
|
|
|
+ url: `https://chtech.ncjti.edu.cn/homestay/file/cos/upload`,
|
|
|
+ filePath: ele,
|
|
|
+ name: 'files',
|
|
|
+ success: (uploadFileRes) => {
|
|
|
+ // console.log(JSON.parse(uploadFileRes.data))
|
|
|
+ let temRes = JSON.parse(uploadFileRes.data)
|
|
|
+ if (temRes.code === 200 || temRes.code === 1) {
|
|
|
+ if (type === 1) {
|
|
|
+ this.subImgList.push(temRes.data)
|
|
|
+ } else if (type === 2) {
|
|
|
+ this.subVideo = temRes.data
|
|
|
+ }
|
|
|
+
|
|
|
+ // console.log(this.subImgList)
|
|
|
+ // console.log(this.subVideo)
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: temRes.message || '上传失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ uni.showToast({
|
|
|
+ title: '上传失败',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ uni.hideLoading({
|
|
|
+ complete: (hide) => {}
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 删除图片回调
|
|
|
+ handleDelete(index) {
|
|
|
+ this.subImgList.splice(index, 1)
|
|
|
+ },
|
|
|
+ // 删除视频回调
|
|
|
+ handleDeleteVideo() {
|
|
|
+ this.subVideo = ''
|
|
|
+ },
|
|
|
+ // 进入全屏和退出全屏时触发的回调
|
|
|
+ fullscreenchange(e) {
|
|
|
+ this.isFullScreen = e.detail.fullScreen
|
|
|
+ },
|
|
|
+ // 点击视频控件时触发的回调
|
|
|
+ handleClickVideo(id) {
|
|
|
+ this.videoContext = uni.createVideoContext(id)
|
|
|
+ if (this.isFullScreen) {
|
|
|
+ this.videoContext.stop()
|
|
|
+ this.videoContext.exitFullScreen()
|
|
|
+ } else {
|
|
|
+ this.videoContext.requestFullScreen()
|
|
|
+ this.videoContext.play()
|
|
|
+ }
|
|
|
+ },
|
|
|
// 点击添加地点回调
|
|
|
- handleGoPage(url) {
|
|
|
+ handleGoPage() {
|
|
|
+ this.andList = this.andList.filter((ele) => ele.is_collect_hotel)
|
|
|
+ const list = JSON.stringify(this.andList)
|
|
|
uni.navigateTo({
|
|
|
- url
|
|
|
+ url: `/pages/addPlace/addPlace?list=${list}`
|
|
|
})
|
|
|
},
|
|
|
// 全局自定义事件
|
|
|
@@ -146,15 +299,50 @@ export default {
|
|
|
},
|
|
|
// 点击发布按钮回调
|
|
|
handleClickSub() {
|
|
|
- console.log(this.andList)
|
|
|
+ if (!this.subImgList.length && !this.subVideo) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请上传图片或者视频',
|
|
|
+ icon: 'none',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.titleValue) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请输入标题',
|
|
|
+ icon: 'none',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.contentValue) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请分享你的故事吧~',
|
|
|
+ icon: 'none',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
let temList = this.andList.filter((ele) => ele.is_collect_hotel)
|
|
|
console.log(temList)
|
|
|
+ console.log(this.subImgList)
|
|
|
+ console.log(this.subVideo)
|
|
|
+ console.log(this.titleValue)
|
|
|
+ console.log(this.contentValue)
|
|
|
this.$refs.popup.open()
|
|
|
},
|
|
|
// 点击弹窗查看推文按钮回调
|
|
|
handleClickLook() {
|
|
|
this.$refs.popup.close()
|
|
|
},
|
|
|
+ // 点击图片回调
|
|
|
+ handleLookImg(urls, current) {
|
|
|
+ uni.previewImage({
|
|
|
+ urls,
|
|
|
+ current
|
|
|
+ })
|
|
|
+ },
|
|
|
handleBack() {
|
|
|
uni.navigateBack(1)
|
|
|
}
|
|
|
@@ -169,6 +357,7 @@ export default {
|
|
|
background-color: #fff;
|
|
|
|
|
|
.header {
|
|
|
+ z-index: 1;
|
|
|
position: fixed;
|
|
|
top: 0;
|
|
|
left: 0;
|
|
|
@@ -192,6 +381,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
.header2 {
|
|
|
+ z-index: 1;
|
|
|
position: fixed;
|
|
|
top: 0;
|
|
|
left: 0;
|
|
|
@@ -217,6 +407,7 @@ export default {
|
|
|
margin-top: 30rpx;
|
|
|
padding-bottom: 10rpx;
|
|
|
display: flex;
|
|
|
+ flex-wrap: wrap;
|
|
|
|
|
|
.upload_img {
|
|
|
display: flex;
|
|
|
@@ -257,6 +448,67 @@ export default {
|
|
|
height: 68rpx;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ .upload_imgBox {
|
|
|
+ position: relative;
|
|
|
+ margin-left: 20rpx;
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+ width: 186rpx;
|
|
|
+ height: 283rpx;
|
|
|
+
|
|
|
+ img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .icon {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ right: 0;
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ width: 30rpx;
|
|
|
+ height: 30rpx;
|
|
|
+ border-radius: 7rpx;
|
|
|
+ background-color: rgba(000, 000, 000, 0.5);
|
|
|
+
|
|
|
+ img {
|
|
|
+ width: 30rpx;
|
|
|
+ height: 30rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .upload_VideoBox {
|
|
|
+ position: relative;
|
|
|
+ margin-left: 20rpx;
|
|
|
+ width: 186rpx;
|
|
|
+ height: 283rpx;
|
|
|
+
|
|
|
+ video {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .icon {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ right: 0;
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ width: 30rpx;
|
|
|
+ height: 30rpx;
|
|
|
+ border-radius: 7rpx;
|
|
|
+ background-color: rgba(000, 000, 000, 0.5);
|
|
|
+
|
|
|
+ img {
|
|
|
+ width: 30rpx;
|
|
|
+ height: 30rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
.title {
|
|
|
@@ -279,7 +531,6 @@ export default {
|
|
|
width: 710rpx;
|
|
|
height: 290rpx;
|
|
|
font-size: 28rpx;
|
|
|
- color: #b3b3b3;
|
|
|
border-bottom: 1rpx solid #e5e5e5;
|
|
|
|
|
|
.textarea {
|