index.js 13 KB

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