js-components-container-dialog.md 6.8 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# dialog<a name="ZH-CN_TOPIC_0000001173324657"></a>

自定义弹窗容器。

## 权限列表<a name="section11257113618419"></a>



## 子组件<a name="section9288143101012"></a>

支持单个子组件。

## 属性<a name="section2907183951110"></a>

除支持[通用属性](js-components-common-attributes.md)外,支持如下属性:

Z
zengyawen 已提交
17
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="19.598040195980403%" id="mcps1.1.6.1.1"><p>名称</p>
Z
zengyawen 已提交
18
</th>
Z
zengyawen 已提交
19
<th class="cellrowborder" valign="top" width="11.178882111788822%" id="mcps1.1.6.1.2"><p>类型</p>
Z
zengyawen 已提交
20
</th>
Z
zengyawen 已提交
21
<th class="cellrowborder" valign="top" width="9.899010098990102%" id="mcps1.1.6.1.3"><p>默认值</p>
Z
zengyawen 已提交
22
</th>
Z
zengyawen 已提交
23
<th class="cellrowborder" valign="top" width="7.56924307569243%" id="mcps1.1.6.1.4"><p>必填</p>
Z
zengyawen 已提交
24
</th>
Z
zengyawen 已提交
25
<th class="cellrowborder" valign="top" width="51.754824517548236%" id="mcps1.1.6.1.5"><p>描述</p>
Z
zengyawen 已提交
26 27 28
</th>
</tr>
</thead>
Z
zengyawen 已提交
29
<tbody><tr><td class="cellrowborder" valign="top" width="19.598040195980403%" headers="mcps1.1.6.1.1 "><p>dragable<sup><span>7+</span></sup></p>
Z
zengyawen 已提交
30
</td>
Z
zengyawen 已提交
31
<td class="cellrowborder" valign="top" width="11.178882111788822%" headers="mcps1.1.6.1.2 "><p>boolean</p>
Z
zengyawen 已提交
32
</td>
Z
zengyawen 已提交
33
<td class="cellrowborder" valign="top" width="9.899010098990102%" headers="mcps1.1.6.1.3 "><p>false</p>
Z
zengyawen 已提交
34
</td>
Z
zengyawen 已提交
35
<td class="cellrowborder" valign="top" width="7.56924307569243%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
36
</td>
Z
zengyawen 已提交
37
<td class="cellrowborder" valign="top" width="51.754824517548236%" headers="mcps1.1.6.1.5 "><p>设置对话框是否支持拖拽。</p>
Z
zengyawen 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
</td>
</tr>
</tbody>
</table>

>![](../../public_sys-resources/icon-note.gif) **说明:** 
>-   弹窗类组件不支持focusable、click-effect属性。

## 样式<a name="section5775351116"></a>

仅支持[通用样式](js-components-common-styles.md)中的width、height、margin、margin-\[left|top|right|bottom\]、margin-\[start|end\]样式。

## 事件<a name="section8562129182916"></a>

不支持[通用事件](js-components-common-events.md),仅支持如下事件:

Z
zengyawen 已提交
54
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="18.459999999999997%" id="mcps1.1.4.1.1"><p>名称</p>
Z
zengyawen 已提交
55
</th>
Z
zengyawen 已提交
56
<th class="cellrowborder" valign="top" width="30.769999999999996%" id="mcps1.1.4.1.2"><p>参数</p>
Z
zengyawen 已提交
57
</th>
Z
zengyawen 已提交
58
<th class="cellrowborder" valign="top" width="50.77%" id="mcps1.1.4.1.3"><p>描述</p>
Z
zengyawen 已提交
59 60 61
</th>
</tr>
</thead>
Z
zengyawen 已提交
62
<tbody><tr><td class="cellrowborder" valign="top" width="18.459999999999997%" headers="mcps1.1.4.1.1 "><p>cancel</p>
Z
zengyawen 已提交
63
</td>
Z
zengyawen 已提交
64
<td class="cellrowborder" valign="top" width="30.769999999999996%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
65
</td>
Z
zengyawen 已提交
66
<td class="cellrowborder" valign="top" width="50.77%" headers="mcps1.1.4.1.3 "><p>用户点击非dialog区域触发取消弹窗时触发的事件。</p>
Z
zengyawen 已提交
67 68
</td>
</tr>
Z
zengyawen 已提交
69
<tr><td class="cellrowborder" valign="top" width="18.459999999999997%" headers="mcps1.1.4.1.1 "><p>show<sup><span>7+</span></sup></p>
Z
zengyawen 已提交
70
</td>
Z
zengyawen 已提交
71
<td class="cellrowborder" valign="top" width="30.769999999999996%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
72
</td>
Z
zengyawen 已提交
73
<td class="cellrowborder" valign="top" width="50.77%" headers="mcps1.1.4.1.3 "><p>对话框弹出时触发该事件。</p>
Z
zengyawen 已提交
74 75
</td>
</tr>
Z
zengyawen 已提交
76
<tr><td class="cellrowborder" valign="top" width="18.459999999999997%" headers="mcps1.1.4.1.1 "><p>close<sup><span>7+</span></sup></p>
Z
zengyawen 已提交
77
</td>
Z
zengyawen 已提交
78
<td class="cellrowborder" valign="top" width="30.769999999999996%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
79
</td>
Z
zengyawen 已提交
80
<td class="cellrowborder" valign="top" width="50.77%" headers="mcps1.1.4.1.3 "><p>对话框关闭时触发该事件。</p>
Z
zengyawen 已提交
81 82 83 84 85 86 87 88 89
</td>
</tr>
</tbody>
</table>

