index.js 14 KB

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