嗨森逛PC管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
high-web/src/app/services/commons.service.ts

359 lines
9.3 KiB

4 years ago
import {Injectable} from '@angular/core';
import {LocalStorageService} from './local-storage.service';
import {DATA} from './local-storage.namespace';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {environment} from '../../environments/environment';
import {HttpClient} from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class CommonsService {
constructor(
private storage: LocalStorageService,
private modalService: NzModalService, // 对话框
private http: HttpClient,
private notification: NzNotificationService
) { }
/**
* GET请求参数 key1=value1&key2=value2
* @param object
*/
getWhereCondition(object: object): string {
let str = '';
for (const i in object) {
if (object[i] != null && object[i] !== '') {
if (str === '') {
str = i + '=' + object[i];
} else {
str += '&' + i + '=' + object[i];
}
}
}
return str;
}
/**
*
* @param btnCode
*/
public isBtnCompetence(btnCode: string): boolean {
let buttonList = [];
buttonList = this.storage.get(DATA).buttonList;
if (buttonList != null && buttonList.length > 0) {
if (buttonList.find(b => b.permissionCode === btnCode) != null) {
return true;
}
}
return false;
}
/**
*
* @param message
* @param callback
*/
public showConfirm(message , callback) {
this.modalService.confirm({
nzTitle: message,
nzOkText: '是',
nzOkType: 'danger',
nzOnOk: () => callback(true),
nzCancelText: '否',
});
}
/**
* estateId
*
* @param estateId id
* @param callBack
*/
public getMallCategoryTree(estateId: number , callBack) {
this.http.get(environment.baseUrl + 'categoryEstates/getMallCategoryTree?estateId=' + estateId).subscribe(data => {
callBack(data);
});
}
/**
*
* @param callBack
*/
public getParentInfosByRegionId(regionId: number, callBack) {
this.http.get(environment.baseUrl + 'common/getParentInfosByRegionId?regionId=' + regionId).subscribe(data => {
callBack(data);
});
}
/**
*
* @param callBack
*/
public getAllRegion(callBack) {
this.http.get(environment.baseUrl + 'common/getAllProvinceAndCity').subscribe(data => {
callBack(data);
});
}
/**
*
* @param callBack
*/
public getAllProvinceAndCityRegion(callBack) {
this.http.get(environment.baseUrl + 'common/getAllProvinceAndCityRegion').subscribe(data => {
callBack(data);
});
}
/**
*
* @param callBack
*/
public getAllIndustry(callBack) {
this.http.get(environment.baseUrl + 'secCompanyIndustry/findIndustryTree').subscribe(data => {
callBack(data);
});
}
/**
*
*
* @param object
*/
public getUniqueObject<T>(object: any): any {
const map = {};
// 1、把数组元素作为对象的键存起来(这样就算有重复的元素,也会相互替换掉)
object.forEach(item => map[JSON.stringify(item)] = item);
// 2、再把对象的值抽成一个数组返回即为不重复的集合
return Object.keys(map).map(key => map[key]) as T[];
}
/**
* String
*
* @param name String
*/
public getStringIsNull<T>(name: string): boolean {
if (name == null) {
return true;
}
if (name === '') {
return true;
}
}
/**
*
*
* @param phone String
*/
public verifyPhone<T>(phone: string): boolean {
return phone.length === 11;
}
/**
*
*
* @param codeType
* @param callback
*/
public getDictionary(codeType: string , callback): any {
this.http.get(environment.baseUrl + '/common/getDictionaryByCodeType?codeType=' + codeType).subscribe( data => {
callback(data);
});
}
4 years ago
public mappingSysNameOl(codeType: string , callback): any {
4 years ago
this.http.get(environment.baseUrl + '/common/getDictionaryByCodeTypeOl?codeType=' + codeType).subscribe( data => {
4 years ago
callback(data);
});
}
4 years ago
public updateDictionary(codeType: string , codeValue: string , callback): any {
this.http.get(environment.baseUrl + '/common/updateDictionary?codeType=' + codeType + '&codeValue=' + codeValue).subscribe( data => {
callback(data);
});
}
4 years ago
4 years ago
/**
*
*
*
* @param callback
*/
getAllJobType(callback) {
this.http.get('assets/json/jobType.json').subscribe( data => {
callback(data);
});
}
/**
*
* timestamp: 时间戳
* formatformatArr里保持一致
*/
public formatTime(timestamp: number, format: string) {
const formatArr = ['yyyy', 'MM', 'dd', 'HH', 'mm', 'ss'];
const returnArr = [];
const date = new Date(timestamp);
returnArr.push(date.getFullYear());
returnArr.push(this.formatNumber(date.getMonth() + 1));
returnArr.push(this.formatNumber(date.getDate()));
returnArr.push(this.formatNumber(date.getHours()));
returnArr.push(this.formatNumber(date.getMinutes()));
returnArr.push(this.formatNumber(date.getSeconds()));
// tslint:disable-next-line:forin
for (const i in returnArr) {
format = format.replace(formatArr[i], returnArr[i]);
}
return format;
}
// 数据转化
formatNumber(n) {
n = n.toString();
return n[1] ? n : '0' + n;
}
/**
* Notification通知提醒框
*
* @param type
* @param title
* @param content
*/
public createNotification(type: string , title: string , content: string): void {
this.notification.create(
type,
title,
content
);
}
/**
* key查询value
*
* @param value string
* @param object object
* @param callback
*/
public positionKeyValue<T>(value: string , object: Array<any> , callback): void {
// tslint:disable-next-line:forin
for (const i in object) {
if (object[i].value === value) {
callback(object[i].label);
} else {
this.positionKeyValue(value , object[i].children , callback);
}
}
}
/**
*
*
* @param codeType
* @param codeValue value
* @param callback
*/
public getDictionaryByCodeTypeAndValue(codeType: string , codeValue: string , callback): any {
this.http.get(environment.baseUrl + '/common/getDictionaryByCodeTypeAndValue?codeType=' + codeType + '&codeValue=' + codeValue).subscribe( data => {
callback(data);
});
}
/**
*
*
* @param codeType
* @param codeValue value
* @param callback
*/
public getDictionaryByCodeTypeAndValuePromise(codeType: string , codeValue: string): any {
return new Promise(resolve => {
this.http.get(environment.baseUrl + '/common/getDictionaryByCodeTypeAndValue?codeType=' + codeType + '&codeValue=' + codeValue).subscribe(data => {
resolve(data['return_data']['codeName']);
});
});
}
/**
*
* @param param
* @param callback
*/
public getHomeCompanyList(param: object, callback): any {
this.http.get(environment.baseUrl + 'common/getHomeCompanyList?' + this.getWhereCondition(param)).subscribe( data => {
callback(data);
});
}
/**
*
*
* @param params
* @param callBack
* @return data
*/
public editGasDiscountOilPrice(params: object, callBack) {
this.http.post(environment.baseUrl + 'highGasDiscountOilPrice/editGasDiscountOilPrice', params).subscribe(data => {
callBack(data);
});
}
/**
*
*
* @param paramsObject
* @param callBack
*/
public getList(paramsObject: object, callBack) {
this.http.get(environment.baseUrl + 'highGasDiscountOilPrice/getList?' + this.getWhereCondition(paramsObject)).subscribe(data => {
callBack(data);
});
}
/**
* estateId
*
* @param id id
* @param callBack
*/
public getDetailById(id: number , callBack) {
this.http.get(environment.baseUrl + 'highGasDiscountOilPrice/getDetailById?id=' + id).subscribe(data => {
callBack(data);
});
}
/**
* estateId
*
* @param id id
* @param callBack
*/
public delete(id: number , callBack) {
this.http.post(environment.baseUrl + 'highGasDiscountOilPrice/delete' , { id: id}).subscribe(data => {
callBack(data);
});
}
/**
*
* @param param
* @param callback
*/
public getOrganizationList(param: object, callback): any {
this.http.get(environment.baseUrl + 'bsOrganization/getOrganizationList?' + this.getWhereCondition(param)).subscribe( data => {
callback(data);
});
}
4 years ago
}