Commit 995c905e authored by wangqinghua's avatar wangqinghua

update

parent 7c32670a
import {Injectable, OnInit} from "@angular/core";
import {NzModalService} from 'ng-zorro-antd';
import {SERVER_API_URL, SERVER_API_URL_COMS} from '../../app.constants';
@Injectable()
export class CommonService implements OnInit {
......@@ -80,4 +81,19 @@ export class CommonService implements OnInit {
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 @@
<button (click)="showUserModal()" nz-button nzType="primary">新增用户</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 nz-button nzType="default">导入用户</button>
<button (click)="downLoad()" nz-button nzType="default">下载模版</button>
<button (click)="showUploadModalOrg()" nz-button nzType="default">导入组织</button>
<button (click)="showUploadModalUser()" nz-button nzType="default">导入用户</button>
</div>
<nz-table #basicTable [nzData]="dataSet" [nzFrontPagination]="false" [nzTotal]="totalNum" [nzPageIndex]="pageNum" [nzPageSize]="pageSize" (nzPageIndexChange)="changePage($event)"
>
......@@ -91,4 +91,6 @@
<smart-group-modal #smartGroupModal (done)="getGroup()"></smart-group-modal>
<!--授予角色-->
<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';
import {GroupModalComponent} from '../modal/group-modal/group-modal.component';
import {SelectRoleComponent} from '../../modal/select-role/select-role.component';
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({
selector: 'jhi-group',
......@@ -17,6 +19,7 @@ export class GroupComponent implements OnInit {
@ViewChild('power') power;
@ViewChild('smartUser') smartUser: UserComponent;
@ViewChild('smartGroupModal') smartGroupModal: GroupModalComponent;
@ViewChild("smartUpload") smartUpload:UploadComponent;
dataSet: any[];
groupList: any[];
......@@ -270,9 +273,29 @@ export class GroupComponent implements OnInit {
}
}
//选择角色
selectRoleModal() {
this.setType = '批量';
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";
import { Injectable } from '@angular/core';
import {SERVER_API_URL_COMS} from "../app.constants";
import {CommonService} from '../shared/common/common.service';
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';
import {RequestOptions} from '@angular/http';
@Injectable()
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 {
getMenuBySeparation(): Observable<any>{
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 @@
<button (click)="showUploadModal()" nz-button nzType="default"><i class="anticon anticon-upload"></i>导入资产</button>
</div>
<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 nz-col nzSpan="8"></div>
<div nz-col nzSpan="6" class="text-right">
......@@ -41,7 +41,7 @@
</div>
</div>
<nz-table #nzTable [nzData]="childrenList">
<nz-table #nzTable [nzData]="childrenList" [nzShowPagination]="true">
<thead>
<tr>
<th>子分类</th>
......
......@@ -99,6 +99,10 @@ export class AssetPartComponent implements OnInit {
//删除父分类
deleteParentType(){
if(this.obj.type == "all"){
this.messge.warning("请选择需要删除的分类");
return false;
}
const data = {
inventoryTypeIds:[]
};
......@@ -144,6 +148,15 @@ export class AssetPartComponent implements OnInit {
//导入资产
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 {
//导入资产
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>
<nz-form-item>
<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 {WorkService} from '../../work.service';
import {SystemService} from '../../../system/system.service';
@Component({
selector: 'smart-upload',
......@@ -9,53 +10,107 @@ import {WorkService} from '../../work.service';
})
export class UploadComponent implements OnInit {
title;
isVisible = false;
fileList: UploadFile[] = [];
constructor(private message:NzMessageService,private workSer:WorkService) { }
constructor(private message: NzMessageService, private workSer: WorkService,
private systemSer: SystemService) {
}
ngOnInit() {
}
showModal(){
showModal(title) {
this.title = title;
this.isVisible = true;
}
beforeUpload = (file: UploadFile): boolean => {
console.log(file.type);
const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
if (!isExcel) {
this.message.error('请上传excel文件!');
}else{
} else {
this.fileList.push(file);
}
return false;
};
handleCancel(){
handleCancel() {
this.isVisible = false;
this.fileList = [];
}
handleOk(){
if(this.fileList.length == 0){
this.message.warning("请选择文件");
handleOk() {
if (this.fileList.length == 0) {
this.message.warning('请选择文件');
return false;
}
if (this.title == '上传资产文件') {
this.assetsUpload();
}
if (this.title == '上传用户文件') {
this.userUpload();
}
if (this.title == '上传组织文件') {
this.orgUpload();
}
}
//上传资产文件
assetsUpload() {
const formData = new FormData();
this.fileList.forEach((file:any)=>{
formData.append('file',file);
})
this.fileList.forEach((file: any) => {
formData.append('file', file);
});
this.workSer.importInventory(formData).subscribe(
(res)=>{
if(res.errCode == 10000){
(res) => {
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.fileList = [];
this.message.success("上传成功");
}else{
this.message.success('上传成功');
} else {
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 {
deleteTypeByparams(data): Observable<any>{
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