ETool - 业务工具
提供设置业务根URL、CRUD方法、初始化表格、提示、字典、当前登录用户、权限验证、读写缓存、jsTree等公用方法
setBaseUrl(url)
设置业务 base url
Param | Type | Description |
---|---|---|
url | string | 访问地址(必要) |
string
getBaseUrl() ⇒ 获取业务 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 元素对象(必要) |
*
| jQuery
initDataTable(options) ⇒ 初始化DataTable,文档请前往DataTable查看
Param | Type | Description |
---|---|---|
options | object | 配置(必要) |
initDataTable~_defaultOptions
默认设置
Kind: inner property of initDataTable
null
| object
queryParams($form) ⇒ 将表单数据序列化为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 | 副标题 |
array
| null
getSysDictArrayByDictType(dictType) ⇒ 根据字典类型获取字典数组
Returns: array
| null
- 如没有返回null
eg:[{...}, {...}]
Param | Type | Description |
---|---|---|
dictType | string | 字典类型(必要) |
object
| null
getSysDictsObjectByDictType(dictType) ⇒ 根据字典类型获取字典对象
Returns: object
| null
- 如没有返回null
eg:{1 : {...}, 2: {...}}
Param | Type | Description |
---|---|---|
dictType | string | 字典类型(必要) |
object
| null
getSysDictObjectByQuery(dictType, code) ⇒ 根据字典类型与编码获取字典信息
Returns: object
| null
- 字典对象或null
Param | Type | Description |
---|---|---|
dictType | string | 字典类型(必要) |
code | string | 代码(必要) |
string
| null
getSysDictNameByQuery(dictType, code) ⇒ 根据字典类型与编码获取字典名称
Returns: string
| null
- 字典名称或null
Param | Type | Description |
---|---|---|
dictType | string | 字典类型(必要) |
code | string | 编码(必要) |
string
getDictElement(code, dict) ⇒ 将字典转为html元素(徽章)
Returns: string
- eg: <span class="xxx">xxx</span>
Param | Type | Description |
---|---|---|
code | string | 字典编码(必要) |
dict | object | 字典对象(必要) |
Object
getUser(cache) ⇒ 获取当前登录用户,默认优先从缓存获取,如不希望从缓存中获取可设置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
object
_getUser~arrayToObject(data) ⇒ 将attr:attr数组转为对象
Kind: inner method of _getUser
Param |
---|
data |
boolean
hasPermissions(code) ⇒ 当前登录用户是否拥有指定权限标识
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
code | string | 权限标识(必要) |
boolean
notHasPermissions(code) ⇒ 当前登录用户是否没有指定权限标识
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
code | string | 权限标识(必要) |
boolean
hasRole(code) ⇒ 当前登录用户是否属于指定角色标识
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
code | string | 角色标识(必要) |
boolean
notHasRole(code) ⇒ 当前登录用户是否不属于指定角色标识
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
code | string | 角色标识(必要) |
boolean
checkPermissions(code, permissions) ⇒ 检查权限
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
code | string | 权限标识(必要) |
permissions | object | 权限对象(必要) |
object
getCache(key) ⇒ 获取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(必要) |
object
| null
getObject(path, object, separate) ⇒ 根据属性路径获取object中的value
Returns: object
| null
- 如果未找到返回null
Param | Type | Description |
---|---|---|
path | string | 属性路径 eg:user.depart.name (必要) |
object | object | 对象(必要) |
separate | string | null | 分隔符(默认:.) |
string
getActionsBtnClass(type) ⇒ 获取操作按钮class
Param | Type | Description |
---|---|---|
type | string | 按钮类型(必要) |
downloadFile(url)
下载文件
Param | Type | Description |
---|---|---|
url | string | 下载地址(必要) |
Object
| string
analysisCode(code) ⇒ 解析响应码,响应码规则请参考响应码
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 | (必要) |
*
| Object
| jQuery
| void
getClickNode(data) ⇒ 获取右键点击的jsTree节点
Param | Type | Description |
---|---|---|
data | object | (必要) |
array
getCheckedNodes(tree, attr) ⇒ 获取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对象(必要) |
object
getTree(tree) ⇒ 获取jsTree对象
Param | Type | Description |
---|---|---|
tree | object | string | 选择器或者jsTree对象(必要) |
Array
getSelectData($dataTable) ⇒ 获取勾选的数据
Returns: Array
- eg:[1,2,3]
Param | Type | Description |
---|---|---|
$dataTable | object | dataTable 对象(必要) |
boolean
checkSelectDataIsNotEmpty(ids, tip) ⇒ 检查ids是否为空
Returns: boolean
- true/false
Param | Type | Description |
---|---|---|
ids | array | ids(必要) |
tip | boolean | 是否需要弹出提示commonTips.noIds ;(默认false ) |