Skip to content

页面结构

每个页面一个目录:page.json 描述长什么样,同目录 page.jsPage({}) 填数据、响应操作。

建议先把 JSON 结构搭出来,再写生命周期和页面事件。组件清单见 组件

只展示固定内容数据会变
文案直接写在 page.json写成 {{hello}} / bind,在 onLoadthis.setData
page.jsPage({}) 即可Page({ data });也可 Http.get 后再 setData
适用关于、说明、固定入口表单回填、列表、统计

入口 homePage 为首页目录,例如 pages/homepage.js 可用 require 引入其他 JS,路径规则见 require

页面字段

参数名类型必填说明
idString页面标记。跳转可写文件夹,或入口 pages 中的 id
titleString / Object导航栏。不写则不显示。字符串为标题;对象见下表
styleObject内容区样式:padding / margin / background 等。未写 padding 时为 16
statusBarString / Object顶部状态栏。字符串为背景色;对象为 background + colorlight / dark
jsString默认加载同目录 page.js。见 页面生命周期页面事件
enablePullDownRefreshBoolean打开整页下拉。见 下拉刷新
bodyArray组件列表
popupsArray弹层。显示隐藏用 showIf。要嵌自定义组件,在弹层 body 里写 { "type": "choose" },见 组件结构组件 · Popup。动作面板、图片查看器写在 body 里,同样用 showIf,见 ActionSheetImageViewer

以上字段会覆盖 deekeScript.jsonwindow 参数的同名配置。先加载 deekeScript.jsonwindow,再加载当前页面。

title 为对象时:

参数名类型说明
textString标题文案
hiddenBooleantrue 则隐藏导航栏
fontSizeNumber字号,单位 sp
colorString文字颜色
backgroundString导航栏背景色
fontWeightStringbold
alignStringleft / center / right
styleObject也可把 fontSize / color 等写在 style
json
{
  "title": {
    "text": "工作台",
    "fontSize": 18,
    "color": "#FFFFFF",
    "background": "#006A65"
  }
}
json
{ "title": { "text": "关于", "hidden": true } }

内容区写在 style 里,覆盖全局 window.style

json
{
  "style": { "padding": 16, "margin": 0, "background": "#F5F5F5" },
  "statusBar": { "background": "#006A65", "color": "light" },
  "body": []
}

组件字段见 组件。把一组内置组件打包复用,见 自定义组件。事件和数据见 父页交互

固定内容

结构和文案都写在 JSON 里,page.js 用空的 Page({}) 即可。

{
  "title": {
    "text": "关于",
    "fontSize": 18,
    "color": "#FFFFFF",
    "background": "#006A65"
  },
  "style": {
    "background": "#F5F5F5"
  },
  "body": [
    {
      "type": "title",
      "text": "DeekeScript"
    },
    {
      "type": "text",
      "text": "用 JSON 描述页面。"
    },
    {
      "type": "notice",
      "text": "当前版本 2.0.0"
    },
    {
      "type": "divider"
    },
    {
      "type": "card",
      "children": [
        {
          "type": "text",
          "text": "页面",
          "style": {
            "fontWeight": "bold"
          }
        },
        {
          "type": "notice",
          "text": "JSON 描述结构,JS 填充数据"
        }
      ]
    },
    {
      "type": "card",
      "children": [
        {
          "type": "text",
          "text": "数据",
          "style": {
            "fontWeight": "bold"
          }
        },
        {
          "type": "notice",
          "text": "模板占位符,onLoad 中 setData"
        }
      ]
    },
    {
      "type": "button",
      "text": "打开官网",
      "action": {
        "type": "openUrl",
        "url": "https://deeke.cn"
      }
    }
  ]
}
UI
9:41100%
关于
DeekeScript
用 JSON 描述页面。
当前版本 2.0.0
页面
JSON 描述结构,JS 填充数据
数据
模板占位符,onLoad 中 setData

数据会变

文案写成 {{hello}},表单用 name 对应 data 里的键。初始值放 Page({ data }),接口数据在 onLoadthis.setData。列表、触底加载见 组件

{
  "title": {
    "text": "设置",
    "fontSize": 18,
    "color": "#FFFFFF",
    "background": "#006A65"
  },
  "style": {
    "background": "#F5F5F5",
    "padding": 10
  },
  "body": [
    {
      "type": "card",
      "children": [
        {
          "type": "input",
          "id": "task_name",
          "name": "task_name",
          "label": "任务名",
          "hint": "请输入"
        },
        {
          "type": "input",
          "id": "nickname",
          "name": "nickname",
          "label": "账号备注",
          "hint": "选填"
        },
        {
          "type": "textarea",
          "id": "remark",
          "name": "remark",
          "label": "备注",
          "minLines": 3
        },
        {
          "type": "select",
          "id": "platform",
          "name": "platform",
          "label": "平台",
          "options": [
            {
              "label": "抖音",
              "value": "dy"
            },
            {
              "label": "小红书",
              "value": "xhs"
            },
            {
              "label": "快手",
              "value": "ks"
            }
          ]
        },
        {
          "type": "switch",
          "id": "auto_start",
          "name": "auto_start",
          "label": "自动开始",
          "value": false
        },
        {
          "type": "switch",
          "id": "notify",
          "name": "notify",
          "label": "完成通知",
          "value": true
        },
        {
          "type": "range",
          "label": "关注数量",
          "separator": "~",
          "inputType": "number",
          "start": {
            "name": "follow_min",
            "hint": "最小"
          },
          "end": {
            "name": "follow_max",
            "hint": "最大"
          }
        },
        {
          "type": "progress",
          "name": "speed",
          "label": "运行速度",
          "value": 50,
          "min": 0,
          "max": 100,
          "unit": "%"
        }
      ]
    },
    {
      "type": "space",
      "height": 8
    },
    {
      "type": "button",
      "text": "保存",
      "onTap": "onSave",
      "action": {
        "type": "save"
      }
    }
  ]
}
UI
9:41100%
设置

模板 {{path}}

写法含义
{{hello}}data 中的字段
{{data.hello}}同上
{{item.title}}列表当前项
{{index}}列表下标,从 0 开始
{{params.id}}跳转参数
{{storage.task_name}}本地 Storage
{{item.tags.0}}数组下标

路径不存在时替换为空字符串。点击、显示条件等写在组件上,见 组件 · 通用字段

AutoJS文档 Released under the ISC License.