zhangwei
2024-08-14 9d8994790fe403935ed46ad478f83ae110bb7a01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:16  3,营业执照号:91 51 0  13  1 3      320061  93  K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
/**
 * 获取屏幕的宽高
 */
 
let windowWidth = 0
let windowHeight = 0
uni.getSystemInfo({
  success(res) {
    windowWidth = res.windowWidth
    windowHeight = res.windowHeight
  }
})
 
const getSystemInfo = () => {
  return [ windowWidth, windowHeight ]
}
 
const bindInstance = () => {
  let instance = {}
 
  return {
    /**
     * 提供键名,绑定对象值
     */
    set: (bindName, data = null) => {
      if (!instance[bindName]) {
        instance[bindName] = data
      }
      return instance[bindName] || {}
    },
    get: (bindName) => {
      return instance[bindName] || {}
    },
    /**
     * 清除实例对象的所有缓存值
     */
    clear: () => {
      instance = {}
    },
    /**
     * 清楚实例对象特定的键
     */
    remove: (bindName) => {
      instance[bindName] && delete instance[bindName]
    }
  }
};
 
export default {
  getSystemInfo,
  cacheInstance: bindInstance(),
}