## 方法<a name="section11753103216253"></a>

不支持[通用方法](js-components-common-methods.md),仅支持如下方法。

Z
zengyawen 已提交
90
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="18.459999999999997%" id="mcps1.1.4.1.1"><p>名称</p>
Z
zengyawen 已提交
91
</th>
Z
zengyawen 已提交
92
<th class="cellrowborder" valign="top" width="30.769999999999996%" id="mcps1.1.4.1.2"><p>参数</p>
Z
zengyawen 已提交
93
</th>
Z
zengyawen 已提交
94
<th class="cellrowborder" valign="top" width="50.77%" id="mcps1.1.4.1.3"><p>描述</p>
Z
zengyawen 已提交
95 96 97
</th>
</tr>
</thead>
Z
zengyawen 已提交
98
<tbody><tr><td class="cellrowborder" valign="top" width="18.459999999999997%" headers="mcps1.1.4.1.1 "><p>show</p>
Z
zengyawen 已提交
99
</td>
Z
zengyawen 已提交
100
<td class="cellrowborder" valign="top" width="30.769999999999996%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
101
</td>
Z
zengyawen 已提交
102
<td class="cellrowborder" valign="top" width="50.77%" headers="mcps1.1.4.1.3 "><p>弹出对话框。</p>
Z
zengyawen 已提交
103 104
</td>
</tr>
Z
zengyawen 已提交
105
<tr><td class="cellrowborder" valign="top" width="18.459999999999997%" headers="mcps1.1.4.1.1 "><p>close</p>
Z
zengyawen 已提交
106
</td>
Z
zengyawen 已提交
107
<td class="cellrowborder" valign="top" width="30.769999999999996%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
108
</td>
Z
zengyawen 已提交
109
<td class="cellrowborder" valign="top" width="50.77%" headers="mcps1.1.4.1.3 "><p>关闭对话框。</p>
Z
zengyawen 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
</td>
</tr>
</tbody>
</table>

>![](../../public_sys-resources/icon-note.gif) **说明:** 
>dialog属性、样式均不支持动态更新。

## 示例<a name="section6663311114620"></a>

```
<!-- xxx.hml -->
<div class="doc-page">
  <div class="btn-div">
    <button type="capsule" value="Click here" class="btn" onclick="showDialog"></button>
  </div>
  <dialog id="simpledialog" dragable="true" class="dialog-main" oncancel="cancelDialog">
    <div class="dialog-div">
      <div class="inner-txt">
        <text class="txt" ondoubleclick="doubleclick">Simple dialog</text>
      </div>
      <div class="inner-btn">
        <button type="capsule" value="Cancel" onclick="cancelSchedule" class="btn-txt"></button>
        <button type="capsule" value="Confirm" onclick="setSchedule" class="btn-txt"></button>
      </div>
    </div>
  </dialog>
</div>
```

```
/* xxx.css */
.doc-page {
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.btn-div {
  width: 100%;
  height: 200px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.btn {
  background-color: #F2F2F2;
  text-color: #0D81F2;
}
.txt {
  color: #000000;
  font-weight: bold;
  font-size: 39px;
}
.dialog-main {
  width: 500px;
}
.dialog-div {
  flex-direction: column;
  align-items: center;
}
.inner-txt {
  width: 400px;
  height: 160px;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}
.inner-btn {
  width: 400px;
  height: 120px;
  justify-content: space-around;
  align-items: center;
}
.btn-txt {
  background-color: #F2F2F2;
  text-color: #0D81F2;
}
```

```
// xxx.js
import prompt from '@system.prompt';
export default {
  showDialog(e) {
    this.$element('simpledialog').show()
  },
  cancelDialog(e) {
    prompt.showToast({
      message: 'Dialog cancelled'
    })
  },
  cancelSchedule(e) {
    this.$element('simpledialog').close()
    prompt.showToast({
      message: 'Successfully cancelled'
    })
  },
  setSchedule(e) {
    this.$element('simpledialog').close()
    prompt.showToast({
      message: 'Successfully confirmed'
    })
  },
  doubleclick(e){
    prompt.showToast({
      message: 'doubleclick'
    })
  }
}
```

![](figures/4.gif)