'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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const path = require('path')
 
const {
  removeExt,
  normalizePath,
  getPagesJson
} = require('@dcloudio/uni-cli-shared')
 
const {
  normalizeNodeModules
} = require('@dcloudio/webpack-uni-mp-loader/lib/shared')
 
const SCROLLER_COMPONENTS = [
  'list',
  'scroller',
  'scroll-view',
  'waterfall'
]
 
module.exports = function (content, map) {
  this.cacheable && this.cacheable()
  const source = content.trim()
 
  if (SCROLLER_COMPONENTS.find(name => source.indexOf('<' + name) === 0)) {
    return this.callback(null, content, map)
  }
  if (source.indexOf('<recycle-list') !== -1) {
    return this.callback(null, content, map)
  }
 
  let resourcePath = normalizeNodeModules(
    removeExt(normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)))
  )
 
  if (
    !process.UNI_NVUE_ENTRY[resourcePath] &&
    this._module.issuer &&
    this._module.issuer.issuer
  ) {
    // <template src=""/>
    resourcePath = normalizeNodeModules(
      removeExt(normalizePath(path.relative(process.env.UNI_INPUT_DIR, this._module.issuer.issuer.resource)))
    )
  }
 
  if (!process.UNI_NVUE_ENTRY[resourcePath]) {
    return this.callback(null, content, map)
  }
  // 暂时实时读取配置信息,查找是否 disableScroll
  const appJson = getPagesJson()
 
  let pageJson
  if (appJson.nvue) { // 旧版本
    if (!appJson.nvue || !appJson.nvue.pages) {
      return this.callback(null, content, map)
    }
    const pagePath = resourcePath + '.html'
    pageJson = appJson.nvue.pages.find(page => page.path === pagePath)
  } else {
    pageJson = appJson.pages.find(page => page.path === resourcePath)
  }
 
  if (!pageJson) {
    return this.callback(null, content, map)
  }
 
  if (!appJson.globalStyle) {
    appJson.globalStyle = {}
  }
 
  Object.assign(appJson.globalStyle, appJson.globalStyle['app-plus'] || {})
  pageJson.style = pageJson.style || {}
  Object.assign(pageJson.style, pageJson.style['app-plus'] || {})
  const pageJsonStyle = Object.assign(appJson.globalStyle, pageJson.style)
  if (pageJsonStyle.disableScroll === true) {
    return this.callback(null, content, map)
  }
 
  this.callback(null,
    `<scroll-view :scroll-y="true" :show-scrollbar="${pageJsonStyle.scrollIndicator === 'none' ? 'false' : 'true'}" :enableBackToTop="true" bubble="true" style="flex-direction:column">${content}</scroll-view>`,
    map)
}