Frames 浮动窗口

用来展示信息,或者引导用户操作。

Frames 拖拽弹窗

>{}
<template>
  <div class="test-win-page">
    <Input v-model="the.frameId" style="width:5rem" />
    <ButtonGroup>
      <Button type="info" @click="btnFramed('close')"> 关闭指定id窗口 </Button>
      <Button type="error" @click="btnFramed('clear')"> 关闭所有窗口 </Button>

      <Button type="primary" @click="btnWin"> 弹窗 </Button>
    </ButtonGroup>
    <Button type="primary" @click="btnWin('pull')"> 全屏弹窗 </Button>

    <Button @click="btnWin('model')"> 组件窗口 </Button>

    <Button @click="btnWin('render')"> 多彩函数窗口 </Button>

    <Button @click="btnWin('html')"> Html窗口 </Button>

    <Button @click="btnWin('size')"> Html窗口 指定大小 </Button>
  </div>
</template>

<script>
export default {
  setup() {
    // 使用外挂方式引入,具体查看demo
    const $plus = window.$plus;
    const { reactive, markRaw, h } = $plus.vue;

    const the = reactive({
      frameId: ''
    });

    // 窗口总数
    let framed_count = 0;

    const btnWin = (type) => {
      let _val = {};
      switch (type) {
        case 'model':
          //  console.log('model', List)
          _val = {
            title: '组件窗口',
            //body: '<h5>body</h5',
            model: {
              // 进行非全局组件需标记
              //  component: markRaw(TextPage),
              props: {
                modelValue: { d: 1 }
              },
              component: 'TextJson'
            },
            /** 监听窗口回调 */
            onEvent: (_resp) => {
              console.log('win.on', _resp);
            },
            onClose: (_resp) => {
              // console.log('win.model.close', _resp);
              // 自定义关闭方法
              _resp.close();
            }
          };

          break;

        case 'render':
          _val = {
            title: '函数组件窗口',
            css: 'test-win-skin',
            move: {
              width: 200,
              height: 300
            },
            show: {
              // 隐藏头部
              // head: false,
              close: false
            },
            model: {
              props: {
                title: '测试组件传参数'
              },

              // 函数组件
              component: (props, { emit }) => {
                /**
                 * named 组件原生命名进行回调触发,
                 * 由于是多窗口模式,需要表面来源的窗口命名
                 * 需要加入 byNamed:当前窗口命名,才能接收
                 *
                 * */
                let _resp = { cmd: 'init', named: 'render', data: props.title };
                // 来源窗口组件命名
                _resp.byNamed = win.named;

                const btn = () => {
                  emit('onEvent', _resp);
                };

                const btnClose = () => {
                  emit('onEvent', { cmd: 'close', byNamed: win.named });
                };

                const btnTop = () => {
                  emit('onEvent', { cmd: 'top', byNamed: win.named });
                };

                return h('div', [
                  h('Button', { onClick: btn }, `${props.title}`),
                  h('Button', { onClick: btnClose }, '调用窗口事件关闭'),
                  h('Button', { onClick: btnTop }, '调用窗口置定')
                ]);
                // return () => (
                //   <div>
                //     <span>Hello</span> jsx
                //   </div>
                // )
              }
            },
            /** 监听组件回调 */
            onEvent: (resp) => {
              console.log('win.render', resp);
            }
          };
          break;
        case 'html':
          _val = {
            body: '<h2>默认窗口尺寸</h2>',
            title: 'html窗口'
          };
          break;

        case 'size':
          _val = {
            title: '指定大小',
            body: '<h2>body</h2>',
            move: {
              width: 300,
              height: 300,
              left: framed_count * 10,
              top: framed_count * 10
            }
          };
          break;

        case 'pull':
          _val = {
            body: '<h2>body</h2>',
            title: '<b>html</b>全屏窗口',
            max: true,
            show: {
              /** 显示头部栏 */
              //  head: true,
              /** 显示工具栏按钮 */
              //  btn: true,
              /** max 按钮 */
              max: false
              /** 最小化按钮 */
              // min: false,
            },
            move: {
              width: 300,
              height: 200
            }
          };
          break;

        default:
          $plus.frame.open(
            `网页可见区域宽:document.body.clientWidth
网页可见区域高:document.body.clientHeight
网页可见区域宽:document.body.offsetWidth (包括边线的宽)
网页可见区域高:document.body.offsetHeight (包括边线的宽)
网页正文全文宽:document.body.scrollWidth
网页正文全文高:document.body.scrollHeight
网页被卷去的高:document.body.scrollTop
网页被卷去的左:document.body.scrollLeft
网页正文部分上:window.screenTop
网页正文部分左:window.screenLeft
屏幕分辨率的高:window.screen.height
屏幕分辨率的宽:window.screen.width
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidth`,
            'JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度',
            {
              onClose: (opts) => {
                console.log(JSON.stringify(opts));
                // $plus.message.info('点击关闭')
                // 返回当前对话框对象
                confirm({
                  title: '全局订阅事件对话框',
                  body: '<p>是否关闭当前窗口?</p>',
                  // 按钮事件
                  onEvent: (val) => {
                    console.log('JSON.stringify(opts)', val);
                    switch (val.cmd) {
                      case 'ok':
                        // 关闭当前窗口
                        opts.close && opts.close();
                        //对话框确认
                        setTimeout(function () {
                          // $plus.confirm({ show: false })
                          // 异步强制关闭指定窗口,不触发onClose 事件
                          //$plus.frame.close(resp.data.named, true)

                          // 关闭对话框
                          val.close && val.close();
                        }, 2000);

                        break;
                      case 'close':
                      case 'cancel':
                        // 对话框取消
                        // 关闭对话框
                        val.close && val.close();
                        break;
                    }

                    message.info('点击:' + val.cmd);

                    // console.log('ModalEvent', val)
                  }
                });
              }
            }
          );
          break;
      }

      /** 创建一个窗口 */
      const win = $plus.frame.open(_val);

      // 窗体创建完成
      if (win && win.finish) {
        // 返回当前窗口id,用于更新管理
        the.frameId = win.named;
        framed_count = win.data.count;
        console.log(the.frameId);
      }
    };

    /**
     * 弹窗事件
     */
    const btnFramed = (cmd) => {
      let resp;
      switch (cmd) {
        case 'close':
          if (the.frameId) {
            console.log(the.frameId);
            resp = $plus.frame.close(the.frameId);
            console.log('btnFramed:' + cmd, JSON.stringify(resp));
          }
          break;

        case 'clear':
          resp = $plus.frame.clear();
          console.log(JSON.stringify(resp));
          break;
      }
    };

    return { the, btnWin, btnFramed };
  }
};
</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

