BUI

其它版本:

API for BUI 1.6.x

Show:

bui.history Class

Module: Core

Available since 1.5.6

[单页跟多页的公共历史记录,反映模块的加载关系, router.history 将废弃使用 ]

Methods

check

(
  • [页面id,或者url,或者模块id]
)

检测有没有当前页面历史记录

Parameters:

  • [页面id,或者url,或者模块id] String optional

Example:

       //  var hasLoadLogin = bui.history.check("pages/login/login.html");
                                            

checkComponent

(
  • [id] [组件的id]
)

检测component标签是否已经加载

Parameters:

  • [id] [组件的id] String optional

Example:

       //  var hasLoad = bui.history.checkComponent("tab1");
                                            

checkPage

(
  • [id] [组件的模块名,或者id]
)

Defined in src/scripts/core/bui.history.js:694

Available since 1.6.0 20200415

检测模块有没有以 page 方式加载

Parameters:

  • [id] [组件的模块名,或者id] String optional

Example:

       //  var hasLoad = bui.history.checkPage("pages/login/login");
                                            

destroy

(
  • [callback] [ 销毁后做什么]
)

插件的公共方法,销毁控件.

Parameters:

  • [callback] [ 销毁后做什么] Function optional

Example:

       插件内部使用: 
                                                   // 插件内部要销毁的东西, 比方 定时器,事件绑定, 外部是不知道的, 所以要内部处理
                                                   that.beforeDestroy = function(){
                                            
                                                   }
                                            
                                                   实例的销毁:
                                                   var accordion = bui.accordion();
                                                   // 调用这个方法前, 会先执行 beforeDestroy. 
                                                   accordion.destroy();
                                            

epmty

()

清空历史记录

Example:

       //  var hasLoadLogin = bui.history.epmty();
                                            

get

(
  • [value] [通过模块名获取某个历史记录,或者历史记录]
  • [key] [默认:"name", 也可以传页面id]
)
Array

获取所有历史记录

Parameters:

  • [value] [通过模块名获取某个历史记录,或者历史记录] String optional
  • [key] [默认:"name", 也可以传页面id] String optional

Returns:

Array:

option [返回数组]

Example:

方法:

       var allHistory = bui.history.get();
                                                   
                                                  方法2:
                                                   // 通过模块名获取某个历史记录
                                                   bui.history.get("pages/login/login")
                                            
                                                  方法3:
                                                   // 通过页面id获取某个历史记录
                                                   bui.history.get("buife172-aafb-0295-180b-6bc17fbd1cfb","id")
                                            

getComponent

(
  • id
  • [field] [默认: exports 字段, 可以不传]
)

获取编译后的组件实例

Parameters:

  • id String

    [获取编译后的组件实例,如果有return, 就能拿到该对象]

  • [field] [默认: exports 字段, 可以不传] String optional

Example:

方法1: 获取编译后的实例

       var distance = bui.history.getComponent("list");
                                            

getLast

(
  • [field] [返回最后一条记录的某个key值]
)
Object

获取最后的历史记录

Parameters:

  • [field] [返回最后一条记录的某个key值] String optional

Returns:

Object:

option [返回对象]

Example:

方法:

       var lastHistory = bui.history.getLast();
                                            
                                                   方法2: 1.6.x
                                                   var currentDistance = bui.history.getLast("exports");
                                            

getPage

(
  • id
  • [field] [默认: exports 字段, 可以不传]
)

获取插入页面的实例

Parameters:

  • id String

    [ id 或者模块名, 不传则是最后一次打开的实例 ]

  • [field] [默认: exports 字段, 可以不传] String optional

Example:

方法:

       var distance = bui.history.getPage("pages/list");
                                            

getPageDialog

(
  • id
)

在模块内部获取对话框的实例

Parameters:

  • id String

    [获取编译后的组件实例,如果有return, 就能拿到该对象]

Example:

方法1: 获取编译后的实例

       var distance = bui.history.getPageDialog(module.id);
                                                   distance.close();
                                            

getParams

(
  • [type] [ 参数的类型, 如果不传则获取多种方式,依次获取, component, page, url, 也可以指定某种类型 page(弹窗加载) | component(局部加载的参数) | url(路由跳转的参数)]
)

综合的获取参数方法, 如果模块会被多种方式加载, 则应该这个方法 bui.history.getParams

Parameters:

  • [type] [ 参数的类型, 如果不传则获取多种方式,依次获取, component, page, url, 也可以指定某种类型 page(弹窗加载) | component(局部加载的参数) | url(路由跳转的参数)] String optional

Example:

方法1: 如果不确定该模块会被哪种方式使用, 则可以使用这种方式获取. module.id 在loader.define(function(req,ext,module){ }) 的第三个参数

  var params = bui.history.getParams(module.id);
                                            

方法2: 获取单页路由或者多页路由的跳转传参 bui.load({url:"",param:{}})

  var params = bui.history.getParams("url");
                                            

