service.ts.vm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {BaseService} from '../../commonService/base.service';
  2. import {AppUtil} from '../../../util/app.util';
  3. import {Injectable} from '@angular/core';
  4. import {Constant} from '../../../config/constant/constant';
  5. import {UrlConstant} from '../../../config/constant/url.constant';
  6. import { Headers } from '@angular/http';
  7. @Injectable()
  8. export class ${m1}Service extends BaseService {
  9. //查询列表
  10. queryDataList(queryData) {
  11. return this.httpInterceptor
  12. .get(UrlConstant.${m3}_LIST + ('?' + AppUtil.stringToUrl(queryData)),
  13. { headers: new Headers({ 'type': 'QUERY', 'Content-Type': Constant.CONTENT_TYPE_GET }) })
  14. .toPromise()
  15. .then(response => response.json())
  16. .catch(this.handleError);
  17. }
  18. // 新增
  19. addEntity(add${m1}) {
  20. return this.httpInterceptor
  21. .post(UrlConstant.${m3}_ADD,
  22. add${m1},
  23. { headers: new Headers({ 'type': 'INSERT', 'Content-Type': Constant.CONTENT_TYPE_JSON }) })
  24. .toPromise()
  25. .then(response => (console.log(response.json()), response.json()))
  26. .catch(this.handleError);
  27. }
  28. // 删除
  29. deleteEntity(${m2}Id) {
  30. return this.httpInterceptor
  31. .delete(UrlConstant.${m3}_DELETE +'/'+ ${m2}Id)
  32. .toPromise()
  33. .then(response => (console.log(response.json()), response.json()))
  34. .catch(this.handleError);
  35. }
  36. // 修改
  37. updateEntity(updateData: any): Promise<any> {
  38. if(!updateData.${primaryKey}){
  39. this.alertService.error('primaryKey 为空');
  40. return;
  41. }
  42. const primaryKey :any = updateData.${primaryKey};
  43. const paramsData = Object.assign({},updateData);
  44. return this.httpInterceptor
  45. .put(UrlConstant.${m3}_UPDATE+'/'+primaryKey,
  46. paramsData,
  47. { headers: new Headers({ 'type': 'UPDATE', 'Content-Type': Constant.CONTENT_TYPE_JSON }) })
  48. .toPromise()
  49. .then(response => (console.log(response.json()),response.json()))
  50. .catch(this.handleError);
  51. }
  52. }