|
|
@ -1,20 +1,24 @@ |
|
|
|
import { Component, OnInit, Inject } from '@angular/core'; |
|
|
|
import { Component, OnInit, Inject } from '@angular/core'; |
|
|
|
import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; |
|
|
|
import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; |
|
|
|
import { FlatTreeControl } from '@angular/cdk/tree'; |
|
|
|
import { FlatTreeControl } from '@angular/cdk/tree'; |
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
import { HttpClient,HttpHeaders, HttpEventType } from '@angular/common/http'; |
|
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; |
|
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; |
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
|
|
|
import format from 'date-fns/format'; |
|
|
|
import format from 'date-fns/format'; |
|
|
|
import { TreeService } from '../../http-interceptors/tree.service' |
|
|
|
import { TreeService } from '../../http-interceptors/tree.service' |
|
|
|
import { FileUploader } from 'ng2-file-upload' |
|
|
|
import { FileUploader, FileItem } from 'ng2-file-upload' |
|
|
|
import { House } from '../../interface' |
|
|
|
import { House } from '../../interface' |
|
|
|
import { AddHouseInfo } from './addhouseinfo.component' |
|
|
|
import { AddHouseInfo } from './addhouseinfo.component' |
|
|
|
import { DomSanitizer } from '@angular/platform-browser' |
|
|
|
import { DomSanitizer } from '@angular/platform-browser' |
|
|
|
interface newHouse extends House{ |
|
|
|
import { Injectable } from "@angular/core" |
|
|
|
gaoceng?:boolean |
|
|
|
import { filter } from 'rxjs/operators'; |
|
|
|
huo?:boolean |
|
|
|
import { async } from '@angular/core/testing'; |
|
|
|
lei?:boolean |
|
|
|
export interface UploadResult { |
|
|
|
|
|
|
|
name: string; |
|
|
|
|
|
|
|
type: string; |
|
|
|
|
|
|
|
size: number; |
|
|
|
|
|
|
|
url: string; |
|
|
|
} |
|
|
|
} |
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'app-basicinfo', |
|
|
|
selector: 'app-basicinfo', |
|
|
@ -22,11 +26,18 @@ interface newHouse extends House{ |
|
|
|
styleUrls: ['./basicinfo.component.scss'] |
|
|
|
styleUrls: ['./basicinfo.component.scss'] |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class BasicinfoComponent implements OnInit { |
|
|
|
export class BasicinfoComponent implements OnInit { |
|
|
|
|
|
|
|
xxxx: any |
|
|
|
|
|
|
|
blockdata: any//将每次的分块数据存储到这个变量
|
|
|
|
|
|
|
|
blockdataindex: any//将每次的分块数据的编号存储到这个变量
|
|
|
|
|
|
|
|
kkkk: any |
|
|
|
|
|
|
|
initializedata: any //初始化分块事件返回的对象名以及唯一id
|
|
|
|
|
|
|
|
|
|
|
|
uploader:FileUploader = new FileUploader({
|
|
|
|
uploader:FileUploader = new FileUploader({
|
|
|
|
url: "/api/Objects/PlanPlatform",
|
|
|
|
url: "/api/Objects/PlanPlatform",
|
|
|
|
method: "POST",
|
|
|
|
method: "POST",
|
|
|
|
itemAlias: "uploadedfile" |
|
|
|
itemAlias: "uploadedfile" |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
private _transformer = (node, level: number) => { |
|
|
|
private _transformer = (node, level: number) => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
expandable: !!node.children && node.children.length > 0, |
|
|
|
expandable: !!node.children && node.children.length > 0, |
|
|
@ -68,9 +79,22 @@ export class BasicinfoComponent implements OnInit { |
|
|
|
//选择单位类型,使底下表单跟着变化
|
|
|
|
//选择单位类型,使底下表单跟着变化
|
|
|
|
newHouses = [] |
|
|
|
newHouses = [] |
|
|
|
ngOnInit(): void { |
|
|
|
ngOnInit(): void { |
|
|
|
this.getallunittype() |
|
|
|
// this.getallunittype()
|
|
|
|
this.getorganization() |
|
|
|
// this.getorganization()
|
|
|
|
this.inithosue() |
|
|
|
this.inithosue() |
|
|
|
|
|
|
|
async function testAsync() { |
|
|
|
|
|
|
|
return "hello ddddddddddddddddd"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = testAsync(); |
|
|
|
|
|
|
|
console.log(1111,result); |
|
|
|
|
|
|
|
testAsync().then(()=>{ |
|
|
|
|
|
|
|
setTimeout(()=>{ |
|
|
|
|
|
|
|
console.log(2222) |
|
|
|
|
|
|
|
},3000) |
|
|
|
|
|
|
|
console.log(3333) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//初始化建筑信息数组
|
|
|
|
//初始化建筑信息数组
|
|
|
|
inithosue() { |
|
|
|
inithosue() { |
|
|
@ -121,23 +145,23 @@ export class BasicinfoComponent implements OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selecttab(node) { |
|
|
|
selecttab(node) { |
|
|
|
console.log(1111,node) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获得所有单位类型
|
|
|
|
//获得所有单位类型
|
|
|
|
getallunittype(){ |
|
|
|
// getallunittype() {
|
|
|
|
this.http.get("/api/BuildingTypes").subscribe(data=>{ |
|
|
|
// this.http.get("/api/BuildingTypes").subscribe(data => {
|
|
|
|
this.allunittype = data |
|
|
|
// this.allunittype = data
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
} |
|
|
|
// }
|
|
|
|
//获得所有组织机构
|
|
|
|
//获得所有组织机构
|
|
|
|
getorganization(){ |
|
|
|
// getorganization() {
|
|
|
|
this.http.get('/api/Organizations').subscribe( |
|
|
|
// this.http.get('/api/Organizations').subscribe(
|
|
|
|
(data:any)=>{ |
|
|
|
// (data: any) => {
|
|
|
|
this.dataSource.data = this.tree.toTree(data); |
|
|
|
// this.dataSource.data = this.tree.toTree(data);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
) |
|
|
|
// )
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add(node) { |
|
|
|
add(node) { |
|
|
@ -154,80 +178,164 @@ export class BasicinfoComponent implements OnInit { |
|
|
|
this.isorganizationbox = true |
|
|
|
this.isorganizationbox = true |
|
|
|
} |
|
|
|
} |
|
|
|
hasChild = (_: number, node: any) => node.expandable; |
|
|
|
hasChild = (_: number, node: any) => node.expandable; |
|
|
|
filechange(e){ |
|
|
|
|
|
|
|
const file = e.srcElement.files[0]; // 获取图片这里只操作一张图片
|
|
|
|
|
|
|
|
var upfilesize = file.size/1048576 //上传照片大小MB
|
|
|
|
|
|
|
|
if(upfilesize <= 5){//如果想要上传照片小于5MB,则走正常上传流程
|
|
|
|
|
|
|
|
this.upload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filechange(e){
|
|
|
|
|
|
|
|
// const file = e.srcElement.files[0]; // 获取图片这里只操作一张图片
|
|
|
|
|
|
|
|
// var upfilesize = file.size/1048576 //上传照片大小MB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(upfilesize <= 5){//如果想要上传照片小于5MB,则走正常上传流程
|
|
|
|
|
|
|
|
// this.upload()
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(upfilesize > 5 && upfilesize <= 20){//如果想要上传照片在5-20之间则采用分块上传
|
|
|
|
|
|
|
|
// var bytesPerPiece = 1024 * 1024 * 5;// 每个文件切片大小定为 5 Mb
|
|
|
|
|
|
|
|
// var blob = e.srcElement.files[0];//想要上传的整体文件
|
|
|
|
|
|
|
|
// var start = 0;
|
|
|
|
|
|
|
|
// var end;
|
|
|
|
|
|
|
|
// var index = 1;
|
|
|
|
|
|
|
|
// var filesize = blob.size;//上传文件的大小
|
|
|
|
|
|
|
|
// var filename = blob.name;//上传文件 原始名字
|
|
|
|
|
|
|
|
// this.http.post("/api/NewMultipartUpload/PlanPlatform/ceshi",{},{
|
|
|
|
|
|
|
|
// params: {
|
|
|
|
|
|
|
|
// filename:filename,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }).subscribe((data:any)=>{
|
|
|
|
|
|
|
|
// this.initializedata = data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var totalPieces;//一共有多少块
|
|
|
|
|
|
|
|
// totalPieces = Math.ceil(filesize / bytesPerPiece);//------计算需要分为多少段
|
|
|
|
|
|
|
|
|
|
|
|
if(upfilesize > 5 && upfilesize <= 20){//如果想要上传照片在5-20之间则采用分块上传
|
|
|
|
|
|
|
|
var bytesPerPiece = 1024 * 1024 * 5;// 每个文件切片大小定为 5 Mb
|
|
|
|
|
|
|
|
var totalPieces;//一共有多少块
|
|
|
|
|
|
|
|
var blob = e.srcElement.files[0];//想要上传的整体文件
|
|
|
|
|
|
|
|
var start = 0; |
|
|
|
|
|
|
|
var end; |
|
|
|
|
|
|
|
var index = 0; |
|
|
|
|
|
|
|
var filesize = blob.size;//上传文件的大小
|
|
|
|
|
|
|
|
var filename = blob.name;//上传文件的名字
|
|
|
|
|
|
|
|
totalPieces = Math.ceil(filesize / bytesPerPiece);//------计算需要分为多少段
|
|
|
|
|
|
|
|
this.http.post(`/api/Objects/PlanPlatform/${filename}?uploads`,{}).subscribe(data=>{ |
|
|
|
|
|
|
|
console.log(data) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
// while(start < filesize){
|
|
|
|
// while(start < filesize){
|
|
|
|
// end = start + bytesPerPiece;
|
|
|
|
// end = start + bytesPerPiece;
|
|
|
|
// if(end > filesize) {
|
|
|
|
// if(end > filesize) {
|
|
|
|
// end = filesize;
|
|
|
|
// end = filesize;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// var chunk = blob.slice(start,end);//切割文件
|
|
|
|
// var chunk = blob.slice(start,end);//切割文件
|
|
|
|
// var sliceIndex= blob.name + index;//分块编号
|
|
|
|
// var sliceIndex= index;//分块编号
|
|
|
|
// var formData = new FormData();
|
|
|
|
// this.blockdataindex = sliceIndex
|
|
|
|
// formData.append("file", chunk, filename);
|
|
|
|
// this.blockdata = chunk
|
|
|
|
// this.blockupload()
|
|
|
|
// this.blockdata.name = filename
|
|
|
|
|
|
|
|
// this.uploader.setOptions({ url:`/api/MultipartUpload/PlanPlatform/${this.initializedata.objectName}?uploadId=${this.initializedata.uploadId}&partNumber=${this.blockdataindex}`});
|
|
|
|
|
|
|
|
// this.upload()
|
|
|
|
// start = end;
|
|
|
|
// start = end;
|
|
|
|
// index++;
|
|
|
|
// index++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// this.blockupload()
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
if(upfilesize > 20){//如果想要上传照片大于20MB
|
|
|
|
// }
|
|
|
|
alert("上传照片应小于20MB") |
|
|
|
|
|
|
|
} |
|
|
|
// if(upfilesize > 20){//如果想要上传照片大于20MB
|
|
|
|
|
|
|
|
// alert("上传照片应小于20MB")
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imgsrc = "../../../assets/images/upload.jpg" |
|
|
|
imgsrc = "../../../assets/images/upload.jpg" |
|
|
|
imgUrl = ""//返回来的图片地址后缀
|
|
|
|
imgUrl = ""//返回来的图片地址后缀
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file: any; //上传的文件
|
|
|
|
|
|
|
|
objectName: any; //上传对象名
|
|
|
|
|
|
|
|
uploadId: any; //上传分块上传事件编号
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//change选择文件
|
|
|
|
|
|
|
|
filechange(e) { |
|
|
|
|
|
|
|
this.file = e.target.files[0] || null //上传的文件
|
|
|
|
|
|
|
|
this.startUploading() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isspinner:boolean=false |
|
|
|
|
|
|
|
//上传文件
|
|
|
|
|
|
|
|
startUploading() { |
|
|
|
|
|
|
|
this.isspinner = true |
|
|
|
|
|
|
|
let file = this.file || null //获取上传的文件
|
|
|
|
|
|
|
|
let fileSize = file.size || null //上传文件的总大小
|
|
|
|
|
|
|
|
let shardSize = 5 * 1024 * 1024 //5MB一个分片
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (file && fileSize <= shardSize) { //上传文件<=5MB时
|
|
|
|
|
|
|
|
this.upload() |
|
|
|
|
|
|
|
} else if (file && fileSize >= shardSize) { //上传文件>5MB时,分块上传
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = { filename: file.name } |
|
|
|
|
|
|
|
this.http.post(`/api/NewMultipartUpload/PlanPlatform/HHH`, {}, { params: data }).subscribe((data: any) => { //初始化分段上传
|
|
|
|
|
|
|
|
this.objectName = data.objectName |
|
|
|
|
|
|
|
this.uploadId = data.uploadId |
|
|
|
|
|
|
|
this.subsectionUploading() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//小于5MB不需要分块上传
|
|
|
|
upload(){ |
|
|
|
upload(){ |
|
|
|
if(!this.uploader.queue[0]){ |
|
|
|
|
|
|
|
alert("请选择文件") |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
this.uploader.queue[0].upload();//开始上传
|
|
|
|
this.uploader.queue[0].upload();//开始上传
|
|
|
|
this.uploader.queue[0].onSuccess = (response, status, headers) => {
|
|
|
|
this.uploader.queue[0].onSuccess = (response, status, headers) => {
|
|
|
|
// 上传文件成功
|
|
|
|
// 上传文件成功
|
|
|
|
if (status == 201) { |
|
|
|
if (status == 201) { |
|
|
|
// 上传文件后获取服务器返回的数据
|
|
|
|
// 上传文件后获取服务器返回的数据
|
|
|
|
alert("上传成功") |
|
|
|
alert("上传成功") |
|
|
|
|
|
|
|
this.isspinner = false |
|
|
|
let tempRes = JSON.parse(response); |
|
|
|
let tempRes = JSON.parse(response); |
|
|
|
this.imgUrl = tempRes.objectName
|
|
|
|
this.imgUrl = tempRes.objectName
|
|
|
|
this.imgsrc = '/api/Objects/PlanPlatform/' + this.imgUrl
|
|
|
|
this.imgsrc = `/api/Objects/PlanPlatform/${this.imgUrl}?x-oss-process=image/resize,m_fill,h_100,w_100` |
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
// 上传文件后获取服务器返回的数据错误
|
|
|
|
// 上传文件后获取服务器返回的数据错误
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.uploader.queue[0].onError = (response, status, headers) => {
|
|
|
|
this.uploader.queue[0].onError = (response, status, headers) => {
|
|
|
|
if (status == 401) { |
|
|
|
if (status == 401) { |
|
|
|
alert("无权限上传")
|
|
|
|
alert("上传失败")
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
PartNumberETag: any = []; //分块上传每次返回需要保存的信息
|
|
|
|
|
|
|
|
flag = true |
|
|
|
|
|
|
|
//开始分块上传
|
|
|
|
|
|
|
|
async subsectionUploading () { |
|
|
|
|
|
|
|
let file = this.file || null //获取上传的文件
|
|
|
|
|
|
|
|
let fileSize = file.size || null //上传文件的总大小
|
|
|
|
|
|
|
|
let shardSize = 5 * 1024 * 1024 //5MB一个分片
|
|
|
|
|
|
|
|
let allSlice = Math.ceil(fileSize / shardSize) //总文件/5MB===共分多少段
|
|
|
|
|
|
|
|
|
|
|
|
blockupload(){//分块上传
|
|
|
|
for (let i = 0;i < allSlice;i++) { //循环分段上传
|
|
|
|
|
|
|
|
let start = i * shardSize //切割文件开始位置
|
|
|
|
|
|
|
|
let end = Math.min(fileSize, start + shardSize); //切割文件结束位置
|
|
|
|
|
|
|
|
let formData = new FormData() |
|
|
|
|
|
|
|
formData.append("file",file.slice(start, end)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 同步写法实现异步调用
|
|
|
|
|
|
|
|
let result = await new Promise((resolve, reject) => { |
|
|
|
|
|
|
|
// await 需要后面返回一个 promise 对象
|
|
|
|
|
|
|
|
this.http.post(`/api/MultipartUpload/PlanPlatform/${this.objectName}?uploadId=${this.uploadId}&partNumber=${i+1}`,formData).subscribe((data:any)=>{ |
|
|
|
|
|
|
|
let msg = { |
|
|
|
|
|
|
|
"partNumber":data.partNumber || null, |
|
|
|
|
|
|
|
"eTag": data.eTag || null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resolve(msg) // 调用 promise 内置方法处理成功
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.PartNumberETag.push(result) |
|
|
|
|
|
|
|
if (this.PartNumberETag.length === allSlice) { |
|
|
|
|
|
|
|
this.endUploading() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//完成分块上传
|
|
|
|
|
|
|
|
endUploading() { |
|
|
|
|
|
|
|
let data = this.PartNumberETag |
|
|
|
|
|
|
|
let paramsData = { uploadId: this.uploadId } |
|
|
|
|
|
|
|
this.http.post(`/api/CompleteMultipartUpload/PlanPlatform/${this.objectName}`, data, { params: paramsData }).subscribe(data => { |
|
|
|
|
|
|
|
this.imgsrc = `/api/Objects/PlanPlatform/${this.objectName}?x-oss-process=image/resize,m_fill,h_100,w_100` |
|
|
|
|
|
|
|
this.isspinner = false |
|
|
|
|
|
|
|
this.PartNumberETag = [] |
|
|
|
|
|
|
|
this.file = null |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
onSubmit(value) { |
|
|
|
onSubmit(value) { |
|
|
|
|
|
|
|
|
|
|
|