Files
dvcp_v2_wxcp_app/src/saas/AppCountryAlbum/Watermark.vue

278 lines
6.2 KiB
Vue
Raw Normal View History

2022-05-10 18:18:59 +08:00
<template>
2022-05-16 18:04:46 +08:00
<div class="photo" ref="waterMarker" :class="[isHide ? 'home-active' : '']" :style="{height: height + 'px'}">
<div class="photo-top" data-html2canvas-ignore>
2022-05-17 14:58:10 +08:00
<!-- <image src="./images/gengduo1.png" @click="back" /> -->
<u-icon name="close" color="#fff" size="28" @click="back"></u-icon>
2022-05-16 18:04:46 +08:00
<div class="photo-top__middle">
<span>保存至默认相册</span>
<image src="./images/gengduo1.png" />
</div>
<span @click="save">保存</span>
</div>
2022-05-17 14:58:10 +08:00
<image :src="img" mode="aspectFit" />
<div class="watermark" v-if="currIndex > -1">
2022-05-16 18:04:46 +08:00
<component :is="'Watermark' + (currIndex + 1)"></component>
</div>
<div class="photo-bottom" v-if="!isHide">
<div class="photo-bottom__top">
2022-05-17 14:58:10 +08:00
<image src="./images/gengduo1.png" @click="isHide = true, currIndex = -1" />
2022-05-16 18:04:46 +08:00
<h2>水印</h2>
<span>确定</span>
</div>
<div class="waterlist">
<div
class="water-item"
:class="[currIndex === index ? 'active' : '']"
v-for="(item, index) in config"
:key="index"
@click="currIndex = index">
<image :src="item.thum" mode="aspectFill" />
<div class="water-item__bottom">{{ item.name }}</div>
</div>
</div>
</div>
<image class="newImg" @click="waterSrc = ''" :src="waterSrc" v-if="waterSrc" />
2022-05-10 18:18:59 +08:00
</div>
</template>
<script>
2022-05-16 18:04:46 +08:00
import html2canvas from 'html2canvas'
import Watermark1 from './components/watermark/Watermark1'
import Watermark2 from './components/watermark/Watermark2'
import Watermark3 from './components/watermark/Watermark3'
import Watermark4 from './components/watermark/Watermark4'
import Watermark5 from './components/watermark/Watermark5'
import Watermark6 from './components/watermark/Watermark6'
import Watermark7 from './components/watermark/Watermark7'
import Watermark8 from './components/watermark/Watermark8'
import { config } from './config'
2022-05-10 18:18:59 +08:00
export default {
name: 'Watermark',
appName: '水印相机',
2022-05-16 18:04:46 +08:00
components: {
Watermark1,
Watermark2,
Watermark3,
Watermark4,
Watermark5,
Watermark6,
Watermark7,
Watermark8
},
2022-05-10 18:18:59 +08:00
data () {
return {
2022-05-17 14:58:10 +08:00
img: '',
2022-05-16 18:04:46 +08:00
config,
currIndex: 0,
isHide: false,
height: '100%',
waterSrc: ''
2022-05-10 18:18:59 +08:00
}
},
2022-05-17 14:58:10 +08:00
onLoad (query) {
this.img = query.url
2022-05-16 18:04:46 +08:00
this.height = uni.getSystemInfoSync().windowHeight
2022-05-10 18:18:59 +08:00
},
methods: {
2022-05-16 18:04:46 +08:00
save () {
this.isHide = true
console.log(this.$refs.waterMarker.offsetHeight)
this.$nextTick(() => {
setTimeout(() => {
html2canvas(this.$refs.waterMarker, {
allowTaint: true,
2022-05-17 14:58:10 +08:00
useCORS: true
2022-05-16 18:04:46 +08:00
}).then((canvas) => {
2022-05-17 14:58:10 +08:00
let dataURL = canvas.toDataURL('image/png')
2022-05-16 18:04:46 +08:00
this.waterSrc = dataURL
}).catch(e => {
console.log(e)
})
}, 2000)
2022-05-10 18:18:59 +08:00
})
2022-05-17 14:58:10 +08:00
},
back () {
uni.navigateBack({
delta: 1
})
2022-05-10 18:18:59 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.photo {
position: relative;
width: 100%;
2022-05-16 18:04:46 +08:00
height: 800px;
background: #444;
overflow: hidden;
.newImg {
position: fixed;
left: 0;
top: 0;
z-index: 11111;
width: 100%;
height: 100%;
}
* {
box-sizing: border-box;
}
.watermark {
position: fixed;
left: 32px;
bottom: 512px;
z-index: 111;
color: #FFFFFF;
font-size: 28px;
}
.photo-bottom {
position: fixed;
bottom: 0;
left: 0;
z-index: 11;
width: 100%;
height: 474px;
background: #FFFFFF;
border-radius: 32px 32px 0px 0px;
.waterlist {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
height: calc(100% - 96px);
padding: 18px 16px;
overflow-y: auto;
.water-item {
display: flex;
position: relative;
align-items: center;
justify-content: center;
width: 352px;
height: 240px;
margin-bottom: 16px;
background: #2A3540;
border-radius: 8px;
overflow: hidden;
&.active {
border: 6px solid #408EF6;
}
image {
width: 176px;
height: 200px;
}
.water-item__bottom {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 56px;
line-height: 56px;
color: #fff;
text-align: center;
font-size: 28px;
background: rgba(0, 0, 0, 0.7);
}
}
}
.photo-bottom__top {
display: flex;
align-items: center;
justify-content: space-between;
height: 96px;
padding: 0 32px;
image {
width: 40px;
height: 40px;
}
h2 {
font-size: 28px;
color: #333;
}
span {
font-size: 32px;
color: #222;
font-weight: 600;
}
}
}
.photo-top {
display: flex;
position: fixed;
align-items: center;
justify-content: space-between;
top: 0;
left: 0;
z-index: 11;
width: 100%;
height: 128px;
padding: 0 32px;
background: rgba(0, 0, 0, 0.5);
& > image {
width: 28px;
height: 28px;
}
& > span {
color: #cbcbcb;
font-size: 32px;
}
.photo-top__middle {
display: flex;
align-items: center;
justify-content: center;
width: 336px;
height: 72px;
background: #0B111F;
border-radius: 40px;
font-size: 28px;
color: #cbcbcb;
image {
width: 32px;
height: 32px;
margin-left: 16px;
}
}
}
&.home-active {
.photo-bottom {
transform: translateY(100%);
}
.watermark {
bottom: 38px;
}
}
2022-05-10 18:18:59 +08:00
& > image {
width: 100%;
height: 100%;
}
}
</style>