ETool - 业务工具
提供设置业务根URL、CRUD方法、初始化表格、提示、字典、当前登录用户、权限验证、读写缓存、jsTree等公用方法
setBaseUrl(url)
设置业务 base url
| Param | Type | Description |
|---|---|---|
| url | string | 访问地址(必要) |
getBaseUrl() ⇒ string
获取业务 base url
importData(importCode)
打开导入页面
| Param | Type | Description |
|---|---|---|
| importCode | string | 系统管理>系统设置>导入模板中的模板代码(必要) |
exportData(element, url)
导出数据
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
| url | string | null | 请求地址 (默认:规则生成) |
saveData(element, url, needAlert, needValidate, callback)
保存数据,一般用于表单页面
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象 (必要) |
| url | string | null | 请求地址 (默认:规则生成) |
| needAlert | boolean | null | 是否需要弹出处理结果提示 (默认:true) |
| needValidate | boolean | null | 是否需要表单验证 (默认:true) |
| callback | function | null | 回调函数 |
saveAndClose(element, url, needAlert, needValidate)
保存并关闭,注: 方法不支持回调函数
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
| url | string | null | 请求地址 (默认:规则生成) |
| needAlert | boolean | null | 是否需要弹出处理结果提示 (默认:true) |
| needValidate | boolean | null | 是否需要表单验证 (默认:true) |
addData(element, name, url, pId)
打开新增页面,在列表页中使用,调用前请确保设置了baseUrl变量
| Param | Type | Description |
|---|---|---|
| element | element | element元素(必要) |
| name | string | null | tab页名称 (默认: 新增数据) |
| url | string | null | 请求地址,用于自定义保存url (默认:规则生成) |
| pId | string | null | 父Id,用于需要在url后拼接 /add/pId场景 |
deleteById(element, id, url, needAlert, callback)
根据数据id删除数据,一般用于表格最后操作列
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
| id | string | 要删除数据的id(必要) |
| url | string | null | 请求地址,用于自定义删除url (默认:规则生成) |
| needAlert | boolean | null | 是否需要弹出处理结果提示 (默认:true) |
| callback | function | null | 回调函数 |
deleteData(element, id, url, needAlert, callback)
删除数据,用于列表页删除数据,支持单个或批量操作
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
| id | string | null | 要删除的id,如果为空则从表格中获取勾选的数据(默认:获取表格中勾选的数据) |
| url | string | null | 请求地址,用于自定义删除url(默认:规则生成) |
| needAlert | boolean | null | 是否需要弹出处理结果提示(默认:true) |
| callback | function | null | 回调函数 |
editById(element, id, name, url, callback)
根据数据id修改数据,一般用于表格最后操作列
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
| id | string | 要修改数据的id(必要) |
| name | string | null | tab页名称(默认: 修改) |
| url | string | null | 请求地址,用于自定义修改url (默认:规则生成) |
| callback | function | null | 回调函数 |
selectData(element)
查询数据,一般用于列表页
| Param | Type | Description |
|---|---|---|
| element | element | html 元素对象(必要) |
initDataTable(options) ⇒ * | jQuery
初始化DataTable,文档请前往DataTable查看
| Param | Type | Description |
|---|---|---|
| options | object | 配置(必要) |
initDataTable~_defaultOptions
默认设置
Kind: inner property of initDataTable
queryParams($form) ⇒ null | object
将表单数据序列化为json对象
Returns: null | object - eg: {a: 1, b: 2}
| Param | Type | Description |
|---|---|---|
| $form | jQuery | 表单(必要) |
infoTip(title, subtitle)
info 提示,
会根据用户偏好设置中设置的提示方式进行提示
| Param | Type | Description |
|---|---|---|
| title | string | 标题(必要) |
| subtitle | string | 副标题 |
successTip(title, subtitle)
success 提示,
会根据用户偏好设置中设置的提示方式进行提示
| Param | Type | Description |
|---|---|---|
| title | string | 标题(必要) |
| subtitle | string | 副标题 |
warnTip(title, subtitle)
warning提示,
会根据用户偏好设置中设置的提示方式进行提示
| Param | Type | Description |
|---|---|---|
| title | string | 标题(必要) |
| subtitle | string | 副标题 |
errorTip(title, subtitle)
error提示,
会根据用户偏好设置中设置的提示方式进行提示
| Param | Type | Description |
|---|---|---|
| title | string | 标题(必要) |
| subtitle | string | 副标题 |
getSysDictArrayByDictType(dictType) ⇒ array | null
根据字典类型获取字典数组
Returns: array | null - 如没有返回null eg:[{...}, {...}]
| Param | Type | Description |
|---|---|---|
| dictType | string | 字典类型(必要) |
getSysDictsObjectByDictType(dictType) ⇒ object | null
根据字典类型获取字典对象
Returns: object | null - 如没有返回null eg:{1 : {...}, 2: {...}}
| Param | Type | Description |
|---|---|---|
| dictType | string | 字典类型(必要) |
getSysDictObjectByQuery(dictType, code) ⇒ object | null
根据字典类型与编码获取字典信息
Returns: object | null - 字典对象或null
| Param | Type | Description |
|---|---|---|
| dictType | string | 字典类型(必要) |
| code | string | 代码(必要) |
getSysDictNameByQuery(dictType, code) ⇒ string | null
根据字典类型与编码获取字典名称
Returns: string | null - 字典名称或null
| Param | Type | Description |
|---|---|---|
| dictType | string | 字典类型(必要) |
| code | string | 编码(必要) |
getDictElement(code, dict) ⇒ string
将字典转为html元素(徽章)
Returns: string - eg: <span class="xxx">xxx</span>
| Param | Type | Description |
|---|---|---|
| code | string | 字典编码(必要) |
| dict | object | 字典对象(必要) |
getUser(cache) ⇒ Object
获取当前登录用户,默认优先从缓存获取,如不希望从缓存中获取可设置cache: false
Returns: Object - 当前登录用户信息
| Param | Type | Description |
|---|---|---|
| cache | boolean | null | 是否使用缓存数据 (默认:true) |
- getUser(cache) ⇒
Object- ~_getUser() ⇒
*- ~arrayToObject(data) ⇒
object
- ~arrayToObject(data) ⇒
- ~_getUser() ⇒
getUser~_getUser() ⇒ *
从后端获取当前登录用户
Kind: inner method of getUser
_getUser~arrayToObject(data) ⇒ object
将attr:attr数组转为对象
Kind: inner method of _getUser
| Param |
|---|
| data |
hasPermissions(code) ⇒ boolean
当前登录用户是否拥有指定权限标识
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| code | string | 权限标识(必要) |
notHasPermissions(code) ⇒ boolean
当前登录用户是否没有指定权限标识
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| code | string | 权限标识(必要) |
hasRole(code) ⇒ boolean
当前登录用户是否属于指定角色标识
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| code | string | 角色标识(必要) |
notHasRole(code) ⇒ boolean
当前登录用户是否不属于指定角色标识
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| code | string | 角色标识(必要) |
checkPermissions(code, permissions) ⇒ boolean
检查权限
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| code | string | 权限标识(必要) |
| permissions | object | 权限对象(必要) |
getCache(key) ⇒ object
获取cookies/localStorage中的对象
Returns: object - value
| Param | Type | Description |
|---|---|---|
| key | string | key(必要) |
setCache(key, value)
设置cookies/localStorage中的对象
| Param | Type | Description |
|---|---|---|
| key | string | key(必要) |
| value | object | value(必要) |
cacheRemove(key)
移除指定cookies/localStorage中的对象
| Param | Type | Description |
|---|---|---|
| key | string | key(必要) |
getObject(path, object, separate) ⇒ object | null
根据属性路径获取object中的value
Returns: object | null - 如果未找到返回null
| Param | Type | Description |
|---|---|---|
| path | string | 属性路径 eg:user.depart.name(必要) |
| object | object | 对象(必要) |
| separate | string | null | 分隔符(默认:.) |
getActionsBtnClass(type) ⇒ string
获取操作按钮class
| Param | Type | Description |
|---|---|---|
| type | string | 按钮类型(必要) |
downloadFile(url)
下载文件
| Param | Type | Description |
|---|---|---|
| url | string | 下载地址(必要) |
analysisCode(code) ⇒ Object | string
解析响应码,响应码规则请参考响应码
| Param | Type | Description |
|---|---|---|
| code | string | 响应码(必要) |
saveNode(tree, node)
保存/修改jsTree的节点信息
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
| node | object | 节点信息(必要) |
deleteNode(tree, ids)
删除jsTree的节点
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
| ids | number | string | 要删除的id(必要) |
_deleteNode(tree, ids)
删除jsTree的指定节点
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
| ids | array | 要删除的节点id(必要) |
getOperationNodes(data)
右键点击时获取用户想操作的jsTree节点
1.右键点击的节点属于多选节点, 返回所有已选中节点
2.右键点击的节点不属于多选的节点, 返回右键点击节点并选中
| Param | Type | Description |
|---|---|---|
| data | object | (必要) |
getClickNode(data) ⇒ * | Object | jQuery | void
获取右键点击的jsTree节点
| Param | Type | Description |
|---|---|---|
| data | object | (必要) |
getCheckedNodes(tree, attr) ⇒ array
获取jsTree选中节点 注: id='#' 节点会被过滤
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
| attr | 要获取的属性(默认:返回节点全部信息) |
checkNodes(tree, values)
jsTree 设置节点选中
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
| values | array | string | 选中的值,数组或字符串(1,2,3)(必要) |
checkAll(tree)
jsTree 全选
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
unCheckAll(tree)
jsTree 全不选
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
getTree(tree) ⇒ object
获取jsTree对象
| Param | Type | Description |
|---|---|---|
| tree | object | string | 选择器或者jsTree对象(必要) |
getSelectData($dataTable) ⇒ Array
获取勾选的数据
Returns: Array - eg:[1,2,3]
| Param | Type | Description |
|---|---|---|
| $dataTable | object | dataTable 对象(必要) |
checkSelectDataIsNotEmpty(ids, tip) ⇒ boolean
检查ids是否为空
Returns: boolean - true/false
| Param | Type | Description |
|---|---|---|
| ids | array | ids(必要) |
| tip | boolean | 是否需要弹出提示commonTips.noIds;(默认false) |