import {BaseService} from '../../commonService/base.service'; import {AppUtil} from '../../../util/app.util'; import {Injectable} from '@angular/core'; import {Constant} from '../../../config/constant/constant'; import {UrlConstant} from '../../../config/constant/url.constant'; import { Headers } from '@angular/http'; @Injectable() export class ${m1}Service extends BaseService { //查询列表 queryDataList(queryData) { return this.httpInterceptor .get(UrlConstant.${m3}_LIST + ('?' + AppUtil.stringToUrl(queryData)), { headers: new Headers({ 'type': 'QUERY', 'Content-Type': Constant.CONTENT_TYPE_GET }) }) .toPromise() .then(response => response.json()) .catch(this.handleError); } // 新增 addEntity(add${m1}) { return this.httpInterceptor .post(UrlConstant.${m3}_ADD, add${m1}, { headers: new Headers({ 'type': 'INSERT', 'Content-Type': Constant.CONTENT_TYPE_JSON }) }) .toPromise() .then(response => (console.log(response.json()), response.json())) .catch(this.handleError); } // 删除 deleteEntity(${m2}Id) { return this.httpInterceptor .delete(UrlConstant.${m3}_DELETE +'/'+ ${m2}Id) .toPromise() .then(response => (console.log(response.json()), response.json())) .catch(this.handleError); } // 修改 updateEntity(updateData: any): Promise { if(!updateData.${primaryKey}){ this.alertService.error('primaryKey 为空'); return; } const primaryKey :any = updateData.${primaryKey}; const paramsData = Object.assign({},updateData); return this.httpInterceptor .put(UrlConstant.${m3}_UPDATE+'/'+primaryKey, paramsData, { headers: new Headers({ 'type': 'UPDATE', 'Content-Type': Constant.CONTENT_TYPE_JSON }) }) .toPromise() .then(response => (console.log(response.json()),response.json())) .catch(this.handleError); } }