客户端控制命令列表

如果您尚不知道如何使用,请看下方的使用说明。

提示信息

  • 命令:notify

  • 参数:

    • 提示信息:填写提示内容文本即可

    • 提示类型:success/warning/error/info. 可不填, 不填写默认为成功提示

    • 提示元素:填写元素选择器, 如: #id. 可不填, 不填写意味着全局提示

  • 示例

    // 命令字符串格式
    [[notify:提示信息]]
    [[notify:提示信息|error]]
    [[notify:提示信息|warning|#id]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "notify",
          "params": ["提示信息"]
        },
        {
          "command": "notify",
          "params": ["提示信息", "error"]
        },
        {
          "command": "notify",
          "params": ["提示信息", "warning", "#id"]
        }
      ]
    }

刷新页面

  • 命令:reload

  • 参数:

  • 示例

    // 命令字符串格式
    [[reload]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "reload",
          "params": []
        }
      ]
    }

跳转页面

  • 命令:openUrl

  • 参数:

    • 需要打开的页面链接

  • 示例

    // 命令字符串格式
    [[openUrl:/index.html]] // 也可以时http开头的全路径
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "openUrl",
          "params": ["/index.html"]
        }
      ]
    }

显示tab标签

  • 命令:showTab

  • 参数:

    • # + 需要显示的tab id

  • 示例

    // 命令字符串格式
    [[showTab:#tab-id1]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "showTab",
          "params": ["#tab-id1"]
        }
      ]
    }

提示:可以多个参数,每个参数格式相同,这样会打开所有参数所指的tab标签页,如:[[showTab:#tab-id1|#tab-id2]]

替换元素内html

  • 命令:replaceHtml

  • 参数:

    • selector= + 选择器

    • html= + 用于替换的html字符串,注意:使用命令字符串格式时参数不能带 |

  • 示例

    // 命令字符串格式
    [[replaceHtml:selector=#id|html=<img src=""/>}]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "replaceHtml",
          "params": ["selector=#id", "html=<img src=""/>"]
        }
      ]
    }

替换元素自身

  • 命令:replaceDom

  • 参数:

    • selector= + 选择器

    • html= + 用于替换的html字符串,注意:使用命令字符串格式时参数不能带 |

  • 示例

    // 命令字符串格式
    [[replaceDom:selector=#id|html=<img src=""/>]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "replaceDom",
          "params": ["selector=#id", "html=<img src=""/>"]
        }
      ]
    }

增加类

  • 命令:addClass

  • 参数:

    • 选择器

    • 类名

  • 示例

    // 命令字符串格式
    [[addClass:#id|active]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "addClass",
          "params": ["#id", "active"]
        }
      ]
    }

删除类

  • 命令:removeClass

  • 参数:

    • 选择器

    • 类名

  • 示例

    // 命令字符串格式
    [[removeClass:#id|active]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "removeClass",
          "params": ["#id", "active"]
        }
      ]
    }

执行js代码

  • 命令:eval

  • 参数:

    • 需要执行的js字符串

  • 示例

    // 命令字符串格式
    [[eval:alert(1)]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "eval",
          "params": ["alert(1)"]
        }
      ]
    }

显示元素

  • 命令:show

  • 参数:

    • 需要显示元素的选择器

  • 示例

    // 命令字符串格式
    [[show:#modal-container-878819}]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "show",
          "params": ["#modal-container-878819"]
        }
      ]
    }

隐藏元素

  • 命令:hide

  • 参数:

    • 需要隐藏元素的选择器

  • 示例:"[[hide:#modal-container-878819]]"

    // 命令字符串格式
    [[hide:#modal-container-878819]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "hide",
          "params": ["#modal-container-878819"]
        }
      ]
    }

更新数据视图

  • 命令:updatelv

  • 参数:

    • 数据JSON字符串

    • 根路径 (可不写)

      • 跟路径是为了可以精确更新某个数组项(嵌套数组也行)

      • 写法为:数组名[判断语句或数组index].数组名[判断语句或数组index]...

      • 判读语句的写法. 语法同js, 需写为 obj.变量名 == "xxx" 注意, 需写为obj的属性

  • 示例

    // 命令字符串格式
    [[updatelv:{"a": 1}|a[1].b[obj.id==xxx].c[2]]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "updatelv",
          "params": [
            {
              "a": 1
            }
          ]
        },
        {
          "command": "updatelv",
          "params": [
            {
              "a": 1
            },
            "a[1].b[obj.id==xxx].c[2]"
          ]
        }
      ]
    }

示例页面:

