# 弹出层(Popup)

用于弹窗出现时,让用户聚焦弹窗内容

蒙层样式

遮罩黑色 #0C0C0C 75%

# 示例

<template>
  <div class="wrapper">
    <dof-minibar title="7.2弹出层"></dof-minibar>
    <div class="btn-box">
      <dof-button @dofButtonClicked="isTopShow = true" text="点击弹出顶部面板"></dof-button>
      <dof-button class="m-t-16" @dofButtonClicked="isBottomShow = true" text="点击弹出底部面板"></dof-button>
      <dof-button class="m-t-16" @dofButtonClicked="isBottomShow2 = true" text="点击弹出底部面板(按钮)"></dof-button>
      <dof-button class="m-t-16" @dofButtonClicked="isBottomShow3 = true" text="点击弹出底部面板(选择器)"></dof-button>
      <dof-button
        class="m-t-16"
        @dofButtonClicked="isBottomShow4 = true"
        text="点击弹出底部面板(参数选择)"
      ></dof-button>
    </div>
    <dof-popup :show="isTopShow" pos="top" @dofPopupOverlayClicked="isTopShow = false" :height="564"></dof-popup>
    <dof-popup
      :show="isBottomShow"
      @dofPopupOverlayClicked="isBottomShow = false"
      pos="bottom"
      :height="564"
    ></dof-popup>
    <dof-popup :show="isBottomShow2" @dofPopupOverlayClicked="isBottomShow2 = false" pos="bottom" :height="304">
      <dof-button pattern="base" text="确定" size="big" :btn-style="btnStyle"></dof-button>
      <dof-button pattern="base" text="更多" size="big" :btn-style="{ width: '750px' }"></dof-button>
      <div style="height: 16px; background-color: #151617;"></div>
      <dof-button pattern="base" text="取消" size="big" :btn-style="{ width: '750px' }"></dof-button>
    </dof-popup>
    <dof-popup :show="isBottomShow3" @dofPopupOverlayClicked="isBottomShow3 = false" pos="bottom" :height="636">
      <div class="tabBox">
        <dof-tab-page
          :bgColor="'#1c1e21'"
          type="primary"
          @dofTabSelected="dofTabSelected"
          :tab-titles="[{ title: '已选中' }, { title: '未选中' }]"
        ></dof-tab-page>
      </div>
      <div class="pickerBox">
        <midea-picker class="picker" :config="pickerConfig" @mideaPickerChange="onMideaPickerChange"></midea-picker>
      </div>
      <div style="height: 16px; background-color: #151617;"></div>
      <div class="compose-box">
        <dof-button
          type="primary"
          pattern="base"
          text="取消"
          size="full"
          :btnStyle="{ width: '375px' }"
          @dofButtonClicked="isBottomShow3 = false"
        ></dof-button>
        <dof-button
          type="primary"
          text="确定"
          size="full"
          :btnStyle="{ width: '375px' }"
          @dofButtonClicked="isBottomShow3 = false"
        ></dof-button>
      </div>
    </dof-popup>
    <dof-popup :show="isBottomShow4" @dofPopupOverlayClicked="isBottomShow4 = false" pos="bottom" :height="960">
      <div class="param-title">
        <text class="param-title-text">智能洗</text>
        <dof-iconfont :code="'\u4795'" :size="48" :color="'rgba(255, 255, 255, 0.4)'"></dof-iconfont>
        <text class="param-title-text">| 参数调节</text>
      </div>
      <div class="tabBox">
        <dof-tab-page
          :bgColor="'#1c1e21'"
          type="primary"
          @dofTabSelected="dofTabSelected"
          :tab-titles="[
            { title: '已选中' },
            { title: '未选中' },
            { title: '未选中' },
            { title: '未选中' },
            { title: '未选中' }
          ]"
        ></dof-tab-page>
      </div>
      <div class="pickerBox">
        <midea-picker class="picker" :config="pickerConfig2" @mideaPickerChange="onMideaPickerChange"></midea-picker>
      </div>
      <div class="cellBox">
        <dof-cell
          :cellStyle="{ height: '160px' }"
          :has-arrow="false"
          :isHighlight="false"
          title="功能名称名称"
          desc="我的家 浴室"
        >
          <dof-switch slot="switch" :checked="switchOn" @dof-change="switchOn = !switchOn"></dof-switch>
        </dof-cell>
      </div>

      <div style="height: 16px; background-color: #151617;"></div>
      <div class="compose-box">
        <dof-button
          type="primary"
          pattern="base"
          text="取消"
          size="full"
          :btnStyle="{ width: '375px' }"
          @dofButtonClicked="isBottomShow4 = false"
        ></dof-button>
        <dof-button
          type="primary"
          text="确定"
          size="full"
          :btnStyle="{ width: '375px' }"
          @dofButtonClicked="isBottomShow4 = false"
        ></dof-button>
      </div>
    </dof-popup>
  </div>
</template>

