Commit 65d5e096 authored by wangqinghua's avatar wangqinghua

4.0.1

parent 7f9f12b4
......@@ -18,11 +18,11 @@
<div class="item1-introduction">
{{introduce}}
</div>
<!--<div class="item1-introduction">-->
<!--<ng-container *ngFor="let file of activity?.fileUploadEntities">-->
<!--<p (click)="downLoad(file)" class="margin-bottom-15" >附件:{{file.showName}}</p>-->
<!--</ng-container>-->
<!--</div>-->
<div class="item1-introduction">
<ng-container *ngFor="let file of activity?.fileUploadEntities">
<p (click)="downLoad(file)" class="margin-bottom-15" >附件:{{file.showName}}</p>
</ng-container>
</div>
</div>
</div>
......
......@@ -174,41 +174,9 @@ export class ActivityDetailPage {
confirm.present();
}
// //下载附件
// downLoad(file){
// this.tabSer.downFile(file).subscribe(
// (res)=>{
// this.commonSer.downloadFile("附件.xlsx",res);
// }
// )
// }
downLoad(file) {
const fileTransfer: FileTransferObject = this.fileTransfer.create();
const url = encodeURI(AppGlobal.domain + '/wisdomgroup/modules/common/file/download/' + file.id);
alert(url);
const folder = this.file.externalRootDirectory + file.showName; //apk保存的目录
alert(folder)
this.diagnostic.requestExternalStorageAuthorization().then((status) => {
alert("Authorization request for external storage use was " + (status == this.diagnostic.permissionStatus.GRANTED ? "授予" : "拒绝"));
fileTransfer.download(url, folder).then((entry) => {
const alertSuccess = this.alertCtrl.create({
title: `Download Succeeded!`,
subTitle: `${url} was successfully downloaded to: ${entry.toURL()}`,
buttons: ['Ok']
});
alertSuccess.present();
}, (error) => {
const alertFailure = this.alertCtrl.create({
title: `Download Failed!`,
subTitle: `${url} was not successfully downloaded. Error code: ${error.exception}`,
buttons: ['Ok']
});
alertFailure.present();
});
}).catch(error => {
//Handle error
});
//下载附件
downLoad(file){
this.commonSer.downloadFile(file.id,file.showName)
}
}
......@@ -10,6 +10,5 @@
<ion-content>
<p class="explain margin-top-100">本次答题共计{{item?.questionCount}}题,满分{{item?.fullMarks}}分</p>
<p class="explain margin-top-20">时间:{{item?.timeLimit | formatTime}}</p>
<p class="explain margin-top-20">分数超过{{item?.score}}分通过</p>
<button class="submit-btn submit" (click)="goToDO()">开始答题</button>
</ion-content>
......@@ -51,26 +51,6 @@ export class AppUpdateService {
enableBackdropDismiss: false,
buttons: ['后台下载']
});
// const fileTransfer: FileTransferObject = this.fileTransfer.create();
// const apk = this.file.externalRootDirectory + 'app.apk'; //apk保存的目录
// fileTransfer.download(AppGlobal.domain+apkUrl, apk).then(() => {
// this.fileOpener.open(apk, 'application/vnd.android.package-archive').then(() => {
// console.log('File is opened')
// }).catch(e => {
// console.log('Error openening file', e)
// });
// });
// fileTransfer.onProgress((event: ProgressEvent) => {
// let num = Math.floor(event.loaded / event.total * 100);
// if (num === 100) {
// alert.dismiss();
// } else {
// let title = document.getElementsByClassName('alert-title')[0];
// title && (title.innerHTML = '下载进度:' + num + '%');
// }
// });
// console.log("this apkUrl is" + apkUrl);
const xhr = new XMLHttpRequest();
const url = AppGlobal.domain + apkUrl;
xhr.open("GET", url);
......
import {Injectable} from "@angular/core";
import {AlertController, ToastController} from "ionic-angular";
import {AppGlobal} from "./appHttpService";
import {File} from "@ionic-native/file";
@Injectable()
export class CommonService{
constructor(public toastCtrl:ToastController,public alertCtrl:AlertController){}
constructor(public toastCtrl:ToastController,public alertCtrl:AlertController,private file: File,){}
/**
* JSON格式数据转化为字符串 接口调用
......@@ -87,14 +89,47 @@ export class CommonService{
* 下载文件
* @param url 文件URL
*/
downloadFile(title,data: Response) {
const blob = new Blob([data]);
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);
downloadFile(fileID,fileName) {
const xhr = new XMLHttpRequest();
const url = encodeURI(AppGlobal.domain + '/wisdomgroup/modules/common/file/download/' + fileID);
xhr.open('GET',url);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.responseType = "blob";
xhr.addEventListener("loadstart",(ev)=>{
})
xhr.addEventListener("progress",(ev)=>{
let progress = Math.round(100.0 * ev.loaded / ev.total);
// alert(progress);
})
xhr.addEventListener("load",(ev)=>{
const blob = xhr.response;
if(blob){
let path = this.file.externalDataDirectory;
this.file.writeFile(path,fileName,blob,{ //写入文件
replace:true
}).then(
()=>{
let toast = this.toastCtrl.create({
message: "下载完成!保存路径:"+this.file.externalDataDirectory,
duration: 2000,
position:'bottom',
dismissOnPageChange: true,
});
toast.present();
}).catch((err)=>{
this.toast("下载文件失败!")
})
}
});
xhr.addEventListener("loadend", (ev) => {
// 结束下载事件
});
xhr.addEventListener("error", (ev) => {
this.alert('下载附件失败!');
});
xhr.addEventListener("abort", (ev) => {
});
xhr.send();
}
}
\ No newline at end of file
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