浏览代码

connected to the drug database

yf 4 月之前
父节点
当前提交
d957c19f84

+ 16 - 14
wisdom-app/src/app/tab3/tab3.page.html

@@ -1,3 +1,5 @@
+<!-- tab3.page.html -->
+
 <ion-header [translucent]="true">
   <ion-toolbar class="custom-toolbar">
     <ion-title class="custom-title">
@@ -18,7 +20,7 @@
       <ion-grid>
         <ion-row class="category-row">
           <ion-col size="3" *ngFor="let category of categories" class="category-col">
-            <div class="category-item">
+            <div class="category-item" (click)="onCategoryClick(category)">
               <div class="category-image-wrapper">
                 <img [src]="category.image" alt="{{category.name}}" class="category-image">
               </div>
@@ -35,15 +37,15 @@
     <ng-container *ngFor="let product of products">
       <ion-card class="product-card" (click)="openDetailModal(product)">
         <ion-card-header class="product-card-header">
-          <div class="product-tag">{{product.title}}</div>
+          <div class="product-tag">{{ product.get('title') || '热销🔥🔥🔥' }}</div>
         </ion-card-header>
         <ion-card-content class="product-card-content">
           <div class="product-image-wrapper">
-            <img [src]="product.image" alt="{{product.name}}" class="product-image">
+            <img [src]="product.get('image')" alt="{{product.get('name')}}" class="product-image">
           </div>
           <div class="product-info">
-            <h3 class="product-name">{{product.name}}</h3>
-            <div class="product-price">{{product.price}}</div>
+            <h3 class="product-name">{{ product.get('name') }}</h3>
+            <div class="product-price">{{ product.get('price') }}</div>
           </div>
         </ion-card-content>
       </ion-card>
@@ -66,16 +68,16 @@
     <ion-content>
       <div class="modal-content" *ngIf="currentProduct">
         <div class="image-container">
-          <img [src]="currentProduct.image" alt="药品图片" class="medicine-image">
+          <img [src]="currentProduct.get('image')" alt="药品图片" class="medicine-image">
         </div>
-        <h2 class="product-name">{{currentProduct.name}}</h2>
-        <p><strong>价格:</strong>{{currentProduct.price}}</p>
-        <p><strong>是否处方药:</strong>{{currentProduct.prescription ? '是' : '否'}}</p>
-        <p><strong>用法用量:</strong>{{currentProduct.usage}}</p>
-        <p><strong>主治功能:</strong>{{currentProduct.function}}</p>
-        <p><strong>规格:</strong>{{currentProduct.spec}}</p>
-        <p><strong>成分:</strong>{{currentProduct.composition}}</p>
-        <p><strong>禁忌:</strong>{{currentProduct.taboo}}</p>
+        <h2 class="product-name">{{ currentProduct.get('name') }}</h2>
+        <p><strong>价格:</strong>{{ currentProduct.get('price') }}</p>
+        <p><strong>是否处方药:</strong>{{ currentProduct.get('prescription') ? '是' : '否' }}</p>
+        <p><strong>用法用量:</strong>{{ currentProduct.get('usage') }}</p>
+        <p><strong>主治功能:</strong>{{ currentProduct.get('function') }}</p>
+        <p><strong>规格:</strong>{{ currentProduct.get('spec') }}</p>
+        <p><strong>成分:</strong>{{ currentProduct.get('composition') }}</p>
+        <p><strong>禁忌:</strong>{{ currentProduct.get('taboo') }}</p>
       </div>
     </ion-content>
   </ion-modal>

+ 63 - 53
wisdom-app/src/app/tab3/tab3.page.ts

@@ -1,11 +1,15 @@
 import { Component } from '@angular/core';
-import { Router } from '@angular/router';
-import { IonHeader, IonToolbar, IonTitle, IonContent, ModalController, IonButton, IonGrid, IonCol, IonCardHeader, IonLabel, IonThumbnail, IonCardContent, IonCardTitle, IonCard, IonIcon, IonSearchbar, IonModal, IonButtons } from '@ionic/angular/standalone';
+import { ModalController, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonAvatar, IonButton, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonIcon, IonButtons, IonGrid, IonRow, IonThumbnail, IonSearchbar, IonCol } from '@ionic/angular/standalone';
 import { ExploreContainerComponent } from '../explore-container/explore-container.component';
