@ -21,7 +21,7 @@ export class KnowRouteComponent implements OnInit {
constructor ( public snackBar : MatSnackBar , private http : HttpClient ) { }
ngOnInit ( ) : void {
// this.uploadSucced = JSON.parse(localStorage.getItem(sessionStorage.getItem("companyId")+"xxx")) || []
}
@ -84,11 +84,9 @@ export class KnowRouteComponent implements OnInit {
this . imgUrl = data . objectName
this . imgsrc = ` /api/Objects/PlanPlatform/ ${ this . imgUrl } ?x-oss-process=image/resize,m_fill,h_170,w_299 `
console . log ( this . imgsrc )
//localStorage.setItem(this.clickName,this.imgsrc)
//this.uploadSucced.push({name:this.clickName,src:this.imgsrc,smark})
this . uploadSucced [ this . chooseid ] . src = this . imgsrc
this . inputShow = false
//this.uploadSucced[this.chooseid].smark=this.textareazhi
console . log ( this . uploadSucced )
const config = new MatSnackBarConfig ( ) ;
config . verticalPosition = 'top' ;
@ -97,95 +95,40 @@ export class KnowRouteComponent implements OnInit {
} )
} else if ( file && fileSize >= shardSize ) { //上传文件>5MB时,分块上传
/ * l e t d a t a = { f i l e n a m e : f i l e . n a m e }
this . http . post ( ` /api/NewMultipartUpload/PlanPlatform/ ${ this . unitinfo . id } ` , { } , { params : data } ) . subscribe ( ( data : any ) = > { //初始化分段上传
this . objectName = data . objectName
this . uploadId = data . uploadId
this . subsectionUploading ( )
} ) * /
}
}
//开始分块上传
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===共分多少段
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_170,w_299 `
this . isspinner = false
this . PartNumberETag = [ ]
} )
}
//熟悉部位点击事件
addRoute ( event , item ) {
this . showorfalse = "show"
this . knowRoute . push ( { name :event.target.innerHTML , idnum : "🠖" } )
this . uploadSucced . push ( { name :item.name , src : "" , smark : "" } )
console . log ( this . uploadSucced )
}
clickName
savekey
uploadSucced :any = JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) || [ ] //上传成功暂存对象
gallery
//熟悉路线点击事件
knowroutwClick ( event , key , item ) {
knowroutwClick ( key , item ) {
this . showorfalse = "show"
this . chooseid = key
setTimeout ( ( ) = > {
if ( document . getElementById ( 'viewerjs' ) ) {
this . gallery = new Viewer ( document . getElementById ( 'viewerjs' ) , {
url : 'data-original'
} ) ;
}
} , 0 ) ;
this . showorfalse = "show"
this . uploadSucced [ key ] . smark = this . textareazhi
this . chooseid = key
this . clickName = item . name + key + sessionStorage . getItem ( "companyId" )
//console.log("sss"+JSON.parse(localStorage.getItem(sessionStorage.getItem("companyId")+"xxx"))[key].src)
/ * i f ( J S O N . p a r s e ( l o c a l S t o r a g e . g e t I t e m ( s e s s i o n S t o r a g e . g e t I t e m ( " c o m p a n y I d " ) + " x x x " ) ) [ k e y ] ) {
} * /
if ( JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) && JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ] && JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ] . src != "" ) {
if ( JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) )
&& JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ]
&& JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ] . src != "" ) {
this . imgsrc = JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ] . src
this . textareazhi = JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) [ key ] . smark
this . inputShow = false
} else if ( this . uploadSucced [ key ] . src != "" ) {
this . imgsrc = this . uploadSucced [ key ] . src
this . inputShow = false
}
else {
} else {
this . imgsrc = "../../../assets/images/upload.jpg"
this . textareazhi = ""
this . inputShow = true
@ -193,10 +136,11 @@ export class KnowRouteComponent implements OnInit {
}
//保存点击事件
savaClick ( ) {
this . uploadSucced [ this . chooseid ] . smark = this . textareazhi
localStorage . setItem ( sessionStorage . getItem ( "companyId" ) + "xxx" , JSON . stringify ( this . uploadSucced ) )
alert ( "保存成功" )
console . log ( JSON . parse ( localStorage . getItem ( sessionStorage . getItem ( "companyId" ) + "xxx" ) ) )
const config = new MatSnackBarConfig ( ) ;
config . verticalPosition = 'top' ;
config . duration = 3000
this . snackBar . open ( '保存成功' , '确定' , config ) ;
}
}