index.js 14 KB

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