|
@@ -1,5 +1,9 @@
|
|
|
import { Component, AfterViewInit } from '@angular/core';
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { ModalController, NavController } from '@ionic/angular';
|
|
|
+import { HttpClient } from '@angular/common/http';
|
|
|
+import { Observable } from 'rxjs';
|
|
|
+import { map, catchError } from 'rxjs/operators';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab1',
|
|
@@ -61,8 +65,6 @@ export class Tab1Page implements AfterViewInit {
|
|
|
cardWidth = 216;
|
|
|
isCyclic: boolean = true;
|
|
|
|
|
|
- constructor(private router: Router) {}
|
|
|
-
|
|
|
ngAfterViewInit() {
|
|
|
this.updateCarousel();
|
|
|
this.calculateCardWidth();
|
|
@@ -93,7 +95,6 @@ export class Tab1Page implements AfterViewInit {
|
|
|
|
|
|
|
|
|
onTouchStart(event: TouchEvent) {
|
|
|
-
|
|
|
this.startX = event.touches[0].clientX;
|
|
|
this.isDragging = true;
|
|
|
}
|
|
@@ -101,7 +102,6 @@ export class Tab1Page implements AfterViewInit {
|
|
|
|
|
|
onTouchMove(event: TouchEvent) {
|
|
|
if (this.isDragging) {
|
|
|
-
|
|
|
const touchX = event.touches[0].clientX;
|
|
|
const deltaX = touchX - this.startX;
|
|
|
this.currentTranslate = -this.currentIndex * this.cardWidth + deltaX;
|
|
@@ -172,6 +172,18 @@ export class Tab1Page implements AfterViewInit {
|
|
|
this.currentIndex = Math.max(0, Math.min(cardIndex, this.doctors.length - 1));
|
|
|
this.updateCarousel();
|
|
|
}
|
|
|
+
|
|
|
+ onConsultNow() {
|
|
|
+ console.log(`立即咨询`);
|
|
|
+ this.router.navigate(['/consultation']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onlineConsultNow(doctor: any) {
|
|
|
+ console.log(`在线咨询: ${doctor.name}`);
|
|
|
+
|
|
|
+ this.router.navigate(['/consultation'], { state: { doctor: doctor } });
|
|
|
+ }
|
|
|
|
|
|
|
|
|
navigateTo(route: string) {
|
|
@@ -183,4 +195,100 @@ export class Tab1Page implements AfterViewInit {
|
|
|
|
|
|
console.log('发布求医信息');
|
|
|
}
|
|
|
+
|
|
|
+ isLoginModalOpen = false;
|
|
|
+ user = {
|
|
|
+ username: '',
|
|
|
+ password: ''
|
|
|
+ };
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private router: Router,
|
|
|
+ private modalController: ModalController,
|
|
|
+ private navCtrl: NavController,
|
|
|
+ private http: HttpClient
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ openLoginModal() {
|
|
|
+ this.isLoginModalOpen = true;
|
|
|
+ console.log('打开登录/注册模态框');
|
|
|
+ }
|
|
|
+
|
|
|
+ closeLoginModal() {
|
|
|
+ this.isLoginModalOpen = false;
|
|
|
+ console.log('关闭登录/注册模态框');
|
|
|
+ }
|
|
|
+
|
|
|
+ onLoginModalDismissed(event: any) {
|
|
|
+ this.isLoginModalOpen = false;
|
|
|
+ console.log('登录/注册模态框已关闭');
|
|
|
+ }
|
|
|
+
|
|
|
+ onLoginFormSubmit(formValue: any) {
|
|
|
+
|
|
|
+ console.log('登录表单提交:', formValue);
|
|
|
+
|
|
|
+
|
|
|
+ this.loginUser(formValue.username, formValue.password)
|
|
|
+ .subscribe(
|
|
|
+ (response) => {
|
|
|
+ console.log('登录成功:', response);
|
|
|
+
|
|
|
+ this.closeLoginModal();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error('登录失败:', error);
|
|
|
+
|
|
|
+ this.closeLoginModal();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ registerUser() {
|
|
|
+
|
|
|
+ console.log('注册用户:', this.user);
|
|
|
+
|
|
|
+
|
|
|
+ this.registerNewUser(this.user.username, this.user.password)
|
|
|
+ .subscribe(
|
|
|
+ (response) => {
|
|
|
+ console.log('注册成功:', response);
|
|
|
+
|
|
|
+ this.closeLoginModal();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error('注册失败:', error);
|
|
|
+
|
|
|
+ this.closeLoginModal();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private loginUser(username: string, password: string): Observable<any> {
|
|
|
+ const loginUrl = 'YOUR_API_ENDPOINT/login';
|
|
|
+ return this.http.post(loginUrl, { username, password })
|
|
|
+ .pipe(
|
|
|
+ map(response => response),
|
|
|
+ catchError(error => {
|
|
|
+ throw error;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private registerNewUser(username: string, password: string): Observable<any> {
|
|
|
+ const registerUrl = 'YOUR_API_ENDPOINT/register';
|
|
|
+ return this.http.post(registerUrl, { username, password })
|
|
|
+ .pipe(
|
|
|
+ map(response => response),
|
|
|
+ catchError(error => {
|
|
|
+ throw error;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onLearnMore() {
|
|
|
+
|
|
|
+ this.navCtrl.navigateForward('/details');
|
|
|
+ }
|
|
|
}
|