mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-02-07 04:55:37 +00:00
13 lines
12 KiB
JavaScript
13 lines
12 KiB
JavaScript
import{ax as d,al as l,z as r,A as h,B as e,R as i,b2 as o,O as a,J as n}from"./chunks/framework.DkLJC2NO.js";const x=JSON.parse('{"title":"Checkbox 多选框","description":"","frontmatter":{},"headers":[],"relativePath":"form-config/fields/checkbox.md","filePath":"form-config/fields/checkbox.md"}'),p={name:"form-config/fields/checkbox.md"};function k(b,t,u,c,E,g){const s=l("demo-block");return h(),r("div",null,[t[7]||(t[7]=e("h1",{id:"checkbox-多选框",tabindex:"-1"},[a("Checkbox 多选框 "),e("a",{class:"header-anchor",href:"#checkbox-多选框","aria-label":'Permalink to "Checkbox 多选框"'},"")],-1)),t[8]||(t[8]=e("p",null,"一组备选项中进行多选",-1)),t[9]||(t[9]=e("h2",{id:"基础用法",tabindex:"-1"},[a("基础用法 "),e("a",{class:"header-anchor",href:"#基础用法","aria-label":'Permalink to "基础用法"'},"")],-1)),t[10]||(t[10]=e("p",null,"单独使用可以表示两种状态之间的切换。",-1)),i(s,{type:"form",config:[{type:"checkbox",name:"checkbox",text:"选项"}]},{source:n(()=>[...t[0]||(t[0]=[e("p",null," 要使用 Checkbox 组件,只需要配置 type: 'checkbox',选中意味着变量的值为 true。默认绑定变量的值会是 Boolean,选中为 true。 ",-1)])]),_:1}),t[11]||(t[11]=e("h2",{id:"禁用状态",tabindex:"-1"},[a("禁用状态 "),e("a",{class:"header-anchor",href:"#禁用状态","aria-label":'Permalink to "禁用状态"'},"")],-1)),t[12]||(t[12]=e("p",null,"多选框不可用状态。",-1)),i(s,{type:"form",config:[{type:"checkbox",name:"checkbox",text:"选项",disabled:()=>!0}]},{source:n(()=>[...t[1]||(t[1]=[e("p",null," 设置 disabled 属性即可,它接受一个 Boolean,true 为禁用,也可以接受一个返回 Boolean 的函数。 ",-1)])]),_:1}),t[13]||(t[13]=e("h2",{id:"自定义选中值",tabindex:"-1"},[a("自定义选中值 "),e("a",{class:"header-anchor",href:"#自定义选中值","aria-label":'Permalink to "自定义选中值"'},"")],-1)),t[14]||(t[14]=e("p",null,[a("通过 "),e("code",null,"activeValue"),a(" 和 "),e("code",null,"inactiveValue"),a(" 自定义选中和未选中时的值。")],-1)),i(s,{type:"form",config:[{type:"checkbox",name:"checkbox",text:"选项",activeValue:"yes",inactiveValue:"no"}]},{source:n(()=>[...t[2]||(t[2]=[e("p",null," 设置 activeValue 为选中时的值,inactiveValue 为未选中时的值。 ",-1)])]),_:1}),t[15]||(t[15]=e("h2",{id:"数值类型",tabindex:"-1"},[a("数值类型 "),e("a",{class:"header-anchor",href:"#数值类型","aria-label":'Permalink to "数值类型"'},"")],-1)),t[16]||(t[16]=e("p",null,[a("当需要绑定数值类型时,可以使用 "),e("code",null,"filter: 'number'"),a(" 配合默认的 activeValue/inactiveValue。")],-1)),i(s,{type:"form",config:[{type:"checkbox",name:"checkbox",text:"选项",filter:"number"}]},{source:n(()=>[...t[3]||(t[3]=[e("p",null," 配置 filter 为 'number' 时,默认 activeValue 为 1,inactiveValue 为 0。 ",-1)])]),_:1}),t[17]||(t[17]=e("h2",{id:"使用-label-显示",tabindex:"-1"},[a("使用 Label 显示 "),e("a",{class:"header-anchor",href:"#使用-label-显示","aria-label":'Permalink to "使用 Label 显示"'},"")],-1)),t[18]||(t[18]=e("p",null,[a("通过 "),e("code",null,"useLabel"),a(" 属性控制是否使用 label 作为显示内容。")],-1)),i(s,{type:"form",config:[{type:"checkbox",name:"checkbox",text:"选项",useLabel:!0}]},{source:n(()=>[...t[4]||(t[4]=[e("p",null," 设置 useLabel 为 true 时,不显示 text 内容,由外部 label 控制显示。 ",-1)])]),_:1}),t[19]||(t[19]=e("h2",{id:"多选框组",tabindex:"-1"},[a("多选框组 "),e("a",{class:"header-anchor",href:"#多选框组","aria-label":'Permalink to "多选框组"'},"")],-1)),t[20]||(t[20]=e("p",null,"适用于多个勾选框绑定到同一个数组的情景,通过是否勾选来表示这一组选项中选中的项。",-1)),i(s,{type:"form",config:[{type:"checkbox-group",name:"checkbox",text:"选项",options:[{text:"选项1",value:1},{text:"选项2",value:2},{text:"选项3",value:3}]}]},{source:n(()=>[...t[5]||(t[5]=[e("p",null," checkbox-group 元素能把多个 checkbox 管理为一组,绑定值为数组类型。 ",-1)])]),_:1}),t[21]||(t[21]=e("h2",{id:"多选框组禁用选项",tabindex:"-1"},[a("多选框组禁用选项 "),e("a",{class:"header-anchor",href:"#多选框组禁用选项","aria-label":'Permalink to "多选框组禁用选项"'},"")],-1)),t[22]||(t[22]=e("p",null,[a("在选项中设置 "),e("code",null,"disabled"),a(" 可禁用单个选项。")],-1)),i(s,{type:"form",config:[{type:"checkbox-group",name:"checkbox",text:"选项",options:[{text:"选项1",value:1},{text:"选项2",value:2,disabled:!0},{text:"选项3",value:3}]}]},{source:n(()=>[...t[6]||(t[6]=[e("p",null," 在 options 中设置 disabled: true 可禁用该选项。 ",-1)])]),_:1}),t[23]||(t[23]=o(`<h2 id="动态选项" tabindex="-1">动态选项 <a class="header-anchor" href="#动态选项" aria-label="Permalink to "动态选项""></a></h2><p>options 支持函数形式,可根据表单状态动态生成选项。</p><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'checkbox-group'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'checkbox'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> text</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'选项'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> options</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">mForm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, { </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">model</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">formValue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 根据表单值动态返回选项</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { text: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'选项A'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, value: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'a'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { text: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'选项B'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, value: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'b'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ];</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2 id="checkbox-attributes" tabindex="-1">Checkbox Attributes <a class="header-anchor" href="#checkbox-attributes" aria-label="Permalink to "Checkbox Attributes""></a></h2><table tabindex="0"><thead><tr><th>参数</th><th>说明</th><th>类型</th><th>可选值</th><th>默认值</th></tr></thead><tbody><tr><td>name</td><td>绑定值</td><td>string</td><td>—</td><td>—</td></tr><tr><td>text</td><td>表单标签</td><td>string</td><td>—</td><td>—</td></tr><tr><td>disabled</td><td>是否禁用</td><td>boolean / <a href="https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts" target="_blank" rel="noreferrer">FilterFunction</a></td><td>—</td><td>false</td></tr><tr><td>activeValue</td><td>选中时的值</td><td>string / number</td><td>—</td><td>true(filter 为 'number' 时默认 1)</td></tr><tr><td>inactiveValue</td><td>未选中时的值</td><td>string / number</td><td>—</td><td>false(filter 为 'number' 时默认 0)</td></tr><tr><td>useLabel</td><td>是否使用外部 label 显示</td><td>boolean</td><td>—</td><td>false</td></tr><tr><td>filter</td><td>值过滤器</td><td>'number' / Function</td><td>—</td><td>—</td></tr><tr><td>onChange</td><td>值变化时触发的函数</td><td><a href="https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts" target="_blank" rel="noreferrer">OnChangeHandler</a></td><td>—</td><td>—</td></tr></tbody></table><h2 id="checkboxgroup-attributes" tabindex="-1">CheckboxGroup Attributes <a class="header-anchor" href="#checkboxgroup-attributes" aria-label="Permalink to "CheckboxGroup Attributes""></a></h2><table tabindex="0"><thead><tr><th>参数</th><th>说明</th><th>类型</th><th>可选值</th><th>默认值</th></tr></thead><tbody><tr><td>name</td><td>绑定值</td><td>string</td><td>—</td><td>—</td></tr><tr><td>text</td><td>表单标签</td><td>string</td><td>—</td><td>—</td></tr><tr><td>disabled</td><td>是否禁用</td><td>boolean / <a href="https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts" target="_blank" rel="noreferrer">FilterFunction</a></td><td>—</td><td>false</td></tr><tr><td>options</td><td>选项列表</td><td>Array / <a href="https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts" target="_blank" rel="noreferrer">FilterFunction</a></td><td>—</td><td>—</td></tr><tr><td>onChange</td><td>值变化时触发的函数</td><td><a href="https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts" target="_blank" rel="noreferrer">OnChangeHandler</a></td><td>—</td><td>—</td></tr></tbody></table><h2 id="options-item" tabindex="-1">options item <a class="header-anchor" href="#options-item" aria-label="Permalink to "options item""></a></h2><table tabindex="0"><thead><tr><th>参数</th><th>说明</th><th>类型</th><th>可选值</th><th>默认值</th></tr></thead><tbody><tr><td>value</td><td>选项的值</td><td>any</td><td>—</td><td>—</td></tr><tr><td>text</td><td>选项的标签</td><td>string</td><td>—</td><td>—</td></tr><tr><td>disabled</td><td>是否禁用该选项</td><td>boolean</td><td>—</td><td>false</td></tr></tbody></table>`,9))])}const f=d(p,[["render",k]]);export{x as __pageData,f as default};
|