'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const PLATFORMS = [
  'h5',
  'app-plus',
  'mp-weixin',
  'mp-qq',
  'mp-baidu',
  'mp-alipay',
  'mp-jd',
  'mp-xhs',
  'mp-toutiao',
  'quickapp-native'
]
 
const DISPLAY = {
  'navigationBarBackgroundColor': 'titleBarBackgroundColor',
  'navigationBarTextStyle': (style, val) => {
    if (val === 'black') {
      style.titleBarTextColor = '#000000'
      style.statusBarTextStyle = 'dark'
    } else {
      style.titleBarTextColor = '#ffffff'
      style.statusBarTextStyle = 'light'
    }
  },
  'navigationBarTitleText': 'titleBarText',
  'navigationStyle': (style, val) => {
    if (val === 'custom') {
      style.titleBar = false
    }
  }
}
 
function parseStyle(style = {}) {
  const ret = {}
  Object.keys(style).forEach(name => {
    if (!PLATFORMS.includes(name)) {
      const transform = DISPLAY[name]
      if (transform) {
        if (typeof transform === 'string') {
          ret[transform] = style[name]
        } else if (typeof transform === 'function') {
          transform(ret, style[name])
        }
      } else {
        ret[name] = style[name]
      }
    }
  })
  if (style['quickapp-native']) {
    Object.assign(ret, style['quickapp-native'])
  }
  return ret
}
 
module.exports = function parseDisplay(manifest, pages, globalStyle = {}) {
  const display = {
    pages: {}
  }
  // globalStyle
  Object.assign(display, parseStyle(globalStyle))
 
  pages.forEach(page => {
    const key = page.path.substr(0, page.path.lastIndexOf('/'))
    display.pages[key] = parseStyle(page.style)
  })
  manifest.display = display
}