海报:完善海报生成展示组件

pull/53/head
puhui999 2024-05-16 16:15:56 +08:00
parent dabefbe21c
commit ccd033b15a
3 changed files with 49 additions and 41 deletions

2
.env
View File

@ -5,7 +5,7 @@ SHOPRO_VERSION = v1.8.3
SHOPRO_BASE_URL = http://api-dashboard.yudao.iocoder.cn SHOPRO_BASE_URL = http://api-dashboard.yudao.iocoder.cn
# 后端接口 - 测试环境(通过 process.env.NODE_ENV = development # 后端接口 - 测试环境(通过 process.env.NODE_ENV = development
SHOPRO_DEV_BASE_URL = http://192.168.2.21:48080 SHOPRO_DEV_BASE_URL = http://127.0.0.1:48080
### SHOPRO_DEV_BASE_URL = http://yunai.natapp1.cc ### SHOPRO_DEV_BASE_URL = http://yunai.natapp1.cc
# 后端接口前缀(一般不建议调整) # 后端接口前缀(一般不建议调整)

View File

@ -1,7 +1,5 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
const socialType = 34; // 社交类型 - 微信小程序
export default { export default {
// 微信相关 // 微信相关
wechat: { wechat: {
@ -25,10 +23,9 @@ export default {
url: '/member/social-user/wxa-qrcode', url: '/member/social-user/wxa-qrcode',
method: 'POST', method: 'POST',
data: { data: {
type: socialType,
scene: query, scene: query,
isCheckPath: false, // TODO 开发环境暂不检查 path 是否存在
path, path,
checkPath: false, // TODO 开发环境暂不检查 path 是否存在
}, },
}); });
}, },

View File

@ -2,24 +2,20 @@
<template> <template>
<su-popup :show="show" round="10" @close="onClosePoster" type="center" class="popup-box"> <su-popup :show="show" round="10" @close="onClosePoster" type="center" class="popup-box">
<view class="ss-flex-col ss-col-center ss-row-center"> <view class="ss-flex-col ss-col-center ss-row-center">
<view <image
v-if="poster.views.length === 0" v-if="!!painterImageUrl"
class="poster-title ss-flex ss-row-center" class="poster-img"
:src="painterImageUrl"
:style="{ :style="{
height: poster.height + 'px', height: poster.css.height+ 'px',
width: poster.width + 'px', width: poster.css.width + 'px',
}" }"
> :show-menu-by-longpress="true"
海报加载中... />
</view>
<!-- v-if 保障等待所有的海报信息都加载完后才开始渲染 -->
<template v-if="poster.views.length > 0">
<l-painter :board="poster" ref="painterRef"/>
</template>
</view> </view>
<view <view
class="poster-btn-box ss-m-t-20 ss-flex ss-row-between ss-col-center" class="poster-btn-box ss-m-t-20 ss-flex ss-row-between ss-col-center"
v-if="poster.views.length > 0" v-if="!!painterImageUrl"
> >
<button class="cancel-btn ss-reset-button" @tap="onClosePoster"></button> <button class="cancel-btn ss-reset-button" @tap="onClosePoster"></button>
<button class="save-btn ss-reset-button ui-BG-Main" @tap="onSavePoster"> <button class="save-btn ss-reset-button ui-BG-Main" @tap="onSavePoster">
@ -30,11 +26,26 @@
}} }}
</button> </button>
</view> </view>
<!-- 海报画板默认隐藏只用来生成海报生成方式为主动调用 -->
<l-painter
isCanvasToTempFilePath
@success="setPainterImageUrl"
hidden
ref="painterRef"
/>
</su-popup> </su-popup>
</template> </template>
<script setup> <script setup>
import { reactive, ref } from 'vue'; /**
* 海报生成和展示
* 提示小程序码默认跳转首页由首页进行 spm 参数解析后跳转到对应的分享页面
* @description 用于生成分享海报分享商品海报
* @tutorial https://ext.dcloud.net.cn/plugin?id=2389
* @property {Boolean} show 弹出层控制
* @property {Object} shareInfo 分享信息
*/
import { reactive, ref, unref } from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { getPosterData } from '@/sheep/components/s-share-modal/canvas-poster/poster'; import { getPosterData } from '@/sheep/components/s-share-modal/canvas-poster/poster';
@ -45,7 +56,7 @@
}, },
shareInfo: { shareInfo: {
type: Object, type: Object,
default() { default: () => {
}, },
}, },
}); });
@ -54,7 +65,7 @@
css: { css: {
// //
width: sheep.$platform.device.windowWidth * 0.9, width: sheep.$platform.device.windowWidth * 0.9,
height: 600 height: 600,
}, },
views: [], views: [],
}); });
@ -65,33 +76,32 @@
emits('close'); emits('close');
}; };
const painterRef = ref() const painterRef = ref(); //
const painterImageUrl = ref(); // url
//
const renderPoster = async () => {
await painterRef.value.render(unref(poster));
};
//
const setPainterImageUrl = (path) => {
painterImageUrl.value = path;
};
// //
const onSavePoster = () => { const onSavePoster = () => {
if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) { if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
sheep.$helper.toast('请长按图片保存'); sheep.$helper.toast('请长按图片保存');
return; return;
} }
// H5
painterRef.value.canvasToTempFilePathSync({ uni.saveImageToPhotosAlbum({
fileType: "jpg", filePath: painterImageUrl.value,
// base64使 saveImageToPhotosAlbum pathTypeurl
pathType: 'url',
quality: 1,
success: (res) => { success: (res) => {
console.log(res.tempFilePath); onClosePoster();
// H5 sheep.$helper.toast('保存成功');
uni.saveImageToPhotosAlbum({ },
filePath: res.tempFilePath, fail: (err) => {
success: (res) => { sheep.$helper.toast('保存失败');
onClosePoster(); console.log('图片保存失败:', err);
sheep.$helper.toast('保存成功');
},
fail: (err) => {
sheep.$helper.toast('保存失败');
console.log('图片保存失败:', err);
},
});
}, },
}); });
}; };
@ -102,6 +112,7 @@
width: poster.css.width, width: poster.css.width,
shareInfo: props.shareInfo, shareInfo: props.shareInfo,
}); });
await renderPoster();
} }
defineExpose({ defineExpose({