analysis.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import I18nBehavior from "../../../../i18n/behavior";
  3. import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  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. I18nBehavior,
  11. PageContainerBehavior,
  12. TickleBehavior
  13. ],
  14. data: {
  15. i18n: {
  16. analysis: { title: '图片结果', date: '' },
  17. },
  18. id: '',
  19. tongue: null as unknown as AnalysisModel,
  20. face: null as unknown as AnalysisModel,
  21. dataset: null as unknown as AnyObject,
  22. switchType: "",
  23. },
  24. onLoad(query: any) {
  25. if (query.scene) {
  26. this.setData({ switchType: query.scene });
  27. wx.showLoading({ title: "加载中" });
  28. } else this._load(query);
  29. },
  30. load(event: AnyObject) { this._load(event.detail, false); },
  31. async _load(query: Record<'id' | 'scene', string>, loading = true) {
  32. if (loading) wx.showLoading({ title: '加载中' });
  33. try {
  34. const { tongue, face, ...dataset } = await healthAnalysisMethod(query);
  35. this.setData({ tongue, face, dataset });
  36. } catch (error) {
  37. getTickleContext.call(this).showErrorMessage(error.errMsg, 0);
  38. }
  39. wx.hideLoading();
  40. },
  41. toHomePage() { toHomePage(this.data.switchType as string); },
  42. openMessage(event: any) {
  43. const message = event?.detail?.content;
  44. if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
  45. }
  46. });