Newer
Older
import {Component, ElementRef, HostListener, NgZone, Renderer2, ViewChild} from '@angular/core';
import {Content, InfiniteScrollContent, IonicPage, NavController, NavParams, Slide, Slides} from 'ionic-angular';
import {TabsService} from "../tabs.service";
import {StuffDetailPage} from "../../home-pages/stuff-detail/stuff-detail";
import {PublishPage} from "../../discover-pages/publish/publish";
import {EmitService} from "../../../provide/emit.service";
import {NoticePage} from "../notice/notice";
@ViewChild('fixedTab') fixedTab: ElementRef;
@ViewChild('topHeight') topHeight: ElementRef;
@ViewChild('tabsParent') tabsParent: ElementRef;
@ViewChild('tabsChildren') tabsChildren: ElementRef;
@ViewChild('tabSpan') tabSpan: ElementRef;
{
"name": "最新发布",
"type": 0,
"indexChildren": '01'
},
]
},
{
]
},
{
"name": "机关党委", "type": 5, "indexParent": 2, "children": [
obj = {
"plateType": null, //分类
"parentName": null,
"childrenName": null,
};
slideList = new Array(7); //数组的改变 会导致上拉加载更多失效。。
slideArr = new Array(7);
slidersItems = [
{
"static": "true",
"id": null,
"plateType": "20",
"title": "不忘初心,牢记使命",
"imgUrl": "./assets/imgs/home/edu_banner.png"
}
];
constructor(public navCtrl: NavController, public navParams: NavParams,
this.storage.get('userLoginInfo').then((value) => {
this.userId = value.userid;
});
this.itemWidth = window.screen.width / 4;
this.spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
this.changeParent(this.tabsList[0])
});
ionViewDidLeave() {
const videoArr = document.querySelectorAll("video");
for (let i = 0; i < videoArr.length; i++) {
videoArr[i].pause();
}
}
scrollHeight() {
const height = this.topHeight.nativeElement.offsetHeight;
this.content.ionScroll.subscribe(($event) => {
this.zone.run(() => {
if (this.content.scrollTop > height) {
this.renderer.addClass(this.fixedTab.nativeElement, 'tabs-fixed-scroll')
} else {
this.renderer.removeClass(this.fixedTab.nativeElement, 'tabs-fixed-scroll')
}
})
})
//初始化swiper
initSwiper() {
let that = this;
that.swiperImg = new Swiper('#swiper-slide', {
speed: 1000,
autoplay: {
delay: 3000,
disableOnInteraction: false,
},//可选选项,自动滑动
that.slideTitle = that.slidersItems[that.swiperImg.realIndex].title;
that.swiperImg.update();
}
click: function () {
const item = that.slidersItems[this.activeIndex];
if (item.static == "true") {
//前往主题教育
goEdu() {
this.swiper.slideTo(1, 500); //前往主题教育
}
//获取轮播图
getBanner() {
const data = {
obj: {
"resourceType": 2, //1标题图片,2推荐轮播图,3视频
"isRecommend": 1, //推荐(1是0否)
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
if (res.data.list.length > 0) {
res.data.list.forEach(e => {
if (e.attachments.length > 0) {
e.imgUrl = e.attachments[0].path;
}
this.slidersItems = this.slidersItems.concat(res.data.list);
this.slideTitle = this.slidersItems[0].title;
this.swiperImg.update();
//父级选择
changeParent(item) {
this.newsContent.nativeElement.scrollLeft = 0; //二级菜单滑动重置
if (this.obj.parentName == "主题教育") {
this.obj.plateType = null;
this.relatePlateType = item.type;
} else {
this.obj.plateType = item.type;
this.relatePlateType = null;
}
this.resourceType = item.name == "知识拓展" ? 3 : 1;
if (this.childrenList.length > 0) this.indexChildren = this.childrenList[0].indexChildren;
this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
// 自身div的一半 - 滑块的一半
this.tips.nativeElement.style.left = this.itemWidth * (this.indexParent) + (this.itemWidth - this.spanWidth) / 2 + 'px';
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
e.path = e.attachments[1].path;
e.resourceType = e.attachments[1].resourceType;
}
}
)
}
//子级选择
changeChildren(item) {
this.indexChildren = item.indexChildren;
this.obj.childrenName = item.name;
if (this.obj.parentName == "主题教育") {
this.obj.plateType = null;
this.relatePlateType = item.type;
} else {
this.obj.plateType = item.type;
this.relatePlateType = null;
}
if (this.obj.childrenName == "你问我答") {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
isRecent: this.isRecent,
obj: {
'plateType': this.obj.plateType,
'resourceType': this.resourceType,
"relatePlateType": this.relatePlateType
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
res.data.list.splice(0, 10);
res.data.list.forEach(e => {
if (e.attachments && e.attachments.length > 0) {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
}
this.slideList[this.indexParent].push(e);
});
//查询我要出题
getQuestion() {
const data = {
pageNum: 1,
pageSize: 1000,
};
this.tabsSer.findPersonQuestions(data).subscribe(
(res) => {
this.slideList[this.indexParent] = this.newList;
}
)
}
'plateType': this.obj.plateType,
'resourceType': this.resourceType,
"relatePlateType": this.relatePlateType
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
this.slideList[this.toIndex] = this.newList;
this.commonSer.toastTime('刷新成功!', 800);
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
//上拉加载更多
doInfinite(e) {
if (this.totalNum == this.slideList[this.indexParent]) {
e.complete();
return false;
}
this.pageNum++;
const data = {
pageNum: this.pageNum,
pageCount: this.pageCount,
isRecent: this.isRecent,
obj: {
'plateType': this.obj.plateType,
'resourceType': this.resourceType,
"relatePlateType": this.relatePlateType
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
this.totalNum = res.data.total;
res.data.list.forEach(e => {
if (e.attachments && e.attachments.length > 0) {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
}
this.slideList[this.indexParent].push(e);
});
e.complete();
}
)
}
//前往搜索页面
goToSearch() {
this.navCtrl.push(SearchNewPage);
}
//查看详情
goToDetail(item) {
this.navCtrl.push(StuffDetailPage, {
id: item.id
});
}
//前往发布页面
if (item.userId == this.userId) {
this.navCtrl.push('AcceptPage', {id: item.id})
} else {
//消息提醒页面
goToNotice() {
this.navCtrl.push(NoticePage);
}
this.isPublish = false;
}
stop(e) {
e.stopPropagation();
}
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属性
let img = new Image();
img.src = canvas.toDataURL("image/png");
img.setAttribute("crossOrigin", 'Anonymous')
img.onload = () => {
e.target.setAttribute("poster", canvas.toDataURL("image/png"));
}