123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <template>
- <s-layout :title="t('share.share')" class="set-userinfo-wrap">
-
- <view class="ss-flex-col ss-col-center ss-row-center">
- <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 ss-m-20" :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>
- <view class="modal-footer ss-flex ss-p-x-20">
- <button class="confirm-btn" @tap="onSavePoster">{{
- ['wechatOfficialAccount', 'H5'].includes(sheep.$platform.name)
- ? t('share.long_press_to_save')
- : t('share.long_press_to_save')
- }}</button>
- <!-- <button class="confirm-btn" @tap="showShareModal">分享</button> -->
- </view>
-
- </s-layout>
- </template>
- <script setup>
- import {
- computed,
- reactive,
- onBeforeMount,
- getCurrentInstance
- } from 'vue';
- import {
- onLoad
- } from '@dcloudio/uni-app';
- import sheep from '@/sheep';
- import useCanvas from '@/sheep/components/s-share-modal/canvas-poster/useCanvas';
- import {
- showAuthModal,
- showShareModal
- } from '@/sheep/hooks/useModal';
- import ShareApi from '@/sheep/api/distri/share';
- import { t } from '@/locale'
- const state = reactive({
- linkId:0
- })
- const poster = reactive({
- canvasId: 'canvasId',
- width: sheep.$platform.device.windowWidth * 0.9,
- height: 600,
- src: '',
- });
- const vm = getCurrentInstance();
- // 使用 canvas 生成海报
- async function getPoster(params) {
- poster.src = '';
- poster.shareInfo = {
- "title": "",
- "desc": "",
- "image": "",
- "path": "",
- "linkId": state.linkId,
- "link": import.meta.env.SHOPRO_BASE_URL+"/#/pages/index/user?linkId="+state.linkId,
- "poster": {
- "type": "user"
- }
- };
- // #ifdef APP-PLUS
- poster.canvasId = 'canvasId-' + new Date().getTime();
- // #endif
- const canvas = await useCanvas(poster, vm);
- return canvas;
- }
-
- async function getLink(){
- //加载分享时用到的linkId
- ShareApi.getLinkId(1).then((res) => {
- if (res.code !== 0) {
- return;
- }
- state.linkId = res.data.linkId
- getPoster()
- });
- }
- // 保存海报图片
- 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);
- },
- });
- };
- // onBeforeMount(() => {
-
- // });
- onLoad(async()=>{
-
- await getLink()
- })
- </script>
- <style lang="scss" scoped>
- .confirm-btn {
- width: 710rpx;
- margin-left: 20rpx;
- height: 80rpx;
- background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
- border-radius: 40rpx;
- color: #fff;
- }
- .confirm-btn:first-child{
- margin-left: 0;
- }
- .hideCanvas {
- position: fixed;
- top: -99999rpx;
- left: -99999rpx;
- z-index: -99999;
- }
- </style>
|