index.js 12 KB

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