play.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. src:'',
  6. id:0,
  7. title:'',
  8. currentPages:1,
  9. coverImg:''
  10. },
  11. onLoad: function (options) {
  12. this.setData({id:options.id});
  13. },
  14. onShow: function () {
  15. let that = this;
  16. if(getCurrentPages().length == 1){
  17. // var getLocation = util.promise();
  18. // getLocation.then(function(value) {
  19. that.getData();
  20. // }, function(error) {
  21. // });
  22. }else{
  23. that.getData();
  24. }
  25. this.setData({currentPages:getCurrentPages().length});
  26. },
  27. getData:function(){
  28. let that = this;
  29. util.ajax({
  30. func:"video/detail",
  31. data:{"id":that.data.id},
  32. load:false
  33. },function(res){
  34. if(res.code == 0){
  35. wx.setNavigationBarTitle({
  36. title: res.data.title
  37. });
  38. that.setData({ src: res.data.url, title: res.data.title, coverImg:res.data.sharePic});
  39. }else{
  40. util.showTips(res.reason);
  41. }
  42. });
  43. },
  44. binderror:function(e){
  45. util.showTips('视频加载失败');
  46. if(this.data.currentPages == 1){
  47. wx.redirectTo({
  48. url: '/pages/home/index'
  49. });
  50. }else{
  51. setTimeout(function(){
  52. wx.navigateBack();
  53. },2300);
  54. }
  55. },
  56. onShareAppMessage: function () {
  57. let that = this;
  58. return {
  59. title: that.data.title,
  60. path: '/pages/public/video/play?id=' + that.data.id,
  61. imageUrl:!util.isEmpty(that.data.coverImg)?that.data.coverImg:'http://img.bbztx.com/image_test/upload/thumbs/20210430/logo/1619766863529068803.jpg'
  62. }
  63. }
  64. })