cnf
2025-05-10 386fa0eca75ddc88165f9b73038f2a2239e1072e
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const isDef = v => v !== undefined
module.exports = api => {
  api.describeConfig({
    id: 'dcloudio.uni-app',
    name: 'uni-app',
    description: '配置 uni-app 项目',
    link: 'https://uniapp.dcloud.io/',
    icon: '/_plugin/%40dcloudio%2Fvue-cli-plugin-uni/logo.png',
    files: {
      manifest: {
        json: ['src/manifest.json']
      }
    },
    onRead: ({
      data: {
        manifest: {
          name,
          h5 = {}
        }
      }
    }) => ({
      tabs: [{
        id: 'h5',
        label: 'h5',
        icon: '/_plugin/%40dcloudio%2Fvue-cli-plugin-uni/h5.png',
        prompts: [{
          name: 'title',
          type: 'input',
          default: '',
          value: name || h5.title,
          message: '应用名称',
          description: '应用的名称',
          group: '基础设置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5'
        }, {
          name: 'base',
          type: 'input',
          default: '/',
          value: h5.router && h5.router.base,
          message: 'Base Url',
          description: '应用的部署地址,如 \'/my-app/\'。如果留空,所有资源将使用相对路径。',
          group: '基础设置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5'
        }, {
          name: 'mode',
          type: 'list',
          default: 'hash',
          choices: [{
            name: 'hash',
            value: 'hash'
          },
          {
            name: 'history',
            value: 'history'
          }
          ],
          value: h5.router && h5.router.mode,
          message: '路由模式',
          description: '选择路由模式,history 模式需要服务器配置',
          group: '基础设置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5'
        },
        {
          name: 'loading',
          type: 'input',
          default: 'AsyncLoading',
          value: h5.async && h5.async.loading,
          message: '加载组件',
          description: '页面按需加载时显示的组件(需注册为全局组件)',
          group: '页面按需加载配置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5-async'
        },
        {
          name: 'error',
          type: 'input',
          default: 'AsyncError',
          value: h5.async && h5.async.error,
          message: '错误组件',
          description: '页面按需加载失败时显示的组件(需注册为全局组件)',
          group: '页面按需加载配置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5-async'
        },
        {
          name: 'delay',
          type: 'input',
          default: 200,
          value: h5.async && h5.async.delay,
          message: '延迟时间',
          description: '页面按需加载展示 loading 组件的延迟时间(页面 js 若在 delay 时间内加载完成,则不会显示 loading 组件)',
          group: '页面按需加载配置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5-async'
        },
        {
          name: 'timeout',
          type: 'input',
          default: 3000,
          value: h5.async && h5.async.timeout,
          message: '超时时间',
          description: '页面按需加载超时时间(超时后展示 error 对应的组件)',
          group: '页面按需加载配置',
          link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5-async'
        }
        ]
      }]
 
    }),
    onWrite: async ({
      api,
      prompts
    }) => {
      const h5 = {}
 
      const title = await api.getAnswer('title')
      if (isDef(title)) {
        h5.title = title
      }
 
      const base = await api.getAnswer('base')
      const mode = await api.getAnswer('mode')
      if (isDef(base) || isDef(mode)) {
        h5.router = {}
        if (isDef(base)) {
          h5.router.base = base
        }
        if (isDef(mode)) {
          h5.router.mode = mode
        }
      }
 
      const loading = await api.getAnswer('loading')
      const error = await api.getAnswer('error')
      const delay = await api.getAnswer('delay')
      const timeout = await api.getAnswer('timeout')
      if (isDef(loading) || isDef(error) || isDef(delay) || isDef(timeout)) {
        h5.async = {}
        if (isDef(loading)) {
          h5.async.loading = loading
        }
        if (isDef(error)) {
          h5.async.error = error
        }
        if (isDef(delay)) {
          h5.async.delay = delay
        }
        if (isDef(timeout)) {
          h5.async.timeout = timeout
        }
      }
 
      api.setData('manifest', {
        h5
      })
    }
  })
}