|
@@ -1,39 +1,30 @@
|
|
import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core';
|
|
import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { Router } from '@angular/router';
|
|
import * as Parse from "parse";
|
|
import * as Parse from "parse";
|
|
-
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-community',
|
|
selector: 'app-community',
|
|
templateUrl: './community.component.html',
|
|
templateUrl: './community.component.html',
|
|
styleUrls: ['./community.component.scss'],
|
|
styleUrls: ['./community.component.scss'],
|
|
-
|
|
|
|
})
|
|
})
|
|
export class CommunityComponent implements OnInit {
|
|
export class CommunityComponent implements OnInit {
|
|
-
|
|
|
|
scienceList: Array<Parse.Object> = [];
|
|
scienceList: Array<Parse.Object> = [];
|
|
recommendList: Array<Parse.Object> = [];
|
|
recommendList: Array<Parse.Object> = [];
|
|
attentionList: Array<Parse.Object> = [];
|
|
attentionList: Array<Parse.Object> = [];
|
|
-
|
|
|
|
startX: number = 0;
|
|
startX: number = 0;
|
|
currentX: number = 0;
|
|
currentX: number = 0;
|
|
isDragging: boolean = false;
|
|
isDragging: boolean = false;
|
|
minTranslateX: number = 0; // 最小平移距离
|
|
minTranslateX: number = 0; // 最小平移距离
|
|
maxTranslateX: number = 0;
|
|
maxTranslateX: number = 0;
|
|
-
|
|
|
|
@ViewChild('carousel', { static: true }) carousel!: ElementRef;
|
|
@ViewChild('carousel', { static: true }) carousel!: ElementRef;
|
|
-
|
|
|
|
cate: string = 'all';
|
|
cate: string = 'all';
|
|
-
|
|
|
|
constructor(private router: Router, private renderer: Renderer2) {
|
|
constructor(private router: Router, private renderer: Renderer2) {
|
|
this.initPage();
|
|
this.initPage();
|
|
}
|
|
}
|
|
-
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchstart', this.onTouchStart.bind(this));
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchstart', this.onTouchStart.bind(this));
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchmove', this.onTouchMove.bind(this));
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchmove', this.onTouchMove.bind(this));
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchend', this.onTouchEnd.bind(this));
|
|
this.renderer.listen(this.carousel.nativeElement, 'touchend', this.onTouchEnd.bind(this));
|
|
}
|
|
}
|
|
-
|
|
|
|
async initPage() {
|
|
async initPage() {
|
|
this.scienceList = await this.getScienceData();
|
|
this.scienceList = await this.getScienceData();
|
|
this.recommendList = await this.getRecommendData();
|
|
this.recommendList = await this.getRecommendData();
|
|
@@ -41,54 +32,45 @@ export class CommunityComponent implements OnInit {
|
|
// 设置最大最小平移距离
|
|
// 设置最大最小平移距离
|
|
this.maxTranslateX = this.carousel.nativeElement.offsetWidth - window.innerWidth;
|
|
this.maxTranslateX = this.carousel.nativeElement.offsetWidth - window.innerWidth;
|
|
}
|
|
}
|
|
-
|
|
|
|
async getScienceData() {
|
|
async getScienceData() {
|
|
- let query = new Parse.Query("PetScience");
|
|
|
|
|
|
+ let query = new Parse.Query("HrmScience");
|
|
let list = await query.find();
|
|
let list = await query.find();
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
-
|
|
|
|
async getRecommendData() {
|
|
async getRecommendData() {
|
|
- let query = new Parse.Query("PetRecommend");
|
|
|
|
|
|
+ let query = new Parse.Query("HrmRecommend");
|
|
let list = await query.find();
|
|
let list = await query.find();
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
-
|
|
|
|
async getAttentionData() {
|
|
async getAttentionData() {
|
|
let query = new Parse.Query("HrmAttention");
|
|
let query = new Parse.Query("HrmAttention");
|
|
let list = await query.find();
|
|
let list = await query.find();
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
-
|
|
|
|
goScienceDetail(science: Parse.Object) {
|
|
goScienceDetail(science: Parse.Object) {
|
|
this.router.navigate(["/lesson/community/scienceDetail"], {
|
|
this.router.navigate(["/lesson/community/scienceDetail"], {
|
|
queryParams: science
|
|
queryParams: science
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
goRecommendDetail(recommend: Parse.Object) {
|
|
goRecommendDetail(recommend: Parse.Object) {
|
|
this.router.navigate(["/lesson/community/recommendDetail"], {
|
|
this.router.navigate(["/lesson/community/recommendDetail"], {
|
|
queryParams: recommend
|
|
queryParams: recommend
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
goAttentionDetail(attention: Parse.Object) {
|
|
goAttentionDetail(attention: Parse.Object) {
|
|
this.router.navigate(["/lesson/community/attentionDetail"], {
|
|
this.router.navigate(["/lesson/community/attentionDetail"], {
|
|
queryParams: attention
|
|
queryParams: attention
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
onTouchStart(event: TouchEvent): void {
|
|
onTouchStart(event: TouchEvent): void {
|
|
this.startX = event.touches[0].clientX;
|
|
this.startX = event.touches[0].clientX;
|
|
this.isDragging = true;
|
|
this.isDragging = true;
|
|
}
|
|
}
|
|
-
|
|
|
|
onTouchMove(event: TouchEvent): void {
|
|
onTouchMove(event: TouchEvent): void {
|
|
if (this.carousel && this.isDragging) {
|
|
if (this.carousel && this.isDragging) {
|
|
const touch = event.touches[0];
|
|
const touch = event.touches[0];
|
|
const deltaX = touch.clientX - this.startX;
|
|
const deltaX = touch.clientX - this.startX;
|
|
this.currentX = this.currentX + deltaX;
|
|
this.currentX = this.currentX + deltaX;
|
|
-
|
|
|
|
// 限制平移范围在最大最小值之间
|
|
// 限制平移范围在最大最小值之间
|
|
this.currentX = Math.max(this.minTranslateX, Math.min(this.maxTranslateX, this.currentX));
|
|
this.currentX = Math.max(this.minTranslateX, Math.min(this.maxTranslateX, this.currentX));
|
|
|
|
|
|
@@ -96,7 +78,6 @@ export class CommunityComponent implements OnInit {
|
|
this.startX = touch.clientX;
|
|
this.startX = touch.clientX;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
onTouchEnd(): void {
|
|
onTouchEnd(): void {
|
|
this.isDragging = false;
|
|
this.isDragging = false;
|
|
}
|
|
}
|