|
|
|
import { HttpClient } from "@angular/common/http";
|
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import { CacheTokenService } from "../http-interceptors/cache-token.service";
|
|
|
|
import { Viewer } from "photo-sphere-viewer";
|
|
|
|
import { DomSanitizer } from "@angular/platform-browser";
|
|
|
|
|
|
|
|
declare var CryptoJS;
|
|
|
|
@Component({
|
|
|
|
selector: "app-external-links-plan",
|
|
|
|
templateUrl: "./external-links-plan.component.html",
|
|
|
|
styleUrls: ["./external-links-plan.component.scss"],
|
|
|
|
})
|
|
|
|
export class ExternalLinksPlanComponent implements OnInit {
|
|
|
|
constructor(
|
|
|
|
private http: HttpClient,
|
|
|
|
private token: CacheTokenService,
|
|
|
|
public route: ActivatedRoute,
|
|
|
|
private sanitizer: DomSanitizer
|
|
|
|
) {}
|
|
|
|
planId: any; //预案id
|
|
|
|
viewer; //全景图对象
|
|
|
|
fetchUrl; //预案文件地址
|
|
|
|
showType; //预案类型 1:全景图
|
|
|
|
planData; //预案信息
|
|
|
|
async ngOnInit(): Promise<void> {
|
|
|
|
await this.login(); //登录存储token
|
|
|
|
this.route.queryParams.subscribe((paramsData) => {
|
|
|
|
this.planId = paramsData.planId;
|
|
|
|
this.http
|
|
|
|
.get(`/api/PlanComponents/${this.planId}`)
|
|
|
|
.subscribe((data: any) => {
|
|
|
|
console.log("单个预案详细信息", data);
|
|
|
|
this.planData = data;
|
|
|
|
if (data.planType != 1 && data.planType != 2) {
|
|
|
|
this.fetchUrl = data.attachmentUrls[0];
|
|
|
|
var index = this.fetchUrl.indexOf("/");
|
|
|
|
if (this.fetchUrl.substr(0, index) == "psw") {
|
|
|
|
this.showType = 1;
|
|
|
|
var obj = document.getElementById("viewer");
|
|
|
|
if (obj != null) {
|
|
|
|
obj.innerHTML = "";
|
|
|
|
}
|
|
|
|
window.setTimeout(() => {
|
|
|
|
this.viewer = new Viewer({
|
|
|
|
container: document.querySelector("#viewer"),
|
|
|
|
panorama: "/api/Objects/PlanPlatform/" + this.fetchUrl,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
//毕生
|
|
|
|
this.lookWord();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 二维三维预案
|
|
|
|
this.handleData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async login() {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
this.http
|
|
|
|
.post("/api/Account/SignIn", {
|
|
|
|
name: "zhuzhouyuanchakan",
|
|
|
|
password: "12345678",
|
|
|
|
})
|
|
|
|
.subscribe((data: any) => {
|
|
|
|
sessionStorage.setItem("level", data.level);
|
|
|
|
sessionStorage.setItem("token", data.token);
|
|
|
|
sessionStorage.setItem("refreshToken", data.refreshToken);
|
|
|
|
console.log("登录成功", data);
|
|
|
|
resolve(data);
|
|
|
|
this.token.startUp();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
iframeSrc; //毕生服务器链接
|
|
|
|
src; //文件存储地址
|
|
|
|
lookWord() {
|
|
|
|
this.showType = 0;
|
|
|
|
let src;
|
|
|
|
let suffix = this.fetchUrl
|
|
|
|
.split(".")
|
|
|
|
[this.fetchUrl.split(".").length - 1].toLowerCase();
|
|
|
|
if (suffix == "docx" || suffix == "doc") {
|
|
|
|
let arr = this.fetchUrl.split(".");
|
|
|
|
arr[arr.length - 1] = "pdf";
|
|
|
|
src = `/api/Objects/PlanPlatform/` + arr.join(".");
|
|
|
|
} else if (suffix == "pdf") {
|
|
|
|
src = `/api/Objects/PlanPlatform/` + this.fetchUrl;
|
|
|
|
}
|
|
|
|
this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
companyData; //当前公司信息
|
|
|
|
thirdPartyURL;
|
|
|
|
threedUrl: any;
|
|
|
|
handleData() {
|
|
|
|
let data = this.planData;
|
|
|
|
if (this.planData.planMode == 1 || this.planData.planMode == 2) {
|
|
|
|
//预案planMode=2时, 跳查看页面组件
|
|
|
|
|
|
|
|
this.http.get(`/api/Plans/${data.companyId}`).subscribe((data: any) => {
|
|
|
|
console.log(data);
|
|
|
|
data && data.company ? (this.companyData = data.company) : null;
|
|
|
|
sessionStorage.setItem(
|
|
|
|
"buildingTypeId",
|
|
|
|
this.companyData.buildingTypes.length
|
|
|
|
? this.companyData.buildingTypes[0].id
|
|
|
|
: undefined
|
|
|
|
);
|
|
|
|
sessionStorage.setItem("companyId", data.companyId);
|
|
|
|
sessionStorage.setItem("planId", this.planId);
|
|
|
|
sessionStorage.setItem("editable", "0");
|
|
|
|
sessionStorage.setItem("planName", this.planData.name);
|
|
|
|
this.showType = 3;
|
|
|
|
// this.threedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`/keyUnit/viewunitinfoplans?id=${data.companyId}`)
|
|
|
|
});
|
|
|
|
} else if (this.planData.planMode == 3) {
|
|
|
|
//预案planMode=3时, 第三方网址'
|
|
|
|
// this.http.get(`/api/Plans/${data.companyId}`).subscribe((data: any) => {
|
|
|
|
// data && data.company ? this.companyData = data.company : null
|
|
|
|
// this.threedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(data.url)
|
|
|
|
// this.showType = 2
|
|
|
|
// })
|
|
|
|
let localhostPath = window.document.location.href.substring(
|
|
|
|
0,
|
|
|
|
window.document.location.href.indexOf(window.document.location.pathname)
|
|
|
|
);
|
|
|
|
//localhostPath : http://39.106.78.171:8000/
|
|
|
|
let url = data.url;
|
|
|
|
if (url.indexOf(localhostPath) != -1) {
|
|
|
|
window.location.href = `${url}?unitId=${data.company.id}&unitName=${data.company.name}&editMode=false`;
|
|
|
|
} else {
|
|
|
|
// let substr = url.split('/').splice(3,url.split('/').length)
|
|
|
|
// let port = url.split(':')[2]
|
|
|
|
// if(port.indexOf('/') != -1){
|
|
|
|
// port = port.split('/')[0]
|
|
|
|
// }
|
|
|
|
// let ip = localhostPath.split(':')
|
|
|
|
// ip.pop()
|
|
|
|
// let newurl = ip.join(':') + ":" + port + "/" + substr.join('/');
|
|
|
|
// // console.log('xxx',newurl)
|
|
|
|
// window.location.href = `${newurl}?unitId=${data.company.id}&unitName=${data.company.name}&editMode=false`
|
|
|
|
|
|
|
|
window.location.href = `${url}?unitId=${data.company.id}&unitName=${data.company.name}&editMode=false`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|