Commit f1ea0484 authored by wangqinghua's avatar wangqinghua

左滑

parent 65b65be3
import { NgModule } from '@angular/core'; import {NgModule} from '@angular/core';
import { SlideComponent } from './slide/slide'; import {SlideComponent} from './slide/slide';
import {IonicPageModule} from "ionic-angular"; import {IonicPageModule} from "ionic-angular";
import { SlideListComponent } from './slide-list/slide-list'; import {SlideListComponent} from './slide-list/slide-list';
@NgModule({ @NgModule({
declarations: [SlideComponent, declarations: [SlideComponent,
SlideListComponent, SlideListComponent,
], ],
imports: [ imports: [
IonicPageModule IonicPageModule
], ],
exports: [SlideComponent, exports: [SlideComponent,
SlideListComponent, SlideListComponent,
], ],
providers:[ providers: [
SlideComponent, SlideComponent,
] SlideListComponent,
]
}) })
export class ComponentsModule {} export class ComponentsModule {
}
<!--true 隐藏 false 显示-->
<div [hidden]="isScroll" class="news-content"> <div [hidden]="isScroll" class="news-content">
<div class="tabs-parent"> <div class="tabs-parent">
<div *ngFor="let item of tabsList;let i = index" (click)="change(item)" class="tabs-children"> <div *ngFor="let item of tabsList;let i = index" (click)="change(item)" class="tabs-children">
...@@ -7,6 +8,7 @@ ...@@ -7,6 +8,7 @@
</div> </div>
</div> </div>
<!--固定 false -->
<div [hidden]="!isScroll" ion-fixed class="news-content ion-fixed"> <div [hidden]="!isScroll" ion-fixed class="news-content ion-fixed">
<div class="tabs-parent"> <div class="tabs-parent">
<div *ngFor="let item of tabsList;let i = index" (click)="change(item)" class="tabs-children"> <div *ngFor="let item of tabsList;let i = index" (click)="change(item)" class="tabs-children">
......
import {AfterViewInit, Component, ElementRef, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, NgZone, ViewChild} from '@angular/core';
import {Slides} from "ionic-angular"; import {Content, Slides} from "ionic-angular";
import {TabsService} from "../../pages/tabs/tabs.service"; import {TabsService} from "../../pages/tabs/tabs.service";
import {AppGlobal} from "../../service/http.service"; import {AppGlobal} from "../../service/http.service";
@Component({ @Component({
selector: 'slide-list', selector: 'slide-list',
templateUrl: 'slide-list.html' templateUrl: 'slide-list.html'
}) })
export class SlideListComponent implements AfterViewInit{ export class SlideListComponent implements AfterViewInit {
@ViewChild(Slides) slides:Slides; @ViewChild(Slides) slides1: Slides;
@ViewChild('tabSpan') tabSpan:ElementRef; @ViewChild('tabSpan') tabSpan: ElementRef;
@ViewChild('tips') tips:ElementRef; @ViewChild('tips') tips: ElementRef;
@ViewChild('tips1') tips1:ElementRef; @ViewChild('tips1') tips1: ElementRef;
isScroll = false; isScroll = false;
//所属板块类型: //所属板块类型:
//1党章党规,2系列讲话,3中央精神,4本市部署,5通知公告,6党建动态,7工作提示,8党务参考 //1党章党规,2系列讲话,3中央精神,4本市部署,5通知公告,6党建动态,7工作提示,8党务参考
//9廉政格言,10纪检提示,11风险排查,12警示教育,13支部活动,14党建联建,15结对帮扶 //9廉政格言,10纪检提示,11风险排查,12警示教育,13支部活动,14党建联建,15结对帮扶
tabsList = [ tabsList = [
{name: "系列讲话", type: 2, index: 0}, {name: "系列讲话", type: 2, index: 0},
{name: "党章党规", type: 1, index: 1}, {name: "党章党规", type: 1, index: 1},
{name: "中央精神", type: 3, index: 2}, {name: "中央精神", type: 3, index: 2},
{name: "本市部署", type: 4, index: 3} {name: "本市部署", type: 4, index: 3}
]; ];
index = 0; index = 0;
slideList = []; slideList = [];
picture: string = AppGlobal.domain + '/wisdomgroup'; picture: string = AppGlobal.domain + '/wisdomgroup';
constructor(private tabsSer: TabsService,public zone:NgZone) {
this.slideList.length = 4;
}
constructor(private tabsSer:TabsService) { ngAfterViewInit(): void {
this.slideList.length = 4; this.change(this.tabsList[0]);
console.log('Hello SlideListComponent Component');
}
ngAfterViewInit(): void {
this.change(this.tabsList[0]);
}
change(item) {
const index = item.index;
let itemWidth = window.screen.width / 4;
let spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
this.tips1.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
// 自身div的一半 - 滑块的一半
this.tips.nativeElement.style.left = itemWidth * (index) + (itemWidth - spanWidth) / 2 + 'px';
this.tips1.nativeElement.style.left = itemWidth * (index) + (itemWidth - spanWidth) / 2 + 'px';
this.index = index;
const data = {
pageSize: 1,
pageCount: 100,
obj: {
'plateType': item.type,
'resourceType': 1
}
} }
this.tabsSer.stuffPage(data).subscribe(
(res) => { change(item) {
let arr = res.data; const index = item.index;
arr.forEach(e => { let itemWidth = window.screen.width / 4;
if (e.attachments.length > 0) { let spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
e.imgUrl = e.attachments[0].path; this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
this.tips1.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
// 自身div的一半 - 滑块的一半
this.tips.nativeElement.style.left = itemWidth * (index) + (itemWidth - spanWidth) / 2 + 'px';
this.tips1.nativeElement.style.left = itemWidth * (index) + (itemWidth - spanWidth) / 2 + 'px';
this.index = index;
const data = {
pageSize: 1,
pageCount: 100,
obj: {
'plateType': item.type,
'resourceType': 1
} }
})
this.slides.slideTo(index,500);
this.slideList[index] = arr;
} }
) this.tabsSer.stuffPage(data).subscribe(
} (res) => {
let arr = res.data;
arr.forEach(e => {
if (e.attachments.length > 0) {
e.imgUrl = e.attachments[0].path;
}
})
this.slides1.slideTo(index, 500);
this.slideList[index] = arr;
}
)
}
slideChange(e){ slideChange(e) {
const index = this.slides.getActiveIndex(); const index = this.slides1.getActiveIndex();
// console.log(this.tabsList[index]); this.change(this.tabsList[index])
// this.changeParent(this.tabsList[index]) }
}
// //判断是否scroll true 滑动 false 不滑动
goToDetail(item){} scroll(bool) {
this.isScroll = bool !== 'false';
console.log(this.isScroll)
}
//
goToDetail(item) {
}
} }
<div class="slides-content"> <div class="slides-content">
<ion-slides (ionSlideDidChange)="slideChange($event)" #slides *ngIf="slidersItems.length>0" pager <ion-slides (ionSlideDidChange)="slideChange($event)" #slides *ngIf="slidersItems.length>0" pager
loop="true" loop="true"
autoplay="2000" speed="1500"> autoplay="2000" speed="1500">
<ion-slide *ngFor="let item of slidersItems;"> <ion-slide *ngFor="let item of slidersItems;">
<img src="{{picture+item.imgUrl}}" class="slide-image" (click)="goToDetail(item)"> <img src="{{picture+item.imgUrl}}" class="slide-image" (click)="goToDetail(item)">
</ion-slide> </ion-slide>
</ion-slides> </ion-slides>
</div> </div>
<p class="slides-title">{{slideTitle}} <span class="main-color" float-end>1<span <p class="slides-title">
{{slideTitle}} <span class="main-color" float-end>1<span
style="font-size: 1.5rem;font-weight: 400;">/{{slidersItems.length}}</span></span></p> style="font-size: 1.5rem;font-weight: 400;">/{{slidersItems.length}}</span></span></p>
\ No newline at end of file
...@@ -12,6 +12,7 @@ import {SearchNewPage} from "../../home-pages/search-new/search-new"; ...@@ -12,6 +12,7 @@ import {SearchNewPage} from "../../home-pages/search-new/search-new";
import {StuffDetailPage} from "../../home-pages/stuff-detail/stuff-detail"; import {StuffDetailPage} from "../../home-pages/stuff-detail/stuff-detail";
import {EmitService} from "../../../provide/emit.service"; import {EmitService} from "../../../provide/emit.service";
import {DatePipe} from "@angular/common"; import {DatePipe} from "@angular/common";
import {SlideListComponent} from "../../../components/slide-list/slide-list";
@IonicPage() @IonicPage()
@Component({ @Component({
...@@ -61,7 +62,7 @@ export class HomePage { ...@@ -61,7 +62,7 @@ export class HomePage {
constructor(public navCtrl: NavController, public tts: TextToSpeech, public datePipe: DatePipe, constructor(public navCtrl: NavController, public tts: TextToSpeech, public datePipe: DatePipe,
public commonSer: CommonService, public emitSer: EmitService, public commonSer: CommonService, public emitSer: EmitService,
public zone: NgZone,public renderer:Renderer2, public zone: NgZone,public slideList:SlideListComponent,
public appService: AppService, public http: Http, public storage: Storage, public appService: AppService, public http: Http, public storage: Storage,
public badge: Badge, public tabsSer: TabsService) { public badge: Badge, public tabsSer: TabsService) {
// 接收发射过来的数据 // 接收发射过来的数据
...@@ -85,15 +86,17 @@ export class HomePage { ...@@ -85,15 +86,17 @@ export class HomePage {
this.getInfo(); this.getInfo();
this.scrollHeight(); this.scrollHeight();
} }
scrollHeight(){ scrollHeight(){
const height = this.topHeight.nativeElement.offsetHeight + 80; const height = this.topHeight.nativeElement.offsetHeight + 80;
this.content.ionScroll.subscribe(($event)=>{ this.content.ionScroll.subscribe(($event)=>{
this.zone.run(()=>{ this.zone.run(()=>{
// this.headerTag.nativeElement. // this.headerTag.nativeElement.
if(this.content.scrollTop > height){ if(this.content.scrollTop > height){
this.isScroll = true; this.slideList.scroll('true');
}else{ }else{
this.isScroll = false; this.slideList.scroll('false');
} }
this.content.resize(); this.content.resize();
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment