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: '21'},
group = [
{groupName: '全体人员', id: 1},
{groupName: '本处室', id: 2},
]; //用户组
pictrue = AppGlobal.domain + '/wisdomgroup';
type; //视频文章or图片文章
actionSheet_publish;
actionSheet_image;
actionSheet_video;
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;
})
}
ionViewWillLeave(){
if(this.actionSheet_image !== undefined){
this.actionSheet_image.dismiss();
}
if(this.actionSheet_video !== undefined){
this.actionSheet_video.dismiss();
}
if(this.actionSheet_publish !== undefined){
this.actionSheet_publish.dismiss();
}
}
//获取部门
getOrg() {
this.tabSer.getUserIntegral().subscribe(
(res) => {
this.orgName = res.data.orgName;
}
);
}
//获取权限
//返回值int :3-管理员,2-处室领导,1-内勤人员,0-普通用户
getRole() {
this.tabsSer.getRoles().subscribe(
(res) => {
this.role = res;
}
)
}
this.actionSheet_image = this.actionSheetCtrl.create({
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
console.log('fromCamera');
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
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 + '%');
let toast;
if (status == 1) {
message = '确定当前内容保存为草稿?';
toast = "已保存为草稿";
}
if (status == 2) {
message = '确定提交审核当前内容?';
toast = "已提交审核";
}
if (status == 3) {
message = '确定直接发布当前内容?';
toast = "已发布";
}
attachmentsArr.push(this.fileList[0]); //将第一张图片作为标题图片,放在附件中 ,后面的图片 作为文章里面的图片
attachmentsArr = this.fileList.filter(e => e.resourceType == 3);
if (this.caroul) attachmentsArr.push(this.caroul); //轮播图放进附件
content: ` ` + content, //内容
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="图片">`;
if (this.type == 'video') {
this.fileList.forEach(e => {
e.resourceType = 3;
})
}
const obj = {
title: this.obj.title,
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
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);
}
};
const draft = {
text: '保存草稿',
role: 'draft',
handler: () => {
this.publish(1);
}
};
buttonArr.push(publish);
} else {
buttonArr.push(submit);
}
this.actionSheet_publish = this.actionSheetCtrl.create({