index.js 14 KB

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