Newer
Older
import {Component, ElementRef, Renderer2, ViewChild} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {TabsService} from "../../tabs/tabs.service";
import {Storage} from "@ionic/storage";
import {CommonService} from "../../../provide/common.service";
@IonicPage()
@Component({
selector: 'page-stuff-detail',
templateUrl: 'stuff-detail.html',
})
export class StuffDetailPage {
@ViewChild('like') like: ElementRef;
@ViewChild('collection') collection: ElementRef;
constructor(public navCtrl: NavController, public navParams: NavParams, public sanitizer: DomSanitizer,
public renderer: Renderer2,
public tabSer: TabsService, public storage: Storage, public commonSer: CommonService) {
}
ionViewDidLoad() {
this.storage.get('userLoginInfo').then((value) => {
this.userId = value.userid;
//增加浏览量
}
//获取文章信息
getStuff() {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
this.stuffObj = res.data;
let con = this.stuffObj.content.replace(/\r?\n/g, "<br />");
this.stuffObj.content = this.sanitizer.bypassSecurityTrustHtml(con);
}
)
}
ionViewWillLeave() {
this.footerView = false;
}
//更新浏览 点赞 收藏 评论
//根据类型,修改数量(1浏览,2点赞,3收藏,4评论)
type: 1,
num: 1,
userid: this.userId,
content: this.content,
}
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.commonSer.log('浏览数 +1')
}
}
)
}
//点赞
likeHandle() {
let num = this.countObj.like == true ? '-1' : 1;
const data = {
id: this.stuffId,
type: 2,
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
if (num == 1) {
this.commonSer.toastTime('谢谢点赞','1000');
this.renderer.addClass(this.like.nativeElement, 'animation');
}
if (num == -1){
this.commonSer.toastTime('点赞已取消','1000');
this.renderer.removeClass(this.like.nativeElement, 'animation');
}
this.countObj = res.data; //防止点赞,评论,收藏之后文章信息刷新刷新
}
)
}
}
)
}
//收藏
collectionHandle() {
let num = this.countObj.collection == true ? '-1' : 1;
const data = {
id: this.stuffId,
type: 3,
num: ~~num,
userid: this.userId,
content: this.content,
};
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
if (num == 1) {
this.renderer.addClass(this.collection.nativeElement, 'animation');
this.commonSer.toastTime('功崇惟志,业广惟勤', '1000')
}
if (num == -1) {
this.renderer.removeClass(this.collection.nativeElement, 'animation');
this.commonSer.toastTime('收藏已取消', '1000')
}
this.countObj = res.data; //防止点赞,评论,收藏之后文章信息刷新刷新
}
)
const data = {
userid: this.userId,
content: this.content,
id: this.stuffId,
}
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.getStuff();
this.commonSer.toast('发布成功');
}
}
)
}
//取消发布