414 lines
8.9 KiB
Plaintext
414 lines
8.9 KiB
Plaintext
<template>
|
|
<view class="cc-page">
|
|
<!-- 相机预览 -->
|
|
<ima-camera-view
|
|
ref="cameraRef"
|
|
class="cc-camera"
|
|
flash="off"
|
|
facing="back"
|
|
@onPictureTaken="onPictureTaken"
|
|
@onCameraOpened="onCameraOpened"
|
|
></ima-camera-view>
|
|
|
|
<!-- 连拍模式提示遮罩 -->
|
|
<view class="cc-burst-overlay" v-if="isBurstMode">
|
|
<text class="cc-burst-tip">连拍中⋯</text>
|
|
<text class="cc-burst-count">{{ capturedList.length }} 张</text>
|
|
<text class="cc-burst-hint">点击红色按钮停止</text>
|
|
</view>
|
|
|
|
<!-- 顶部:已拍数量 & 确认 -->
|
|
<view class="cc-topbar">
|
|
<text class="cc-topbar-title" v-if="capturedList.length > 0">已拍 {{ capturedList.length }}/9</text>
|
|
<text class="cc-topbar-title" v-else>相机</text>
|
|
<text class="cc-topbar-confirm" @click="confirmCapture" :class="{ disabled: capturedList.length === 0 }">
|
|
确认 ({{ capturedList.length }})
|
|
</text>
|
|
</view>
|
|
|
|
<!-- 底部操作区 -->
|
|
<view class="cc-footer">
|
|
<!-- 返回 -->
|
|
<view class="cc-footer-left" @click="goBack">
|
|
<text class="cc-footer-text">取消</text>
|
|
</view>
|
|
|
|
<!-- 中央拍照/停止 -->
|
|
<view class="cc-footer-center">
|
|
<view class="cc-stop-btn" @click="stopBurst" v-if="isBurstMode">
|
|
<view class="cc-stop-inner">■</view>
|
|
</view>
|
|
<view class="cc-capture-btn" @click="capturePhoto" v-else>
|
|
<view class="cc-capture-inner"></view>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 右侧操作 -->
|
|
<view class="cc-footer-right">
|
|
<view class="cc-burst-toggle" @click="toggleBurst" v-if="!isBurstMode && capturedList.length < 9">
|
|
<text class="cc-burst-toggle-text">⚡连拍</text>
|
|
</view>
|
|
<view class="cc-flip-btn" @click="flipCamera" v-if="!isBurstMode">
|
|
<text class="cc-flip-icon">↺</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 已拍照缩略图横条 -->
|
|
<view class="cc-thumb-bar" v-if="capturedList.length > 0">
|
|
<scroll-view class="cc-thumb-scroll" scroll-x="true" show-scrollbar="false">
|
|
<view class="cc-thumb-list">
|
|
<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',
|
|
isBurstMode: false,
|
|
burstTimer: null
|
|
}
|
|
},
|
|
onUnload() {
|
|
this.clearBurstTimer()
|
|
},
|
|
methods: {
|
|
// 相机初始化完成
|
|
onCameraOpened() {
|
|
this.cameraReady = true
|
|
console.log('相机已就绪')
|
|
},
|
|
|
|
// 拍照
|
|
takePhotoAction() {
|
|
if (!this.cameraReady) {
|
|
uni.showToast({ title: '相机未就绪', icon: 'none' })
|
|
return
|
|
}
|
|
this.$refs.cameraRef.takePhoto()
|
|
},
|
|
|
|
// 拍照完成回调
|
|
onPictureTaken(e) {
|
|
var path = e.detail?.path || ''
|
|
if (path) {
|
|
this.capturedList.push(path)
|
|
}
|
|
},
|
|
|
|
// 单拍
|
|
capturePhoto() {
|
|
if (this.capturedList.length >= 9) {
|
|
uni.showToast({ title: '最多拍9张', icon: 'none' })
|
|
return
|
|
}
|
|
this.takePhotoAction()
|
|
},
|
|
|
|
// 连拍开关
|
|
toggleBurst() {
|
|
if (this.capturedList.length >= 9) {
|
|
uni.showToast({ title: '最多拍9张', icon: 'none' })
|
|
return
|
|
}
|
|
this.isBurstMode = true
|
|
this.doBurstCapture()
|
|
},
|
|
|
|
doBurstCapture() {
|
|
if (!this.isBurstMode || this.capturedList.length >= 9) {
|
|
this.isBurstMode = false
|
|
return
|
|
}
|
|
this.takePhotoAction()
|
|
// 间隔 1.5 秒后继续
|
|
var that = this
|
|
this.burstTimer = setTimeout(function() {
|
|
that.doBurstCapture()
|
|
}, 1500)
|
|
},
|
|
|
|
stopBurst() {
|
|
this.isBurstMode = false
|
|
this.clearBurstTimer()
|
|
},
|
|
|
|
clearBurstTimer() {
|
|
if (this.burstTimer) {
|
|
clearTimeout(this.burstTimer)
|
|
this.burstTimer = null
|
|
}
|
|
},
|
|
|
|
// 切换摄像头
|
|
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: #000;
|
|
position: relative;
|
|
}
|
|
.cc-camera {
|
|
flex: 1;
|
|
width: 750rpx;
|
|
}
|
|
/* 连拍遮罩 */
|
|
.cc-burst-overlay {
|
|
position: absolute;
|
|
top: 0; left: 0; right: 0; bottom: 0;
|
|
background-color: rgba(0,0,0,0.25);
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
z-index: 10;
|
|
pointer-events: none;
|
|
}
|
|
.cc-burst-tip {
|
|
color: #fff;
|
|
font-size: 40rpx;
|
|
font-weight: bold;
|
|
text-shadow: 0 2rpx 8rpx rgba(0,0,0,0.6);
|
|
}
|
|
.cc-burst-count {
|
|
color: rgba(255,255,255,0.9);
|
|
font-size: 32rpx;
|
|
margin-top: 16rpx;
|
|
text-shadow: 0 2rpx 8rpx rgba(0,0,0,0.6);
|
|
}
|
|
.cc-burst-hint {
|
|
color: rgba(255,255,255,0.6);
|
|
font-size: 24rpx;
|
|
margin-top: 20rpx;
|
|
text-shadow: 0 2rpx 8rpx rgba(0,0,0,0.6);
|
|
}
|
|
/* 顶部栏 */
|
|
.cc-topbar {
|
|
position: absolute;
|
|
top: 0; left: 0; right: 0;
|
|
height: 100rpx;
|
|
padding-top: var(--status-bar-height);
|
|
display: flex;
|
|
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: #fff;
|
|
font-size: 32rpx;
|
|
font-weight: bold;
|
|
}
|
|
.cc-topbar-confirm {
|
|
color: #409eff;
|
|
font-size: 28rpx;
|
|
font-weight: bold;
|
|
padding: 10rpx 24rpx;
|
|
border-radius: 32rpx;
|
|
background: rgba(64, 158, 255, 0.15);
|
|
}
|
|
.cc-topbar-confirm.disabled {
|
|
color: #666;
|
|
background: transparent;
|
|
}
|
|
/* 底部操作区 */
|
|
.cc-footer {
|
|
position: absolute;
|
|
bottom: 0; left: 0; right: 0;
|
|
height: 200rpx;
|
|
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
|
|
display: flex;
|
|
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-left {
|
|
width: 120rpx;
|
|
}
|
|
.cc-footer-text {
|
|
color: #fff;
|
|
font-size: 28rpx;
|
|
}
|
|
.cc-footer-center {
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.cc-footer-right {
|
|
width: 200rpx;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: flex-end;
|
|
gap: 20rpx;
|
|
}
|
|
/* 拍照按钮 */
|
|
.cc-capture-btn {
|
|
width: 80rpx;
|
|
height: 80rpx;
|
|
border-radius: 50%;
|
|
border: 6rpx solid #fff;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.cc-capture-inner {
|
|
width: 64rpx;
|
|
height: 64rpx;
|
|
border-radius: 50%;
|
|
background: #fff;
|
|
}
|
|
/* 停止按钮 */
|
|
.cc-stop-btn {
|
|
width: 80rpx;
|
|
height: 80rpx;
|
|
border-radius: 50%;
|
|
border: 6rpx solid #ff4444;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: rgba(255,68,68,0.15);
|
|
}
|
|
.cc-stop-inner {
|
|
color: #ff4444;
|
|
font-size: 32rpx;
|
|
font-weight: bold;
|
|
}
|
|
/* 连拍按钮 */
|
|
.cc-burst-toggle {
|
|
padding: 12rpx 18rpx;
|
|
border-radius: 28rpx;
|
|
border: 2rpx solid #409eff;
|
|
background: rgba(64,158,255,0.1);
|
|
}
|
|
.cc-burst-toggle-text {
|
|
color: #409eff;
|
|
font-size: 22rpx;
|
|
font-weight: bold;
|
|
}
|
|
/* 翻转按钮 */
|
|
.cc-flip-btn {
|
|
width: 64rpx;
|
|
height: 64rpx;
|
|
border-radius: 50%;
|
|
border: 2rpx solid rgba(255,255,255,0.4);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.cc-flip-icon {
|
|
color: #fff;
|
|
font-size: 32rpx;
|
|
}
|
|
/* 缩略图横条 */
|
|
.cc-thumb-bar {
|
|
position: absolute;
|
|
bottom: 200rpx;
|
|
left: 0;
|
|
right: 0;
|
|
padding: 10rpx 20rpx;
|
|
z-index: 8;
|
|
}
|
|
.cc-thumb-scroll {
|
|
white-space: nowrap;
|
|
}
|
|
.cc-thumb-list {
|
|
display: flex;
|
|
flex-direction: row;
|
|
gap: 12rpx;
|
|
}
|
|
.cc-thumb-item {
|
|
width: 100rpx;
|
|
height: 100rpx;
|
|
border-radius: 8rpx;
|
|
overflow: hidden;
|
|
position: relative;
|
|
border: 2rpx solid rgba(255,255,255,0.3);
|
|
flex-shrink: 0;
|
|
background: #333;
|
|
}
|
|
.cc-thumb-img {
|
|
width: 100rpx;
|
|
height: 100rpx;
|
|
}
|
|
.cc-thumb-del {
|
|
position: absolute;
|
|
top: -6rpx;
|
|
right: -6rpx;
|
|
width: 32rpx;
|
|
height: 32rpx;
|
|
border-radius: 50%;
|
|
background: rgba(0,0,0,0.6);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.cc-del-icon {
|
|
color: #fff;
|
|
font-size: 18rpx;
|
|
}
|
|
</style>
|