方法3: 获取以bui.page({url:"",param:{}}) 加载的的参数, 通过以下方式获取

  var pageParams = bui.history.getParams("page");
                                            

方法4: 获取以router.loadPart, loader.load , component标签 加载的的参数, 通过以下方式获取

  var partParams = bui.history.getParams("component");
                                            

getParentComponent

()

Defined in src/scripts/core/bui.history.js:242

Available since 1.6.2

获取父组件实例, 在第一层component获取到的是页面组件

Example:

方法1: var distance = bui.history.getParentComponent();

getParentParams

()

Defined in src/scripts/core/bui.history.js:261

Available since 1.6.2

获取父组件实例, 在第一层component获取到的是页面组件

Example:

方法1: var distance = bui.history.getParentParams();

getPrev

(
  • [field] [返回最后一条记录的某个key值]
)
Object

Defined in src/scripts/core/bui.history.js:88

Available since 1.6.0

获取上一页历史记录

Parameters:

  • [field] [返回最后一条记录的某个key值] String optional

Returns:

Object:

option [返回对象]

Example:

方法:

       var lastHistory = bui.history.getPrev();
                                            
                                                   方法2: 1.6.x
                                                   var currentDistance = bui.history.getPrev("exports");
                                            

init

()

Defined in src/scripts/core/bui.extend.js:126

Available since 1.5.3

[控件的初始化]

Example:

       //初始化生命周期,默认已经初始化1次
                                                   var accordion = bui.accordion();
                                            
                                                   // 执行多一次初始化
                                                   accordion.init();
                                            

option

(
  • [key] [ 获取依赖的时候]
  • [value] [ 获取依赖的时候]
)

外部统一的修改获取参数, 修改this.config 的参数, 并且重新调用 init 方法.

Parameters:

  • [key] [ 获取依赖的时候] String | Object optional
  • [value] [ 获取依赖的时候] String optional

Example:

       比方初始化了插件: 
                                                   var accordion = bui.accordion();
                                            
                                                   // 实例获取参数
                                                   accordion.option("id");
                                            
                                                   // 修改一个参数
                                                   accordion.option("height",500);
                                            
                                                   // 修改多个参数
                                                   accordion.option({"height":500,handle:".bui-btn-test"});
                                            

prefix

(
  • [str] [ 去除前缀以后的值]
)
String

处理样式的前缀.

Parameters:

  • [str] [ 去除前缀以后的值] String optional

Returns:

String:

[ 出现问题的位置 ]

Example:

       var className = that.prefix("accordion");
                                            
                                                   // bui-accordion
                                            

refresh

()

刷新页面

Example:

       bui.history.refresh();
                                            

reinit

()

插件的公共方法,重新初始化.

Example:

       实例:
                                                   var accordion = bui.accordion();
                                                   // 重新初始化
                                                   accordion.reinit();
                                            

showLog

(
  • [str] [ 日志说明, try{}catche(e){ that.showLog(e) }]
  • [where] [ 出现问题的位置]
)

插件内部统一的抛出日志方法.

Parameters:

  • [str] [ 日志说明, try{}catche(e){ that.showLog(e) }] String | Object optional
  • [where] [ 出现问题的位置] String optional

Example:

       // 抛出异常, 在bui.accordion init 方法
                                                   that.showLog("初始化错误","bui.accordion init")
                                            
                                                   // 支持对象
                                                   try{}catche(e){ that.showLog(e) }
                                            

widget

(
  • [name] [ 获取依赖的时候]
)

实例的公共方法, 获取插件里面的实例,

Parameters:

  • [name] [ 获取依赖的时候] String optional

Example:

       插件内部使用 that.widgets.loading = bui.loading(); 初始化, 实例才能通过widget方法获取得到内部依赖.
                                            
                                                   比方初始化了插件: 
                                                   var accordion = bui.accordion();
                                            
                                                   // 实例获取依赖
                                                   accordion.widget("loading");
                                            

Events

off

为控件取消绑定事件

Event Payload:

  • [type] [ 事件类型: "show"(显示目标时) | "hide"(隐藏目标时)] String optional
  • [callback] [ 绑定的事件, this 为当前点击的菜单] Function optional

Example:

       that.off("show");
                                            

on

为控件绑定事件

Event Payload:

  • [type] [ 事件类型: "show"(显示目标时) | "hide"(隐藏目标时)] String optional
  • [callback] [ 绑定的事件, this 为当前点击的菜单] Function optional

Example:

       that.on("show",function () {
                                                       // 点击的菜单
                                                       console.log(this);
                                                   });
                                            

trigger

触发自定义事件

Event Payload:

  • [type] [ 自定义事件名称] String optional
  • [arguments] [ 需要传给自定义事件的参数,可以有多个] String | Object | Number optional

Example:

       $("#id").click(function (e) {
                                                   that.trigger("show",e);
                                                   })