analysis.ts 1.6 KB

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