Newer
Older
import {Component, ElementRef, Renderer2, ViewChild} from '@angular/core';
import {IonicPage, ModalController, NavController, NavParams} from 'ionic-angular';
import {TabsService} from "../../tabs/tabs.service";
import {Storage} from "@ionic/storage";
import {CommonService} from "../../../provide/common.service";
import {ReplyComponent} from "../../../components/reply/reply";
import {CommentComponent} from "../../../components/comment/comment";
@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 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) => {
}
}
)
}
//点赞
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') {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
if (num == 1) {
this.renderer.addClass(this.like.nativeElement, 'animation');
}
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
148
149
150
151
152
153
154
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; //防止点赞,评论,收藏之后文章信息刷新刷新
}
)
let modal = this.modalCtrl.create(CommentComponent, {placeholder: '回复:' + item.username});
modal.onDidDismiss(res => {
if (res) {
this.replyContent = res;
this.replyHandle();
}
});
modal.present();
}
//回复
commentId: this.replyItem.id,
content: this.replyContent,
parentId: '',
this.getStuff();
this.reply = false;
}
)
}
//取消评论
cancel() {
this.content = '';
this.comment = false;
this.reply = false;
}
//查看回复
commentSearch(comment) {
let modal = this.modalCtrl.create(ReplyComponent, {
comment: comment
openComment() {
let modal = this.modalCtrl.create(CommentComponent, {placeholder: ''});
modal.onDidDismiss(res => {
if (res) {
this.content = res;
this.sure();
}
})
modal.present();
}
// 提交评论
const data = {
userid: this.userId,
content: this.content,
id: this.stuffId,
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.getStuff();
//列表视频不同时播放
clickVideo(e) {
const videoArr = document.querySelectorAll("video");
for (let i = 0; i < videoArr.length; i++) {
if (videoArr[i] != e.target) {
videoArr[i].pause();
}
}
}
loadVideo(e) {
const scale = 0.8;
const canvas = document.createElement('canvas');
canvas.width = 120 * scale;
canvas.height = 120 * scale;
//绘制图片
canvas.getContext('2d').drawImage(e.target, 0, 0, canvas.width, canvas.height);
//设置标签的poster属性
e.target.setAttribute("poster", canvas.toDataURL("image/png"));
}