<div class="lyrow ui-draggable"><a href="#close" class="remove label label-danger"><i class="glyphicon-remove glyphicon"></i>删除</a> <span class="drag label label-default ui-draggable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-warning" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false" data-type="layout"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview"><input class="form-control" value="12"></div><div class="view"><div class="row clearfix"><div class="col-md-12 column ui-sortable"><div class="box box-element ui-draggable" style=""><a href="#close" class="remove label label-danger"><i class="glyphicon glyphicon-remove"></i> 删除</a> <span class="drag label label-default ui-draggable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-default" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview">按钮</div><div class="view"><p><button class="btn btn-default" data-anijs="if: click,do: $bindingScript sc698209" data-script-sc698209="$.wwclass.runCommand([{command:&quot;updatelv&quot;,params:[{&quot;id&quot;:3, &quot;ctx&quot;: &quot;lalasdasdasdasdala&quot;},&quot;arr[0].arr1[0].arr2[obj.id=== 1]&quot;]}])" type="button">arr[0].arr1[0].arr2[obj.id===1]</button></p>

<p><button class="btn btn-default" data-anijs="if: click,do: $bindingScript sc698209" data-script-sc698209="$.wwclass.runCommand([{command:&quot;updatelv&quot;,params:[{ &quot;ctx&quot;: &quot;la0000000lala&quot;},&quot;arr[1].arr1[obj.id===\&quot;b\&quot;].arr2[1]&quot;]}])" type="button">arr[1].arr1[obj.id==="b"].arr2[1]</button></p>

<p><button class="btn btn-default" data-anijs="if: click,do: $bindingScript sc698209" data-script-sc698209="$.wwclass.runCommand([{command:&quot;updatelv&quot;,params:[{&quot;id&quot;:5, &quot;ctx&quot;: &quot;123123&quot;},&quot;arr[0].arr1[0].arr2[obj.ctx===\&quot;ctx\&quot;]&quot;]}])" type="button">arr[0].arr1[0].arr2[obj.ctx==="ctx"]</button></p>

<p><button class="btn btn-default" data-anijs="if: click,do: $bindingScript sc698209" data-script-sc698209="$.wwclass.runCommand([{command:&quot;updatelv&quot;,params:[[{&quot;id&quot;:0, &quot;ctx&quot;: &quot;ctx&quot;},{&quot;id&quot;:1, &quot;ctx&quot;: &quot;ctx&quot;}],&quot;arr[0].arr1[0].arr2&quot;]}])" type="button">arr[0].arr1[0].arr2</button></p>
</div></div></div></div></div></div><div class="lyrow ui-draggable" style=""><a href="#close" class="remove label label-danger"><i class="glyphicon-remove glyphicon"></i> 删除</a> <span class="drag label label-default ui-draggable-handle ui-sortable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-warning" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false" data-type="layout"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview"><input class="form-control" value="6 6"></div><div class="view"><div class="row clearfix"><div class="col-md-6 column ui-sortable"><div class="box box-element ui-draggable ui-sortable-handle" style="position: relative; opacity: 1; z-index: 0;"><a href="#close" class="remove label label-danger"><i class="glyphicon glyphicon-remove"></i> 删除</a> <span class="drag label label-default ui-draggable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-default" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview">有序列表</div><div class="view"><ul data-bind="foreach: arr">
	<li>
      <p data-bind="text: id">1</p>
	<ul data-bind="foreach: arr1">
		<li>
          <p data-bind="text: id">1</p>
		<ul data-bind="foreach: arr2">
			<li><p data-bind="text: id">1</p><input class="form-control" data-bind="textInput: ctx" type="text" value=""></li>
		</ul>
		</li>
	</ul>
	</li>
</ul>
</div></div></div><div class="col-md-6 column ui-sortable"><div class="box box-element ui-draggable ui-sortable-handle" style="position: relative; opacity: 1; z-index: 0;"><a href="#close" class="remove label label-danger"><i class="glyphicon glyphicon-remove"></i> 删除</a> <span class="drag label label-default ui-draggable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-default" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview">有序列表</div><div class="view"><ul data-bind="foreach: arr">
	<li>
      <p data-bind="text: id">第一天</p>
	<ul data-bind="foreach: arr1">
		<li>
          <p data-bind="text: id">第一天</p>
		<ul data-bind="foreach: arr2">
			<li><p data-bind="text: id">第一天</p><p data-bind="text: ctx">第一天</p></li>
		</ul>
		</li>
	</ul>
	</li>
