index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <view class="activity" catchtouchmove="true" :style="pageIndex == 1 ? 'background-image:none;background-color:#e03519;padding:0 0 120rpx' : ''">
  3. <!-- <view class="rule" @click="showRule">活动规则</view> -->
  4. <!-- logo与跑马灯 -->
  5. <view class="header">
  6. <img :src="acticve_detail.logo" class="logo" v-if="pageIndex == 1" mode="widthFix" />
  7. <view class="barrage-box" :style="pageIndex == 1 ? 'margin-top:0' : ''">
  8. <view class="text">{{ lottery_list }}</view>
  9. </view>
  10. </view>
  11. <!-- 立即参与页面 -->
  12. <view class="page-1" v-if="pageIndex == 1" style="padding: 0 16rpx">
  13. <view class="activity-info">
  14. <text class="title">{{ acticve_detail?.name }}</text>
  15. <view class="active-rule">
  16. <rich-text :nodes="acticve_detail.active_rule" class="rich_text"></rich-text>
  17. </view>
  18. </view>
  19. <view class="activity-btn" @click="_handleChangePage(1)">立即参与</view>
  20. </view>
  21. <!-- 答题页面 -->
  22. <view class="page-2" v-if="pageIndex == 2">
  23. <!-- 题干区域 -->
  24. <view class="question">
  25. <text>猜灯谜:{{ question.title }}</text>
  26. <br />
  27. <view style="margin-top: 20rpx">(请从下面选择正确答案提交)</view>
  28. </view>
  29. <!-- 选项区域 -->
  30. <view class="options">
  31. <view :class="['option', { active: answer_id == item.id }]" v-for="item in question.answer_list" :key="item.id" @click="_handleSelectAnswer(item.id)">{{ item.value }}</view>
  32. </view>
  33. <!-- 提交答案 -->
  34. <button :class="['submit-btn', { disabled: !answer_id }]" @click="_handleSubmitAnswer">提交</button>
  35. </view>
  36. <!-- 结果页面 -->
  37. <view class="page-3" v-if="pageIndex == 3">
  38. <view class="no-join-number" v-if="acticve_detail.join_last == 0 && acticve_detail.share_last == 0 && isFromIndex">
  39. <view class="header">
  40. <text>您的答题次数已用完!</text>
  41. <text>谢谢参与</text>
  42. </view>
  43. <view class="tip">
  44. <text>1.余额请前往小程序余额页面申请提现</text>
  45. <text>2.实物奖励请填写收获地址或者等待客服进行充值</text>
  46. </view>
  47. </view>
  48. <view v-else>
  49. <!-- 结果展示 -->
  50. <view class="result-success result-content" v-if="is_answer">
  51. <view class="result-text" style="color: #fff">恭喜您,答对啦!</view>
  52. <view class="result-btn" @click="_goLottery">立即抽奖</view>
  53. </view>
  54. <view class="result-fail result-content" v-if="!is_answer">
  55. <view class="result-text" style="color: #fff">很遗憾,您答错了!</view>
  56. <button open-type="share" class="result-btn">分享给好友再来一次</button>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 抽奖入口 -->
  61. <view class="lottery-entrance" v-if="showLottery">
  62. <view class="close-btn" @click="_handleCloseLottery">x</view>
  63. <image @click="_goLottery" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174439.gif" alt="" />
  64. </view>
  65. </view>
  66. </template>
  67. <script setup>
  68. import { ref, getCurrentInstance } from "vue";
  69. import { onShareAppMessage, onLoad, onShow } from "@dcloudio/uni-app";
  70. import http from "@/utils/request";
  71. const { appContext } = getCurrentInstance();
  72. const $checkAccess = appContext.config.globalProperties.$checkAccess;
  73. const pageIndex = ref(1);
  74. const question = ref({
  75. title: "",
  76. answer_list: [],
  77. });
  78. const showLottery = ref(true);
  79. const acticve_detail = ref({});
  80. const detialId = ref(null);
  81. const answer_id = ref(null);
  82. const is_answer = ref(false);
  83. const lottery_list = ref("还没有人中奖,快来参与吧!");
  84. const isFromIndex = ref(false);
  85. onLoad((options) => {
  86. //未登陆提醒用户登陆
  87. if (!$checkAccess.checkLogin()) {
  88. uni.showModal({
  89. title: "温馨提示",
  90. content: "请先登录",
  91. confirmText: "去登录",
  92. cancelText: "取消",
  93. success: (res) => {
  94. if (res.confirm) {
  95. uni.redirectTo({
  96. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${options.id}`,
  97. });
  98. }
  99. },
  100. });
  101. return;
  102. }
  103. if (options.id) {
  104. _getDeatail(detialId.value);
  105. detialId.value = options.id;
  106. }
  107. // #ifdef MP-WEIXIN
  108. //分享按钮
  109. uni.showShareMenu({
  110. withShareTicket: true,
  111. menus: ["shareAppMessage", "shareTimeline"],
  112. });
  113. // #endif
  114. });
  115. onShow(() => {
  116. console.log("回到小程序");
  117. if (detialId.value) {
  118. _getDeatail(detialId.value);
  119. }
  120. });
  121. // 定义页面的分享逻辑
  122. onShareAppMessage((res) => {
  123. if (res) {
  124. _addShare();
  125. }
  126. return {
  127. title: "正月十五猜灯谜",
  128. path: `/pages/activity/index?id=${detialId.value}`,
  129. imageUrl: "https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174500.jpg",
  130. };
  131. });
  132. const _handleCloseLottery = () => {
  133. showLottery.value = false;
  134. };
  135. const _getDeatail = (id) => {
  136. http.request("api/riddle_active/get_detail", { id }).then((response) => {
  137. if (response.code == "success") {
  138. acticve_detail.value = response.data;
  139. if (response.data.join_last > 0) {
  140. _getQuestion();
  141. pageIndex.value = 1;
  142. }
  143. http.request("api/lottery_riddle_record/get_list_all", { lottery_id: response.data.lottery_id }).then((res) => {
  144. if (res.code == "success") {
  145. if (res.data?.length > 0) {
  146. let str = "";
  147. res.data.forEach((item) => {
  148. str += `用户${item.username}已获得${item.reward_name};`;
  149. });
  150. lottery_list.value = str;
  151. }
  152. }
  153. });
  154. }
  155. });
  156. };
  157. const _getQuestion = () => {
  158. http.request("api/riddle_question/get_question").then((response) => {
  159. if (response.code == "success") {
  160. question.value = response.data;
  161. }
  162. });
  163. };
  164. const _handleSelectAnswer = (id) => {
  165. answer_id.value = id;
  166. };
  167. const _handleSubmitAnswer = () => {
  168. if (!answer_id.value) return;
  169. const _param = {
  170. active_id: detialId.value,
  171. question_id: question.value.id,
  172. answer_id: answer_id.value,
  173. };
  174. http.request("api/riddle_answer/check_answer", _param).then((response) => {
  175. if (response.code == "success") {
  176. pageIndex.value = 3;
  177. _getDeatail(detialId.value);
  178. is_answer.value = response.data.is_answer;
  179. }
  180. });
  181. };
  182. const _addShare = () => {
  183. http.request("api/riddle_active_share/add", { active_id: detialId.value }).then((response) => {});
  184. };
  185. const _goLottery = () => {
  186. if (!$checkAccess.checkLogin()) {
  187. uni.showModal({
  188. title: "温馨提示",
  189. content: "请先登录",
  190. confirmText: "去登录",
  191. cancelText: "取消",
  192. success: (res) => {
  193. if (res.confirm) {
  194. uni.redirectTo({
  195. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${detialId.value}`,
  196. });
  197. }
  198. },
  199. });
  200. return;
  201. }
  202. uni.navigateTo({
  203. url: `/pages/activity/lottery?id=${acticve_detail.value.lottery_id}&activity_id=${detialId.value}`,
  204. });
  205. setTimeout(() => {
  206. pageIndex.value = 1;
  207. }, 1000);
  208. };
  209. const _handleChangePage = (index) => {
  210. if (index == 1 && acticve_detail.value.join_last > 0) {
  211. pageIndex.value = 2;
  212. } else {
  213. pageIndex.value = 3;
  214. if (acticve_detail.value.join_last == 0 && acticve_detail.value.share_last == 0) {
  215. isFromIndex.value = true;
  216. }
  217. }
  218. };
  219. </script>
  220. <style lang="less" scoped>
  221. .activity {
  222. padding: 0 16rpx 120rpx;
  223. height: 100vh;
  224. box-sizing: border-box;
  225. overflow: hidden;
  226. position: relative;
  227. width: 100vw;
  228. background-image: url("https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174500.jpg");
  229. background-repeat: no-repeat;
  230. background-size: 100% 100%;
  231. .header {
  232. .logo {
  233. width: 100%;
  234. }
  235. .barrage-box {
  236. padding: 10rpx;
  237. width: 100%;
  238. transform-origin: 65vw 75vw;
  239. transform: rotate(0deg);
  240. white-space: nowrap;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. z-index: 3;
  245. box-sizing: border-box;
  246. background-color: #fff;
  247. opacity: 0.8;
  248. overflow-x: hidden;
  249. margin-top: 20rpx;
  250. }
  251. .text {
  252. width: 200vw; //调整文字显示
  253. font-size: 16px;
  254. color: #333;
  255. animation: aniMove 8s linear infinite;
  256. animation-fill-mode: forwards;
  257. }
  258. /* 文字滚动 */
  259. @keyframes aniMove {
  260. 0% {
  261. transform: translateX(100%);
  262. }
  263. 100% {
  264. transform: translateX(-100%);
  265. }
  266. }
  267. }
  268. .page-1 {
  269. width: 100%;
  270. display: flex;
  271. align-items: center;
  272. flex-direction: column;
  273. justify-content: center;
  274. box-sizing: border-box;
  275. .activity-info {
  276. padding-top: 100rpx;
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. justify-content: center;
  281. width: 100%;
  282. .title {
  283. font-size: 46rpx;
  284. font-weight: bold;
  285. color: #fff;
  286. text-align: center;
  287. margin-bottom: 40rpx;
  288. }
  289. .active-rule {
  290. display: block;
  291. height: 500rpx;
  292. width: 100%;
  293. font-size: 24rpx;
  294. line-height: 40rpx;
  295. border-radius: 10rpx;
  296. padding: 20rpx;
  297. box-sizing: border-box;
  298. margin-bottom: 40rpx;
  299. background-color: #ffffff;
  300. opacity: 0.8;
  301. .rich_text {
  302. white-space: break-spaces;
  303. }
  304. }
  305. }
  306. .activity-btn {
  307. width: 90%;
  308. background-color: #e7522f;
  309. color: #fff;
  310. border-radius: 60rpx;
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. padding: 16rpx;
  315. }
  316. }
  317. .page-2 {
  318. height: 100%;
  319. display: flex;
  320. flex-direction: column;
  321. z-index: 10;
  322. width: 100%;
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. justify-content: center;
  327. .question {
  328. // 题干的样式
  329. background-color: #fff;
  330. height: 200rpx;
  331. border-radius: 6rpx;
  332. padding: 26rpx;
  333. opacity: 0.95;
  334. margin-bottom: 60rpx;
  335. }
  336. .options {
  337. // 选项的样式
  338. display: flex;
  339. gap: 20rpx;
  340. flex-direction: column;
  341. width: 100%;
  342. > .option {
  343. height: 80rpx;
  344. line-height: 80rpx;
  345. padding-left: 26rpx;
  346. border-radius: 6rpx;
  347. background-color: #fff;
  348. margin-bottom: 20rpx;
  349. opacity: 0.95;
  350. width: 100%;
  351. box-sizing: border-box;
  352. &.active {
  353. background-color: #ffd6a0;
  354. }
  355. }
  356. }
  357. .submit-btn {
  358. width: 100%;
  359. height: 80rpx;
  360. background-color: #ffd6a0;
  361. color: #7e4304;
  362. border-radius: 60rpx;
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. padding: 16rpx;
  367. margin-top: 60rpx;
  368. &.disabled {
  369. background-color: #ccc;
  370. }
  371. }
  372. }
  373. .page-3 {
  374. width: 100%;
  375. height: 100%;
  376. display: flex;
  377. flex-direction: column;
  378. align-items: center;
  379. justify-content: center;
  380. opacity: 0.95;
  381. .result-content {
  382. width: 100%;
  383. .result-text {
  384. font-size: 46rpx;
  385. font-weight: bold;
  386. color: #fff;
  387. text-align: center;
  388. margin-bottom: 40rpx;
  389. }
  390. .result-btn {
  391. width: 100%;
  392. height: 80rpx;
  393. background-color: #f0370e;
  394. color: #fff;
  395. border-radius: 60rpx;
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. padding: 16rpx;
  400. margin-top: 60rpx;
  401. box-sizing: border-box;
  402. }
  403. }
  404. .no-join-number {
  405. width: 100%;
  406. background-color: #fff;
  407. border-radius: 6rpx;
  408. padding: 26rpx;
  409. opacity: 0.95;
  410. margin-bottom: 60rpx;
  411. display: flex;
  412. flex-direction: column;
  413. box-sizing: border-box;
  414. gap: 40rpx;
  415. font-size: 36rpx;
  416. .header {
  417. display: flex;
  418. flex-direction: column;
  419. align-items: center;
  420. justify-content: center;
  421. gap: 20rpx;
  422. }
  423. .tip {
  424. font-size: 24rpx;
  425. display: flex;
  426. flex-direction: column;
  427. gap: 20rpx;
  428. }
  429. }
  430. }
  431. .lottery-entrance {
  432. position: absolute;
  433. z-index: 10;
  434. right: 20rpx;
  435. bottom: 100rpx;
  436. image {
  437. width: 160rpx;
  438. height: 160rpx;
  439. }
  440. .close-btn {
  441. width: 40rpx;
  442. height: 40rpx;
  443. font-size: 24rpx;
  444. line-height: 40rpx;
  445. border-radius: 50%;
  446. border: 1rpx solid #ddd;
  447. display: flex;
  448. align-items: center;
  449. justify-content: center;
  450. position: absolute;
  451. top: 5rpx;
  452. right: 0;
  453. color: #fff;
  454. }
  455. }
  456. }
  457. </style>