<style scoped>
.wrapper {
  background-color: #f9f9f9;
}
.m-t-16 {
  margin-top: 16px;
}
.title-box {
  padding: 32px;
  background-color: #e5e5e8;
}
.title-text {
  font-family: PingFangSC-Medium;
  font-size: 36px;
  color: #000000;
  font-weight: 500;
}
.btn-box {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 120px;
}
.tabBox {
  height: 104px;
}
.pickerBox {
  height: 420px;
}
.picker {
  width: 750px;
  height: 420px;
}
.picker2 {
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}
.compose-box {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.param-title {
  height: 104px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}
.param-title-text {
  font-family: PingFangSC-Regular;
  font-size: 32px;
  color: rgba(255, 255, 255, 0.8);
}
.cellBox {
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  margin-top: 55px;
}
@media screen and (weex-theme: colmo) {
  .wrapper {
    background-color: #151617;
  }
}
</style>

<script>
import { DofMinibar, DofPopup, DofButton, DofTabPage, DofIconfont, DofCell, DofSwitch } from 'dolphin-weex-ui'
const config = {
  loop: true,
  itemMaps: [],
  textColor: '#d2d2d3', // 选中的字体颜色
  backgroundColor: '#1c1e21', //picker背景色
  dividerColor: '#343538', // 分割线颜色
  type: '0', // 0代表普通picker, 1:联动类型,2:日期类型(年/月/日) 3:时间类型 4:PM2.5/温湿度类型,单位会根据滚动值变化
  value: '2021-03-01', // 如果是时间/日期picker类则传值,格式:"2021-03-01",普通类型picker无值
  wheelList: [
    {
      index: 0,
      isLoop: 1,
      textSize: 20,
      label: '时', // 单位名字
      labelTextColor: '#4a4b4d', //单位颜色
      labelTextSize: '14', //单位字体大小
      itemList: Array.apply(null, { length: 24 }).map((v, k) => {
        return {
          id: k,
          name: k,
          pid: 0
        }
      })
    },
    {
      index: 0,
      isLoop: 1,
      textSize: 20,
      label: '时', // 单位名字
      labelTextColor: '#4a4b4d', //单位颜色
      labelTextSize: '14', //单位字体大小
      itemList: Array.apply(null, { length: 24 }).map((v, k) => {
        return {
          id: k,
          name: k,
          pid: 0
        }
      })
    }
  ]
}
export default {
  components: { DofMinibar, DofPopup, DofButton, DofTabPage, DofIconfont, DofCell, DofSwitch },
  data: () => ({
    show: false,
    isTopShow: false,
    isBottomShow: false,
    isBottomShow2: false,
    isBottomShow3: false,
    isBottomShow4: false,
    btnStyle: { width: '750px', 'border-bottom-width': '1px', 'border-bottom-color': 'rgba(255, 255, 255, 0.1)' },
    pickerConfig: JSON.parse(JSON.stringify(config)),
    pickerConfig2: JSON.parse(JSON.stringify(config)),
    switchOn: false
  }),
  computed: {},
  created() {
    this.pickerConfig2.wheelList.unshift({
      index: 0,
      isLoop: 1,
      textSize: 20,
      label: '℃', // 单位名字
      labelTextColor: '#4a4b4d', //单位颜色
      labelTextSize: '14', //单位字体大小
      itemList: Array.apply(null, { length: 16 }).map((v, k) => {
        return {
          id: k,
          name: k + 20,
          pid: 0
        }
      })
    })
  },
  methods: {
    dofOverlayBodyClicked() {
      this.show = false
    },
    onMideaPickerChange(event) {
      // this.$toast(JSON.stringify(event))
    },
    dofTabSelected(i) {
      this.$toast(i)
    }
  }
}
</script>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

# Attributes

Prop Type Required Default Description
show Boolean Y false 打开或关闭弹层
pos String N bottom 弹出位置top/bottom/left/right
height [Number, String] N 840 弹出层的高度(向上向下时候设置)
width [Number, String] N 750 弹出层的宽度(向左向右时候设置)
button Array N [] 弹窗面板下方有按钮时使用, 例:['取消', '确定']
或者:
[{ text: '确定', textColor: '#f66' }, { text: '取消', textColor: '#666' }]
borderRadius String N 32px 圆角大小

# Events

事件名 说明 回调参数
dofPopupOverlayClicked 关闭 e e.pos
dofPopupButtonClicked 下方按钮点击事件 e e.index, e.text

# Slot

<slot></slot>:匿名插槽,可直接在dof-popup标签内直接使用,替换默认slot占位

# 主动调用关闭

在dof-popup上面绑定ref属性'refname',然后调用this.$refs[refname].hide();即可关闭,常用于自定义主动关闭,它比于直接将`show`属性设为`false`增加了过渡效果,比如在取消操作时可使用,示例代码如下:
1
<script>
  <dof-popup 
      :show="show"
      ref='popup'
      @dofPopupOverlayClicked="isBottomShow=false">
     <dof-button @dofButtonClicked="onHideClick" size="medium" text="主动关闭"></dof-button>
  </dof-popup>

  onHideClick(){
    this.$refs['popup'].hide()
  }
</script>
1
2
3
4
5
6
7
8
9
10
11
12

# 备注

  使用面板按钮时,只需要考虑按钮和间隔条的总高度`120px`即可,组件已针对iPhoneX及其他有Home Indicator的机型做了适配,无需开发者考虑。
1
点我扫二维码 查看demo
Last Updated: 1/4/2024, 4:01:09 PM