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'},
{name: '学思践悟', id: '21'},
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() {
this.storage.get("userLoginInfo").then((value) => {
this.userid = value.userid;
})
//获取用户组
this.tabSer.getGroup().subscribe(
(res) => {
this.group = res.list;
}
)
}
//获取权限
//返回值int :3-管理员,2-处室领导,1-内勤人员,0-普通用户
getRole() {
this.tabsSer.getRoles().subscribe(
(res) => {
this.role = res;
}
)
}
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
console.log('fromCamera');
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
//选择图片
selectPicture(srcType, resourceType) {
if (this.fileList.length > 8) {
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: {
option.fileName = arr[arr.length - 1];
this.upload(imagedata, option, resourceType);
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', //不加入 发生错误!!
},
option.fileName = arr[arr.length - 1];
this.upload(videoData, option, resourceType);
})
}
//上传文件或视频
// 接口返回参数的格式
// {
// "code" : 0,
// "data" : [ {
// "id" : null,
// "fileName" : null,
// "fileType" : "image/png",
// "showName" : "demo.png",
// "uploadTime" : 1557734823883,
// "filePath" : "/upload/image/F1F18A0762814B25A2DA98344C38058/demo.png"
// } ],
// "error" : [ ]
// }
});
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);
path: data.data[0].filePath,
name: data.data[0].showName,
};
if (resourceType == 2) this.caroul = obj;
if (resourceType != 2) this.fileList.push(obj);
fileTransfer.onProgress((listener) => {
let per = <any>(listener.loaded / listener.total) * 100;
per = Math.round(per * Math.pow(10, 2)) / Math.pow(10, 2)
uploadLoading.setContent('上传中...' + per + '%');
if (status == 2) message = '确定提交审核当前内容?';
if (status == 3) message = '确定直接发布当前内容?';
if (!this.check()) {
attachmentsArr.push(this.fileList[0]); //将第一张图片作为标题图片,放在附件中 ,后面的图片 作为文章里面的图片
if (this.type == 'video') {
attachmentsArr = this.fileList.filter(e => e.resourceType == 2)
title: this.obj.title, //标题
plateType: this.obj.type, //分类
source: '上海市委组织部', //来源
publishStatus: status, //已提交
content: ` ` + content, //内容
publishRange: this.obj.publishRange, //范围
submitter: this.userid, //提交者
setTimeout(() => {
this.navCtrl.pop()
}, 800)
}
)
})
const preview = {
text: '预览',
role: 'preview',
handler: () => {
let content = this.obj.content;
if (this.fileList.length > 0) {
if (this.type == 'image') { //将第一张图片作为标题图片 ,后面的图片 作为文章里面的图片
let arr = this.fileList.slice(1); //2.....
arr.forEach(e => {
content += `<br><img src="${this.pictrue}${e.path} " alt="图片">`;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
if (this.type == 'video') {
this.fileList.forEach(e => {
e.resourceType = 3;
})
}
const obj = {
title: this.obj.title,
source: '上海市委组织部',
publishTime: new Date().getTime(),
content: ` ` + content,
attachments: this.fileList,
}
this.navCtrl.push('PreviewPage', {
stuff: obj
});
}
};
const cancel = {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
};
const publish = {
text: '直接发布',
role: 'publish',
handler: () => {
this.publish(3);
}
};
const submit = {
text: '提交审核',
role: 'submit',
handler: () => {
this.publish(2);
}
};
let buttonArr = [];
buttonArr.push(preview);
if (this.role == 3) {
buttonArr.push(publish);
} else {
buttonArr.push(submit);
}
buttonArr.push(cancel);
const actionSheet = this.actionSheetCtrl.create({
title: '',
cssClass: 'stuffAction',
buttons: buttonArr