vendor: amis 6.13.0 base (fork root)
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules/
|
||||||
|
public/
|
||||||
|
lib/
|
||||||
|
npm/
|
||||||
|
.git/
|
||||||
|
.github/
|
||||||
|
.vscode/
|
||||||
|
.rollup.cache
|
||||||
21
.editorconfig
Normal file
21
.editorconfig
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[**.{js,ts,tsx,scss}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[**.{py}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[**.tsv]
|
||||||
|
indent_style = tab
|
||||||
15
.gitattributes
vendored
Normal file
15
.gitattributes
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 避免 windows 下自动转
|
||||||
|
* text eol=lf
|
||||||
|
*.jpg -text
|
||||||
|
*.png -text
|
||||||
|
*.eot -text
|
||||||
|
*.otf binary
|
||||||
|
*.eot binary
|
||||||
|
*.svg binary
|
||||||
|
*.ttf binary
|
||||||
|
*.woff binary
|
||||||
|
*.docx binary
|
||||||
|
*.xlsx binary
|
||||||
|
*.pptx binary
|
||||||
|
*.TTF binary
|
||||||
|
*.sketch binary
|
||||||
31
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
31
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: 报告问题,帮助我们做的更好
|
||||||
|
title: ''
|
||||||
|
labels: need confirm
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 描述问题:
|
||||||
|
|
||||||
|
请用一段清晰简洁的文字描述问题是什么...
|
||||||
|
|
||||||
|
#### 截图或视频:
|
||||||
|
|
||||||
|
可以的话,尽可能提供截图或视频来补充描述你的问题...
|
||||||
|
|
||||||
|
#### 如何复现(请务必完整填写下面内容):
|
||||||
|
|
||||||
|
1. 你是如何使用 amis 的?
|
||||||
|
`sdk`、`npm` 或`其他`...
|
||||||
|
|
||||||
|
2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在
|
||||||
|
|
||||||
|
3. 粘贴有问题的完整 `amis schema` 代码:
|
||||||
|
```
|
||||||
|
code here...
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 操作步骤
|
||||||
|
请简单描述一下复现的操作步骤...
|
||||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
20
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: 为我们提出一个新的想法
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 是否关联于某个问题吗:
|
||||||
|
请用一段简单清晰的文字描述你的想法是关联于某个问题,例如:因为我没办法实现xxx...
|
||||||
|
|
||||||
|
#### 预期的解决方案:
|
||||||
|
请简单描述你想达到的效果...
|
||||||
|
|
||||||
|
#### 其他可接受方案:
|
||||||
|
请简单描述其他你可以接受的效果...
|
||||||
|
|
||||||
|
#### 任何附加信息:
|
||||||
|
请添加任何可以补充说明上述问题的材料,例如图片或视频等...
|
||||||
40
.github/ISSUE_TEMPLATE/rfc.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/rfc.md
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
name: RFC
|
||||||
|
about: request for comments
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
简单地描述这项功能。
|
||||||
|
|
||||||
|
## 动机
|
||||||
|
|
||||||
|
为什么要做出这个更改?应对什么样的场景?会产生什么结果?
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
如果提案新增或更改 JSON 配置。
|
||||||
|
|
||||||
|
## 详细设计
|
||||||
|
|
||||||
|
可选。
|
||||||
|
|
||||||
|
## 缺陷
|
||||||
|
|
||||||
|
我们是不是可以不做这个功能,请考虑:
|
||||||
|
|
||||||
|
- 实现这个功能的投入:包括代码的复杂度、代码体积的增加
|
||||||
|
- 这个功能是不是不需要 amis 提供,比如基于 amis 自己扩展更合适
|
||||||
|
- 对 amis 现有功能的影响,以及用户进行迁移的成本
|
||||||
|
|
||||||
|
## 替代选择
|
||||||
|
|
||||||
|
还有其他的方案也可以实现这个功能吗?
|
||||||
|
|
||||||
|
## 适配策略
|
||||||
|
|
||||||
|
如果我们实现了这个提案,有没有什么办法可以帮助开发者更好地适应这个改动?
|
||||||
21
.github/ISSUE_TEMPLATE/usage-question.md
vendored
Normal file
21
.github/ISSUE_TEMPLATE/usage-question.md
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
name: Usage question
|
||||||
|
about: amis 使用方法问题
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 实现场景:
|
||||||
|
请简单描述你想要实现的原始场景,例如:我想要实现xxx的功能...
|
||||||
|
|
||||||
|
#### 存在的问题:
|
||||||
|
请简单描述你现在遇到的不符合预期的问题...
|
||||||
|
|
||||||
|
#### 当前方案:
|
||||||
|
请粘贴你当前方案的完整 amis schema 代码...
|
||||||
|
|
||||||
|
```
|
||||||
|
code here...
|
||||||
|
```
|
||||||
27
.github/labeler.yml
vendored
Normal file
27
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# labeler "simple" schema
|
||||||
|
# Comment is applied to both issues and pull requests.
|
||||||
|
# If you need a more robust solution, consider the "full" schema.
|
||||||
|
comment: |
|
||||||
|
👍 Thanks for this!
|
||||||
|
🏷 I have applied any labels matching special text in your issue.
|
||||||
|
|
||||||
|
Please review the labels and make any necessary changes.
|
||||||
|
|
||||||
|
# Labels is an object where:
|
||||||
|
# - keys are labels
|
||||||
|
# - values are array of string patterns to match against title + body in issues/prs
|
||||||
|
labels:
|
||||||
|
'bug':
|
||||||
|
- '(?i)\bbug[s]?\b'
|
||||||
|
'help wanted':
|
||||||
|
- '(?i)\bhelp( wanted)?\b'
|
||||||
|
'feat':
|
||||||
|
- '(?i)\bfeat'
|
||||||
|
'fix':
|
||||||
|
- '(?i)\bfix'
|
||||||
|
'style':
|
||||||
|
- '(?i)\bstyle'
|
||||||
|
'chore':
|
||||||
|
- '(?i)\bchore'
|
||||||
|
'doc':
|
||||||
|
- '(?i)\bdoc[s]?'
|
||||||
58
.github/release-drafter.yml
vendored
Normal file
58
.github/release-drafter.yml
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
categories:
|
||||||
|
- title: 新功能 Features 🚀
|
||||||
|
label: feat
|
||||||
|
- title: 问题修复 Bugfix 🐛
|
||||||
|
labels:
|
||||||
|
- 'fix'
|
||||||
|
- 'fixes'
|
||||||
|
- title: 依赖更新
|
||||||
|
label: dep
|
||||||
|
- title: 日常维护 Chore
|
||||||
|
label: chore
|
||||||
|
- title: 样式调整 Style 🌈
|
||||||
|
labels:
|
||||||
|
- 'style'
|
||||||
|
- 'styles'
|
||||||
|
- title: 文档更新 Docs
|
||||||
|
labels:
|
||||||
|
- 'doc'
|
||||||
|
- 'docs'
|
||||||
|
- title: 单元测试 test
|
||||||
|
label: test
|
||||||
|
|
||||||
|
autolabeler:
|
||||||
|
- label: 'feat'
|
||||||
|
branch:
|
||||||
|
- '/feat-.+/i'
|
||||||
|
title:
|
||||||
|
- '/feat/i'
|
||||||
|
- label: 'fix'
|
||||||
|
branch:
|
||||||
|
- '/fix-.+/i'
|
||||||
|
title:
|
||||||
|
- '/fix/i'
|
||||||
|
- label: 'chore'
|
||||||
|
branch:
|
||||||
|
- '/chore-.+/i'
|
||||||
|
title:
|
||||||
|
- '/chore/i'
|
||||||
|
- label: 'style'
|
||||||
|
branch:
|
||||||
|
- '/style[s]?-.+/i'
|
||||||
|
title:
|
||||||
|
- '/style/i'
|
||||||
|
- label: 'doc'
|
||||||
|
branch:
|
||||||
|
- '/doc[s]?-.+/i'
|
||||||
|
title:
|
||||||
|
- '/doc/i'
|
||||||
|
- label: 'test'
|
||||||
|
branch:
|
||||||
|
- '/test[s]?-.+/i'
|
||||||
|
title:
|
||||||
|
- '/test/i'
|
||||||
|
template: |
|
||||||
|
|
||||||
|
## 更新记录
|
||||||
|
|
||||||
|
$CHANGES
|
||||||
18
.github/workflows/auto-labeler.yml
vendored
Normal file
18
.github/workflows/auto-labeler.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
name: Community
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened, edited, milestoned]
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
labeler:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check Labels
|
||||||
|
id: labeler
|
||||||
|
uses: jimschubert/labeler-action@v2
|
||||||
|
with:
|
||||||
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
67
.github/workflows/codeql-analysis.yml
vendored
Normal file
67
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: 'CodeQL'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: ['**']
|
||||||
|
schedule:
|
||||||
|
- cron: '21 7 * * 2'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: ['javascript']
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v3
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v3
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v3
|
||||||
53
.github/workflows/gh-pages.yml
vendored
Normal file
53
.github/workflows/gh-pages.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: gh-pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [20.x]
|
||||||
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: n1hility/cancel-previous-runs@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: build gh-pages
|
||||||
|
run: |
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
cd packages/office-viewer
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
cd ../../
|
||||||
|
npm run build --workspaces
|
||||||
|
sh deploy-gh-pages.sh
|
||||||
|
- name: Deploy 🚀
|
||||||
|
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||||
|
with:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
BRANCH: gh-pages # The branch the action should deploy to.
|
||||||
|
FOLDER: gh-pages # The folder the action should deploy.
|
||||||
|
CLEAN: true # Automatically remove deleted files from the deploy branch
|
||||||
|
SINGLE_COMMIT: true
|
||||||
|
- name: Generate coverage report
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: '--max-old-space-size=8192'
|
||||||
|
run: |
|
||||||
|
npm run coverage
|
||||||
|
- uses: codecov/codecov-action@v4
|
||||||
|
with:
|
||||||
|
name: codecov-umbrella # optional
|
||||||
|
fail_ci_if_error: false # optional (default = false)
|
||||||
|
verbose: true # optional (default = false)
|
||||||
65
.github/workflows/pr-test.yml
vendored
Normal file
65
.github/workflows/pr-test.yml
vendored
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
name: PR test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: ['**']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [20.x]
|
||||||
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: npm install
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: '--max-old-space-size=8192'
|
||||||
|
run: |
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
cd packages/office-viewer
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
cd ../../
|
||||||
|
- name: build amis-formula
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis-formula
|
||||||
|
- name: build amis-core
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis-core
|
||||||
|
- name: build amis-ui
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis-ui
|
||||||
|
- name: build amis
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis
|
||||||
|
- name: check schema.json
|
||||||
|
run: |
|
||||||
|
cp ./packages/amis/schema.json .
|
||||||
|
- name: build amis-editor-core
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis-editor-core
|
||||||
|
- name: build amis-editor
|
||||||
|
run: |
|
||||||
|
npm run build --workspace amis-editor
|
||||||
|
- name: typescript check
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: '--max-old-space-size=8192'
|
||||||
|
run: |
|
||||||
|
npm run typecheck
|
||||||
|
- name: test
|
||||||
|
run: |
|
||||||
|
npm test --workspaces
|
||||||
|
cd packages/office-viewer
|
||||||
|
npm test
|
||||||
|
cd ../../
|
||||||
|
sh deploy-gh-pages.sh
|
||||||
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Files
|
||||||
|
.DS_Store
|
||||||
|
.ruby-version
|
||||||
|
test.sass
|
||||||
|
npm-debug.log
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
|
||||||
|
# Folders
|
||||||
|
.idea/
|
||||||
|
.sass-cache
|
||||||
|
gh_pages
|
||||||
|
_site
|
||||||
|
**/node_modules
|
||||||
|
/dist
|
||||||
|
/lib
|
||||||
|
**/esm
|
||||||
|
**/lib
|
||||||
|
/sdk
|
||||||
|
/public
|
||||||
|
/gh-pages
|
||||||
|
/.vscode/*
|
||||||
|
/output
|
||||||
|
/toolkit/amis-renderer
|
||||||
|
/toolkit/output
|
||||||
|
/coverage
|
||||||
|
/npm
|
||||||
|
/mock/cfc/cfc.zip
|
||||||
|
.rollup.cache
|
||||||
|
/theme-npm
|
||||||
|
|
||||||
|
dist
|
||||||
|
tsconfig.tsbuildinfo
|
||||||
|
lerna-debug.log
|
||||||
|
.rollup.cache
|
||||||
|
package-lock.json
|
||||||
|
revision.json
|
||||||
|
**/revision.json
|
||||||
|
~$*
|
||||||
|
|
||||||
|
|
||||||
|
!/.vscode/iconConfig.json
|
||||||
|
publish.sh
|
||||||
24
.gitpod.yml
Normal file
24
.gitpod.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# This configuration file was automatically generated by Gitpod.
|
||||||
|
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
|
||||||
|
# and commit this file to your remote git repository to share the goodness with others.
|
||||||
|
|
||||||
|
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- port: 3000
|
||||||
|
onOpen: ignore
|
||||||
|
visibility: public
|
||||||
|
- port: 8888
|
||||||
|
onOpen: ignore
|
||||||
|
visibility: public
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: SDK
|
||||||
|
command: |
|
||||||
|
npm i
|
||||||
|
npm run build --workspace amis --workspace amis-ui
|
||||||
|
npx -y serve packages/amis/
|
||||||
|
- name: Amis
|
||||||
|
command: |
|
||||||
|
gp await-port 3000
|
||||||
|
npm run start
|
||||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
_
|
||||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npx lint-staged
|
||||||
20
.prettierrc
Normal file
20
.prettierrc
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"semi": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"quoteProps": "consistent",
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"jsxBracketSameLine": false,
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "src/locale/*.ts",
|
||||||
|
"options": {
|
||||||
|
"printWidth": 800
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
17
.stylelintrc.json
Normal file
17
.stylelintrc.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"color-hex-case": "lower",
|
||||||
|
"no-extra-semicolons": true,
|
||||||
|
"declaration-colon-space-after": "always-single-line",
|
||||||
|
"block-no-empty": true
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"*.scss",
|
||||||
|
"**/*.scss"
|
||||||
|
],
|
||||||
|
"customSyntax": "postcss-scss"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
23
.swcrc
Normal file
23
.swcrc
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/swcrc",
|
||||||
|
"jsc": {
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"tsx": true,
|
||||||
|
"decorators": true,
|
||||||
|
"dynamicImport": true
|
||||||
|
},
|
||||||
|
"transform": {
|
||||||
|
"decoratorMetadata": true,
|
||||||
|
"legacyDecorator": true,
|
||||||
|
"react": {
|
||||||
|
"runtime": "classic"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keepClassNames": true,
|
||||||
|
"externalHelpers": true,
|
||||||
|
"loose": false
|
||||||
|
},
|
||||||
|
"sourceMaps": true,
|
||||||
|
"minify": false
|
||||||
|
}
|
||||||
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- 12
|
||||||
|
script: sh deploy-gh-pages.sh
|
||||||
22
.vscode/iconConfig.json
vendored
Normal file
22
.vscode/iconConfig.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "packages/amis",
|
||||||
|
"iconPath": "packages/amis-ui/src/components/icons.tsx",
|
||||||
|
"iconDir": "packages/amis-ui/src/icons"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "packages/amis-ui",
|
||||||
|
"iconPath": "packages/amis-ui/src/components/icons.tsx",
|
||||||
|
"iconDir": "packages/amis-ui/src/icons"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "packages/amis-editor",
|
||||||
|
"iconPath": "packages/amis-editor/src/icons/index.tsx",
|
||||||
|
"iconDir": "packages/amis-editor/src/icons"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "packages/amis-editor-core",
|
||||||
|
"iconPath": "packages/amis-editor-core/src/icons/index.tsx",
|
||||||
|
"iconDir": "packages/amis-editor-core/src/icons"
|
||||||
|
}
|
||||||
|
]
|
||||||
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest: current file",
|
||||||
|
//"env": { "NODE_ENV": "test" },
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["${fileBasenameNoExtension}"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
34
.vscode/settings.json
vendored
Normal file
34
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
|
"gitHistory.showEditorTitleMenuBarIcons": false,
|
||||||
|
"files.exclude": {
|
||||||
|
"**/lib": true,
|
||||||
|
"**/esm": true,
|
||||||
|
"**/sdk": true,
|
||||||
|
"**/tsconfig.tsbuildinfo": true,
|
||||||
|
"**/schema.json": true,
|
||||||
|
"**/lerna-debug.log": true,
|
||||||
|
"**/package-lock.json": true,
|
||||||
|
"**/.rollup.cache": true,
|
||||||
|
"public/**": true
|
||||||
|
},
|
||||||
|
"search.exclude": {
|
||||||
|
"**/lib": true,
|
||||||
|
"**/esm": true,
|
||||||
|
"**/sdk": true,
|
||||||
|
"**/tsconfig.tsbuildinfo": true,
|
||||||
|
"**/schema.json": true,
|
||||||
|
"**/lerna-debug.log": true,
|
||||||
|
"**/package-lock.json": true,
|
||||||
|
"**/.rollup.cache": true,
|
||||||
|
"public/**": true,
|
||||||
|
"examples/docs.json": true,
|
||||||
|
"examples/components/EChartsEditor/option-parts/**/*": true
|
||||||
|
},
|
||||||
|
"[xml]": {
|
||||||
|
"editor.defaultFormatter": "redhat.vscode-xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2023 Baidu
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
115
README-en.md
Normal file
115
README-en.md
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<div align="center">
|
||||||
|
<p>
|
||||||
|
<img width="284" src="https://github.com/baidu/amis/raw/master/examples/static/logo.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[Documentation (China)](https://aisuda.bce.baidu.com/amis/) |
|
||||||
|
[Documentation (Global)](https://baidu.github.io/amis/) |
|
||||||
|
[Visual Editor](https://aisuda.github.io/amis-editor-demo/) |
|
||||||
|
[amis-admin](https://github.com/aisuda/amis-admin) |
|
||||||
|
[AiSuDa](https://aisuda.baidu.com/)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
Ruliu Group: 3395342 |
|
||||||
|
Ruliu Group 2: 5511067 |
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
[](https://codecov.io/gh/baidu/amis)
|
||||||
|

|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
A low-code front-end framework that allows you to generate various backend pages using JSON configuration, greatly reducing development costs, and even eliminating the need for front-end expertise.
|
||||||
|
|
||||||
|
## Development Guide
|
||||||
|
|
||||||
|
The following is for those who want to contribute to the development of amis. For usage, refer to the documentation above.
|
||||||
|
|
||||||
|
> If GitHub downloads are slow, you can use the mirror on [gitee](https://gitee.com/baidu/amis).
|
||||||
|
|
||||||
|
Node.js versions 12/14/16 are recommended. Use npm 7+ because the workspaces feature is required.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install project dependencies. There may be errors with Node.js 12, but they don't affect normal use.
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
|
||||||
|
# Start the project. Once compilation is complete, access it at http://127.0.0.1:8888/examples/pages/simple.
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're developing the editor, access it at `http://127.0.0.1:8888/packages/amis-editor/`.
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
> Note: After modifying code locally, you must run npm run build to complete compilation before executing test cases (`npm test --workspaces`), as Jest doesn't support TypeScript directly.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install dependencies
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Run all test cases
|
||||||
|
npm test --workspaces
|
||||||
|
|
||||||
|
# Run a specific test case
|
||||||
|
# <spec-name> is the name of the test case, e.g., inputImage
|
||||||
|
npm test --workspace amis -- -t <spec-name>
|
||||||
|
|
||||||
|
# Run a specific test file
|
||||||
|
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx
|
||||||
|
|
||||||
|
# Run a specific example in a test file
|
||||||
|
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx -t 'Renderer:button-toolbar'
|
||||||
|
|
||||||
|
# View test coverage
|
||||||
|
npm run coverage
|
||||||
|
|
||||||
|
# Update snapshots
|
||||||
|
npm run update-snapshot
|
||||||
|
|
||||||
|
# Update a single snapshot
|
||||||
|
# <spec-name> is the name of the test case, e.g., inputImage
|
||||||
|
npm run update-snapshot --workspace amis -- -t <spec-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Release Version
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Publish to internal registry
|
||||||
|
npm run publish
|
||||||
|
|
||||||
|
# Publish to external environment
|
||||||
|
# First, set the version number with the following command
|
||||||
|
npm run version
|
||||||
|
npm run release
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to Contribute
|
||||||
|
|
||||||
|
Please use a branch for development. First, create a branch:
|
||||||
|
|
||||||
|
git checkout -b feat-xxx
|
||||||
|
|
||||||
|
After committing your changes, use `git push --set-upstream origin feat-xxx` to create a remote branch.
|
||||||
|
|
||||||
|
Then submit a PR using the system-generated link: https://github.com/xxx/amis/pull/new/feat-xxx.
|
||||||
|
|
||||||
|
Please write in TypeScript. All reasonable changes, new public renderers, test cases, or documentation submissions will be accepted.
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
<a href="https://github.com/baidu/amis/graphs/contributors"><img src="https://opencollective.com/amis/contributors.svg?width=890" /></a>
|
||||||
|
|
||||||
|
## Low-Code Platform
|
||||||
|
|
||||||
|
amis enables low-code front-end development. For a complete low-code platform, we recommend using [AiSuDa](https://aisuda.baidu.com/).
|
||||||
115
README.md
Normal file
115
README.md
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<div align="center">
|
||||||
|
<p>
|
||||||
|
<img width="284" src="https://github.com/baidu/amis/raw/master/examples/static/logo.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[文档(国内)](https://aisuda.bce.baidu.com/amis/) |
|
||||||
|
[文档(国外)](https://baidu.github.io/amis/) |
|
||||||
|
[可视化编辑器](https://aisuda.github.io/amis-editor-demo/) |
|
||||||
|
[amis-admin](https://github.com/aisuda/amis-admin) |
|
||||||
|
[爱速搭](https://aisuda.baidu.com/)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
如流群:3395342 |
|
||||||
|
如流群2:5511067|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
[](https://codecov.io/gh/baidu/amis)
|
||||||
|

|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
前端低代码框架,通过 JSON 配置就能生成各种后台页面,极大减少开发成本,甚至可以不需要了解前端。
|
||||||
|
|
||||||
|
## 开发指南
|
||||||
|
|
||||||
|
以下是参与开发 amis 才需要看的,使用请看前面的文档。
|
||||||
|
|
||||||
|
> 如果 github 下载慢可以使用 [gitee](https://gitee.com/baidu/amis) 上的镜像。
|
||||||
|
|
||||||
|
推荐使用 node 12/14/16。npm 7+, 因为用到了 workspaces 功能。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装项目 npm 依赖,在 node 12 下会有报错但不影响正常使用。
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
|
||||||
|
# 启动项目,等编译结束后通过 http://127.0.0.1:8888/examples/pages/simple 访问。
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
如果是开发编辑器,需要访问 `http://127.0.0.1:8888/packages/amis-editor/`
|
||||||
|
|
||||||
|
### 测试
|
||||||
|
|
||||||
|
> 注意:本地修改代码后,执行测试用例(`npm test --workspaces`)之前需要先执行`npm run build`完成编译,因为 jest 并不支持 TypeScript
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装依赖
|
||||||
|
npm i --legacy-peer-deps
|
||||||
|
|
||||||
|
# 执行构建
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 执行测试用例
|
||||||
|
npm test --workspaces
|
||||||
|
|
||||||
|
# 测试某个用例
|
||||||
|
# <spec-name>为用例名称,比如inputImage
|
||||||
|
npm test --workspace amis -- -t <spec-name>
|
||||||
|
|
||||||
|
# 运行某个单测文件
|
||||||
|
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx
|
||||||
|
|
||||||
|
# 运行某个单测文件里的某个例子
|
||||||
|
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx -t 'Renderer:button-toolbar'
|
||||||
|
|
||||||
|
# 查看测试用例覆盖率
|
||||||
|
npm run coverage
|
||||||
|
|
||||||
|
# 更新 snapshot
|
||||||
|
npm run update-snapshot
|
||||||
|
|
||||||
|
# 更新单个 snapshot
|
||||||
|
# <spec-name>为用例名称,比如inputImage
|
||||||
|
npm run update-snapshot --workspace amis -- -t <spec-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 发布版本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 发布内部 registry
|
||||||
|
npm run publish
|
||||||
|
|
||||||
|
# 发布外网环境
|
||||||
|
# 先通过一下命令设置版本号
|
||||||
|
npm run version
|
||||||
|
npm run release
|
||||||
|
```
|
||||||
|
|
||||||
|
### 如何贡献
|
||||||
|
|
||||||
|
请使用分支开发,首先创建分支
|
||||||
|
|
||||||
|
git checkout -b feat-xxx
|
||||||
|
|
||||||
|
开发提交后使用 `git push --set-upstream origin feat-xxx` 创建远程分支。
|
||||||
|
|
||||||
|
然后通过系统提示的 https://github.com/xxx/amis/pull/new/feat-xxx 链接来提交 PR。
|
||||||
|
|
||||||
|
请采用 typescript 编写,所有合理的改动、新的公用渲染器、用例或者文档的提交都会被接收。
|
||||||
|
|
||||||
|
## 贡献者
|
||||||
|
|
||||||
|
<a href="https://github.com/baidu/amis/graphs/contributors"><img src="https://opencollective.com/amis/contributors.svg?width=890" /></a>
|
||||||
|
|
||||||
|
## 低代码平台
|
||||||
|
|
||||||
|
amis 只能实现前端低代码,如果需要完整的低代码平台推荐使用[爱速搭](https://aisuda.baidu.com/)。
|
||||||
23
__mocks__/monaco.ts
Normal file
23
__mocks__/monaco.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* monaco 加载没搞定,可能后续会先 mock
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const languages = {
|
||||||
|
register: function (language: any) {},
|
||||||
|
setMonarchTokensProvider: function (name: any, tokens: any) {},
|
||||||
|
registerCompletionItemProvider: function (name: any, provider: any) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const editor = {
|
||||||
|
defineTheme: function (name: any, theme: any) {},
|
||||||
|
create: function (name: any, theme: any) {
|
||||||
|
return {
|
||||||
|
onDidChangeModelDecorations: () => {
|
||||||
|
return {
|
||||||
|
dispose: () => {}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
dispose: () => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
6
__mocks__/styleMock.js
Normal file
6
__mocks__/styleMock.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* 用于 jest 加载 css 的 mock
|
||||||
|
*/
|
||||||
|
module.exports = {};
|
||||||
5
__mocks__/svgJsMock.js
Normal file
5
__mocks__/svgJsMock.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const React = require('react');
|
||||||
|
|
||||||
|
exports['default'] = React.forwardRef((props, ref) =>
|
||||||
|
React.createElement('icon-mock', {ref, ...props})
|
||||||
|
);
|
||||||
5
__mocks__/svgMock.js
Normal file
5
__mocks__/svgMock.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const React = require('react');
|
||||||
|
|
||||||
|
module.exports = React.forwardRef((props, ref) =>
|
||||||
|
React.createElement('icon-mock', {ref, ...props})
|
||||||
|
);
|
||||||
65
amis.code-workspace
Normal file
65
amis.code-workspace
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "./",
|
||||||
|
"name": "monorepo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-formula"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-core"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-ui"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/office-viewer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-editor-core"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-editor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/amis-theme-editor-helper"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
|
"files.exclude": {
|
||||||
|
"**/lib": true,
|
||||||
|
"**/esm": true,
|
||||||
|
"**/sdk": true,
|
||||||
|
"**/tsconfig.tsbuildinfo": true,
|
||||||
|
"**/schema.json": true,
|
||||||
|
"**/lerna-debug.log": true,
|
||||||
|
"**/package-lock.json": true,
|
||||||
|
"**/.rollup.cache": true,
|
||||||
|
"public/**": true
|
||||||
|
},
|
||||||
|
"search.exclude": {
|
||||||
|
"**/lib": true,
|
||||||
|
"**/esm": true,
|
||||||
|
"**/sdk": true,
|
||||||
|
"**/tsconfig.tsbuildinfo": true,
|
||||||
|
"**/schema.json": true,
|
||||||
|
"**/lerna-debug.log": true,
|
||||||
|
"**/package-lock.json": true,
|
||||||
|
"**/.rollup.cache": true,
|
||||||
|
"public/**": true,
|
||||||
|
"examples/docs.json": true,
|
||||||
|
"examples/components/EChartsEditor/option-parts/**/*": true
|
||||||
|
},
|
||||||
|
"[xml]": {
|
||||||
|
"editor.defaultFormatter": "redhat.vscode-xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
deploy-gh-pages.sh
Executable file
22
deploy-gh-pages.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
|
||||||
|
echo "building"
|
||||||
|
node ./scripts/generate-search-data.js
|
||||||
|
|
||||||
|
./node_modules/.bin/fis3 release gh-pages -c
|
||||||
|
|
||||||
|
# 拷贝一份兼容之前的访问路径
|
||||||
|
cp -r gh-pages/zh-CN/docs/* gh-pages/docs/
|
||||||
|
|
||||||
|
cp ./packages/amis/schema.json ./gh-pages
|
||||||
|
|
||||||
|
cp -r mock gh-pages/
|
||||||
|
|
||||||
|
tar -zcvf sdk.tar.gz packages/amis/sdk
|
||||||
|
|
||||||
|
mv sdk.tar.gz gh-pages/
|
||||||
|
|
||||||
|
# 加这个 github page 就不会忽略下划线开头的文件
|
||||||
|
touch gh-pages/.nojekyll
|
||||||
1131
docs/zh-CN/components/action.md
Executable file
1131
docs/zh-CN/components/action.md
Executable file
File diff suppressed because it is too large
Load Diff
283
docs/zh-CN/components/alert.md
Executable file
283
docs/zh-CN/components/alert.md
Executable file
@@ -0,0 +1,283 @@
|
|||||||
|
---
|
||||||
|
title: Alert 提示
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Alert 提示
|
||||||
|
icon:
|
||||||
|
order: 27
|
||||||
|
---
|
||||||
|
|
||||||
|
用来做文字特殊提示,分为四类:提示类、成功类、警告类和危险类。
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
`level`属性支持 4 种预设样式:`info`, `success`, `warning`, `danger`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "提示类文案",
|
||||||
|
"level": "info",
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "提示类标题",
|
||||||
|
"body": "提示类文案",
|
||||||
|
"level": "info",
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "成功类文案",
|
||||||
|
"level": "success",
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "成功类标题",
|
||||||
|
"body": "成功类文案",
|
||||||
|
"level": "success",
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "警告类文案",
|
||||||
|
"level": "warning",
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "警告类标题",
|
||||||
|
"body": "警告类文案",
|
||||||
|
"level": "warning",
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "危险类文案",
|
||||||
|
"level": "danger",
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "危险类标题",
|
||||||
|
"body": "危险类文案",
|
||||||
|
"level": "danger",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 图标
|
||||||
|
|
||||||
|
配置`"showIcon": true`后展示图标让信息更加醒目。可以通过`icon`属性自定义设置 icon 内容,如果`icon`属性为空,则根据`level`值添加默认 icon。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "提示类文案",
|
||||||
|
"level": "info",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "提示类标题",
|
||||||
|
"body": "提示类文案",
|
||||||
|
"level": "info",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "成功类文案",
|
||||||
|
"level": "success",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "成功类标题",
|
||||||
|
"body": "成功类文案",
|
||||||
|
"level": "success",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "警告类文案",
|
||||||
|
"level": "warning",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "警告类标题",
|
||||||
|
"body": "警告类文案",
|
||||||
|
"level": "warning",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "危险类文案",
|
||||||
|
"level": "danger",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "危险类标题",
|
||||||
|
"body": "危险类文案",
|
||||||
|
"level": "danger",
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "自定义ICON文案",
|
||||||
|
"showIcon": true,
|
||||||
|
"icon": "info-circle",
|
||||||
|
"className": "mb-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "自定义ICON标题",
|
||||||
|
"body": "自定义ICON文案",
|
||||||
|
"showIcon": true,
|
||||||
|
"icon": "fa fa-list"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## level 支持表达式
|
||||||
|
|
||||||
|
> 1.6.4 及以上版本
|
||||||
|
|
||||||
|
修改下面例子的 status 值为 2 就能看到变化
|
||||||
|
|
||||||
|
```schema:
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"status": 1
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"level": "${IFS(status===1, 'danger', status===2, 'warning')}",
|
||||||
|
"body": "这是内容区"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
同时 icon 和 showIcon 也都支持表达式
|
||||||
|
|
||||||
|
## 显示关闭按钮
|
||||||
|
|
||||||
|
配置`"showCloseButton": true`实现显示关闭按钮。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "显示关闭按钮的提示",
|
||||||
|
"level": "info",
|
||||||
|
"showCloseButton": true,
|
||||||
|
"showIcon": true,
|
||||||
|
"className": "mb-2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"title": "可关闭提示",
|
||||||
|
"body": "显示关闭按钮的提示",
|
||||||
|
"level": "success",
|
||||||
|
"showCloseButton": true,
|
||||||
|
"showIcon": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 操作区域
|
||||||
|
|
||||||
|
> `3.6.0`及以上版本
|
||||||
|
|
||||||
|
配置`actions`属性,可以添加操作区域。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"level": "success",
|
||||||
|
"className": "mb-3",
|
||||||
|
"showIcon": true,
|
||||||
|
"showCloseButton": true,
|
||||||
|
"title": "标题",
|
||||||
|
"body": "创建成功",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "查看详情",
|
||||||
|
"size": "xs",
|
||||||
|
"level": "link",
|
||||||
|
"style": {
|
||||||
|
"position": "relative",
|
||||||
|
"top": "25px",
|
||||||
|
"left": "30px"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"level": "info",
|
||||||
|
"showIcon": true,
|
||||||
|
"showCloseButton": true,
|
||||||
|
"body": "创建成功",
|
||||||
|
"actions": {
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "flex-start",
|
||||||
|
"alignItems": "flex-start",
|
||||||
|
"direction": "column",
|
||||||
|
"style": {"padding": "6px"},
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "详情",
|
||||||
|
"size": "xs",
|
||||||
|
"level": "primary",
|
||||||
|
"style": {
|
||||||
|
"marginBottom": "5px"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "关闭",
|
||||||
|
"size": "xs",
|
||||||
|
"level": "danger"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| -------------------- | ----------------------------------------- | --------- | -------------------------------------------------------- | --- |
|
||||||
|
| type | `string` | `"alert"` | 指定为 alert 渲染器 |
|
||||||
|
| title | `string` | | alert标题 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| level | `string` | `info` | 级别,可以是:`info`、`success`、`warning` 或者 `danger` |
|
||||||
|
| body | [`SchemaNode[] \| SchemaNode`](../../docs/types/schemanode) | | 显示内容 |
|
||||||
|
| showCloseButton | `boolean` | `false` | 是否显示关闭按钮 |
|
||||||
|
| closeButtonClassName | `string` | | 关闭按钮的 CSS 类名 |
|
||||||
|
| showIcon | `boolean` | `false` | 是否显示 icon |
|
||||||
|
| icon | `string` | | 自定义 icon |
|
||||||
|
| iconClassName | `string` | | icon 的 CSS 类名 |
|
||||||
|
| actions | [`SchemaNode[] \| SchemaNode`](../../docs/types/schemanode) | | 操作区域 | `3.6.0` |
|
||||||
87
docs/zh-CN/components/amis.md
Normal file
87
docs/zh-CN/components/amis.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
---
|
||||||
|
title: AMIS 渲染器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: AMIS 渲染器
|
||||||
|
icon:
|
||||||
|
order: 28
|
||||||
|
---
|
||||||
|
|
||||||
|
用于渲染数据中的 amis 配置
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
只需要设置 schema 或 name,值可以是 JSON 对象或字符串的 JSON
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "amis",
|
||||||
|
"schema": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "amis render"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 通过 name 绑定动态数据
|
||||||
|
|
||||||
|
可以用在表单或 CRUD 中,下面示例演示了编辑后实时渲染的效果,因为使用了相同 的 name
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"title": "实时测试 amis 渲染效果",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "amis",
|
||||||
|
"language": "json",
|
||||||
|
"value": {
|
||||||
|
"label": "弹框",
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "弹框",
|
||||||
|
"body": "这是个简单的弹框。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "amis",
|
||||||
|
"name": "amis"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 向下传递 props
|
||||||
|
|
||||||
|
通过设置 props 向下传递,这个 props 会作为默认值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "amis",
|
||||||
|
"props": {
|
||||||
|
"tpl": "amis render"
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "tpl"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------ | -------- | -------- | ------------------ |
|
||||||
|
| type | `string` | `"amis"` | 指定为 amis 渲染器 |
|
||||||
|
| name | `string` | | 绑定上下文变量名 |
|
||||||
|
| props | `object` | | 向下传递的 props |
|
||||||
493
docs/zh-CN/components/anchor-nav.md
Normal file
493
docs/zh-CN/components/anchor-nav.md
Normal file
@@ -0,0 +1,493 @@
|
|||||||
|
---
|
||||||
|
title: AnchorNav 锚点导航
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: AnchorNav
|
||||||
|
icon:
|
||||||
|
order: 68
|
||||||
|
---
|
||||||
|
|
||||||
|
锚点导航容器组件。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
`6.1.0`及以上版本垂直方向支持配置子节点
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "anchor-nav",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "input-email",
|
||||||
|
"label": "邮箱:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "工作信息",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"title": "工作信息-1",
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "workInfo1-1",
|
||||||
|
"label": "工作信息1-1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "workInfo1-2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "工作信息1-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "工作信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "cname",
|
||||||
|
"label": "公司名称:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "caddress",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "公司地址:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"title": "兴趣爱好1-1",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "兴趣爱好1-1",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "interest1-1",
|
||||||
|
"label": "interest1-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest1-2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "interest1-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "interest1",
|
||||||
|
"label": "兴趣爱好1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好2:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest3",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好3:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest4",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好4:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest5",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好5:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest6",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好6:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
默认想要显示多少锚点导航配置多少个 `links` 成员即可。
|
||||||
|
|
||||||
|
## 水平导航
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "anchor-nav",
|
||||||
|
"direction": "horizontal",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "input-email",
|
||||||
|
"label": "邮箱:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "工作信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "工作信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "cname",
|
||||||
|
"label": "公司名称:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "caddress",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "公司地址:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "interest1",
|
||||||
|
"label": "兴趣爱好1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好2:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest3",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好3:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest4",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好4:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest5",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好5:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest6",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好6:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 默认定位到某个区域
|
||||||
|
|
||||||
|
主要配置`active`属性来实现该效果,共有下面两种方法:
|
||||||
|
|
||||||
|
#### 配置 href 值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "anchor-nav",
|
||||||
|
"active": "work",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"title": "基本信息",
|
||||||
|
"href": "base",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "input-email",
|
||||||
|
"label": "邮箱:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "工作信息",
|
||||||
|
"href": "work",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"title": "工作信息-1",
|
||||||
|
"href": "work-1",
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "workInfo1-1",
|
||||||
|
"label": "工作信息1-1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "workInfo1-2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "工作信息1-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "工作信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "cname",
|
||||||
|
"label": "公司名称:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "caddress",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "公司地址:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"href": "interest",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "interest1",
|
||||||
|
"label": "兴趣爱好1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好2:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest3",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好3:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest4",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好4:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest5",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好5:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest6",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好6:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 配置索引值
|
||||||
|
|
||||||
|
单个`link`上不要配置`href`属性,配置需要展示的`link`索引值,`0`代表第一个。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "anchor-nav",
|
||||||
|
"active": 1,
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "基本信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "input-email",
|
||||||
|
"label": "邮箱:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "工作信息",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"title": "工作信息-1",
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "workInfo1-1",
|
||||||
|
"label": "工作信息1-1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "workInfo1-2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "工作信息1-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "工作信息",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "cname",
|
||||||
|
"label": "公司名称:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "caddress",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "公司地址:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "兴趣爱好",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "interest1",
|
||||||
|
"label": "兴趣爱好1:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好2:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest3",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好3:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest4",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好4:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest5",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好5:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "interest6",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "兴趣爱好6:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------------ | --------------------------------- | ----------------------------------- | -------------------------------------------------------------------------- |
|
||||||
|
| type | `string` | `"anchor-nav"` | 指定为 AnchorNav 渲染器 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| linkClassName | `string` | | 导航 Dom 的类名 |
|
||||||
|
| sectionClassName | `string` | | 锚点区域 Dom 的类名 |
|
||||||
|
| links | `Array` | | links 内容 |
|
||||||
|
| direction | `string` | `"vertical"` | 可以配置导航水平展示还是垂直展示。对应的配置项分别是:vertical、horizontal |
|
||||||
|
| active | `string` | | 需要定位的区域 |
|
||||||
|
| links[x].title | `string` | | 区域 标题 |
|
||||||
|
| links[x].href | `string` | | 区域 标识 |
|
||||||
|
| links[x].body | [SchemaNode](../types/schemanode) | | 区域 内容区,`6.1.0`及以上版本垂直方向支持配置子节点 |
|
||||||
|
| links[x].className | `string` | `"bg-white b-l b-r b-b wrapper-md"` | 区域成员 样式 |
|
||||||
87
docs/zh-CN/components/app.md
Normal file
87
docs/zh-CN/components/app.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
---
|
||||||
|
title: App 多页应用
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: App 多页应用
|
||||||
|
icon:
|
||||||
|
order: 99
|
||||||
|
---
|
||||||
|
|
||||||
|
用于实现多页应用,适合于全屏模式,如果只是局部渲染请不要使用。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
类型定义为 `app`,通过 pages 定义页面,支持层级,支持内嵌 schema,或者 通过 schemaApi 远程拉取页面,完整用法请参考 [amis-admin](https://github.com/aisuda/amis-admin) 项目里的代码示例,需要修改 `env`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "app",
|
||||||
|
"brandName": "应用名称",
|
||||||
|
"pages": [
|
||||||
|
{
|
||||||
|
"label": "分组1",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "父页面",
|
||||||
|
"url": "/parent",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "子页面",
|
||||||
|
"url": "pageA",
|
||||||
|
"schema": {
|
||||||
|
"type": "page",
|
||||||
|
"title": "Page A"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性说明
|
||||||
|
|
||||||
|
- `type` 请配置成 `app`
|
||||||
|
- `api` 页面配置接口,如果你想远程拉取页面配置请配置。返回配置路径 `json>data>pages`,具体格式请参考 `pages` 属性。
|
||||||
|
- `brandName` 应用名称。
|
||||||
|
- `logo` 支持图片地址,或者 svg。
|
||||||
|
- `className` css 类名。
|
||||||
|
- `header` 顶部区域。
|
||||||
|
- `asideBefore` 页面菜单上前面区域。
|
||||||
|
- `asideAfter` 页面菜单下前面区域。
|
||||||
|
- `footer` 页面。
|
||||||
|
- `pages` `Array<页面配置>`具体的页面配置。
|
||||||
|
通常为数组,数组第一层为分组,一般只需要配置 label 集合,如果你不想分组,直接不配置,真正的页面请在第二层开始配置,即第一层的 children 中。
|
||||||
|
|
||||||
|
具体的页面配置也支持属性结构,每层有以下配置。
|
||||||
|
|
||||||
|
- `label` 菜单名称。
|
||||||
|
- `icon` 菜单图标,比如:fa fa-file.
|
||||||
|
- `url` 页面路由路径,当路由命中该路径时,启用当前页面。当路径不是 `/` 打头时,会连接父级路径。比如:父级的路径为 `folder`,而此时配置 `pageA`, 那么当页面地址为 `/folder/pageA` 时才会命中此页面。当路径是 `/` 开头如: `/crud/list` 时,则不会拼接父级路径。另外还支持 `/crud/view/:id` 这类带参数的路由,页面中可以通过 `${params.id}` 取到此值。
|
||||||
|
- `schema` 页面的配置,具体配置请前往 [Page 页面说明](./page)
|
||||||
|
- `schemaApi` 如果想通过接口拉取,请配置。返回路径为 `json>data`。schema 和 schemaApi 只能二选一。
|
||||||
|
- `link` 如果想配置个外部链接菜单,只需要配置 link 即可。
|
||||||
|
- `redirect` 跳转,当命中当前页面时,跳转到目标页面。
|
||||||
|
- `rewrite` 改成渲染其他路径的页面,这个方式页面地址不会发生修改。
|
||||||
|
- `isDefaultPage` 当你需要自定义 404 页面的时候有用,不要出现多个这样的页面,因为只有第一个才会有用。
|
||||||
|
- `visible` 有些页面可能不想出现在菜单中,可以配置成 `false`,另外带参数的路由无需配置,直接就是不可见的。
|
||||||
|
- `className` 菜单类名。
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | -------- | --------------------------------------------------- |
|
||||||
|
| init | - | 组件实例被创建并插入 DOM 中时触发。2.4.1 及以上版本 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | -------------------------- | ---------------- |
|
||||||
|
| reload | - | 刷新(重新加载) |
|
||||||
|
| setValue | `value: object` 更新的数据 | 更新数据 |
|
||||||
31
docs/zh-CN/components/audio.md
Executable file
31
docs/zh-CN/components/audio.md
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
title: Audio 音频
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Audio 音频
|
||||||
|
icon:
|
||||||
|
order: 28
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "audio",
|
||||||
|
"src": "https://amis.bj.bcebos.com/amis/2019-7/1562137295708/chicane-poppiholla-original-radio-edit%20(1).mp3"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | --------- | ------------------------------------------------ | --------------------------------------- |
|
||||||
|
| type | `string` | `"audio"` | 指定为 audio 渲染器 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| inline | `boolean` | true | 是否是内联模式 |
|
||||||
|
| src | `string` | | 音频地址 |
|
||||||
|
| loop | `boolean` | false | 是否循环播放 |
|
||||||
|
| autoPlay | `boolean` | false | 是否自动播放 |
|
||||||
|
| rates | `array` | `[]` | 可配置音频播放倍速如:`[1.0, 1.5, 2.0]` |
|
||||||
|
| controls | `array` | `['rates', 'play', 'time', 'process', 'volume']` | 内部模块定制化 |
|
||||||
342
docs/zh-CN/components/avatar.md
Normal file
342
docs/zh-CN/components/avatar.md
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
---
|
||||||
|
title: Avatar 头像
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Avatar 头像
|
||||||
|
icon:
|
||||||
|
order: 27
|
||||||
|
---
|
||||||
|
|
||||||
|
用来显示用户头像
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 文字
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"text": "AM"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 图标
|
||||||
|
|
||||||
|
通过 icon 设置图标
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"icon": "fa fa-user"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 如果同时存在 src、text 和 icon,会优先用 src、接着 text、最后 icon
|
||||||
|
|
||||||
|
## 动态图片或文字
|
||||||
|
|
||||||
|
src、text 都支持变量,可以从上下文中动态获取图片或文字,下面的例子中:
|
||||||
|
|
||||||
|
- 第一个获取到了,显示正常
|
||||||
|
- 第二个没获取到,因此降级为显示 icon
|
||||||
|
- 第三个图片没获取到,由于 text 优先级比 icon 高,所以显示 text
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"myAvatar": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
},
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"src": "$myAvatar"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"src": "$other"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"src": "$other",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"text": "avatar"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 方形和圆角形
|
||||||
|
|
||||||
|
可以通过 shape 改成方形或圆角形
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"shape": "square",
|
||||||
|
"text": "AM"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"shape": "rounded",
|
||||||
|
"text": "AM",
|
||||||
|
"style": {
|
||||||
|
"marginLeft": "10px"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 大小
|
||||||
|
|
||||||
|
通过 size 可以控制头像的大小
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"size": 'large',
|
||||||
|
"icon": "fa fa-user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"size": 'default',
|
||||||
|
"icon": "fa fa-user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"size": 'small',
|
||||||
|
"icon": "fa fa-user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"size": 60,
|
||||||
|
"src": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"size": 20,
|
||||||
|
"src": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 控制字符类型距离左右两侧边界单位像素
|
||||||
|
|
||||||
|
通过 gap 可以控制字符类型距离左右两侧边界单位像素
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"text": 'ejson',
|
||||||
|
"gap": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"text": "ejson",
|
||||||
|
"gap": 7
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 图片拉伸方式
|
||||||
|
|
||||||
|
通过 `fit` 可以控制图片拉伸方式,默认是 `'cover'`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "cover",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "fill",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "contain",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "none",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "scale-down",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 控制图片是否允许拖动
|
||||||
|
|
||||||
|
通过 draggable 可以控制图片是否允许拖动
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "cover",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg",
|
||||||
|
"draggable": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"fit": "cover",
|
||||||
|
"src": "https://suda.cdn.bcebos.com/images/amis/plumeria.jpeg",
|
||||||
|
"draggable": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 图片加载失败后,通过 onError 控制是否进行 text、icon 置换
|
||||||
|
|
||||||
|
> 如果同时存在 text 和 icon,会优先用 text、接着 icon
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"src": "empty",
|
||||||
|
"text": "avatar",
|
||||||
|
"onError": "return true;"
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式
|
||||||
|
|
||||||
|
可以通过 style 来控制背景及文字颜色
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"text": "AM",
|
||||||
|
"style": {
|
||||||
|
"background": "#DB3E35",
|
||||||
|
"color": "#FFFFFF"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------- | ------------------------------------------------------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| className | `string` | | 外层 dom 的类名 |
|
||||||
|
| style | `object` | | 外层 dom 的样式 |
|
||||||
|
| fit | `'contain'` \| `'cover'` \| `'fill'` \| `'none'` \| `'scale-down'` | `'cover'` | 具体细节可以参考 MDN [文档](https://developer.mozilla.org/zh-CN/docs/Web/CSS/object-fit) |
|
||||||
|
| src | `string` | | 图片地址 |
|
||||||
|
| defaultAvatar | `string` | | 占位图 |
|
||||||
|
| text | `string` | | 文字 |
|
||||||
|
| icon | `string` | `'fa fa-user'` | 图标 |
|
||||||
|
| shape | `'circle'` \| `'square'` \| `'rounded'` | `'circle'` | 形状,有三种 `'circle'` (圆形)、`'square'`(正方形)、`'rounded'`(圆角) |
|
||||||
|
| size | `number` \| `'default'` \| `'normal'` \| `'small'` | `'default'` | `'default' \| 'normal' \| 'small'`三种字符串类型代表不同大小(分别是 48、40、32),也可以直接数字表示 |
|
||||||
|
| gap | `number` | 4 | 控制字符类型距离左右两侧边界单位像素 |
|
||||||
|
| alt | `number` | | 图像无法显示时的替代文本 |
|
||||||
|
| draggable | `boolean` | | 图片是否允许拖动 |
|
||||||
|
| crossOrigin | `'anonymous'` \| `'use-credentials'` \| `''` | | 图片的 `CORS` 属性设置 |
|
||||||
|
| onError | `string` | | 图片加载失败的字符串,这个字符串是一个 New Function 内部执行的字符串,参数是 event(使用 event.nativeEvent 获取原生 dom 事件),这个字符串需要返回 boolean 值。设置 `"return ture;"` 会在图片加载失败后,使用 `text` 或者 `icon` 代表的信息来进行替换。目前图片加载失败默认是不进行置换。注意:图片加载失败,不包括$获取数据为空情况 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
> 6.1.0 及以上版本
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| ---------- | -------- | -------------- |
|
||||||
|
| click | - | 点击时触发 |
|
||||||
|
| mouseenter | - | 鼠标移入时触发 |
|
||||||
|
| mouseleave | - | 鼠标移出时触发 |
|
||||||
|
|
||||||
|
### click
|
||||||
|
|
||||||
|
鼠标点击。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### mouseenter
|
||||||
|
|
||||||
|
鼠标移入。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseenter": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### mouseleave
|
||||||
|
|
||||||
|
鼠标移出。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseleave": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
370
docs/zh-CN/components/badge.md
Normal file
370
docs/zh-CN/components/badge.md
Normal file
@@ -0,0 +1,370 @@
|
|||||||
|
---
|
||||||
|
title: Badge 角标
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Badge
|
||||||
|
icon:
|
||||||
|
order: 30
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
部分组件可以设置 `badge` 属性来显示角标。
|
||||||
|
|
||||||
|
> 1.2.2 及之前版本只支持头像组件
|
||||||
|
>
|
||||||
|
> 1.2.3 开始支持按钮、链接、模板组件。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "action",
|
||||||
|
"label": "按钮",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "link",
|
||||||
|
"href": "https://www.baidu.com",
|
||||||
|
"body": "百度一下,你就知道",
|
||||||
|
"badge": {
|
||||||
|
"position": "top-right"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "Hello ${text}",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 25
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "icon",
|
||||||
|
"icon": "cloud",
|
||||||
|
"className": "text-info text-xl",
|
||||||
|
"badge": {
|
||||||
|
"position": "top-left"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "action",
|
||||||
|
"label": "按钮",
|
||||||
|
"badge": {
|
||||||
|
"mode": "ribbon",
|
||||||
|
"text": "HOT"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示文字或数值
|
||||||
|
|
||||||
|
设置 `mode` 为 `text`,通过 `text` 属性来显示文字或数字,数值为零的时候将不显示。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": "new"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示位置
|
||||||
|
|
||||||
|
通过 `position` 来控制角标显示位置,默认 `top-right`,还可以设置为 `top-left`、`bottom-left`、`bottom-right`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"position": "top-left"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"position": "bottom-left"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"position": "bottom-right"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
通过 `offset` 来控制角标显示位置,offset 相对于 position 位置进行水平、垂直偏移。offset 在 mode=ribbon 下设置无效。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"offset": [10, 10]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动态数字
|
||||||
|
|
||||||
|
`text` 可以取上下文变量。
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"myData": 10
|
||||||
|
},
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"visibleOn": "this.myData > 1",
|
||||||
|
"text": "${myData}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置封顶值
|
||||||
|
|
||||||
|
通过 `overflowCount` 可以设置封顶值。超过 overflowCount 的会显示为 ${overflowCount}+,默认的 overflowCount 为 99
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"overflowCount": 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动态控制是否显示角标
|
||||||
|
|
||||||
|
角标可以直接写表达式来判断是否显示
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"myData": 10
|
||||||
|
},
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": "this.myData > 1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": "this.myData > 10"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
还可以通过 `visibleOn` 表达式来动态控制,这样还能设置其他属性
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"myData": 10
|
||||||
|
},
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"visibleOn": "this.myData > 1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"visibleOn": "this.myData > 10"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置大小
|
||||||
|
|
||||||
|
通过 `size` 来控制大小
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"size": 20
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"size": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"size": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"size": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置角标级别
|
||||||
|
|
||||||
|
通过 `level` 来设置角标级别,改变角标背景颜色
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"size": 20,
|
||||||
|
"level": "success"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 是否显示动画
|
||||||
|
|
||||||
|
在默认点状态下,可以通过设置 `animation` 属性来控制是否显示动画
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"animation": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
通过 `style` 来控制展现样式,比如背景及文字的颜色
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"style": {
|
||||||
|
"background": "#46C93A"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "avatar",
|
||||||
|
"className": "m-l",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 10,
|
||||||
|
"style": {
|
||||||
|
"background": "#1A5CFF"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------- | ------------------------------------------- | --------- | ---------------------------------------------------------------------- |
|
||||||
|
| mode | `string` | dot | 角标类型,可以是 dot/text/ribbon |
|
||||||
|
| text | `string`\|`number` | | 角标文案,支持字符串和数字,在 mode='dot'下设置无效 |
|
||||||
|
| size | `number` | | 角标大小 |
|
||||||
|
| level | `string` | | 角标级别, 可以是 info/success/warning/danger, 设置之后角标背景颜色不同 |
|
||||||
|
| overflowCount | `number` | 99 | 设置封顶的数字值 |
|
||||||
|
| position | `string` | top-right | 角标位置, 可以是 top-right/top-left/bottom-right/bottom-left |
|
||||||
|
| offset | `number[top, left]` | [0, 0] | 角标位置,offset 相对于 position 位置进行水平、垂直偏移 |
|
||||||
|
| className | `string` | | 外层 dom 的类名 |
|
||||||
|
| animation | `boolean` | | 角标是否显示动画 |
|
||||||
|
| style | `object` | | 角标的自定义样式 |
|
||||||
|
| visibleOn | [表达式](../../../docs/concepts/expression) | | 控制角标的显示隐藏 |
|
||||||
43
docs/zh-CN/components/barcode.md
Normal file
43
docs/zh-CN/components/barcode.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
title: BarCode 条形码
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: BarCode 条形码
|
||||||
|
icon:
|
||||||
|
order: 62
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "barcode",
|
||||||
|
"value": "amis"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 条形码配置
|
||||||
|
|
||||||
|
通过 options 属性配置,具体请参考[这里](https://github.com/lindell/JsBarcode/wiki/Options),比如
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "barcode",
|
||||||
|
"value": "123",
|
||||||
|
"options": {
|
||||||
|
"format": "pharmacode",
|
||||||
|
"lineColor": "#0aa",
|
||||||
|
"width": "4",
|
||||||
|
"height": "40",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | -------- | ------ | ------------------------------ |
|
||||||
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
|
| value | `string` | | 显示的颜色值 |
|
||||||
|
| name | `string` | | 在其他组件中,时,用作变量映射 |
|
||||||
163
docs/zh-CN/components/breadcrumb.md
Normal file
163
docs/zh-CN/components/breadcrumb.md
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
---
|
||||||
|
title: Breadcrumb 面包屑
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Breadcrumb
|
||||||
|
icon:
|
||||||
|
order: 30
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "breadcrumb",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"label": "首页",
|
||||||
|
"href": "https://baidu.gitee.com/",
|
||||||
|
"icon": "fa fa-home"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "上级页面"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "当前页面"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动态数据
|
||||||
|
|
||||||
|
可以配置 source 来获取上下文中的动态数据,结合 [service](service) 来实现动态生成。
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"breadcrumb": [
|
||||||
|
{
|
||||||
|
"label": "首页",
|
||||||
|
"href": "https://baidu.gitee.com/"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "上级页面"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "当前页面"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "breadcrumb",
|
||||||
|
"source": "${breadcrumb}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 分隔符
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "breadcrumb",
|
||||||
|
"separator": ">",
|
||||||
|
"separatorClassName": "text-black",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"href": "https://baidu.gitee.com/",
|
||||||
|
"icon": "fa fa-home"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "上级页面"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "当前页面"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下拉菜单
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "breadcrumb",
|
||||||
|
"separator": ">",
|
||||||
|
"separatorClassName": "text-black",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"label": "首页",
|
||||||
|
"href": "https://baidu.gitee.com/",
|
||||||
|
"icon": "fa fa-home"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "上级页面",
|
||||||
|
"dropdown": [
|
||||||
|
{
|
||||||
|
"label": "选项一",
|
||||||
|
"href": "https://baidu.gitee.com/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "选项二"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "当前页面"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 最大展示长度
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "breadcrumb",
|
||||||
|
"separator": ">",
|
||||||
|
"separatorClassName": "text-black",
|
||||||
|
"labelMaxLength": 16,
|
||||||
|
"tooltipPosition": "top",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"href": "https://baidu.gitee.com/",
|
||||||
|
"icon": "fa fa-home"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "上级页面上级页面上级页面上级页面上级页面"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"label": "当前页面"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------------ | -------------------------------- | ------------- | ---------------------------------------------------- |
|
||||||
|
| className | `string` | | 外层类名 |
|
||||||
|
| itemClassName | `string` | | 导航项类名 |
|
||||||
|
| separatorClassName | `string` | | 分割符类名 |
|
||||||
|
| dropdownClassName | `string` | | 下拉菜单类名 |
|
||||||
|
| dropdownItemClassName | `string` | | 下拉菜单项类名 |
|
||||||
|
| separator | `string` | | 分隔符 |
|
||||||
|
| labelMaxLength | `number` | 16 | 最大展示长度 |
|
||||||
|
| tooltipPosition | `top \| bottom \| left \| right` | `top` | 浮窗提示位置 |
|
||||||
|
| source | `string` | | 动态数据 |
|
||||||
|
| items[].label | `string` | | 文本 |
|
||||||
|
| items[].href | `string` | | 链接 |
|
||||||
|
| items[].icon | `string` | | [图标](icon) |
|
||||||
|
| items[].dropdown | `dropdown[]` | | 下拉菜单,dropdown[]的每个对象都包含label、href、icon属性 |
|
||||||
137
docs/zh-CN/components/button-group.md
Executable file
137
docs/zh-CN/components/button-group.md
Executable file
@@ -0,0 +1,137 @@
|
|||||||
|
---
|
||||||
|
title: ButtonGroup 按钮组
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: ButtonGroup
|
||||||
|
icon:
|
||||||
|
order: 30
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-group",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "Button",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"confirmMode": false,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "对,你刚点击了!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "url",
|
||||||
|
"url": "https://www.baidu.com",
|
||||||
|
"blank": true,
|
||||||
|
"label": "百度一下"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "普通按钮"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 垂直模式
|
||||||
|
|
||||||
|
配置`"vertical": true`,实现垂直模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "button-group",
|
||||||
|
"vertical": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 平铺模式
|
||||||
|
|
||||||
|
配置 `"tiled": true` 实现平铺模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "button-group",
|
||||||
|
"tiled": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 按钮主题样式
|
||||||
|
|
||||||
|
配置 `btnLevel` 统一设置按钮主题样式,注意 `buttons ` 或 `options` 中的`level`属性优先级高于`btnLevel`。配置 `btnActiveLevel` 为按钮设置激活态时的主题样式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "button-group",
|
||||||
|
"btnLevel": "light",
|
||||||
|
"btnActiveLevel": "warning",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3",
|
||||||
|
"level": "primary"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| -------------- | ------------------------------------------------------------------------------------------------------------------- | ---------------- | -------------------------- |
|
||||||
|
| type | `string` | `"button-group"` | 指定为 button-group 渲染器 |
|
||||||
|
| vertical | `boolean` | `false` | 是否使用垂直模式 |
|
||||||
|
| tiled | `boolean` | `false` | 是否使用平铺模式 |
|
||||||
|
| btnLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 按钮样式 |
|
||||||
|
| btnActiveLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 选中按钮样式 |
|
||||||
|
| buttons | `Array<Action>` | | [按钮](./action) |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
43
docs/zh-CN/components/button.md
Executable file
43
docs/zh-CN/components/button.md
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
title: Button 按钮
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Button 按钮
|
||||||
|
icon:
|
||||||
|
order: 29
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"label": "弹个框",
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "弹框",
|
||||||
|
"body": "这是个简单的弹框。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`button` 实际上是 `action` 的别名,更多用法见 [action](./action)
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------- |
|
||||||
|
| className | `string` | | 指定添加 button 类名 |
|
||||||
|
| url | `string` | | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 |
|
||||||
|
| size | `'xs' \| 'sm' \| 'md' \| 'lg' ` | | 设置按钮大小 |
|
||||||
|
| actionType | `'button' \| 'reset' \| 'submit'\| 'clear'\| 'url'` | button | 设置按钮类型 |
|
||||||
|
| level | `'link' \| 'primary' \| 'enhance' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | default | 设置按钮样式 |
|
||||||
|
| tooltip | `'string' \| 'TooltipObject'` | | 气泡提示内容 |
|
||||||
|
| tooltipPlacement | `'top' \| 'right' \| 'bottom' \| 'left' ` | top | 气泡框位置器 |
|
||||||
|
| tooltipTrigger | `'hover' \| 'focus'` | | 触发 tooltip |
|
||||||
|
| disabled | `'boolean'` | false | 按钮失效状态 |
|
||||||
|
| disabledTip | `'string' \| 'TooltipObject'` | | 按钮失效状态下的提示 |
|
||||||
|
| block | `'boolean'` | false | 将按钮宽度调整为其父宽度的选项 |
|
||||||
|
| loading | `'boolean'` | false | 显示按钮 loading 效果 |
|
||||||
|
| loadingOn | `'string'` | | 显示按钮 loading 表达式 |
|
||||||
238
docs/zh-CN/components/calendar.md
Normal file
238
docs/zh-CN/components/calendar.md
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
---
|
||||||
|
title: Calendar 日历日程
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Calendar 日历日程
|
||||||
|
icon:
|
||||||
|
order: 36
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
设置 `schedules` 属性
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "1638288000",
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-11 05:14:00",
|
||||||
|
"endTime": "2021-12-11 06:14:00",
|
||||||
|
"content": "这是一个日程1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义颜色
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "1638288000",
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-11 05:14:00",
|
||||||
|
"endTime": "2021-12-11 06:14:00",
|
||||||
|
"content": "这是一个日程1",
|
||||||
|
"className": "bg-success"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程2",
|
||||||
|
"className": "bg-info"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义日程展示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "1638288000",
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-11 05:14:00",
|
||||||
|
"endTime": "2021-12-11 06:14:00",
|
||||||
|
"content": "这是一个日程1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"scheduleAction": {
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "日程",
|
||||||
|
"body": {
|
||||||
|
"type": "table",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "time",
|
||||||
|
"label": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "content",
|
||||||
|
"label": "内容"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"data": "${scheduleData}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持从数据源中获取日程
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-11 05:14:00",
|
||||||
|
"endTime": "2021-12-11 06:14:00",
|
||||||
|
"content": "这是一个日程1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "1638288000",
|
||||||
|
"schedules": "${schedules}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 放大模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "1638288000",
|
||||||
|
"largeMode": true,
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-10 23:59:59",
|
||||||
|
"endTime": "2021-12-11 00:00:00",
|
||||||
|
"content": "这是一个日程1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-12 00:00:00",
|
||||||
|
"endTime": "2021-12-13 00:00:01",
|
||||||
|
"content": "这是一个日程2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-20 05:14:00",
|
||||||
|
"endTime": "2021-12-21 05:14:00",
|
||||||
|
"content": "这是一个日程3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-22 02:14:00",
|
||||||
|
"endTime": "2021-12-23 05:14:00",
|
||||||
|
"content": "这是一个日程5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-22 02:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-22 02:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-25 12:00:00",
|
||||||
|
"endTime": "2021-12-25 15:00:00",
|
||||||
|
"content": "这是一个日程8"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 今日高亮样式自定义
|
||||||
|
|
||||||
|
> 2.1.1 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "calendar",
|
||||||
|
"value": "NOW()",
|
||||||
|
"todayActiveStyle": {
|
||||||
|
"backgroundColor": "#ef4444 !important",
|
||||||
|
"color": "#f8f9fa",
|
||||||
|
"border": "none",
|
||||||
|
"borderRadius": "15px"
|
||||||
|
},
|
||||||
|
"schedules": [
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-11 05:14:00",
|
||||||
|
"endTime": "2021-12-11 06:14:00",
|
||||||
|
"content": "这是一个日程1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startTime": "2021-12-21 05:14:00",
|
||||||
|
"endTime": "2021-12-22 05:14:00",
|
||||||
|
"content": "这是一个日程2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Calendar 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------------ | ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| type | `string` | `"calendar"` | 指定为 calendar 渲染器 |
|
||||||
|
| schedules | `Array<{startTime: string, endTime: string, content: any, className?: string}> \| string` | | 日历中展示日程,可设置静态数据或从上下文中取数据,startTime 和 endTime 格式参考[文档](https://momentjs.com/docs/#/parsing/string/),className 参考[背景色](https://baidu.gitee.io/amis/zh-CN/style/background/background-color) |
|
||||||
|
| scheduleClassNames | `Array<string>` | `['bg-warning', 'bg-danger', 'bg-success', 'bg-info', 'bg-secondary']` | 日历中展示日程的颜色,参考[背景色](https://baidu.gitee.io/amis/zh-CN/style/background/background-color) |
|
||||||
|
| scheduleAction | `SchemaNode` | | 自定义日程展示 |
|
||||||
|
| largeMode | `boolean` | `false` | 放大模式 |
|
||||||
|
| todayActiveStyle | `Record<string, any>` | | 今日激活时的自定义样式 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`来获取事件产生的数据(`< 2.3.2 及以下版本 为 ${event.data.[事件参数名]}`),详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| ---------- | ------------------------ | ------------------ |
|
||||||
|
| change | `value: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| click | `value: string` 组件的值 | 点击日期时触发 |
|
||||||
|
| mouseenter | `value: string` 组件的值 | 鼠标移入日期时触发 |
|
||||||
|
| mouseleave | `value: string` 组件的值 | 鼠标移出日期时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的值 | 更新数据 |
|
||||||
739
docs/zh-CN/components/card.md
Executable file
739
docs/zh-CN/components/card.md
Executable file
@@ -0,0 +1,739 @@
|
|||||||
|
---
|
||||||
|
title: Card 卡片
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Card 卡片
|
||||||
|
icon:
|
||||||
|
order: 31
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"header": {
|
||||||
|
"title": "标题",
|
||||||
|
"subTitle": "副标题",
|
||||||
|
"description": "这是一段描述",
|
||||||
|
"avatarClassName": "pull-left thumb-md avatar b-3x m-r",
|
||||||
|
"avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "Trident",
|
||||||
|
"inline": false,
|
||||||
|
"label": "Engine"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "static",
|
||||||
|
"type": "static",
|
||||||
|
"label": "Browser",
|
||||||
|
"value": "Internet Explorer 5.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "version",
|
||||||
|
"label": "Version",
|
||||||
|
"size": "sm"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "编辑",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"icon": "fa fa-pencil",
|
||||||
|
"dialog": {
|
||||||
|
"title": "编辑",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "删除",
|
||||||
|
"icon": "fa fa-trash",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "你删掉了该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 打开链接
|
||||||
|
|
||||||
|
> 1.4.0 及以上版本
|
||||||
|
|
||||||
|
通过 `href` 属性可以设置点击卡片打开外部链接
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"href": "https://github.com/baidu/amis",
|
||||||
|
"header": {
|
||||||
|
"title": "标题",
|
||||||
|
"subTitle": "副标题",
|
||||||
|
"description": "这是一段描述",
|
||||||
|
"avatarClassName": "pull-left thumb-md avatar b-3x m-r",
|
||||||
|
"avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E"
|
||||||
|
},
|
||||||
|
"useCardLabel": false,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "Trident",
|
||||||
|
"inline": false,
|
||||||
|
"label": "Engine"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "static",
|
||||||
|
"type": "static",
|
||||||
|
"label": "Browser",
|
||||||
|
"value": "Internet Explorer 5.0",
|
||||||
|
"mode": "horizontal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "version",
|
||||||
|
"label": "Version",
|
||||||
|
"size": "sm",
|
||||||
|
"mode": "horizontal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "编辑",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "编辑",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "删除",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "你删掉了该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置头像文本
|
||||||
|
|
||||||
|
如果没有 avatar,还可以通过 `avatarText` 设置头像文本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"href": "https://github.com/baidu/amis",
|
||||||
|
"header": {
|
||||||
|
"title": "标题",
|
||||||
|
"subTitle": "副标题",
|
||||||
|
"description": "这是一段描述",
|
||||||
|
"avatarText": "AMIS"
|
||||||
|
},
|
||||||
|
"body": "这里是内容"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
可以设置文本背景色,它会根据数据分配一个颜色,主要配合 `cards` 使用
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"engine": "Trident",
|
||||||
|
"browser": "Internet Explorer 4.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"engine": "Chrome",
|
||||||
|
"browser": "Chrome 44"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"engine": "Gecko",
|
||||||
|
"browser": "Firefox 1.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"engine": "Presto",
|
||||||
|
"browser": "Opera 10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"engine": "Webkie",
|
||||||
|
"browser": "Safari 12"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "cards",
|
||||||
|
"source": "$items",
|
||||||
|
"card": {
|
||||||
|
"header": {
|
||||||
|
"avatarText": "${engine|substring:0:2|upperCase}",
|
||||||
|
"avatarTextBackground": ["#FFB900", "#D83B01", "#B50E0E", "#E81123", "#B4009E", "#5C2D91", "#0078D7", "#00B4FF", "#008272"]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"label": "Browser",
|
||||||
|
"name": "browser"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 点击卡片的行为
|
||||||
|
|
||||||
|
> 1.4.0 及以上版本
|
||||||
|
|
||||||
|
通过设置 `itemAction` 可以设置整个卡片的点击行为
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"itemAction": {
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "详情",
|
||||||
|
"body": "当前描述"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"header": {
|
||||||
|
"title": "标题",
|
||||||
|
"subTitle": "副标题",
|
||||||
|
"description": "这是一段描述",
|
||||||
|
"avatarClassName": "pull-left thumb-md avatar b-3x m-r",
|
||||||
|
"avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E"
|
||||||
|
},
|
||||||
|
"body": "这里是内容"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
注意它和前面的 `href` 配置冲突,如果设置了 `href` 这个将不会生效
|
||||||
|
|
||||||
|
## 设置多媒体卡片
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
通过设置 `media` 可以设置为多媒体卡片, 通过 `mediaPosition` 可以设置多媒体位置
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"header": {
|
||||||
|
"title": "标题"
|
||||||
|
},
|
||||||
|
"media": {
|
||||||
|
"type": "image",
|
||||||
|
"className": "w-36 h-24",
|
||||||
|
"url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"position": "left"
|
||||||
|
},
|
||||||
|
"body": "这里是内容",
|
||||||
|
"secondary": "次要说明",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "操作",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"className": "mr-4",
|
||||||
|
"dialog": {
|
||||||
|
"title": "操作",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "操作",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"className": "mr-2.5",
|
||||||
|
"dialog": {
|
||||||
|
"title": "操作",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"level": "link",
|
||||||
|
"icon": "fa fa-ellipsis-h",
|
||||||
|
"className": "pr-1 flex",
|
||||||
|
"hideCaret": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "编辑",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "编辑",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "删除",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "你删掉了该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"toolbar": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "标签",
|
||||||
|
"className": "label label-warning"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置标签卡片
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"header": {
|
||||||
|
"title": "标题"
|
||||||
|
},
|
||||||
|
"body": "这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容",
|
||||||
|
"secondary": "次要说明",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "操作",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"className": "mr-4",
|
||||||
|
"dialog": {
|
||||||
|
"title": "操作",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "操作",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"className": "mr-2.5",
|
||||||
|
"dialog": {
|
||||||
|
"title": "操作",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"level": "link",
|
||||||
|
"icon": "fa fa-ellipsis-h",
|
||||||
|
"className": "pr-1 flex",
|
||||||
|
"hideCaret": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "编辑",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "编辑",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "删除",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "你删掉了该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"toolbar": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "标签",
|
||||||
|
"className": "label label-warning"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置按钮卡片
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
按钮卡片一般以卡片形式展示当前卡片的执行语义,例如:创建卡片、添加卡片等场景。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"className": "hover:shadow",
|
||||||
|
"body": {
|
||||||
|
"type": "wrapper",
|
||||||
|
"className": "h-32 flex items-center justify-center",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"className": "text-center",
|
||||||
|
"body": {
|
||||||
|
"type": "icon",
|
||||||
|
"icon": "plus",
|
||||||
|
"className": "text-2xl",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"body": "点击会有弹框"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"itemAction": {
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "详情",
|
||||||
|
"body": "当前描述"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置文本卡片
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"header": {
|
||||||
|
"className": "items-center",
|
||||||
|
"title": "卡片标题"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"body": {
|
||||||
|
"type": "tabs",
|
||||||
|
"tabs": [
|
||||||
|
{
|
||||||
|
"title": "标签1",
|
||||||
|
"className": "p-0",
|
||||||
|
"tab": [
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"className": "border-0",
|
||||||
|
"header": {
|
||||||
|
"className": "p-0 pb-2",
|
||||||
|
"title": "内容标题"
|
||||||
|
},
|
||||||
|
"body": "卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容",
|
||||||
|
"bodyClassName": "p-0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"className": "border-0",
|
||||||
|
"header": {
|
||||||
|
"className": "p-0 pb-2",
|
||||||
|
"title": "内容标题"
|
||||||
|
},
|
||||||
|
"body": "卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容",
|
||||||
|
"bodyClassName": "p-0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "标签2",
|
||||||
|
"className": "p-0",
|
||||||
|
"tab": "卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"toolbar": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "操作",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "操作",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置单元格卡片
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"body": {
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"display": "flex",
|
||||||
|
"align-items": "center",
|
||||||
|
"justify-content": "space-between",
|
||||||
|
"margin-bottom": "4px"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"flex": "1",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"white-space": "nowrap",
|
||||||
|
"text-overflow": "ellipsis"
|
||||||
|
},
|
||||||
|
"body": "单元格"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"color": "#999"
|
||||||
|
},
|
||||||
|
"body": "内容"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"display": "flex",
|
||||||
|
"alignItems": "center",
|
||||||
|
"justifyContent": "space-between",
|
||||||
|
"marginBottom": "4px"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"flex": "1",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"whiteSpace": "nowrap",
|
||||||
|
"textOverflow": "ellipsis"
|
||||||
|
},
|
||||||
|
"body": "单元格"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"color": "#999"
|
||||||
|
},
|
||||||
|
"body": "内容"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "wrapper",
|
||||||
|
"size": "none",
|
||||||
|
"style": {
|
||||||
|
"color": "#999",
|
||||||
|
"fontSize": "12px"
|
||||||
|
},
|
||||||
|
"body": "描述信息"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置工具栏
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "card",
|
||||||
|
"header": {
|
||||||
|
"title": "标题",
|
||||||
|
"subTitle": "副标题",
|
||||||
|
"description": "这是一段描述",
|
||||||
|
"avatarClassName": "pull-left thumb-md avatar b-3x m-r",
|
||||||
|
"avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E"
|
||||||
|
},
|
||||||
|
"body": "这里是内容",
|
||||||
|
"toolbar": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"icon": "fa fa-eye",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "查看",
|
||||||
|
"body": {
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"name": "engine",
|
||||||
|
"label": "Engine"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"name": "browser",
|
||||||
|
"label": "Browser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"name": "platform",
|
||||||
|
"label": "Platform(s)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"name": "version",
|
||||||
|
"label": "Engine version"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"name": "grade",
|
||||||
|
"label": "CSS grade"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "html",
|
||||||
|
"html": "<p>添加其他 <span>Html 片段</span> 需要支持变量替换(todo).</p>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"level": "link",
|
||||||
|
"icon": "fa fa-ellipsis-h",
|
||||||
|
"hideCaret": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "编辑",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "编辑",
|
||||||
|
"body": "你正在编辑该卡片"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "删除",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "你删掉了该卡片"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ----------------------------- | ------------------------------------ | ----------------------------------- | ------------------------------------------------- |
|
||||||
|
| type | `string` | `"card"` | 指定为 Card 渲染器 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| href | [模板](../../docs/concepts/template) | | 外部链接 |
|
||||||
|
| header | `Object` | | Card 头部内容设置 |
|
||||||
|
| header.className | `string` | | 头部类名 |
|
||||||
|
| header.title | [模板](../../docs/concepts/template) | | 标题 |
|
||||||
|
| header.titleClassName | `string` | | 标题类名 |
|
||||||
|
| header.subTitle | [模板](../../docs/concepts/template) | | 副标题 |
|
||||||
|
| header.subTitleClassName | `string` | | 副标题类名 |
|
||||||
|
| header.subTitlePlaceholder | `string` | | 副标题占位 |
|
||||||
|
| header.description | [模板](../../docs/concepts/template) | | 描述 |
|
||||||
|
| header.descriptionClassName | `string` | | 描述类名 |
|
||||||
|
| header.descriptionPlaceholder | `string` | | 描述占位 |
|
||||||
|
| header.avatar | [模板](../../docs/concepts/template) | | 图片 |
|
||||||
|
| header.avatarClassName | `string` | `"pull-left thumb avatar b-3x m-r"` | 图片包括层类名 |
|
||||||
|
| header.imageClassName | `string` | | 图片类名 |
|
||||||
|
| header.avatarText | [模板](../../docs/concepts/template) | | 如果不配置图片,则会在图片处显示该文本 |
|
||||||
|
| header.avatarTextBackground | `Array` | | 设置文本背景色,它会根据数据分配一个颜色 |
|
||||||
|
| header.avatarTextClassName | `string` | | 图片文本类名 |
|
||||||
|
| header.highlight | `boolean` | `false` | 是否显示激活样式 |
|
||||||
|
| header.highlightClassName | `string` | | 激活样式类名 |
|
||||||
|
| header.href | [模板](../../docs/concepts/template) | | 点击卡片跳转的链接地址 |
|
||||||
|
| header.blank | `boolean` | `true` | 是否新窗口打开 |
|
||||||
|
| body | `Array` | | 内容容器,主要用来放置非表单项组件 |
|
||||||
|
| bodyClassName | `string` | | 内容区域类名 |
|
||||||
|
| actions | Array<[Action](./action)> | | 配置按钮集合 |
|
||||||
|
| actionsCount | `number` | `4` | 按钮集合每行个数 |
|
||||||
|
| itemAction | [Action](./action) | | 点击卡片的行为 |
|
||||||
|
| media | `Object` | | Card 多媒体部内容设置 |
|
||||||
|
| media.type | `'image'\|'video'` | | 多媒体类型 |
|
||||||
|
| media.url | `string` | | 图片/视频链接 |
|
||||||
|
| media.position | `'left'\|'right'\|'top'\|'bottom'` | `'left'` | 多媒体位置 |
|
||||||
|
| media.className | `string` | `"w-44 h-28"` | 多媒体类名 |
|
||||||
|
| media.isLive | `boolean` | `false` | 视频是否为直播 |
|
||||||
|
| media.autoPlay | `boolean` | `false` | 视频是否自动播放 |
|
||||||
|
| media.poster | `string` | `false` | 视频封面 |
|
||||||
|
| secondary | [模板](../../docs/concepts/template) | | 次要说明 |
|
||||||
|
| toolbar | Array<[Action](./action)> | | 工具栏按钮 |
|
||||||
|
| dragging | `boolean` | `false` | 是否显示拖拽图标 |
|
||||||
|
| selectable | `boolean` | `false` | 卡片是否可选 |
|
||||||
|
| checkable | `boolean` | `true` | 卡片选择按钮是否禁用 |
|
||||||
|
| selected | `boolean` | `false` | 卡片选择按钮是否选中 |
|
||||||
|
| hideCheckToggler | `boolean` | `false` | 卡片选择按钮是否隐藏 |
|
||||||
|
| multiple | `boolean` | `false` | 卡片是否为多选 |
|
||||||
|
| useCardLabel | `boolean` | `true` | 卡片内容区的表单项 label 是否使用 Card 内部的样式 |
|
||||||
1129
docs/zh-CN/components/cards.md
Executable file
1129
docs/zh-CN/components/cards.md
Executable file
File diff suppressed because it is too large
Load Diff
345
docs/zh-CN/components/carousel.md
Executable file
345
docs/zh-CN/components/carousel.md
Executable file
@@ -0,0 +1,345 @@
|
|||||||
|
---
|
||||||
|
title: Carousel 轮播图
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Carousel 幻灯片
|
||||||
|
icon:
|
||||||
|
order: 33
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"html": "<div style=\"width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;\">carousel data</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbMode": "contain",
|
||||||
|
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动态列表
|
||||||
|
|
||||||
|
轮播图组件目前没有获取数据的配置,因此需要依赖 `service` 来获取数据。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "service",
|
||||||
|
"api": "/api/mock2/options/carousel",
|
||||||
|
"body": {
|
||||||
|
"type": "carousel",
|
||||||
|
"name": "imageList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
目前数据关联是通过 name 的方式,因此 api 返回应该是类似这样的:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
status: 0,
|
||||||
|
msg: '',
|
||||||
|
data: {
|
||||||
|
imageList: [{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
其中的 `imageList` 要和配置的 `name` 值对应。
|
||||||
|
|
||||||
|
## 点击图片打开外部链接
|
||||||
|
|
||||||
|
> 1.3.3 及以上版本
|
||||||
|
|
||||||
|
需要放回的字段中除了前面的 image,还有 href 属性
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"imageList": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png",
|
||||||
|
"href": "https://github.com/baidu/amis"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "carousel",
|
||||||
|
"name": "imageList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义轮播图的展现
|
||||||
|
|
||||||
|
通过配置 `itemSchema` 可以自定义轮播图的展现,比如图片默认背景配置是 contain,可以改成 cover:
|
||||||
|
|
||||||
|
```
|
||||||
|
itemSchema: {
|
||||||
|
type: 'tpl',
|
||||||
|
tpl: '<div style="background-image: url("${image}"); background-size: cover; background-repeat: no-repeat; background-position: center center;" class="image ${imageClassName}"></div>'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 多图展示
|
||||||
|
|
||||||
|
> `2.8.1` 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"multiple": {count: 3},
|
||||||
|
"interval": 1000,
|
||||||
|
"duration": 5000,
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693379/8f2e79f82be0.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ---------------------------- | ----------------------------------------------------- | ---------------------- | ------------------------------------------------------- | ------- |
|
||||||
|
| type | `string` | `"carousel"` | 指定为 Carousel 渲染器 |
|
||||||
|
| className | `string` | `"panel-default"` | 外层 Dom 的类名 |
|
||||||
|
| options | `array` | `[]` | 轮播面板数据 |
|
||||||
|
| options.image | `string` | | 图片链接 |
|
||||||
|
| options.href | `string` | | 图片打开网址的链接 |
|
||||||
|
| options.imageClassName | `string` | | 图片类名 |
|
||||||
|
| options.title | `string` | | 图片标题 |
|
||||||
|
| options.titleClassName | `string` | | 图片标题类名 |
|
||||||
|
| options.description | `string` | | 图片描述 |
|
||||||
|
| options.descriptionClassName | `string` | | 图片描述类名 |
|
||||||
|
| options.html | `string` | | HTML 自定义,同[Tpl](./tpl)一致 |
|
||||||
|
| itemSchema | `object` | | 自定义`schema`来展示数据 |
|
||||||
|
| auto | `boolean` | `true` | 是否自动轮播 |
|
||||||
|
| interval | `string` | `5s` | 切换动画间隔 |
|
||||||
|
| duration | `number` | `500` | 切换动画时长(ms) |
|
||||||
|
| width | `string` | `auto` | 宽度 |
|
||||||
|
| height | `string` | `200px` | 高度 |
|
||||||
|
| controls | `array` | `['dots', 'arrows']` | 显示左右箭头、底部圆点索引 |
|
||||||
|
| controlsTheme | `string` | `light` | 左右箭头、底部圆点索引颜色,默认`light`,另有`dark`模式 |
|
||||||
|
| animation | `string` | fade | 切换动画效果,默认`fade`,另有`slide`模式,`marquee`跑马灯模式 |
|
||||||
|
| thumbMode | `string` | `"cover" \| "contain"` | 图片默认缩放模式 |
|
||||||
|
| multiple | `object` | `{count: 1}` | 多图展示,count 表示展示的数量 | `2.8.1` |
|
||||||
|
| alwaysShowArrow | `boolean` | `false` | 是否一直显示箭头,为 false 时鼠标 hover 才会显示 | `2.8.1` |
|
||||||
|
| icons | {prev: `SchemaCollection`; next: `SchemaCollection`;} | | 自定义箭头图标 | `2.8.1` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | -------------------------------------------------------------------------------- | ---------------- |
|
||||||
|
| change | `activeIndex: number` 激活图片的索引 <br /> `prevIndex: number` 上一张图片的索引 | 轮播图切换时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"html": "<div style=\"width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;\">carousel data</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbMode": "contain",
|
||||||
|
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "滚动至${activeIndex}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| ---------- | ------------------------------------ | ---------- |
|
||||||
|
| next | - | 下一张 |
|
||||||
|
| prev | - | 上一张 |
|
||||||
|
| goto-image | `activeIndex: number` 切换图片的索引 | 切换轮播图 |
|
||||||
|
|
||||||
|
### next
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "action",
|
||||||
|
"label": "下一张",
|
||||||
|
"className": "mr-3 mb-3",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "next",
|
||||||
|
"componentId": "carousel_001"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"id": "carousel_001",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"html": "<div style=\"width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;\">carousel data</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbMode": "contain",
|
||||||
|
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### prev
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "action",
|
||||||
|
"label": "上一张",
|
||||||
|
"className": "mr-3 mb-3",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "prev",
|
||||||
|
"componentId": "carousel_002"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"id": "carousel_002",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"html": "<div style=\"width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;\">carousel data</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbMode": "contain",
|
||||||
|
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### goto-image
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "action",
|
||||||
|
"label": "滚动到第三张",
|
||||||
|
"className": "mr-3 mb-3",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "goto-image",
|
||||||
|
"componentId": "carousel_003",
|
||||||
|
"args": {
|
||||||
|
"activeIndex": "${index}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "carousel",
|
||||||
|
"id": "carousel_003",
|
||||||
|
"auto": false,
|
||||||
|
"thumbMode": "cover",
|
||||||
|
"animation": "slide",
|
||||||
|
"height": 300,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"image": "https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"html": "<div style=\"width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;\">carousel data</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbMode": "contain",
|
||||||
|
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
1557
docs/zh-CN/components/chart.md
Executable file
1557
docs/zh-CN/components/chart.md
Executable file
File diff suppressed because it is too large
Load Diff
144
docs/zh-CN/components/code.md
Normal file
144
docs/zh-CN/components/code.md
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
---
|
||||||
|
title: Code 代码高亮
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Code
|
||||||
|
icon:
|
||||||
|
order: 38
|
||||||
|
---
|
||||||
|
|
||||||
|
使用代码高亮的方式来显示一段代码。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "code",
|
||||||
|
"language": "html",
|
||||||
|
"value": "<div>html</div>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 语言设置
|
||||||
|
|
||||||
|
默认语言是 html,可以通过 language 指定以下语言:
|
||||||
|
|
||||||
|
`bat`、 `c`、 `coffeescript`、 `cpp`、 `csharp`、 `css`、 `dockerfile`、 `fsharp`、 `go`、 `handlebars`、 `html`、 `ini`、 `java`、 `javascript`、 `json`、 `less`、 `lua`、 `markdown`、 `msdax`、 `objective-c`、 `php`、 `plaintext`、 `postiats`、 `powershell`、 `pug`、 `python`、 `r`、 `razor`、 `ruby`、 `sb`、 `scss`、`shell`、 `sol`、 `sql`、 `swift`、 `typescript`、 `vb`、 `xml`、 `yaml`
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"body": {
|
||||||
|
"type": "code",
|
||||||
|
"language": "javascript",
|
||||||
|
"value": "(function () {\n let amis = amisRequire('amis/embed');\n let amisJSON = {\n type: 'page',\n title: '表单页面',\n body: {\n type: 'form',\n mode: 'horizontal',\n api: '/saveForm',\n body: [\n {\n label: 'Name',\n type: 'input-text',\n name: 'name'\n },\n {\n label: 'Email',\n type: 'input-email',\n name: 'email'\n }\n ]\n }\n };\n let amisScoped = amis.embed('#root', amisJSON);\n})();"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
language 支持从上下文获取数据
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"lang": "javascript"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "code",
|
||||||
|
"language": "${lang}",
|
||||||
|
"value": "function amis() {\n console.log('amis');\n}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动态数据
|
||||||
|
|
||||||
|
可以使用 name 来从上下文来获取数据,比如
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"sourcecode": "<div>html</div>"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "code",
|
||||||
|
"language": "html",
|
||||||
|
"name": "sourcecode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
因此它还能放在表单、crud 中实现代码的展现。
|
||||||
|
|
||||||
|
## 主题及 tab 大小
|
||||||
|
|
||||||
|
通过 `editorTheme` 设置主题,`tagSize` 设置 tab 宽度
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "code",
|
||||||
|
"language": "javascript",
|
||||||
|
"tagSize": 4,
|
||||||
|
"value": "function amis() {\n\tconsole.log('amis');\n}"
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 超出换行
|
||||||
|
|
||||||
|
> 1.5.1 及以上版本
|
||||||
|
|
||||||
|
通过 `wordWrap` 设置是否折行,默认是折行
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "code",
|
||||||
|
"language": "typescript",
|
||||||
|
"tagSize": 4,
|
||||||
|
"wordWrap": false,
|
||||||
|
"value": "function amis() {\n\tconsole.log('amis')\tconsole.log('amis')\tconsole.log('amis')\tconsole.log('amis')\tconsole.log('amis')\tconsole.log('amis');\n}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 最大高度
|
||||||
|
|
||||||
|
通过配置 `maxHeight` 可以实现最大高度,超出滚动
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"body": {
|
||||||
|
"type": "code",
|
||||||
|
"language": "javascript",
|
||||||
|
"className": "b-a",
|
||||||
|
"maxHeight": 200,
|
||||||
|
"value": "(function () {\n let amis = amisRequire('amis/embed');\n let amisJSON = {\n type: 'page',\n title: '表单页面',\n body: {\n type: 'form',\n mode: 'horizontal',\n api: '/saveForm',\n body: [\n {\n label: 'Name',\n type: 'input-text',\n name: 'name'\n },\n {\n label: 'Email',\n type: 'input-email',\n name: 'email'\n }\n ]\n }\n };\n let amisScoped = amis.embed('#root', amisJSON);\n})();"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义语言高亮
|
||||||
|
|
||||||
|
还可以通过 `customLang` 参数来自定义高亮,详情参考[示例](../../../examples/code)。
|
||||||
|
|
||||||
|
`customLang` 中主要是 `tokens` 设置,这里是语言词法配置,它有 4 个配置项:
|
||||||
|
|
||||||
|
- `name`:词法名称
|
||||||
|
- `regex`:词法的正则匹配,注意因为是在字符串中,这里正则中如果遇到 `\` 需要写成 `\\`
|
||||||
|
- `regexFlags`: 可选,正则的标志参数
|
||||||
|
- `color`:颜色
|
||||||
|
- `fontStyle`: 可选,字体样式,比如 `bold` 代表加粗
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ----------- | ------------------ | ------ | ---------------------------------- |
|
||||||
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
|
| value | `string` | | 显示的颜色值 |
|
||||||
|
| name | `string` | | 在其他组件中,时,用作变量映射 |
|
||||||
|
| language | `string` | | 所使用的高亮语言,默认是 plaintext |
|
||||||
|
| tabSize | `number` | 4 | 默认 tab 大小 |
|
||||||
|
| editorTheme | `string` | 'vs' | 主题,还有 'vs-dark' |
|
||||||
|
| wordWrap | `string` | `true` | 是否折行 |
|
||||||
|
| maxHeight | `string`\|`number` | | 最大高度 |
|
||||||
403
docs/zh-CN/components/collapse.md
Normal file
403
docs/zh-CN/components/collapse.md
Normal file
@@ -0,0 +1,403 @@
|
|||||||
|
---
|
||||||
|
title: Collapse 折叠器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Collapse 折叠器
|
||||||
|
icon:
|
||||||
|
order: 36
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "3",
|
||||||
|
"header": "标题3",
|
||||||
|
"body": "这里是内容3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 手风琴模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"accordion": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "3",
|
||||||
|
"header": "标题3",
|
||||||
|
"body": "这里是内容3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义图标
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"expandIcon": {
|
||||||
|
"type": "icon",
|
||||||
|
"icon": "caret-right"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "3",
|
||||||
|
"header": "标题3",
|
||||||
|
"body": "这里是内容3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置图标位置
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"expandIconPosition": "right",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "3",
|
||||||
|
"header": "标题3",
|
||||||
|
"body": "这里是内容3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 面板嵌套
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": {
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "嵌套面板标题",
|
||||||
|
"body": "嵌套面板内容"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 折叠面板禁用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"disabled": true,
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 折叠面板图标隐藏
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"showArrow": false,
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 类FieldSet样式
|
||||||
|
|
||||||
|
当Collapse组件作为Form组件的子元素时,`enableFieldSetStyle`属性可以控制Collapse组件样式风格,开启后转换为类似[FieldSet组件](./form/fieldset)的样式,默认开启。
|
||||||
|
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "enableFieldSetStyle",
|
||||||
|
"label": "切换展示方式",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": ["1"],
|
||||||
|
"enableFieldSetStyle": "${enableFieldSetStyle}",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"header": "标题1",
|
||||||
|
"body": "这里是内容1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": "这里是内容2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "3",
|
||||||
|
"header": "标题3",
|
||||||
|
"body": "这里是内容3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## CollapseGroup 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------ | ------------------------------------------------------ | ------------------ | ----------------------------------- | --- |
|
||||||
|
| type | `string` | `"collapse-group"` | 指定为 collapse-group 渲染器 |
|
||||||
|
| activeKey | `Array<string \| number \| never> \| string \| number` | - | 初始化激活面板的 key |
|
||||||
|
| accordion | `boolean` | `false` | 手风琴模式 |
|
||||||
|
| expandIcon | `SchemaNode` | - | 自定义切换图标 |
|
||||||
|
| expandIconPosition | `string` | `"left"` | 设置图标位置,可选值`left \| right` |
|
||||||
|
| enableFieldSetStyle | `boolean` | `true` | 当Collapse作为Form组件的子元素时,开启该属性后组件样式设置为FieldSet组件的样式,默认开启 | `3.5.0` |
|
||||||
|
|
||||||
|
|
||||||
|
## CollapseGroup 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过 onEvent 来监听这些事件,并通过 actions 来配置执行的动作,在 actions 中可以通过${事件参数名}或${event.data.[事件参数名]}来获取事件产生的数据,详细查看事件动作。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
|
||||||
|
| change | `activeKeys: Array<string \| number>` 当前展开的索引列表 <br /> `collapseId: string \| number` 折叠器索引 <br/> `collapsed: boolean` 折叠器状态 | 折叠面板折叠状态改变时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
折叠面板折叠状态改变时触发。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse-group",
|
||||||
|
"activeKey": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "1",
|
||||||
|
"active": true,
|
||||||
|
"header": "标题1",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "这里是内容1",
|
||||||
|
"wrapperComponent": "",
|
||||||
|
"inline": false,
|
||||||
|
"id": "u:757ad799da08"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "u:b1b68dfbb08d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"key": "2",
|
||||||
|
"header": "标题2",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "这里是内容1",
|
||||||
|
"wrapperComponent": "",
|
||||||
|
"inline": false,
|
||||||
|
"id": "u:92caa03f227e"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "u:621a22c8b18c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "u:23e4c5ec9c89",
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"weight": 0,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"position": "top-right",
|
||||||
|
"closeButton": true,
|
||||||
|
"showIcon": true,
|
||||||
|
"title": "折叠状态改变",
|
||||||
|
"msg": "activeKeys: ${event.data.activeKeys | json}, collapseId: ${event.data.collapseId}, collapsed: ${event.data.collapsed}",
|
||||||
|
"className": "theme-toast-action-scope"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Collapse 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| --------- | ---------------------- | ------------ | ---------------------- | --- |
|
||||||
|
| type | `string` | `"collapse"` | 指定为 collapse 渲染器 |
|
||||||
|
| disabled | `boolean` | `false` | 禁用 |
|
||||||
|
| collapsed | `boolean` | `true` | 初始状态是否折叠 |
|
||||||
|
| key | `string \| number` | - | 标识 |
|
||||||
|
| header | `string \| SchemaNode` | - | 标题 |
|
||||||
|
| body | `string \| SchemaNode` | - | 内容 |
|
||||||
|
| showArrow | `boolean` | `true` | 是否展示图标 |
|
||||||
|
|
||||||
|
## Collapse 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过 onEvent 来监听这些事件,并通过 actions 来配置执行的动作,在 actions 中可以通过${事件参数名}或${event.data.[事件参数名]}来获取事件产生的数据,详细查看事件动作。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------- | ------------------------ |
|
||||||
|
| change | `collapsed: boolean` 折叠器状态 | 折叠器折叠状态改变时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
折叠面板折叠状态改变时触发。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "collapse",
|
||||||
|
"header": "标题",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "内容",
|
||||||
|
"wrapperComponent": "",
|
||||||
|
"inline": false,
|
||||||
|
"id": "u:6588c12ee3b0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "u:62aa2f0c7fd9",
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"weight": 0,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"position": "top-right",
|
||||||
|
"closeButton": true,
|
||||||
|
"showIcon": true,
|
||||||
|
"title": "collapsedChange",
|
||||||
|
"msg": "collapsed: ${event.data.collapsed}",
|
||||||
|
"className": "theme-toast-action-scope"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
95
docs/zh-CN/components/color.md
Executable file
95
docs/zh-CN/components/color.md
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
---
|
||||||
|
title: Color 颜色
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Color
|
||||||
|
icon:
|
||||||
|
order: 37
|
||||||
|
---
|
||||||
|
|
||||||
|
用于展示颜色
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "color",
|
||||||
|
"value": "#108cee"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 用作 Field 时
|
||||||
|
|
||||||
|
当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置`name`属性,映射同名变量
|
||||||
|
|
||||||
|
### Table 中的列类型
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "table",
|
||||||
|
"data": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"color": "#108cee"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"color": "#f38900"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"color": "#04c1ba"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"label": "Id"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "color",
|
||||||
|
"label": "颜色",
|
||||||
|
"type": "color"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
List 的内容、Card 卡片的内容配置同上
|
||||||
|
|
||||||
|
### Form 中静态展示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"data": {
|
||||||
|
"color": "#108cee"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static-color",
|
||||||
|
"name": "color",
|
||||||
|
"label": "颜色"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | |
|
||||||
|
| ------------------------ | --------- | ------ | -------------------------------------------------------------------------------------- | ------- |
|
||||||
|
| type | `string` | | 如果在 Table、Card 和 List 中,为`"color"`;在 Form 中用作静态展示,为`"static-color"` |
|
||||||
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
|
| value | `string` | | 显示的颜色值 |
|
||||||
|
| name | `string` | | 在其他组件中,时,用作变量映射 |
|
||||||
|
| defaultColor | `string` | | 默认颜色值 |
|
||||||
|
| showValue | `boolean` | `true` | 是否显示右边的颜色值 |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.2` |
|
||||||
143
docs/zh-CN/components/container.md
Executable file
143
docs/zh-CN/components/container.md
Executable file
@@ -0,0 +1,143 @@
|
|||||||
|
---
|
||||||
|
title: Container 容器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Container 容器
|
||||||
|
icon:
|
||||||
|
order: 38
|
||||||
|
---
|
||||||
|
|
||||||
|
Container 是一种容器组件,它可以渲染其他 amis 组件。
|
||||||
|
|
||||||
|
注意 Container 组件因为历史原因多了一层 div,推荐使用 [wrapper](wrapper) 来作为容器。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"body": "这里是容器内容区"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### style
|
||||||
|
|
||||||
|
container 可以通过 style 来设置样式,比如背景色或背景图,注意这里的属性是使用驼峰写法,是 `backgroundColor` 而不是 `background-color`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#C4C4C4"
|
||||||
|
},
|
||||||
|
"body": "这里是容器内容区"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### wrapperComponent
|
||||||
|
|
||||||
|
修改标签名可以让容器使用其它标签渲染,比如 `pre`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"wrapperComponent": "pre",
|
||||||
|
"body": "var a = 1;"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------------- | ----------------------------------------- | ------------- | ----------------------- |
|
||||||
|
| type | `string` | `"container"` | 指定为 container 渲染器 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| bodyClassName | `string` | | 容器内容区的类名 |
|
||||||
|
| wrapperComponent | `string` | `"div"` | 容器标签名 |
|
||||||
|
| style | `Object` | | 自定义样式 |
|
||||||
|
| body | [SchemaNode](../../docs/types/schemanode) | | 容器内容 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
> 3.3.0 及以上版本
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| ---------- | -------- | -------------- |
|
||||||
|
| click | - | 点击时触发 |
|
||||||
|
| mouseenter | - | 鼠标移入时触发 |
|
||||||
|
| mouseleave | - | 鼠标移出时触发 |
|
||||||
|
|
||||||
|
### click
|
||||||
|
|
||||||
|
鼠标点击。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"body": "这里是容器内容区",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### mouseenter
|
||||||
|
|
||||||
|
鼠标移入。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"body": "这里是容器内容区",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseenter": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### mouseleave
|
||||||
|
|
||||||
|
鼠标移出。可以尝试通过`${event.context.nativeEvent}`获取鼠标事件对象。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "container",
|
||||||
|
"body": "这里是容器内容区",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseleave": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "${event.context.nativeEvent.type}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
6455
docs/zh-CN/components/crud.md
Executable file
6455
docs/zh-CN/components/crud.md
Executable file
File diff suppressed because it is too large
Load Diff
189
docs/zh-CN/components/custom.md
Normal file
189
docs/zh-CN/components/custom.md
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
---
|
||||||
|
title: Custom 自定义组件
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Custom 自定义组件
|
||||||
|
icon:
|
||||||
|
order: 26
|
||||||
|
---
|
||||||
|
|
||||||
|
用于实现自定义组件,它解决了之前 JS SDK 和可视化编辑器中难以支持自定义组件的问题。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
设置 type 类型为 custom
|
||||||
|
|
||||||
|
### onMount
|
||||||
|
|
||||||
|
这是节点在初始化的时候执行的函数,它接收三个参数:
|
||||||
|
|
||||||
|
- dom,组件加载之后的 dom 节点
|
||||||
|
- data,组件初始值,需要设置 name
|
||||||
|
- onChange,修改这个组件对应 name 的值
|
||||||
|
- props,后面会单独介绍
|
||||||
|
|
||||||
|
比如在这样的 form 组件中:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
type: 'page',
|
||||||
|
title: '表单页面',
|
||||||
|
body: {
|
||||||
|
type: 'form',
|
||||||
|
title: 'custom 组件',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'custom',
|
||||||
|
name: 'myName',
|
||||||
|
label: '自定义组件',
|
||||||
|
onMount: (dom, value, onChange, props) => {
|
||||||
|
const button = document.createElement('button');
|
||||||
|
button.innerText = '点击修改';
|
||||||
|
button.onclick = event => {
|
||||||
|
// 这个 onChange 方法只有放在表单项中才能调用,第二个参数是表单项名称
|
||||||
|
onChange('new', 'myName');
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
dom.appendChild(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
点击按钮之后,执行 `onChange` 函数,就会将 `myName` 这个参数的值改成 `new`,点击表单提交的时候,就会有一个 `myName=new` 的表单数据。
|
||||||
|
|
||||||
|
### onUpdate
|
||||||
|
|
||||||
|
onUpdate 是在数据变更的时候调用,注意这个数据变更会包含表单内的所有其他组件。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
type: 'page',
|
||||||
|
title: '表单页面',
|
||||||
|
body: {
|
||||||
|
type: 'form',
|
||||||
|
title: 'custom 组件',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
name: 'email',
|
||||||
|
label: '邮箱',
|
||||||
|
type: 'input-text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'username',
|
||||||
|
label: '用户名',
|
||||||
|
type: 'input-text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'custom',
|
||||||
|
label: '自定义组件',
|
||||||
|
onUpdate: (dom, data, prevData, props) => {
|
||||||
|
console.log('data', data, prevData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这个例子中,无论是邮箱还是用户名修改,都会触发 onUpdata 函数,其中 `data` 是当前值,`prevData` 是之前的值:
|
||||||
|
|
||||||
|
1. 如果修改 email,则 data 将会是 `{email: 'xxx'}`,prevData 是 `{}`
|
||||||
|
2. 如果再次修改 email,则 data 将会是 `{email: 'xxx1'}`,prevData 是 `{email: 'xxx '}`
|
||||||
|
3. 如果修改 username,则 data 将会是 `{email: 'xxx1', username: 'yyy'}`,prevData 是 `{email: 'xxx1'}`
|
||||||
|
|
||||||
|
### onUnmount
|
||||||
|
|
||||||
|
onUnmount 是在组件销毁的时候执行,可以在这里做资源清理,这个函数只有一个 props 参数。
|
||||||
|
|
||||||
|
### Vue.js
|
||||||
|
|
||||||
|
因为 onMount 拿到的 dom 就是标准的 dom,所以可以执行任意 JavaScript 代码,包括 jQuery 等,下面的例子演示了如何使用 vue 2.0 实现自定义组件:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
type: 'page',
|
||||||
|
title: '表单页面',
|
||||||
|
body: {
|
||||||
|
type: 'form',
|
||||||
|
title: 'custom 组件',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'custom',
|
||||||
|
name: 'my-custom',
|
||||||
|
html: `
|
||||||
|
<ol>
|
||||||
|
<li v-for="todo in todos">
|
||||||
|
{{ todo.text }}
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
`,
|
||||||
|
label: '自定义组件',
|
||||||
|
onMount: (dom, data, onChange, props) => {
|
||||||
|
const app = new Vue({
|
||||||
|
el: dom,
|
||||||
|
data: {
|
||||||
|
todos: [
|
||||||
|
{ text: 'hello' },
|
||||||
|
{ text: 'world' },
|
||||||
|
{ text: 'vue' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
【温馨提示】
|
||||||
|
custom 组件中使用 vue2 语法,请先引入vue.js(umd 或 global 模块,比如:https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js) 。
|
||||||
|
同理,使用 vue3 语法请先引入 vue3 对应的 umd 或 global 模块,比如:https://unpkg.com/vue@3/dist/vue.global.js 。
|
||||||
|
|
||||||
|
### props
|
||||||
|
|
||||||
|
前面可以看到所有函数最后都有一个 props 参数,在这个参数里能拿到 amis 内部属性和方法,比如弹框
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
onMount: (dom, data, onChange, props) => {
|
||||||
|
const button = document.createElement('button');
|
||||||
|
button.innerText = '点击修改姓名';
|
||||||
|
button.onclick = event => {
|
||||||
|
onChange('new name', 'name');
|
||||||
|
props.onAction(
|
||||||
|
event,
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '弹个框',
|
||||||
|
actionType: 'dialog',
|
||||||
|
dialog: {
|
||||||
|
title: '弹框',
|
||||||
|
body: 'Hello World!'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{} // 这是 data
|
||||||
|
);
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
dom.appendChild(button);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
或者执行 `props.env.notify('success', '执行成功')` 来在右上角弹出提示等。
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | --------- | -------- | --------------------------------------------- |
|
||||||
|
| type | 'custom' | | |
|
||||||
|
| id | `string` | | 节点 id |
|
||||||
|
| name | `string` | | 节点 名称 |
|
||||||
|
| className | `string` | | 节点 class |
|
||||||
|
| inline | `boolean` | false | 默认使用 div 标签,如果 true 就使用 span 标签 |
|
||||||
|
| html | `string` | | 初始化节点 html |
|
||||||
|
| onMount | `string` | Function | 节点初始化之后调的用函数 |
|
||||||
|
| onUpdate | `string` | Function | 数据有更新的时候调用的函数 |
|
||||||
|
| onUnmount | `string` | Function | 节点销毁的时候调用的函数 |
|
||||||
193
docs/zh-CN/components/date.md
Executable file
193
docs/zh-CN/components/date.md
Executable file
@@ -0,0 +1,193 @@
|
|||||||
|
---
|
||||||
|
title: Date 日期时间
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Date
|
||||||
|
icon:
|
||||||
|
order: 39
|
||||||
|
---
|
||||||
|
|
||||||
|
用于展示日期
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "date",
|
||||||
|
"value": "1591326307"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 用作 Field 时
|
||||||
|
|
||||||
|
当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置`name`属性,映射同名变量
|
||||||
|
|
||||||
|
### Table 中的列类型
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "table",
|
||||||
|
"data": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"date": "1591326307"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"date": "1591321307"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"date": "1591322307"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"label": "Id"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
List 的内容、Card 卡片的内容配置同上
|
||||||
|
|
||||||
|
### Form 中静态展示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"data": {
|
||||||
|
"now": "1591322307"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static-date",
|
||||||
|
"name": "now",
|
||||||
|
"label": "日期",
|
||||||
|
"format": "YYYY年MM月DD日 HH时mm分ss秒"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置展示格式
|
||||||
|
|
||||||
|
例如你想将某一个时间值,以 `xxxx年xx月xx日 xx时xx分xx秒` 这样的格式输出,那么查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY年MM月DD日 HH时mm分ss秒`,即:
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"now": 1586865590
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "date",
|
||||||
|
"value": "1586865590",
|
||||||
|
"format": "YYYY年MM月DD日 HH时mm分ss秒"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置数据格式
|
||||||
|
|
||||||
|
如果你的数据值默认不是`X`格式(时间戳秒格式),那么需要配置 `valueFormat` 参数用于解析当前时间值,比如毫秒是配置 `"valueFormat": "x"`。
|
||||||
|
|
||||||
|
除此之外还支持各种自定义日期格式,例如下面`value`值为:`"2020/4/14 19:59:50"`,查阅 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知,需要配置数据格式为 `"YYYY/MM/DD HH:mm:ss"`,然后我们配置输出格式`format`,输出指定格式日期:
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "date",
|
||||||
|
"value": "2020/4/14 19:59:50",
|
||||||
|
"valueFormat": "YYYY/MM/DD HH:mm:ss",
|
||||||
|
"format": "YYYY年MM月DD日 HH时mm分ss秒"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 转成相对当前时间的描述
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "date",
|
||||||
|
"fromNow": true,
|
||||||
|
"value": "1591326307"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置展示时区
|
||||||
|
|
||||||
|
通过配置 `displayTimeZone` 参数,可以设置展示时区,默认展示当前时区。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "crud",
|
||||||
|
"api": {
|
||||||
|
"method": "get",
|
||||||
|
"url": "/whatever/api",
|
||||||
|
"mockResponse": {
|
||||||
|
"status": 200,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"date": "2023-10-27 15:00:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"type": "date",
|
||||||
|
"label": "Asia/Shanghai",
|
||||||
|
"name": "date",
|
||||||
|
"displayTimeZone": "Asia/Shanghai",
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "date",
|
||||||
|
"label": "America/Los_Angeles",
|
||||||
|
"name": "date",
|
||||||
|
"displayTimeZone": "America/Los_Angeles",
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "Asia/Tokyo",
|
||||||
|
"displayTimeZone": "Asia/Tokyo",
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| --------------- | --------- | ------------ | ------------------------------------------------------------------------------------------------------ | ----------------------- |
|
||||||
|
| type | `string` | | 如果在 Table、Card 和 List 中,为`"date"`;在 Form 中用作静态展示,为`"static-date"` |
|
||||||
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
|
| value | `string` | | 显示的日期数值 |
|
||||||
|
| name | `string` | | 在其他组件中,时,用作变量映射 |
|
||||||
|
| placeholder | `string` | `-` | 占位内容 |
|
||||||
|
| displayFormat | `string` | `YYYY-MM-DD` | 展示格式, 更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 版本号 3.4.0 及以上支持 |
|
||||||
|
| valueFormat | `string` | `X` | 数据格式,默认为时间戳。更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) |
|
||||||
|
| fromNow | `boolean` | `false` | 是否显示相对当前的时间描述,比如: 11 小时前、3 天前、1 年前等,fromNow 为 true 时,format 不生效。 |
|
||||||
|
| updateFrequency | `number` | `60000` | 更新频率, 默认为 1 分钟 |
|
||||||
|
| displayTimeZone | `string` | | 设置日期展示时区,可设置清单参考:https://gist.github.com/diogocapela/12c6617fc87607d11fd62d2a4f42b02a |
|
||||||
1287
docs/zh-CN/components/dialog.md
Executable file
1287
docs/zh-CN/components/dialog.md
Executable file
File diff suppressed because it is too large
Load Diff
71
docs/zh-CN/components/divider.md
Executable file
71
docs/zh-CN/components/divider.md
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
---
|
||||||
|
title: Divider 分割线
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Divider 分割线
|
||||||
|
icon:
|
||||||
|
order: 42
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 不同样式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "divider",
|
||||||
|
"lineStyle": "solid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider",
|
||||||
|
"lineStyle": "dashed"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 带标题的分割线
|
||||||
|
|
||||||
|
> `3.5.0`及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "divider",
|
||||||
|
"title": "Text",
|
||||||
|
"titlePosition": "left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider",
|
||||||
|
"title": "Text",
|
||||||
|
"titlePosition": "center"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider",
|
||||||
|
"title": "Text",
|
||||||
|
"titlePosition": "right"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| --------- | -------- | ------------ | --------------------------------------- |---------- |
|
||||||
|
| type | `string` | | `"divider"` 指定为 分割线 渲染器 |
|
||||||
|
| className | `string` | | 外层 Dom 的类名 |
|
||||||
|
| lineStyle | `string` | `solid` | 分割线的样式,支持`dashed`和`solid` |
|
||||||
|
| direction | `string` | `horizontal` | 分割线的方向,支持`horizontal`和`vertical` | `3.5.0` |
|
||||||
|
| color | `string` | | 分割线的颜色 | `3.5.0` |
|
||||||
|
| rotate | `number` | | 分割线的旋转角度 | `3.5.0` |
|
||||||
|
| title | [SchemaNode](../../docs/types/schemanode) | | 分割线的标题 | `3.5.0` |
|
||||||
|
| titleClassName | `string` | | 分割线的标题类名 | `3.5.0` |
|
||||||
|
| titlePosition | `string` | `center`| 分割线的标题位置,支持`left`、`center`和`right` | `3.5.0` |
|
||||||
|
|
||||||
851
docs/zh-CN/components/drawer.md
Executable file
851
docs/zh-CN/components/drawer.md
Executable file
@@ -0,0 +1,851 @@
|
|||||||
|
---
|
||||||
|
title: Drawer 抽屉
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Drawer 抽屉
|
||||||
|
icon:
|
||||||
|
order: 43
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"label": "弹出",
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "抽屉标题",
|
||||||
|
"body": "这是一个抽屉"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 多级弹框
|
||||||
|
|
||||||
|
可以嵌套使用。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "多级抽屉",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是个简单的抽屉",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "confirm",
|
||||||
|
"label": "确认",
|
||||||
|
"primary": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"label": "再弹一个",
|
||||||
|
"drawer": {
|
||||||
|
"title": "抽屉中的抽屉",
|
||||||
|
"body": "如果你想,可以继续弹下去",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"label": "来吧",
|
||||||
|
"level": "info",
|
||||||
|
"drawer": {
|
||||||
|
"title": "抽屉中的抽屉",
|
||||||
|
"body": "如果你想,可以无限弹下去",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "confirm",
|
||||||
|
"label": "不弹了",
|
||||||
|
"primary": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 指定弹出方向
|
||||||
|
|
||||||
|
通过配置 `position`,可以指定抽屉弹出的方向,可选 `left`、`right`、`top` 和 `bottom`。默认为 `right`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "左侧弹出",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "left",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个从左侧弹出的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "右侧弹出",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "right",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个从右侧弹出的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "顶部弹出",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "top",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个从顶部弹出的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "底部弹出",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "bottom",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个从底部弹出的抽屉"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 抽屉尺寸
|
||||||
|
|
||||||
|
通过设置 `size` 来控制抽屉的大小,可选值:`xs`、`sm`、`md`、`lg` 和 `xl`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "极小框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"size": "xs",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个极小的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "小框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"size": "sm",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个小抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "中框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"size": "md",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个标准的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "大框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"size": "lg",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个大抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "超大框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"size": "xl",
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个超大的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义抽屉尺寸
|
||||||
|
|
||||||
|
通过设置 `width`(`position` 为 `left` 或 `right` 时生效)和 `height`(`position` 为 `top` 或 `bottom` 时生效)来控制抽屉的尺寸。
|
||||||
|
|
||||||
|
值如果是数字类型,单位默认使用 `px`, 如果是字符串类型,可以使用自定义 css 宽度变量,如:`%`、`vw`、`px` 等。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "自定义宽度",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "right",
|
||||||
|
"width": 300,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个自定义 300px 宽度的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "自定义高度",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"position": "bottom",
|
||||||
|
"height": 300,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个自定义 300px 高度的抽屉"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 可拖拽抽屉大小
|
||||||
|
|
||||||
|
配置 `"resizable": true`,可以拖拽调整 `drawer` 大小。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "可拖拽调整大小",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"resizable": true,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个可拖拽的抽屉"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 是否展示关闭按钮
|
||||||
|
|
||||||
|
配置 `"showCloseButton": false`,可以隐藏关闭按钮。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "无关闭按钮",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个没有关闭按钮的抽屉",
|
||||||
|
"showCloseButton": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 蒙层显示
|
||||||
|
|
||||||
|
通过配置 `overlay`,来控制是否显示蒙层。默认为 `true`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "默认",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"overlay": true,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个有蒙层的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "不显示",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"overlay": false,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个没有蒙层的抽屉"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关闭方式
|
||||||
|
|
||||||
|
通过配置 `closeOnOutside`,即可在点击抽屉外部时,直接关闭抽屉。
|
||||||
|
|
||||||
|
同时可以配置 `closeOnEsc`,让抽屉支持 <kbd>Esc</kbd> 键关闭。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "点击抽屉外自动关闭(有蒙层)",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"closeOnOutside": true,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个简单的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "点击抽屉外自动关闭(无蒙层)",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"overlay": false,
|
||||||
|
"closeOnOutside": true,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个简单的抽屉"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按键关闭",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"closeOnEsc": true,
|
||||||
|
"title": "提示",
|
||||||
|
"body": "试试按下 Esc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作后关闭抽屉
|
||||||
|
|
||||||
|
在抽屉中配置行为按钮,可以在按钮上配置 `"close": true`,在行为完成后,关闭当前抽屉。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "打开",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "默认的 ajax 请求",
|
||||||
|
"actionType": "ajax",
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "ajax 请求成功后关闭抽屉",
|
||||||
|
"actionType": "ajax",
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=1",
|
||||||
|
"close": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
以上例子是关闭当前抽屉,如果希望关闭上层抽屉,则需要给目标抽屉设置 `name` 属性,然后配置按钮 `close` 属性为目标 `name` 属性如:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "多级抽屉",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是个简单的抽屉",
|
||||||
|
"name": "drawer_1",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "confirm",
|
||||||
|
"label": "确认",
|
||||||
|
"primary": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"label": "再弹一个",
|
||||||
|
"drawer": {
|
||||||
|
"title": "抽屉中的抽屉",
|
||||||
|
"body": "关闭当前抽屉时,将外层抽屉一并关闭",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "关闭所有",
|
||||||
|
"level": "info",
|
||||||
|
"close": "drawer_1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 3.3.0 及以上版本
|
||||||
|
|
||||||
|
如果是表单,可以在表单上配置 `close: false`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "弹个框",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"close": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置抽屉的按钮
|
||||||
|
|
||||||
|
默认抽屉会自动生成两个按钮,一个取消,一个确认。如果通过 `actions` 来自定义配置,则以配置的为准。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "无按钮",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "这是一个没有按钮的抽屉",
|
||||||
|
"actions": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "一个按钮",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "只有一个 OK 的抽屉",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"actionType": "confirm",
|
||||||
|
"label": "OK",
|
||||||
|
"primary": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------------- | ----------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------- |
|
||||||
|
| type | `string` | | `"drawer"` 指定为 Drawer 渲染器 |
|
||||||
|
| title | [SchemaNode](../../docs/types/schemanode) | | 弹出层标题 |
|
||||||
|
| body | [SchemaNode](../../docs/types/schemanode) | | 往 Drawer 内容区加内容 |
|
||||||
|
| size | `string` | | 指定 Drawer 大小,支持: `xs`、`sm`、`md`、`lg`、`xl` |
|
||||||
|
| position | `string` | `right` | 指定 Drawer 方向,支持: `left`、`right`、`top`、`bottom` |
|
||||||
|
| className | `string` | | Drawer 最外层容器的样式类名 |
|
||||||
|
| headerClassName | `string` | | Drawer 头部 区域的样式类名 |
|
||||||
|
| bodyClassName | `string` | `modal-body` | Drawer body 区域的样式类名 |
|
||||||
|
| footerClassName | `string` | | Drawer 页脚 区域的样式类名 |
|
||||||
|
| showCloseButton | `boolean` | `true` | 是否展示关闭按钮,当值为 `false` 时,默认开启 closeOnOutside |
|
||||||
|
| closeOnEsc | `boolean` | `false` | 是否支持按 <kbd>Esc</kbd> 关闭 Drawer |
|
||||||
|
| closeOnOutside | `boolean` | `false` | 点击内容区外是否关闭 Drawer |
|
||||||
|
| overlay | `boolean` | `true` | 是否显示蒙层 |
|
||||||
|
| resizable | `boolean` | `false` | 是否可通过拖拽改变 Drawer 大小 |
|
||||||
|
| width | `string \| number` | `500px` | 容器的宽度,在 `position` 为 `left` 或 `right` 时生效 |
|
||||||
|
| height | `string \| number` | `500px` | 容器的高度,在 `position` 为 `top` 或 `bottom` 时生效 |
|
||||||
|
| actions | Array<[Action](./action)> | 【确认】和【取消】 | 可以不设置,默认只有两个按钮。 |
|
||||||
|
| data | `object` | | 支持 [数据映射](../../docs/concepts/data-mapping),如果不设定将默认将触发按钮的上下文中继承数据。 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过 `onEvent` 来监听这些事件,并通过 `actions` 来配置执行的动作,在 `actions` 中可以通过 `${事件参数名}` 或 `${event.data.[事件参数名]}` 来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------------------------------------------------ | ------------------ |
|
||||||
|
| confirm | `event.data: object` 抽屉数据<br/>`[name]: any` 当前数据域中指定字段的值 | 点击确认提交时触发 |
|
||||||
|
| cancel | `event.data: object` 抽屉数据<br/>`[name]: any` 当前数据域中指定字段的值 | 点击取消时触发 |
|
||||||
|
|
||||||
|
### confirm
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"label": "打开",
|
||||||
|
"type": "button",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "标题",
|
||||||
|
"body": "这是一个抽屉",
|
||||||
|
"onEvent": {
|
||||||
|
"confirm": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "confirm"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### cancel
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"label": "打开",
|
||||||
|
"type": "button",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "标题",
|
||||||
|
"body": "这是一个抽屉",
|
||||||
|
"onEvent": {
|
||||||
|
"cancel": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "cancel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定 `actionType: 动作名称`、`componentId: 该组件id` 来触发这些动作,动作配置可以通过 `args: {动作配置项名称: xxx}` 来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | -------------------------- | ------------ |
|
||||||
|
| confirm | - | 确认(提交) |
|
||||||
|
| cancel | - | 取消(关闭) |
|
||||||
|
| setValue | `value: object` 更新的数据 | 更新数据 |
|
||||||
|
|
||||||
|
### confirm 动作
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "弹个表单",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "在抽屉中的表单",
|
||||||
|
"id": "drawer_confirm",
|
||||||
|
"body": {
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "username",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入用户名",
|
||||||
|
"label": "用户名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入密码"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"name": "rememberMe",
|
||||||
|
"label": "记住登录"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "触发确认",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "confirm",
|
||||||
|
"componentId": "drawer_confirm"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### cancel 动作
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "弹个表单",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "在抽屉中的表单",
|
||||||
|
"id": "drawer_cancel",
|
||||||
|
"body": {
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "username",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入用户名",
|
||||||
|
"label": "用户名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入密码"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"name": "rememberMe",
|
||||||
|
"label": "记住登录"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "触发取消",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "cancel",
|
||||||
|
"componentId": "drawer_cancel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue 动作
|
||||||
|
|
||||||
|
通过 `setValue` 更新指定抽屉的数据。
|
||||||
|
|
||||||
|
#### 合并数据
|
||||||
|
|
||||||
|
默认 `setValue` 会将新数据与目标组件数据进行合并。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "弹个表单",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "在抽屉中的表单",
|
||||||
|
"id": "drawer_setvalue",
|
||||||
|
"data": {
|
||||||
|
"username": "amis",
|
||||||
|
"password": "amis@baidu.com"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "初始化时,抽屉的数据 data 为 {username: 'amis', password: 'fex'},表单内或者表单外都可以读取这些数据,当点击【更新抽屉数据】按钮后,抽屉的数据被更新为 {username: 'aisuda', password: 'aisuda@baidu.com'}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "表单外的密码",
|
||||||
|
"name": "password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "username",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入用户名",
|
||||||
|
"label": "用户名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入密码"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "更新抽屉数据",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "drawer_setvalue",
|
||||||
|
"args": {
|
||||||
|
"value": {
|
||||||
|
"username": "aisuda",
|
||||||
|
"password": "aisuda@baidu.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 覆盖数据
|
||||||
|
|
||||||
|
可以通过 `"dataMergeMode": "override"` 来覆盖目标组件数据。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "弹个表单",
|
||||||
|
"actionType": "drawer",
|
||||||
|
"drawer": {
|
||||||
|
"title": "在抽屉中的表单",
|
||||||
|
"id": "drawer_setvalue2",
|
||||||
|
"data": {
|
||||||
|
"username": "amis",
|
||||||
|
"password": "amis@baidu.com"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "alert",
|
||||||
|
"body": "初始化时,抽屉的数据 data 为 {username: 'amis', password: 'fex'},表单内或者表单外都可以读取这些数据,当点击【更新抽屉数据】按钮后,抽屉的数据被更新为 {username: 'aisuda'},即 password 将被删除"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "表单外的密码",
|
||||||
|
"name": "password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "username",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入用户名",
|
||||||
|
"label": "用户名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码",
|
||||||
|
"required": true,
|
||||||
|
"placeholder": "请输入密码"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "更新抽屉数据",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "drawer_setvalue2",
|
||||||
|
"args": {
|
||||||
|
"value": {
|
||||||
|
"username": "aisuda"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dataMergeMode": "override"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
358
docs/zh-CN/components/dropdown-button.md
Executable file
358
docs/zh-CN/components/dropdown-button.md
Executable file
@@ -0,0 +1,358 @@
|
|||||||
|
---
|
||||||
|
title: DropDownButton 下拉菜单
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: DropDownButton
|
||||||
|
icon:
|
||||||
|
order: 44
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 分组展示模式
|
||||||
|
|
||||||
|
配置`children`可以实现分组展示,分组标题支持配置`icon`。
|
||||||
|
|
||||||
|
> 1.5.7 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"label": "RD",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "前端FE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "后端RD"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "QA",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "测试QA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "交付测试DQA",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Manager",
|
||||||
|
"icon": "fa fa-user",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "项目经理PM"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "项目管理中心PMO",
|
||||||
|
"visible": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关闭下拉菜单
|
||||||
|
|
||||||
|
配置`"closeOnClick": true`可以实现点击按钮后自动关闭下拉菜单。
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"closeOnClick": true,
|
||||||
|
"closeOnOutside": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 触发方式
|
||||||
|
|
||||||
|
> 1.4.0 及以上版本
|
||||||
|
|
||||||
|
默认是点击鼠标触发,可以通过 `"trigger": "hover"` 配置为鼠标移上去后触发
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"trigger": "hover",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置图标
|
||||||
|
|
||||||
|
通过 `icon` 可以设置左侧图标
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"trigger": "hover",
|
||||||
|
"icon": "fa fa-home",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 只显示图标
|
||||||
|
|
||||||
|
可以设置 `level` 及 `hideCaret` 来只显示图标,并配合 `tooltip` 来显示提示文字
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"level": "link",
|
||||||
|
"icon": "fa fa-ellipsis-h",
|
||||||
|
"hideCaret": true,
|
||||||
|
"tooltip": "提示",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置右侧图标
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
通过 `rightIcon` 设置右侧图标,同时通过 `hideCaret` 隐藏右侧下拉图标
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉菜单",
|
||||||
|
"trigger": "hover",
|
||||||
|
"rightIcon": "fa fa-ellipsis-v",
|
||||||
|
"hideCaret": true,
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------------- | ----------------------- | ----------------- | ----------------------------------------- |
|
||||||
|
| type | `string` | `dropdown-button` | 类型 |
|
||||||
|
| label | `string` | | 按钮文本 |
|
||||||
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
|
| btnClassName | `string` | | 按钮 CSS 类名 |
|
||||||
|
| menuClassName | `string` | | 下拉菜单 CSS 类名 |
|
||||||
|
| block | `boolean` | | 块状样式 |
|
||||||
|
| size | `string` | | 尺寸,支持`'xs'`、`'sm'`、`'md'` 、`'lg'` |
|
||||||
|
| align | `string` | | 位置,可选`'left'`或`'right'` |
|
||||||
|
| buttons | `Array<DropdownButton>` | | 配置下拉按钮 |
|
||||||
|
| iconOnly | `boolean` | | 只显示 icon |
|
||||||
|
| defaultIsOpened | `boolean` | | 默认是否打开 |
|
||||||
|
| closeOnOutside | `boolean` | `true` | 点击外侧区域是否收起 |
|
||||||
|
| closeOnClick | `boolean` | `false` | 点击按钮后自动关闭下拉菜单 |
|
||||||
|
| trigger | `click` 或 `hover` | `click` | 触发方式 |
|
||||||
|
| hideCaret | `boolean` | false | 隐藏下拉图标 |
|
||||||
|
| popOverContainerSelector | `string` | | 弹出的下拉按钮放在哪个节点下 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| ---------- | ---------------------------- | --------------------------------------- |
|
||||||
|
| mouseenter | items: Array<DropdownButton> | 触发方式为 hover 模式下,鼠标移入时触发 |
|
||||||
|
| mouseleave | items: Array<DropdownButton> | 触发方式为 hover 模式下,鼠标移出时触发 |
|
||||||
|
|
||||||
|
### mouseenter
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉按钮",
|
||||||
|
"trigger": "hover",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseenter": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "mouseenter ${event.data.items.length}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### mouseleave
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "dropdown-button",
|
||||||
|
"label": "下拉按钮",
|
||||||
|
"trigger": "hover",
|
||||||
|
"onEvent": {
|
||||||
|
"mouseleave": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "mouseleave ${event.data.items.length}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
暂无
|
||||||
225
docs/zh-CN/components/each.md
Executable file
225
docs/zh-CN/components/each.md
Executable file
@@ -0,0 +1,225 @@
|
|||||||
|
---
|
||||||
|
title: Each 循环渲染器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Each 循环渲染器
|
||||||
|
icon:
|
||||||
|
order: 45
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
通过 name 属性指定要循环的数组,items 属性指定循环的内容。
|
||||||
|
|
||||||
|
```schema: scope="page"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"arr": ["A", "B", "C"]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "each",
|
||||||
|
"name": "arr",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-default m-l-sm'>${item}</span> "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 如果是对象数组
|
||||||
|
|
||||||
|
如果数组中的数据是对象,可以直接使用内部变量 xxx 来获取,或者通过 `item.xxxx`。另外能用 index 来获取数组索引。
|
||||||
|
|
||||||
|
> 如果成员对象本身也有名字为 index 的字段就会覆盖到,获取不到索引了,请查看「循环嵌套」的章节解决
|
||||||
|
|
||||||
|
```schema:height="160" scope="page"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"arr": [{"name": "a"}, {"name": "b"}, {"name": "c"}]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "each",
|
||||||
|
"name": "arr",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-default m-l-sm'>${name}:${index}</span> "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 循环嵌套
|
||||||
|
|
||||||
|
如果存在嵌套使用,通过默认的 `item` 或者 `index` 始终是拿的最里面那层的信息,想要获取上层 each 的信息,则需要自定义 `itemKeyName` 和 `indexKeyName` 来指定字段名。
|
||||||
|
|
||||||
|
```schema:height="160" scope="page"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"arr": [{"name": "a", "subList": ["a1", "a2"]}, {"name": "b", "subList": ["b1", "b2"]}, {"name": "c", "subList": ["c1", "c2"]}]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "each",
|
||||||
|
"name": "arr",
|
||||||
|
"itemKeyName": "itemOutter",
|
||||||
|
"indexKeyName": "indexOutter",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"inline": false,
|
||||||
|
"tpl": "<span class='label label-default m-l-sm'>${name}:${index}</span> "
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "each",
|
||||||
|
"name": "subList",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-default m-l-sm'>${itemOutter.name}-${item}:${indexOutter}-${index}</span> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 用作 Field 时
|
||||||
|
|
||||||
|
当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置`name`属性,映射同名变量,然后用可以通过 `item` 变量获取单项值
|
||||||
|
|
||||||
|
### Table 中的列类型
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "table",
|
||||||
|
"data": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"each": ["A1", "B1", "C1"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"each": ["A2", "B2", "C2"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"each": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"label": "Id"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "each",
|
||||||
|
"label": "循环",
|
||||||
|
"type": "each",
|
||||||
|
"placeholder": "暂无内容",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-info m-l-sm'>${item}</span>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
List 的内容、Card 卡片的内容配置同上
|
||||||
|
|
||||||
|
### Form 中静态展示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"data": {
|
||||||
|
"each": ["A", "B", "C"]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "each",
|
||||||
|
"label": "静态展示each",
|
||||||
|
"name": "each",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-info m-l-sm'>${item}</span>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用数据映射
|
||||||
|
|
||||||
|
```schema: scope="page"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"arr": ["A", "B", "C"]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "each",
|
||||||
|
"source": "${arr}",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-default m-l-sm'>${item}</span> "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`name` 的优先级会比 `source` 更高
|
||||||
|
|
||||||
|
## 动态表单项
|
||||||
|
|
||||||
|
> 3.5.0 版本开始支持
|
||||||
|
|
||||||
|
表单项支持通过表达式配置动态表单项,可结合 `each` 组件一起使用。
|
||||||
|
|
||||||
|
```schema: scope="page"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"data": {
|
||||||
|
"arr": ["A", "B", "C"]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
type: "form",
|
||||||
|
debug: true,
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
"type": "each",
|
||||||
|
"source": "${arr}",
|
||||||
|
"items": {
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "Input${item}",
|
||||||
|
"name": "text${index}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------ | -------- | -------- | -------------------------------------------------------------------- |
|
||||||
|
| type | `string` | `"each"` | 指定为 Each 组件 |
|
||||||
|
| value | `array` | `[]` | 用于循环的值 |
|
||||||
|
| name | `string` | | 获取数据域中变量 |
|
||||||
|
| source | `string` | | 获取数据域中变量, 支持 [数据映射](../../docs/concepts/data-mapping) |
|
||||||
|
| items | `object` | | 使用`value`中的数据,循环输出渲染器。 |
|
||||||
|
| placeholder | `string` | | 当 `value` 值不存在或为空数组时的占位文本 |
|
||||||
|
| itemKeyName | `string` | `item` | 获取循环当前数组成员 |
|
||||||
|
| indexKeyName | `string` | `index` | 获取循环当前索引 |
|
||||||
521
docs/zh-CN/components/flex.md
Normal file
521
docs/zh-CN/components/flex.md
Normal file
@@ -0,0 +1,521 @@
|
|||||||
|
---
|
||||||
|
title: Flex 布局
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: Flex 布局
|
||||||
|
icon:
|
||||||
|
order: 47
|
||||||
|
---
|
||||||
|
|
||||||
|
Flex 布局是基于 CSS Flex 实现的布局效果,它比 Grid 和 HBox 对子节点位置的可控性更强,比用 CSS 类的方式更易用,并且默认使用水平垂直居中的对齐。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
其中 `items` 里的每一个都可以是其他 amis 类型。
|
||||||
|
|
||||||
|
## 子节点水平分布
|
||||||
|
|
||||||
|
> 严格来说并不一定是水平,因为还能通过 direction 修改方向,不过这里为了简化就这么称呼了
|
||||||
|
|
||||||
|
可以通过 justify 控制水平分布方式,默认是 `center` 居中,其他几种的示例如下:
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
"center",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "center",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"flex-start",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "flex-start",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"flex-end",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "flex-end",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"space-around",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "space-around",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"space-between",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "space-between",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"space-evenly",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"justify": "space-evenly",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 垂直方向位置
|
||||||
|
|
||||||
|
可以通过设置 `alignItems` 改变在子节点在垂直方向的位置,默认是 `center` 居中,其他几个常见设置请参考:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
"center",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"alignItems": "center",
|
||||||
|
"style": {
|
||||||
|
"height": 60,
|
||||||
|
"backgroundColor": "#fff"
|
||||||
|
},
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
"flex-start",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"alignItems": "flex-start",
|
||||||
|
"style": {
|
||||||
|
"height": 60,
|
||||||
|
"backgroundColor": "#fff"
|
||||||
|
},
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
"flex-end",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"alignItems": "flex-end",
|
||||||
|
"style": {
|
||||||
|
"height": 60,
|
||||||
|
"backgroundColor": "#fff"
|
||||||
|
},
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 布局方向
|
||||||
|
|
||||||
|
默认是行的方式,可以通过 "direction": "column" 改成列的方式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": [
|
||||||
|
"direction: row",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"direction: column",
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"direction": "column",
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 30,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 移动端支持
|
||||||
|
|
||||||
|
有时候希望在移动端有不同展现,比如将 `direction` 改成 `column`:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "flex",
|
||||||
|
"mobile": {
|
||||||
|
"direction": "column"
|
||||||
|
},
|
||||||
|
"items": [{
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#1A5CFF",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#46C93A",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}, {
|
||||||
|
"style": {
|
||||||
|
"backgroundColor": "#FF4757",
|
||||||
|
"width": 100,
|
||||||
|
"height": 50,
|
||||||
|
"margin": 5
|
||||||
|
},
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": ""
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
其他关于移动端定制的细节请参考[这里](../docs/extend/mobile)。
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------- | -------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
|
||||||
|
| type | `string` | `flex` | 指定为 Flex 渲染器 |
|
||||||
|
| className | `string` | | css 类名 |
|
||||||
|
| justify | `string` | | "start", "flex-start", "center", "end", "flex-end", "space-around", "space-between", "space-evenly" |
|
||||||
|
| alignItems | `string` | | "stretch", "start", "flex-start", "flex-end", "end", "center", "baseline" |
|
||||||
|
| style | `object` | | 自定义样式 |
|
||||||
|
| items[] | [SchemaNode](../docs/types/schemanode) | |
|
||||||
451
docs/zh-CN/components/form/button-group-select.md
Executable file
451
docs/zh-CN/components/form/button-group-select.md
Executable file
@@ -0,0 +1,451 @@
|
|||||||
|
---
|
||||||
|
title: Button-Group-Select 按钮点选
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Button-Group-Select
|
||||||
|
icon:
|
||||||
|
order: 6
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
按钮集合当 select 点选用。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 垂直模式
|
||||||
|
|
||||||
|
配置`"vertical": true`,实现垂直模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"vertical": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 平铺模式
|
||||||
|
|
||||||
|
配置 `"tiled": true` 实现平铺模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"tiled": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 按钮主题样式
|
||||||
|
|
||||||
|
配置 `btnLevel` 统一设置按钮主题样式,注意 `buttons ` 或 `options` 中的`level`属性优先级高于`btnLevel`。配置 `btnActiveLevel` 为按钮设置激活态时的主题样式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"btnLevel": "light",
|
||||||
|
"btnActiveLevel": "warning",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c",
|
||||||
|
"level": "primary"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持角标
|
||||||
|
|
||||||
|
按钮可支持角标,在 options 中配置
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b",
|
||||||
|
"badge": {
|
||||||
|
"mode": "text",
|
||||||
|
"text": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c",
|
||||||
|
"badge": {
|
||||||
|
"mode": "ribbon",
|
||||||
|
"text": "HOT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| -------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------- | ------- |
|
||||||
|
| type | `string` | `"button-group-select"` | 指定为 button-group-select 渲染器 |
|
||||||
|
| vertical | `boolean` | `false` | 是否使用垂直模式 |
|
||||||
|
| tiled | `boolean` | `false` | 是否使用平铺模式 |
|
||||||
|
| btnLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 按钮样式 |
|
||||||
|
| btnActiveLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 选中按钮样式 |
|
||||||
|
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
|
||||||
|
| option.badge | `object` | | [角标](../badge#属性表) | `2.8.1` |
|
||||||
|
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
|
||||||
|
| multiple | `boolean` | `false` | [多选](./options#%E5%A4%9A%E9%80%89-multiple) |
|
||||||
|
| labelField | `boolean` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
|
||||||
|
| valueField | `boolean` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
|
||||||
|
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||||
|
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||||
|
| autoFill | `object` | | [自动填充](./options#%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85-autofill) |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | ---------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 选中值变化时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.value|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
|
||||||
|
| setValue | `value: string` 更新的值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "clear_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"data": {
|
||||||
|
"abc": {
|
||||||
|
"type": "c"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "reset_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reload
|
||||||
|
|
||||||
|
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "reload_type",
|
||||||
|
"source": "/api/mock2/form/getOptions?waitSeconds=1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重新加载",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reload",
|
||||||
|
"componentId": "reload_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "button-group-select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "setvalue_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_type",
|
||||||
|
"args": {
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
59
docs/zh-CN/components/form/button-toolbar.md
Executable file
59
docs/zh-CN/components/form/button-toolbar.md
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
title: Button-Toolbar 按钮工具栏
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Button-Toolbar
|
||||||
|
icon:
|
||||||
|
order: 5
|
||||||
|
---
|
||||||
|
|
||||||
|
默认按钮会独占一行,如果想让多个按钮并排方式,可以使用 `button-toolbar` 组件包裹起来,另外还有能用 [button-group](./button-group) 来在展现上更紧凑。
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "test",
|
||||||
|
"label": "Text"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "button-toolbar",
|
||||||
|
"label": "按钮组",
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "按钮",
|
||||||
|
"actionType": "dialog",
|
||||||
|
"dialog": {
|
||||||
|
"title": "提示",
|
||||||
|
"body": "对,你刚点击了!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "submit",
|
||||||
|
"label": "提交"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "reset",
|
||||||
|
"label": "重置"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------- | --------------------------- | ------------------ | ------------------------- |
|
||||||
|
| type | `string` | `"button-toolbar"` | 指定为 ButtonToolbar 组件 |
|
||||||
|
| buttons | Array<[行为按钮](./action)> | | 按钮组 |
|
||||||
246
docs/zh-CN/components/form/chain-select.md
Executable file
246
docs/zh-CN/components/form/chain-select.md
Executable file
@@ -0,0 +1,246 @@
|
|||||||
|
---
|
||||||
|
title: Chained-Select 链式下拉框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Chained-Select
|
||||||
|
icon:
|
||||||
|
order: 7
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
用于实现无限级别下拉,只支持单选,且必须和 `source` 搭配,通过 API 拉取数据,只要 API 有返回结果,就能一直无限级别下拉。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "select3",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> `source`接口中配置的参数`waitSeconds=1`和`maxLevel=4`是测试接口所需参数,实际使用自己接口时不需要添加这两个参数
|
||||||
|
|
||||||
|
## 暴露参数
|
||||||
|
|
||||||
|
为了帮助后端接口获取当前选择器状态,chained-select 会默认给 source 接口的数据域中,添加若干个参数:
|
||||||
|
|
||||||
|
- `value`: 选中的表单项值;
|
||||||
|
- `level`: 当前拉取数据时的层级,
|
||||||
|
- `parentId`: 上一级选项的值,数据格式基于配置的`joinValues`和`extractValue`属性
|
||||||
|
- `parent`: 上一级选项的完整的数据格式
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------ | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
|
||||||
|
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
|
||||||
|
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
|
||||||
|
| autoComplete | `string`或 [API](../../../docs/types/api) | | [自动选中](./options#%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8-autocomplete) |
|
||||||
|
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
|
||||||
|
| labelField | `boolean` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
|
||||||
|
| valueField | `boolean` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
|
||||||
|
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||||
|
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | ---------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 选中值变化时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "select3",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b",
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.value|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
|
||||||
|
| setValue | `value: string` 更新的值 | 更新数据,多个值用`,`分隔 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "type",
|
||||||
|
"id": "clear_type",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "type",
|
||||||
|
"id": "reset_type",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reload
|
||||||
|
|
||||||
|
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "type",
|
||||||
|
"id": "reload_type",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重新加载",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reload",
|
||||||
|
"componentId": "reload_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "type",
|
||||||
|
"id": "setvalue_type",
|
||||||
|
"type": "chained-select",
|
||||||
|
"label": "链式下拉",
|
||||||
|
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
|
||||||
|
"value": "a,b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_type",
|
||||||
|
"args": {
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
57
docs/zh-CN/components/form/chart-radios.md
Normal file
57
docs/zh-CN/components/form/chart-radios.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
title: ChartRadios 图表单选框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: ⚙ 组件
|
||||||
|
menuName: ChartRadios 图表单选框
|
||||||
|
icon:
|
||||||
|
order: 34
|
||||||
|
---
|
||||||
|
|
||||||
|
图表点选功能,用来做多个图表联动。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "chart-radios",
|
||||||
|
name: 'main',
|
||||||
|
chartValueField: 'num',
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "A",
|
||||||
|
"num": 100,
|
||||||
|
value: 'a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "B",
|
||||||
|
"num": 120,
|
||||||
|
value: 'b'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "C",
|
||||||
|
"num": 30,
|
||||||
|
value: 'c'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "D",
|
||||||
|
"num": 40,
|
||||||
|
value: 'd'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 ## 二级标题 |
|
||||||
|
| ---------------------- | --------- | --------- | -------------------------- |
|
||||||
|
| config | `object` | | echart 图表配置 |
|
||||||
|
| showTooltipOnHighlight | `boolean` | `false` | 高亮的时候是否显示 tooltip |
|
||||||
|
| chartValueField | `string` | `"value"` | 图表数值字段名 |
|
||||||
254
docs/zh-CN/components/form/checkbox.md
Executable file
254
docs/zh-CN/components/form/checkbox.md
Executable file
@@ -0,0 +1,254 @@
|
|||||||
|
---
|
||||||
|
title: Checkbox 勾选框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Checkbox
|
||||||
|
icon:
|
||||||
|
order: 8
|
||||||
|
---
|
||||||
|
|
||||||
|
用于实现勾选,功能和 [Switch](./switch) 类似,只是展现上不同。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkbox",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "勾选框",
|
||||||
|
"option": "选项说明"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置真假值
|
||||||
|
|
||||||
|
默认情况:
|
||||||
|
|
||||||
|
- 勾选框勾选时,表单项值为:true
|
||||||
|
- 勾选框取消勾选时,表单项值为:false
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkbox",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "勾选框",
|
||||||
|
"option": "选项说明"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你想调整这个值,可以配置`trueValue`和`falseValue`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkbox",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "勾选框",
|
||||||
|
"option": "选项说明",
|
||||||
|
"trueValue": 1,
|
||||||
|
"falseValue": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
勾选上例中的勾选框,观察数据域变化,会发现勾选后值为`1`,而取消勾选后为`0`
|
||||||
|
|
||||||
|
## 按钮模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkbox",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "勾选框",
|
||||||
|
"trueValue": true,
|
||||||
|
"falseValue": false,
|
||||||
|
"optionType": "button",
|
||||||
|
"option": "选项说明"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------- | ------------------------- | --------- | ---------------- |
|
||||||
|
| option | `string` | | 选项说明 |
|
||||||
|
| trueValue | `string|number|boolean` | `true` | 标识真值 |
|
||||||
|
| falseValue | `string|number|boolean` | `false` | 标识假值 |
|
||||||
|
| optionType | `default|button` | `default` | 设置 option 类型 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | -------------------------- | ------------------ |
|
||||||
|
| change | `[name]: boolean` 组件的值 | 选中状态变化时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkbox",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "勾选框",
|
||||||
|
"option": "选项说明",
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.value|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string \|number \|boolean` 更新的值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "clear_type",
|
||||||
|
"option": "选项说明",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "reset_type",
|
||||||
|
"option": "选项说明",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "setvalue_type",
|
||||||
|
"option": "选项说明",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_type",
|
||||||
|
"args": {
|
||||||
|
"value": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
864
docs/zh-CN/components/form/checkboxes.md
Executable file
864
docs/zh-CN/components/form/checkboxes.md
Executable file
@@ -0,0 +1,864 @@
|
|||||||
|
---
|
||||||
|
title: Checkboxes 复选框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Checkboxes
|
||||||
|
icon:
|
||||||
|
order: 9
|
||||||
|
---
|
||||||
|
|
||||||
|
用于实现多选。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 结果是数组模式
|
||||||
|
|
||||||
|
默认是拼接成字符串,如果希望结果是数组,可以设置 `"joinValues": false`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"joinValues": false,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果只想提取 value,需要加上 `"extractValue": true`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"joinValues": false,
|
||||||
|
"extractValue": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示全选
|
||||||
|
|
||||||
|
通过 `checkAll` 属性配置全选
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"checkAll": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 按钮模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"optionType": "button",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 按列显示
|
||||||
|
|
||||||
|
设置 `"inline": false`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"inline": false,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 展示多行
|
||||||
|
|
||||||
|
可以配置`columnsCount`属性调整展示列的个数
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes1",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "默认的复选框",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "checkboxes2",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "显示两列的复选框",
|
||||||
|
"columnsCount": 2,
|
||||||
|
"inline": false,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 1.8.0 及以上版本
|
||||||
|
|
||||||
|
`columnsCount` 还有一种数组形式,可以手动控制每行显示的列数
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes1",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "默认的复选框",
|
||||||
|
"columnsCount": [1, 2, 3],
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionE",
|
||||||
|
"value": "e"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionF",
|
||||||
|
"value": "f"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 分组显示
|
||||||
|
|
||||||
|
`"inline": false` 下,选项中配置 `children` 字段可以实现分组展示效果。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkboxes",
|
||||||
|
"name": "checkboxes",
|
||||||
|
"label": "城市选择",
|
||||||
|
"inline": false,
|
||||||
|
"checkAll": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "A类型",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "选项 A-1",
|
||||||
|
"value": "a-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "选项 A-2",
|
||||||
|
"value": "a-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "B类型",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "选项 B-1",
|
||||||
|
"value": "b-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "选项 B-2",
|
||||||
|
"value": "b-2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "选项 B-3",
|
||||||
|
"value": "b-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "选项 B-4",
|
||||||
|
"value": "b-4"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义选项渲染
|
||||||
|
|
||||||
|
> 2.0.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"menuTpl": "<span class='label label-${klass}'>${label}</span>",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a",
|
||||||
|
"klass": "success"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b",
|
||||||
|
"klass": "danger"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c",
|
||||||
|
"klass": "warning"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d",
|
||||||
|
"klass": "info"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------------- | ----------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| options | `Array<object>`或`Array<string>` | | [选项组](./#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
|
||||||
|
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
|
||||||
|
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
|
||||||
|
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
|
||||||
|
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
|
||||||
|
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||||
|
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||||
|
| columnsCount | `number` | `1` | 选项按几列显示,默认为一列 |
|
||||||
|
| menuTpl | `string` | | 支持自定义选项渲染 |
|
||||||
|
| checkAll | `boolean` | `false` | 是否支持全选 |
|
||||||
|
| inline | `boolean` | `true` | 是否显示为一行 |
|
||||||
|
| defaultCheckAll | `boolean` | `false` | 默认是否全选 |
|
||||||
|
| creatable | `boolean` | `false` | [新增选项](./options#%E5%89%8D%E7%AB%AF%E6%96%B0%E5%A2%9E-creatable) |
|
||||||
|
| createBtnLabel | `string` | `"新增选项"` | [新增选项](./options#%E6%96%B0%E5%A2%9E%E9%80%89%E9%A1%B9) |
|
||||||
|
| addControls | Array<[表单项](./formitem)> | | [自定义新增表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B0%E5%A2%9E%E8%A1%A8%E5%8D%95%E9%A1%B9-addcontrols) |
|
||||||
|
| addApi | [API](../../docs/types/api) | | [配置新增选项接口](./options#%E9%85%8D%E7%BD%AE%E6%96%B0%E5%A2%9E%E6%8E%A5%E5%8F%A3-addapi) |
|
||||||
|
| editable | `boolean` | `false` | [编辑选项](./options#%E5%89%8D%E7%AB%AF%E7%BC%96%E8%BE%91-editable) |
|
||||||
|
| editControls | Array<[表单项](./formitem)> | | [自定义编辑表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BC%96%E8%BE%91%E8%A1%A8%E5%8D%95%E9%A1%B9-editcontrols) |
|
||||||
|
| editApi | [API](../../docs/types/api) | | [配置编辑选项接口](./options#%E9%85%8D%E7%BD%AE%E7%BC%96%E8%BE%91%E6%8E%A5%E5%8F%A3-editapi) |
|
||||||
|
| removable | `boolean` | `false` | [删除选项](./options#%E5%88%A0%E9%99%A4%E9%80%89%E9%A1%B9) |
|
||||||
|
| deleteApi | [API](../../docs/types/api) | | [配置删除选项接口](./options#%E9%85%8D%E7%BD%AE%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3-deleteapi) |
|
||||||
|
| optionType | `default` \| `button` | `default` | 按钮模式 |
|
||||||
|
| itemClassName | `string` | | 选项样式类名 |
|
||||||
|
| labelClassName | `string` | | 选项标签样式类名 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------------------------------- | ----------------------------------------------------------------------------------------- | ------------------ |
|
||||||
|
| change | `[name]: string` 选中值 | 选中值变化时触发 |
|
||||||
|
| addConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 新增的节点信息<br/>`items: object[]`选项集合 | 新增节点提交时触发 |
|
||||||
|
| editConfirm (3.6.4 及以上版本) | `[name]: object` 组件的值<br/>`item: object` 编辑的节点信息<br/>`items: object[]`选项集合 | 编辑节点提交时触发 |
|
||||||
|
| deleteConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 删除的节点信息<br/>`items: object[]`选项集合 | 删除节点提交时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.value}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### addConfirm
|
||||||
|
|
||||||
|
配置 `creatable`后,可监听确认新增操作。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"creatable": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"addConfirm": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.item|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### editConfirm
|
||||||
|
|
||||||
|
配置 `editable`后,可监听确认编辑操作。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"editable": true,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "OptionA",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionB",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionC",
|
||||||
|
"value": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "OptionD",
|
||||||
|
"value": "d"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"editConfirm": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.item|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### deleteConfirm
|
||||||
|
|
||||||
|
配置 `removable`后,可监听确认删除操作。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "checkboxes",
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "复选框",
|
||||||
|
"removable": true,
|
||||||
|
"labelField": "label2",
|
||||||
|
"valueField": "value2",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label2": "OptionA",
|
||||||
|
"value2": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label2": "OptionB",
|
||||||
|
"value2": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label2": "OptionC",
|
||||||
|
"value2": "c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label2": "OptionD",
|
||||||
|
"value2": "d"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onEvent": {
|
||||||
|
"deleteConfirm": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.item|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
|
||||||
|
| setValue | `value: string` 更新的值 | 更新数据,多个值用`,`分隔 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "clear_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "reset_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reload
|
||||||
|
|
||||||
|
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "reload_type",
|
||||||
|
"source": "/api/mock2/form/getOptions?waitSeconds=1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重新加载",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reload",
|
||||||
|
"componentId": "reload_type"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "checkboxes",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "type",
|
||||||
|
"id": "setvalue_type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Option A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Option C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_type",
|
||||||
|
"args": {
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
2010
docs/zh-CN/components/form/combo.md
Executable file
2010
docs/zh-CN/components/form/combo.md
Executable file
File diff suppressed because it is too large
Load Diff
1477
docs/zh-CN/components/form/condition-builder.md
Normal file
1477
docs/zh-CN/components/form/condition-builder.md
Normal file
File diff suppressed because it is too large
Load Diff
78
docs/zh-CN/components/form/control.md
Normal file
78
docs/zh-CN/components/form/control.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
title: Control 表单项包裹
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Control
|
||||||
|
icon:
|
||||||
|
order: 24
|
||||||
|
---
|
||||||
|
|
||||||
|
展示类的组件,如果直接放在表单项里面,不会有 `label` 和 `description` 之类的信息展示。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本输入"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "image",
|
||||||
|
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "qr-code",
|
||||||
|
"codeSize": 128,
|
||||||
|
"backgroundColor": "#108cee",
|
||||||
|
"foregroundColor": "#000",
|
||||||
|
"value": "https://www.baidu.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果想像文本输入框一样,可以配置 `label` 和 `description`,则可以通过这个组件包裹一下。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本输入"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "control",
|
||||||
|
"label": "图片",
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
"type": "image",
|
||||||
|
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "control",
|
||||||
|
"label": "二维码",
|
||||||
|
"description": "还可以来点描述",
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
"type": "qr-code",
|
||||||
|
"codeSize": 128,
|
||||||
|
"backgroundColor": "#108cee",
|
||||||
|
"foregroundColor": "#000",
|
||||||
|
"value": "https://www.baidu.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
245
docs/zh-CN/components/form/diff-editor.md
Executable file
245
docs/zh-CN/components/form/diff-editor.md
Executable file
@@ -0,0 +1,245 @@
|
|||||||
|
---
|
||||||
|
title: DiffEditor 对比编辑器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: DiffEditor 对比编辑器
|
||||||
|
icon:
|
||||||
|
order: 17
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 禁用编辑器
|
||||||
|
|
||||||
|
左侧编辑器始终不可编辑,右侧编辑器可以通过设置`disabled`或`disabledOn`,控制是否禁用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello",
|
||||||
|
"disabledOn": "this.isDisabled"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "isDisabled",
|
||||||
|
"label": "是否禁用"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## diff 数据域中的两个变量
|
||||||
|
|
||||||
|
如下例,左侧编辑器中的值,通过`"diffValue": "${value1}"`获取,右侧编辑器的值,通过设置`"name": "value2"`,自动映射数据域中`value2`的值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"data": {
|
||||||
|
"value1": "hello world",
|
||||||
|
"value2": "hello wrold"
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "value2",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "${value1}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | ------------- | ------------ | ------------------------------------------------------------------------------------------- |
|
||||||
|
| language | `string` | `javascript` | 编辑器高亮的语言,可选 [支持的语言](./editor#%E6%94%AF%E6%8C%81%E7%9A%84%E8%AF%AD%E8%A8%80) |
|
||||||
|
| diffValue | [Tpl](../tpl) | | 左侧值 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | ------------------------ |
|
||||||
|
| change | `[name]: string` 组件的值 | 代码变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 右侧输入框获取焦点时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 右侧输入框失去焦点时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| focus | - | 获取焦点,焦点落在右侧编辑面板 |
|
||||||
|
| setValue | `value: string` 更新的右侧编辑面板中的值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"id": "clear_text",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"id": "reset_text",
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### focus
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"id": "focus_text",
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "聚焦",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "focus",
|
||||||
|
"componentId": "focus_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"type": "diff-editor",
|
||||||
|
"name": "diff",
|
||||||
|
"label": "Diff-Editor",
|
||||||
|
"diffValue": "hello world",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": "amis go go go!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
322
docs/zh-CN/components/form/editor.md
Executable file
322
docs/zh-CN/components/form/editor.md
Executable file
@@ -0,0 +1,322 @@
|
|||||||
|
---
|
||||||
|
title: Editor 编辑器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Editor
|
||||||
|
icon:
|
||||||
|
order: 19
|
||||||
|
---
|
||||||
|
|
||||||
|
用于实现代码编辑,如果要实现富文本编辑请使用 [Rich-Text](./input-rich-text)。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
placeholder: "function() {\n console.log('hello world')\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持的语言
|
||||||
|
|
||||||
|
可以设置`language`配置高亮的语言,支持的语言有:
|
||||||
|
|
||||||
|
`bat`、 `c`、 `coffeescript`、 `cpp`、 `csharp`、 `css`、 `dockerfile`、 `fsharp`、 `go`、 `handlebars`、 `html`、 `ini`、 `java`、 `javascript`、 `json`、 `less`、 `lua`、 `markdown`、 `msdax`、 `objective-c`、 `php`、 `plaintext`、 `postiats`、 `powershell`、 `pug`、 `python`、 `r`、 `razor`、 `ruby`、 `sb`、 `scss`、`shell`、 `sol`、 `sql`、 `swift`、 `typescript`、 `vb`、 `xml`、 `yaml`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "JSON编辑器",
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 因为性能原因,上面的例子不支持实时修改 language 生效
|
||||||
|
|
||||||
|
当然你也可以使用`xxx-editor`这种形式,例如`"type": "json-editor"`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "json-editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "JSON编辑器"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 只读模式
|
||||||
|
|
||||||
|
使用 `disabled: true`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "json-editor",
|
||||||
|
"name": "editor",
|
||||||
|
"disabled": true,
|
||||||
|
"label": "JSON编辑器"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 全屏模式
|
||||||
|
|
||||||
|
设置`allowFullscreen`属性为`true`,显示编辑器的全屏模式开关,开关开启后编辑器进入全屏模式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "支持全屏模式的编辑器",
|
||||||
|
"allowFullscreen": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 编辑器展现控制
|
||||||
|
|
||||||
|
通过 `options` 来控制编辑器展现,比如下面的配置可以关闭行号
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"options": {
|
||||||
|
"lineNumbers": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 编辑器自定义开发
|
||||||
|
|
||||||
|
amis 的编辑器是基于 monaco 开发的,如果想进行深度定制,比如自动完成功能,可以通过自定义 `editorDidMount` 属性来获取到 monaco 实例,它有两种写法,一种是在 JS 中直接用函数,示例如下:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"language": "myLan",
|
||||||
|
"editorDidMount": (editor, monaco) => {
|
||||||
|
// editor 是 monaco 实例,monaco 是全局的名称空间
|
||||||
|
const dispose = monaco.languages.registerCompletionItemProvider('myLan', {
|
||||||
|
/// 其他细节参考 monaco 手册
|
||||||
|
});
|
||||||
|
|
||||||
|
// 如果返回一个函数,这个函数会在编辑器组件卸载的时候调用,主要用于清理资源
|
||||||
|
return dispose;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------------- | --------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| language | `string` | `javascript` | 编辑器高亮的语言,支持通过 `${xxx}` 变量获取 |
|
||||||
|
| size | `string` | `md` | 编辑器高度,取值可以是 `md`、`lg`、`xl`、`xxl` |
|
||||||
|
| allowFullscreen | `boolean` | `false` | 是否显示全屏模式开关 |
|
||||||
|
| options | `object` | | monaco 编辑器的其它配置,比如是否显示行号等,请参考[这里](https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IEditorOptions.html),不过无法设置 readOnly,只读模式需要使用 `disabled: true` |
|
||||||
|
| placeholder | `string` | | 占位描述,没有值的时候展示 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 代码变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| focus | - | 获取焦点 |
|
||||||
|
| setValue | `value: string` 更新的值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"id": "clear_text",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"id": "reset_text",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### focus
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"id": "focus_text",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "聚焦",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "focus",
|
||||||
|
"componentId": "focus_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "editor",
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"name": "editor",
|
||||||
|
"label": "编辑器",
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": "amis go go go!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
245
docs/zh-CN/components/form/fieldset.md
Executable file
245
docs/zh-CN/components/form/fieldset.md
Executable file
@@ -0,0 +1,245 @@
|
|||||||
|
---
|
||||||
|
title: FieldSet 表单项集合
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: FieldSet
|
||||||
|
icon:
|
||||||
|
order: 20
|
||||||
|
---
|
||||||
|
|
||||||
|
FieldSet 是用于分组展示表单项的一种容器型组件,可以折叠。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
可以通过配置标题`title`和表单项数组`body`,实现多个表单项分组展示
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 展示模式
|
||||||
|
|
||||||
|
可以通过设置`mode`调整展示模式,用法同 [Form 展示模式](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA)
|
||||||
|
|
||||||
|
下面`group`我们配置了`"mode": "horizontal"`,观察显示情况
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text",
|
||||||
|
"label": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 可折叠
|
||||||
|
|
||||||
|
配置`"collapsable": true`可以实现点击标题折叠显隐表单项。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"collapsable": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 默认是否折叠
|
||||||
|
|
||||||
|
默认是展开的,如果想默认折叠,那么配置`"collapsed": true`默认折叠。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"collapsable": true,
|
||||||
|
"collapsed": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 标题放底部
|
||||||
|
|
||||||
|
fieldSet 的另一种标题展现样式,不同的是展开的时候收起文本是在下方的,如果组件比较多的时候更容易收起。
|
||||||
|
|
||||||
|
设置 `"titlePosition": "bottom"`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "展开更多设置",
|
||||||
|
"collapseTitle": "收起设置",
|
||||||
|
"titlePosition": "bottom",
|
||||||
|
"collapsable": true,
|
||||||
|
"collapsed": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 嵌套使用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"collapsable": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "fieldSet",
|
||||||
|
"title": "基本配置",
|
||||||
|
"collapsable": true,
|
||||||
|
"collapsed": true,
|
||||||
|
size: 'base',
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "text1",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "text2",
|
||||||
|
"type": "input-text",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------------- | -------------------------------------------- | ------- | -------------------------------------------------------------------------- |
|
||||||
|
| className | `string` | | CSS 类名 |
|
||||||
|
| headingClassName | `string` | | 标题 CSS 类名 |
|
||||||
|
| bodyClassName | `string` | | 内容区域 CSS 类名 |
|
||||||
|
| title | [SchemaNode](../../../docs/types/schemanode) | | 标题 |
|
||||||
|
| body | Array<[表单项](./formitem)> | | 表单项集合 |
|
||||||
|
| mode | `string` | | 展示默认,同 [Form](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA) 中的模式 |
|
||||||
|
| collapsable | `boolean` | `false` | 是否可折叠 |
|
||||||
|
| collapsed | `booelan` | `false` | 默认是否折叠 |
|
||||||
|
| collapseTitle | [SchemaNode](../../../docs/types/schemanode) | `收起` | 收起的标题 |
|
||||||
|
| size | string | `` | 大小,支持 xs、sm、base、md、lg |
|
||||||
1864
docs/zh-CN/components/form/formitem.md
Executable file
1864
docs/zh-CN/components/form/formitem.md
Executable file
File diff suppressed because it is too large
Load Diff
255
docs/zh-CN/components/form/formula.md
Executable file
255
docs/zh-CN/components/form/formula.md
Executable file
@@ -0,0 +1,255 @@
|
|||||||
|
---
|
||||||
|
title: Formula 公式
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Formula
|
||||||
|
icon:
|
||||||
|
order: 22
|
||||||
|
---
|
||||||
|
|
||||||
|
可以设置公式,将公式结果设置到指定表单项上。
|
||||||
|
|
||||||
|
> 该表单项是隐藏的
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "a",
|
||||||
|
"label": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "b",
|
||||||
|
"label": "B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "sum",
|
||||||
|
"label": "和",
|
||||||
|
"disabled": true,
|
||||||
|
"description": "自动计算 A + B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "sum",
|
||||||
|
"value": 0,
|
||||||
|
"formula": "a + b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自动应用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "a",
|
||||||
|
"label": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "b",
|
||||||
|
"label": "B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "sum",
|
||||||
|
"label": "和",
|
||||||
|
"disabled": true,
|
||||||
|
"description": "自动计算 A + B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "sum",
|
||||||
|
"value": 0,
|
||||||
|
"formula": "a + b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 手动应用
|
||||||
|
|
||||||
|
配置`"autoSet": false`,然后按钮上配置`target`,配置值为`formula`的`id`值,就可以实现手动触发公式应用
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "a",
|
||||||
|
"label": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "b",
|
||||||
|
"label": "B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "sum",
|
||||||
|
"label": "和",
|
||||||
|
"disabled": true,
|
||||||
|
"columnClassName": "col-sm-11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "计算",
|
||||||
|
"columnClassName": "col-sm-1 v-bottom",
|
||||||
|
"target": "theFormula"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "sum",
|
||||||
|
"id": "theFormula",
|
||||||
|
"value": 0,
|
||||||
|
"formula": "a + b",
|
||||||
|
"initSet": false,
|
||||||
|
"autoSet": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 为什么设置`id`而不是设置`name`?
|
||||||
|
>
|
||||||
|
> 因为`name`值已经用来设置目标变量名了,这个表单项肯定已经存在了,所以不是唯一了,不能够被按钮指定。
|
||||||
|
|
||||||
|
## 条件应用
|
||||||
|
|
||||||
|
可以配置`condition`用来指定作用条件,有两种写法:
|
||||||
|
|
||||||
|
- 用 tpl 语法,把关联的字段写上如: `${xxx} ${yyy}` 意思是当 xxx 和 yyy 的取值结果变化了就再应用一次公式结果。
|
||||||
|
- 自己写判断如: `this.xxx == "a" && this.xxx !== this.__prev.xxx` 当 xxx 变化了,且新的值是字符 "a" 时应用,可以写更加复杂的判断。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "radios",
|
||||||
|
"name": "radios",
|
||||||
|
"label": "radios",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "a",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "b",
|
||||||
|
"value": "b"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "radios 变化会自动清空 B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "b",
|
||||||
|
"label": "B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "b",
|
||||||
|
"value": "some string",
|
||||||
|
"formula": "''",
|
||||||
|
"condition": "${radios}",
|
||||||
|
"initSet": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用新表达式语法
|
||||||
|
|
||||||
|
> 1.5.0 及以上版本
|
||||||
|
|
||||||
|
通过新的[表达式](../../../docs/concepts/expression)语法,可以调用其中的函数,比如
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static",
|
||||||
|
"value": "这个表单没有内容,通过上面的 debug 可以看到输出当前日期"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "date",
|
||||||
|
"formula": "${DATETOSTR(NOW(), 'YYYY-MM-DD')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这种写法默认会解决浮点数计算问题(需要更新到 amis 1.6.4 及以上版本),比如
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "a",
|
||||||
|
"value": 0.1,
|
||||||
|
"label": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "b",
|
||||||
|
"value": 0.2,
|
||||||
|
"label": "B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "sum",
|
||||||
|
"label": "直接相加",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "sum",
|
||||||
|
"formula": "a + b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "sum-new",
|
||||||
|
"label": "使用新表达式",
|
||||||
|
"disabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "formula",
|
||||||
|
"name": "sum-new",
|
||||||
|
"formula": "${a + b}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | ------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| name | `string` | | 需要应用的表单项`name`值,公式结果将作用到此处指定的变量中去。 |
|
||||||
|
| formula | [表达式](../../../docs/concepts/expression) | | 应用的公式 |
|
||||||
|
| condition | [表达式](../../../docs/concepts/expression) | | 公式作用条件 |
|
||||||
|
| initSet | `boolean` | `true` | 初始化时是否设置 |
|
||||||
|
| autoSet | `boolean` | `true` | 观察公式结果,如果计算结果有变化,则自动应用到变量上 |
|
||||||
|
| id | `string` | | 定义个名字,当某个按钮的目标指定为此值后,会触发一次公式应用。这个机制可以在 `autoSet` 为 false 时用来手动触发 |
|
||||||
232
docs/zh-CN/components/form/group.md
Executable file
232
docs/zh-CN/components/form/group.md
Executable file
@@ -0,0 +1,232 @@
|
|||||||
|
---
|
||||||
|
title: Group 表单项组
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Group
|
||||||
|
icon:
|
||||||
|
order: 24
|
||||||
|
---
|
||||||
|
|
||||||
|
表单项,默认都是一行显示一个,Group 组件用于在一行展示多个表单项,会自动根据表单项数量均分宽度。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text3",
|
||||||
|
"label": "文本3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text4",
|
||||||
|
"label": "文本4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text5",
|
||||||
|
"label": "文本5"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 展示
|
||||||
|
|
||||||
|
可以给`group`组件设置`mode`调整展示模式,用法同 [Form 展示](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA)
|
||||||
|
|
||||||
|
下面`group`我们配置了`"mode": "horizontal"`,观察显示情况
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text",
|
||||||
|
"label": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": "文本1"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": "文本2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
当表单在水平模式下时,如果`group`内表单项设置`"label": false`,会导致布局错乱,如下
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text",
|
||||||
|
"label": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这时可以给`group`配置`label`属性,保持和其他表单项布局统一
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text",
|
||||||
|
"label": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"label": "文本组",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 宽度占比
|
||||||
|
|
||||||
|
在表单项内部可以通过 `columnRatio` 来控制宽度,整体是 12 等分
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": "text1",
|
||||||
|
"columnRatio": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": "text2",
|
||||||
|
"columnRatio": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text1",
|
||||||
|
"label": "text1",
|
||||||
|
"columnRatio": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text2",
|
||||||
|
"label": "text2",
|
||||||
|
"columnRatio": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text3",
|
||||||
|
"label": "text3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| --------- | --------------------------- | -------------- | -------------------------------------------------------------------------- |
|
||||||
|
| className | `string` | | CSS 类名 |
|
||||||
|
| label | `string` | | group 的标签 |
|
||||||
|
| body | Array<[表单项](./formitem)> | | 表单项集合 |
|
||||||
|
| mode | `string` | | 展示默认,同 [Form](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA) 中的模式 |
|
||||||
|
| gap | `string` | | 表单项之间的间距,可选:`xs`、`sm`、`normal` |
|
||||||
|
| direction | `string` | `"horizontal"` | 可以配置水平展示还是垂直展示。对应的配置项分别是:`vertical`、`horizontal` |
|
||||||
38
docs/zh-CN/components/form/hidden.md
Executable file
38
docs/zh-CN/components/form/hidden.md
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
title: Hidden 隐藏字段
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Hidden 隐藏字段
|
||||||
|
icon:
|
||||||
|
order: 26
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
默认表单提交,在没有 [自定义 API 请求数据](../../../docs/types/api#%E9%85%8D%E7%BD%AE%E8%AF%B7%E6%B1%82%E6%95%B0%E6%8D%AE) 的情况下,只会发送 `body` 里面的这些成员,对于隐藏的字段同时又希望提交表单的时候带过去,可以使用 `hidden` 组件
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "hidden",
|
||||||
|
"name": "id",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "name",
|
||||||
|
"label": "姓名:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "input-email",
|
||||||
|
"label": "邮箱:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
2599
docs/zh-CN/components/form/index.md
Executable file
2599
docs/zh-CN/components/form/index.md
Executable file
File diff suppressed because it is too large
Load Diff
75
docs/zh-CN/components/form/input-array.md
Executable file
75
docs/zh-CN/components/form/input-array.md
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
---
|
||||||
|
title: InputArray 数组输入框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputArray 数组输入框
|
||||||
|
icon:
|
||||||
|
order: 3
|
||||||
|
---
|
||||||
|
|
||||||
|
InputArray 是一种简化的 [Combo](./combo),用于输入多个某种类型的[表单项](./formitem),提交的时将以数组的形式提交。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="form2"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "array",
|
||||||
|
"label": "颜色集合",
|
||||||
|
"type": "input-array",
|
||||||
|
"value": ["red"],
|
||||||
|
"inline": true,
|
||||||
|
"items": {
|
||||||
|
"type": "input-color",
|
||||||
|
"clearable": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 新增成员默认值
|
||||||
|
|
||||||
|
部分情况下,期望新增元素时使用默认值,这时可以通过设置`scaffold`属性配置新增成员的默认值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"debugConfig": {
|
||||||
|
"levelExpand": 2
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "array",
|
||||||
|
"label": "整数集合",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "input-array",
|
||||||
|
"value": [123, 456],
|
||||||
|
"scaffold": 0,
|
||||||
|
"inline": true,
|
||||||
|
"items": {
|
||||||
|
"type": "input-number",
|
||||||
|
"clearable": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------ |
|
||||||
|
| type | `string` | `"input-array"` | 指明为`array`组件 |
|
||||||
|
| items | [`SchemaNode`](../../docs/types/schemanode) | | 配置单项表单类型 |
|
||||||
|
| addable | `boolean` | | 是否可新增。 |
|
||||||
|
| removable | `boolean` | | 是否可删除 |
|
||||||
|
| draggable | `boolean` | `false` | 是否可以拖动排序, 需要注意的是当启用拖动排序的时候,会多一个\$id 字段 |
|
||||||
|
| draggableTip | `string` | | 可拖拽的提示文字,默认为:`"可通过拖动每行中的【交换】按钮进行顺序调整"` |
|
||||||
|
| addButtonText | `string` | `"新增"` | 新增按钮文字 |
|
||||||
|
| minLength | `number` | | 限制最小长度 |
|
||||||
|
| maxLength | `number` | | 限制最大长度 |
|
||||||
|
| scaffold | `any` | | 新增成员时的默认值,一般根据`items`的数据类型指定需要的默认值 |
|
||||||
253
docs/zh-CN/components/form/input-city.md
Executable file
253
docs/zh-CN/components/form/input-city.md
Executable file
@@ -0,0 +1,253 @@
|
|||||||
|
---
|
||||||
|
title: InputCity 城市选择器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputCity
|
||||||
|
icon:
|
||||||
|
order: 10
|
||||||
|
---
|
||||||
|
|
||||||
|
城市选择器,方便输入城市,可以理解为自动配置了国内城市选项的 Select,支持到县级别。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"searchable": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
观察数据域中表单项的值,存储的是位置邮编。
|
||||||
|
|
||||||
|
## 配置选择级别
|
||||||
|
|
||||||
|
可以通过设置 `allowDistrict` 和 `allowCity` 设置用户选择级别,例如只选择省份:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"allowDistrict": false,
|
||||||
|
"allowCity": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 获取更多选项信息
|
||||||
|
|
||||||
|
表单项值默认格式是编码(即 `code`),如果你想要详细点的信息,可以把 `extractValue` 设置成 `false`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"extractValue": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置下拉框样式
|
||||||
|
|
||||||
|
可以通过 `itemClassName` 指定下拉框样式,如配置最小宽度
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"itemClassName": "min-w-xs",
|
||||||
|
"searchable": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| allowCity | `boolean` | `true` | 允许选择城市 |
|
||||||
|
| allowDistrict | `boolean` | `true` | 允许选择区域 |
|
||||||
|
| searchable | `boolean` | `false` | 是否出搜索框 |
|
||||||
|
| extractValue | `boolean` | `true` | 默认 `true` 是否抽取值,如果设置成 `false` 值格式会变成对象,包含 `code`、`province`、`city` 和 `district` 文字信息。 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ----------------------------------- | ---------------- |
|
||||||
|
| change | `[name]: number \| string` 组件的值 | 选中值变化时触发 |
|
||||||
|
|
||||||
|
### change
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"onEvent": {
|
||||||
|
"change": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msg": "${event.data.value|json}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string \| number` 更新的值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"id": "clear_text",
|
||||||
|
"value": "110000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"id": "reset_text",
|
||||||
|
"value": "110000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "city",
|
||||||
|
"type": "input-city",
|
||||||
|
"label": "城市",
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"value": "110000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": "110100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
115
docs/zh-CN/components/form/input-color.md
Executable file
115
docs/zh-CN/components/form/input-color.md
Executable file
@@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
title: InputColor 颜色选择器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputColor
|
||||||
|
icon:
|
||||||
|
order: 11
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-color",
|
||||||
|
"name": "color",
|
||||||
|
"label": "普通色盘"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 选择器预设颜色值
|
||||||
|
|
||||||
|
颜色选择器底部预设有会写可选的颜色值,默认为:
|
||||||
|
|
||||||
|
```
|
||||||
|
['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']
|
||||||
|
```
|
||||||
|
|
||||||
|
你可以配置`presetColors`数组进行自定义。颜色支持两种格式`string` 和 `{color: string; title: string}`,并支持两种格式混合使用。`string`格式支持所有合法的 CSS 颜色码,`object`类型下的`color`属性为 CSS 颜色码,`title`属性为颜色名称,鼠标悬浮于色块时会显示对应颜色名称。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-color",
|
||||||
|
"name": "color",
|
||||||
|
"label": "自定义预设色盘",
|
||||||
|
"presetColors": [
|
||||||
|
{"color": "#d4380d", "title": "熔岩红"},
|
||||||
|
{"color": "#ffa940", "title": "金桔橙"},
|
||||||
|
{"color": "#ffec3d", "title": "土豪金"},
|
||||||
|
{"color": "#73d13d", "title": "苹果绿"},
|
||||||
|
{"color": "#73E3EC", "title": "蒂芙尼青"},
|
||||||
|
{"color": "#2f54eb", "title": "冰川蓝"},
|
||||||
|
{"color": "#9254de", "title": "薰衣草紫"},
|
||||||
|
{"color": "#ffc0cb", "title": "樱花粉"},
|
||||||
|
"rgb(212, 56, 13)", "rgba(255, 169, 64, 1.0)", "hsl(54,100%,62%)", "hsla(98, 62%, 53%, 1.0)", "#73E3EC", "#2f54eb", "#9254de", "pink"
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## rgba
|
||||||
|
|
||||||
|
将 `format` 设置为 rgba 就能改变颜色透明度。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-color",
|
||||||
|
"name": "color",
|
||||||
|
"label": "带透明度调节的色盘",
|
||||||
|
"format": "rgba"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## hexa (8 digits HEX)
|
||||||
|
|
||||||
|
将 `format` 设置为 hexa 支持 8位 HEX,参考 `https://drafts.csswg.org/css-color/`。
|
||||||
|
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-color",
|
||||||
|
"name": "color",
|
||||||
|
"label": "带透明度调节的色盘, 8 digits HEX",
|
||||||
|
"value": "#73E3EC88",
|
||||||
|
"format": "hexa"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------------- | --------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
|
||||||
|
| format | `string` | `hex` | 请选择 `hex`、`hexa`、`hls`、`rgb`或者`rgba`。 |
|
||||||
|
| presetColors | `Array<string>` | [选择器预设颜色值](./input-color#%E9%80%89%E6%8B%A9%E5%99%A8%E9%A2%84%E8%AE%BE%E9%A2%9C%E8%89%B2%E5%80%BC) | 选择器底部的默认颜色,数组内为空则不显示默认颜色 |
|
||||||
|
| allowCustomColor | `boolean` | `true` | 为`false`时只能选择颜色,使用 `presetColors` 设定颜色选择范围 |
|
||||||
|
| clearable | `boolean` | `"label"` | 是否显示清除按钮 |
|
||||||
|
| resetValue | `string` | `""` | 清除后,表单项值调整成该值 |
|
||||||
477
docs/zh-CN/components/form/input-date-range.md
Executable file
477
docs/zh-CN/components/form/input-date-range.md
Executable file
@@ -0,0 +1,477 @@
|
|||||||
|
---
|
||||||
|
title: InputDateRange 日期范围
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputDateRange
|
||||||
|
icon:
|
||||||
|
order: 15
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 默认值
|
||||||
|
|
||||||
|
通过 value 设置默认值,除了实际值,比如
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期范围",
|
||||||
|
"value": "1659283200,1661961599"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
还可以是相对值,比如最近一周内
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期范围",
|
||||||
|
"value": "today,+1weeks"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
支持的相对值关键字有:
|
||||||
|
|
||||||
|
- today: 当前日期
|
||||||
|
- day 或 days: 天
|
||||||
|
- week 或 weeks: 周
|
||||||
|
- month 或 months: 月
|
||||||
|
- year 或 years: 年
|
||||||
|
|
||||||
|
或者用公式来配置复杂情况, 比如本周一到周日
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期范围",
|
||||||
|
"value": "${DATETOSTR(DATEMODIFY(STARTOF(NOW(), 'week'), 1, 'day'), 'X') + ',' + DATETOSTR(DATEMODIFY(ENDOF(NOW(), 'week'), '1', 'day'), 'X')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 因为默认周日是第一天,所以需要往后加一天
|
||||||
|
|
||||||
|
再看个上月第一天到上月最后一天的例子
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期范围",
|
||||||
|
"value": "${DATETOSTR(STARTOF(DATEMODIFY(NOW(), -1, 'month'), 'month'), 'X') + ',' + DATETOSTR(ENDOF(DATEMODIFY(NOW(), -1, 'month'), 'month'), 'X')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快捷键
|
||||||
|
|
||||||
|
`shortcuts`属性支持自定义快捷选择日期范围快捷键
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期范围",
|
||||||
|
"shortcuts": [
|
||||||
|
"7daysago",
|
||||||
|
"15dayslater",
|
||||||
|
"2weeksago",
|
||||||
|
"1weekslater",
|
||||||
|
"thismonth",
|
||||||
|
"2monthsago",
|
||||||
|
"3monthslater"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
支持的快捷键有
|
||||||
|
|
||||||
|
- `today`: 今天
|
||||||
|
- `yesterday`: 昨天
|
||||||
|
- `tomorrow`: 明天
|
||||||
|
- `prevweek`: 上周
|
||||||
|
- `thisweek`: 这个周
|
||||||
|
- `thismonth`: 本月
|
||||||
|
- `prevmonth`: 上个月
|
||||||
|
- `prevquarter`: 上个季度
|
||||||
|
- `thisquarter`: 这个季度
|
||||||
|
- `thisyear`: 今年
|
||||||
|
- `lastYear`: 去年
|
||||||
|
- `{n}daysago` : 最近 n 天,例如:`7daysago`,下面用法相同
|
||||||
|
- `{n}dayslater`: n 天以内
|
||||||
|
- `{n}weeksago`: 最近 n 周
|
||||||
|
- `{n}weekslater`: n 周以内
|
||||||
|
- `{n}monthsago`: 最近 n 月
|
||||||
|
- `{n}monthslater`: n 月以内
|
||||||
|
- `{n}quartersago`: 最近 n 季度
|
||||||
|
- `{n}quarterslater`: n 季度以内
|
||||||
|
- `{n}yearsago`: 最近 n 年
|
||||||
|
- `{n}yearslater`: n 年以内
|
||||||
|
|
||||||
|
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期范围",
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"label": "1天前",
|
||||||
|
"startDate": "${DATEMODIFY(NOW(), -1, 'day')}",
|
||||||
|
"endDate": "${NOW()}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "1个月前",
|
||||||
|
"startDate": "${DATEMODIFY(NOW(), -1, 'months')}",
|
||||||
|
"endDate": "${NOW()}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "本季度",
|
||||||
|
"startDate": "${STARTOF(NOW(), 'quarter')}",
|
||||||
|
"endDate": "${ENDOF(NOW(), 'quarter')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内嵌模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期范围",
|
||||||
|
"embed": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 存成两个字段
|
||||||
|
|
||||||
|
默认日期范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "begin",
|
||||||
|
"extraName": "end",
|
||||||
|
"label": "日期范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 数据处理函数
|
||||||
|
|
||||||
|
> `3.5.0`及以上版本
|
||||||
|
|
||||||
|
默认情况下,日期范围选择器组件的绑定值的开始时间为所选时间当天的 0 点(使用`moment().startOf('day')`处理),结束时间为所选时间当天的 23 时 59 分 59 秒 999 毫秒(使用`moment().endOf('day')`处理)。如果设置了`timeFormat`(时间格式),则会基于`timeFormat`配置决定**最小时间单位**,举例:
|
||||||
|
|
||||||
|
- 不设置`timeFormat`(时间格式),默认按照天(day)级处理:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
moment().startOf('day'); // 2008-08-08 00:00:00.000
|
||||||
|
moment().endOf('day'); // 2008-08-08 23:59:59.999
|
||||||
|
```
|
||||||
|
|
||||||
|
- `timeFormat`(时间格式)为 `"HH:mm:ss"`,则会按照秒(second)级处理:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
moment().startOf('second'); // 2008-08-08 08:08:08.000
|
||||||
|
moment().endOf('second'); // 2008-08-08 08:08:08.999
|
||||||
|
```
|
||||||
|
|
||||||
|
- `timeFormat`(时间格式)为 `"HH:mm"`,则会按照分钟(minute)级处理:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
moment().startOf('minute'); // 2008-08-08 08:08:00.000
|
||||||
|
moment().endOf('minute'); // 2008-08-08 08:08:59.999
|
||||||
|
```
|
||||||
|
|
||||||
|
- `timeFormat`(时间格式)为 `"HH"`,则会按照小时(hour)级处理:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
moment().startOf('hour'); // 2008-08-08 08:00:00.000
|
||||||
|
moment().endOf('hour'); // 2008-08-08 08:59:59.999
|
||||||
|
```
|
||||||
|
|
||||||
|
部分情况下,即使配置`timeFormat`也无法满足需求,此时可以使用`transform`函数对时间值做进一步处理, 函数签名如下:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface TransFormFunc {
|
||||||
|
(
|
||||||
|
/* 当前值,Moment对象 */
|
||||||
|
value: moment.Moment,
|
||||||
|
config: {
|
||||||
|
/* 操作类型,start:起始时间;end:结束时间 */
|
||||||
|
type: 'start' | 'end';
|
||||||
|
/* 初始值,最近一次选择的时间值 */
|
||||||
|
originValue: moment.Moment;
|
||||||
|
/* 时间格式 */
|
||||||
|
timeFormat: string;
|
||||||
|
},
|
||||||
|
/* 当前组件的属性 */
|
||||||
|
props: any,
|
||||||
|
/* 当前组件数据域 */
|
||||||
|
data: any,
|
||||||
|
/* moment函数 */
|
||||||
|
moment: moment
|
||||||
|
): moment.Moment;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "range1",
|
||||||
|
"label": "日期范围(默认)",
|
||||||
|
"valueFormat": "YYYY-MM-DDTHH:mm:ss[Z]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "range2",
|
||||||
|
"label": "日期范围(使用transform函数)",
|
||||||
|
"valueFormat": "YYYY-MM-DDTHH:mm:ss[Z]",
|
||||||
|
"transform": "const now = moment(); if (config.type === 'end') {value.set({hours: now.hours(), minutes: now.minutes(), seconds: now.seconds(), milliseconds: now.milliseconds()})}; return value;"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上面的示例使用 `transform` 函数,将结束时间的值设置为当前时间
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
function transform(value, config, props, data) {
|
||||||
|
const now = moment();
|
||||||
|
|
||||||
|
if (config.type === 'end') {
|
||||||
|
value.set({
|
||||||
|
hours: now.hours(),
|
||||||
|
minutes: now.minutes(),
|
||||||
|
seconds: now.seconds(),
|
||||||
|
milliseconds: now.milliseconds()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------- | ----------------------- |
|
||||||
|
| valueFormat | `string` | `X` | [日期选择器值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
|
||||||
|
| displayFormat | `string` | `YYYY-MM-DD` | [日期选择器显示格式](./date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
|
||||||
|
| placeholder | `string` | `"请选择日期范围"` | 占位文本 |
|
||||||
|
| shortcuts | `string \| string[] \| Array<{label: string; startDate: string; endDate: string}>` | `"yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter"` | 日期范围快捷键 | `3.1.0`版本后支持表达式 |
|
||||||
|
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| minDuration | `string` | | 限制最小跨度,如: 2days |
|
||||||
|
| maxDuration | `string` | | 限制最大跨度,如:1year |
|
||||||
|
| utc | `boolean` | `false` | [保存 UTC 值](./date#utc) |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| embed | `boolean` | `false` | 是否内联模式 |
|
||||||
|
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
|
||||||
|
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
|
||||||
|
| transform | `string` | | 日期数据处理函数,用来处理选择日期之后的的值,返回值为 `Moment`对象 | `3.5.0` |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------------------------- | ----------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,,依赖格式`format`,例如:'1650556800,1652889599' |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "clear_text",
|
||||||
|
"value": "1714060800,1714319999"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "reset_text",
|
||||||
|
"value": "1714060800,1714319999"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date-range",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"value": "1714060800,1714319999"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": "1714060800,1714492799"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
552
docs/zh-CN/components/form/input-date.md
Executable file
552
docs/zh-CN/components/form/input-date.md
Executable file
@@ -0,0 +1,552 @@
|
|||||||
|
---
|
||||||
|
title: InputDate 日期
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Date
|
||||||
|
icon:
|
||||||
|
order: 13
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示格式
|
||||||
|
|
||||||
|
选中任意日期,可以看到默认显示日期的格式是像`2020-04-14`这样的格式,如果你想要自定义显示格式,那么可以配置`inputFormat`。
|
||||||
|
|
||||||
|
例如你想显示`2020年04月14日`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY年MM月DD日`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"inputFormat": "YYYY年MM月DD日"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
选中任意日期,观察显示格式
|
||||||
|
|
||||||
|
## 值格式
|
||||||
|
|
||||||
|
选中任意日期,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你想要其他格式的日期值,那么可以配置`format`参数用于调整表单项的值格式。
|
||||||
|
|
||||||
|
例如你调整值为`2020-04-14`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY-MM-DD`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"format": "YYYY-MM-DD"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
选中任意日期,观察数据域中表单项值的变化
|
||||||
|
|
||||||
|
## 默认值
|
||||||
|
|
||||||
|
可以设置`value`属性,设置日期选择器的默认值
|
||||||
|
|
||||||
|
### 基本配置
|
||||||
|
|
||||||
|
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"value": "1591862818"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 相对值
|
||||||
|
|
||||||
|
`value` 还支持类似像`"+1days"`这样的相对值,更加便捷的配置默认值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"value": "+1days"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中配置了`"value": "+1days"`,默认就会选中明天。
|
||||||
|
|
||||||
|
支持的相对值关键字有:
|
||||||
|
|
||||||
|
- `today`: 当前日期
|
||||||
|
- `day`或`days`: 天
|
||||||
|
- `week`或`weeks`: 周
|
||||||
|
- `month`或`months`: 月
|
||||||
|
- `year`或`years`: 年
|
||||||
|
|
||||||
|
### 通过公式配置默认值
|
||||||
|
|
||||||
|
> 1.7.0 及以上版本
|
||||||
|
|
||||||
|
可以通过日期公式来动态计算。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"value": "${DATEMODIFY(NOW(), 2, 'days')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 限制范围
|
||||||
|
|
||||||
|
可以通过配置`maxDate`和`minDate`显示可选范围
|
||||||
|
|
||||||
|
### 固定时间值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"minDate": "1591862818",
|
||||||
|
"description": "限制可选最小日期是 <code>2020-06-11 16:06:58</code>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "end",
|
||||||
|
"label": "结束时间",
|
||||||
|
"maxDate": "1591862818",
|
||||||
|
"description": "限制可选最大日期是 <code>2020-06-11 16:06:58</code>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 支持相对值
|
||||||
|
|
||||||
|
范围限制也支持设置 [相对值](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC)。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"minDate": "-1days",
|
||||||
|
"description": "限制可选最小日期是昨天"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 支持模板
|
||||||
|
|
||||||
|
也支持通过[模板](./template),设置自定义值。
|
||||||
|
|
||||||
|
来一个常见例子,配置两个选择`开始时间`和`结束时间`的时间选择器,需要满足:`开始时间`不能大于`结束时间`,`结束时间`也不能小于`开始时间`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始日期",
|
||||||
|
"maxDate": "$end"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "end",
|
||||||
|
"label": "结束日期",
|
||||||
|
"minDate": "$start"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 通过 js 来控制
|
||||||
|
|
||||||
|
> 3.3.0 及以上版本
|
||||||
|
|
||||||
|
可以通过 `disabledDate` 字符函数来控制,比如不允许选择周一、周六、周日
|
||||||
|
|
||||||
|
函数签名: `(currentDate: moment.Moment, props: any) => boolean`
|
||||||
|
示例: `"return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"description": "限制不能选周一、周六、周日",
|
||||||
|
"disabledDate": "return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快捷键
|
||||||
|
|
||||||
|
你也可以配置`shortcuts`属性支持快捷选择日期
|
||||||
|
|
||||||
|
> 注:移动端 picker 的形式不支持快捷键
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"shortcuts": ["yesterday", "today", "tomorrow"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中我们配置了`"shortcuts": ["yesterday" ,"today", "tomorrow"]`,选择器顶部有将会显示快捷键`昨天`,`今天`和`明天`
|
||||||
|
|
||||||
|
支持的快捷键有
|
||||||
|
|
||||||
|
- `today`: 今天
|
||||||
|
- `yesterday`: 昨天
|
||||||
|
- `thisweek`: 本周一
|
||||||
|
- `thismonth`: 本月初
|
||||||
|
- `prevmonth`: 上个月初
|
||||||
|
- `prevquarter`: 上个季节初
|
||||||
|
- `thisquarter`: 本季度初
|
||||||
|
- `tomorrow`: 明天
|
||||||
|
- `endofthisweek`: 本周日
|
||||||
|
- `endofthismonth`:本月底
|
||||||
|
- `endoflastmonth`:上月底
|
||||||
|
- `{n}daysago` : n 天前,例如:`2daysago`,下面用法相同
|
||||||
|
- `{n}dayslater`: n 天后
|
||||||
|
- `{n}weeksago`: n 周前
|
||||||
|
- `{n}weekslater`: n 周后
|
||||||
|
- `{n}monthsago`: n 月前
|
||||||
|
- `{n}monthslater`: n 月后
|
||||||
|
- `{n}quartersago`: n 季度前
|
||||||
|
- `{n}quarterslater`: n 季度后
|
||||||
|
|
||||||
|
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"label": "前天",
|
||||||
|
"date": "${STARTOF(DATEMODIFY(NOW(), -2, 'day'))}"
|
||||||
|
},
|
||||||
|
"yesterday",
|
||||||
|
"today"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## UTC
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "普通日期",
|
||||||
|
"format": "YYYY-MM-DD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date-utc",
|
||||||
|
"label": "UTC日期",
|
||||||
|
"utc": true,
|
||||||
|
"format": "YYYY-MM-DD"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内嵌模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "当前值"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"embed": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 原生日期组件
|
||||||
|
|
||||||
|
原生数字日期将直接使用浏览器的实现,最终展现效果和浏览器有关,而且只支持 `min`、`max`、`step` 这几个属性设置。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "native-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | -------------------------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------- |
|
||||||
|
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
|
||||||
|
| valueFormat | `string` | `X` | 日期选择器值格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
|
||||||
|
| displayFormat | `string` | `YYYY-MM-DD` | 日期选择器显示格式,即时间戳格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
|
||||||
|
| closeOnSelect | `boolean` | `false` | 点选日期后,是否马上关闭选择框 |
|
||||||
|
| placeholder | `string` | `"请选择日期"` | 占位文本 |
|
||||||
|
| shortcuts | `string \| string[] \| Array<{"label": string; date: string}>` | | 日期快捷键,字符串格式为预设值,对象格式支持写表达式 | `3.1.0`版本后支持表达式 |
|
||||||
|
| minDate | `string` | | 限制最小日期 |
|
||||||
|
| maxDate | `string` | | 限制最大日期 |
|
||||||
|
| utc | `boolean` | `false` | 保存 utc 值 |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| embed | `boolean` | `false` | 是否内联模式 |
|
||||||
|
| disabledDate | `string` | | 用字符函数来控制哪些天不可以被点选 |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1650556800' |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "clear_text",
|
||||||
|
"value": "1714060800"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "reset_text",
|
||||||
|
"value": "1714060800"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-date",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期",
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"value": "1714060800"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": "1714233600"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
163
docs/zh-CN/components/form/input-datetime-range.md
Executable file
163
docs/zh-CN/components/form/input-datetime-range.md
Executable file
@@ -0,0 +1,163 @@
|
|||||||
|
---
|
||||||
|
title: InputDatetimeRange 日期时间范围
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputDatetimeRange
|
||||||
|
icon:
|
||||||
|
order: 16
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期时间范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 时间显示到秒
|
||||||
|
|
||||||
|
通过 `"timeFormat": "HH:mm:ss"` 设置时间输入框显示秒
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime-range",
|
||||||
|
"name": "select",
|
||||||
|
"timeFormat": "HH:mm:ss",
|
||||||
|
"label": "日期时间范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快捷键
|
||||||
|
|
||||||
|
`shortcuts`属性支持自定义日期时间范围快捷键
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期范围",
|
||||||
|
"shortcuts": "today,yesterday,1dayago,7daysago"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime-range",
|
||||||
|
"name": "select",
|
||||||
|
"label": "日期范围",
|
||||||
|
"inputFormat": "YYYY-MM-DD HH:mm:ss",
|
||||||
|
"timeFormat": "HH:mm:ss",
|
||||||
|
"format": "x",
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"label": "1天前",
|
||||||
|
"startDate": "${DATEMODIFY(NOW(), -1, 'day')}",
|
||||||
|
"endDate": "${NOW()}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "1个月前",
|
||||||
|
"startDate": "${DATEMODIFY(NOW(), -1, 'months')}",
|
||||||
|
"endDate": "${NOW()}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "本季度",
|
||||||
|
"startDate": "${STARTOF(NOW(), 'quarter')}",
|
||||||
|
"endDate": "${ENDOF(NOW(), 'quarter')}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 存成两个字段
|
||||||
|
|
||||||
|
默认日期范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime-range",
|
||||||
|
"name": "begin",
|
||||||
|
"extraName": "end",
|
||||||
|
"label": "日期范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------- |
|
||||||
|
| valueFormat | `string` | `X` | [日期时间选择器值格式](./input-datetime#%E5%80%BC%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
|
||||||
|
| displayFormat | `string` | `YYYY-MM-DD` | [日期时间选择器显示格式](./input-datetime#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
|
||||||
|
| placeholder | `string` | `"请选择日期范围"` | 占位文本 |
|
||||||
|
| shortcuts | `string \| string[] \| Array<{label: string; startDate: string; endDate: string}>` | `"yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter"` | 日期范围快捷键,详情参考[快捷键](./input-date-range#快捷键) | `3.1.0`版本后支持表达式 |
|
||||||
|
| minDate | `string` | | 限制最小日期时间,用法同 [限制范围](./input-datetime#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| maxDate | `string` | | 限制最大日期时间,用法同 [限制范围](./input-datetime#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| utc | `boolean` | `false` | [保存 UTC 值](./input-datetime#utc) |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
|
||||||
|
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------------------------- | -------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1650556800,1652889599' |
|
||||||
451
docs/zh-CN/components/form/input-datetime.md
Executable file
451
docs/zh-CN/components/form/input-datetime.md
Executable file
@@ -0,0 +1,451 @@
|
|||||||
|
---
|
||||||
|
title: InputDatetime 日期时间
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputDatetime
|
||||||
|
icon:
|
||||||
|
order: 14
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示格式
|
||||||
|
|
||||||
|
选中任意日期时间,可以看到默认显示日期的格式是像`2020-04-14 12:20:10`这样的格式,如果你想要自定义显示格式,那么可以配置`inputFormat`。
|
||||||
|
|
||||||
|
例如你想显示`2020年04月14日 12时20分10秒`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY年MM月DD日 HH时mm分ss秒`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间",
|
||||||
|
"inputFormat": "YYYY年MM月DD日 HH时mm分ss秒"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
选中任意日期时间,观察显示格式
|
||||||
|
|
||||||
|
## 值格式
|
||||||
|
|
||||||
|
选中任意日期时间,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你想要其他格式的日期值,那么可以配置`format`参数用于调整表单项的值格式。
|
||||||
|
|
||||||
|
例如你调整值为`2020-04-14 12:20:10`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY-MM-DD HH:mm:ss`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间",
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
选中任意日期时间,观察数据域中表单项值的变化
|
||||||
|
|
||||||
|
## 默认值
|
||||||
|
|
||||||
|
可以设置`value`属性,设置日期选择器的默认值
|
||||||
|
|
||||||
|
### 基本配置
|
||||||
|
|
||||||
|
配置符合当前 [值格式](./datetime#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间",
|
||||||
|
"value": "1591862818"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 相对值
|
||||||
|
|
||||||
|
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期",
|
||||||
|
"value": "+1hours"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中配置了`"value": "+1hours"`,默认就会选中一小时后的时间。
|
||||||
|
|
||||||
|
支持的相对值关键字除了 [Date](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC) 中的以外,还支持:
|
||||||
|
|
||||||
|
- `now`: 当前时间
|
||||||
|
- `minute`或`minutes`或`min`或`mins`: 分钟
|
||||||
|
- `hour`或`hours`: 小时
|
||||||
|
|
||||||
|
## 限制范围
|
||||||
|
|
||||||
|
### 控制时间范围
|
||||||
|
|
||||||
|
通过 `timeConstraints` 属性可以控制时间输入范围
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间",
|
||||||
|
"timeConstraints": {
|
||||||
|
"hours": {
|
||||||
|
"min": 12,
|
||||||
|
"max": 18
|
||||||
|
},
|
||||||
|
"minutes": {
|
||||||
|
"step": 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
可以通过配置`maxDate`和`minDate`显示可选范围
|
||||||
|
|
||||||
|
### 固定时间值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"minDate": "1591862818",
|
||||||
|
"description": "限制可选最小日期是 <code>2020-06-11 16:06:58</code>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "end",
|
||||||
|
"label": "结束时间",
|
||||||
|
"maxDate": "1591862818",
|
||||||
|
"description": "限制可选最大日期是 <code>2020-06-11 16:06:58</code>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 支持相对值
|
||||||
|
|
||||||
|
范围限制也支持设置 [相对值](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC)。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"minDate": "-1days",
|
||||||
|
"description": "限制可选最小日期是昨天"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 支持模板
|
||||||
|
|
||||||
|
也支持通过[模板](./template),设置自定义值。
|
||||||
|
|
||||||
|
来一个常见例子,配置两个选择`开始时间`和`结束时间`的时间选择器,需要满足:`开始时间`不能小于`结束时间`,`结束时间`也不能大于`开始时间`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"maxDate": "$end"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "end",
|
||||||
|
"label": "结束时间",
|
||||||
|
"minDate": "$start"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 通过 js 来控制
|
||||||
|
|
||||||
|
> 3.3.0 及以上版本
|
||||||
|
|
||||||
|
可以通过 `disabledDate` 字符函数来控制,比如不允许选择周一、周六、周日
|
||||||
|
|
||||||
|
函数签名: `(currentDate: moment.Moment, props: any) => boolean`
|
||||||
|
示例: `"return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "start",
|
||||||
|
"label": "开始时间",
|
||||||
|
"description": "限制不能选周一、周六、周日",
|
||||||
|
"disabledDate": "return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快捷键
|
||||||
|
|
||||||
|
你也可以配置`shortcuts`属性支持快捷选择日期
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期",
|
||||||
|
"shortcuts": ["yesterday" ,"today", "tomorrow"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中我们配置了`"shortcuts": ["yesterday" ,"today", "tomorrow"]`,选择器顶部有将会显示快捷键`昨天`,`今天`和`明天`
|
||||||
|
|
||||||
|
除了支持 的快捷键有
|
||||||
|
|
||||||
|
支持的快捷键除了 [Date](./date#%E5%BF%AB%E6%8D%B7%E9%94%AE) 中的以外,还支持:
|
||||||
|
|
||||||
|
- `now`: 现在
|
||||||
|
- `{n}hoursago` : n 小时前,例如:`2hoursago`,下面用法相同
|
||||||
|
- `{n}hourslater` : n 小时后,例如:`2hourslater`,下面用法相同
|
||||||
|
|
||||||
|
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期",
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"label": "前天",
|
||||||
|
"date": "${STARTOF(DATEMODIFY(NOW(), -2, 'day'))}"
|
||||||
|
},
|
||||||
|
"yesterday",
|
||||||
|
"today"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## UTC
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "普通日期时间",
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime-utc",
|
||||||
|
"label": "UTC日期时间",
|
||||||
|
"utc": true,
|
||||||
|
"format": "YYYY-MM-DD HH:mm:ss"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内嵌模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "static-date",
|
||||||
|
"name": "date",
|
||||||
|
"format": "LLL",
|
||||||
|
"label": "当前值"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "date",
|
||||||
|
"label": "日期时间",
|
||||||
|
"embed": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 确认模式
|
||||||
|
|
||||||
|
> `3.6.0`及以上版本
|
||||||
|
|
||||||
|
设置`"closeOnSelect": false`,点选日期时间后,不会自动关闭浮层,需要点击底部工具栏的确认才会关闭。点击**取消按钮**或者**浮层外部区域**也会关闭浮层,并将值重置为初始状态。
|
||||||
|
|
||||||
|
> 注意:该特性仅对`input-datetime`有效,其他日期时间组件无效。开启内嵌模式后,该特性无效。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-datetime",
|
||||||
|
"name": "datetime",
|
||||||
|
"label": "日期时间",
|
||||||
|
"shortcuts": ["yesterday", "today", "tomorrow"],
|
||||||
|
"closeOnSelect": false,
|
||||||
|
"valueFormat": "YYYY-MM-DD HH:mm:ss",
|
||||||
|
"displayFormat": "YYYY-MM-DD HH:mm:ss",
|
||||||
|
"clearable": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | -------------------------------------------------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
||||||
|
| value | `string` | | [默认值](./datetime#%E9%BB%98%E8%AE%A4%E5%80%BC) |
|
||||||
|
| valueFormat | `string` | `X` | 日期时间选择器值格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
|
||||||
|
| displayFormat | `string` | `YYYY-MM-DD HH:mm:ss` | 日期时间选择器显示格式,即时间戳格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
|
||||||
|
| placeholder | `string` | `"请选择日期以及时间"` | 占位文本 |
|
||||||
|
| shortcuts | `string \| string[] \| Array<{"label": string; date: string}>` | | 日期时间快捷键 | `3.1.0`版本后支持表达式 |
|
||||||
|
| minDate | `string` | | 限制最小日期时间 |
|
||||||
|
| maxDate | `string` | | 限制最大日期时间 |
|
||||||
|
| utc | `boolean` | `false` | 保存 utc 值 |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| embed | `boolean` | `false` | 是否内联 |
|
||||||
|
| timeConstraints | `object` | `true` | 请参考 [input-time](./input-time#控制输入范围) 里的说明 |
|
||||||
|
| isEndDate | `boolean` | `false` | 如果配置为 true,会自动默认为 23:59:59 秒 |
|
||||||
|
| disabledDate | `string` | | 用字符函数来控制哪些天不可以被点选 |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0`版本后支持 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1650556800' |
|
||||||
438
docs/zh-CN/components/form/input-excel.md
Normal file
438
docs/zh-CN/components/form/input-excel.md
Normal file
@@ -0,0 +1,438 @@
|
|||||||
|
---
|
||||||
|
title: InputExcel 解析 Excel
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputExcel
|
||||||
|
icon:
|
||||||
|
order: 14
|
||||||
|
---
|
||||||
|
|
||||||
|
这个组件是通过前端对 Excel 进行解析,将结果作为表单项,使用它有两个好处:
|
||||||
|
|
||||||
|
1. 节省后端开发成本,无需再次解析 Excel
|
||||||
|
2. 可以前端实时预览效果,比如配合 input-table 组件进行二次修改
|
||||||
|
|
||||||
|
> 2.10.0 以上版本支持 xls 文件格式,2.9.0 及以下版本只支持 xlsx
|
||||||
|
|
||||||
|
## 基本使用
|
||||||
|
|
||||||
|
默认情况下只解析第一个 sheet 的内容,下面的例子中,选择上传文件后,就能知道最终会解析成什么数据
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
默认模式是解析成对象数组,将第一行作为对象里的键,可以上传一个类似这样的 Excel 内容试试
|
||||||
|
|
||||||
|
```
|
||||||
|
|名称|网址|
|
||||||
|
|amis|https://baidu.gitee.io/amis|
|
||||||
|
|百度|https://www.baidu.com|
|
||||||
|
```
|
||||||
|
|
||||||
|
解析后的的数据格式将会是
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"名称": "amis",
|
||||||
|
"网址": "https://baidu.gitee.io/amis"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"名称": "百度",
|
||||||
|
"网址": "https://www.baidu.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
可以配合 `input-table` 来实现上传后二次编辑
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"placeholder": "请拖拽Excel文件到当前区域"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-table",
|
||||||
|
"name": "excel",
|
||||||
|
"visibleOn": "data.excel",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "名称",
|
||||||
|
"label": "名称",
|
||||||
|
"type": "input-text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "网址",
|
||||||
|
"label": "网址",
|
||||||
|
"type": "input-text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
需要保证 `input-table` 的 `name` 和 `input-excel` 一致,同时 `columns` 中的 `name` 也需要和 Excel 的列名一致。
|
||||||
|
|
||||||
|
## 二维数组模式
|
||||||
|
|
||||||
|
除了默认配置的对象数组格式,还可以使用二维数组方式,方法是设置 `"parseMode": "array"`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"parseMode": "array",
|
||||||
|
"label": "上传 Excel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果是前面的例子,解析结果将会是
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
["名称", "网址"],
|
||||||
|
["amis", "https://baidu.gitee.io/amis"],
|
||||||
|
["百度", "https://www.baidu.com"]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 解析多个 sheet
|
||||||
|
|
||||||
|
默认配置只解析第一个 sheet,如果要解析多个 sheet,可以通过 `"allSheets": true` 开启多个 sheet 的读取,这时的数据会增加一个层级。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"allSheets": true,
|
||||||
|
"label": "上传 Excel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果按之前的例子,结果将会是
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"sheetName": "Sheet1",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"名称": "amis",
|
||||||
|
"网址": "https://baidu.gitee.io/amis"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"名称": "百度",
|
||||||
|
"网址": "https://www.baidu.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
## 解析多个文件
|
||||||
|
可以配置"multiple": true,来开启多文件解析功能,通过"maxLength": 5,来限制最多上传5个文件。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"allSheets": true,
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"multiple": true,
|
||||||
|
"maxLength": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 解析图片
|
||||||
|
|
||||||
|
> 2.6.0 及以上版本
|
||||||
|
|
||||||
|
通过配置 `parseImage` 来支持解析 excel 里的图片
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"parseImage": true,
|
||||||
|
"label": "上传 Excel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
默认情况下解析结果是 data URI 格式,如果不想要这个前缀可以通过 `"imageDataURI": false` 关闭
|
||||||
|
|
||||||
|
## 富文本模式
|
||||||
|
|
||||||
|
默认情况下 Excel 内容将会解析为纯文本,如果要使用富文本格式,可以通过 `plainText` 属性控制
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"plainText": false,
|
||||||
|
"label": "上传 Excel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
开启这个模式后,对于富文本的内容会解析成对象的形式,有以下几种
|
||||||
|
|
||||||
|
- 富文本,内容放在 richText 属性下
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"richText": [
|
||||||
|
{text: 'This is '},
|
||||||
|
{font: {italic: true}, text: 'italic'}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 出错
|
||||||
|
|
||||||
|
```
|
||||||
|
{ error: '#N/A' }
|
||||||
|
```
|
||||||
|
|
||||||
|
- 公式
|
||||||
|
|
||||||
|
```
|
||||||
|
{ formula: 'A1+A2', result: 7 };
|
||||||
|
```
|
||||||
|
|
||||||
|
- 超链接
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
text: 'www.mylink.com',
|
||||||
|
hyperlink: 'http://www.mylink.com',
|
||||||
|
tooltip: 'www.mylink.com'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 解析文件名称
|
||||||
|
|
||||||
|
> `3.5.0`及以上版本
|
||||||
|
|
||||||
|
文件解析成功后,可以使用`autoFill`属性,在当前组件所在的数据域中填充值,`input-excel`组件特有的保留字段请查看下方定义,`InputExcelData`中的字段可以用变量获取。通常可以利用这个属性为`input-excel`所在的表单追加文件名称。
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface InputExcelData {
|
||||||
|
/* 文件名称 */
|
||||||
|
filename: string;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"autoFill": {
|
||||||
|
"operator": "amis",
|
||||||
|
"time": "${DATETOSTR(NOW(), 'YYYY-MM-DD HH:mm:ss')}",
|
||||||
|
"fileName": "${filename}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
|--------------|--------------------------|-----------------------|--------------|----------|
|
||||||
|
| allSheets | `boolean` | false | 是否解析所有 sheet |
|
||||||
|
| parseMode | `'array'` 或 `'object'` | 'object' | 解析模式 |
|
||||||
|
| includeEmpty | `boolean` | true | 是否包含空值 |
|
||||||
|
| plainText | `boolean` | true | 是否解析为纯文本 |
|
||||||
|
| placeholder | `string` | `"拖拽 Excel 到这,或点击上传"` | 占位文本提示 | `2.8.1` |
|
||||||
|
| autoFill | `Record<string, string>` | | 自动填充 | `3.5.0` |
|
||||||
|
| multiple | `boolean` | | 解析多个文件 | `6.13.0` |
|
||||||
|
| maxLength | `number` | | 解析文件最大数 | `6.13.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------------------------------ | ------------------------ |
|
||||||
|
| change | `[name]: Array<object>` 组件的值(excel 解析后的数据) | excel 上传解析完成后触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------------------------- | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: Array<object>` 更新的 excel 解析后数据 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"id": "clear_text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"id": "reset_text",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"ID": "1",
|
||||||
|
"NAME": "amis"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-excel",
|
||||||
|
"name": "excel",
|
||||||
|
"label": "上传 Excel",
|
||||||
|
"id": "setvalue_text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"ID": "1",
|
||||||
|
"NAME": "amis"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
538
docs/zh-CN/components/form/input-file.md
Executable file
538
docs/zh-CN/components/form/input-file.md
Executable file
@@ -0,0 +1,538 @@
|
|||||||
|
---
|
||||||
|
title: InputFile 文件上传
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputFile
|
||||||
|
icon:
|
||||||
|
order: 21
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
用来负责文件上传,文件上传成功后会返回文件地址,这个文件地址会作为这个表单项的值,整个表单提交的时候,其实提交的是文件地址,文件上传已经在这个控件中完成了。
|
||||||
|
|
||||||
|
> 如果希望文件内容伴随表单一起提交,可以配置 `asBlob` 或者 `asBase64`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 接口说明
|
||||||
|
|
||||||
|
这是单文件上传模式,通过配置 `receiver` 来接管文件上传。
|
||||||
|
|
||||||
|
接口发送方式是 POST, 数据体为 form-data 格式。对应的文件字段名为 `file`。这个可以通过 `fileField` 来配置。要求返回的数据格式如下。
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"value": "xxxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- value:必须返回该字段用作回显,一般是文件资源地址
|
||||||
|
|
||||||
|
> 注意这只是单文件上传部分,如果允许上传的文件比较大,建议用分块上传,请阅读下面的分块上传部分。
|
||||||
|
|
||||||
|
## 限制文件类型
|
||||||
|
|
||||||
|
可以配置`accept`来限制可选择的文件类型,格式是文件后缀名`.xxx`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "限制只能上传csv文件",
|
||||||
|
"accept": ".csv",
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
想要限制多个类型,则用逗号分隔,例如:`.csv,.md`
|
||||||
|
|
||||||
|
## 限制文件大小
|
||||||
|
|
||||||
|
可以配置`maxSize`来限制文件大小
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "不能上传超过 1M 的文件",
|
||||||
|
"maxSize": 1048576,
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 手动上传
|
||||||
|
|
||||||
|
默认`"autoUpload": true`,即添加文件后自动上传。可以设置`"autoUpload": false`关闭自动上传,此时通过点击上传按钮上传。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"data": {
|
||||||
|
"file": {
|
||||||
|
"id":"2ba48d02d348",
|
||||||
|
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"filename":"file(single).md",
|
||||||
|
"name":"file(single).md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"id":"2ba48d02d349",
|
||||||
|
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"filename":"file1.md",
|
||||||
|
"name":"file1.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"14723e0bc640",
|
||||||
|
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"filename":"file2.md",
|
||||||
|
"name":"file2.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "files",
|
||||||
|
"label": "File(多选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": true,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File(单选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": false,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 作为表单项上传
|
||||||
|
|
||||||
|
如果不希望 InputFile 组件在提交 Form 之前上传,可以配置 `asBlob` 或者 `asBase64`,采用这种方式后,组件不再自己上传了,而是直接把文件数据作为表单项的值,文件内容会在 Form 表单提交的接口里面一起带上。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"accept": "*",
|
||||||
|
"asBlob": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中,选择任意文件,然后观察数据域变化;点击提交,amis 自动会调整接口数据格式为`FormData`
|
||||||
|
|
||||||
|
## 分块上传
|
||||||
|
|
||||||
|
如果文件过大,则可能需要使用分块上传,默认大于 5M(chunkSize 配置决定) 的文件是会自动开启,可以通过 `useChunk` 配置成 false 关闭。
|
||||||
|
|
||||||
|
分块上传需要配置三个接口来完成分别是:
|
||||||
|
|
||||||
|
- `startChunkApi` 用来做分块前的准备工作
|
||||||
|
- `chunkApi` 用来接收每个分块上传
|
||||||
|
- `finishChunkApi` 用来收尾分块上传
|
||||||
|
|
||||||
|
还可以通过 `concurrency` 控制并行数量,默认是 3
|
||||||
|
|
||||||
|
### startChunkApi
|
||||||
|
|
||||||
|
用来做分块前的准备工作,一个文件只会调用一次。如果出错了,后续的分块上传就会中断。
|
||||||
|
|
||||||
|
发送说明:默认是 post,发送的数据中会包含 `filename` 字段,记录文件名,默认的数据体格式为 json。可以额外配置参数,请参考 API 的配置说明。
|
||||||
|
|
||||||
|
要求返回的数据中必须包含:
|
||||||
|
|
||||||
|
- `uploadId` 这次上传的唯一 ID。
|
||||||
|
- `key` 有点类似 `uploadId`,可有可无,爱速搭中用来记录后端文件存储路径。
|
||||||
|
|
||||||
|
其他属性返回目前是没有任何作用的。
|
||||||
|
|
||||||
|
如:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"key": "images/JSSDK_page-xxxx.zip",
|
||||||
|
"uploadId": "036f64cd5dd95750d4bcb33556b629c6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### chunkApi
|
||||||
|
|
||||||
|
用来接收每个分块上传,大文件会根据 chunkSize 分割成多块,然后每块上传都会调用这个接口。
|
||||||
|
|
||||||
|
发送说明:默认为 post,发送体格式为 form-data。包含以下信息:
|
||||||
|
|
||||||
|
- `uploadId` startChunkApi 返回的
|
||||||
|
- `key` startChunkApi 返回的
|
||||||
|
- `partNumber` 分块序号,从 1 开始。
|
||||||
|
- `partSize` 分块大小
|
||||||
|
- `file` 文件体
|
||||||
|
|
||||||
|
要求返回的数据中必须包含:
|
||||||
|
|
||||||
|
- `eTag` 通常为文件的内容戳。
|
||||||
|
|
||||||
|
如:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"eTag": "016bd9b68ddd5cd7318875da3ea28207"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### finishChunkApi
|
||||||
|
|
||||||
|
等所有分块上传完后,将上传文件收集到的 `eTag` 信息合并一起,再次请求后端完成文件上传。
|
||||||
|
|
||||||
|
发送说明:默认为 post,数据体默认为 json,包含以下信息
|
||||||
|
|
||||||
|
- `filename` 文件名
|
||||||
|
- `key` startChunkApi 返回的
|
||||||
|
- `uploadId` startChunkApi 返回的
|
||||||
|
- `partList` 数组,每个成员为 `{partNumber: xxx, eTag: "xxxxx"}` 即分块编号和分块 `eTag` 信息。
|
||||||
|
|
||||||
|
数据返回,类似单文件上传一样,必须有 `value` 属性,可选返回 `url` 用来决定文件的下载地址。如:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"value": "https://xxxx.cdn.bcebos.com/images/JSSDK_page-xxxxx.zip"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自动填充
|
||||||
|
|
||||||
|
上传成功后,可以通过配置 `autoFill` 将上传接口返回的值填充到某个表单项中(在非表单下暂不支持):
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${url}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "myUrl",
|
||||||
|
"label": "url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中,file 组件上传后,接口返回格式例如如下:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"value": "xxxxxxx",
|
||||||
|
"filename": "xxxx.csv",
|
||||||
|
"url": "http://xxxx.xxx.xxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
然后 file 上配置:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${url}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这样上传成功后,会把接口中的 `url` 变量,赋值给 `myUrl` 变量
|
||||||
|
|
||||||
|
**多选模式**
|
||||||
|
|
||||||
|
当表单项为多选模式时,不能再直接取选项中的值了,而是通过 `items` 变量来取,通过它可以获取当前选中的选项集合。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"multiple": true,
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${items|pick:url}",
|
||||||
|
"lastUrl": "${items|last|pick:url}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 拖拽上传
|
||||||
|
|
||||||
|
把文件拖入指定区域,完成上传,同样支持点击上传。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"drag": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 上传文件列表
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"data": {
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"id":"2ba48d02d349",
|
||||||
|
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"filename":"file1.md",
|
||||||
|
"name":"file1.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"14723e0bc640",
|
||||||
|
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
|
||||||
|
"filename":"file2.md",
|
||||||
|
"name":"file2.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "files",
|
||||||
|
"label": false,
|
||||||
|
"mode": "horizontal",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/mock2/upload/random",
|
||||||
|
"multiple": true,
|
||||||
|
"joinValues": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ------------------ | ------------------------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| receiver | [API](../../../docs/types/api) | | 上传文件接口 |
|
||||||
|
| accept | `string` | `text/plain` | 默认只支持纯文本,要支持其他类型,请配置此属性为文件后缀`.xxx` |
|
||||||
|
| capture | `string` | `undefined` | 用于控制 input[type=file] 标签的 capture 属性,在移动端可控制输入来源 |
|
||||||
|
| asBase64 | `boolean` | `false` | 将文件以`base64`的形式,赋值给当前组件 |
|
||||||
|
| asBlob | `boolean` | `false` | 将文件以二进制的形式,赋值给当前组件 |
|
||||||
|
| maxSize | `number` | | 默认没有限制,当设置后,文件大小大于此值将不允许上传。单位为`B` |
|
||||||
|
| maxLength | `number` | | 默认没有限制,当设置后,一次只允许上传指定数量文件。 |
|
||||||
|
| multiple | `boolean` | `false` | 是否多选。 |
|
||||||
|
| drag | `boolean` | `false` | 是否为拖拽上传 |
|
||||||
|
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||||
|
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||||
|
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
|
||||||
|
| autoUpload | `boolean` | `true` | 否选择完就自动开始上传 |
|
||||||
|
| hideUploadButton | `boolean` | `false` | 隐藏上传按钮 |
|
||||||
|
| stateTextMap | object | `{ init: '', pending: '等待上传', uploading: '上传中', error: '上传出错', uploaded: '已上传', ready: '' }` | 上传状态文案 |
|
||||||
|
| fileField | `string` | `file` | 如果你不想自己存储,则可以忽略此属性。 |
|
||||||
|
| nameField | `string` | `name` | 接口返回哪个字段用来标识文件名 |
|
||||||
|
| valueField | `string` | `value` | 文件的值用那个字段来标识。 |
|
||||||
|
| urlField | `string` | `url` | 文件下载地址的字段名。 |
|
||||||
|
| btnLabel | `string` | | 上传按钮的文字 |
|
||||||
|
| downloadUrl | `boolean`或`string` | `""` 1.1.6 版本开始支持 `post:http://xxx.com/${value}` 这种写法 | 默认显示文件路径的时候会支持直接下载,可以支持加前缀如:`http://xx.dom/filename=` ,如果不希望这样,可以把当前配置项设置为 `false`。 |
|
||||||
|
| useChunk | `boolean`或`"auto"` | `"auto"` | amis 所在服务器,限制了文件上传大小不得超出 10M,所以 amis 在用户选择大文件的时候,自动会改成分块上传模式。 |
|
||||||
|
| chunkSize | `number` | `5 * 1024 * 1024` | 分块大小 |
|
||||||
|
| startChunkApi | [API](../../../docs/types/api) | | startChunkApi |
|
||||||
|
| chunkApi | [API](../../../docs/types/api) | | chunkApi |
|
||||||
|
| finishChunkApi | [API](../../../docs/types/api) | | finishChunkApi |
|
||||||
|
| concurrency | `number` | | 分块上传时并行个数 |
|
||||||
|
| documentation | `string` | | 文档内容 |
|
||||||
|
| documentLink | `string` | | 文档链接 |
|
||||||
|
| initAutoFill | `boolean` | `true` | 初表单反显时是否执行 |
|
||||||
|
| invalidTypeMessage | `string` | | 校验格式失败后的提示信息 可以用{{}}获取内部变量值,如{{accept}} |
|
||||||
|
| invalidSizeMessage | `string` | | 校验文件大小失败时显示的文字信息 可以用{{}}获取内部变量值,如{{maxSize}} |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`file`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
|
||||||
|
| change | `[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件值变化时触发(上传失败同样会触发) |
|
||||||
|
| remove | `item: FileValue` 被移除的文件<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 移除文件时触发 |
|
||||||
|
| success | `item: FileValue` 上传的文件<br/>`result: any` 远程上传请求成功后接口返回的结果数据<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传成功时触发 |
|
||||||
|
| fail | `item: FileValue` 上传的文件 <br /> `error: object` 远程上传请求失败后返回的错误信息<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件失败时触发 |
|
||||||
|
|
||||||
|
### FileValue 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 说明 |
|
||||||
|
| ------ | -------- | -------------------------------------------------- |
|
||||||
|
| name | `string` | 文件名称 |
|
||||||
|
| value | `string` | 上传成功后返回的 url |
|
||||||
|
| state | `string` | 文件当前状态,值可为 `pending` `uploaded` `invalid` |
|
||||||
|
| error | `string` | 错误信息 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | -------- | ---- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-file",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File",
|
||||||
|
"accept": "*",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"id": "clear_text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
545
docs/zh-CN/components/form/input-formula.md
Normal file
545
docs/zh-CN/components/form/input-formula.md
Normal file
@@ -0,0 +1,545 @@
|
|||||||
|
---
|
||||||
|
title: InputFormula 公式编辑器
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputFormula
|
||||||
|
icon:
|
||||||
|
order: 21
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
用来输入公式。还是 beta 版本,整体待优化。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"evalMode": true,
|
||||||
|
"value": "SUM(1 , user.id)",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "人员对象",
|
||||||
|
"value": "user",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "ID",
|
||||||
|
"value": "user.id"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "用户名",
|
||||||
|
"value": "user.name"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "长文本测试分类长文本测试分类长文本测试分类长文本测试分类",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "这是一段测试长文本这是一段测试长文本这是一段测试长文本",
|
||||||
|
"value": "longtext",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 展示模式
|
||||||
|
|
||||||
|
设置`"inputMode": "button"`可以切换编辑器的展示模式为按钮模式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"variableMode": "tree",
|
||||||
|
"evalMode": true,
|
||||||
|
"value": "SUM(1 , 2)",
|
||||||
|
"inputMode": "button",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
设置`"inputMode": "input-group"`可以切换编辑器的展示模式为输入框组合模式,1.10.0 及以上版本。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"variableMode": "tree",
|
||||||
|
"evalMode": true,
|
||||||
|
"value": "SUM(1 , 2)",
|
||||||
|
"inputMode": "input-group",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 变量展示模式
|
||||||
|
|
||||||
|
设置不同`variableMode`字段切换变量展示模式,树形结构:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"variableMode": "tree",
|
||||||
|
"evalMode": true,
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Tab 结构:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"variableMode": "tabs",
|
||||||
|
"evalMode": false,
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 模板模式
|
||||||
|
|
||||||
|
当配置 `evalMode` 为 false 时则为模板模式,意思是说默认不当做表达式,只有 `${`和`}`包裹的部分才是表达式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "formula",
|
||||||
|
"label": "公式",
|
||||||
|
"evalMode": false,
|
||||||
|
"value": "my name is \\${name}",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 混合模式
|
||||||
|
|
||||||
|
混合模式的意思是支持输入文本和输入公式两种格式的值,当输入公式时值会自动用 `${` 和 `}` 包裹,如果不是这种格式则认为是输入普通的字符串。通过 `mixedMode` 为 true 启用这种模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-formula",
|
||||||
|
"name": "value",
|
||||||
|
"label": "混合模式",
|
||||||
|
"mixedMode": true,
|
||||||
|
"value": "\\${SUM(1, 2)}",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"label": "表单字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "文章名",
|
||||||
|
"value": "name",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "作者",
|
||||||
|
"value": "author",
|
||||||
|
"tag": "文本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "售价",
|
||||||
|
"value": "price",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版时间",
|
||||||
|
"value": "time",
|
||||||
|
"tag": "时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "版本号",
|
||||||
|
"value": "version",
|
||||||
|
"tag": "数字"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "出版社",
|
||||||
|
"value": "publisher",
|
||||||
|
"tag": "文本"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "流程字段",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"label": "联系电话",
|
||||||
|
"value": "telphone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "地址",
|
||||||
|
"value": "addr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ----------------- | ------------------------------------------------------------------------------------------ | -------------- | ------------------------------------------------------------------------------ |
|
||||||
|
| title | `string` | `'公式编辑器'` | 弹框标题 |
|
||||||
|
| header | `string` | - | 编辑器 header 标题,如果不设置,默认使用表单项`label`字段 |
|
||||||
|
| evalMode | `boolean` | `true` | 表达式模式 或者 模板模式,模板模式则需要将表达式写在 `${` 和 `}` 中间。 |
|
||||||
|
| variables | `{label: string; value: string; children?: any[]; tag?: string}[]` | `[]` | 可用变量 |
|
||||||
|
| variableMode | `string` | `list` | 可配置成 `tabs` 或者 `tree` 默认为列表,支持分组。 |
|
||||||
|
| functions | `Object[]` | - | 可以不设置,默认就是 amis-formula 里面定义的函数,如果扩充了新的函数则需要指定 |
|
||||||
|
| inputMode | `'button' \| 'input-button' \| 'input-group'` | - | 控件的展示模式 |
|
||||||
|
| icon | `string` | - | 按钮图标,例如`fa fa-list` |
|
||||||
|
| btnLabel | `string` | `'公示编辑'` | 按钮文本,`inputMode`为`button`时生效 |
|
||||||
|
| level | `'info' \| 'success' \| 'warning' \| 'danger' \| 'link' \| 'primary' \| 'dark' \| 'light'` | `default` | 按钮样式 |
|
||||||
|
| allowInput | `boolean` | - | 输入框是否可输入 |
|
||||||
|
| btnSize | `'xs' \| 'sm' \| 'md' \| 'lg'` | - | 按钮大小 |
|
||||||
|
| borderMode | `'full' \| 'half' \| 'none'` | - | 输入框边框模式 |
|
||||||
|
| placeholder | `string` | `'暂无数据'` | 输入框占位符 |
|
||||||
|
| className | `string` | - | 控件外层 CSS 样式类名 |
|
||||||
|
| variableClassName | `string` | - | 变量面板 CSS 样式类名 |
|
||||||
|
| functionClassName | `string` | - | 函数面板 CSS 样式类名 |
|
||||||
151
docs/zh-CN/components/form/input-group.md
Executable file
151
docs/zh-CN/components/form/input-group.md
Executable file
@@ -0,0 +1,151 @@
|
|||||||
|
---
|
||||||
|
title: Input-Group 输入框组合
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: Input-Group
|
||||||
|
icon:
|
||||||
|
order: 28
|
||||||
|
---
|
||||||
|
|
||||||
|
**输入框组合选择器** 可用于输入框与其他组件进行组合。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-group",
|
||||||
|
"name": "input-group",
|
||||||
|
"label": "input 组合",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"placeholder": "搜索作业ID/名称",
|
||||||
|
"inputClassName": "b-r-none p-r-none",
|
||||||
|
"name": "input-group"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "submit",
|
||||||
|
"label": "搜索",
|
||||||
|
"level": "primary"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-group",
|
||||||
|
"label": "各种组合",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "memoryUnits",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Gi",
|
||||||
|
"value": "Gi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Mi",
|
||||||
|
"value": "Mi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Ki",
|
||||||
|
"value": "Ki"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "Gi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "memory"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "memoryUnits2",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Gi",
|
||||||
|
"value": "Gi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Mi",
|
||||||
|
"value": "Mi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Ki",
|
||||||
|
"value": "Ki"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"value": "Gi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "Go"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 校验
|
||||||
|
|
||||||
|
input-group 配置校验方法较为特殊,需要配置下面步骤:
|
||||||
|
|
||||||
|
1. input-group 上配置任意`name`值 (必填, 否则表单内存在多个输入组合时无法定位)
|
||||||
|
2. input-group 的 body 内配置的表单项上配置校验规则
|
||||||
|
3. 如果 input-group 的子元素配置了`label`, 则会在校验失败时作为标识符展示, 否则仅使用索引值作为标识符
|
||||||
|
4. 单个子元素多条校验信息会使用`; `分隔
|
||||||
|
5. 可以使用`"errorMode": "full" | "partial"`设置错误提示风格, `full`整体飘红, `partial`仅错误元素飘红, 默认为`"full"`
|
||||||
|
|
||||||
|
> 细粒度错误提示需`2.7.1`及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-group",
|
||||||
|
"name": "input-group",
|
||||||
|
"label": "输入组合校验",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"placeholder": "请输入长度不超过6的数字类型",
|
||||||
|
"name": "group-input1",
|
||||||
|
"label": "子元素一",
|
||||||
|
"validations": {
|
||||||
|
"isNumeric": true,
|
||||||
|
"maxLength": 6
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"placeholder": "请输入长度不少于5的文本",
|
||||||
|
"name": "group-input2",
|
||||||
|
"required": true,
|
||||||
|
"validations": {
|
||||||
|
"minLength": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ---------------- | ----------------------------------------- | -------- | ----------------------------------------------------- | ------- |
|
||||||
|
| className | `string` | | CSS 类名 | |
|
||||||
|
| body | Array<[表单项](./formitem)> | | 表单项集合 | |
|
||||||
|
| validationConfig | `Record<'errorMode' \| 'delimiter', any>` | - | 校验相关配置, 具体配置属性如下 | `2.8.0` |
|
||||||
|
| +errorMode | `"full" \| "partial"` | `"full"` | 错误提示风格, `full`整体飘红, `partial`仅错误元素飘红 | `2.8.0` |
|
||||||
|
| +delimiter | `string` | `"; "` | 单个子元素多条校验信息的分隔符 | `2.8.0` |
|
||||||
770
docs/zh-CN/components/form/input-image.md
Executable file
770
docs/zh-CN/components/form/input-image.md
Executable file
@@ -0,0 +1,770 @@
|
|||||||
|
---
|
||||||
|
title: InputImage 图片
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputImage
|
||||||
|
icon:
|
||||||
|
order: 27
|
||||||
|
---
|
||||||
|
|
||||||
|
图片格式输入,需要实现接收器,提交时将以 url 的方式提交,如果需要以表单方式提交请使用 [InputFile](input-file#作为表单项上传)。
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "image",
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
默认情况下,选中文件后,就会自动调用 `receiver` 配置里的接口进行上传,比如 node 版本的示例如下:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const express = require('express');
|
||||||
|
const multer = require('multer');
|
||||||
|
const upload = multer({dest: 'uploads/'});
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
// 默认情况下是 file 字段名作为文件参数,也可以通过 fileField 配置来改成别的名字
|
||||||
|
app.post('/uploader', upload.single('file'), function (req, res, next) {
|
||||||
|
res.json({
|
||||||
|
status: 0,
|
||||||
|
data: {
|
||||||
|
value: '/' + req.file.path
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 配合上面的返回值,将 uploads 目录可读,这样返回的文件才能正常显示
|
||||||
|
app.get('uploads', express.static('uploads'));
|
||||||
|
|
||||||
|
app.listen(8080, function () {});
|
||||||
|
```
|
||||||
|
|
||||||
|
这个接口需要返回图片地址,比如下面的格式
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"value": "https:/xxx.yy/zz.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
点击表单提交的时候,实际提交的就是这个返回的图片地址,比如上面的例子是 `image`,则会提交
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"image": "https:/xxx.yy/zz.png"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 限制文件类型
|
||||||
|
|
||||||
|
可以配置`accept`来限制可选择的文件类型,格式是文件后缀名`.xxx`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "限制只能上传jpg图片",
|
||||||
|
"accept": ".jpg",
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
想要限制多个类型,则用逗号分隔,例如:`.jpg,.png`
|
||||||
|
|
||||||
|
## 限制文件宽度
|
||||||
|
|
||||||
|
配置 `limit`,更多属性请参考后面的属性说明。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "限制只能上传宽度大于 1000 的图片",
|
||||||
|
"accept": ".jpg",
|
||||||
|
"limit": {
|
||||||
|
"minWidth": 1000
|
||||||
|
},
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 限制文件大小
|
||||||
|
|
||||||
|
配置 `maxSize`,限制文件大小,单位为 `B`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "上传文件不能大于 1K",
|
||||||
|
"accept": ".jpg",
|
||||||
|
"maxSize": 1024,
|
||||||
|
"receiver": "/api/upload/file"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持裁剪
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "上传后裁剪",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"crop": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
设置裁剪比例等配置,具体细节可以参考[这里](https://github.com/fengyuanchen/cropperjs#options)。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "上传后裁剪",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"crop": {
|
||||||
|
"aspectRatio": 1.7777
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
默认情况下裁剪结果是 `png` 格式,如果要支持其它格式,请设置 `cropFormat`,比如下面设置为 `jpeg` 格式,同时设置质量为 `0.9`
|
||||||
|
|
||||||
|
> 1.4.0 及以上版本
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "上传后裁剪",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"crop": true,
|
||||||
|
"cropFormat": "image/jpeg",
|
||||||
|
"cropQuality": 0.9
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 手动上传
|
||||||
|
|
||||||
|
默认`"autoUpload": true`,即添加文件后自动上传。可以设置`"autoUpload": false`关闭自动上传,此时通过点击底部上传按钮上传。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"data": {
|
||||||
|
"file": {
|
||||||
|
"id":"2ba48d02d348",
|
||||||
|
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file(single).md",
|
||||||
|
"name":"file(single).md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"id":"2ba48d02d349",
|
||||||
|
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file1.md",
|
||||||
|
"name":"file1.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "14723e0bc640",
|
||||||
|
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file2.md",
|
||||||
|
"name":"file2.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "files",
|
||||||
|
"label": "File(多选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "image/jpeg, image/jpg, image/png, image/gif",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": true,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File(单选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "image/jpeg, image/jpg, image/png, image/gif",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": false,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 隐藏上传按钮
|
||||||
|
|
||||||
|
设置 `"hideUploadButton": true` 隐藏手动上传的按钮。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"data": {
|
||||||
|
"file": {
|
||||||
|
"id":"2ba48d02d348",
|
||||||
|
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file(single).md",
|
||||||
|
"name":"file(single).md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"id":"2ba48d02d349",
|
||||||
|
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file1.md",
|
||||||
|
"name":"file1.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "14723e0bc640",
|
||||||
|
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
|
||||||
|
"filename":"file2.md",
|
||||||
|
"name":"file2.md",
|
||||||
|
"state":"uploaded"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "files",
|
||||||
|
"label": "File(多选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "image/jpeg, image/jpg, image/png, image/gif",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": true,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"hideUploadButton": true,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "file",
|
||||||
|
"label": "File(单选)",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"labelAlign": "left",
|
||||||
|
"accept": "image/jpeg, image/jpg, image/png, image/gif",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"multiple": false,
|
||||||
|
"autoUpload": false,
|
||||||
|
"joinValues": false,
|
||||||
|
"hideUploadButton": true,
|
||||||
|
"onEvent": {
|
||||||
|
"success": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "toast",
|
||||||
|
"args": {
|
||||||
|
"msgType": "info",
|
||||||
|
"msg": "「${event.data.path}」上传成功"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果浏览器支持,还能设置为 `image/webp`
|
||||||
|
|
||||||
|
## 自动填充
|
||||||
|
|
||||||
|
上传成功后,可以通过配置 `autoFill` 将上传接口返回的值填充到某个表单项中:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "image",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${url}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"name": "myUrl",
|
||||||
|
"label": "url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中,image 组件上传后,接口返回格式例如如下:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"value": "xxxxxxx",
|
||||||
|
"filename": "xxxx.jpg",
|
||||||
|
"url": "http://xxxx.xxx.xxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
然后 image 上配置:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${url}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
这样上传成功后,会把接口中的 `url` 变量,赋值给 `myUrl` 变量,这个里支持表达式,比如在前面加上域名
|
||||||
|
|
||||||
|
```json
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "https://cdn.com/${filename}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 多选模式
|
||||||
|
|
||||||
|
当表单项为多选模式时,不能再直接取选项中的值了,而是通过 `items` 变量来取,通过它可以获取当前选中的选项集合。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "image",
|
||||||
|
"multiple": true,
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"myUrl": "${items|pick:url}",
|
||||||
|
"lastUrl": "${items|last|pick:url}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"label": false,
|
||||||
|
"inline": false,
|
||||||
|
"tpl": "<strong>myUrl集合</strong>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "each",
|
||||||
|
"name": "myUrl",
|
||||||
|
"className": "mb-1",
|
||||||
|
"items": {
|
||||||
|
"type": "tpl",
|
||||||
|
"tpl": "<span class='label label-info m-l-sm inline-block mb-1'>${item}</span>"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tpl",
|
||||||
|
"label": false,
|
||||||
|
"inline": false,
|
||||||
|
"tpl": "<strong>lastUrl</strong>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"name": "lastUrl",
|
||||||
|
"label": "lastUrl",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 其他表单项填充
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "表单",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"label": "选项",
|
||||||
|
"name": "imageUrl",
|
||||||
|
"delimiter": "|",
|
||||||
|
"autoFill": {
|
||||||
|
"inputImage": "${value}"
|
||||||
|
},
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "imageURL",
|
||||||
|
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "空链接",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"label": "图片上传",
|
||||||
|
"name": "inputImage",
|
||||||
|
"imageClassName": "r w-full"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### initAutoFill 初始化时自动同步
|
||||||
|
|
||||||
|
当表单反显时,可通过`initAutoFill`控制`autoFill`在数据反显时是否执行。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
type: 'crud',
|
||||||
|
api: '/api/mock2/crud/list',
|
||||||
|
perPage: 3,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'operation',
|
||||||
|
label: '操作',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
label: '修改',
|
||||||
|
level: 'link',
|
||||||
|
size: 'xs',
|
||||||
|
actionType: 'dialog',
|
||||||
|
dialog: {
|
||||||
|
title: '修改',
|
||||||
|
size: 'lg',
|
||||||
|
body: {
|
||||||
|
"type": "form",
|
||||||
|
"horizontal": {
|
||||||
|
"left": 3,
|
||||||
|
"right": 9
|
||||||
|
},
|
||||||
|
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "image",
|
||||||
|
"receiver": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"text": "${url}"
|
||||||
|
},
|
||||||
|
"initAutoFill": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "text",
|
||||||
|
"label": "文本",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "carousel",
|
||||||
|
"label": "image",
|
||||||
|
"receiver": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/upload/file",
|
||||||
|
"autoFill": {
|
||||||
|
"id": "${url}"
|
||||||
|
},
|
||||||
|
"initAutoFill": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "id",
|
||||||
|
"label": "ID",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
label: 'ID',
|
||||||
|
type: 'text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'text',
|
||||||
|
label: '文本',
|
||||||
|
type: 'text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
label: '图片',
|
||||||
|
name: 'image',
|
||||||
|
enlargeAble: true,
|
||||||
|
title: '233',
|
||||||
|
thumbMode: 'cover'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'carousel',
|
||||||
|
label: '轮播图',
|
||||||
|
type: 'carousel',
|
||||||
|
width: '300'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 拖拽排序
|
||||||
|
|
||||||
|
可配置 `draggable` 为 `true` 启动拖拽排序。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"title": "表单",
|
||||||
|
data: {
|
||||||
|
image: [
|
||||||
|
'http://www.sortablejs.com/assets/img/npm.png',
|
||||||
|
'http://www.sortablejs.com/assets/img/bower.png',
|
||||||
|
'http://www.sortablejs.com/assets/img/js.png'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
'Images: <br />${image|split|join:"<br />"}',
|
||||||
|
{
|
||||||
|
type: 'input-image',
|
||||||
|
name: 'image',
|
||||||
|
multiple: true,
|
||||||
|
draggable: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
|--------------------|-------------------------------------------------------|------------------------|-----------------------------------------------------------------------------------|
|
||||||
|
| receiver | [API](../../../docs/types/api) | | 上传文件接口 |
|
||||||
|
| accept | `string` | `.jpeg,.jpg,.png,.gif` | 支持的图片类型格式,请配置此属性为图片后缀,例如`.jpg,.png` |
|
||||||
|
| capture | `string` | `undefined` | 用于控制 input[type=file] 标签的 capture 属性,在移动端可控制输入来源 |
|
||||||
|
| maxSize | `number` | | 默认没有限制,当设置后,文件大小大于此值将不允许上传。单位为`B` |
|
||||||
|
| maxLength | `number` | | 默认没有限制,当设置后,一次只允许上传指定数量文件。 |
|
||||||
|
| multiple | `boolean` | `false` | 是否多选。 |
|
||||||
|
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||||
|
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||||
|
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
|
||||||
|
| autoUpload | `boolean` | `true` | 否选择完就自动开始上传 |
|
||||||
|
| hideUploadButton | `boolean` | `false` | 隐藏上传按钮 |
|
||||||
|
| fileField | `string` | `file` | 如果你不想自己存储,则可以忽略此属性。 |
|
||||||
|
| crop | `boolean`或`{"aspectRatio":""}` | | 用来设置是否支持裁剪。 |
|
||||||
|
| crop.aspectRatio | `number` | | 裁剪比例。浮点型,默认 `1` 即 `1:1`,如果要设置 `16:9` 请设置 `1.7777777777777777` 即 `16 / 9`。。 |
|
||||||
|
| crop.rotatable | `boolean` | `false` | 裁剪时是否可旋转 |
|
||||||
|
| crop.scalable | `boolean` | `false` | 裁剪时是否可缩放 |
|
||||||
|
| crop.viewMode | `number` | `1` | 裁剪时的查看模式,0 是无限制 |
|
||||||
|
| cropFormat | `string` | `image/png` | 裁剪文件格式 |
|
||||||
|
| cropQuality | `number` | `1` | 裁剪文件格式的质量,用于 jpeg/webp,取值在 0 和 1 之间 |
|
||||||
|
| limit | Limit | | 限制图片大小,超出不让上传。 |
|
||||||
|
| frameImage | `string` | | 默认占位图地址 |
|
||||||
|
| fixedSize | `boolean` | | 是否开启固定尺寸,若开启,需同时设置 fixedSizeClassName |
|
||||||
|
| fixedSizeClassName | `string` | | 开启固定尺寸时,根据此值控制展示尺寸。例如`h-30`,即图片框高为 h-30,AMIS 将自动缩放比率设置默认图所占位置的宽度,最终上传图片根据此尺寸对应缩放。 |
|
||||||
|
| initAutoFill | `boolean` | `false` | 表单反显时是否执行 autoFill |
|
||||||
|
| uploadBtnText | `string` \| [SchemaNode](../../docs/types/schemanode) | | 上传按钮文案。支持 tpl、schema 形式配置。 |
|
||||||
|
| dropCrop | `boolean` | `true` | 图片上传后是否进入裁剪模式 |
|
||||||
|
| initCrop | `boolean` | `false` | 图片选择器初始化后是否立即进入裁剪模式 |
|
||||||
|
| draggable | `boolean` | false | 开启后支持拖拽排序改变图片值顺序 |
|
||||||
|
| draggableTip | `string` | '拖拽排序' | 拖拽提示文案 |
|
||||||
|
| showErrorModal | `boolean` | `true` | 校验失败后是否弹窗提醒 |
|
||||||
|
| invalidTypeMessage | `string` | '文件格式不正确' | 校验格式失败后的提示信息 | |
|
||||||
|
| invalidSizeMessage | `string` | '文件大小超出限制' | 校验文件大小失败时显示的文字信息 | |
|
||||||
|
|
||||||
|
### Limit 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ----------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| width | `number` | | 限制图片宽度。 |
|
||||||
|
| height | `number` | | 限制图片高度。 |
|
||||||
|
| minWidth | `number` | | 限制图片最小宽度。 |
|
||||||
|
| minHeight | `number` | | 限制图片最小高度。 |
|
||||||
|
| maxWidth | `number` | | 限制图片最大宽度。 |
|
||||||
|
| maxHeight | `number` | | 限制图片最大高度。 |
|
||||||
|
| aspectRatio | `number` | | 限制图片宽高比,格式为浮点型数字,默认 `1` 即 `1:1`,如果要设置 `16:9` 请设置 `1.7777777777777777` 即 `16 / 9`。 如果不想限制比率,请设置空字符串。 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`file`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
|
||||||
|
| change | `[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件值变化时触发(上传失败同样会触发) |
|
||||||
|
| remove | `item: FileValue` 被移除的文件<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 移除文件时触发 |
|
||||||
|
| success | `item: FileValue` 上传的文件<br/>`result: any` 远程上传请求成功后接口返回的结果数据<br/>`id: string` id<br />`[name]: FileValue` 组件的值 | 上传成功时触发 |
|
||||||
|
| fail | `item: FileValue` 上传的文件 <br /> `error: object` 远程上传请求失败后返回的错误信息<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件失败时触发 |
|
||||||
|
|
||||||
|
### FileValue 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 说明 |
|
||||||
|
| ------ | -------- | -------------------------------------------------- |
|
||||||
|
| name | `string` | 图片名称 |
|
||||||
|
| value | `string` | 上传成功后返回的 url |
|
||||||
|
| state | `string` | 文件当前状态,值可为 `pending` `uploaded` `invalid` |
|
||||||
|
| error | `string` | 错误信息 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | -------- | ---- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-image",
|
||||||
|
"name": "image",
|
||||||
|
"label": "Image",
|
||||||
|
"receiver": "/api/upload/file",
|
||||||
|
"id": "clear_text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
229
docs/zh-CN/components/form/input-kv.md
Normal file
229
docs/zh-CN/components/form/input-kv.md
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
---
|
||||||
|
title: InputKV 键值对
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputKV
|
||||||
|
icon:
|
||||||
|
order: 14
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
`input-kv` 是用来支持对象形式的数据编辑,比如类似这样的数据:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"css": {
|
||||||
|
"width": 1,
|
||||||
|
"height": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`css` 中的 key 是不确定的,没法用 combo 来实现,这时可以使用 `input-kv`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "kv"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
最终发送的数据将会是
|
||||||
|
|
||||||
|
## 自定义 value 的格式
|
||||||
|
|
||||||
|
key 只能是字符串,因此输入格式是 `input-text`,但 value 格式可通过 `valueType` 自定义。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "kv",
|
||||||
|
"valueType": "input-number"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义 value 的默认值
|
||||||
|
|
||||||
|
通过 `defaultValue` 设置默认值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "css",
|
||||||
|
"defaultValue": "1.0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义 value 的 schema
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
默认创建的 value schema 是
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"placeholder": "Value",
|
||||||
|
"type": "input-text",
|
||||||
|
"name": "value"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
前面的配置可以改其中的 type 或 placeholder,而这个新的 `valueSchema` 配置就能做到替换所有配置,比如
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "css",
|
||||||
|
"valueSchema": {
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义 key schema
|
||||||
|
|
||||||
|
> 3.1.0 及以上版本
|
||||||
|
|
||||||
|
和前面的 value schema 类似,还可以自定义 key 的 schema
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "css",
|
||||||
|
"keySchema": {
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "A",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "B",
|
||||||
|
"value": "b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "C",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关闭可拖拽排序
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "css",
|
||||||
|
"draggable": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 自定义提示信息
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kv",
|
||||||
|
"name": "css",
|
||||||
|
"keyPlaceholder": "属性",
|
||||||
|
"valuePlaceholder": "值"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| ---------------- | --------- | -------------- | ---------------------------- |
|
||||||
|
| valueType | `type` | `"input-text"` | 值类型 |
|
||||||
|
| keyPlaceholder | `string` | | key 的提示信息的 |
|
||||||
|
| valuePlaceholder | `string` | | value 的提示信息的 |
|
||||||
|
| draggable | `boolean` | true | 是否可拖拽排序 |
|
||||||
|
| defaultValue | | `''` | 默认值 |
|
||||||
|
| autoParseJSON | `boolean` | `true` | 是否自动转换 json 对象字符串 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------------------------------------------------------------------ | ---------------- |
|
||||||
|
| add | `[name]: string \| string[]` 组件的值 | 添加组合项时触发 |
|
||||||
|
| delete | `key: number` 移除项的索引<br />`item: string` 移除项<br />`[name]: object` 组件的值 | 删除组合项时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------ | ------------------------------------------------ |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: object` 更新的值 | 更新数据 |
|
||||||
320
docs/zh-CN/components/form/input-kvs.md
Normal file
320
docs/zh-CN/components/form/input-kvs.md
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
---
|
||||||
|
title: InputKVS 键值对象
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputKVS
|
||||||
|
icon:
|
||||||
|
order: 15
|
||||||
|
---
|
||||||
|
|
||||||
|
> 2.1.0 及以上版本
|
||||||
|
|
||||||
|
这个组件的功能和 `input-kv` 类似,`input-kv` 的 value 值只支持一个对象,`input-kvs` 的最大不同就是 value 支持对象和数组,可以用来支持深层结构编辑
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "field",
|
||||||
|
"addButtonText": "新增字段",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "字段名"
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "primary",
|
||||||
|
"label": "是否是主键"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "type",
|
||||||
|
"label": "字段类型",
|
||||||
|
"options": [
|
||||||
|
"text",
|
||||||
|
"int",
|
||||||
|
"float"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
其中 `keyItem` 可以用来修改 key 值控件,比如可以改成下拉框
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "field",
|
||||||
|
"addButtonText": "新增字段",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "字段名",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"id",
|
||||||
|
"title",
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "primary",
|
||||||
|
"label": "是否是主键"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "type",
|
||||||
|
"label": "字段类型",
|
||||||
|
"options": [
|
||||||
|
"text",
|
||||||
|
"int",
|
||||||
|
"float"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
而 `valueItems` 是用来控制值的控件,这里的配置和 combo 的 items 一样,唯一限制是不允许有 `"name": "_key"` 值的情况,因为这个值被当成对象 key 了。
|
||||||
|
|
||||||
|
## 水平模式
|
||||||
|
|
||||||
|
通过 `"mode": "horizontal"` 设置,需要分别在 `keyItem` 和 `valueItems` 里设置
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "field",
|
||||||
|
"addButtonText": "新增字段",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "字段名",
|
||||||
|
"mode": "horizontal"
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "primary",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"label": "是否是主键"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "type",
|
||||||
|
"label": "字段类型",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"options": [
|
||||||
|
"text",
|
||||||
|
"int",
|
||||||
|
"float"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 嵌套的场景
|
||||||
|
|
||||||
|
`valueItems` 可以进一步嵌套,比如里面又嵌一个 `input-kvs` 实现深层结构编辑
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "dataModel",
|
||||||
|
"addButtonText": "新增表",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "表名",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"table1",
|
||||||
|
"table2",
|
||||||
|
"table3"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"addButtonText": "新增字段",
|
||||||
|
"name": "column",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "字段名",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"id",
|
||||||
|
"title",
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "primary",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"label": "是否是主键"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "type",
|
||||||
|
"label": "字段类型",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"options": [
|
||||||
|
"text",
|
||||||
|
"int",
|
||||||
|
"float"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
前面的嵌套会多一个层级,如果想去掉这个层级 `column`,可以将 `"name": "column"` 改成 `"name": "_value"`,这时值就会直接放入
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "dataModel",
|
||||||
|
"addButtonText": "新增表",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "表名",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"table1",
|
||||||
|
"table2",
|
||||||
|
"table3"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"addButtonText": "新增字段",
|
||||||
|
"name": "_value",
|
||||||
|
"keyItem": {
|
||||||
|
"label": "字段名",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"id",
|
||||||
|
"title",
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
"type": "switch",
|
||||||
|
"name": "primary",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"label": "是否是主键"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "type",
|
||||||
|
"label": "字段类型",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"options": [
|
||||||
|
"text",
|
||||||
|
"int",
|
||||||
|
"float"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
除了前面的对象,值也可以是数组,需要配置一下 `valueIsArray`
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-kvs",
|
||||||
|
"name": "dataModel",
|
||||||
|
"addButtonText": "新增表",
|
||||||
|
"valueIsArray": true,
|
||||||
|
"keyItem": {
|
||||||
|
"label": "表名",
|
||||||
|
"mode": "horizontal",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"table1",
|
||||||
|
"table2",
|
||||||
|
"table3"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"valueItems": [
|
||||||
|
{
|
||||||
|
type: 'checkboxes',
|
||||||
|
name: '_value',
|
||||||
|
joinValues: false,
|
||||||
|
extractValue: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '查询',
|
||||||
|
value: 'select'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '写入',
|
||||||
|
value: 'insert'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '更新',
|
||||||
|
value: 'update'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
value: 'delete'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
106
docs/zh-CN/components/form/input-month-range.md
Normal file
106
docs/zh-CN/components/form/input-month-range.md
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
---
|
||||||
|
title: InputMonthRange 月份范围
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputMonthRange
|
||||||
|
icon:
|
||||||
|
order: 15
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month-range",
|
||||||
|
"name": "a",
|
||||||
|
"label": "月份范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内嵌模式
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month-range",
|
||||||
|
"name": "a",
|
||||||
|
"label": "月份范围",
|
||||||
|
"embed": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 存成两个字段
|
||||||
|
|
||||||
|
默认月份范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month-range",
|
||||||
|
"name": "begin",
|
||||||
|
"extraName": "end",
|
||||||
|
"label": "月份范围"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | --------- | ------------------ | ---------------------------------------------------------------------------------- | ------- |
|
||||||
|
| format | `string` | `X` | [日期选择器值格式](./input-date#%E5%80%BC%E6%A0%BC%E5%BC%8F) |
|
||||||
|
| inputFormat | `string` | `YYYY-DD` | [日期选择器显示格式](./input-date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) |
|
||||||
|
| placeholder | `string` | `"请选择月份范围"` | 占位文本 |
|
||||||
|
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
|
||||||
|
| minDuration | `string` | | 限制最小跨度,如: 2days |
|
||||||
|
| maxDuration | `string` | | 限制最大跨度,如:1year |
|
||||||
|
| utc | `boolean` | `false` | [保存 UTC 值](./input-date#utc) |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| embed | `boolean` | `false` | 是否内联模式 |
|
||||||
|
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
|
||||||
|
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ------------------------------------------- | -------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1646064000,1651334399' |
|
||||||
178
docs/zh-CN/components/form/input-month.md
Executable file
178
docs/zh-CN/components/form/input-month.md
Executable file
@@ -0,0 +1,178 @@
|
|||||||
|
---
|
||||||
|
title: InputMonth 月份
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputMonth 月份
|
||||||
|
icon:
|
||||||
|
order: 81
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "时间"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 显示格式
|
||||||
|
|
||||||
|
选中月份,可以看到默认显示月份的格式是像`01`这样的格式,如果你想要自定义显示格式,那么可以配置`displayFormat`。
|
||||||
|
|
||||||
|
例如你想显示`01月`这样的格式,查找 moment 文档可知配置格式应为 `MM月`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "月份",
|
||||||
|
"displayFormat": "MM月"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
调整月份,观察显示格式
|
||||||
|
|
||||||
|
## 值格式
|
||||||
|
|
||||||
|
选中任意月份,可以看到默认表单项的值格式是像`1582992000`这样的时间戳格式。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "月份"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你想要其他格式的月份值,那么可以配置`valueFormat`参数用于调整表单项的值格式。
|
||||||
|
|
||||||
|
例如你调整值为`01`这样的格式,查找 moment 文档可知配置格式应为 `MM`,即:
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "月份",
|
||||||
|
"valueFormat": "MM"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
调整月份,观察数据域中表单项值的变化
|
||||||
|
|
||||||
|
## 默认值
|
||||||
|
|
||||||
|
可以设置`value`属性,设置月份选择器的默认值
|
||||||
|
|
||||||
|
### 基本配置
|
||||||
|
|
||||||
|
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "月份",
|
||||||
|
"value": "1582992000"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 相对值
|
||||||
|
|
||||||
|
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-month",
|
||||||
|
"name": "month",
|
||||||
|
"label": "月份",
|
||||||
|
"value": "+1month"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
上例中配置了`"value": "+1month"`,默认就会选中一个月后。
|
||||||
|
|
||||||
|
支持的相对值关键字有:
|
||||||
|
|
||||||
|
- `now`: 当前时间
|
||||||
|
- `hour`或`hours`: 时
|
||||||
|
- `minute`或`minutes`: 分
|
||||||
|
- `second`或`seconds`: 秒
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ------------------------ | --------- | -------------- | ----------------------------------------------------------------------------------- | ------- |
|
||||||
|
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
|
||||||
|
| valueFormat | `string` | `X` | 月份选择器值格式,更多格式类型请参考 [moment](http://momentjs.com/) | `3.4.0` |
|
||||||
|
| displayFormat | `string` | `YYYY-MM` | 月份选择器显示格式,即时间戳格式,更多格式类型请参考 [moment](http://momentjs.com/) | `3.4.0` |
|
||||||
|
| placeholder | `string` | `"请选择月份"` | 占位文本 |
|
||||||
|
| clearable | `boolean` | `true` | 是否可清除 |
|
||||||
|
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | -------------------------------- |
|
||||||
|
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
|
||||||
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
|
||||||
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | ---------------------------- | --------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
|
||||||
|
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`valueFormat`,例如:'1646064000' |
|
||||||
417
docs/zh-CN/components/form/input-number.md
Executable file
417
docs/zh-CN/components/form/input-number.md
Executable file
@@ -0,0 +1,417 @@
|
|||||||
|
---
|
||||||
|
title: InputNumber 数字输入框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputNumber
|
||||||
|
icon:
|
||||||
|
order: 32
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设置精度
|
||||||
|
|
||||||
|
`precision` 设置数字的显示精度,一般需要配合 `step` 属性使用,以实现细粒度调整。注意带有单位的输入不支持配置精度属性。若设置了 `step` 值,则会基于 `step` 和 `precision` 的值,选择更高的精度。若输入的内容不满足精度要求,组件会按照精度自动处理,遵循四舍五入规则。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"data": {
|
||||||
|
"number2": 3.1234
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number1",
|
||||||
|
"label": "数字",
|
||||||
|
"precision": 2,
|
||||||
|
"step": 0.01,
|
||||||
|
"value": 2.98786
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number2",
|
||||||
|
"label": "数字2",
|
||||||
|
"precision": 3,
|
||||||
|
"step": 0.001
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number3",
|
||||||
|
"label": "数字3",
|
||||||
|
"step": 0.001,
|
||||||
|
"description": "不设置precision,仅设置step, 实际精度为3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 重置值
|
||||||
|
|
||||||
|
清空/重置组件输入后,组件绑定的值将被设置为 `resetValue`,默认为 `""`。若 `resetValue` 为合法数字时,会根据 `min`、`max` 和 `precision` 属性,将组件值设置为满足条件的值。若 `resetValue` 为非数字,则组件清空/重置后设置为该值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number1",
|
||||||
|
"label": "数字resetValue为0",
|
||||||
|
"resetValue": 0,
|
||||||
|
"value": 1234
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number2",
|
||||||
|
"label": "数字带有min",
|
||||||
|
"min": 100,
|
||||||
|
"resetValue": 0,
|
||||||
|
"value": 1234,
|
||||||
|
"description": "清空输入后组件值变为100,因为设置了最小值min为100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number3",
|
||||||
|
"label": "数字带有max和precision",
|
||||||
|
"max": 100.5,
|
||||||
|
"precision": 2,
|
||||||
|
"resetValue": 1000,
|
||||||
|
"value": 1234,
|
||||||
|
"description": "清空输入后组件值变为100.5,因为设置了最大值max为100.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number4",
|
||||||
|
"label": "数字未设置resetValue",
|
||||||
|
"resetValue": "string",
|
||||||
|
"value": 1234,
|
||||||
|
"description": "清空输入后组件值变为\"string\",因为resetValue不是一个合法的数字"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 前后缀、千分分隔
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"value": 111111,
|
||||||
|
"prefix": "$",
|
||||||
|
"suffix": "%",
|
||||||
|
"kilobitSeparator": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 带单位数字
|
||||||
|
|
||||||
|
> 1.4.0 及以上版本
|
||||||
|
|
||||||
|
可以通过 `unitOptions` 设置数字的单位选项,和前面的前后缀不同,它的输出结果也将会是字符串,包含单位,默认取选项的第一个。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"unitOptions": ["px", "%", "em"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 加强版输入框
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"displayMode": "enhance"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 是否是大数
|
||||||
|
|
||||||
|
> 2.3.0 及以上版本
|
||||||
|
|
||||||
|
默认情况下使用 JavaScript 原生数字类型,但如果要支持输入超过 JavaScript 支持范围的整数或浮点数,可以通过 `"big": true` 开启大数支持,开启之后输入输出都将是字符串。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"big": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内容清空时删除字段
|
||||||
|
|
||||||
|
> 2.8.0 及以上版本
|
||||||
|
|
||||||
|
如果设置了 `"clearValueOnEmpty": true`,当输入框的值清空时,会从数据域中删除该表单项对应的值。比较常见的用法是在 `combo`、`input-array` 等组件中避免 `input-number` 清空后提交空字符串。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"debugConfig": {
|
||||||
|
"levelExpand": 2
|
||||||
|
},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"name": "numberClear",
|
||||||
|
"type": "input-number",
|
||||||
|
"label": "清空",
|
||||||
|
"value": 123,
|
||||||
|
"clearValueOnEmpty": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "numberNotClear",
|
||||||
|
"type": "input-number",
|
||||||
|
"label": "不清空",
|
||||||
|
"value": 456
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "combo",
|
||||||
|
"name": "user",
|
||||||
|
"label": "用户",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"name": "text",
|
||||||
|
"label": "名字",
|
||||||
|
"type": "input-text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "gender",
|
||||||
|
"label": "性别",
|
||||||
|
"type": "select",
|
||||||
|
"options": ["男", "女"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "age",
|
||||||
|
"label": "年龄",
|
||||||
|
"type": "input-number",
|
||||||
|
"clearValueOnEmpty": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 原生数字组件
|
||||||
|
|
||||||
|
原生数字组件将直接使用浏览器的实现,最终展现效果和浏览器有关,并且只支持 `min`、`max` 和 `step` 这几个属性设置,这个功能主要是给移动端浏览器使用的,PC 下不建议使用。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "native-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|
||||||
|
| ----------------- | --------------------------------------- | -------- | ------------------------------------------- | ------- |
|
||||||
|
| min | [模板](../../../docs/concepts/template) | | 最小值 |
|
||||||
|
| max | [模板](../../../docs/concepts/template) | | 最大值 |
|
||||||
|
| step | `number` | | 步长 |
|
||||||
|
| precision | `number` | | 精度,即小数点后几位,支持 0 和正整数 |
|
||||||
|
| showSteps | `boolean` | `true` | 是否显示上下点击按钮 |
|
||||||
|
| readOnly | `boolean` | `false` | 只读 |
|
||||||
|
| prefix | `string` | | 前缀 |
|
||||||
|
| suffix | `string` | | 后缀 |
|
||||||
|
| unitOptions | `string[]` | | 单位选项 | `1.4.0` |
|
||||||
|
| kilobitSeparator | `boolean` | `false` | 千分分隔 |
|
||||||
|
| keyboard | `boolean` | `true` | 键盘事件(方向上下) |
|
||||||
|
| big | `boolean` | `false` | 是否使用大数 | `2.3.0` |
|
||||||
|
| displayMode | `"base" \| "enhance"` | `"base"` | 样式类型 |
|
||||||
|
| borderMode | `"full" \| "half" \| "none"` | `"full"` | 边框模式,全边框,还是半边框,或者没边框 |
|
||||||
|
| resetValue | `number \| string` | `""` | 清空输入内容时,组件值将设置为 `resetValue` |
|
||||||
|
| clearValueOnEmpty | `boolean` | `false` | 内容为空时从数据域中删除该表单项对应的值 | `2.8.0` |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
当前组件会对外派发以下事件,可以通过 `onEvent` 来监听这些事件,并通过 `actions` 来配置执行的动作,在 `actions` 中可以通过 `${事件参数名}` 或 `${event.data.[事件参数名]}` 来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
||||||
|
|
||||||
|
> `[name]` 表示当前组件绑定的名称,即 `name` 属性,如果没有配置 `name` 属性,则通过 `value` 取值。
|
||||||
|
|
||||||
|
| 事件名称 | 事件参数 | 说明 |
|
||||||
|
| -------- | ------------------------- | ---------------- |
|
||||||
|
| change | `[name]: number` 组件的值 | 输入值变化时触发 |
|
||||||
|
| blur | `[name]: number` 组件的值 | - |
|
||||||
|
| focus | `[name]: number` 组件的值 | - |
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
当前组件对外暴露以下特性动作,其他组件可以通过指定 `actionType: 动作名称`、`componentId: 该组件id` 来触发这些动作,动作配置可以通过 `args: {动作配置项名称: xxx}` 来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
||||||
|
|
||||||
|
| 动作名称 | 动作配置 | 说明 |
|
||||||
|
| -------- | -------------------------- | -------------------------------------------------------- |
|
||||||
|
| clear | - | 清空 |
|
||||||
|
| reset | - | 将值重置为 `resetValue`,若没有配置 `resetValue`,则清空 |
|
||||||
|
| setValue | `value: number` 更新的数值 | 更新数据 |
|
||||||
|
|
||||||
|
### clear
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"id": "clear_text",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "清空",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "clear",
|
||||||
|
"componentId": "clear_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### reset
|
||||||
|
|
||||||
|
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"id": "reset_text",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "重置",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "reset",
|
||||||
|
"componentId": "reset_text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### setValue
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"debug": true,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-number",
|
||||||
|
"name": "number",
|
||||||
|
"label": "数字",
|
||||||
|
"id": "setvalue_text",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"label": "赋值",
|
||||||
|
"onEvent": {
|
||||||
|
"click": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"actionType": "setValue",
|
||||||
|
"componentId": "setvalue_text",
|
||||||
|
"args": {
|
||||||
|
"value": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
60
docs/zh-CN/components/form/input-password.md
Normal file
60
docs/zh-CN/components/form/input-password.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
title: InputPassword 密码输入框
|
||||||
|
description:
|
||||||
|
type: 0
|
||||||
|
group: null
|
||||||
|
menuName: InputPassword
|
||||||
|
icon:
|
||||||
|
order: 35
|
||||||
|
---
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置密码显/隐藏
|
||||||
|
|
||||||
|
`revealPassword`属性可以设置是否展示密码显/隐按钮,默认为`true`。
|
||||||
|
|
||||||
|
```schema: scope="body"
|
||||||
|
{
|
||||||
|
"type": "form",
|
||||||
|
"api": "/api/mock2/form/saveForm",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "input-password",
|
||||||
|
"name": "password",
|
||||||
|
"label": "密码",
|
||||||
|
"revealPassword": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
|
请参考[输入框](./input-text)
|
||||||
|
|
||||||
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
|
| -------------- | --------- | ------ | --------------------- |
|
||||||
|
| revealPassword | `boolean` | `true` | 是否展示密码显/隐按钮 |
|
||||||
|
|
||||||
|
## 事件表
|
||||||
|
|
||||||
|
请参考[输入框](./input-text)
|
||||||
|
|
||||||
|
## 动作表
|
||||||
|
|
||||||
|
请参考[输入框](./input-text)
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user