</ul>
</div></div></div></div></div></div><div class="lyrow ui-draggable" style="" data-layer="数据"><a href="#close" class="remove label label-danger"><i class="glyphicon-remove glyphicon"></i>删除</a> <span class="drag label label-default ui-draggable-handle ui-sortable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-warning" type="button" data-target="#editorModal" data-toggle="modal" data-backdrop="false" data-keyboard="false" data-type="layout"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button><span class="layername">数据</span></span><div class="preview"><input class="form-control" value="12"></div><div class="view"><div class="row clearfix"><div class="col-md-12 column ui-sortable"><div class="box box-element ui-draggable ui-sortable-handle" style="position: relative; opacity: 1; z-index: 0;"><a href="#close" class="remove label label-danger"><i class="glyphicon glyphicon-remove"></i> 删除</a> <span class="drag label label-default ui-draggable-handle"><i class="glyphicon glyphicon-move"></i> 拖拽</span> <span class="configuration"><button class="label label-default" type="button" data-target="#editorModal" data-toggle="modal"><span><i class="glyphicon glyphicon-edit"></i></span>编辑</button></span><div class="preview"></div><div class="view"><p data-bindvars="{&quot;arr&quot;:[{&quot;id&quot;:0,&quot;arr1&quot;:[{&quot;id&quot;:&quot;a&quot;,&quot;arr2&quot;:[{&quot;id&quot;:0,&quot;ctx&quot;:&quot;ctx&quot;},{&quot;id&quot;:1,&quot;ctx&quot;:&quot;ctx&quot;}]},{&quot;id&quot;:&quot;b&quot;,&quot;arr2&quot;:[{&quot;id&quot;:0,&quot;ctx&quot;:&quot;ctx&quot;},{&quot;id&quot;:1,&quot;ctx&quot;:&quot;ctx&quot;}]}]},{&quot;id&quot;:1,&quot;arr1&quot;:[{&quot;id&quot;:&quot;a&quot;,&quot;arr2&quot;:[{&quot;id&quot;:0,&quot;ctx&quot;:&quot;ctx&quot;},{&quot;id&quot;:1,&quot;ctx&quot;:&quot;ctx&quot;}]},{&quot;id&quot;:&quot;b&quot;,&quot;arr2&quot;:[{&quot;id&quot;:0,&quot;ctx&quot;:&quot;ctx&quot;},{&quot;id&quot;:1,&quot;ctx&quot;:&quot;ctx&quot;}]}]}]}">wware允许领域专家快速开发部署基于WEB的复杂智能应用</p>
</div></div></div></div></div></div><script id="_wwblockConfig" data-config="%7B%22fluid%22:true,%22noscale%22:false,%22theme%22:%22shouce_paper%22,%22showwhen%22:%22always%22,%22redirect%22:%5B%7B%22rule%22:%22mobile%22,%22url%22:%22%22%7D%5D,%22title%22:%22%E8%8F%9C%E5%8D%95%E6%A0%8F%22%7D"></script>

root path 写法规则是

由于我们限定没有对象套对象格式,所以格式通常为:数组名称[数组项序号/判断字符串].内层数组[数组项序号/判断字符串].xxx

如果写判断表达式,需要将要判断的内容作为 obj的属性。比如要判断 属性 name 为 "abc"字符串,写为 obj.name=="abc"

示例:

{
  "arr": [
    { // 获取本数组项可以写为 arr[0] 或者 arr[obj.id==1]
      "id": 1
    },
    {
      "id": 2
    }
  ]
}
{
  "arr": [
    {
      "id": 1,
      "arr1": [
        {
          "id": 1
        },
        {
          "id": 2
        }
      ]
    },
    {
      "id": 2,
      "arr1": [
        { // arr[1/obj.id==2].arr1[0/obj.id==1], []括号内的/表示两种写法
          "id": 1
        },
        {
          "id": 2
        }
      ]
    }
  ]
}

数据绑定编程

  • 命令:bindingScript

  • 参数:

    • 数据绑定编程字符串

  • 示例

    // 命令字符串格式
    [[bindingScript:_vm.a(_vm.b() + _vm.c())]]
    
    // 命令对象格式
    {
      "success": true,
      "data": 1,
      "_runCommand": [
        {
          "command": "bindingScript",
          "params": [
            "_vm.a(_vm.b() + _vm.c())"
          ]
        }
      ]
    }

