陈鹏飞 3 years ago
parent
commit
35427a0266
  1. 24
      src/app/babylon/controller/data-manager.ts
  2. 13
      src/app/babylon/controller/serve-manager.ts
  3. 1
      src/app/babylon/controller/status/login-status.ts
  4. 6
      src/app/babylon/tool/babylon-tool.ts
  5. 1
      src/app/babylon/view/building-window/building-window.ts
  6. 2
      src/app/babylon/view/indoor-window/indoor-window.ts
  7. 4
      src/app/pages/plan/plan.component.ts
  8. 4
      src/app/service/babylon/building-basic-infos.service.ts
  9. 87
      src/app/service/babylon/objects.service.ts
  10. 80
      src/app/service/objects.service.ts

24
src/app/babylon/controller/data-manager.ts

@ -142,7 +142,6 @@ export class DataManager {
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.environmentDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.Environment,
'modelEn001'
);
DataManager.institutionData.environmentDatas[0].outdoorData.modelData = new ModelData_building(
'modelEn001',
@ -200,7 +199,6 @@ export class DataManager {
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.OutDoor,
'modelOut001'
);
DataManager.institutionData.normalBuildingDatas[0].outdoorData.modelData = new ModelData_building(
'modelOut001',
@ -221,7 +219,6 @@ export class DataManager {
let resPath_inDoor1 = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.Indoor,
'nei1'
);
indoorData1.modelData = new ModelData_building(
@ -241,7 +238,6 @@ export class DataManager {
let resPath_inDoor2 = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.Indoor,
'nei2'
);
indoorData2.modelData = new ModelData_building(
@ -274,21 +270,25 @@ export class DataManager {
//获取建筑资源完整路径
/**
* (ObjectsService.baseUrl)
* @param institutionKey
* @param buildingKey
* @param key
*/
static getResPath_building(
institutionKey: string,
buildingKey: string,
buildingPosType: BuildingPosType,
key: string
): string {
let result =
ConfigManager.c_resPath_institutionsRoot +
institutionKey.toLocaleLowerCase() +
institutionKey.toLocaleLowerCase()
'/' +
ServeManager.ngAssetsPath +
'/' +
buildingKey.toLocaleLowerCase() +
'/' +
buildingPosType +
'/' +
key +
'/';
return result;
@ -299,9 +299,10 @@ export class DataManager {
buildingKey: string, facilityType: FacilityType, facilityKey: string, key: string) {
let result =
ConfigManager.c_resPath_institutionsRoot +
institutionKey.toLocaleLowerCase() +
'/' +
ServeManager.ngAssetsPath +
'/' +
buildingKey.toLocaleLowerCase() +
'/' +
ConfigManager.c_reaPath_facilityProperty +
@ -311,7 +312,6 @@ export class DataManager {
facilityKey.toLocaleLowerCase() +
"/";
return result;
}

13
src/app/babylon/controller/serve-manager.ts

@ -1,7 +1,7 @@
import { HttpErrorResponse } from "@angular/common/http";
import { classToPlain } from "class-transformer";
import { BuildingBasicInfosService } from "src/app/service/babylon/building-basic-infos.service";
import { ObjectsService } from "src/app/service/babylon/objects.service";
import { ObjectsService } from "src/app/service/objects.service";
import { InsitutionDataSimple } from "../model/data/institution/institution-data-simple";
import { AllMarkPlanData } from "../model/data/mark/mark-plan-data";
import { ModeManager } from "./mode-manager";
@ -192,12 +192,12 @@ export class ServeManager {
async postFile(file: File) {
await new Promise((resolve, reject) => {
ServeManager.instance.objectsSrv.postFile(ServeManager.ngAssetsPath + this.postFilePath, file).subscribe(data => {
ServeManager.instance.objectsSrv.postFile(this.postFilePath, file).subscribe(data => {
let dataObj = data as any;
let fileName = dataObj.fileName;
let filePath: string = dataObj.objectName;
filePath = filePath.replace(fileName, "");
filePath = ObjectsService.baseUrl + filePath;
let filePath: string = dataObj.objectName;//此路径不全,前面缺少ObjectsService.baseUrl,这部分不可序列化,要在运行时拼接
filePath = filePath.replace(fileName, "");//去掉结尾的文件名
//filePath = ObjectsService.baseUrl + filePath;
ServeManager.instance.onGetPostFileResult(fileName, filePath, file);
resolve('success')
});
@ -211,8 +211,6 @@ export class ServeManager {
* @param file
*/
onGetPostFileResult(fileName: string, filePath: string, file: File) {
if (ServeManager.instance.onPostFileSuccess) {
ServeManager.instance.onPostFileSuccess(fileName, filePath, file);
}
@ -226,6 +224,7 @@ export class ServeManager {
postFileByMul(file: File) {
ServeManager.instance.objectsSrv.postFile_MultipartUpload(ServeManager.ngAssetsPath + this.postFilePath, file).then((value) => {
let dataObj = value as any;
dataObj.filePath = dataObj.filePath.replace(dataObj.name, ""); //去掉结尾的文件名
ServeManager.instance.onGetPostFileResult(dataObj.fileName, dataObj.filePath, file);
});

1
src/app/babylon/controller/status/login-status.ts

@ -78,6 +78,7 @@ export class LoginSatus extends StatusBase {
console.log("新建数据列表");
}
else {
console.log("单纯报错", error instanceof HttpErrorResponse, error.status === 404)
if (onFail) {
onFail(error);
}

6
src/app/babylon/tool/babylon-tool.ts

@ -31,6 +31,7 @@ import {
StackPanel,
TextBlock,
} from '@babylonjs/gui';
import { ObjectsService } from 'src/app/service/objects.service';
import { ConfigManager } from '../controller/config-manager';
import { ModeManager } from '../controller/mode-manager';
import { UIManager } from '../controller/ui-manager';
@ -124,9 +125,12 @@ export class BabylonTool {
if (path == null) {
return null;
}
if (path.indexOf(ConfigManager.c_resPath_assetsRoot) == -1) {
if (path.indexOf(ConfigManager.c_resPath_assetsRoot) == -1) { //本地资源
path = ConfigManager.c_resPath_assetsRoot + rootUrl;
}
else {
path = ObjectsService.baseUrl + path; //根据环境,动态改变桶名
}
console.log("异步加载模型" + path + sceneFilename);
let modelPath = path + sceneFilename;

1
src/app/babylon/view/building-window/building-window.ts

@ -97,7 +97,6 @@ export class BuildingWindow extends UIBase {
let resPath_out = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
normalData.key.toLocaleLowerCase(),
BuildingPosType.OutDoor,
buildingData.normalData.key
);
// console.log("新资源路径" + resPath_out);

2
src/app/babylon/view/indoor-window/indoor-window.ts

@ -77,7 +77,7 @@ export class IndoorWindow extends UIBase {
let institutionKey = DataManager.institutionData.normalData.key;
let indoorData = modelEditData;
let buildingKey = StatusManager.getStatus<IndoorStatus>(IndoorStatus).buildingInfo.buildingData.normalData.key;
let path = DataManager.getResPath_building(institutionKey, buildingKey, BuildingPosType.Indoor, indoorData.modelData.key);
let path = DataManager.getResPath_building(institutionKey, buildingKey, indoorData.modelData.key);
// console.log("模型路径" + path);
let instance = this;

4
src/app/pages/plan/plan.component.ts

@ -17,7 +17,7 @@ import { ObjectsService } from 'src/app/service/objects.service';
})
export class PlanComponent implements OnInit {
constructor(private element: ElementRef,private buildingBISrv: BuildingBasicInfosService, private objectsSrv: ObjectsService,) { }
constructor(private element: ElementRef, private buildingBISrv: BuildingBasicInfosService, private objectsSrv: ObjectsService) { }
static instance: PlanComponent;
public game: Game = new Game();
@ -26,7 +26,7 @@ export class PlanComponent implements OnInit {
ngOnInit(): void {
PlanComponent.instance = this;
// ServeManager.Init(this.buildingBISrv, this.objectsSrv);
ServeManager.Init(this.buildingBISrv, this.objectsSrv);
this.canvas = this.element.nativeElement.querySelector('#center') as HTMLCanvasElement;
this.game.init(this.canvas);
}

4
src/app/service/babylon/building-basic-infos.service.ts

@ -8,12 +8,12 @@ import { catchError, retry } from 'rxjs/operators';
})
export class BuildingBasicInfosService {
//获取单位信息的api
baseUrl = 'api/v2/BuildingBasicInfos';
baseUrl = 'api/Services/3D/BuildingBasicInfo';
/**
* ()api
*/
markUrl = "api/v2/Sandboxie";
markUrl = "api/Services/3D/Sandboxie";
constructor(

87
src/app/service/babylon/objects.service.ts

@ -1,87 +0,0 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ObjectsService {
static readonly c_apiRoot = "/api/";//普通上传的API根路径
static readonly c_apiRoot_Multipart = "/api/";//分块上传的API根路径
// static testPath = "f1/f2";//测试路径
constructor(private http: HttpClient) { }
//普通上传,单个文件上限5M
static baseUrl = ObjectsService.c_apiRoot + 'Objects/WebPlan/';
postFile(extensionPath: string, file: File): Observable<Object> {
let formData = new FormData()
//console.log(file.name + file.type);
formData.append("file", file, file.name)
let data = { keepOriginalName: 'true' }
return this.http.post(ObjectsService.baseUrl + extensionPath, formData, { params: data });
}
//分块上传
static baseUrl_MultipartUpload = ObjectsService.c_apiRoot_Multipart + 'NewMultipartUpload/WebPlan/';
// {
// "objectName": "string",
// "uploadId": "string"
// }
postFile_MultipartUpload(extensionPath: string, file: File): Promise<Object> {
// let formData = new FormData()
// formData.append("file", file, file.name)
// return this.http.post(ObjectsService.baseUrl + extensionPath, formData);
let data = { keepOriginalName: 'true', filename: file.name }
return new Promise((resolve, reject) => {
this.http.post(ObjectsService.baseUrl_MultipartUpload + extensionPath, {}, { params: data }).subscribe(async (data: any) => { //初始化分段上传
let objectName = data.objectName
let uploadId = data.uploadId
let PartNumberETag = []; //每次返回需要保存的信息
//分块 处理
let fileSize = file.size || null //上传文件的总大小
let shardSize = 5 * 1024 * 1024 //5MB一个分片
let allSlice = Math.ceil(fileSize / shardSize) //总文件/5MB===共分多少段
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(ObjectsService.c_apiRoot_Multipart + `MultipartUpload/WebPlan/${objectName}?uploadId=${uploadId}&partNumber=${i + 1}`, formData).subscribe((data: any) => {
let msg = { "partNumber": data.partNumber || null, "eTag": data.eTag || null }
resolve(msg) // 调用 promise 内置方法处理成功
})
});
PartNumberETag.push(result)
if (PartNumberETag.length === allSlice) { //分块上传完成
let data = PartNumberETag
let paramsData = { uploadId: uploadId };
let path = ObjectsService.c_apiRoot_Multipart + 'CompleteMultipartUpload/WebPlan/' + objectName;
this.http.post(path, data, { params: paramsData }).subscribe(data => {
let objData: any = new Object();
objData.fileName = file.name;
objData.filePath = (ObjectsService.baseUrl + objectName).replace(file.name, "");
resolve(objData)
})
}
}//for循环
//分块 处理
})
})
}
}

80
src/app/service/objects.service.ts

@ -2,22 +2,72 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
/**
*
*/
enum EnvironmentType {
/**
*
*/
DevelopEditor,
/**
*
*/
Test,
/**
*
*/
Production,
}
@Injectable({
providedIn: 'root'
})
export class ObjectsService {
static readonly c_apiRoot = "/api/";//普通上传的API根路径
static readonly c_apiRoot_Multipart = "/api/";//分块上传的API根路径
static readonly c_apiRoot = "/api/Objects/";//普通上传的API根路径
static apiRoot_Multipart = "/api/";//分块上传的API根路径
/**
*
*/
static currentEnvironmentType: EnvironmentType = EnvironmentType.DevelopEditor;
/**
* +
*/
static baseUrl;
/**
*
*/
obsRootByEnv = new Map<EnvironmentType, string>([
[EnvironmentType.DevelopEditor, "sinochemweb/"], //开发与编辑
[EnvironmentType.Test, "sinochem3d/"],//测试
[EnvironmentType.Production, "prod/"],//生产环境(根据需要设置)
]);
// static testPath = "f1/f2";//测试路径
constructor(private http: HttpClient) { }
constructor(private http: HttpClient) {
let bucketName = this.getBucketName();
ObjectsService.baseUrl = ObjectsService.c_apiRoot + bucketName;
}
/**
*
*/
getBucketName() {
return this.obsRootByEnv.get(ObjectsService.currentEnvironmentType);
}
//普通上传,单个文件上限5M
static baseUrl = ObjectsService.c_apiRoot + 'Objects/PlanPlatform/';
/**
* 5M
*/
postFile(extensionPath: string, file: File): Observable<Object> {
let formData = new FormData()
formData.append("file", file, file.name)
@ -29,18 +79,14 @@ export class ObjectsService {
//分块上传
static baseUrl_MultipartUpload = ObjectsService.c_apiRoot_Multipart + 'NewMultipartUpload/PlanPlatform/';
// {
// "objectName": "string",
// "uploadId": "string"
// }
postFile_MultipartUpload(extensionPath: string, file: File): Promise<Object> {
// let formData = new FormData()
// formData.append("file", file, file.name)
// return this.http.post(ObjectsService.baseUrl + extensionPath, formData);
let data = { keepOriginalName: 'true', filename: file.name }
return new Promise((resolve, reject) => {
this.http.post(ObjectsService.baseUrl_MultipartUpload + extensionPath, {}, { params: data }).subscribe(async (data: any) => { //初始化分段上传
this.http.post(ObjectsService.apiRoot_Multipart + "NewMultipartUpload/" + this.getBucketName() + extensionPath, {}, { params: data }).subscribe(async (data: any) => { //初始化分段上传
let instance = this;
let objectName = data.objectName
let uploadId = data.uploadId
let PartNumberETag = []; //每次返回需要保存的信息
@ -58,7 +104,7 @@ export class ObjectsService {
//同步写法实现异步调用
let result = await new Promise((resolve, reject) => {
// await 需要后面返回一个 promise 对象
this.http.post(ObjectsService.c_apiRoot_Multipart + `MultipartUpload/PlanPlatform/${objectName}?uploadId=${uploadId}&partNumber=${i + 1}`, formData).subscribe((data: any) => {
this.http.post(ObjectsService.apiRoot_Multipart + `MultipartUpload/${instance.getBucketName()}${objectName}?uploadId=${uploadId}&partNumber=${i + 1}`, formData).subscribe((data: any) => {
let msg = { "partNumber": data.partNumber || null, "eTag": data.eTag || null }
resolve(msg) // 调用 promise 内置方法处理成功
})
@ -68,11 +114,12 @@ export class ObjectsService {
if (PartNumberETag.length === allSlice) { //分块上传完成
let data = PartNumberETag
let paramsData = { uploadId: uploadId };
let path = ObjectsService.c_apiRoot_Multipart + 'CompleteMultipartUpload/PlanPlatform/' + objectName;
let path = ObjectsService.apiRoot_Multipart + `CompleteMultipartUpload/${instance.getBucketName()}` + objectName;
this.http.post(path, data, { params: paramsData }).subscribe(data => {
let objData: any = new Object();
objData.fileName = file.name;
objData.filePath = (ObjectsService.baseUrl + objectName).replace(file.name, "");
// objData.filePath = (ObjectsService.baseUrl + objectName).replace(file.name, "");//桶名要根据当前环境动态组装
objData.filePath = objectName;//此路径不全,前面缺少ObjectsService.baseUrl,这部分不可序列化,要在运行时拼接
resolve(objData)
})
}
@ -83,3 +130,6 @@ export class ObjectsService {
})
}
}

Loading…
Cancel
Save