index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // pages/detail/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. detail: {},
  9. playUrl: "",
  10. videoData:{},
  11. imgList: []
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let que = app.globalData.selectQuestion || {};
  18. wx.setNavigationBarTitle({
  19. title: que.name
  20. })
  21. if (que.type === "video") {
  22. que.content = que.content.map(v => {
  23. v.play_count = this.formatNumber(v.play_count);
  24. return v
  25. })
  26. }
  27. this.setData({
  28. detail: que || {}
  29. })
  30. },
  31. formatNumber: function (n) {
  32. if (isNaN(n)) return 0;
  33. var out = n;
  34. if (out >= 100000000) {
  35. out = (out / 100000000).toFixed(2) + '亿';
  36. } else if (out >= 10000) {
  37. out = (out / 10000).toFixed(2) + '万';
  38. }
  39. return out
  40. },
  41. playVideo(e) {
  42. this.setData({
  43. playUrl: e.currentTarget.dataset.url || ""
  44. })
  45. },
  46. bindloadedmetadata(e){
  47. let p = {
  48. ...e.detail
  49. }
  50. let sys = wx.getSystemInfoSync();
  51. console.log(e.detail,sys.windowWidth);
  52. p.height = p.height/p.width * sys.windowWidth;
  53. p.width = sys.windowWidth;
  54. this.setData({
  55. videoData: p
  56. })
  57. },
  58. closeVideo(){
  59. this.setData({
  60. playUrl: ""
  61. })
  62. },
  63. bindload(e){
  64. const list = this.data.imgList || [];
  65. let height =339/ e.detail.width * e.detail.height
  66. list[e.target.dataset.index] = height;
  67. console.log(list);
  68. this.setData({
  69. imgList: list
  70. })
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. },
  102. /**
  103. * 用户点击右上角分享
  104. */
  105. onShareAppMessage: function () {
  106. }
  107. })