index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. var host = app.globalData.host;
  5. Page({
  6. data: {
  7. zimu_list: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
  8. scroll: '', //滚动到指定 id值的子元素
  9. touchmove: 0,//给字母导航添加背景色 1 添加 0不添加
  10. nav_height: '',//字母导航单个元素高度
  11. nav_top:'',
  12. hiddenn: true,//hint_box 提示框 展示隐藏
  13. nav_text: '',//hint_box 提示框里面的文本
  14. lb:[],
  15. act:0,
  16. journals:[],
  17. organizers:[],
  18. subjects:[]
  19. },
  20. onLoad: function () {
  21. this.getData();
  22. },
  23. //获取所有数据
  24. getData:function(){
  25. wx.showLoading({
  26. title: '加载中',
  27. })
  28. var that=this;
  29. wx.request({
  30. url: host+'/api/index/banners',
  31. method:'GET',
  32. success:function(res){
  33. that.setData({
  34. lb: res.data.data.banners
  35. })
  36. }
  37. })
  38. // 全刊
  39. wx.request({
  40. url: host + '/api/index/journals',
  41. method: 'GET',
  42. success: function (res) {
  43. wx.hideLoading()
  44. that.setData({
  45. journals: res.data.data.journals
  46. })
  47. }
  48. })
  49. // 主办单位
  50. wx.request({
  51. url: host + '/api/index/organizers',
  52. method: 'GET',
  53. success: function (res) {
  54. that.setData({
  55. organizers: res.data.data.list
  56. })
  57. }
  58. })
  59. // 领域期刊
  60. wx.request({
  61. url: host + '/api/index/subjects',
  62. method: 'GET',
  63. success: function (res) {
  64. that.setData({
  65. subjects: res.data.data.list
  66. })
  67. }
  68. })
  69. },
  70. //置顶
  71. top: function(e){
  72. wx.request({
  73. url: host+'/api/index/totop',
  74. method:'PUT',
  75. data:{
  76. id:e.target.dataset.id,
  77. type:'subject'
  78. },
  79. success:function(res){
  80. console.log(res.data)
  81. }
  82. })
  83. },
  84. tab:function(e){
  85. this.setData({
  86. act: e.target.dataset.id
  87. })
  88. },
  89. swchange:function(e){
  90. this.setData({
  91. act: e.detail.current
  92. })
  93. },
  94. onReady: function () {
  95. this.get_height();
  96. },
  97. //事件处理函数
  98. touchstart: function (e) {
  99. this.set_scroll(e)
  100. },
  101. touchmove: function (e) {
  102. this.set_scroll(e)
  103. },
  104. touchend: function () {
  105. this.setData({
  106. touchmove: 0,
  107. hiddenn: true
  108. })
  109. },
  110. scroll(e){
  111. var that = this
  112. this.setData({
  113. scroll:e.target.dataset.id.toLowerCase(),
  114. })
  115. },
  116. set_scroll: function (e) {
  117. var page_y = e.changedTouches[0].pageY - this.data.nav_top;
  118. // console.log(page_y)
  119. var nav_height = +this.data.nav_height
  120. var idx = Math.floor(page_y / nav_height)
  121. var zimu = this.data.zimu_list[idx];
  122. this.setData({
  123. touchmove: 1,
  124. scroll: zimu.toLowerCase(),
  125. nav_text: zimu,
  126. hiddenn: false
  127. })
  128. },
  129. get_height: function () {
  130. var that = this
  131. var query = wx.createSelectorQuery();
  132. query.select('#nav_item').boundingClientRect()
  133. wx.createSelectorQuery().select('#nav').boundingClientRect(function (rect) {
  134. that.setData({
  135. nav_top: rect.top,
  136. })
  137. }).exec()
  138. query.exec(function (res) {
  139. that.setData({
  140. nav_height: res[0].height,
  141. })
  142. })
  143. },
  144. getUserInfo: function(e) {
  145. console.log(e)
  146. app.globalData.userInfo = e.detail.userInfo
  147. this.setData({
  148. userInfo: e.detail.userInfo,
  149. hasUserInfo: true
  150. })
  151. }
  152. })