# 配置

## 全局配置

### **app.json**

小程序根目录下的 `app.json` 文件用来对微信小程序进行全局配置，决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。

#### entryPagePath <a href="#entrypagepath" id="entrypagepath"></a>

指定小程序的默认启动路径（首页），常见情景是从微信聊天列表页下拉启动、小程序列表启动等。如果不填，将默认为 `pages` 列表的第一项。不支持带页面路径参数。

```
{
  "entryPagePath": "pages/index/index"
}
```

**pages**

```
{
  "pages": ["pages/index/index", "pages/logs/logs"]
}
```

#### window <a href="#window" id="window"></a>

用于设置小程序的状态栏、导航条、标题、窗口背景色。

![](/files/-MFfTcquvF7xOMkbxBXj)

* **navigationBarBackgroundColor** 导航栏背景颜色
* **navigationBarTextStyle** 导航栏标题颜色 两个参数“black”和“white”
* **navigationBarTitleText** 导航栏标题文字内容
* **navigationStyle** 导航栏样式仅支持default和custom
* **backgroundColor** #ffffff
* **backgroundTextStyle**  下拉 loading 的样式，仅支持 `dark` / `light`
* **backgroundColorTop** 顶部窗口的背景色，仅 iOS 支持
* **backgroundColorBottom** 底部窗口的背景色，仅 iOS 支持
* **onReachBottomDistance**
* **enablePullDownRefresh** 页面刷新，true or false
* **pageOrientation** 页面旋转，拥有参数auto/portrait/landscape，其中auto是跟随系统旋转，landscape是固定横屏，portrait是固定竖屏，如果要支持ipad，则需要是使用如下的命令：

```
{
  "resizable": true
}
```

**tap**

如果小程序是一个多 tab 应用（客户端窗口的底部或顶部有 tab 栏可以切换页面），可以通过 tabBar 配置项指定 tab 栏的表现，以及 tab 切换时显示的对应页面。

&#x20;其中 list 接受一个数组，**只能配置最少 2 个、最多 5 个 tab**。tab 按数组的顺序排序，每个项都是一个对象，其属性值如下：

![](/files/-MFhjuZKNgV7eSQwb7FJ)

#### networkTimeout <a href="#networktimeout" id="networktimeout"></a>

各类网络请求的超时时间，单位均为毫秒。

### app.wxss

### app.js

#### App(Object object) <a href="#app-object-object" id="app-object-object"></a>

注册小程序。接受一个 `Object` 参数，其指定小程序的生命周期回调等。

App() 必须在 `app.js` 中调用，必须调用且只能调用一次。不然会出现无法预期的后果。

**参数**

**Object object**

| 属性                   | 类型       | 默认值 | 必填 | 说明                                            | 最低版本   |
| -------------------- | -------- | --- | -- | --------------------------------------------- | ------ |
| **onLaunch**         | function |     | 否  | 生命周期回调——监听小程序初始化。                             |        |
| onShow               | function |     | 否  | 生命周期回调——监听小程序启动或切前台。                          |        |
| onHide               | function |     | 否  | 生命周期回调——监听小程序切后台。                             |        |
| onError              | function |     | 否  | 错误监听函数。                                       |        |
| onPageNotFound       | function |     | 否  | 页面不存在监听函数。                                    | 1.9.90 |
| onUnhandledRejection | function |     | 否  | 未处理的 Promise 拒绝事件监听函数。                        | 2.10.0 |
| onThemeChange        | function |     | 否  | 监听系统主题变化                                      | 2.11.0 |
| 其他                   | any      |     | 否  | 开发者可以添加任意的函数或数据变量到 `Object` 参数中，用 `this` 可以访问 |        |

### Sitemap.json

小程序根目录下的 `sitemap.json` 文件用来配置小程序及其页面是否允许被微信索引。

```
{
  "rules":[{
    "action": "allow",
    "page": "*"
  }]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luckydesigner.space/wechat/pei-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
