Files
blog-frontEnd/admin/src/app/utils/dataUtil.ts
2019-11-28 19:26:45 +08:00

43 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {Page} from '../classes/page';
import {Observable, of} from 'rxjs';
/**
* 判断 一个Page<any>[] 中是否存在一条已查询的数据
* @param pageNum 页码
* @param pageSize 单页数量
* @param pageList 源数据
* @return 未查到null 查到:该条数据
*/
export function exist<T>(pageNum: number, pageSize: number, pageList: Page<any>[]): Observable<Page<T>> {
if (pageList === undefined || pageList == null || pageList.length === 0) {
return null;
}
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < pageList.length; i++) {
// tslint:disable-next-line:triple-equals
if (pageList[i].pageNum == pageNum && pageList[i].pageSize == pageSize) {
return of<Page<T>>(pageList[i]);
}
}
return null;
}
/**
* 将reqBody对象 转化为拼接到url上面的字符串
* @param reqBody 请求体 from {a:xx,b:xxx}
* @return 字符串 to ==> a=xx&b=xxx
*/
export function reqBody2Str(reqBody: object): string {
let submitBody = '';
for (const key in reqBody) {
// 跳过值为null的参数请求
if (reqBody[key] == null || reqBody[key] === 'null') {
continue;
}
submitBody = submitBody + '&' + key + '=' + reqBody[key];
}
return submitBody.substring(1);
}