activityDetail.vue 35 KB

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