数据绑定数组操作

  • 命令:vmArrFuc

  • 参数:

    • 数组操作的方法

      • push:向数组的尾部添加n项

      • pop:除去数组最后n项

      • unshift:向数组首部添加n项

      • shift:除去数组第n项

      • reverse:反序

      • sort:排序

      • splice:删除数组的其中几项,从某项开始的几项

      • remove:删除数组的地几项

      • removeAll:清空数组

    • 数组名

    • 其他参数,根据数组操作方法的不同有区别

  • 示例

    • push:向数组的尾部添加n项

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "push",
              "arrName",
              {name:"value"},
              {name2:"value2"}
            ]
          }
        ]
      }
    • pop:除去数组最后n项

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "pop",
              "arrName",
              2 // 删除多少项
            ]
          }
        ]
      }
    • unshift:向数组首部添加n项

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "unshift",
              "arrName",
              {name:"value"},
              {name2:"value2"}
            ]
          }
        ]
      }
    • shift:除去数组第n项

      // 命令对象格式, 本功能建议使用对象格式使用
      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "shift",
              "arrName",
              2 // 删除多少项
            ]
          }
        ]
      }
    • reverse:反序

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "reverse",
              "arrName"
            ]
          }
        ]
      }
    • sort:排序

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "sort",
              "arrName",
              "(function () {  return function a (left, right) { return left.name == right.name ? 0 : (left.name < right.name ? -1 : 1) }}())" // 函数字符串
            ]
          }
        ]
      }
    • splice:删除数组的其中几项, 从某项开始的几项

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "splice",
              "arrName",
              1, // 从第1项开始删除
              2 // 删除2项
            ]
          }
        ]
      }
    • remove:删除数组的地几项

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "remove",
              "arrName",
              3 // 删除第3项
            ]
          }
        ]
      }
    • removeAll:清空数组

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "vmArrFuc",
            "params": [
              "removeAll",
              "arrName"
            ]
          }
        ]
      }

特殊命令

特殊命令有特殊的使用方式和使用场景,如何使用请查看具体说明

获取时区信息

  • 命令:getTimeZone

  • 参数:无参数

  • 使用

    • 在页面的 a 标签中使用

获取数据

  • 命令:getValue

  • 参数:

    • 选择器

  • 使用

    • 在逻辑发送请求功能中使用

    • 在页面的 a 标签中使用

特殊用法,当参数为"url"时,会获取当前页面链接。添加第二个参数可以确定是否转译 示例:

[[getValue:url]]
[[getValue:encodeUrl]]

注意:如果您的选择器选出的元素不止一个,仅会取得第一个元素的值


使用方式

如何才能运行命令,目前有三种使用方式 (ps:之后还会支持webSocket运行命令)

方式一

通过页面url运行,将命令以字符串格式放入url的hash部分,则页面显示后自动运行命令,如:http://www.test.com/test.html#[[showTab:#panel-274095]]

小提示:

  1. 使用url运行命令仅支持命令字符串格式

  2. 命令是可以多条运行的,您可以运行任意条命令

    • 如: http://www.test.com/test.html#[[showTab:#panel-274095]][[replaceHtml:selector=#li1|html=asdasdasd]]

  3. 执行时会自动从hash中查询出命令并执行,所以,命令字符串外的部分,一般字符都不会影响命令的正常支持,除非您加 [[ 这样的命令标识

    • 如: http://www.test.com/test.html#sadasd[[showTab:#panel-274095]],lll[[replaceHtml:selector=#li1|html=asdasdasd]]&kkk,仍可以正常执行

  4. 同一个命令可以多次执行,即使参数相同

    • 如: http://www.test.com/test.html#[[showTab:#panel-274095]][[showTab:#panel-111111]]

方式二

通过提交数据功能的返回值运行,在返回值中带 _runCommand 属性,页面会自动解析其中的内容并执行相应的操作,如:

{
  "success": true,
  "data": 1,
  "_runCommand": [
    {
      "command": "showTab",
      "params": [
        "#panel-274095"
      ]
    }
  ]
}

参数说明:command 的值为命令类型,params 的值为命令参数

小提示:

  1. _runCommand 的内容是数组,其中的每项都是一个命令

  2. params 的内容是命令参数,其中每项都是一个参数,参数是有顺序的,不允许调换参数的顺序,若没有参数可不写或写为空数组

  3. 无论返回 success 是 true 还是 false,都会执行命令

  4. _runCommand 可以执行多条命令

    • 如:

      {
        "success": true,
        "data": 1,
        "_runCommand": [
          {
            "command": "showTab",
            "params": [
              "#panel-274095"
            ]
          },
          {
            "command": "showTab",
            "params": [
              "#panel-111111"
            ]
          }
        ]
      }

方式三

打开chrome调试窗口,在console中运行js函数执行命令,这种方式仅用于测试您写得命令是否正确,该函数是:$.wwclass.helper.runCommand() 传入命令字符串或者命令对象都可,如:

// 传入命令字符串示例
$.wwclass.runCommand("[[showTab:#panel-274095]]");
// 传入命令对象示例
$.wwclass.runCommand([
  {
    "command": "showTab",
    "params": [
      "#panel-274095"
    ]
  },
  {
    "command": "showTab",
    "params": [
      "#panel-111111"
    ]
  }
]);