You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							140 lines
						
					
					
						
							3.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							140 lines
						
					
					
						
							3.1 KiB
						
					
					
				| // pages/article/index.js | |
| import {ArticeModel} from '../../models/artice.js' | |
| import dayjs from '../../utils/dayjs/index.js' | |
| import { store } from '../../utils/store.js' | |
| let artice = new ArticeModel() | |
| 
 | |
| Page({ | |
| 
 | |
|   /** | |
|    * 页面的初始数据 | |
|    */ | |
|   data: { | |
|     nodes: '', | |
|     isStar: true, // 是否 | |
|     showBtn: false, | |
|     image: '', | |
|     aId: '', | |
|     title: '', | |
|     date: '', | |
|     origin: '', | |
|     unStar: '/images/common/star.png', | |
|     star: '/images/common/star_light.png', | |
|     disable: true, | |
|     readNum: 0, | |
|     collectNum: 0, | |
|   }, | |
|   onClickCollect () { | |
|     // 收藏功能 | |
|     if (store.hasBindUserInfo()) { | |
|       this.addOrRemoveCollectionApi() | |
|     } else { | |
|       wx.redirectTo({ | |
|         url: '/pages/weChatAuth/index', | |
|       }) | |
|     } | |
|   }, | |
|   onlineSubmit () { | |
|     // console.log('在线报名') | |
|     this.setData({ | |
|       disable: true | |
|     }) | |
|     if (store.hasBindUserInfo()) { | |
|       this.onlineSignApi() // 在线报名 | |
|     } else { | |
|       wx.redirectTo({ | |
|         url: '/pages/weChatAuth/index', | |
|       }) | |
|     } | |
|     // if (store.hasPhone()) { | |
|     //   this.onlineSignApi() // 在线报名 | |
|     // } else { | |
|     //   wx.redirectTo({ | |
|     //     url: `/pages/register/index`, | |
|     //   }) | |
|     // } | |
|   }, | |
|   onShareAppMessage (res) { | |
|     return { | |
|       title: this.data.title, | |
|       path: `/pages/article/index?id=${this.data.aId}` | |
|     } | |
|   }, | |
|   /** | |
|    * 生命周期函数--监听页面加载 | |
|    */ | |
|   onLoad: function (options) { | |
|     //console.log(options) | |
|     const {id} = options | |
|     this.setData({ | |
|       aId: id | |
|     }) | |
|     this.fetchArticeApi() | |
|   }, | |
|   fetchArticeApi () { | |
|     wx.showLoading({ | |
|       title: '加载中...', | |
|     }) | |
|     artice.getDetail(this.data.aId, (res) => { | |
|       //console.log('artice detail') | |
|       console.log(res) | |
|       const data = res.result | |
|       const date = dayjs(data.createTime).format('MM月DD日') | |
|       wx.setNavigationBarTitle({ | |
|         title: data.title, | |
|       }) | |
|       this.setData({ | |
|         nodes: data.content, | |
|         title: data.title, | |
|         date: date, | |
|         image: data.titlePic, | |
|         origin: data.source, | |
|         isStar: data.isCollection ? true : false, | |
|         showBtn: data.typeFlag >= 2 ? true : false, | |
|         disable: data.typeFlag == 3 ? true : false, | |
|         readNum: data.readNum, | |
|         collectNum: data.collectNum, | |
|       }, () => { | |
|         wx.hideLoading() | |
|       }) | |
|     }) | |
|   }, | |
|   addOrRemoveCollectionApi () { | |
|     artice.addOrRemoveCollect(this.data.aId, res => { | |
|       //console.log(res) | |
|       if (res.code == 200) { | |
|         this.setData({ | |
|           isStar: !this.data.isStar | |
|         }) | |
|         wx.showToast({ | |
|           title: this.data.isStar ? '收藏成功' : '取消收藏成功', | |
|           icon: 'none' | |
|         }) | |
|       } | |
|     }) | |
|   }, | |
|   onlineSignApi () { | |
|     artice.onlineSign(this.data.aId, res => { | |
|       console.log(res) | |
|       if(res.code == 200){ | |
|         console.log(res.code); | |
|         wx.showToast({ | |
|           title: res.message, | |
|           icon: 'none' | |
|         }) | |
|       } | |
|       if(res.code != 200){ | |
|         console.log(res.code); | |
|         this.setData({ | |
|           disable: false | |
|         }) | |
|         wx.showToast({ | |
|           title: res.message, | |
|           icon: 'none' | |
|         }) | |
|       } | |
|       // this.fetchArticeApi() | |
|     }) | |
|   }, | |
|    | |
| }) |