Frames win 全局弹窗

  • App.vue 全局引入
<template>
  <teleport to="#endOfBody">
    <!-- Frames 全局浮动窗口组件 -->
    <Frames :mobile="framed" :specs="frameSpecs" />
  </teleport>
</template>

<script>
import { onMounted, ref } from 'vue';
import { html } from 'quick.lib';

export default {
  name: 'App',
  setup() {
    //const {ref} = window.$plus.vue;
    //  console.log('quick.lib', version)

    // 浮窗初始化 是否小屏幕尺寸,全屏打开
    const frameMobile = ref(false);
    // 浮窗基础参数配置
    const frameSpecs = ref({});

    const onResize = () => {
      // 页面基础字体 缩放
      let size = html.fontRem();

      if (size.offsetWidth < 1024) {
        // 小屏幕尺寸,默认全屏显示
        frameMobile.value = true;
        frameSpecs.value = {
          width: document.body.clientWidth,
          height: document.body.clientHeight
        };
      }

      console.log('App.onResize:' + frameMobile.value, size);
    };

    onMounted(() => {
      // 执行基础字体缩放
      onResize();
      // 窗口发生变化时,响应式布局
      window.onresize = onResize;
    });

    return { frameMobile, frameSpecs };
  }
};
</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

弹窗事件监听 byNamed

