Newer
Older
import {Component} from '@angular/core';
import {ActionSheetController, IonicPage, LoadingController, NavController, NavParams} from 'ionic-angular';
import {TabsService} from "../../tabs/tabs.service";
import {Storage} from "@ionic/storage";
import {Camera, CameraOptions} from "@ionic-native/camera";
import {FileTransfer, FileTransferObject, FileUploadOptions} from "@ionic-native/file-transfer";
import {AppGlobal} from "../../../service/http.service";
//1党规党章,2系列讲话,3中央精神,4本市部署,5通知公告,6党建动态,7工作提示, 8党务参考,9廉政格言,10纪检提示,11风险排查,12警示教育,13支部活动,14党建联建,15结对帮扶
plateList = [
{name: '党规党章', id: '1'}, {name: '系列讲话', id: '2'}, {name: '中央精神', id: '3'}, {
name: '本市部署',
id: '4'
}, {name: '通知公告', id: '5'},
{name: '党建动态', id: '6'}, {name: '工作提示', id: '7'}, {name: '党务参考', id: '8'}, {
name: '廉政格言',
id: '9'
}, {name: '纪检提示', id: '10'},
{name: '风险排查', id: '11'}, {name: '警示教育', id: '12'}, {name: '支部活动', id: '13'}, {
name: '党建联建',
id: '14'
}, {name: '结对帮扶', id: '15'},
];
obj = {
type: '1',
title: '',
content: '',
publishRange: '',
};
pictrue = AppGlobal.domain + '/wisdomgroup';
type; //视频文章or图片文章
constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage,
public camera: Camera, public actionSheetCtrl: ActionSheetController,
public loadingCtrl: LoadingController, public transfer: FileTransfer,
public commonSer: CommonService, public tabSer: TabsService) {
}
ionViewDidLoad() {
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
this.storage.get("userLoginInfo").then((value) => {
this.userid = value.userid;
})
//获取用户组
this.tabSer.getGroup().subscribe(
(res) => {
this.group = res.list;
}
)
}
tackePic() {
const actionSheet = this.actionSheetCtrl.create({
title: '上传图片',
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
console.log('fromCamera');
this.selectPicture(1);
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
this.selectPicture(0);
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
//选择图片
selectPicture(srcType) {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: srcType,
saveToPhotoAlbum: false
};
const option: FileUploadOptions = {
httpMethod: 'POST',
headers: {
'Accept': 'application/json', //不加入 发生错误!!
},
fileName:'image.png'
};
if(imagedata.indexOf('?') !== -1){ //获取文件名
imagedata = imagedata.split('?')[0];
}
let arr = imagedata.split('/');
this.upload(arr[arr.length -1], option);
//选择视频
selectVideo() {
const options: CameraOptions = {
quality: 30,
destinationType: this.camera.DestinationType.FILE_URI,
mediaType: this.camera.MediaType.VIDEO,
sourceType: 0,
};
const option: FileUploadOptions = {
httpMethod: 'POST',
headers: {
'Accept': 'application/json', //不加入 发生错误!!
},
fileName:'video.mp4',
mimeType:'mp4'
if(videoData.indexOf('?') !== -1){ //获取文件名
videoData = videoData.split('?')[0];
}
let arr = videoData.split('/');
this.upload(arr[arr.length -1], option);
this.upload(videoData, option);
})
}
//上传文件或视频
// 接口返回参数的格式
// {
// "code" : 0,
// "data" : [ {
// "id" : null,
// "fileName" : null,
// "fileType" : "image/png",
// "showName" : "demo.png",
// "uploadTime" : 1557734823883,
// "filePath" : "/upload/image/F1F18A0762814B25A2DA98344C38058/demo.png"
// } ],
// "error" : [ ]
// }
content: '上传中...',
dismissOnPageChange:true,
enableBackdropDismiss:true,
});
uploadLoading.present();
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(file, AppGlobal.domain + '/wisdomgroup/modules/common/file/upload1', options).then(
(res) => {
uploadLoading.dismiss();
this.commonSer.toast('上传成功');
const data = JSON.parse(res.response);
const obj = {
resourceType: 1,
path: data.data[0].filePath,
name: data.data[0].showName,
};
this.commonSer.log(data);
this.fileList.push(obj);
}, err => {
uploadLoading.dismiss();
this.commonSer.toast('上传错误');
});
}
//发布
publish() {
const data = {
title: this.obj.title,
plateType: this.obj.type,
source: '上海市委组织部',
publishStatus: '2',
content: this.obj.content,
publishRange: this.obj.publishRange,
submitter: this.userid,
stuffType: 1,
};
this.commonSer.alert('确定提交审核当前内容?', () => {
this.tabSer.stuffSave(data).subscribe(
(res) => {
this.commonSer.toast('已提交审核')
setTimeout(() => {
this.navCtrl.pop()
}, 800)
}
)
})
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//选择发布或者预览
handle(){
const actionSheet = this.actionSheetCtrl.create({
title: '',
buttons: [
{
text: '预览',
handler: () => {
const obj = {
title:this.obj.title,
source: '上海市委组织部',
publishTime:new Date().getTime(),
content:this.obj.content,
attachments:this.fileList,
}
this.navCtrl.push('PreviewPage',{
stuff:obj
});
}
}, {
text: '发布',
role: 'fromPhoto',
handler: () => {
this.publish();
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}