cc12458 1 год назад
Родитель
Сommit
5897aa64c4
1 измененных файлов с 217 добавлено и 205 удалено
  1. 217 205
      miniprogram/pages/home/home.ts

+ 217 - 205
miniprogram/pages/home/home.ts

@@ -9,25 +9,37 @@ const offset = shared(0);
 import { getPatients, healthReportMethod, healthIndexMethod, getSolarTerms, getShortScienceList } from "./request";
 import { toCertificationPage } from "./router";
 import { useLocation } from "../../lib/use/use-location";
-Component({
+
+Page({
   behaviors: [
     PageContainerBehavior,
     DraggableSheetBehavior('.draggable-sheet-wrapper'),
   ],
-  lifetimes: {
-    attached() {
-      this.initFabAnimated();
-    }
+  onLoad() {
+    wx.showShareMenu({
+      withShareTicket: true,
+      menus: ['shareAppMessage', 'shareTimeline']
+    });
+    this.initFabAnimated();
+  },
+  onShow() {
+    this.load();
   },
-  pageLifetimes: {
-    show() { this.load(); },
-    hide() {
-      offset.value = timing(0, { duration: 100, easing: (<any>Easing).linear }, () => { 'worklet' });
+  onHide() {
+    offset.value = timing(0, { duration: 100, easing: (<any>Easing).linear }, () => { 'worklet' });
+  },
+  onShareAppMessage(opts): WechatMiniprogram.Page.ICustomShareContent {
+    console.log(opts.target)
+    return {
+      title: `健康为基,从容赏生活之美`,
+      imageUrl: `https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg`,
+      path: `/pages/home/home`,
     }
   },
-  properties: {
-    patientId: { type: String, value: '' },
-    next: { type: String, value: '' },
+  onShareTimeline() {
+    return {
+      title: `健康为基,从容赏生活之美`, 
+    }
   },
   data: {
     patients: [] as (App.Patient.Model & { isDefault: 'Y' | 'N' })[],
@@ -48,214 +60,214 @@ Component({
 
     _loaded: false,
   },
-  observers: {
-    'patient'(model: { patientId: string, sex: 0 | 1 }) {
-      wx.setStorageSync('patientId', model.patientId);
-      this._getHealthReport();
-      this._getAbnormalHealthIndex();
-      const patientIcon = { 0: 'gender-male', 1: 'gender-female' }[model.sex];
-      const patientIconColor = { 0: '#0f40f5', 1: '#E560B3' }[model.sex];
-      this.setData({ patientIcon, patientIconColor })
-    },
-  },
-  methods: {
-    async load() {
-      await login();
-      wx.showLoading({ title: '加载中' });
-      const { patient } = await getPatients(/*this.data.patientId*/);
-      if (!patient) await toCertificationPage();
-      else this.setData({ patient });
-      wx.hideLoading();
+  async load() {
+    await login();
+    wx.showLoading({ title: '加载中' });
+    const { patient } = await getPatients(/*this.data.patientId*/);
+    if (!patient) await toCertificationPage();
+    else {
+      this.setData({ patient });
+      this.observerPatient(patient);
+    };
+    wx.hideLoading();
 
-      if (!this.data._loaded) {
-        this.loadScienceList();
-        useLocation().then((location) => { this.setData({ location }) }).catch(()=>{});
-        getSolarTerms().then((solarTerms) => { this.setData({ solarTerms }) }).catch(()=>{});
-        this.setData({ _loaded: true });
-      }
-    },
-
-    async _getHealthReport() {
-      wx.showLoading({ title: '加载中' });
-      this.setData({ 'healthReport.loading': true, })
-      try {
-        const data = await healthReportMethod();
-        this.setData({
-          'healthReport.data': data,
-          'healthReport.loading': false,
-          healthId: data?.healthAnalysisReportId,
-        });
-      } catch (error) {
-        this.setData({
-          'healthReport.data': [],
-          'healthReport.loading': false,
-          'healthReport.message': error.errMsg,
-          healthId: '',
-        });
-      }
-      wx.hideLoading();
-    },
-    async _getAbnormalHealthIndex() {
-      this.setData({ 'healthIndex.loading': true, })
-      try {
-        const data = await healthIndexMethod();
-        this.setData({
-          'healthIndex.data': data.map((item: AnyObject) => item.abnormalDesc).filter(Boolean),
-          'healthIndex.loading': false,
-        });
-      } catch (error) {
-        this.setData({
-          'healthIndex.data': [],
-          'healthIndex.loading': false,
-          'healthIndex.message': error.errMsg,
-        });
-      }
-    },
-    onBodyModel(event: WechatMiniprogram.TouchEvent) {
-      if (event.detail?.position === 'LB') { this.toReportPage(); }
-      else if (event.detail?.position === 'LT') {
-        const report = this.data.healthReport.data as unknown as AnyObject;
-        this.setData({
-          position: {
-            LT: ['willillState', 'willillDegree', 'willillSocial', 'willillFunction'].map(key => {
-              const title = report[`${key}Name`]
-              const description = report[`${key}Description`]
-              return title || description ? { title, description } : null
-            }).filter(Boolean)
-          },
-        });
-        this.showDraggableSheet();
-      }
-      else if (event.detail?.position === 'RT') {
-        const report = this.data.healthReport.data as unknown as AnyObject;
-        const get = (key: string) => ({ [key]: report[key] })
-        this.setData({
-          position: {
-            RT: {
-              ...get('constitutionGroupName'),
-              ...get('constitutionGroupDefinition'),
-              ...get('faceImg'),
-              ...get('faceAnalysisResult'),
-              ...get('tongueAnalysisResult'),
-              ...get('upImg'),
-              ...get('downImg'),
-            }
-          },
-        });
-        this.showDraggableSheet();
-      }
-      else if (event.detail?.position === 'RB') {
-        const report = this.data.healthReport.data as unknown as AnyObject;
-        const get = (key: string) => ({ [key]: report[key] })
-        this.setData({
-          position: {
-            RB: {
-              ...get('diagnoseSyndromeSummary'),
-              ...get('diagnoseSyndromes'),
-              ...get('factorItemSummary'),
-              ...get('factorItems'),
-            }
-          },
-        });
-        this.showDraggableSheet();
-      }
-      else if (event.detail?.position === 'CT') {
-        this.setData({
-          position: { CT: this.data.healthIndex.data.map((item, index) => `${index + 1}、${item}`) }
-        });
-        this.showDraggableSheet();
-      }
-    },
+    if (!this.data._loaded) {
+      this.loadScienceList();
+      useLocation().then((location) => { this.setData({ location }) }).catch(() => { });
+      getSolarTerms().then((solarTerms) => { this.setData({ solarTerms }) }).catch(() => { });
+      this.setData({ _loaded: true });
+    }
+  },
 
-    initFabAnimated() {
-      (<any>this).applyAnimatedStyle('.fab-wrapper', () => {
-        'worklet'
-        return { right: `${Math.min(offset.value, 36) - 36}px` };
+  async _getHealthReport() {
+    wx.showLoading({ title: '加载中' });
+    this.setData({ 'healthReport.loading': true, })
+    try {
+      const data = await healthReportMethod();
+      this.setData({
+        'healthReport.data': data,
+        'healthReport.loading': false,
+        healthId: data?.healthAnalysisReportId,
+      });
+    } catch (error) {
+      this.setData({
+        'healthReport.data': [],
+        'healthReport.loading': false,
+        'healthReport.message': error.errMsg,
+        healthId: '',
+      });
+    }
+    wx.hideLoading();
+  },
+  async _getAbnormalHealthIndex() {
+    this.setData({ 'healthIndex.loading': true, })
+    try {
+      const data = await healthIndexMethod();
+      this.setData({
+        'healthIndex.data': data.map((item: AnyObject) => item.abnormalDesc).filter(Boolean),
+        'healthIndex.loading': false,
       });
-      (<any>this).applyAnimatedStyle('.fab-1', () => {
-        'worklet'
-        return { transform: `translateY(${-offset.value}px)` };
+    } catch (error) {
+      this.setData({
+        'healthIndex.data': [],
+        'healthIndex.loading': false,
+        'healthIndex.message': error.errMsg,
       });
-      (<any>this).applyAnimatedStyle('.fab-2', () => {
-        'worklet'
-        return { transform: `translateX(${-offset.value}px) translateY(${-offset.value / 2}px)` };
+    }
+  },
+  onBodyModel(event: WechatMiniprogram.TouchEvent) {
+    if (event.detail?.position === 'LB') { this.toReportPage(); }
+    else if (event.detail?.position === 'LT') {
+      const report = this.data.healthReport.data as unknown as AnyObject;
+      this.setData({
+        position: {
+          LT: ['willillState', 'willillDegree', 'willillSocial', 'willillFunction'].map(key => {
+            const title = report[`${key}Name`]
+            const description = report[`${key}Description`]
+            return title || description ? { title, description } : null
+          }).filter(Boolean)
+        },
       });
-      (<any>this).applyAnimatedStyle('.fab-3', () => {
-        'worklet'
-        return { transform: `translateX(${-offset.value}px) translateY(${offset.value / 2}px)` };
+      this.showDraggableSheet();
+    }
+    else if (event.detail?.position === 'RT') {
+      const report = this.data.healthReport.data as unknown as AnyObject;
+      const get = (key: string) => ({ [key]: report[key] })
+      this.setData({
+        position: {
+          RT: {
+            ...get('constitutionGroupName'),
+            ...get('constitutionGroupDefinition'),
+            ...get('faceImg'),
+            ...get('faceAnalysisResult'),
+            ...get('tongueAnalysisResult'),
+            ...get('upImg'),
+            ...get('downImg'),
+          }
+        },
       });
-      (<any>this).applyAnimatedStyle('.fab-4', () => {
-        'worklet'
-        return { transform: `translateY(${offset.value}px)` };
+      this.showDraggableSheet();
+    }
+    else if (event.detail?.position === 'RB') {
+      const report = this.data.healthReport.data as unknown as AnyObject;
+      const get = (key: string) => ({ [key]: report[key] })
+      this.setData({
+        position: {
+          RB: {
+            ...get('diagnoseSyndromeSummary'),
+            ...get('diagnoseSyndromes'),
+            ...get('factorItemSummary'),
+            ...get('factorItems'),
+          }
+        },
       });
-    },
-    onFabTap() {
-      const value = Math.abs(offset.value - 72);
-      offset.value = timing(value, { duration: 500, easing: (<any>Easing).linear }, () => {
-        'worklet'
-        if (offset.value > 0) offset.value = 72
-      })
-    },
-    toChatsPage() {
-      wx.navigateTo({ url: `/module/chats/pages/index/index` })
-    },
-    toHealthPage() {
-      wx.navigateTo({ url: `/module/health/pages/home/home` })
-    },
-    toDietTonicPage() {
-      wx.navigateTo({ url: `/module/article/pages/diet-list/diet-list?classify=tonic` })
-    },
-    toDietTeaPage() {
-      wx.navigateTo({ url: `/module/article/pages/diet-list/diet-list?classify=tea` })
-    },
-    toSciencePage() {
-      wx.navigateTo({ url: `/module/article/pages/science-list/science-list` })
-    },
-    toSchemePage() {
-      const id = this.data.healthId;
-      if (id) wx.navigateTo({ url: `/module/health/pages/scheme/scheme?id=${id}` })
-      else wx.showToast({ title: '暂无调理方案', icon: 'none' });
-    },
-    toReportPage() {
-      const id = this.data.healthId;
-      if (id) wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` })
-      else wx.showToast({ title: '暂无分析报告', icon: 'none' });
-    },
-    onDraggableSizeUpdate(e) {
+      this.showDraggableSheet();
+    }
+    else if (event.detail?.position === 'CT') {
+      this.setData({
+        position: { CT: this.data.healthIndex.data.map((item, index) => `${index + 1}、${item}`) }
+      });
+      this.showDraggableSheet();
+    }
+  },
+
+  initFabAnimated() {
+    (<any>this).applyAnimatedStyle('.fab-wrapper', () => {
       'worklet'
-      if (e.pixels < 1) {
-        wx.worklet.runOnJS(this.hideDraggableSheet.bind(this))()
-      }
-    },
-    showDraggableSheet() {
+      return { right: `${Math.min(offset.value, 36) - 36}px` };
+    });
+    (<any>this).applyAnimatedStyle('.fab-1', () => {
+      'worklet'
+      return { transform: `translateY(${-offset.value}px)` };
+    });
+    (<any>this).applyAnimatedStyle('.fab-2', () => {
+      'worklet'
+      return { transform: `translateX(${-offset.value}px) translateY(${-offset.value / 2}px)` };
+    });
+    (<any>this).applyAnimatedStyle('.fab-3', () => {
+      'worklet'
+      return { transform: `translateX(${-offset.value}px) translateY(${offset.value / 2}px)` };
+    });
+    (<any>this).applyAnimatedStyle('.fab-4', () => {
+      'worklet'
+      return { transform: `translateY(${offset.value}px)` };
+    });
+  },
+  onFabTap() {
+    const value = Math.abs(offset.value - 72);
+    offset.value = timing(value, { duration: 500, easing: (<any>Easing).linear }, () => {
+      'worklet'
+      if (offset.value > 0) offset.value = 72
+    })
+  },
+  toChatsPage() {
+    wx.navigateTo({ url: `/module/chats/pages/index/index` })
+  },
+  toHealthPage() {
+    wx.navigateTo({ url: `/module/health/pages/home/home` })
+  },
+  toDietTonicPage() {
+    wx.navigateTo({ url: `/module/article/pages/diet-list/diet-list?classify=tonic` })
+  },
+  toDietTeaPage() {
+    wx.navigateTo({ url: `/module/article/pages/diet-list/diet-list?classify=tea` })
+  },
+  toSciencePage() {
+    wx.navigateTo({ url: `/module/article/pages/science-list/science-list` })
+  },
+  toSchemePage() {
+    const id = this.data.healthId;
+    if (id) wx.navigateTo({ url: `/module/health/pages/scheme/scheme?id=${id}` })
+    else wx.showToast({ title: '暂无调理方案', icon: 'none' });
+  },
+  toReportPage() {
+    const id = this.data.healthId;
+    if (id) wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` })
+    else wx.showToast({ title: '暂无分析报告', icon: 'none' });
+  },
+  onDraggableSizeUpdate(e) {
+    'worklet'
+    if (e.pixels < 1) {
+      wx.worklet.runOnJS(this.hideDraggableSheet.bind(this))()
+    }
+  },
+  showDraggableSheet() {
+    getDraggableSheetContext.call(this).scrollTo({
+      size: 0.5,
+      pixels: 600,
+      animated: true,
+      duration: 300,
+      easingFunction: 'ease'
+    });
+    this.setData({ sheet: true });
+  },
+  hideDraggableSheet(event?: any) {
+    if (event) {
       getDraggableSheetContext.call(this).scrollTo({
-        size: 0.5,
-        pixels: 600,
+        size: 0,
         animated: true,
         duration: 300,
         easingFunction: 'ease'
       });
-      this.setData({ sheet: true });
-    },
-    hideDraggableSheet(event?: any) {
-      if (event) {
-        getDraggableSheetContext.call(this).scrollTo({
-          size: 0,
-          animated: true,
-          duration: 300,
-          easingFunction: 'ease'
-        });
-      }
-      this.setData({ position: {}, sheet: false })
-    },
+    }
+    this.setData({ position: {}, sheet: false })
+  },
 
-    async loadScienceList() {
-      try {
-        const { data } = await getShortScienceList();
-        this.setData({ scienceList: data })
-      } catch (error) {
+  async loadScienceList() {
+    try {
+      const { data } = await getShortScienceList();
+      this.setData({ scienceList: data })
+    } catch (error) {
 
-      }
     }
   },
+
+  observerPatient(model: { patientId: string, sex: 0 | 1 }) {
+    wx.setStorageSync('patientId', model.patientId);
+    this._getHealthReport();
+    this._getAbnormalHealthIndex();
+    const patientIcon = { 0: 'gender-male', 1: 'gender-female' }[model.sex];
+    const patientIconColor = { 0: '#0f40f5', 1: '#E560B3' }[model.sex];
+    this.setData({ patientIcon, patientIconColor })
+  },
 })