index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. <template>
  2. <view class="sign">
  3. <image src="../../static/sign_back.png" class="back" mode="widthFix"></image>
  4. <view class="signCenter">
  5. <!-- 个人信息模块 -->
  6. <view class="signTop">
  7. <view class="left">
  8. <view class="avatarView">
  9. <open-data type="userAvatarUrl" class="avatar"></open-data>
  10. </view>
  11. <view class="userInfo">
  12. <view class="account">{{signData.mpName}}</view>
  13. <view class="ID">ID:{{signData.userId}}</view>
  14. </view>
  15. </view>
  16. <navigator v-if="mpAppIdShow" :url="'../checkInRecord/checkInRecord?openId=' + openId + '&mpAppId=' + mpData.mpAppId + '&mpOpenId=' + mpData.mpOpenId" class="right">
  17. <image src="../../static/signRecord.png" mode="widthFix"></image>
  18. <text>签到记录</text>
  19. </navigator>
  20. </view>
  21. <view class="signBottom">
  22. <!-- 滚动通知 -->
  23. <view class="notice">
  24. <image src="../../static/horn.png" class="horn" mode="widthFix"></image>
  25. <view class="txts">
  26. <u-notice-bar mode="vertical" :volume-icon="false" color="#FFFFFF" type="none" :list="list"></u-notice-bar>
  27. </view>
  28. </view>
  29. <!-- 签到展示模块 -->
  30. <view class="exhibitionContent" v-if="signData.signInDayVoList.length > 0">
  31. <view class="ts">已连续签到{{signData.sustainDayCount}}天,有{{signData.canSupplement}}次补签机会</view>
  32. <view class="signinExhibition">
  33. <view v-for="(item, index) in signData.signInDayVoList" :key="index" :class="item.signIn ? 'select' : item.canSupplement ? 'repairSign' : ''">
  34. <template v-if="index < 6">
  35. <view class="repair" v-if="item.canSupplement">看视频补签</view>
  36. <text class="day">{{item.dayDescribe}}</text>
  37. <image src="../../static/goldSelect.png" class="goldCoins" style="width: 68rpx;" mode="heightFix" v-if="item.signIn"></image>
  38. <image src="../../static/clickVideo.png" class="goldCoins" mode="heightFix" style="position: relative; z-index: 101;" @click="showVideoAd(2, item)" v-else-if="item.canSupplement"></image>
  39. <image src="../../static/gold.png" class="goldCoins" style="width: 68rpx;" mode="heightFix" v-else></image>
  40. <text class="reward">{{item.bookCoin}}书币</text>
  41. <image src="../../static/signSub.png" class="signSub" mode="widthFix" v-if="item.signIn"></image>
  42. </template>
  43. <template v-else>
  44. <view class="left">
  45. <text class="day">{{item.dayDescribe}}</text>
  46. <text class="reward">{{item.bookCoin}}书币</text>
  47. </view>
  48. <view class="right">
  49. <image src="../../static/giftBag.png" mode="heightFix" v-if="!item.signIn"></image>
  50. <image src="../../static/giftBagSelect.png" mode="heightFix" v-else></image>
  51. </view>
  52. <image src="../../static/signSub.png" class="signSub" mode="widthFix" v-if="item.signIn"></image>
  53. </template>
  54. </view>
  55. </view>
  56. <template v-if="!mpAppIdShow">
  57. <view class="gignBt" @click="tsAccount" v-if="isSignIn" :animation="btAnimationData">签到领书币</view>
  58. <view class="already" v-else>今日已签</view>
  59. </template>
  60. <template v-else>
  61. <!-- <navigator url="../officialAccount/officialAccount" class="gignBt" v-if="!signData.mpName" :animation="btAnimationData">签到领书币</navigator> -->
  62. <view class="gignBt" @click="tsAccount" v-if="!signData.mpName" :animation="btAnimationData">签到领书币</view>
  63. <view class="gignBt" @click="signIn" v-else-if="!isSignIn" :animation="btAnimationData">签到领书币</view>
  64. <!-- <view class="already" v-else>今日已签</view> -->
  65. <view class="gignBt" v-else @click="moreGold" :animation="btAnimationData">去抽奖获更多奖励</view>
  66. </template>
  67. </view>
  68. <!-- 签到提醒模块 -->
  69. <view class="signRemind">
  70. <text>签到提醒</text>
  71. <view class="remindSwitch">
  72. <view :class="signRemind ? 'open' : 'close'" @click="signRemindHandle(true)">
  73. <view class="select"></view>
  74. <text>开启</text>
  75. </view>
  76. <view :class="!signRemind ? 'open' : 'close'" @click="signRemindHandle(false)">
  77. <view class="select"></view>
  78. <text>关闭</text>
  79. </view>
  80. </view>
  81. </view>
  82. <ad-view :unitId="adConfig.bannerAd" adIntervals="200"></ad-view>
  83. <!-- 活动规则模块 -->
  84. <view class="activityRules">
  85. <view class="top" @click="activityRulesHandle">
  86. <text>活动规则</text>
  87. <image :src="!activityRules ? '../../static/unfold.png' : '../../static/retract.png'" mode="widthFix"></image>
  88. </view>
  89. <view class="bottom" v-if="activityRules">
  90. <view>
  91. 1.用户进入每日送书币小程序后,每日首次打开小程序,点击签到按钮即可完成一次签到。
  92. </view>
  93. <view>
  94. 2.签到获得的书币奖励,在领取日后天效。连续签到所得书币奖励在周期内稍有变化,非均等分布。连续7日完成签到的用户在第7日可获得更多的奖励。
  95. </view>
  96. <view>
  97. 3.用户每个周期(7天),至多拥有2次补签机会(连续签到2天拥有1次补签机会,一天内只允许补签一次空缺天数),可通过观看小视频获得,连续未签到2天,签到重新开始。
  98. </view>
  99. <view>
  100. 4.连续签到:自首日完成签到开始累计,连续7天签到为一个周期。签到中断,则重新开始计算。
  101. </view>
  102. <view>
  103. 5.每日同一注册用户仅可参与一次。
  104. </view>
  105. <view>
  106. 6.本活动解释权由开发者所有,有任何疑问请联系公众号内客服。
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- 金币飞行组 -->
  112. <view class="fragmentGold" :animation="animationDatas[index]" v-for="(item, index) in goldData" :key="index" :style="{top: item.top, left: item.left}">
  113. <image src="../../static/gold.png" mode="widthFix"></image>
  114. </view>
  115. <!-- 去抽奖路口 -->
  116. <view class="qLuckDraw" @click="moreGold" v-if="mpAppIdShow">
  117. <image src="../../static/1234.gif" mode="widthFix"></image>
  118. </view>
  119. </view>
  120. <!-- -->
  121. <view class="popup" v-if="popupShow">
  122. <view class="popupContent">
  123. <view class="content">
  124. <image src="../../static/popupBack.png"></image>
  125. <view class="textCon">
  126. <text class="ts">签到成功!</text> </br>
  127. <text class="reward">恭喜您获得{{signInDay.bookCoin}}书币</text> </br>
  128. <image src="../../static/doubleBt.png" class="doubleBt" mode="widthFix" :style="{transform: `scale(${scale})`}" @click="lookVideo"></image> </br>
  129. <text :class="['bt', { btTrue: status }]" @click="signInHandle(false)">不了,单倍领取</text>
  130. </view>
  131. </view>
  132. <image src="../../static/close.png" class="close" mode="widthFix" @click="closeHandle"></image>
  133. </view>
  134. </view>
  135. <!-- 弹窗提示 -->
  136. <view class="receiveTs" :animation="animationDataTs">
  137. {{tsTitle}}
  138. </view>
  139. <!-- 格子广告 -->
  140. <!-- <view class="singleLattice">
  141. <ad-custom-view :unit-id="adConfig.singleLatticeAd" adIntervals="200"></ad-custom-view>
  142. </view> -->
  143. </view>
  144. </template>
  145. <script>
  146. let timer = null, btTimer = null, adTimer = null, powerOnTimer = null
  147. import { config, getHome, getOpenId, signInAjax, getTemplateIDs, setMessage, switchUpdate, getState } from '@/api/api.js'
  148. import { bannerAd, urgeVideoAd, insertScreenAd, singleLatticeAd } from '@/utils/ad_config.js'
  149. import adView from '@/components/ad-view/ad-view.vue'
  150. import adCustomView from '@/components/ad-custom-view/ad-custom-view.vue'
  151. export default {
  152. components: {
  153. adView,
  154. adCustomView
  155. },
  156. data() {
  157. return {
  158. adConfig: {
  159. bannerAd,
  160. singleLatticeAd
  161. },
  162. list: [
  163. '恭喜用户 “0016” 成功提现 200书币',
  164. '恭喜用户 “1037” 成功提现 10书币',
  165. '恭喜用户 “9128” 成功提现 20书币',
  166. '恭喜用户 “1873” 成功提现 140书币',
  167. '恭喜用户 “9834” 成功提现 200书币',
  168. '恭喜用户 “5623” 成功提现 10书币',
  169. '恭喜用户 “0934” 成功提现 20书币',
  170. '恭喜用户 “7843” 成功提现 60书币',
  171. '恭喜用户 “1344” 成功提现 20书币',
  172. '恭喜用户 “5464” 成功提现 140书币',
  173. '恭喜用户 “0823” 成功提现 200书币',
  174. '恭喜用户 “8910” 成功提现 10书币',
  175. '恭喜用户 “0714” 成功提现 20书币',
  176. ],
  177. signRemind: false, // 是否开启签到提醒
  178. activityRules: false, // 是否展开活动规则
  179. popupShow: false, // 弹窗控制
  180. signData: {
  181. sustainDayCount: 0,
  182. canSupplement: 0,
  183. userId: null,
  184. mpName: null,
  185. signInDayVoList: [
  186. {
  187. signIn: false,
  188. canSupplement: false,
  189. dayDescribe: '第一天',
  190. bookCoin: 10,
  191. isSignIn: true
  192. },
  193. {
  194. signIn: false,
  195. canSupplement: false,
  196. dayDescribe: '第二天',
  197. bookCoin: 20,
  198. isSignIn: false
  199. },
  200. {
  201. signIn: false,
  202. canSupplement: false,
  203. dayDescribe: '第三天',
  204. bookCoin: 30,
  205. isSignIn: false
  206. },
  207. {
  208. signIn: false,
  209. canSupplement: false,
  210. dayDescribe: '第四天',
  211. bookCoin: 40,
  212. isSignIn: false
  213. },
  214. {
  215. signIn: false,
  216. canSupplement: false,
  217. dayDescribe: '第五天',
  218. bookCoin: 50,
  219. isSignIn: false
  220. },
  221. {
  222. signIn: false,
  223. canSupplement: false,
  224. dayDescribe: '第六天',
  225. bookCoin: 60,
  226. isSignIn: false
  227. },
  228. {
  229. signIn: false,
  230. canSupplement: false,
  231. dayDescribe: '第七天',
  232. bookCoin: 70,
  233. isSignIn: false
  234. },
  235. ]
  236. }, // 签到相关信息
  237. openId: '',
  238. mpData: {}, // 公众号相关
  239. isSignIn: true, // 是否已经签到
  240. userId: undefined, // 用户ID
  241. signIdTemID: [], // 签到提醒模板ID
  242. isMainSwitch: true, // 是否关闭了通知按钮
  243. isAlwaysCancel: false, // 是否点击了总是允许取消
  244. signInDay: {}, // 今天签到信息
  245. scale: 1,
  246. btAnimation: null, // 按钮呼吸动画实例
  247. btAnimationData: {}, // 按钮呼吸动画
  248. btScale: 1,
  249. tsTitle: '+100金币', // 提示文字
  250. durationMath1: 20,
  251. durationMath2: 20,
  252. animationDataTs: {}, // 提示文字动画
  253. goldData: [
  254. {top: '532rpx', left: '82rpx'},
  255. {top: '532rpx', left: '252rpx'},
  256. {top: '532rpx', left: '426rpx'},
  257. {top: '532rpx', left: '600rpx'},
  258. {top: '724rpx', left: '82rpx'},
  259. {top: '724rpx', left: '252rpx'},
  260. {top: '724rpx', left: '426rpx'},
  261. {top: '724rpx', left: '484rpx'}
  262. ],
  263. animationDatas: [null, null, null, null, null, null, null, null], // 金币动画组
  264. getIntoCount: 0,
  265. loading: false,
  266. powerOnTimer: new Date().getTime(), // 保存当前进入页面的时间挫
  267. isVideoType: null, // 1 是否是看视频签到 2 是否是补签
  268. repairSignData: null, // 保存补签的信息
  269. powerOnCount: 0, // 记录开机秒数
  270. mpAppIdShow: false,
  271. status: false
  272. }
  273. },
  274. watch: {
  275. 'signData.signInDayVoList':{
  276. handler(val, oldVal){
  277. if (val.length > 0) {
  278. let signInDay = val.find(item => item.canSign)
  279. if (signInDay) {
  280. this.isSignIn = signInDay.signIn
  281. }
  282. }
  283. },
  284. deep: true
  285. },
  286. popupShow(newVal, oldVal) {
  287. if(newVal) {
  288. timer = setInterval(() => {
  289. if(this.scale === 1) {
  290. this.scale = 0.92
  291. }else {
  292. this.scale = 1
  293. }
  294. }, 500)
  295. } else {
  296. timer && clearInterval(timer)
  297. }
  298. }
  299. },
  300. onLoad(options) {
  301. this.mpData = options
  302. try {
  303. const value = uni.getStorageSync('storage_key');
  304. if (value) { // 内存找到有
  305. this.mpAppIdShow = true
  306. if (options.mpAppId) {
  307. // 链接上带有保存
  308. uni.setStorageSync('storage_key', options.mpAppId);
  309. // uni.setNavigationBarTitle({ title: '签到有礼' })
  310. }
  311. } else {
  312. // 内存没找到
  313. if (options.mpAppId) {
  314. // 链接上带有
  315. this.mpAppIdShow = true
  316. uni.setStorageSync('storage_key', options.mpAppId);
  317. // uni.setNavigationBarTitle({ title: '签到有礼' })
  318. } else {
  319. this.mpAppIdShow = false
  320. // uni.setNavigationBarTitle({ title: '生成二维码' })
  321. }
  322. }
  323. } catch (e) {
  324. // error
  325. console.log(2222222, e);
  326. }
  327. uni.login({
  328. success: async res => {
  329. if (res.code) {
  330. let openIDInfo = await getOpenId({appId: config.appid, code: res.code})
  331. this.openId = openIDInfo.data
  332. this.getList()
  333. }
  334. }
  335. })
  336. getState({appId: config.appid}).then(res => {
  337. this.status = res.data || false
  338. })
  339. },
  340. onShareAppMessage() {},
  341. onReady() {
  342. this.createInterstitialAd()
  343. this.btAnimation = uni.createAnimation({ timingFunction: 'ease' })
  344. this.btBreathAni()
  345. this.powerOnShowAd()
  346. },
  347. onUnload() {
  348. console.log('onUnload---->')
  349. timer && clearInterval(timer)
  350. btTimer && clearInterval(btTimer)
  351. this.interstitialAd.destroy()
  352. adTimer && clearTimeout(adTimer)
  353. powerOnTimer && clearInterval(powerOnTimer)
  354. },
  355. methods: {
  356. // 提示关注公众号
  357. tsAccount() {
  358. this.signData = {
  359. sustainDayCount: 1,
  360. canSupplement: 0,
  361. userId: null,
  362. mpName: null,
  363. signInDayVoList: [
  364. {
  365. signIn: true,
  366. canSupplement: false,
  367. dayDescribe: '第一天',
  368. bookCoin: 10,
  369. isSignIn: true
  370. },
  371. {
  372. signIn: false,
  373. canSupplement: false,
  374. dayDescribe: '第二天',
  375. bookCoin: 20,
  376. isSignIn: false
  377. },
  378. {
  379. signIn: false,
  380. canSupplement: false,
  381. dayDescribe: '第三天',
  382. bookCoin: 30,
  383. isSignIn: false
  384. },
  385. {
  386. signIn: false,
  387. canSupplement: false,
  388. dayDescribe: '第四天',
  389. bookCoin: 40,
  390. isSignIn: false
  391. },
  392. {
  393. signIn: false,
  394. canSupplement: false,
  395. dayDescribe: '第五天',
  396. bookCoin: 50,
  397. isSignIn: false
  398. },
  399. {
  400. signIn: false,
  401. canSupplement: false,
  402. dayDescribe: '第六天',
  403. bookCoin: 60,
  404. isSignIn: false
  405. },
  406. {
  407. signIn: false,
  408. canSupplement: false,
  409. dayDescribe: '第七天',
  410. bookCoin: 70,
  411. isSignIn: false
  412. },
  413. ]
  414. }
  415. this.startGold(false)
  416. this.isSignIn = false
  417. uni.showToast({
  418. title: '签到成功~~',
  419. icon: 'none'
  420. })
  421. },
  422. powerOnShowAd() {
  423. // 开机25秒调取弹窗广告 以后没5分钟调取
  424. powerOnTimer = setInterval(() => {
  425. this.powerOnCount += 1
  426. if(this.powerOnCount === 25 || this.powerOnCount % 325 === 0) {
  427. this.showInterstitialAd()
  428. }
  429. }, 1000)
  430. },
  431. // 创建插屏广告 激励视频广告
  432. createInterstitialAd() {
  433. // 创建插屏广告
  434. let interstitialAd = this.interstitialAd = uni.createInterstitialAd({adUnitId: insertScreenAd});
  435. interstitialAd.onLoad(() => {
  436. // 插屏 广告加载成功
  437. console.log("插屏 广告加载成功");
  438. this.loading = false;
  439. });
  440. interstitialAd.onClose(() => {
  441. // 用户点击了关闭或返回键(仅Android有返回键)
  442. console.log("插屏 广告关闭");
  443. });
  444. interstitialAd.onError((err) => {
  445. // 插屏 广告加载失败
  446. console.log("插屏 广告加载失败", err);
  447. this.loading = false;
  448. });
  449. // 广告实例创建成功后默认会执行一次 load,加载广告数据
  450. // 如果界面有 "显示广告" 按钮,需要先禁用掉,防止用户点击,等待广告数据加载成功后在放开
  451. this.loading = true;
  452. // 激励视频广告
  453. this._isLoaded = false
  454. let rewardedVideoAd = this._rewardedVideoAd = uni.createRewardedVideoAd({ adUnitId: urgeVideoAd }) // 仅用于HBuilder基座调试 adpid: '1507000689'
  455. rewardedVideoAd.onLoad(() => {
  456. this._isLoaded = true
  457. console.log('onLoad event')
  458. // 加载激励视频成功
  459. // 当激励视频被关闭时,默认预载下一条数据,加载完成时仍然触发 `onLoad` 事件
  460. })
  461. rewardedVideoAd.onError((err) => {
  462. // 加载激励视频失败
  463. // console.log('onError event', err)
  464. })
  465. rewardedVideoAd.onClose((res) => {
  466. // 用户点击了【关闭广告】按钮
  467. if (res && res.isEnded) {
  468. // 正常播放结束
  469. if(this.isVideoType === 1){ // 看视频签到
  470. this.signInHandle(true)
  471. } else if (this.isVideoType === 2) { // 看视频补签
  472. this.repairSign(this.repairSignData)
  473. }
  474. } else {
  475. // 播放中途退出
  476. }
  477. })
  478. },
  479. // 显示插屏广告广告
  480. showInterstitialAd() {
  481. // 调用 interstitialAd.show(),如果数据正在加载中不会显示广告,加载成功后才显示
  482. // 在数据没有加载成功时,需要防止用户频繁点击显示广告
  483. if(adTimer) {
  484. clearTimeout(adTimer)
  485. }
  486. let newT = new Date().getTime()
  487. if (((newT / 1000) - (this.powerOnTimer / 1000)) < 15) { // 判断是否开机15秒
  488. adTimer = setTimeout(() => {
  489. if (this.loading == true) {
  490. return
  491. }
  492. this.loading = true;
  493. this.interstitialAd.show().then((res) => {
  494. console.log('插屏广告成功---》', res)
  495. this.loading = false;
  496. }).catch(err => {
  497. console.log('插屏广告错误---》', err)
  498. });
  499. clearTimeout(adTimer)
  500. }, newT - this.powerOnTimer + 1000)
  501. return
  502. }
  503. if (this.loading == true) {
  504. return
  505. }
  506. this.loading = true;
  507. this.interstitialAd.show().then((res) => {
  508. console.log('插屏广告成功---》', res)
  509. this.loading = false;
  510. }).catch(err => {
  511. console.log('插屏广告错误---》', err)
  512. });
  513. },
  514. // 显示激励视频广告
  515. showVideoAd(type, data) {
  516. if (this._isLoaded) {
  517. this.isVideoType = type
  518. this.repairSignData = data
  519. this._rewardedVideoAd.show().catch(() => {
  520. this._rewardedVideoAd && this._rewardedVideoAd.load().then(() => this._rewardedVideoAd && this._rewardedVideoAd.show()).catch(err => {
  521. uni.showToast({
  522. title: '当前无视频广告',
  523. icon: 'none'
  524. })
  525. })
  526. })
  527. }
  528. },
  529. // 按钮呼吸
  530. btBreathAni() {
  531. btTimer = setInterval(() => {
  532. if(this.btScale === 1) {
  533. this.btScale = 0.92
  534. this.btAnimation.scale(0.92).step({ duration: 600 })
  535. this.btAnimationData = this.btAnimation.export()
  536. } else {
  537. this.btScale = 1
  538. this.btAnimation.scale(1).step({ duration: 600 })
  539. this.btAnimationData = this.btAnimation.export()
  540. }
  541. }, 600)
  542. },
  543. // 提示动画
  544. startTsAni(watchVideos) {
  545. if (watchVideos) {
  546. this.tsTitle = '+' + (this.signInDay.bookCoin * 2) + '书币'
  547. } else {
  548. this.tsTitle = '+' + this.signInDay.bookCoin + '书币'
  549. }
  550. if( this.durationMath2 >= 50 ) {
  551. this.durationMath2 = 20
  552. } else {
  553. this.durationMath2 = this.durationMath2 + 1
  554. }
  555. let animation = uni.createAnimation({ timingFunction: 'ease' })
  556. animation.opacity(1).step({ duration: this.durationMath2 })
  557. animation.top('150rpx').step({ duration: 1000, delay: 100 })
  558. animation.opacity(0).top('350rpx').step({ duration: 0 })
  559. this.animationDataTs = animation.export()
  560. },
  561. // 金币组动画
  562. startGold(watchVideos) {
  563. this.startTsAni(watchVideos)
  564. if( this.durationMath1 >= 50 ) {
  565. this.durationMath1 = 20
  566. } else {
  567. this.durationMath1 = this.durationMath1 + 1
  568. }
  569. this.animationDatas = this.goldData.map(item => {
  570. let animation = uni.createAnimation({ timingFunction: 'ease' })
  571. animation.opacity(1).step({ duration: this.durationMath1 })
  572. animation.top('76rpx').left('60rpx').step({ duration: Math.floor(Math.random() * 101) + 650, delay: 100 }) //
  573. animation.opacity(0).top(item.top).left(item.left).step({ duration: 0 })
  574. return animation.export()
  575. })
  576. },
  577. // 更多书币
  578. moreGold() {
  579. let path = 'pages/index/index'
  580. if(Object.keys(this.mpData).length > 0) {
  581. path = path + this.getSerialize(this.mpData)
  582. }
  583. uni.navigateToMiniProgram({
  584. appId: 'wx021e792baf529aff',
  585. path,
  586. success(res) {
  587. // 打开成功
  588. }
  589. })
  590. },
  591. // 对象序列化成 a=1&b=2
  592. getSerialize(value) {
  593. if(Object.prototype.toString.call(value) === "[object Object]") {
  594. let path = ""
  595. for (const key in value) {
  596. if (Object.prototype.hasOwnProperty.call(value, key)) {
  597. const element = value[key];
  598. if (path === "") {
  599. path = `?${key}=${element}`
  600. }else {
  601. path = path + `&${key}=${element}`
  602. }
  603. }
  604. }
  605. return path
  606. } else {
  607. return ""
  608. }
  609. },
  610. // 判断模板消息是否点击了总是允许
  611. getSetting() {
  612. return new Promise((resolve, reject) => {
  613. uni.getSetting({
  614. withSubscriptions: true,
  615. success: resSetting => {
  616. console.log('订阅消息---->', resSetting)
  617. let { subscriptionsSetting } = resSetting
  618. if (subscriptionsSetting) {
  619. let { mainSwitch, itemSettings, ...data } = subscriptionsSetting
  620. if (data && Object.keys(data).length > 0) {
  621. if (mainSwitch) {
  622. for (const key in data) {
  623. if (Object.prototype.hasOwnProperty.call(data, key)) {
  624. const element = data[key];
  625. if (element === 'accept') {
  626. resolve(200) // 总是允许开启
  627. } else {
  628. resolve(400) // 总是允许取消
  629. }
  630. }
  631. }
  632. } else {
  633. resolve(401) // 后台关闭开关
  634. }
  635. } else {
  636. resolve(402) // 没有点总是允许
  637. }
  638. } else {
  639. resolve(402) // 没有点总是允许
  640. }
  641. }
  642. })
  643. })
  644. },
  645. handleMessage(remindSwitch, allowSwitch = 0) { // 设置签到消息接口
  646. let { mpName, ...mp } = this.mpData
  647. setMessage({appId: config.appid, openId: this.openId, allowSwitch, remindSwitch, ...mp}).then(res => {
  648. this.getList()
  649. this.showInterstitialAd()
  650. })
  651. },
  652. // 获取模板签到ID
  653. getTemplate() {
  654. getTemplateIDs({appId: config.appid, type: 1}).then(res => {
  655. this.signIdTemID = [res.data]
  656. })
  657. },
  658. // 获取首页数据
  659. async getList(signTime) {
  660. let data = {appId: config.appid, userSource: 1, openId: this.openId, ...this.mpData, ...(signTime ? {signTime} : {})}
  661. let res = await getHome(data)
  662. if (res.data) {
  663. this.mpData = {
  664. mpAppId: res.data.mpAppId,
  665. mpName: res.data.mpName,
  666. mpOpenId: res.data.mpOpenId
  667. }
  668. this.signData = res.data
  669. this.signRemind = res.data.loginRemindSwitch === 0 ? false : true
  670. this.getTemplate()
  671. }
  672. },
  673. /** 补签*/
  674. repairSign(data) {
  675. let { dayTime, dayNum } = data
  676. signInAjax({watchVideo: false, supplement: true, appId: config.appid, openId: this.openId, dayNum, dayTime, ...this.mpData}).then(res => {
  677. this.getList(res.data)
  678. this.startGold(false)
  679. uni.showToast({
  680. title: '补签成功',
  681. icon: 'success'
  682. })
  683. setTimeout(() => {
  684. this.showInterstitialAd()
  685. }, 20000)
  686. })
  687. },
  688. getTimer() { // 获取年月日时分秒
  689. let timestamp = Date.parse(new Date())
  690. let date = new Date(timestamp)
  691. let Y = date.getFullYear()
  692. let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  693. let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  694. return `${Y}${M}${D}`
  695. },
  696. /** 签到提醒按钮 */
  697. signRemindHandle(state) {
  698. if (!this.signData.mpName) {
  699. uni.navigateTo({
  700. url: '../officialAccount/officialAccount'
  701. })
  702. return
  703. }
  704. if(state) { // 点击开启
  705. if (this.signIdTemID.length > 0) {
  706. uni.requestSubscribeMessage({
  707. tmplIds: this.signIdTemID,
  708. success: async res => {
  709. let { errMsg, ...massageData } = res
  710. console.log('------>', res)
  711. let msg = await this.getSetting()
  712. console.log('----2222---->', msg)
  713. if(msg === 400) {
  714. uni.showToast({
  715. title: '签到消息微信关闭,如要开启通知,请到通知管理开启',
  716. icon: 'none',
  717. duration: 2000
  718. })
  719. return
  720. } else if(msg === 401) {
  721. uni.showToast({
  722. title: '通知管理按钮关闭,如要开启通知,请到通知管理开启',
  723. icon: 'none',
  724. duration: 2000
  725. })
  726. } else {
  727. for (const key in massageData) {
  728. if (Object.prototype.hasOwnProperty.call(massageData, key)) {
  729. const element = massageData[key];
  730. if (element === 'accept') { // 允许
  731. console.log('msg--->', msg)
  732. this.handleMessage(1, msg === 200 ? 1 : 0)
  733. } else if (element === 'reject') { // 取消
  734. }
  735. }
  736. }
  737. }
  738. }
  739. })
  740. } else {
  741. uni.showToast({
  742. title: '模板ID为空',
  743. icon: 'none'
  744. })
  745. }
  746. } else { // 点击关闭
  747. this.handleMessage(0, 0)
  748. }
  749. },
  750. /** 活动规则展开和收起 */
  751. activityRulesHandle() {
  752. this.activityRules = !this.activityRules
  753. },
  754. /** 签到 */
  755. signIn() {
  756. if(!this.signData.mpName) {
  757. uni.showToast({
  758. title: '请先关注公众号',
  759. icon: 'none'
  760. })
  761. return
  762. }
  763. this.signInDay = this.signData.signInDayVoList.find(item => item.canSign)
  764. this.popupShow = true
  765. },
  766. /** 关闭弹窗 */
  767. closeHandle() {
  768. this.popupShow = false
  769. this.signInHandle(false)
  770. },
  771. /** 签到 */
  772. signInHandle(watchVideo) {
  773. let signInDay = this.signData.signInDayVoList.find(item => item.canSign)
  774. console.log(signInDay)
  775. if (signInDay) {
  776. let { dayTime, dayNum, signIn } = signInDay
  777. if (!signIn) {
  778. signInAjax({watchVideo, supplement: false, appId: config.appid, openId: this.openId, dayNum, dayTime, ...this.mpData}).then(res => {
  779. this.getList()
  780. this.startGold(watchVideo)
  781. this.popupShow = false
  782. if(!watchVideo) {
  783. this.showInterstitialAd()
  784. } else {
  785. setTimeout(() => {
  786. this.showInterstitialAd()
  787. }, 20000)
  788. }
  789. })
  790. } else {
  791. uni.showToast({
  792. title: '今日已签!',
  793. icon: 'error'
  794. })
  795. }
  796. } else {
  797. uni.showToast({
  798. title: '数据获取失败!',
  799. icon: 'error'
  800. })
  801. }
  802. },
  803. /** 看视频签到 */
  804. lookVideo() {
  805. this.showVideoAd(1)
  806. },
  807. }
  808. }
  809. </script>
  810. <style lang="scss">
  811. page{
  812. background-color: #FC6E53;
  813. }
  814. .sign {
  815. position: relative;
  816. &>.back {
  817. width: 100%;
  818. margin-top: 104rpx;
  819. }
  820. .signCenter {
  821. position: absolute;
  822. top: 0;
  823. margin: 40rpx 0 60rpx;
  824. font-family: PingFangSC-Medium, PingFang SC;
  825. }
  826. .signTop {
  827. padding: 0 28rpx;
  828. height: 104rpx;
  829. display: flex;
  830. justify-content: space-between;
  831. align-items: center;
  832. .left{
  833. display: flex;
  834. justify-content: flex-start;
  835. align-items: center;
  836. .avatarView{
  837. width: 104rpx;
  838. height: 104rpx;
  839. overflow: hidden;
  840. border-radius: 10px;
  841. .avatar {
  842. width: 104rpx;
  843. height: 104rpx;
  844. background: #D8D8D8;
  845. }
  846. }
  847. .userInfo{
  848. margin-left: 28rpx;
  849. &>view{
  850. font-size: 28rpx;
  851. font-weight: 400;
  852. color: #FFFFFF;
  853. &.ID{
  854. margin-top: 4rpx;
  855. }
  856. }
  857. }
  858. }
  859. .right{
  860. width: 212rpx;
  861. height: 68rpx;
  862. background-color: #FFFFFF;
  863. border-radius: 40rpx;
  864. display: flex;
  865. justify-content: center;
  866. align-items: center;
  867. &>image {
  868. width: 28rpx;
  869. height: 32rpx;
  870. }
  871. &>text {
  872. font-size: 28rpx;
  873. font-weight: 400;
  874. color: #FD9C01;
  875. margin-left: 18rpx;
  876. }
  877. }
  878. }
  879. // 滚动通知
  880. .notice {
  881. width: 656rpx;
  882. height: 68rpx;
  883. background: #C7322C;
  884. box-shadow: 0px 4rpx 8rpx 0rpx rgba(49, 49, 49, 0.08);
  885. border-radius: 38rpx;
  886. opacity: 0.53;
  887. margin: 58rpx auto 0;
  888. padding: 0 30rpx;
  889. box-sizing: border-box;
  890. display: flex;
  891. justify-content: flex-start;
  892. align-items: center;
  893. margin-bottom: 30rpx;
  894. .horn {
  895. width: 28rpx;
  896. height: 28rpx;
  897. }
  898. .txts {
  899. // flex: 1;
  900. height: 68rpx;
  901. width: 600rpx;
  902. }
  903. }
  904. .signBottom{
  905. margin: 0 14rpx;
  906. margin-top: 160rpx;
  907. width: 722rpx;
  908. }
  909. .exhibitionContent{
  910. padding: 26rpx 26rpx 40rpx;
  911. box-sizing: border-box;
  912. background-color: #FFFFFF;
  913. border-radius: 22rpx;
  914. box-shadow: 0px 4rpx 8rpx 0rpx rgba(230, 230, 230, 0.5);
  915. &>.ts {
  916. font-size: 28rpx;
  917. font-weight: 400;
  918. color: #666666;
  919. }
  920. &>.signinExhibition {
  921. margin-top: 18rpx;
  922. display: flex;
  923. justify-content: space-between;
  924. flex-wrap: wrap;
  925. &>view{
  926. width: 152rpx;
  927. height: 168rpx;
  928. background: #FFF7EF;
  929. box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(254, 173, 165, 0.26);
  930. border-radius: 16rpx;
  931. border: 2rpx solid #FFB35C;
  932. margin-bottom: 20rpx;
  933. padding: 12rpx;
  934. box-sizing: border-box;
  935. display: flex;
  936. flex-direction: column;
  937. justify-content: flex-start;
  938. align-items: center;
  939. position: relative;
  940. .day{
  941. font-size: 24rpx;
  942. font-weight: 500;
  943. color: #FF9011;
  944. }
  945. &>.goldCoins {
  946. height: 68rpx;
  947. margin: 5rpx 0;
  948. }
  949. .reward{
  950. font-size: 24rpx;
  951. font-weight: 500;
  952. color: #FE604F;
  953. }
  954. &:last-child{
  955. width: 322rpx;
  956. display: flex;
  957. justify-content: space-between;
  958. flex-direction: row;
  959. &>.left {
  960. display: flex;
  961. flex-direction: column;
  962. align-items: flex-start;
  963. margin-left: 35rpx;
  964. height: 100%;
  965. flex: 1;
  966. .reward{
  967. margin-top: 28rpx;
  968. font-size: 32rpx;
  969. font-weight: 500;
  970. }
  971. }
  972. &>.right {
  973. width: 115rpx;
  974. height: 100%;
  975. display: flex;
  976. justify-content: center;
  977. align-items: center;
  978. &>image{
  979. width: 108rpx;
  980. height: 128rpx;
  981. }
  982. }
  983. }
  984. // 已签到
  985. &.select {
  986. overflow: hidden;
  987. border: 2rpx solid #D2D2D2;
  988. background: #F2F2F2;
  989. .day, .reward{
  990. color: #999999;
  991. }
  992. }
  993. .signSub {
  994. position: absolute;
  995. bottom: 0;
  996. right: 0;
  997. width: 72rpx;
  998. }
  999. // 看视频补签
  1000. &.repairSign {
  1001. position: relative;
  1002. .repair {
  1003. position: absolute;
  1004. width: calc(100% + 2rpx);
  1005. left: -1rpx;
  1006. top: -1rpx;
  1007. text-align: center;
  1008. line-height: 46rpx;
  1009. height: 46rpx;
  1010. background: #FE604F;
  1011. font-size: 24rpx;
  1012. font-weight: 500;
  1013. color: #FFFFFF;
  1014. border-radius: 16rpx 16rpx 0 0;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. &>.gignBt {
  1020. width: 456rpx;
  1021. height: 80rpx;
  1022. line-height: 80rpx;
  1023. text-align: center;
  1024. // background-color: #D8D8D8;
  1025. background: linear-gradient(180deg, #FDC606 0%, #FF8D12 100%);
  1026. box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(241, 139, 11, 0.61);
  1027. margin: 40rpx auto 0;
  1028. font-size: 32rpx;
  1029. font-weight: 500;
  1030. color: #FFFFFF;
  1031. border-radius: 40rpx;
  1032. }
  1033. &>.already{
  1034. margin: 40rpx auto 0;
  1035. width: 456rpx;
  1036. height: 80rpx;
  1037. background: #D8D8D8;
  1038. border-radius: 40rpx;
  1039. font-size: 32rpx;
  1040. font-weight: 500;
  1041. color: #FFFFFF;
  1042. line-height: 80rpx;
  1043. text-align: center;
  1044. }
  1045. }
  1046. .signRemind {
  1047. margin-top: 40rpx;
  1048. height: 92rpx;
  1049. background: rgba(255, 255, 255, 0.15);
  1050. border-radius: 20rpx;
  1051. line-height: 92rpx;
  1052. color: #FFFFFF;
  1053. font-size: 32rpx;
  1054. padding: 0 28rpx;
  1055. box-sizing: border-box;
  1056. display: flex;
  1057. font-weight: 400;
  1058. justify-content: space-between;
  1059. .remindSwitch{
  1060. display: flex;
  1061. justify-content: flex-start;
  1062. align-items: center;
  1063. &>view {
  1064. display: flex;
  1065. justify-content: flex-start;
  1066. align-items: center;
  1067. &>text {
  1068. font-weight: 400;
  1069. font-size: 32rpx;
  1070. margin-left: 12rpx;
  1071. }
  1072. &.open > .select {
  1073. width: 24rpx;
  1074. height: 24rpx;
  1075. background: #FFFFFF;
  1076. border-radius: 24rpx;
  1077. }
  1078. &.close > .select {
  1079. width: 24rpx;
  1080. height: 24rpx;
  1081. border: 2rpx solid #FFFFFF;
  1082. box-sizing: border-box;
  1083. border-radius: 24rpx;
  1084. }
  1085. &:first-child {
  1086. margin-right: 38rpx;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. .activityRules {
  1092. margin-top: 40rpx;
  1093. background: rgba(255, 255, 255, 0.15);
  1094. border-radius: 20rpx;
  1095. color: #FFFFFF;
  1096. font-size: 32rpx;
  1097. font-weight: 400;
  1098. &>.top {
  1099. height: 92rpx;
  1100. padding: 0 28rpx;
  1101. box-sizing: border-box;
  1102. display: flex;
  1103. justify-content: space-between;
  1104. align-items: center;
  1105. &>image {
  1106. width: 40rpx;
  1107. }
  1108. }
  1109. &>.bottom {
  1110. padding: 0 28rpx 30rpx;
  1111. box-sizing: border-box;
  1112. &> view {
  1113. margin-bottom: 12rpx;
  1114. font-size: 28rpx;
  1115. font-weight: 400;
  1116. color: #FFFFFF;
  1117. line-height: 46rpx;
  1118. }
  1119. }
  1120. }
  1121. .popup {
  1122. position: fixed;
  1123. width: 100%;
  1124. height: 100vh;
  1125. background: rgba(0, 0, 0, 0.6);
  1126. top: 0;
  1127. left: 0;
  1128. right: 0;
  1129. bottom: 0;
  1130. .popupContent {
  1131. width: 632rpx;
  1132. position: absolute;
  1133. top: 50%;
  1134. left: 50%;
  1135. transform: translate(-50%, -50%);
  1136. text-align: center;
  1137. &>.content {
  1138. position: relative;
  1139. &>image {
  1140. width: 100%;
  1141. height: 652rpx;
  1142. }
  1143. &>.textCon {
  1144. position: absolute;
  1145. width: 100%;
  1146. top: 0;
  1147. left: 0;
  1148. right: 0;
  1149. bottom: 0;
  1150. padding-top: 192rpx;
  1151. .ts {
  1152. font-size: 60rpx;
  1153. font-weight: 500;
  1154. color: #F5631D;
  1155. }
  1156. .reward {
  1157. height: 60rpx;
  1158. background: #FFD9A2;
  1159. border-radius: 31rpx;
  1160. font-size: 32rpx;
  1161. font-weight: 400;
  1162. display: inline-block;
  1163. padding: 0 32rpx;
  1164. color: #F5631E;
  1165. line-height: 60rpx;
  1166. margin-top: 20rpx;
  1167. }
  1168. .doubleBt {
  1169. width: 456rpx;
  1170. height: 104rpx;
  1171. margin-top: 90rpx;
  1172. transition: all linear .5s;
  1173. }
  1174. .bt {
  1175. margin-top: 14rpx;
  1176. font-size: 32rpx;
  1177. font-weight: 400;
  1178. color: #FCE8CD;
  1179. display: inline-block;
  1180. text-align: center;
  1181. }
  1182. .btTrue {
  1183. width: 300rpx;
  1184. height: 68rpx;
  1185. background-color: #ffd555;
  1186. line-height: 68rpx;
  1187. color: #831902;
  1188. font-size: 36rpx;
  1189. font-weight: 700;
  1190. border-radius: 34rpx;
  1191. }
  1192. }
  1193. }
  1194. &>.close {
  1195. width: 54rpx;
  1196. height: 54rpx;
  1197. margin-top: 76rpx;
  1198. }
  1199. }
  1200. }
  1201. .fragmentGold {
  1202. position: absolute;
  1203. z-index: 100;
  1204. opacity: 0;
  1205. &>image {
  1206. width: 68rpx;
  1207. height: 68rpx;
  1208. }
  1209. }
  1210. .qLuckDraw {
  1211. position: absolute;
  1212. top: 240rpx;
  1213. right: 8rpx;
  1214. z-index: 200;
  1215. animation: lanimation 1.3s linear infinite;
  1216. &>image {
  1217. width: 150rpx;
  1218. height: 150rpx;
  1219. }
  1220. }
  1221. .receiveTs {
  1222. position: absolute;
  1223. border: 2rpx solid rgb(242, 164, 39);
  1224. top: 350rpx;
  1225. z-index: 100;
  1226. color: #FFFFFF;
  1227. left: 50%;
  1228. transform: translateX(-50%);
  1229. padding: 10rpx 20rpx;
  1230. background-color: rgba(195, 106, 106, 0.6);
  1231. border-radius: 5rpx;
  1232. opacity: 0;
  1233. }
  1234. .singleLattice {
  1235. position: fixed;
  1236. top: 200rpx;
  1237. right: 4rpx;
  1238. }
  1239. }
  1240. @-webkit-keyframes lanimation {
  1241. 0% {
  1242. transform: rotate(0deg);
  1243. }
  1244. 8% {
  1245. transform: rotate(12deg);
  1246. }
  1247. 16% {
  1248. transform: rotate(0deg);
  1249. }
  1250. 24% {
  1251. transform: rotate(-12deg);
  1252. }
  1253. 32% {
  1254. transform: rotate(0deg);
  1255. }
  1256. 100% {
  1257. transform: rotate(0deg);
  1258. }
  1259. }
  1260. </style>