index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. sub_list:[],
  20. show:1,
  21. uid:'',
  22. page_org:1,
  23. page_sub:1,
  24. total_org:0,
  25. total_sub:0,
  26. cycleId: 'day',
  27. value: ['日榜','周榜','月榜'],
  28. select:0,
  29. day:'',
  30. week:'',
  31. month: '',
  32. m_value:0,
  33. show_month:0,
  34. sub_value:0,
  35. week_h:0,
  36. casci_list:[],
  37. page_csi:1,
  38. total_csi: 0,
  39. yestoday:''
  40. },
  41. onLoad: function () {
  42. var y = new Date().getFullYear() ,m=(new Date().getMonth() + 1) ,d=new Date().getDate();
  43. m = m > 9 ? m : '0' + m;
  44. d = d > 9 ? d : '0' + d;
  45. this.setData({
  46. day:y+'-'+m+'-'+d,
  47. month: y + '-' + m,
  48. yestoday: y + '-' + m + '-' + (d-1)
  49. })
  50. this.getTimer()
  51. if (this.data.uid){
  52. this.setData({
  53. organizers: [],
  54. subjects: [],
  55. page_org: 1,
  56. page_sub: 1,
  57. total_org: 0,
  58. total_sub: 0
  59. })
  60. this.getData();
  61. }else{
  62. this.setData({
  63. openid: app.globalData.openid
  64. })
  65. wx.getStorage({
  66. key: 'uid',
  67. success: res => {
  68. if (res.data) {
  69. this.setData({ show: 0, uid: res.data })
  70. }
  71. this.getData();
  72. },
  73. })
  74. }
  75. },
  76. /**
  77. * 周期切换点击
  78. * @param {*} e
  79. */
  80. onTabItemClick: function onTabItemClick(e) {
  81. var id = e.currentTarget.dataset.tabs;
  82. this.setData({
  83. select:id,
  84. page_csi:1,
  85. total_csi:0,
  86. casci_list:[]
  87. })
  88. this.getcasci()
  89. },
  90. //周榜
  91. changeMonth:function(e){
  92. var id = e.currentTarget.dataset.id;
  93. this.setData({
  94. m_value: id
  95. })
  96. },
  97. monthSelect: function () {
  98. var week=this.data.columns[this.data.m_value]
  99. this.setData({
  100. week: week,
  101. show_month:0,
  102. page_csi: 1,
  103. total_csi: 0,
  104. casci_list: []
  105. })
  106. this.getcasci()
  107. },
  108. open: function () {
  109. this.setData({
  110. show_month: 1,
  111. week_h: this.data.m_value*40
  112. })
  113. },
  114. close:function(){
  115. this.setData({
  116. show_month: 0
  117. })
  118. },
  119. // 日榜
  120. bindDateChange:function(e){
  121. this.setData({
  122. yestoday: e.detail.value,
  123. page_csi: 1,
  124. total_csi: 0,
  125. casci_list: []
  126. })
  127. this.getcasci()
  128. },
  129. //领域期刊
  130. subChange:function(e){
  131. this.setData({
  132. sub_value: e.detail.value,
  133. page_csi: 1,
  134. total_csi: 0,
  135. casci_list: []
  136. })
  137. this.getcasci()
  138. },
  139. //月榜
  140. bindDateChange1: function (e) {
  141. this.setData({
  142. month: e.detail.value,
  143. page_csi: 1,
  144. total_csi: 0,
  145. casci_list: []
  146. })
  147. this.getcasci()
  148. },
  149. onGotUserInfo: function () {
  150. wx.getUserProfile({
  151. desc: '用于完善会员资料',
  152. success: res=> {
  153. //获取基本信息
  154. var data = {
  155. nickName: res.userInfo.nickName,
  156. avatarUrl: res.userInfo.avatarUrl
  157. }
  158. wx.showLoading({
  159. title: '正在登陆',
  160. })
  161. wx.setStorage({
  162. key: 'userInfo',
  163. data: data,
  164. })
  165. wx.request({
  166. url: host + '/api/auth',
  167. method: 'POST',
  168. data: {
  169. nickname: data.nickName,
  170. avatar: data.avatarUrl,
  171. openid: app.globalData.openid,
  172. },
  173. success: res => {
  174. wx.hideLoading()
  175. wx.setStorage({
  176. key: 'uid',
  177. data: res.data.data.uid,
  178. })
  179. this.setData({
  180. show: 0,
  181. uid: res.data.data.uid
  182. })
  183. this.getData()
  184. },
  185. fail:error=>{
  186. wx.hideLoading()
  187. wx.showLoading({
  188. title: '登陆失败',
  189. })
  190. }
  191. })
  192. }
  193. })
  194. },
  195. //主办单位下一页
  196. next_org:function(){
  197. if(this.data.organizers.length < this.data.total_org){
  198. const page = this.data.page_org+1
  199. this.setData({
  200. page_org: page
  201. })
  202. this.getorg()
  203. }
  204. },
  205. //领域期刊下一页
  206. next_sub:function(){
  207. if(this.data.subjects.length < this.data.total_sub){
  208. const page = this.data.page_sub+1
  209. this.setData({
  210. page_sub: page
  211. })
  212. this.getsub()
  213. }
  214. },
  215. //指数下一页
  216. next_csi: function () {
  217. if (this.data.casci_list.length < this.data.total_csi) {
  218. const page = this.data.page_csi + 1
  219. this.setData({
  220. page_csi: page
  221. })
  222. this.getcasci()
  223. }
  224. },
  225. //获取所有数据
  226. getData:function(flag){
  227. wx.showNavigationBarLoading()
  228. var that=this;
  229. if(!flag){
  230. wx.request({
  231. url: host+'/api/index/banners',
  232. method:'GET',
  233. success:function(res){
  234. that.setData({
  235. lb: res.data.data.banners
  236. })
  237. },
  238. fail: function () {
  239. wx.hideNavigationBarLoading()
  240. wx.showToast({
  241. title: '服务器开小差啦!',
  242. icon: 'none'
  243. })
  244. }
  245. })
  246. // 全刊
  247. wx.request({
  248. url: host + '/api/index/journals',
  249. method: 'GET',
  250. success: function (res) {
  251. wx.hideNavigationBarLoading()
  252. that.setData({
  253. journals: res.data.data.journals
  254. })
  255. }
  256. })
  257. }
  258. //全部数据
  259. wx.request({
  260. url: host + '/api/index/subjects',
  261. method: 'GET',
  262. data: {
  263. uid: this.data.uid,
  264. page_size:100000
  265. },
  266. success: res => {
  267. if (res.data.code == 0) {
  268. const list = res.data.data.list;
  269. list.unshift({
  270. name:'请选择领域',
  271. id:''
  272. })
  273. this.setData({
  274. sub_list: list
  275. })
  276. this.getcasci()
  277. }
  278. }
  279. })
  280. this.getorg()
  281. this.getsub()
  282. },
  283. //指数
  284. getcasci:function(){
  285. wx.showNavigationBarLoading()
  286. const casci_list = this.data.casci_list;
  287. var subject_id=this.data.sub_list[this.data.sub_value].id,date='';
  288. if (this.data.select == 0){
  289. date = this.data.yestoday
  290. }
  291. if (this.data.select == 1) {
  292. date = this.data.week.replace('至',',')
  293. }
  294. if (this.data.select == 2) {
  295. date = this.data.month
  296. }
  297. wx.request({
  298. url: host + '/api/casci/list',
  299. method: 'GET',
  300. data: {
  301. uid: this.data.uid,
  302. date: date,
  303. signup_id: subject_id,
  304. page:this.data.page_csi,
  305. // page_size:20
  306. },
  307. success: res => {
  308. wx.hideNavigationBarLoading()
  309. if (res.data.code == 0) {
  310. const list = res.data.data[1];
  311. for (let i = 0; i < list.length; i++) {
  312. casci_list.push(list[i])
  313. }
  314. this.setData({
  315. casci_list: casci_list,
  316. total_csi: res.data.data[0]
  317. })
  318. }
  319. }
  320. })
  321. },
  322. //主办单位
  323. getorg:function(){
  324. wx.showNavigationBarLoading()
  325. const organizers=this.data.organizers;
  326. wx.request({
  327. url: host + '/api/index/organizers',
  328. method: 'GET',
  329. data: {
  330. uid: this.data.uid,
  331. page: this.data.page_org
  332. },
  333. success: res=>{
  334. wx.hideNavigationBarLoading()
  335. if(res.data.code == 0){
  336. const list=res.data.data.list;
  337. for(let i=0;i<list.length;i++){
  338. organizers.push(list[i])
  339. }
  340. this.setData({
  341. organizers: organizers,
  342. total_org:res.data.data.total
  343. })
  344. }
  345. }
  346. })
  347. },
  348. //领域期刊
  349. getsub:function(){
  350. wx.showNavigationBarLoading()
  351. const subjects=this.data.subjects;
  352. wx.request({
  353. url: host + '/api/index/subjects',
  354. method: 'GET',
  355. data: {
  356. uid: this.data.uid,
  357. page: this.data.page_sub
  358. },
  359. success: res=>{
  360. wx.hideNavigationBarLoading()
  361. if(res.data.code == 0){
  362. const list=res.data.data.list;
  363. for(let i=0;i<list.length;i++){
  364. subjects.push(list[i])
  365. }
  366. this.setData({
  367. subjects: subjects,
  368. total_sub:res.data.data.total
  369. })
  370. }
  371. }
  372. })
  373. },
  374. search:function(){
  375. wx.navigateTo({
  376. url: '../searchList/searchList',
  377. })
  378. },
  379. //置顶
  380. top: function(e){
  381. var type = e.target.dataset.type;
  382. wx.request({
  383. url: host+'/api/index/totop',
  384. method:'PUT',
  385. data:{
  386. id:e.target.dataset.id,
  387. type: type,
  388. uid:this.data.uid,
  389. action:'do'
  390. },
  391. success: res=>{
  392. wx.showToast({
  393. title: '置顶成功',
  394. icon:'none'
  395. })
  396. if (type == 'organizer'){
  397. this.setData({
  398. organizers:[],
  399. page_org:1
  400. })
  401. this.getorg()
  402. }else{
  403. this.setData({
  404. subjects: [],
  405. page_sub: 1
  406. })
  407. this.getsub()
  408. }
  409. }
  410. })
  411. },
  412. cancel_top: function (e) {
  413. var type = e.target.dataset.type;
  414. wx.request({
  415. url: host + '/api/index/totop',
  416. method: 'PUT',
  417. data: {
  418. id: e.target.dataset.id,
  419. type: type,
  420. uid: this.data.uid,
  421. action:'cancel'
  422. },
  423. success: res=> {
  424. wx.showToast({
  425. title: '已取消',
  426. icon: 'none'
  427. })
  428. if (type == 'organizer') {
  429. this.setData({
  430. organizers: [],
  431. page_org: 1
  432. })
  433. this.getorg()
  434. } else {
  435. this.setData({
  436. subjects: [],
  437. page_sub: 1
  438. })
  439. this.getsub()
  440. }
  441. }
  442. })
  443. },
  444. tab:function(e){
  445. this.setData({
  446. act: e.target.dataset.id
  447. })
  448. },
  449. swchange:function(e){
  450. this.setData({
  451. act: e.detail.current
  452. })
  453. },
  454. onReady: function () {
  455. this.get_height();
  456. },
  457. //事件处理函数
  458. touchstart: function (e) {
  459. this.set_scroll(e)
  460. },
  461. touchmove: function (e) {
  462. this.set_scroll(e)
  463. },
  464. touchend: function () {
  465. this.setData({
  466. touchmove: 0,
  467. hiddenn: true
  468. })
  469. },
  470. scroll(e){
  471. var that = this
  472. this.setData({
  473. scroll:e.target.dataset.id,
  474. })
  475. },
  476. set_scroll: function (e) {
  477. var page_y = e.changedTouches[0].pageY - this.data.nav_top;
  478. // console.log(page_y)
  479. var nav_height = +this.data.nav_height
  480. var idx = Math.floor(page_y / nav_height)
  481. var zimu = this.data.zimu_list[idx];
  482. this.setData({
  483. touchmove: 1,
  484. scroll: zimu,
  485. nav_text: zimu,
  486. hiddenn: false
  487. })
  488. },
  489. get_height: function () {
  490. var that = this
  491. var query = wx.createSelectorQuery();
  492. query.select('#nav_item').boundingClientRect()
  493. wx.createSelectorQuery().select('#nav').boundingClientRect(function (rect) {
  494. that.setData({
  495. nav_top: rect.top,
  496. })
  497. }).exec()
  498. query.exec(function (res) {
  499. that.setData({
  500. nav_height: res[0].height,
  501. })
  502. })
  503. },
  504. getUserInfo: function(e) {
  505. app.globalData.userInfo = e.detail.userInfo
  506. this.setData({
  507. userInfo: e.detail.userInfo,
  508. hasUserInfo: true
  509. })
  510. },
  511. toDetail:function(e){
  512. // console.log(e)
  513. },
  514. toBanner:function(e){
  515. var url = e.target.dataset.id
  516. wx.navigateTo({
  517. url: url,
  518. })
  519. },
  520. /**
  521. * 页面相关事件处理函数--监听用户下拉动作
  522. */
  523. onPullDownRefresh: function () {
  524. wx.startPullDownRefresh()
  525. },
  526. getTimer() {
  527. let time = new Date() // 获取当前时间
  528. let nowTime = time.getTime()
  529. let day = time.getDay()
  530. let oneDayTime = 24 * 60 * 60 * 1000; // 一周的时间
  531. let MondayTime = nowTime - (day - 1) * oneDayTime; //显示当前周一
  532. let SundayTime = nowTime + (7 - day) * oneDayTime; //显示当前周日
  533. let setlist = [] // 初始化一个空数组 准备装食物--你好骚啊
  534. for (let i = 0; i < 365*3; i++) {
  535. // 这块我不知道怎么回事一直会有重复的push进去,后面做了去重,可以放心食用,当然也可以优化一下
  536. setlist.push(this.setTime(MondayTime) + ' 至 ' + this.setTime(SundayTime)) // this.setTime()在下面 放心食用
  537. // 重点 push完,赶紧让它获取上一周的时间 oneDayTime上面有写
  538. time = new Date(time - oneDayTime)
  539. nowTime = time.getTime()
  540. day = time.getDay()
  541. MondayTime = nowTime - (day - 1) * oneDayTime; //显示当前周一
  542. SundayTime = nowTime + (7 - day) * oneDayTime; //显示当前周日
  543. }
  544. let list = [...new Set(setlist)] // 简单去重一下
  545. list.shift()
  546. console.log(list);
  547. this.setData({
  548. columns: list,
  549. week: list[0]
  550. })
  551. },
  552. setTime(time) {
  553. // 将time时间戳 先格式化一下
  554. let date = new Date(time)
  555. let yy = date.getFullYear()
  556. let m = date.getMonth() + 1
  557. let day = date.getDate()
  558. let str = yy + '-' + (m < 10 ? '0' + m : m) + '-' + (day < 10 ? '0' + day : day)
  559. return str
  560. }
  561. })