activityDetail.vue 36 KB

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