Newer
Older
import {SERVER_API_URL, SERVER_API_URL_COMS} from '../../app.constants';
// 定义发射事件
}
ngOnInit() {
}
exists(list, parentId,myId){
for(let i=0; i<list.length; i++){
if(list[i][myId] == parentId){
return true;
}
}
return false;
}
/**
* list一层数组转为树形结构的数组
* @param myId 父级ID
* @param pId 子级ID
* @param list
* @returns {any[]}
*/
listToTree(myId,pId,list){
const nodes = [];
for(let i=0; i<list.length; i++){
list[i].checked = false;
const row = list[i];
if ( !this.exists(list, row[pId],myId) ){
nodes.push(row);
}
}
const toDo = [];
for(let i=0; i<nodes.length; i++){
toDo.push(nodes[i]);
}
while(toDo.length){
const node = toDo.shift(); // the parent node
for(let i=0; i<list.length; i++){
const row = list[i];
if (row[pId] == node[myId]){
if (node.children){
node.children.push(row);
} else {
node.children = [row];
}
toDo.push(row);
}
}
}
return nodes;
}
/**
* JSON格式数据转化为字符串 接口调用
* @param data json格式的数据
* @returns {string}
*/
if (data.hasOwnProperty(key)) {
const value = data[key];
str += key + '=' + value + '&';
}
}
str = str.substring(0, str.length - 1);
return str;
}
/**
* 删除确认函数
* @param title 提示语
* @param callback 回调函数
*/
confirmThing(title,content,callback){
nzTitle: title,
nzContent: '<b style="color: red;">'+content+'</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: callback,
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel'),
})
}
/**
* 下载文件
* @param url 文件URL
*/
downloadFile(title,data: Response) {
const blob = new Blob([data], {type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"});
const url= window.URL.createObjectURL(blob);
let link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", title);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
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
/**
* 部分区域全屏
* @param element 全屏区域
* @param method 全屏方法
* @returns {any}
*/
showInFullScreen(element, method){
let usablePrefixMethod;
['webkit', 'moz', 'ms', 'o', ''].forEach( (prefix)=> {
if (usablePrefixMethod) {
return
}
if (prefix === '') {
// 无前缀,方法首字母小写
// method = method.slice(0, 1).toLowerCase() + method.slice(1)
}
let typePrefixMethod = typeof element[prefix + method];
if (typePrefixMethod + '' !== 'undefined') {
if (typePrefixMethod === 'function') {
usablePrefixMethod = element[prefix + method]()
} else {
usablePrefixMethod = element[prefix + method]
}
}
}
)
return usablePrefixMethod;
}