import { frame } from 'qvui';

import { frame } from 'qvui';

const win = frame.open({
  model: {
    props: {
      title: '测试组件传参数'
    },
    // 函数组件
    component: (props, { emit }) => {
      /**
       * named 组件原生命名进行回调触发,
       * 由于是多窗口模式,需要表面来源的窗口命名
       * 需要加入 byNamed:当前窗口命名,才能接收
       *
       * */
      let _resp = { cmd: 'init', named: 'render', data: props.title };
      // 来源窗口组件命名
      _resp.byNamed = win.named;

      emit('onEvent', _resp);
    }
  },
  /** 监听组件回调 */
  onEvent: (resp) => {
    console.log('win.render', resp);
  },
  onClose: (opts) => {
    console.log(JSON.stringify(opts));
  }
});

frame.open({
  model: {
    props: {
      modelValue: { d: 1 }
    },
    /**
     TextPage 
     组件内部需要接收创建窗口的命名
    {
      props:{
        named
      },
      setup(props,{emit}){
        // byNamed 参数是传出当前窗口的命名
         emit('onEvent', {byNamed:props.named});
      }
    }
    */
    // 全局注册组件名
    component: 'TextPage'
    // 进行非全局组件需标记
    //  component: markRaw(TextPage),
  },
  /** 监听窗口回调 */
  onEvent: (resp) => {
    console.log('win.on', resp);
  },
  onClose: (opts) => {
    console.log(JSON.stringify(opts));
  }
});
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

浮窗参数 open

TIP

项目引入时定义,外挂弹窗方法

import { frame } from 'qvui';

// 项目外挂方式打开
//const {frame} = window.$plus.ui

frame.open('标题', '内容', { onClose: (e) => {} });
1
2
3
4
5
6
  • 传递参数
参数说明类型默认值
第一个浮窗标题String-
第二个浮窗内容String-
第三个浮窗参数,onClose(event)json-

浮窗方法

  • 传递对象
const win=frame.open({title:''...});

// 关闭指定的窗口(窗口命名)
frame.close(win.named);

//清除所有弹窗方法
frame.clear();

1
2
3
4
5
6
7
8

Frames 属性

参数说明类型默认值
named组件订阅命名,默认值,为空不订阅Stringframes
mobile手机端显示Booleanfalse
max以最大化显示窗口Booleanfalse
specs初始窗体配置参数Object-
dynamic 0.4.3是否动态响应 specs 参数配置Booleanfalse

specs

// 浮窗传入配置参数
let specs = {
  width: document.body.clientWidth,
  height: document.body.clientHeight,
  top: 0,
  left: 0,
  space: fontSize() // 默认间距 config字体大小
};

// 传入specs参数,frames会按比例适配默认参数
if (!_max) {
  //不是全屏就按比例缩小窗口
  specs.top = parseInt(specs.height * 0.05);
  specs.left = parseInt(specs.width * 0.1);
  specs.width = parseInt(specs.width * 0.75);
  specs.height = parseInt(specs.height * 0.7);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Frames 订阅事件

事件名说明
open创建新的浮窗
close关闭指定名浮窗
clear移除所有浮窗
confirm创建对话框

Frame.open 参数

参数说明类型默认值
title标题String-
body内容,htmlString-
model组件对象Object-
move自定义窗口位置 px:width:300,height,top,leftObject-
show自定义窗口组件显示Object-
css 0.4.2样式名Stringqv-drag-base
onEvent事件监听回调Funciton-
onClose自定义关闭事件拦截Funciton-

Frame.open.model

参数说明类型默认值
props模板参数Object-
component模板内容,可以传递组件或者方法Object,Funciton-

Frame.open.show

参数说明类型默认值
head显示头部栏Booltrue
btn显示工具栏按钮Booltrue
max显示工具栏最大化按钮Booltrue
min显示工具栏最小化按钮Booltrue
move是否允许拖动Booltrue
close 0.4.2显示关闭按钮Booltrue

Last Updated: