analysis.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  3. // module/health/pages/analysis/analysis.ts
  4. import { toHomePage } from "../../router";
  5. import { healthAnalysisMethod } from "../../request";
  6. import { AnalysisModel } from "../../model/health.model";
  7. Page({
  8. behaviors: [
  9. PageContainerBehavior,
  10. TickleBehavior
  11. ],
  12. data: {
  13. id: '',
  14. tongue: null as unknown as AnalysisModel,
  15. face: null as unknown as AnalysisModel,
  16. dataset: null as unknown as AnyObject,
  17. switchType: "",
  18. },
  19. onLoad(query: any) {
  20. if (query.scene) {
  21. this.setData({ switchType: query.scene });
  22. wx.showLoading({ title: "加载中" });
  23. } else this._load(query);
  24. },
  25. load(event: AnyObject) { this._load(event.detail, false); },
  26. async _load(query: Record<'id' | 'scene', string>, loading = true) {
  27. if (loading) wx.showLoading({ title: '加载中' });
  28. try {
  29. const { tongue, face, ...dataset } = await healthAnalysisMethod(query);
  30. this.setData({ tongue, face, dataset });
  31. } catch (error) {
  32. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  33. }
  34. wx.hideLoading();
  35. },
  36. toHomePage() { toHomePage(this.data.switchType as string); },
  37. openMessage(event: any) {
  38. const message = event?.detail?.content;
  39. if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
  40. }
  41. });