activityDetail.vue 36 KB

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