|
|
@@ -29,8 +29,18 @@
|
|
|
<img class="img" src="../../static/index/photo.png" />
|
|
|
<view class="msg">照片/视频</view>
|
|
|
</view>
|
|
|
- <view class="uploading_box" v-for="(ele, index) in subImgList" :key="index">
|
|
|
- <img class="img2" mode="aspectFill" :src="ele" />
|
|
|
+ <view class="uploading_box" v-for="(ele, index) in viewImgList" :key="index">
|
|
|
+ <img class="img2" mode="aspectFill" v-if="ele.fileType === 'image'" :src="ele.url" @click="handleLook(ele.url, index)" />
|
|
|
+ <video
|
|
|
+ id="myVideo"
|
|
|
+ class="video"
|
|
|
+ :show-fullscreen-btn="false"
|
|
|
+ :show-play-btn="false"
|
|
|
+ v-if="ele.fileType === 'video'"
|
|
|
+ :src="ele.url"
|
|
|
+ @fullscreenchange="fullscreenchange"
|
|
|
+ @click="handleClickVideo('myVideo')"
|
|
|
+ ></video>
|
|
|
<view class="icon" @click="handleDelete(index)">
|
|
|
<img src="../../static/index/close2.png" />
|
|
|
</view>
|
|
|
@@ -40,10 +50,25 @@
|
|
|
|
|
|
<!-- 提交按钮区域 -->
|
|
|
<view class="btn" @click="handleSub">提交</view>
|
|
|
+
|
|
|
+ <!-- 用于图片压缩的canvas画布 -->
|
|
|
+ <canvas
|
|
|
+ :style="{
|
|
|
+ width: cw + 'px',
|
|
|
+ height: cw + 'px',
|
|
|
+ position: 'absolute',
|
|
|
+ zIndex: -1,
|
|
|
+ left: '-10000rpx',
|
|
|
+ top: '-10000rpx'
|
|
|
+ }"
|
|
|
+ canvas-id="zipCanvas"
|
|
|
+ ></canvas>
|
|
|
+ <!--画布结束-->
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import getLessLimitSizeImage from '../../util/imageCompress.js'
|
|
|
var dayjs = require('dayjs')
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -56,12 +81,20 @@ export default {
|
|
|
textareaValuelength: 0,
|
|
|
// 上传的图片数据
|
|
|
subImgList: [],
|
|
|
+ // 显示的图片数据
|
|
|
+ viewImgList: [],
|
|
|
// 订单id
|
|
|
bookingId: '',
|
|
|
// 民宿id
|
|
|
hotelId: '',
|
|
|
// 房间id
|
|
|
- houseId: ''
|
|
|
+ houseId: '',
|
|
|
+ //画板边长默认是屏幕宽度,正方形画布
|
|
|
+ cw: uni.getSystemInfoSync().windowWidth,
|
|
|
+ // video 上下文 videoContext 对象
|
|
|
+ videoContext: null,
|
|
|
+ // 是否是全屏状态
|
|
|
+ isFullScreen: false
|
|
|
}
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
@@ -70,6 +103,21 @@ export default {
|
|
|
this.houseId = options.houseId
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 进入全屏和退出全屏时触发的回调
|
|
|
+ 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()
|
|
|
+ }
|
|
|
+ },
|
|
|
// 评价输入框输入回调
|
|
|
handleInput(e) {
|
|
|
this.textareaValuelength = e.detail.cursor
|
|
|
@@ -77,54 +125,116 @@ export default {
|
|
|
// 上传图片回调
|
|
|
handleUpLoad() {
|
|
|
uni.chooseMedia({
|
|
|
- count: 9,
|
|
|
- maxDuration: 15,
|
|
|
+ count: 6,
|
|
|
+ mediaType: ['mix'],
|
|
|
success: (res) => {
|
|
|
- console.log(res)
|
|
|
- console.log(res.tempFiles)
|
|
|
- if (this.subImgList.length + res.tempFiles.length > 9) {
|
|
|
+ // console.log(res)
|
|
|
+ // console.log(res.tempFiles)
|
|
|
+ // 判断文件不能超过6个
|
|
|
+ if (this.subImgList.length + res.tempFiles.length > 6) {
|
|
|
uni.showToast({
|
|
|
- title: '最多只能上传9个图片/视频',
|
|
|
+ title: '最多只能上传6个图片/视频',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- uni.showLoading({
|
|
|
- title: '上传中'
|
|
|
- })
|
|
|
- // reverse()
|
|
|
+ // 判断视频文件不能超过1个
|
|
|
+ let temList = [...this.viewImgList, ...res.tempFiles]
|
|
|
+ let temList2 = temList.filter((ele) => ele.fileType === 'video')
|
|
|
+ if (temList2.length > 1) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '最多只能上传1个视频',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
res.tempFiles.forEach((ele) => {
|
|
|
- uni.uploadFile({
|
|
|
- url: `https://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
|
|
|
- filePath: ele.tempFilePath,
|
|
|
- name: 'myFile',
|
|
|
- success: (uploadFileRes) => {
|
|
|
- console.log(JSON.parse(uploadFileRes.data))
|
|
|
- let temRes = JSON.parse(uploadFileRes.data)
|
|
|
- if (temRes.code === 200) {
|
|
|
- this.subImgList.push(temRes.data.url)
|
|
|
- console.log(this.subImgList)
|
|
|
- uni.hideLoading()
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: temRes.message,
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
+ if (ele.fileType === 'image' && ele.size > 1024 * 1024 * 3) {
|
|
|
+ //这里的id和页面中写的html代码的canvas的id要一致
|
|
|
+ let canvasId = 'zipCanvas'
|
|
|
+ //原图的路径
|
|
|
+ let imagePath = ele.tempFilePath
|
|
|
+ //大小限制1024kb
|
|
|
+ let limitSize = 1024 * 3
|
|
|
+ //初始绘画区域是画布自身的宽度也就是屏幕宽度
|
|
|
+ let drawWidth = uni.getSystemInfoSync().windowWidth
|
|
|
+ // 图片过大压缩
|
|
|
+ getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
|
|
|
+ this.handleUploadMini({ tempFilePath: resPath, fileType: ele.fileType })
|
|
|
+ })
|
|
|
+ } else if (ele.fileType === 'video' && ele.size > 1024 * 1024 * 5) {
|
|
|
+ // 视频过大压缩
|
|
|
+ uni.compressVideo({
|
|
|
+ src: ele.tempFilePath,
|
|
|
+ quality: 'low',
|
|
|
+ // bitrate: 60000,
|
|
|
+ // fps: 30,
|
|
|
+ // resolution: 1,
|
|
|
+ success: (res) => {
|
|
|
+ // console.log('压缩后', res)
|
|
|
+ this.handleUploadMini({ tempFilePath: res.tempFilePath, fileType: ele.fileType })
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ // console.log(err)
|
|
|
+ uni.showToast(
|
|
|
+ {
|
|
|
+ title: '视频压缩失败',
|
|
|
+ icon: 'none'
|
|
|
+ },
|
|
|
+ 2000
|
|
|
+ )
|
|
|
}
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- uni.showToast({
|
|
|
- title: '上传失败',
|
|
|
- icon: 'error'
|
|
|
- })
|
|
|
- }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.handleUploadMini(ele)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleUploadMini(ele) {
|
|
|
+ // console.log(ele)
|
|
|
+ // 开始上传
|
|
|
+ uni.showLoading({
|
|
|
+ title: '上传中'
|
|
|
+ })
|
|
|
+ uni.uploadFile({
|
|
|
+ // url: `https://chtech.ncjti.edu.cn/hotelReservation/mhotel/mhotel/uploadhimage.action`,
|
|
|
+ url: `https://chtech.ncjti.edu.cn/homestay/file/cos/upload`,
|
|
|
+ filePath: ele.tempFilePath,
|
|
|
+ // name: 'myFile',
|
|
|
+ name: 'files',
|
|
|
+ success: (uploadFileRes) => {
|
|
|
+ // console.log(JSON.parse(uploadFileRes.data))
|
|
|
+ let temRes = JSON.parse(uploadFileRes.data)
|
|
|
+ if (temRes.code === 200 || temRes.code === 1) {
|
|
|
+ this.subImgList.push(temRes.data)
|
|
|
+ // console.log(this.subImgList)
|
|
|
+ this.viewImgList.push({
|
|
|
+ url: temRes.data,
|
|
|
+ fileType: ele.fileType === 'image' ? 'image' : 'video'
|
|
|
})
|
|
|
+ // console.log(this.viewImgList)
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: temRes.message || '上传失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ uni.hideLoading()
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ uni.showToast({
|
|
|
+ title: '上传失败',
|
|
|
+ icon: 'error'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// 提交按钮回调
|
|
|
async handleSub() {
|
|
|
+ const reg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~!@#¥……&*()——|{}【】‘;:”“'。,、? ]")
|
|
|
if (!this.inputValue) {
|
|
|
uni.showToast({
|
|
|
title: '请输入标题',
|
|
|
@@ -133,6 +243,14 @@ export default {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
+ if (reg.test(this.inputValue)) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '标题不能含有特殊字符和标点符号',
|
|
|
+ icon: 'none',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!this.textareaValue) {
|
|
|
uni.showToast({
|
|
|
title: '请输入投诉内容',
|
|
|
@@ -171,6 +289,16 @@ export default {
|
|
|
// 删除图片回调
|
|
|
handleDelete(index) {
|
|
|
this.subImgList.splice(index, 1)
|
|
|
+ this.viewImgList.splice(index, 1)
|
|
|
+ },
|
|
|
+ handleLook(url, current) {
|
|
|
+ if (this.videoContext) {
|
|
|
+ this.videoContext.stop()
|
|
|
+ }
|
|
|
+ uni.previewImage({
|
|
|
+ urls: [url],
|
|
|
+ current
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -277,6 +405,12 @@ export default {
|
|
|
border-radius: 7rpx;
|
|
|
}
|
|
|
|
|
|
+ .video {
|
|
|
+ width: 124rpx;
|
|
|
+ height: 124rpx;
|
|
|
+ border-radius: 7rpx;
|
|
|
+ }
|
|
|
+
|
|
|
.icon {
|
|
|
position: absolute;
|
|
|
top: 0;
|