230 lines
5.5 KiB
Plaintext
230 lines
5.5 KiB
Plaintext
<template>
|
|
<view class="cc-page">
|
|
<!-- 相机预览 -->
|
|
<ima-camera-view
|
|
ref="cameraRef"
|
|
:style="'width:' + winWidth + 'px;height:' + winHeight + 'px;'"
|
|
flash="off"
|
|
facing="back"
|
|
@onPictureTaken="onPictureTaken"
|
|
@onCameraOpened="onCameraOpened"
|
|
></ima-camera-view>
|
|
|
|
<!-- 顶部 -->
|
|
<view class="cc-topbar" style="padding-top:50px;">
|
|
<text class="cc-topbar-title">{{ capturedList.length > 0 ? '已拍 '+capturedList.length+'/9 张' : '拍照' }}</text>
|
|
<text class="cc-topbar-confirm" @click="confirmCapture">确认 ({{ capturedList.length }})</text>
|
|
</view>
|
|
|
|
<!-- 底部 -->
|
|
<view class="cc-footer" style="padding-bottom:30px;">
|
|
<text class="cc-footer-cancel" @click="goBack">取消</text>
|
|
<view class="cc-capture-btn" @click="capturePhoto">
|
|
<view class="cc-capture-inner"></view>
|
|
</view>
|
|
<view class="cc-flip-btn" @click="flipCamera">
|
|
<text class="cc-flip-icon">↺</text>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 缩略图 -->
|
|
<view class="cc-thumb-bar" v-if="capturedList.length > 0">
|
|
<scroll-view scroll-x="true" show-scrollbar="false" style="flex-direction:row;">
|
|
<view style="flex-direction:row;">
|
|
<view class="cc-thumb-item" v-for="(img, idx) in capturedList" :key="idx">
|
|
<image class="cc-thumb-img" :src="img" mode="aspectFill"></image>
|
|
<view class="cc-thumb-del" @click.stop="deletePhoto(idx)">
|
|
<text class="cc-del-icon">✕</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
capturedList: [],
|
|
cameraReady: false,
|
|
facing: 'back',
|
|
winWidth: 750,
|
|
winHeight: 1334
|
|
}
|
|
},
|
|
onLoad() {
|
|
var that = this
|
|
uni.getSystemInfo({
|
|
success: function(res) {
|
|
that.winWidth = res.windowWidth
|
|
that.winHeight = res.windowHeight
|
|
}
|
|
})
|
|
},
|
|
methods: {
|
|
onCameraOpened() {
|
|
this.cameraReady = true
|
|
console.log('相机已就绪')
|
|
},
|
|
capturePhoto() {
|
|
if (this.capturedList.length >= 9) {
|
|
uni.showToast({ title: '最多拍9张', icon: 'none' })
|
|
return
|
|
}
|
|
if (!this.cameraReady) {
|
|
uni.showToast({ title: '相机未就绪', icon: 'none' })
|
|
return
|
|
}
|
|
this.$refs.cameraRef.takePhoto()
|
|
},
|
|
onPictureTaken(e) {
|
|
var path = ''
|
|
if (e.detail) {
|
|
path = e.detail.path || ''
|
|
}
|
|
if (path) {
|
|
this.capturedList.push(path)
|
|
}
|
|
},
|
|
flipCamera() {
|
|
this.facing = this.facing === 'back' ? 'front' : 'back'
|
|
this.$refs.cameraRef.changeFacing(this.facing)
|
|
},
|
|
deletePhoto(idx) {
|
|
this.capturedList.splice(idx, 1)
|
|
},
|
|
goBack() {
|
|
if (this.capturedList.length > 0) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '确定取消拍照吗?已拍照片将丢失',
|
|
success: function(res) {
|
|
if (res.confirm) { uni.navigateBack() }
|
|
}
|
|
})
|
|
} else {
|
|
uni.navigateBack()
|
|
}
|
|
},
|
|
confirmCapture() {
|
|
if (this.capturedList.length === 0) {
|
|
uni.showToast({ title: '请先拍照', icon: 'none' })
|
|
return
|
|
}
|
|
var pages = getCurrentPages()
|
|
var prevPage = pages[pages.length - 2]
|
|
if (prevPage) {
|
|
prevPage.$vm.capturedPhotoList = this.capturedList
|
|
}
|
|
uni.navigateBack()
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.cc-page {
|
|
flex: 1;
|
|
background-color: #000000;
|
|
}
|
|
/* 顶部 */
|
|
.cc-topbar {
|
|
position: absolute;
|
|
top: 0; left: 0; right: 0;
|
|
height: 100px;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding-left: 30rpx;
|
|
padding-right: 30rpx;
|
|
z-index: 8;
|
|
background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent);
|
|
}
|
|
.cc-topbar-title {
|
|
color: #ffffff;
|
|
font-size: 32rpx;
|
|
font-weight: bold;
|
|
}
|
|
.cc-topbar-confirm {
|
|
color: #409eff;
|
|
font-size: 28rpx;
|
|
font-weight: bold;
|
|
padding-left: 24rpx;
|
|
padding-right: 24rpx;
|
|
padding-top: 10rpx;
|
|
padding-bottom: 10rpx;
|
|
border-radius: 32rpx;
|
|
background-color: rgba(64,158,255,0.15);
|
|
}
|
|
/* 底部 */
|
|
.cc-footer {
|
|
position: absolute;
|
|
bottom: 0; left: 0; right: 0;
|
|
height: 180rpx;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding-left: 40rpx;
|
|
padding-right: 40rpx;
|
|
z-index: 8;
|
|
background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
|
|
}
|
|
.cc-footer-cancel {
|
|
color: #ffffff;
|
|
font-size: 28rpx;
|
|
}
|
|
.cc-capture-btn {
|
|
width: 80rpx; height: 80rpx;
|
|
border-radius: 80rpx;
|
|
border-width: 6rpx; border-color: #ffffff; border-style: solid;
|
|
align-items: center; justify-content: center;
|
|
}
|
|
.cc-capture-inner {
|
|
width: 60rpx; height: 60rpx;
|
|
border-radius: 60rpx;
|
|
background-color: #ffffff;
|
|
}
|
|
.cc-flip-btn {
|
|
width: 64rpx; height: 64rpx;
|
|
border-radius: 64rpx;
|
|
border-width: 2rpx; border-color: rgba(255,255,255,0.4); border-style: solid;
|
|
align-items: center; justify-content: center;
|
|
}
|
|
.cc-flip-icon {
|
|
color: #ffffff;
|
|
font-size: 32rpx;
|
|
}
|
|
/* 缩略图 */
|
|
.cc-thumb-bar {
|
|
position: absolute;
|
|
bottom: 190rpx; left: 0; right: 0;
|
|
padding-left: 20rpx; padding-right: 20rpx; padding-top: 10rpx; padding-bottom: 10rpx;
|
|
z-index: 8;
|
|
}
|
|
.cc-thumb-item {
|
|
width: 100rpx; height: 100rpx;
|
|
border-radius: 8rpx; overflow: hidden;
|
|
position: relative;
|
|
border-width: 2rpx; border-color: rgba(255,255,255,0.3); border-style: solid;
|
|
margin-right: 12rpx;
|
|
background-color: #333333;
|
|
}
|
|
.cc-thumb-img {
|
|
width: 100rpx; height: 100rpx;
|
|
}
|
|
.cc-thumb-del {
|
|
position: absolute;
|
|
top: -6rpx; right: -6rpx;
|
|
width: 32rpx; height: 32rpx;
|
|
border-radius: 32rpx;
|
|
background-color: rgba(0,0,0,0.6);
|
|
align-items: center; justify-content: center;
|
|
}
|
|
.cc-del-icon {
|
|
color: #ffffff;
|
|
font-size: 18rpx;
|
|
}
|
|
</style>
|