123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <!-- 海报弹窗 -->
- <template>
- <su-popup :show="show" round="10" @close="onClosePoster" type="center" class="popup-box">
- <view class="ss-flex-col ss-col-center ss-row-center">
- <!-- <image class="poster-img" :src="imageUrl"/> -->
- <view v-if="poster.src === ''" class="poster-title ss-flex ss-row-center" :style="{
- height: poster.height + 'px',
- width: poster.width + 'px',
- }">
- {{ t('share.poster_loading') }}
- </view>
- <image v-else class="poster-img" :src="poster.src" :style="{
- height: poster.height + 'px',
- width: poster.width + 'px',
- }" :show-menu-by-longpress="true" />
- <canvas class="hideCanvas" :canvas-id="poster.canvasId" :id="poster.canvasId" :style="{
- height: poster.height + 'px',
- width: poster.width + 'px',
- }" />
- <view class="poster-btn-box ss-m-t-20 ss-flex ss-row-between ss-col-center" v-if="poster.src !== ''">
- <button class="cancel-btn ss-reset-button" @tap="onClosePoster">{{ t('common.cancel') }}</button>
- <button class="save-btn ss-reset-button ui-BG-Main" @tap="onSavePoster">
- {{t('share.long_press_to_save') }}
- <!-- {{
- ['wechatOfficialAccount', 'H5'].includes(sheep.$platform.name)
- ? '保存图片'
- : '长按图片保存'
- }} -->
-
- </button>
- </view>
- </view>
- </su-popup>
- </template>
- <script setup>
- import {
- reactive,
- getCurrentInstance,
- ref
- } from 'vue';
- import sheep from '@/sheep';
- import useCanvas from './useCanvas';
- import { t } from '@/locale'
- // import FileApi from '@/sheep/api/infra/file';
- const props = defineProps({
- show: {
- type: Boolean,
- default: false,
- },
- shareInfo: {
- type: Object,
- default () {},
- },
- });
-
- const poster = reactive({
- canvasId: 'canvasId',
- width: sheep.$platform.device.windowWidth * 0.9,
- height: 600,
- src: '',
- imgData:''
- });
- const emits = defineEmits(['success', 'close']);
- const vm = getCurrentInstance();
- const onClosePoster = () => {
- emits('close');
- };
- // 保存海报图片
- const onSavePoster = () => {
- if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
- sheep.$helper.toast(t('share.long_press_to_save') );
- return;
- }
- uni.saveImageToPhotosAlbum({
- filePath: poster.src,
- success: (res) => {
- onClosePoster();
- sheep.$helper.toast(t('share.save_success'));
- },
- fail: (err) => {
- sheep.$helper.toast(t('share.save_failure'));
- console.log('图片保存失败:', err);
- },
- });
- };
- const imageUrl = ref("")
-
- async function getPoster(params) {
- // console.log(props.shareInfo)
- poster.src = '';
- poster.shareInfo = props.shareInfo;
- // #ifdef APP-PLUS
- poster.canvasId = 'canvasId-' + new Date().getTime();
- // #endif
- const canvas = await useCanvas(poster, vm);
- return canvas;
- }
- defineExpose({
- getPoster,
- });
- </script>
- <style lang="scss" scoped>
- .popup-box {
- position: relative;
- }
- .poster-title {
- color: #999;
- }
- // 分享海报
- .poster-btn-box {
- width: 600rpx;
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- bottom: -80rpx;
- .cancel-btn {
- width: 280rpx;
- height: 70rpx;
- line-height: 70rpx;
- background: $white;
- border-radius: 35rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: $dark-9;
- }
- .save-btn {
- width: 280rpx;
- height: 70rpx;
- line-height: 70rpx;
- border-radius: 35rpx;
- font-size: 28rpx;
- font-weight: 500;
- }
- }
- .poster-img {
- border-radius: 20rpx;
- }
- .hideCanvas {
- position: fixed;
- top: -99999rpx;
- left: -99999rpx;
- z-index: -99999;
- }
- </style>
|