-import { FmChatModalInput } from 'fmode-ng';
-import { IonRow, IonItem } from '@ionic/angular/standalone';
-import { CommonModule } from '@angular/common';
+import { addIcons } from 'ionicons';
+import { airplane, bluetooth, call, wifi, close } from 'ionicons/icons';
 import { SaleCardComponent } from '../component/sale-card/sale-card.component';
+import { CommonModule } from '@angular/common';
+import { CloudObject, CloudQuery } from 'src/lib/ncloud';
+import { Router } from '@angular/router';
+import { FmChatModalInput } from 'fmode-ng';
+
+addIcons({ airplane, bluetooth, call, wifi });
 
 @Component({
   selector: 'app-tab3',
@@ -19,16 +23,10 @@ import { SaleCardComponent } from '../component/sale-card/sale-card.component';
     FmChatModalInput, IonModal, IonButtons
   ]
 })
-
 export class Tab3Page {
   showDetailModal = false;  // 控制模态显示与否
   currentProduct: any;      // 当前选择的商品信息
 
-  constructor(
-    private modalCtrl:ModalController,
-    private router:Router,
-  ) {}
-
   categories = [
     { name: '皮肤用药', image: '../../assets/image/doctor7.png' },
     { name: '妇科用药', image: '../../assets/image/doctor7.png' },
@@ -39,48 +37,29 @@ export class Tab3Page {
     { name: '耳鼻咽喉', image: '../../assets/image/doctor7.png' },
     { name: '男科用药', image: '../../assets/image/doctor7.png' },
   ];
-  
-  products = [
-    { 
-      title: '热销🔥🔥🔥', 
-      subtitle: '药品', 
-      name: '藿香正气水', 
-      price: '¥120', 
-      image: '../../assets/image/doctor7.png',
-      prescription: false, 
-      usage: '口服,每次5-10毫升,每天2次', 
-      function: '解表化湿,理气和中。',
-      spec: '10ml*10支/盒', 
-      composition: '藿香、紫苏叶、白芷、法半夏、厚朴等',
-      taboo: '孕妇慎用'
-    },
-    { 
-      title: '特价💰💰💰', 
-      subtitle: '药品', 
-      name: '知柏地黄丸', 
-      price: '¥200', 
-      image: '../../assets/image/doctor7.png',
-      prescription: true,
-      usage: '口服,一次6克,一日2次',
-      function: '滋阴清热,用于阴虚火旺所致的潮热盗汗。',
-      spec: '9g*10丸/盒',
-      composition: '知母、黄柏、熟地黄、山药等',
-      taboo: '孕妇、严重肝肾功能不全者慎用'
-    },
-    { 
-      title: '特价💰💰💰', 
-      subtitle: '药品', 
-      name: '知柏地黄丸', 
-      price: '¥200', 
-      image: '../../assets/image/doctor7.png',
-      prescription: true,
-      usage: '口服,一次6克,一日2次',
-      function: '滋阴清热,用于阴虚火旺所致的潮热盗汗。',
-      spec: '9g*10丸/盒',
-      composition: '知母、黄柏、熟地黄、山药等',
-      taboo: '孕妇、严重肝肾功能不全者慎用'
-    },
-  ];
+
+  products: Array<CloudObject> = [];
+  allProducts: Array<CloudObject> = []; // 存储所有药品数据,用于分类过滤
+
+  constructor(
+    private modalCtrl: ModalController,
+    private router: Router,
+  ) {
+      addIcons({close}); }
+
+  async ngOnInit() {
+    await this.loadProducts();
+  }
+
+  async loadProducts() {
+    try {
+      const query = new CloudQuery('Drug');
+      this.products = await query.find();
+      this.allProducts = [...this.products]; // 初始化所有产品
+    } catch (error) {
+      console.error('加载药品数据失败', error);
+    }
+  }
 
   openDetailModal(product: any) {
     this.currentProduct = product;
@@ -91,4 +70,35 @@ export class Tab3Page {
     this.showDetailModal = false;
     this.currentProduct = null;
   }
+
+  // 根据分类过滤产品
+  filterProducts(categoryName: string) {
+    if (categoryName === '全部') {
+      this.products = [...this.allProducts];
+    } else {
+      this.products = this.allProducts.filter(product => product.get('category') === categoryName);
+    }
+  }
+
+  // 分类点击事件
+  onCategoryClick(category: any) {
+    this.filterProducts(category.name);
+  }
+
+  // 分享链接功能(可选)
+  shareDetailModal() {
+    // 实现分享功能
+    console.log('分享功能待实现');
+  }
+
+  // 复制链接功能
+  copyLink() {
+    const link = window.location.href;
+    navigator.clipboard.writeText(link).then(() => {
+      console.log('链接已复制');
+      // 可添加用户提示
+    }).catch(err => {
+      console.error('复制失败', err);
+    });
+  }
 }

+ 1 - 1
wisdom-server/lib/ncloud.js

@@ -47,7 +47,7 @@ class CloudObject{
           if(result?.objectId){this.id = result?.objectId}
           return this
     }
-    async destory(){
+    async destroy(){
         if(!this.id) return
         let response = await fetch("http://dev.fmode.cn:1337/parse/classes/"+this.className+"/"+this.id, {
             "headers": {

+ 37 - 2
wisdom-server/migration/data.js

@@ -421,5 +421,40 @@ module.exports.HotDotList = [
 ]
 
 module.exports.DrugList = [
-  
-]
+  {
+      "objectId": "drug001",
+      "name": "头孢克肟片",
+      "price": "¥50",
+      "image": "https://img0.baidu.com/it/u=4236046589,3116401473&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
+      "prescription": true,
+      "usage": "口服,每次1片,每日3次",
+      "function": "抗菌消炎,用于敏感菌引起的感染",
+      "spec": "0.25g*10片/盒",
+      "composition": "头孢克肟",
+      "taboo": "对头孢菌素过敏者禁用"
+  },
+  {
+      "objectId": "drug002",
+      "name": "布洛芬缓释胶囊",
+      "price": "¥80",
+      "image": "http://t14.baidu.com/it/u=775392130,3619143306&fm=224&app=112&f=JPEG?w=500&h=500",
+      "prescription": false,
+      "usage": "口服,每次1粒,每日2次",
+      "function": "解热镇痛,用于轻至中度疼痛",
+      "spec": "200mg*10粒/盒",
+      "composition": "布洛芬",
+      "taboo": "孕妇、哺乳期妇女慎用"
+  },
+  {
+      "objectId": "drug003",
+      "name": "氯雷他定片",
+      "price": "¥30",
+      "image": "https://drug-platform.cdn.bcebos.com/drug-platform/online/drug/d1708155468458393265.jpg?x-bce-process=image/auto-orient,o_1/resize,w_1242,limit_1/quality,Q_85/format,f_auto",
+      "prescription": false,
+      "usage": "口服,每次1片,每日1次",
+      "function": "抗过敏,用于缓解鼻炎症状",
+      "spec": "10mg*10片/盒",
+      "composition": "氯雷他定",
+      "taboo": "对本品成分过敏者禁用"
+  },
+];

+ 53 - 53
wisdom-server/migration/import-data.js

@@ -1,73 +1,73 @@
+// import-data.js
+
 const { CloudQuery, CloudObject } = require("../lib/ncloud");
-const { DepartList, DoctorList, HotDotList,DrugList} = require("./data");
-inportDapartAndDoctor()
+const { DepartList, DoctorList, HotDotList, DrugList } = require("./data");
+inportDapartAndDoctor();
 
 DataMap = {
-    Doctor:{},
-    Department:{},
-    HotDot:{},
-    Drug:{},
-}
-
-async function inportDapartAndDoctor(){
-    // // 导入科室数据
-    // let departList = DepartList
-    // for (let index = 0; index < departList.length; index++) {
-    //     let depart = departList[index];
-    //     depart = await importObject("Department",depart)
-    // }
-
-    // // 导入医生数据
-    // let doctorList = DoctorList
-    // for (let index = 0; index < doctorList.length; index++) {
-    //     let doctor = doctorList[index];
-    //     doctor = await importObject("Doctor",doctor)
-    // }
-
-    // 导入热点数据
-    // let hotDotList = HotDotList
-    // for (let index = 0; index < hotDotList.length; index++) {
-    //     let hotDot = hotDotList[index];
-    //     hotDot = await importObject("HotDot",hotDot)
-    // }
-    // let query = new CloudQuery('HotDot');
-    // query.equalTo('category', 'HotDot');
-    // console.log(await query.find())
+    Doctor: {},
+    Department: {},
+    HotDot: {},
+    Drug: {},
+};
 
+async function inportDapartAndDoctor() {
     // 导入药品数据
-    let drugList = DrugList
+    let drugList = DrugList;
     for (let index = 0; index < drugList.length; index++) {
         let drug = drugList[index];
-        drug = await importObject("Drug",drug)
+        drug = await importObject("Drug", drug);
     }
 
-    // console.log(DataMap["Doctor"])
-}
+    // 如果需要导入其他数据(科室、医生、热点),可以取消注释以下代码
+    /*
+    // 导入科室数据
+    let departList = DepartList;
+    for (let index = 0; index < departList.length; index++) {
+        let depart = departList[index];
+        depart = await importObject("Department", depart);
+    }
+
+    // 导入医生数据
+    let doctorList = DoctorList;
+    for (let index = 0; index < doctorList.length; index++) {
+        let doctor = doctorList[index];
+        doctor = await importObject("Doctor", doctor);
+    }
 
-async function importObject(className,data){
+    // 导入热点数据
+    let hotDotList = HotDotList;
+    for (let index = 0; index < hotDotList.length; index++) {
+        let hotDot = hotDotList[index];
+        hotDot = await importObject("HotDot", hotDot);
+    }
+    */
+    console.log("药品数据导入完成");
+}
 
+async function importObject(className, data) {
     // 查重 srcId 数据源列表中的objectId并非数据库生成的唯一ID,因此需要有一个srcId字段进行记录,并查重
-    let query = new CloudQuery(className)
-    let srcId = data.objectId
-    query.equalTo("srcId",srcId)
-    let importObj = await query.first()
-    console.log(importObj)
+    let query = new CloudQuery(className);
+    let srcId = data.objectId;
+    query.equalTo("srcId", srcId);
+    let importObj = await query.first();
+    console.log(importObj);
 
-    // 导入
     // 导入前批量处理Pointer类型数据,进行重定向
-    Object.keys(data)?.forEach(key=>{
-        let field = data[key]
-        let srcId = field?.objectId
-        if(srcId){ // 是数组字段
-            if(key=="depart"){
-                data[key] = DataMap?.["Department"]?.[srcId]?.toPointer();
+    Object.keys(data)?.forEach(key => {
+        let field = data[key];
+        let srcId = field?.objectId;
+        if (srcId) { // 是 Pointer 类型字段
+            if (key === "depart") {
+                data[key] = DataMap["Department"]?.[srcId]?.toPointer();
             }
+            // 如果有其他 Pointer 类型的字段,可以在这里处理
         }
-    })
+    });
 
     // 若未添加,则创建新对象并保存
-    if(!importObj?.id){
-        importObj = new CloudObject(className)
+    if (!importObj?.id) {
+        importObj = new CloudObject(className);
     }
 
     // 保存或更新数据
@@ -75,5 +75,5 @@ async function importObject(className,data){
     importObj.set(data);
     importObj = await importObj.save();
 
-    DataMap[className][srcId] = importObj
+    DataMap[className][srcId] = importObj;
 }