video.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. // pages/video/video.js
  2. import {
  3. getVideoList,
  4. getTemplateConfig,
  5. getUuid, userLogin
  6. } from '../../api/api'
  7. import {
  8. rnd,
  9. deepCopy,
  10. goToBookDetail,
  11. goToVideoDetail, SendEvent
  12. } from '../../utils/util'
  13. import {
  14. apple
  15. } from '../../config/config'
  16. const app = getApp()
  17. let interstitialAd = null
  18. const HAPPY_PHOTO_LIST = [
  19. {
  20. adType: 'video',
  21. cover_image: '',
  22. title: 'material202304',
  23. tmpName: 'material202304',
  24. views: 223,
  25. lock: false,
  26. },
  27. {
  28. adType: 'video',
  29. cover_image: '',
  30. title: 'moon',
  31. tmpName: 'moon',
  32. views: 223,
  33. lock: false,
  34. },
  35. {
  36. adType: 'video',
  37. cover_image: '',
  38. title: 'qiangwei',
  39. tmpName: 'qiangwei',
  40. views: 223,
  41. lock: false,
  42. },
  43. {
  44. adType: 'video',
  45. cover_image: '',
  46. title: 'qingren17',
  47. tmpName: 'qingren17',
  48. views: 223,
  49. lock: false,
  50. },
  51. {
  52. adType: 'video',
  53. cover_image: '',
  54. title: 'qingrenjie2020',
  55. tmpName: 'qingrenjie2020',
  56. views: 223,
  57. lock: false,
  58. },
  59. {
  60. adType: 'video',
  61. cover_image: '',
  62. title: 'rose',
  63. tmpName: 'rose',
  64. views: 223,
  65. lock: false,
  66. },
  67. {
  68. adType: 'video',
  69. cover_image: '',
  70. title: 'sqjh2018',
  71. tmpName: 'sqjh2018',
  72. views: 223,
  73. lock: false,
  74. },
  75. {
  76. adType: 'video',
  77. cover_image: '',
  78. title: 'yujiandongtian2022',
  79. tmpName: 'yujiandongtian2022',
  80. views: 223,
  81. lock: false,
  82. },
  83. {
  84. adType: 'video',
  85. cover_image: '',
  86. title: 'yujianqiutian2023',
  87. tmpName: 'yujianqiutian2023',
  88. views: 223,
  89. lock: false,
  90. },
  91. ]
  92. Page({
  93. data: {
  94. videoList: [],
  95. loading: false,
  96. hasMore: true,
  97. page: 1,
  98. size: 10,
  99. // 状态栏高度
  100. statusBarHeight: 20,
  101. navHeight: 64, // 导航栏高度 = 状态栏 + 44
  102. navStyle: '',
  103. listStyle: '',
  104. // 添加防抖时间戳
  105. lastLoadTime: 0,
  106. ads: null,
  107. globalConfig: null,
  108. // 视频分类列表
  109. categoryList: [],
  110. // 当前选中的分类ID
  111. currentCategoryId: null,
  112. share_count: 1,
  113. hasLoadAdConfig: false,
  114. templateAdId: '',
  115. adErrorField: {
  116. videoError: false,
  117. bannerError: false,
  118. templateError: false
  119. },
  120. },
  121. onLoad(options) {
  122. console.log('打开视频页面--------------------------')
  123. wx.setStorageSync('jump', parseInt(options.jump)) // 是否跳转阅读器
  124. if (!app.globalData.uuid) {
  125. this.getUUID().then(uuid => {
  126. // getApp().globalData.uuid = uuid
  127. console.log('登录成功')
  128. })
  129. }
  130. this.handleEntrace(options);
  131. this.setData({
  132. templateAdId: apple.ads.templateAdId,
  133. hasLoadAdConfig: true
  134. })
  135. this.interstitalLoad()
  136. getTemplateConfig({
  137. box_type: 67,
  138. uuid: app.globalData.uuid
  139. }).then(res => {
  140. this.setData({
  141. globalConfig: res.globalConfig
  142. });
  143. app.globalData.ads_config = res.globalConfig;
  144. // 获取视频分类
  145. this.getVideoCategories()
  146. })
  147. // 获取状态栏高度
  148. this.getSystemInfo()
  149. // this.handleEntrace(options);
  150. },
  151. onShow() {
  152. console.log('页面显示--------------------------')
  153. this.rewardVideoLoad()
  154. // 每次显示页面时刷新列表
  155. if (this.data.videoList.length === 0) {
  156. this.setData({
  157. page: 1
  158. })
  159. // this.loadVideoList()
  160. }
  161. // 获取当前页面的参数
  162. const pages = getCurrentPages();
  163. const currentPage = pages[pages.length - 1];
  164. const options = currentPage.options;
  165. const jump = parseInt(options.jump); // 是否跳转阅读器 1-不跳转
  166. const scene = wx.getStorageSync('scene');
  167. console.log('scene场景值:', scene);
  168. console.log('jump阅读器:', jump);
  169. console.log('shared_video_id:', options.shared_video_id);
  170. console.log('share_count:', options.share_count);
  171. console.log('isEnterVideoDetail:', app.globalData.isEnterVideoDetail);
  172. if (options.shared_video_id) {
  173. // 处理分享进入的情况
  174. if (!app.globalData.isEnterVideoDetail) {
  175. // 延迟跳转,确保列表页已经加载完成
  176. setTimeout(() => {
  177. wx.navigateTo({
  178. url: `/pages/video/detail?id=${options.shared_video_id}&title=${options.title || ''}&tag_id=${options.tag_id || ''}`,
  179. fail: (err) => {
  180. console.error('跳转到视频详情页失败:', err);
  181. wx.showToast({
  182. title: '打开视频失败',
  183. icon: 'none'
  184. });
  185. }
  186. });
  187. }, 500);
  188. } else {
  189. // 第二次进入把isEnterVideoDetail恢复默认值
  190. app.globalData.isEnterVideoDetail = true;
  191. }
  192. }
  193. // if (options.shared_video_id) {
  194. // if (+options.share_count === 1 && this.data.share_count === 1) {
  195. // this.setData({
  196. // share_count: 2
  197. // });
  198. // console.log('share_count1:', this.data.share_count)
  199. // if (jump === 1) {
  200. // console.log('jump为1直接跳转到视频详情页')
  201. // // 延迟跳转
  202. // setTimeout(() => {
  203. // this.goToVideoDetail(options.shared_video_id, options.tag_id)
  204. // }, 500);
  205. // } else {
  206. // if (scene === 1007 || scene === 1008) {
  207. // console.log('scene为1007或1008且jump不为1,跳转到书详情页')
  208. // this.goToBookDetail();
  209. // } else {
  210. // console.log('scene不为1007,1008且jump不为1,跳转到视频详情页')
  211. // // 延迟跳转
  212. // setTimeout(() => {
  213. // this.goToVideoDetail(options.shared_video_id, options.tag_id)
  214. // }, 500);
  215. // }
  216. // }
  217. // // if ((scene === 1007 || scene === 1008) && jump != 1) {
  218. // // this.goToBookDetail();
  219. // // } else {
  220. // // this.goToVideoDetail(options.shared_video_id, options.tag_id);
  221. // // }
  222. // // this.goToBookDetail();
  223. // } else if (+options.share_count === 1 && this.data.share_count === 2) {
  224. // this.setData({
  225. // share_count: 3
  226. // });
  227. // console.log('share_count2:', this.data.share_count)
  228. // // 延迟跳转,确保列表页已经加载完成
  229. // setTimeout(() => {
  230. // wx.navigateTo({
  231. // url: `/pages/video/detail?id=${options.shared_video_id}&title=${options.title || ''}&tag_id=${options.tag_id || ''}`,
  232. // fail: (err) => {
  233. // console.error('跳转到视频详情页失败:', err);
  234. // wx.showToast({
  235. // title: '打开视频失败',
  236. // icon: 'none'
  237. // });
  238. // }
  239. // });
  240. // }, 500);
  241. // }
  242. // }
  243. },
  244. handleEntrace(options) {
  245. console.log('点击入口按钮')
  246. if (!options || Object.keys(options).length === 0) {
  247. return
  248. }
  249. console.log('入口:', options)
  250. try {
  251. let {type, jump, shared_video_id, tag_id} = options
  252. const scene = wx.getStorageSync('scene');
  253. console.log('入口:', type, jump, scene, shared_video_id)
  254. if ((type === 'share' || type === 'tuiguang') && shared_video_id) {
  255. if (jump === "1") {
  256. console.log('jump为1直接跳转到视频详情页')
  257. // 延迟跳转,确保列表页已经加载完成
  258. setTimeout(() => {
  259. this.goToVideoDetail(shared_video_id, tag_id)
  260. }, 500);
  261. } else {
  262. if (scene === 1007 || scene === 1008) {
  263. console.log('scene为1007或1008且jump不为1,跳转到书详情页')
  264. // 延迟跳转,确保列表页已经加载完成
  265. setTimeout(() => {
  266. this.goToBookDetail()
  267. }, 500);
  268. } else {
  269. console.log('scene不为1007,1008且jump不为1,跳转到视频详情页')
  270. // 延迟跳转,确保列表页已经加载完成
  271. setTimeout(() => {
  272. this.goToVideoDetail(shared_video_id, tag_id)
  273. }, 500);
  274. }
  275. }
  276. }
  277. } catch (e) {
  278. console.log('处理不同场景进入小程序出错', error)
  279. }
  280. },
  281. onTabItemTap(item) {
  282. console.log(item.index)
  283. setTimeout(() => {
  284. this.interstitalPlayFn()
  285. }, 1000)
  286. },
  287. // 插屏广告加载
  288. interstitalLoad() {
  289. let adId = apple.ads.insertAdId
  290. interstitialAd = wx.createInterstitialAd({
  291. adUnitId: adId
  292. })
  293. interstitialAd.onLoad(() => {
  294. console.log('视频页插屏广告onLoad')
  295. })
  296. interstitialAd.onError((err) => {
  297. console.log('视频页插屏广告onError', err)
  298. })
  299. interstitialAd.onClose(() => {
  300. console.log('视频页插屏广告onClose')
  301. })
  302. },
  303. // 插屏广告展示
  304. interstitalPlayFn() {
  305. if (interstitialAd) {
  306. interstitialAd.show().catch((err) => {
  307. console.error(err)
  308. })
  309. }
  310. },
  311. /**
  312. * 获取uuid
  313. */
  314. getUUID() {
  315. return new Promise((resolve, reject) => {
  316. wx.login({
  317. success: res => {
  318. console.log('wxlogin:', res);
  319. let body = {
  320. code: res.code,
  321. source_type: 1,
  322. source_id: ''
  323. }
  324. getUuid(body).then(async uuidres => {
  325. console.log('登录成功:', uuidres);
  326. app.globalData.uuid = uuidres.uuid;
  327. app.globalData.openId = uuidres.open_id;
  328. // 直接从视频链接进入,同时登录IAA小说用户
  329. // userLogin({
  330. // "appid": apple.appid,
  331. // "channel": 1,
  332. // "srcType": "0",
  333. // "srcAppId": "",
  334. // "srcId": "",
  335. // "cusId": "",
  336. // "inviter": "",
  337. // "promotionId": "",
  338. // "inviterPromotionId": "",
  339. // "system": "pc",
  340. // "type": "inner",
  341. // "inner": 1,
  342. // code: res.code,
  343. // }).then(logres => {
  344. // console.log('userLogin', logres);
  345. // wx.setStorageSync('accessToken', logres.accessToken);
  346. // app.globalData.isLogin = true;
  347. // app.globalData.userCode = logres.userCode;
  348. // app.globalData.openId = logres.openId;
  349. // app.globalData.unionId = logres.unionId;
  350. // console.log('登录成功', app.globalData)
  351. // resolve(logres);
  352. // }).catch(err => {
  353. // app.globalData.isLogin = false;
  354. // reject(err);
  355. // })
  356. console.log('登录后的openid:', uuidres.open_id)
  357. console.log('登录成功:', app.globalData)
  358. SendEvent('login_shanhu', {"uuid": uuidres.uuid});
  359. resolve(res.uuid)
  360. }).catch((err) => {
  361. reject(err)
  362. })
  363. }
  364. })
  365. })
  366. },
  367. // 获取系统信息
  368. getSystemInfo() {
  369. const systemInfo = wx.getSystemInfoSync()
  370. const statusBarHeight = systemInfo.statusBarHeight
  371. const navHeight = statusBarHeight + 44
  372. this.setData({
  373. statusBarHeight: statusBarHeight,
  374. navHeight: navHeight,
  375. navStyle: `height:${navHeight}px`,
  376. listStyle: `top:${navHeight}px`
  377. })
  378. },
  379. // 获取视频分类
  380. getVideoCategories() {
  381. console.log('getVideoCategories', this.data.globalConfig)
  382. // 筛选出type=1的视频分类
  383. const videoCategories = this.data.globalConfig.categoryList.filter(item => item.type === 1)
  384. // 添加幸福相册分类
  385. videoCategories.push({
  386. id: 999,
  387. name: '幸福相册'
  388. })
  389. console.log('videoCategories', videoCategories)
  390. if (videoCategories.length > 0) {
  391. // 设置分类列表和默认选中的分类
  392. this.setData({
  393. categoryList: videoCategories,
  394. currentCategoryId: videoCategories[0].id
  395. })
  396. // 加载第一个分类的视频列表
  397. this.loadVideoList()
  398. } else {
  399. console.error('未找到视频分类')
  400. wx.showToast({
  401. title: '未找到视频分类',
  402. icon: 'none'
  403. })
  404. }
  405. },
  406. // 切换分类
  407. switchCategory(e) {
  408. const categoryId = e.currentTarget.dataset.id
  409. if (categoryId === this.data.currentCategoryId) return
  410. this.setData({
  411. currentCategoryId: categoryId,
  412. page: 1,
  413. videoList: [],
  414. hasMore: true
  415. })
  416. if (this.data.currentCategoryId !== 999) {
  417. this.loadVideoList()
  418. } else {
  419. this.setData({
  420. videoList: HAPPY_PHOTO_LIST
  421. })
  422. }
  423. },
  424. // 加载视频列表
  425. async loadVideoList() {
  426. if (this.data.loading) return
  427. this.setData({
  428. loading: true
  429. })
  430. try {
  431. const params = {
  432. page: this.data.page,
  433. size: this.data.size,
  434. tag_id: this.data.currentCategoryId,
  435. // 如果不是第一页,传递最后一个视频的ID作为next_id
  436. next_id: this.data.page > 1 && this.data.videoList.length > 0 ?
  437. this.data.videoList[this.data.videoList.length - 1].id :
  438. ""
  439. }
  440. let videoList = []
  441. try {
  442. videoList = await getVideoList(params)
  443. if (!Array.isArray(videoList)) {
  444. throw new Error('返回数据格式错误')
  445. }
  446. videoList = videoList.map(item => ({
  447. ...item,
  448. views: rnd(1, 10),
  449. favors: rnd(5000, 10000),
  450. adType: "video",
  451. lock: false
  452. }))
  453. videoList = this.formatVideoAdList(videoList);
  454. console.log("format videoList", videoList)
  455. } catch (apiError) {
  456. console.error('API调用失败:', apiError)
  457. throw apiError
  458. }
  459. // 如果是第一页,直接替换数据
  460. if (this.data.page === 1) {
  461. this.setData({
  462. videoList: videoList,
  463. loading: false,
  464. hasMore: videoList.length >= this.data.size
  465. })
  466. } else {
  467. // 否则追加数据
  468. this.setData({
  469. videoList: [...this.data.videoList, ...videoList],
  470. loading: false,
  471. hasMore: videoList.length >= this.data.size
  472. })
  473. }
  474. } catch (error) {
  475. console.error('加载视频列表失败:', error)
  476. }
  477. },
  478. /* ------------------ 广告相关 ----------------- */
  479. /**
  480. * 标记广告位置
  481. * @param {} arr
  482. * @returns
  483. */
  484. formatVideoAdList(arr) {
  485. // 原生广告间隔,激励广告间隔
  486. let templateGap = 0,
  487. rewardGap = 0
  488. console.log(this.data.globalConfig)
  489. if (this.data.globalConfig.isHomeTemplateAd === 1) {
  490. templateGap = this.data.globalConfig.homeTemplateAdInterval
  491. } else {
  492. templateGap = 0
  493. }
  494. if (this.data.globalConfig.isHomeRewardAd) {
  495. rewardGap = this.data.globalConfig.homeRewardAdInterval
  496. } else {
  497. rewardGap = 0
  498. }
  499. console.log('原生间隔templateGap', templateGap, '激励间隔rewardGap', rewardGap)
  500. // 第二个固定是原生广告
  501. let result = [arr.shift(), {
  502. adType: 'templateAd'
  503. }]
  504. // 辅助计算间隔变量
  505. let markIndex = 0
  506. let templateAdFlag = true
  507. let rewardAdFlag = true
  508. do {
  509. markIndex += 1
  510. if (templateGap > 0) {
  511. if (templateAdFlag && markIndex - 1 === templateGap) {
  512. markIndex = 0
  513. result.push({
  514. adType: "templateAd"
  515. })
  516. templateAdFlag = false
  517. rewardAdFlag = true
  518. continue
  519. }
  520. } else {
  521. rewardAdFlag = true
  522. }
  523. if (rewardGap > 0) {
  524. if (rewardAdFlag && markIndex - 1 === rewardGap) {
  525. markIndex = 0
  526. templateAdFlag = true
  527. rewardAdFlag = false
  528. let rewardItem = arr.shift()
  529. rewardItem.lock = true
  530. result.push(rewardItem)
  531. console.log("标记激励项:", rewardItem)
  532. continue
  533. }
  534. } else {
  535. templateAdFlag = true
  536. }
  537. result.push(arr.shift())
  538. } while (arr.length > 0);
  539. return result;
  540. },
  541. // 加载更多
  542. loadMore() {
  543. console.log("触发loadMore")
  544. console.log("当前状态:", {
  545. loading: this.data.loading,
  546. hasMore: this.data.hasMore,
  547. page: this.data.page,
  548. videoListLength: this.data.videoList.length
  549. })
  550. // 添加防抖,避免频繁触发
  551. const now = Date.now()
  552. if (now - this.data.lastLoadTime < 500) {
  553. console.log("防抖触发,跳过本次加载")
  554. return
  555. }
  556. if (this.data.hasMore && !this.data.loading) {
  557. console.log("开始加载更多数据")
  558. this.setData({
  559. page: this.data.page + 1,
  560. lastLoadTime: now
  561. })
  562. this.loadVideoList()
  563. } else {
  564. console.log("不满足加载条件:", {
  565. hasMore: this.data.hasMore,
  566. loading: this.data.loading
  567. })
  568. }
  569. },
  570. // 刷新列表
  571. refreshList() {
  572. wx.showLoading({
  573. title: '刷新中...',
  574. })
  575. this.setData({
  576. page: 1,
  577. videoList: [],
  578. hasMore: true
  579. })
  580. this.loadVideoList().then(() => {
  581. wx.hideLoading()
  582. wx.showToast({
  583. title: '刷新成功',
  584. icon: 'success',
  585. duration: 1500
  586. })
  587. }).catch(() => {
  588. wx.hideLoading()
  589. })
  590. },
  591. // 点击视频
  592. onVideoTap(e) {
  593. const {id, info, index} = e.currentTarget.dataset;
  594. console.log(id, info, index, '视频详情')
  595. if (!info) {
  596. wx.hideLoading();
  597. wx.showToast({
  598. title: '视频数据错误',
  599. icon: 'none'
  600. });
  601. return;
  602. }
  603. SendEvent('click_video_tab_video', {"video_id": id, "tag_id": info.tag_ids[0], "uuid": app.globalData.uuid})
  604. const encodedTitle = encodeURIComponent(info.title || '');
  605. this.unlockUrl = `/pages/video/detail?id=${id}&title=${encodedTitle}&tag_id=${info.tag_ids[0]}`
  606. if (!info.lock) {
  607. // 显示加载中提示
  608. wx.showLoading({
  609. title: '加载中...',
  610. mask: true
  611. });
  612. // 跳转到视频详情页
  613. wx.navigateTo({
  614. url: this.unlockUrl,
  615. success: () => {
  616. wx.hideLoading();
  617. },
  618. fail: (err) => {
  619. console.error('跳转失败:', err);
  620. wx.hideLoading();
  621. wx.showToast({
  622. title: '跳转失败',
  623. icon: 'none'
  624. });
  625. }
  626. });
  627. } else {
  628. this.reawrdVideoIndex = index
  629. this.rewardVideo = info
  630. this.rewardVideoPlayFn()
  631. }
  632. },
  633. onPhotoTap (e) {
  634. const {info} = e.currentTarget.dataset;
  635. wx.navigateTo({
  636. url: `/happyphoto/${info.tmpName}/${info.tmpName}`
  637. })
  638. },
  639. // 下拉刷新
  640. onPullDownRefresh() {
  641. this.setData({
  642. page: 1,
  643. videoList: []
  644. })
  645. this.loadVideoList().then(() => {
  646. wx.stopPullDownRefresh()
  647. })
  648. },
  649. // 分享按钮点击事件
  650. onShareTap(e) {
  651. // 阻止事件冒泡
  652. e.stopPropagation();
  653. // SendEvent('click_list_share', {"video_id": video.id, "tag_id": video.tag_ids[0]});
  654. },
  655. // 分享给朋友
  656. onShareAppMessage(e) {
  657. const video = e.target.dataset.video
  658. if (!video) return {}
  659. const jump = wx.getStorageSync('jump');// 是否跳转阅读器
  660. let url = '';
  661. url = `/pages/video/video?shared_video_id=${video.id}&title=${encodeURIComponent(video.title)}&tag_id=${video.tag_ids[0]}&share_count=1`;
  662. if (jump === 1) {
  663. url += '&jump=1';
  664. }
  665. SendEvent('click_list_share', {"video_id": video.id, "tag_id": video.tag_ids[0], "uuid": app.globalData.uuid});
  666. return {
  667. title: video.title,
  668. path: url,
  669. imageUrl: video.cover_image,
  670. success: function (res) {
  671. wx.showToast({
  672. title: '分享成功',
  673. icon: 'success',
  674. duration: 1500
  675. })
  676. },
  677. fail: function (res) {
  678. wx.showToast({
  679. title: '分享失败',
  680. icon: 'none',
  681. duration: 1500
  682. })
  683. }
  684. }
  685. },
  686. // 分享到朋友圈
  687. onShareTimeline(e) {
  688. const video = e.target.dataset.video
  689. if (!video) return {}
  690. const jump = wx.getStorageSync('jump');// 是否跳转阅读器
  691. let url = '';
  692. url = `shared_video_id=${video.id}&title=${encodeURIComponent(video.title)}&tag_id=${video.tag_ids[0]}&share_count=1`;
  693. SendEvent('click_list_share', {"video_id": video.id, "tag_id": video.tag_ids[0], "uuid": app.globalData.uuid});
  694. if (jump === 1) {
  695. url += '&jump=1';
  696. }
  697. return {
  698. title: video.title,
  699. query: url,
  700. imageUrl: video.cover_image
  701. }
  702. },
  703. // 跳转到书籍详情
  704. goToBookDetail() {
  705. getApp().globalData.isShowDialog = true
  706. // 使用公共的goToBookDetail函数
  707. goToBookDetail({
  708. bookId: 7266,
  709. wxBookId: 'A1Hcfv456vGtMYxQjxUm8KNdJ8',
  710. chapterId: null
  711. });
  712. },
  713. // 跳转视频详情
  714. goToVideoDetail(videoId, tagId) {
  715. // 使用公共的goToVideoDetail函数
  716. goToVideoDetail({
  717. videoId: videoId,
  718. tagId: tagId
  719. });
  720. },
  721. // 激励视频加载
  722. rewardVideoLoad() {
  723. if (wx.createRewardedVideoAd) {
  724. let adId = apple.ads.rewardAdId
  725. let that = this
  726. this.videoAd = wx.createRewardedVideoAd({
  727. adUnitId: adId
  728. })
  729. this.videoAd.onLoad(() => {
  730. console.log('首页激励加载成功')
  731. })
  732. this.videoAd.onError((err) => {
  733. console.log('首页激励失败', err)
  734. })
  735. this.videoAd.onClose((res) => {
  736. // 用户点击了【关闭广告】按钮
  737. this.setData({
  738. isLoadingVideo: false
  739. })
  740. if (res && res.isEnded) {
  741. // 发放奖励
  742. that.setData({
  743. [`videoList[${that.reawrdVideoIndex}].lock`]: false
  744. })
  745. console.log('发放奖励跳转')
  746. wx.navigateTo({
  747. url: `${that.unlockUrl}`
  748. })
  749. }
  750. })
  751. }
  752. },
  753. // 激励视频展示
  754. rewardVideoPlayFn() {
  755. wx.showLoading({
  756. title: '解锁视频中',
  757. })
  758. this.videoAd.show().then(() => {
  759. console.log('激励视频播放成功')
  760. }).catch((err) => {
  761. console.log('激励视频播放失败', err)
  762. this.setData({
  763. [`videoList[${that.reawrdVideoIndex}].lock`]: false
  764. })
  765. wx.navigateTo({
  766. url: `${this.unlockUrl}`
  767. })
  768. }).then(() => {
  769. wx.hideLoading()
  770. })
  771. },
  772. // 统一小程序广告加载成功
  773. appletsAdLoad(e) {
  774. let _target = e.currentTarget.dataset
  775. this.setData({
  776. [`adErrorField.${_target.field}`]: false
  777. })
  778. },
  779. // 统一小程序广告加载失败
  780. appletsAdError(e) {
  781. let _target = e.currentTarget.dataset
  782. this.setData({
  783. [`adErrorField.${_target.field}`]: true
  784. })
  785. console.error(_target.name, '错误', e)
  786. },
  787. // 统一小程序广告关闭
  788. appletsAdClose(e) {
  789. let _target = e.currentTarget.dataset
  790. },
  791. // 统一小程序广告点击
  792. appletsAdClick(e) {
  793. let _target = e.currentTarget.dataset
  794. },
  795. })