get-wxml-node-info.js 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: '获取WXML节点信息',
  5. path: 'packageAPI/pages/page/get-wxml-node-info/get-wxml-node-info'
  6. }
  7. },
  8. data: {
  9. theme: 'light',
  10. metrics: []
  11. },
  12. onReady() {
  13. this.getNodeInfo()
  14. },
  15. getNodeInfo() {
  16. const $ = wx.createSelectorQuery()
  17. const target = $.select('.target')
  18. target.boundingClientRect()
  19. $.exec((res) => {
  20. const rect = res[0]
  21. if (rect) {
  22. const metrics = []
  23. // eslint-disable-next-line
  24. for (const key in rect) {
  25. if (key !== 'id' && key !== 'dataset') {
  26. const val = rect[key]
  27. metrics.push({key, val})
  28. }
  29. }
  30. this.setData({metrics})
  31. }
  32. })
  33. },
  34. onLoad() {
  35. this.setData({
  36. theme: wx.getSystemInfoSync().theme || 'light'
  37. })
  38. if (wx.onThemeChange) {
  39. wx.onThemeChange(({theme}) => {
  40. this.setData({theme})
  41. })
  42. }
  43. }
  44. })