message-analysis.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. interface Gallery {
  2. label?: string;
  3. src: string;
  4. }
  5. type Result = {
  6. thumbnail: Gallery[];
  7. source: (Gallery & { target: string; })[];
  8. }
  9. // module/chats/components/message-analysis/message-analysis.ts
  10. const defaultGallery = {
  11. 'tongueImgUrl': '',
  12. 'tongueBackImgUrl': '',
  13. 'faceImgUrl': '',
  14. }
  15. Component({
  16. properties: {
  17. payload: { type: Object, value: { title: '', description: '' } },
  18. active: { type: Boolean, value: false },
  19. messageType: { type: Number, value: 0 },
  20. },
  21. data: {
  22. isAnalysis: 0,
  23. examples: [
  24. { label: '舌面举例', src: '../../assets/tongue-1.png' },
  25. { label: '舌下举例', src: '../../assets/tongue-2.png' },
  26. { label: '面部举例', src: '../../assets/face-1.png' },
  27. ] as Gallery[],
  28. source: [] as Gallery[],
  29. },
  30. attached(){
  31. this.setData({
  32. isAnalysis: wx.getStorageSync("isAnalysis"),
  33. });
  34. },
  35. /**
  36. * 组件的方法列表
  37. */
  38. methods: {
  39. onConfirm() {
  40. if (this.data.source.length) return;
  41. wx.navigateTo({
  42. url: '/module/chats/pages/analysis/analysis?messageType=' + this.data.messageType,
  43. events: { update: (data: Result) => this._update(data) }
  44. });
  45. },
  46. onCancel() {
  47. this.triggerEvent('next', defaultGallery);
  48. },
  49. _update({source, thumbnail}:Result) {
  50. this.setData({ source: thumbnail });
  51. const data = {} as AnyObject;
  52. for (const item of source) { data[item.target] = item.src; }
  53. this.triggerEvent('next', {
  54. ...defaultGallery,
  55. ...data,
  56. });
  57. }
  58. }
  59. })