Commit 995c905e authored by wangqinghua's avatar wangqinghua

update

parent 7c32670a
import {Injectable, OnInit} from "@angular/core"; import {Injectable, OnInit} from "@angular/core";
import {NzModalService} from 'ng-zorro-antd'; import {NzModalService} from 'ng-zorro-antd';
import {SERVER_API_URL, SERVER_API_URL_COMS} from '../../app.constants';
@Injectable() @Injectable()
export class CommonService implements OnInit { export class CommonService implements OnInit {
...@@ -80,4 +81,19 @@ export class CommonService implements OnInit { ...@@ -80,4 +81,19 @@ export class CommonService implements OnInit {
nzOnCancel: () => console.log('Cancel'), 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);
}
} }
...@@ -51,9 +51,9 @@ ...@@ -51,9 +51,9 @@
<button (click)="showUserModal()" nz-button nzType="primary">新增用户</button> <button (click)="showUserModal()" nz-button nzType="primary">新增用户</button>
<button (click)="batchDelete()" nz-button nzType="default">批量删除</button> <button (click)="batchDelete()" nz-button nzType="default">批量删除</button>
<button nz-button nzType="default">批量修改</button> <button nz-button nzType="default">批量修改</button>
<button nz-button nzType="default">下载模版</button> <button (click)="downLoad()" nz-button nzType="default">下载模版</button>
<button nz-button nzType="default">导入组织</button> <button (click)="showUploadModalOrg()" nz-button nzType="default">导入组织</button>
<button nz-button nzType="default">导入用户</button> <button (click)="showUploadModalUser()" nz-button nzType="default">导入用户</button>
</div> </div>
<nz-table #basicTable [nzData]="dataSet" [nzFrontPagination]="false" [nzTotal]="totalNum" [nzPageIndex]="pageNum" [nzPageSize]="pageSize" (nzPageIndexChange)="changePage($event)" <nz-table #basicTable [nzData]="dataSet" [nzFrontPagination]="false" [nzTotal]="totalNum" [nzPageIndex]="pageNum" [nzPageSize]="pageSize" (nzPageIndexChange)="changePage($event)"
> >
...@@ -91,4 +91,6 @@ ...@@ -91,4 +91,6 @@
<smart-group-modal #smartGroupModal (done)="getGroup()"></smart-group-modal> <smart-group-modal #smartGroupModal (done)="getGroup()"></smart-group-modal>
<!--授予角色--> <!--授予角色-->
<smart-select-role #smartSelectRole (done)="setRole($event)"></smart-select-role> <smart-select-role #smartSelectRole (done)="setRole($event)"></smart-select-role>
<!--导入文件-->
<smart-upload #smartUpload></smart-upload>
...@@ -5,7 +5,9 @@ import {UserComponent} from '../modal/user/user.component'; ...@@ -5,7 +5,9 @@ import {UserComponent} from '../modal/user/user.component';
import {GroupModalComponent} from '../modal/group-modal/group-modal.component'; import {GroupModalComponent} from '../modal/group-modal/group-modal.component';
import {SelectRoleComponent} from '../../modal/select-role/select-role.component'; import {SelectRoleComponent} from '../../modal/select-role/select-role.component';
import {CommonService} from '../../shared/common/common.service'; import {CommonService} from '../../shared/common/common.service';
import {pageSize} from '../../app.constants'; import {pageSize, SERVER_API_URL_COMS} from '../../app.constants';
import 'rxjs/Rx' ;
import {UploadComponent} from '../../work/modal/upload/upload.component';
@Component({ @Component({
selector: 'jhi-group', selector: 'jhi-group',
...@@ -17,6 +19,7 @@ export class GroupComponent implements OnInit { ...@@ -17,6 +19,7 @@ export class GroupComponent implements OnInit {
@ViewChild('power') power; @ViewChild('power') power;
@ViewChild('smartUser') smartUser: UserComponent; @ViewChild('smartUser') smartUser: UserComponent;
@ViewChild('smartGroupModal') smartGroupModal: GroupModalComponent; @ViewChild('smartGroupModal') smartGroupModal: GroupModalComponent;
@ViewChild("smartUpload") smartUpload:UploadComponent;
dataSet: any[]; dataSet: any[];
groupList: any[]; groupList: any[];
...@@ -270,9 +273,29 @@ export class GroupComponent implements OnInit { ...@@ -270,9 +273,29 @@ export class GroupComponent implements OnInit {
} }
} }
//选择角色
selectRoleModal() { selectRoleModal() {
this.setType = '批量'; this.setType = '批量';
this.smartSelectRole.showModal('选择角色', null); this.smartSelectRole.showModal('选择角色', null);
} }
//下载模版
downLoad(){
this.systemSer.downloadTemplate().subscribe(
data=>{
this.commonSer.downloadFile("模版",data)
}
);
}
//导入用户
showUploadModalUser(){
this.smartUpload.showModal("上传用户文件");
}
//导入组织
showUploadModalOrg(){
this.smartUpload.showModal("上传组织文件");
}
} }
...@@ -3,11 +3,14 @@ import {Observable} from "rxjs/Rx"; ...@@ -3,11 +3,14 @@ import {Observable} from "rxjs/Rx";
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {SERVER_API_URL_COMS} from "../app.constants"; import {SERVER_API_URL_COMS} from "../app.constants";
import {CommonService} from '../shared/common/common.service'; import {CommonService} from '../shared/common/common.service';
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';
import {RequestOptions} from '@angular/http';
@Injectable() @Injectable()
export class SystemService { export class SystemService {
constructor(private http: HttpClient,private commonSer:CommonService) { constructor(private http: HttpClient,private commonSer:CommonService,
private localStorage:LocalStorageService,private sessionStorage:SessionStorageService) {
} }
//角色列表 //角色列表
...@@ -207,4 +210,19 @@ export class SystemService { ...@@ -207,4 +210,19 @@ export class SystemService {
getMenuBySeparation(): Observable<any>{ getMenuBySeparation(): Observable<any>{
return this.http.get(SERVER_API_URL_COMS + '/resources/getMenuBySeparation' ); return this.http.get(SERVER_API_URL_COMS + '/resources/getMenuBySeparation' );
} }
//下载文件
downloadTemplate(): Observable<any>{
return this.http.get(SERVER_API_URL_COMS + '/user/downloadTemplate',{responseType: 'text'} );
}
//用户导入
importUser(data): Observable<any>{
return this.http.post(SERVER_API_URL_COMS + '/user/importUser',data);
}
//组织导入
importOrg(data): Observable<any>{
return this.http.post(SERVER_API_URL_COMS + '/organization/importOrg',data );
}
} }
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<button (click)="showUploadModal()" nz-button nzType="default"><i class="anticon anticon-upload"></i>导入资产</button> <button (click)="showUploadModal()" nz-button nzType="default"><i class="anticon anticon-upload"></i>导入资产</button>
</div> </div>
<div nz-col nzSpan="3" class="text-center"> <div nz-col nzSpan="3" class="text-center">
<button nz-button nzType="default"><i class="anticon anticon-download"></i>下载模版</button> <button (click)="downLoad()" nz-button nzType="default"><i class="anticon anticon-download"></i>下载模版</button>
</div> </div>
<div nz-col nzSpan="8"></div> <div nz-col nzSpan="8"></div>
<div nz-col nzSpan="6" class="text-right"> <div nz-col nzSpan="6" class="text-right">
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
</div> </div>
</div> </div>
<nz-table #nzTable [nzData]="childrenList"> <nz-table #nzTable [nzData]="childrenList" [nzShowPagination]="true">
<thead> <thead>
<tr> <tr>
<th>子分类</th> <th>子分类</th>
......
...@@ -99,6 +99,10 @@ export class AssetPartComponent implements OnInit { ...@@ -99,6 +99,10 @@ export class AssetPartComponent implements OnInit {
//删除父分类 //删除父分类
deleteParentType(){ deleteParentType(){
if(this.obj.type == "all"){
this.messge.warning("请选择需要删除的分类");
return false;
}
const data = { const data = {
inventoryTypeIds:[] inventoryTypeIds:[]
}; };
...@@ -144,6 +148,15 @@ export class AssetPartComponent implements OnInit { ...@@ -144,6 +148,15 @@ export class AssetPartComponent implements OnInit {
//导入资产 //导入资产
showUploadModal(){ showUploadModal(){
this.smartUpload.showModal(); this.smartUpload.showModal("上传资产文件");
}
//下载模版
downLoad(){
this.workSer.download("inventory").subscribe(
(data)=>{
this.commonSer.downloadFile("资产模版",data);
}
)
} }
} }
...@@ -80,7 +80,7 @@ export class ChildAssetsComponent implements OnInit { ...@@ -80,7 +80,7 @@ export class ChildAssetsComponent implements OnInit {
//导入资产 //导入资产
showUploadModal(){ showUploadModal(){
this.smartUpload.showModal(); this.smartUpload.showModal("上传资产文件");
} }
} }
<!--添加图片--> <!--添加图片-->
<nz-modal [(nzVisible)]="isVisible" nzTitle="上传文件" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()"> <nz-modal [(nzVisible)]="isVisible" [nzTitle]="title" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
<form nz-form> <form nz-form>
<nz-form-item> <nz-form-item>
<nz-form-label [nzSpan]="7" nzRequired nzFor="group">选择文件</nz-form-label> <nz-form-label [nzSpan]="7" nzRequired nzFor="group">选择文件</nz-form-label>
......
import { Component, OnInit } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {NzMessageService, UploadFile} from 'ng-zorro-antd'; import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {WorkService} from '../../work.service'; import {WorkService} from '../../work.service';
import {SystemService} from '../../../system/system.service';
@Component({ @Component({
selector: 'smart-upload', selector: 'smart-upload',
templateUrl: './upload.component.html', templateUrl: './upload.component.html',
styles: [] styles: []
}) })
export class UploadComponent implements OnInit { export class UploadComponent implements OnInit {
title;
isVisible = false; isVisible = false;
fileList: UploadFile[] = []; fileList: UploadFile[] = [];
constructor(private message:NzMessageService,private workSer:WorkService) { }
ngOnInit() { constructor(private message: NzMessageService, private workSer: WorkService,
} private systemSer: SystemService) {
}
ngOnInit() {
}
showModal(){ showModal(title) {
this.isVisible = true; this.title = title;
} this.isVisible = true;
}
beforeUpload = (file: UploadFile): boolean => { beforeUpload = (file: UploadFile): boolean => {
console.log(file.type);
const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
if (!isExcel) { if (!isExcel) {
this.message.error('请上传excel文件!'); this.message.error('请上传excel文件!');
}else{ } else {
this.fileList.push(file); this.fileList.push(file);
} }
return false; return false;
}; };
handleCancel(){ handleCancel() {
this.isVisible = false; this.isVisible = false;
this.fileList = []; this.fileList = [];
} }
handleOk(){ handleOk() {
if(this.fileList.length == 0){ if (this.fileList.length == 0) {
this.message.warning("请选择文件"); this.message.warning('请选择文件');
return false; return false;
} }
if (this.title == '上传资产文件') {
this.assetsUpload();
}
if (this.title == '上传用户文件') {
this.userUpload();
}
if (this.title == '上传组织文件') {
this.orgUpload();
}
}
//上传资产文件
assetsUpload() {
const formData = new FormData(); const formData = new FormData();
this.fileList.forEach((file:any)=>{ this.fileList.forEach((file: any) => {
formData.append('file',file); formData.append('file', file);
}) });
this.workSer.importInventory(formData).subscribe( this.workSer.importInventory(formData).subscribe(
(res)=>{ (res) => {
if(res.errCode == 10000){ if (res.errCode == 10000) {
this.isVisible = false;
this.fileList = [];
this.message.success('上传成功');
} else {
this.message.error(res.errMsg);
}
}
);
}
//导入用户
userUpload() {
const formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('user', file);
});
this.systemSer.importUser(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisible = false; this.isVisible = false;
this.fileList = []; this.fileList = [];
this.message.success("上传成功"); this.message.success('上传成功');
}else{ } else {
this.message.error(res.errMsg); this.message.error(res.errMsg);
} }
} }
) );
} }
//导入组织
orgUpload() {
const formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('organization', file);
});
this.systemSer.importOrg(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.fileList = [];
this.message.success('上传成功');
} else {
this.message.error(res.errMsg);
}
}
);
}
} }
...@@ -168,4 +168,9 @@ export class WorkService { ...@@ -168,4 +168,9 @@ export class WorkService {
deleteTypeByparams(data): Observable<any>{ deleteTypeByparams(data): Observable<any>{
return this.http.post(SERVER_API_URL + '/syseventType/delete' ,data); return this.http.post(SERVER_API_URL + '/syseventType/delete' ,data);
} }
//下载模版
download(params): Observable<any>{
return this.http.get(SERVER_API_URL + '/api/template/download/' +params,{responseType: 'text'});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment