先吐槽一下, 有些特定需求是没有直接的 API 的, 必须自己来通过原 API 封装

直接用关键词在网上搜, 给出来的搜索结果真的大都是乱七八糟

目录 Index

  • screen 篇

screen 篇

官方 screen 文档

  • getCurrentDisplay 想要在多屏幕情况下, 获取当前屏幕

getCurrentDisplay 想要在多屏幕情况下, 获取当前屏幕

  1. /**
  2. * 主要是为了多屏幕情况下, 获取当前屏幕
  3. * { ds, x, y } = config
  4. * ds: Array<any> 由 screen.getAllDisplays() 获得
  5. * x: number 当前 x
  6. * y: number 当前 y
  7. */
  8. const getCurrentDisplay = (config) => {
  9. const { ds, x, y } = config;
  10. return ds.filter((d) => {
  11. const { bounds, size } = d;
  12. // bx <= x <= bx + bw && by <= y <= by + bh
  13. return bounds.x <= x && x <= bounds.x + size.width && bounds.y <= y && y <= bounds.y + size.height;
  14. })[0];
  15. };