video.js 26 KB

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