activityDetail.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. <template>
  2. <view class="common_page adffc" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <!-- Canvas组件,用于后台绘制海报,通过绝对定位移出屏幕外 -->
  4. <canvas canvas-id="posterCanvas"
  5. :style="{width: canvasWidth + 'px', height: canvasHeight + 'px', position: 'fixed', top: '-99999px', left: '0'}" />
  6. <cus-header title="公益活动详情" bgColor="transparent"></cus-header>
  7. <image src="https://oss.familydaf.cn/sxsnfile/20251218/811a8863a74d4ed9b86f68284eaff0c9.png" class="top_bg_img" mode="widthFix"></image>
  8. <view class="lunbo">
  9. <up-swiper
  10. :list="imgList"
  11. @change="e => current = e.current"
  12. :autoplay="true"
  13. height="440rpx"
  14. >
  15. <template #indicator>
  16. <view class="indicator adf">
  17. <view class="indicator__dot" v-for="(item, index) in imgList" :key="index"
  18. :class="[index === current && 'indicator__dot--active']">
  19. </view>
  20. </view>
  21. </template>
  22. </up-swiper>
  23. </view>
  24. <view class="box box1">
  25. <view class="box1-top">
  26. <text class="box1-top-status" :class="{'end':activityInfo?.activeState==3}">{{statusCfg[activityInfo?.activeState]||'未知'}}</text>
  27. <text class="box1-top-title">{{activityInfo?.activityName||''}}</text>
  28. </view>
  29. <view class="box1-line" style="margin-top: 36rpx;"></view>
  30. <view class="box1-place adfacjb">
  31. <view class="box1-place-left adffcjb">
  32. <text>活动地点</text>
  33. <view class="addr">{{activityInfo?.provinceName||''}}{{activityInfo?.cityName||''}}{{activityInfo?.address||''}}</view>
  34. </view>
  35. <view class="box1-place-right">
  36. <image src="https://oss.familydaf.cn/sxsnfile/20251218/dc3034ff405549059cc52eac7479f0e0.png"></image>
  37. </view>
  38. </view>
  39. <view class="box1-line" style="margin-top: 24rpx;"></view>
  40. <view class="box1-member adfacjb">
  41. <view class="box1-member-left adffc">
  42. <text>招募人数</text>
  43. <view class="num"><text>{{activityInfo?.recruitmentNow}}</text> /{{activityInfo?.recruitmentMax||'不限'}}</view>
  44. </view>
  45. <view class="box1-member-right adffc" @tap="handleReviewMembers">
  46. <view class="review adfac">
  47. <text>查看报名人员</text>
  48. <image src="https://oss.familydaf.cn/sxsnfile/20251218/d22838b7cdae42b5a8e6ebfa01d06445.png"></image>
  49. </view>
  50. <view class="avatars">
  51. <up-avatar-group :urls="avatars" size="30" gap="0.4" :maxCount="3"></up-avatar-group>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="box1-line" style="margin-top: 33rpx;"></view>
  56. <view class="box1-time adffc">
  57. <text>活动时间</text>
  58. <view class="text">{{activityInfo?.activityStartTime}} - {{activityInfo?.activityEndTime}}</view>
  59. </view>
  60. <view class="box1-line" style="margin-top: 30rpx;"></view>
  61. <view class="box1-need adffc">
  62. <text>报名要求</text>
  63. <template v-if="activityInfo?.activityLimit==1">
  64. <view class="text"><text>{{activityInfo?.valueLimit||0}}</text>爱心值</view>
  65. <view class="tip">{{activityInfo?.loveValueContent||''}}</view>
  66. </template>
  67. <template v-else-if="activityInfo?.activityLimit==2">
  68. <view class="text"><text>{{activityInfo?.valueLimit||0}}</text>张专享券</view>
  69. <view class="tip">{{activityInfo?.loveValueContent||''}}</view>
  70. </template>
  71. <template v-else-if="activityInfo?.activityLimit==3">
  72. <view class="text"><text>免费</text></view>
  73. <view class="tip"></view>
  74. </template>
  75. </view>
  76. <view class="box1-line" style="margin-top: 30rpx;"></view>
  77. <view class="box1-info adfacjb">
  78. <view class="box1-info-pre">
  79. <text>年龄限制</text>
  80. <view class="text" v-if="activityInfo?.userAgeMax">{{activityInfo?.userAgeMin}}岁 到 {{activityInfo?.userAgeMax}}岁</view>
  81. <view class="text" v-else>不限制</view>
  82. </view>
  83. <view class="box1-info-pre line">
  84. <text>可获得义工时长</text>
  85. <!-- typeId=='1977564860095348737'为义工活动,义工时长只有义工活动才有 -->
  86. <view class="hour" v-if="activityInfo?.typeId=='1977564860095348737'"><text>{{activityInfo?.serviceHours||0}}</text> 小时</view>
  87. <view class="hour" v-else>无</view>
  88. </view>
  89. </view>
  90. <view class="box1-line" style="margin-top: 30rpx;"></view>
  91. <view class="box1-info adfacjb">
  92. <view class="box1-info-pre">
  93. <text>联系人</text>
  94. <view class="text">{{activityInfo?.contact||''}}/{{activityInfo?.contactPhone||''}}</view>
  95. </view>
  96. <view class="box1-info-pre line">
  97. <text>公益合作</text>
  98. <view class="text">{{activityInfo?.channelName||''}}</view>
  99. </view>
  100. </view>
  101. </view>
  102. <view class="box box2">
  103. <view class="box-title">活动详情</view>
  104. <view class="box2-detail" v-if="activityInfo&&activityInfo.activityDetails">
  105. <up-read-more :toggle="true" showHeight="374rpx" color="#989998" fontSize="24rpx" openText="收起更多信息" closeText="展开更多信息">
  106. <rich-text :nodes="activityInfo.activityDetails"></rich-text>
  107. </up-read-more>
  108. </view>
  109. </view>
  110. <view class="bottom">
  111. <view class="time">
  112. 报名时间:{{activityInfo?.signupStartTime}} - {{activityInfo?.signupEndTime}}
  113. </view>
  114. <view class="btns adfacjb">
  115. <view class="left adffcacjc" @tap="showShareOptions">
  116. <up-icon name="share-square" color="#252525" size="48rpx"></up-icon>
  117. <text>分享</text>
  118. </view>
  119. <view class="right" @click="handleApply" v-if="activityInfo?.activeState==1&&activityInfo?.signupState==0">立即报名</view>
  120. <view class="right" @click="handleCancel" v-else-if="activityInfo?.activeState==1&&activityInfo?.signupState==1">取消报名</view>
  121. <view class="right" @click="handleSignup" v-else-if="activityInfo?.activeState==2&&activityInfo?.signupState==1">我要签到</view>
  122. <view class="right" @click="handleFill" v-else-if="activityInfo?.activeState==3&&activityInfo?.signupState==1">填写公益档案</view>
  123. <view class="right end" v-else-if="activityInfo?.activeState==0">活动未开始</view>
  124. <view class="right end" v-else-if="activityInfo?.activeState==1&&activityInfo?.signupState==2">活动已签到</view>
  125. <view class="right end" v-else-if="activityInfo?.activeState==2&&activityInfo?.signupState==0">活动进行中不可报名</view>
  126. <view class="right end" v-else-if="activityInfo?.activeState==3">活动已结束</view>
  127. <view class="right end" v-else-if="activityInfo?.activeState==4">已报满暂无活动名额</view>
  128. </view>
  129. </view>
  130. <view class="fail" v-if="fail">
  131. <view class="fbox adffcac">
  132. <image class="clock" src="https://oss.familydaf.cn/sxsnfile/20251218/4a47278697174d04bf54b8b691587a9c.png"></image>
  133. <image class="close" src="https://oss.familydaf.cn/sxsnfile/20251218/5e39649ad9d0433c96a491bd040413eb.png" @click="fail=false"></image>
  134. <image class="alert" src="https://oss.familydaf.cn/sxsnfile/20251218/39c584e1f7214b32aab2418272bb8678.png" mode="widthFix"></image>
  135. <view class="texts adffcacjc">
  136. <view class="text">您当前{{activityLimitCfg[activityInfo?.activityLimit]}}不足,无法报名活动</view>
  137. <view class="tip">欢迎联系专属客服,了解更多公益活动,积攒{{activityLimitCfg[activityInfo?.activityLimit]}}</view>
  138. </view>
  139. <image class="down" src="https://oss.familydaf.cn/sxsnfile/20251218/445791524423424da07755060a6d50ad.png"></image>
  140. <view class="user adfacjc">
  141. "善行少年"咨询微信
  142. </view>
  143. <view class="finfo adffcac">
  144. <view class="finfo-code adffcacjc">
  145. <image :src="imageUrl" :show-menu-by-longpress="true"></image>
  146. </view>
  147. <view class="finfo-title">长按识别二维码</view>
  148. <view class="finfo-tip">添加您的专属公益向导</view>
  149. <view class="finfo-btn" @click="toWebView">了解善行少年</view>
  150. <view class="finfo-zblj" @click="fail=false">暂不了解</view>
  151. </view>
  152. </view>
  153. </view>
  154. <view class="share" v-if="share">
  155. <view class="sbox">
  156. <view class="sbox-title">分享给好友</view>
  157. <image class="close" src="https://oss.familydaf.cn/sxsnfile/20251218/bbf9472f744741bf9fcf2a2d4c5c0f11.png" @click="share=false"></image>
  158. <view class="sbox-items adfac">
  159. <view class="sbox-items-pre adffcac">
  160. <button class="share-btn" open-type="share">
  161. <image src="https://oss.familydaf.cn/sxsnfile/20251218/9b409327172b42b5a165e1d4da631753.png"></image>
  162. <text>分享页面</text>
  163. </button>
  164. </view>
  165. <view class="sbox-items-pre adffcac" @click="generatePoster">
  166. <image src="https://oss.familydaf.cn/sxsnfile/20251218/8f7e9292eb054271a03cf5f7d63a6b25.png"></image>
  167. <text>生成海报</text>
  168. </view>
  169. <view class="sbox-items-pre adffcac" @click="shareToTimeline">
  170. <image src="https://oss.familydaf.cn/sxsnfile/20251218/b29cf7f4b77e44458c5abc01ca2ff56e.png"></image>
  171. <text>分享到朋友圈</text>
  172. </view>
  173. </view>
  174. </view>
  175. </view>
  176. <!-- 海报展示弹窗 -->
  177. <view class="posterbox adffcacjc" v-if="posterShow">
  178. <!-- 加载状态 -->
  179. <u-loading-icon v-if="posterLoading" text="海报生成中..." size="28" textSize="18" inactiveColor="#ffffff" color="#ffffff"></u-loading-icon>
  180. <!-- 海报生成后的内容 -->
  181. <template v-else>
  182. <!-- 此处不再使用HTML结构,而是直接显示生成的图片 -->
  183. <div class="posterbox-card adffcac">
  184. <image :src="posterUrl" mode="widthFix" class="poster-image"></image>
  185. </div>
  186. <div class="posterbox-menu adfacjb">
  187. <div class="posterbox-menu-pre adffcac" v-for="(item,index) in menuList" :key="index" @click="handleMenuClick(item.type)">
  188. <template v-if="index===0">
  189. <button class="share-btn" open-type="share">
  190. <image :src="item.img"></image>
  191. <text>{{item.title}}</text>
  192. </button>
  193. </template>
  194. <template v-else>
  195. <image :src="item.img"></image>
  196. <text>{{item.title}}</text>
  197. </template>
  198. </div>
  199. </div>
  200. <div class="posterbox-close adfacjc">
  201. <image src="https://oss.familydaf.cn/sxsnfile/20251218/44d55c9cb46a404d9dfc0e4ed106c69d.png" @click="posterShow=false"></image>
  202. </div>
  203. </template>
  204. </view>
  205. </view>
  206. </template>
  207. <script setup name="">
  208. import CusHeader from '@/components/CusHeader/index.vue'
  209. import { onLoad } from '@dcloudio/uni-app';
  210. import { ref, reactive, onMounted, getCurrentInstance } from 'vue'
  211. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  212. const { proxy } = getCurrentInstance()
  213. const id = ref('')
  214. const activityInfo = ref(null)
  215. const statusCfg = ref({
  216. 0:'未开始',
  217. 1:'报名中',
  218. 4:'报名中',
  219. 2:'进行中',
  220. 3:'已结束'
  221. })
  222. const activityLimitCfg = ref({
  223. 1:'爱心值',
  224. 2:'专享券',
  225. 3:'免费'
  226. })
  227. const imgList = ref([])
  228. const detail = ref('')
  229. const avatars = ref([])
  230. const fail = ref(false)
  231. const share = ref(false)
  232. // --- 海报生成相关 ---
  233. const posterShow = ref(false) // 控制海报弹窗显示
  234. const posterLoading = ref(false) // 控制海报生成时的加载状态
  235. const posterUrl = ref('') // 存储生成的海报图片临时路径
  236. const canvasWidth = ref(0) // Canvas 宽度
  237. const canvasHeight = ref(0) // Canvas 高度
  238. // 海报上所需的动态数据
  239. const posterData = reactive({
  240. mainImg: 'https://sxsn.ringzle.com/happytree-admin/profile/2025/12/12/e8218de1-d059-4197-b677-f9d2e446971e.png',
  241. title: '《环保知识知多少》让孩子成为健康公益大使',
  242. time: '06.01-12:00 ~ 06.02-12:00',
  243. timeIcon: 'https://oss.familydaf.cn/sxsnfile/20251218/762878799914422d835e505291b9d4c6.png',
  244. address: '深圳市南山区南山街道丰潭路',
  245. addressIcon: 'https://oss.familydaf.cn/sxsnfile/20251218/57539643ab974aef9401d76818e1bf3b.png',
  246. organizer: '锦鲤俱乐部',
  247. organizerIcon: 'https://oss.familydaf.cn/sxsnfile/20251218/47953738adfc46d8b959d7cead7a186e.png',
  248. qrCode: 'https://oss.familydaf.cn/sxsnfile/20251218/4eeb3cf6799141c9853349533c33e529.jpg'
  249. })
  250. const imageUrl = ref('https://oss.familydaf.cn/sxsnfile/20251218/b25745272a52435194dbc3987d5645f2.png')
  251. const menuList = ref([
  252. { img:'https://oss.familydaf.cn/sxsnfile/20251218/533e0ec5511043c6853c4a05b720dadf.png',title:'发送给朋友', type:'shareApp' },
  253. { img:'https://oss.familydaf.cn/sxsnfile/20251218/43a1bf3fc87240a2b33359f10d9d4d19.png',title:'分享到朋友圈', type:'shareTimeline' },
  254. { img:'https://oss.familydaf.cn/sxsnfile/20251218/875a7d2a8f9e47cb813246879b2b0714.png',title:'收藏', type:'favorite' },
  255. { img:'https://oss.familydaf.cn/sxsnfile/20251218/125b3da887974ae2b600ce2ec72c1fbe.png',title:'保存图片', type:'save' },
  256. ])
  257. const handleReviewMembers = () => {
  258. uni.navigateTo({
  259. url:'/pagesHome/recruitsNumber?activityId='+activityInfo.value?.id+'&recruitmentMax='+activityInfo.value?.recruitmentMax+'&recruitmentMin='+activityInfo.value?.recruitmentMin
  260. })
  261. }
  262. //立即报名
  263. const handleApply = async () => {
  264. let { loveValue, couponIds } = await getUserLoveTicket();
  265. let url = `/pagesHome/activityApply?activity=${encodeURIComponent(JSON.stringify(activityInfo.value))}`;
  266. if((activityInfo.value?.activityLimit==1&&loveValue<activityInfo?.value.valueLimit)
  267. ||(activityInfo.value?.activityLimit==2&&couponIds?.length<activityInfo?.value.valueLimit)){
  268. fail.value = true;
  269. return
  270. }
  271. uni.navigateTo({ url })
  272. }
  273. //取消报名
  274. const handleCancel = () => {
  275. uni.reLaunch({
  276. url:'/pages/nonprofit?type=1'
  277. })
  278. }
  279. //我要签到
  280. const handleSignup = () => {
  281. uni.reLaunch({
  282. url:'/pages/nonprofit?type=2'
  283. })
  284. }
  285. //填写公益档案
  286. const handleFill = () => {
  287. uni.reLaunch({
  288. url:'/pages/nonprofit?type=3'
  289. })
  290. }
  291. const getUserLoveTicket = () => {
  292. return new Promise(resolve=>{
  293. let userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  294. proxy.$api.get(`/core/activity/signup/userAsset/${userId}/${activityInfo.value?.id}`).then(({data:res})=>{
  295. if(res.code!==0) return proxy.$showToast(res.msg)
  296. resolve({loveValue:res.data?.loveValue||0,couponIds:res.data?.couponIds||0})
  297. })
  298. })
  299. }
  300. onShareAppMessage((res) => {
  301. // 如果是点击海报菜单的“发送给朋友”按钮
  302. if (res.from === 'button' && res.target.id === 'posterShareBtn') {
  303. return {
  304. title: posterData.title,
  305. path: `/pagesHome/activityDetail?shareADId=${id.value}`,
  306. imageUrl: posterUrl.value // 使用生成的海报作为分享图
  307. };
  308. }
  309. // 默认页面右上角分享
  310. const sharerId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  311. return {
  312. title: activityInfo.value?.activityName || '发现一个好物,分享给你!',
  313. path: `/pagesHome/activityDetail?shareADId=${activityInfo.value?.id}&shareUserId=${sharerId}`,
  314. imageUrl: activityInfo.value?.coverFile
  315. };
  316. })
  317. onShareTimeline((res) => {
  318. const sharerId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  319. return {
  320. title: activityInfo.value?.activityName || '发现一个好物,分享给你!',
  321. query: `shareADId=${activityInfo.value?.id}&shareUserId=${sharerId}`,
  322. imageUrl: activityInfo.value?.coverFile
  323. };
  324. })
  325. const showShareOptions = () => {
  326. share.value = true;
  327. }
  328. // 分享到朋友圈(旧逻辑)
  329. const shareToTimeline = () => {
  330. uni.showModal({
  331. title:'温馨提示',
  332. content:'分享到朋友圈请点击页面右上方的“···”标志后选择“分享到朋友圈”进行分享'
  333. })
  334. }
  335. // --- Canvas海报生成核心逻辑 ---
  336. // 1. 触发生成
  337. const generatePoster = async () => {
  338. share.value = false;
  339. posterShow.value = true;
  340. posterLoading.value = true;
  341. posterUrl.value = ''; // 清空旧海报
  342. try {
  343. // 获取设备信息,用于rpx转px
  344. const systemInfo = uni.getSystemInfoSync();
  345. const screenWidth = systemInfo.screenWidth;
  346. const rpxRatio = screenWidth / 750;
  347. // --- 定义尺寸和坐标 (单位: px) ---
  348. // 卡片总宽度为 100% - 220rpx
  349. const cardWidth = screenWidth - 220 * rpxRatio;
  350. const cardPadding = 20 * rpxRatio;
  351. const contentWidth = cardWidth - cardPadding * 2;
  352. const mainImgHeight = 368 * rpxRatio;
  353. const infoTopMargin = 14 * rpxRatio;
  354. const qrCodeWidth = 123 * rpxRatio;
  355. const qrCodeHeight = 123 * rpxRatio;
  356. const rightPartWidth = 163 * rpxRatio;
  357. const leftPartWidth = contentWidth - rightPartWidth;
  358. // 计算总高度
  359. const titleHeight = calculateWrappedTextHeight(posterData.title, 24 * rpxRatio, contentWidth, 36 * rpxRatio);
  360. const infoBlockHeight = 160 * rpxRatio; // 估算下方信息区域高度
  361. const cardHeight = cardPadding * 2 + mainImgHeight + infoTopMargin + infoBlockHeight;
  362. canvasWidth.value = cardWidth;
  363. canvasHeight.value = cardHeight;
  364. // 等待一帧,确保canvas尺寸设置生效
  365. await new Promise(resolve => setTimeout(resolve, 50));
  366. const ctx = uni.createCanvasContext('posterCanvas', proxy);
  367. // --- 下载所有需要的图片 ---
  368. const [mainImg, timeIcon, addressIcon, orgIcon, qrCode] = await Promise.all([
  369. uni.getImageInfo({ src: posterData.mainImg }),
  370. uni.getImageInfo({ src: posterData.timeIcon }),
  371. uni.getImageInfo({ src: posterData.addressIcon }),
  372. uni.getImageInfo({ src: posterData.organizerIcon }),
  373. uni.getImageInfo({ src: posterData.qrCode }),
  374. ]);
  375. // --- 开始绘制 ---
  376. // 1. 绘制白色背景
  377. ctx.fillStyle = '#FFFFFF';
  378. ctx.fillRect(0, 0, cardWidth, cardHeight);
  379. // 2. 绘制主图
  380. ctx.drawImage(mainImg.path, cardPadding, cardPadding, contentWidth, mainImgHeight);
  381. let currentY = cardPadding + mainImgHeight + infoTopMargin;
  382. // 3. 绘制左侧信息
  383. const leftX = cardPadding;
  384. // 3.1 绘制标题 (自动换行)
  385. ctx.font = `bold ${Math.round(24 * rpxRatio)}px "PingFang-SC", sans-serif`;
  386. ctx.fillStyle = '#252525';
  387. currentY += drawWrappedText(ctx, posterData.title, leftX, currentY + 24 * rpxRatio, leftPartWidth, 36 * rpxRatio, 1);
  388. currentY += 12 * rpxRatio; // 标题和下方内容的间距
  389. // 3.2 绘制时间
  390. const iconSize = 24 * rpxRatio;
  391. const textLeftMargin = 10 * rpxRatio;
  392. const infoLineHeight = 36 * rpxRatio;
  393. ctx.drawImage(timeIcon.path, leftX, currentY + (infoLineHeight - iconSize) / 2, iconSize, iconSize);
  394. ctx.font = `bold ${Math.round(20 * rpxRatio)}px "PingFang-SC", sans-serif`;
  395. ctx.fillStyle = '#8B8B8B';
  396. ctx.fillText(posterData.time, leftX + iconSize + textLeftMargin, currentY + 25 * rpxRatio);
  397. currentY += infoLineHeight;
  398. // 3.3 绘制地点
  399. ctx.drawImage(addressIcon.path, leftX, currentY + (infoLineHeight - iconSize) / 2, iconSize, iconSize);
  400. ctx.fillText(posterData.address, leftX + iconSize + textLeftMargin, currentY + 25 * rpxRatio);
  401. currentY += infoLineHeight;
  402. // 3.4 绘制俱乐部
  403. const orgIconSize = 30 * rpxRatio;
  404. ctx.drawImage(orgIcon.path, leftX, currentY + (infoLineHeight - orgIconSize) / 2, orgIconSize, orgIconSize);
  405. ctx.fillText(posterData.organizer, leftX + orgIconSize + textLeftMargin, currentY + 25 * rpxRatio);
  406. // 4. 绘制右侧二维码
  407. const rightX = cardPadding + leftPartWidth;
  408. const qrY = cardPadding + mainImgHeight + infoTopMargin;
  409. ctx.drawImage(qrCode.path, rightX + (rightPartWidth - qrCodeWidth) / 2, qrY, qrCodeWidth, qrCodeHeight);
  410. // 4.1 绘制二维码下方文字
  411. ctx.textAlign = 'center';
  412. ctx.font = `bold ${Math.round(20 * rpxRatio)}px "PingFang-SC", sans-serif`;
  413. ctx.fillStyle = '#8B8B8B';
  414. ctx.fillText('微信扫一扫', rightX + rightPartWidth / 2, qrY + qrCodeHeight + 20 * rpxRatio);
  415. ctx.textAlign = 'left'; // 恢复默认
  416. // --- 生成图片 ---
  417. ctx.draw(false, () => {
  418. uni.canvasToTempFilePath({
  419. canvasId: 'posterCanvas',
  420. success: (res) => {
  421. posterUrl.value = res.tempFilePath;
  422. posterLoading.value = false;
  423. },
  424. fail: (err) => {
  425. console.error('canvasToTempFilePath failed:', err);
  426. proxy.$showToast('海报生成失败,请稍后再试');
  427. posterLoading.value = false;
  428. posterShow.value = false;
  429. }
  430. }, proxy);
  431. });
  432. } catch (error) {
  433. console.error('generatePoster failed:', error);
  434. proxy.$showToast('图片资源加载失败,无法生成海报');
  435. posterLoading.value = false;
  436. posterShow.value = false;
  437. }
  438. }
  439. // Canvas 文本换行绘制函数
  440. // ctx: canvas context, text: 文本, x,y: 起始坐标, maxWidth: 最大宽度, lineHeight: 行高, maxLines: 最大行数
  441. function drawWrappedText(ctx, text, x, y, maxWidth, lineHeight, maxLines = 2) {
  442. let lines = [];
  443. let currentLine = '';
  444. let totalHeight = 0;
  445. for (let i = 0; i < text.length; i++) {
  446. let char = text[i];
  447. let testLine = currentLine + char;
  448. let metrics = ctx.measureText(testLine);
  449. let testWidth = metrics.width;
  450. if (testWidth > maxWidth && i > 0) {
  451. lines.push(currentLine);
  452. currentLine = char;
  453. } else {
  454. currentLine = testLine;
  455. }
  456. }
  457. lines.push(currentLine);
  458. if (lines.length > maxLines) {
  459. lines = lines.slice(0, maxLines);
  460. lines[maxLines - 1] += '...';
  461. }
  462. for (let j = 0; j < lines.length; j++) {
  463. ctx.fillText(lines[j], x, y + j * lineHeight);
  464. totalHeight += lineHeight;
  465. }
  466. return totalHeight;
  467. }
  468. // 辅助函数,用于估算换行后的文本高度
  469. function calculateWrappedTextHeight(text, fontSize, maxWidth, lineHeight) {
  470. // 这是一个简化的估算,实际应使用canvas.measureText
  471. const charsPerLine = Math.floor(maxWidth / (fontSize * 1.1));
  472. const lines = Math.ceil(text.length / charsPerLine);
  473. return lines * lineHeight;
  474. }
  475. // --- 海报下方菜单点击事件 ---
  476. const handleMenuClick = (type) => {
  477. switch(type) {
  478. case 'shareApp':
  479. break;
  480. case 'shareTimeline':
  481. // 同上,提示用户
  482. uni.showToast({ title: '请点击右上角“···”分享到朋友圈', icon: 'none' });
  483. break;
  484. case 'favorite':
  485. uni.showModal({
  486. title: '收藏提示',
  487. content: "请点击右上角 '...' 按钮,然后选择 '添加到我的小程序' 或 '收藏',即可方便下次访问哦!",
  488. showCancel: false, // 通常只保留一个“我知道了”按钮
  489. confirmText: '我知道了'
  490. });
  491. break;
  492. case 'save':
  493. // 保存图片到相册
  494. savePosterToAlbum();
  495. break;
  496. }
  497. }
  498. // 保存海报到相册
  499. const savePosterToAlbum = () => {
  500. if (!posterUrl.value) {
  501. proxy.$showToast('海报图片不存在');
  502. return;
  503. }
  504. uni.saveImageToPhotosAlbum({
  505. filePath: posterUrl.value,
  506. success: () => {
  507. proxy.$showToast('海报已保存到相册');
  508. },
  509. fail: (err) => {
  510. if (err.errMsg.includes('auth deny') || err.errMsg.includes('auth denied')) {
  511. uni.showModal({
  512. title: '授权提示',
  513. content: '需要您授权保存图片到相册',
  514. showCancel: false,
  515. success: () => {
  516. uni.openSetting(); //引导用户去设置页
  517. }
  518. })
  519. } else {
  520. proxy.$showToast('保存失败,请稍后再试');
  521. }
  522. }
  523. })
  524. }
  525. const toWebView = () => {
  526. uni.navigateTo({
  527. url:'/pages/webView?src=https://mp.weixin.qq.com/s/-oQlSBucYU_ifgd1j6eL3A?scene=1&click_id=2'
  528. })
  529. }
  530. const getActivityDetail = (id) => {
  531. proxy.$api.get(`/core/activity/${id}`).then(({data:res})=>{
  532. if(res.code!==0) return proxy.$showToast(res.msg)
  533. activityInfo.value = res.data;
  534. // 更新海报数据
  535. posterData.title = activityInfo.value?.activityName || posterData.title;
  536. posterData.time = `${new Date(activityInfo.value?.activityStartTime).Format('MM.dd-hh:mm') } ~ ${new Date(activityInfo.value?.activityEndTime).Format('MM.dd-hh:mm')}` || posterData.time;
  537. posterData.address = `${activityInfo.value?.provinceName||''}${activityInfo.value?.cityName||''}${activityInfo.value?.address||''}` || posterData.address;
  538. posterData.organizer = activityInfo.value?.channelName || posterData.organizer;
  539. if(activityInfo.value?.coverFile) posterData.mainImg = activityInfo.value?.coverFile;
  540. if(activityInfo.value.signupState==0
  541. &&activityInfo.value.activeState===1
  542. &&activityInfo.value.recruitmentNow==(activityInfo.value.recruitmentMax||99999)){
  543. activityInfo.value.activeState = 4;//已报满暂无活动名额
  544. }
  545. imgList.value = activityInfo.value?.imageFiles&&(activityInfo.value?.imageFiles.split(',')||[])
  546. for(let i=0;i<activityInfo.value.recruitmentNow;i++){
  547. avatars.value.push('https://oss.familydaf.cn/sxsnfile/20251218/0a35e90f0fd543a1afa4e4bd7fc9b2f6.png')
  548. }
  549. })
  550. }
  551. onLoad(options=>{
  552. id.value = options?.id||options?.shareADId||'';
  553. if(id.value) {
  554. getActivityDetail(id.value)
  555. }
  556. })
  557. </script>
  558. <style scoped lang="scss">
  559. /* 按钮分享样式 */
  560. .share-btn {
  561. background-color: transparent;
  562. border: none;
  563. padding: 0;
  564. margin: 0;
  565. line-height: 1;
  566. display: flex;
  567. flex-direction: column;
  568. justify-content: center;
  569. align-items: center;
  570. &::after {
  571. border: none;
  572. }
  573. }
  574. .common_page{
  575. padding-bottom: 276rpx;
  576. .lunbo{
  577. width: 100%;
  578. height: 440rpx;
  579. margin-top: 20rpx;
  580. position: relative;
  581. }
  582. .box{
  583. background: linear-gradient(45deg,#FFFFFF 70%,#F2FFE8 100%);
  584. border-radius: 24rpx;
  585. padding: 36rpx 24rpx 30rpx;
  586. margin-top: 20rpx;
  587. position: relative;
  588. &-title{
  589. width: 170rpx;
  590. height: 44rpx;
  591. padding-left: 2rpx;
  592. font-family: PingFang-SC, PingFang-SC;
  593. font-weight: 800;
  594. font-size: 36rpx;
  595. color: #151B29;
  596. line-height: 36rpx;
  597. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  598. background-size: 170rpx 31rpx;
  599. background-position: 0 20rpx;
  600. background-repeat: no-repeat;
  601. }
  602. }
  603. .box1{
  604. &-top{
  605. &-status{
  606. padding: 10rpx 20rpx;
  607. background: url('https://oss.familydaf.cn/sxsnfile/20251218/5b591d1c173943dca6e33f950714e5e2.png') no-repeat;
  608. background-size: 100% 100%;
  609. font-family: PingFang-SC, PingFang-SC;
  610. font-weight: bold;
  611. font-size: 24rpx;
  612. color: #151B29;
  613. line-height: 33rpx;
  614. &.end{
  615. background: linear-gradient( 270deg, #FD8A8A 0%, #FE6161 100%);
  616. border-radius: 16px 4px 16px 4px;
  617. color: #FFFFFF;
  618. }
  619. }
  620. &-title{
  621. font-family: PingFang-SC, PingFang-SC;
  622. font-weight: bold;
  623. font-size: 36rpx;
  624. color: #151B29;
  625. line-height: 54rpx;
  626. margin-left: 10rpx;
  627. }
  628. }
  629. &-line{
  630. width: 100%;
  631. height: 1rpx;
  632. background: #E7E7E7;
  633. }
  634. &-place{
  635. &-left{
  636. width: calc(100% - 228rpx);
  637. text{
  638. font-family: PingFangSC, PingFang SC;
  639. font-weight: 400;
  640. font-size: 24rpx;
  641. color: #989998;
  642. line-height: 26rpx;
  643. }
  644. .addr{
  645. width: 100%;
  646. font-family: PingFang-SC, PingFang-SC;
  647. font-weight: bold;
  648. font-size: 26rpx;
  649. color: #151B29;
  650. line-height: 26rpx;
  651. margin-top: 24rpx;
  652. }
  653. }
  654. &-right{
  655. width: 188rpx;
  656. height: 115rpx;
  657. image{
  658. width: 100%;
  659. height: 100%;
  660. }
  661. }
  662. }
  663. &-member{
  664. margin-top: 37rpx;
  665. &-left{
  666. &>text{
  667. font-family: PingFangSC, PingFang SC;
  668. font-weight: 400;
  669. font-size: 24rpx;
  670. color: #989998;
  671. line-height: 26rpx;
  672. }
  673. .num{
  674. font-family: PingFang-SC, PingFang-SC;
  675. font-weight: bold;
  676. font-size: 26rpx;
  677. color: #676775;
  678. line-height: 48rpx;
  679. margin-top: 25rpx;
  680. text{
  681. font-size: 36rpx;
  682. color: #151B29;
  683. }
  684. }
  685. }
  686. &-right{
  687. .review{
  688. text{
  689. font-family: PingFangSC, PingFang SC;
  690. font-weight: 400;
  691. font-size: 24rpx;
  692. color: #989998;
  693. line-height: 26rpx;
  694. }
  695. image{
  696. width: 28rpx;
  697. height: 28rpx;
  698. margin-left: 8rpx;
  699. }
  700. }
  701. .avatars{
  702. margin-top: 27rpx;
  703. display: flex;
  704. justify-content: flex-end;
  705. }
  706. }
  707. }
  708. &-time{
  709. margin-top: 30rpx;
  710. text{
  711. font-family: PingFangSC, PingFang SC;
  712. font-weight: 400;
  713. font-size: 24rpx;
  714. color: #989998;
  715. line-height: 26rpx;
  716. }
  717. .text{
  718. font-family: PingFang-SC, PingFang-SC;
  719. font-weight: bold;
  720. font-size: 26rpx;
  721. color: #151B29;
  722. line-height: 26rpx;
  723. margin-top: 24rpx;
  724. }
  725. }
  726. &-need{
  727. margin-top: 30rpx;
  728. &>text{
  729. font-family: PingFangSC, PingFang SC;
  730. font-weight: 400;
  731. font-size: 24rpx;
  732. color: #989998;
  733. line-height: 26rpx;
  734. }
  735. .text{
  736. margin-top: 30rpx;
  737. font-family: PingFangSC, PingFang SC;
  738. font-weight: 400;
  739. font-size: 24rpx;
  740. color: #676775;
  741. line-height: 26rpx;
  742. text{
  743. font-weight: bold;
  744. font-size: 36rpx;
  745. color: #151B29;
  746. }
  747. }
  748. .tip{
  749. font-family: PingFangSC, PingFang SC;
  750. font-weight: 400;
  751. font-size: 24rpx;
  752. color: #C9A771;
  753. line-height: 26rpx;
  754. margin-top: 20rpx;
  755. }
  756. }
  757. &-info{
  758. margin-top: 30rpx;
  759. &-pre{
  760. width: 50%;
  761. &.line{
  762. border-left: 1rpx solid #E7E7E7;
  763. padding-left: 24rpx;
  764. box-sizing: border-box;
  765. }
  766. &>text{
  767. font-family: PingFangSC, PingFang SC;
  768. font-weight: 400;
  769. font-size: 24rpx;
  770. color: #989998;
  771. line-height: 26rpx;
  772. }
  773. .text{
  774. font-family: PingFang-SC, PingFang-SC;
  775. font-weight: bold;
  776. font-size: 26rpx;
  777. color: #151B29;
  778. line-height: 26rpx;
  779. margin-top: 24rpx;
  780. }
  781. .hour{
  782. margin-top: 24rpx;
  783. font-family: PingFangSC, PingFang SC;
  784. font-weight: 400;
  785. font-size: 24rpx;
  786. color: #676775;
  787. line-height: 26rpx;
  788. text{
  789. font-weight: bold;
  790. font-size: 36rpx;
  791. color: #151B29;
  792. }
  793. }
  794. }
  795. }
  796. }
  797. .box2{
  798. &-detail{
  799. margin-top: 40rpx;
  800. }
  801. }
  802. .bottom{
  803. width: 100%;
  804. height: 256rpx;
  805. background: #FFFFFF;
  806. box-shadow: 0rpx -2rpx 8rpx 0rpx rgba(178,178,178,0.1);
  807. position: fixed;
  808. left: 0;
  809. right: 0;
  810. bottom: 0;
  811. padding: 30rpx 24rpx 0;
  812. box-sizing: border-box;
  813. .time{
  814. padding: 19rpx 24rpx 12rpx;
  815. background: #F8F8F9;
  816. border-radius: 32rpx;
  817. font-family: PingFangSC, PingFang SC;
  818. font-weight: 400;
  819. font-size: 24rpx;
  820. color: #4B545C;
  821. line-height: 33rpx;
  822. }
  823. .btns{
  824. margin-top: 24rpx;
  825. .left{
  826. margin-left: 30rpx;
  827. text{
  828. font-family: PingFangSC, PingFang SC;
  829. font-weight: 400;
  830. font-size: 26rpx;
  831. color: #151B29;
  832. line-height: 26rpx;
  833. margin-top: 17rpx;
  834. }
  835. }
  836. .right{
  837. width: 540rpx;
  838. height: 90rpx;
  839. background: #B7F358;
  840. border-radius: 45rpx;
  841. font-family: PingFang-SC, PingFang-SC;
  842. font-weight: bold;
  843. font-size: 32rpx;
  844. color: #151B29;
  845. line-height: 90rpx;
  846. text-align: center;
  847. letter-spacing: 2rpx;
  848. &.end{
  849. background: #F7F7F7;
  850. }
  851. }
  852. }
  853. }
  854. .fail{
  855. position: fixed;
  856. left: 0;
  857. right: 0;
  858. top: 0;
  859. bottom: 0;
  860. background: rgba(0,0,0,0.4);
  861. display: flex;
  862. flex-direction: column;
  863. justify-content: flex-end;
  864. .fbox{
  865. background: #FFFFFF;
  866. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/f168e863e60b423588821f8aa0388e27.png');
  867. background-repeat: no-repeat;
  868. background-position: top left;
  869. background-size: 100% 399rpx;
  870. border-radius: 24rpx 24rpx 0 0;
  871. position: relative;
  872. padding: 40rpx 30rpx 123rpx;
  873. .clock{
  874. width: 219rpx;
  875. height: 143rpx;
  876. position: absolute;
  877. left: 51rpx;
  878. top: -37rpx;
  879. }
  880. .close{
  881. width: 40rpx;
  882. height: 40rpx;
  883. position: absolute;
  884. top: 40rpx;
  885. right: 36rpx;
  886. }
  887. .alert{
  888. width: 212rpx;
  889. }
  890. .texts{
  891. width: 100%;
  892. margin-top: 69rpx;
  893. background: #FFFFFF;
  894. border-radius: 24rpx;
  895. border: 1rpx dotted #979797;
  896. padding: 36rpx 0;
  897. .text{
  898. font-family: PingFang-SC, PingFang-SC;
  899. font-weight: bold;
  900. font-size: 36rpx;
  901. color: #252525;
  902. line-height: 36rpx;
  903. }
  904. .tip{
  905. font-family: PingFangSC, PingFang SC;
  906. font-weight: 400;
  907. font-size: 24rpx;
  908. color: #676775;
  909. line-height: 26rpx;
  910. margin-top: 24rpx;
  911. }
  912. }
  913. .down{
  914. width: 514rpx;
  915. height: 34rpx;
  916. margin-top: 20rpx;
  917. }
  918. .user{
  919. width: 100%;
  920. margin-top: 50rpx;
  921. box-sizing: border-box;
  922. font-family: PingFang-SC, PingFang-SC;
  923. font-weight: bold;
  924. font-size: 32rpx;
  925. color: #252525;
  926. line-height: 32rpx;
  927. }
  928. .finfo{
  929. width: 100%;
  930. margin-top: 36rpx;
  931. &-code{
  932. width: 310rpx;
  933. height: 310rpx;
  934. background: #FFFFFF;
  935. border: 3rpx solid #C5E3FE;
  936. image{
  937. width: 244rpx;
  938. height: 244rpx;
  939. }
  940. }
  941. &-title{
  942. margin-top: 24rpx;
  943. font-size: 28rpx;
  944. color: #252525;
  945. line-height: 40rpx;
  946. }
  947. &-tip{
  948. margin-top: 10rpx;
  949. font-size: 24rpx;
  950. color: #656775;
  951. line-height: 40rpx;
  952. }
  953. &-btn{
  954. width: calc(100% - 20rpx);
  955. height: 90rpx;
  956. background: #B7F358;
  957. border-radius: 45rpx;
  958. font-family: PingFang-SC, PingFang-SC;
  959. font-weight: bold;
  960. font-size: 32rpx;
  961. color: #151B29;
  962. line-height: 90rpx;
  963. text-align: center;
  964. margin-top: 48rpx;
  965. }
  966. &-zblj{
  967. font-family: PingFangSC, PingFang SC;
  968. font-weight: 400;
  969. font-size: 28rpx;
  970. color: #989998;
  971. line-height: 40rpx;
  972. margin-top: 48rpx;
  973. padding-bottom: 5rpx;
  974. border-bottom: 1rpx solid #989998;
  975. }
  976. }
  977. }
  978. }
  979. .share{
  980. position: fixed;
  981. left: 0;
  982. right: 0;
  983. top: 0;
  984. bottom: 0;
  985. z-index: 1000;
  986. background: rgba(0,0,0,0.4);
  987. display: flex;
  988. flex-direction: column;
  989. justify-content: flex-end;
  990. .sbox{
  991. position: relative;
  992. background: #FFFFFF;
  993. border-radius: 24rpx 24rpx 0rpx 0rpx;
  994. padding: 50rpx 30rpx 148rpx;
  995. &-title{
  996. font-family: PingFang-SC, PingFang-SC;
  997. font-weight: bold;
  998. font-size: 36rpx;
  999. color: #151B29;
  1000. line-height: 36rpx;
  1001. text-align: center;
  1002. }
  1003. .close{
  1004. width: 27rpx;
  1005. height: 27rpx;
  1006. position: absolute;
  1007. top: 50rpx;
  1008. right: 40rpx;
  1009. }
  1010. &-items{
  1011. margin-top: 88rpx;
  1012. &-pre{
  1013. width: calc(100% / 3);
  1014. image{
  1015. width: 94rpx;
  1016. height: 94rpx;
  1017. }
  1018. text{
  1019. font-family: PingFangSC, PingFang SC;
  1020. font-weight: 400;
  1021. font-size: 26rpx;
  1022. color: #252525;
  1023. line-height: 26rpx;
  1024. text-align: center;
  1025. margin-top: 24rpx;
  1026. }
  1027. }
  1028. }
  1029. }
  1030. }
  1031. .posterbox{
  1032. position: fixed;
  1033. left: 0;
  1034. right: 0;
  1035. top: 0;
  1036. bottom: 0;
  1037. z-index: 1001;
  1038. background: rgba(0,0,0,0.7);
  1039. .posterbox-card{
  1040. width: calc(100% - 220rpx);
  1041. .poster-image {
  1042. width: 100%;
  1043. border-radius: 8px; // 给生成的图片也加个圆角,更美观
  1044. }
  1045. }
  1046. &-menu{
  1047. width: 100%;
  1048. margin-top: 239rpx;
  1049. &-pre{
  1050. width: 25%;
  1051. image{
  1052. width: 103rpx;
  1053. height: 104rpx;
  1054. }
  1055. text{
  1056. font-family: PingFangSC, PingFang SC;
  1057. font-weight: 400;
  1058. font-size: 24rpx;
  1059. color: rgba(255,255,255,0.6);
  1060. line-height: 33rpx;
  1061. margin-top: 32rpx;
  1062. }
  1063. }
  1064. }
  1065. &-close{
  1066. margin-top: 58rpx;
  1067. image{
  1068. width: 64rpx;
  1069. height: 64rpx;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. </style>