Newer
Older
import {Component} from '@angular/core';
import {ActionSheetController, IonicPage, LoadingController, NavController, NavParams} from 'ionic-angular';
import {AppGlobal} from "../../../service/http.service";
import {Camera, CameraOptions} from "@ionic-native/camera";
import {FileTransfer, FileUploadOptions, FileTransferObject} from "@ionic-native/file-transfer";
import {TabsService} from "../../tabs/tabs.service";
import {CommonService} from "../../../provide/common.service";
import {DomSanitizer} from "@angular/platform-browser";
import {Storage} from "@ionic/storage";
@IonicPage()
@Component({
selector: 'page-verify-edit',
templateUrl: 'verify-edit.html',
})
export class VerifyEditPage {
//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: '21'},
// {name: '党建联建', id: '14'},
// {name: '结对帮扶', id: '15'},
];
obj = {
plateType: '13',
title: '',
content: null,
group = [
{groupName: '全体人员', id: 1},
{groupName: '本处室', id: 2},
]; //用户组
userid; //当前登录人的id
file; // 文件
pictrue = AppGlobal.domain + '/wisdomgroup';
type = "image"; //视频文章or图片文章
constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage,
public camera: Camera, public actionSheetCtrl: ActionSheetController,
public loadingCtrl: LoadingController, public transfer: FileTransfer,
private tabsSer: TabsService, private sanitizer: DomSanitizer,
public commonSer: CommonService, public tabSer: TabsService) {
}
ionViewDidLoad() {
this.stuffId = this.navParams.get('stuffId');
this.storage.get("userLoginInfo").then((value) => {
this.userid = value.userid;
});
}
//获取文章信息
getStuff() {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
const stuffObj = res.data;
this.obj = stuffObj;
res.data.attachments.forEach(e => { //1 标题图片 2 轮播图 3 视频
if (e.resourceType == 2) {
this.caroul = e;
} else {
this.fileList.push(e);
}
});
this.obj.content = stuffObj.content.substring(48, stuffObj.content.length);
}
)
}
//获取部门
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;
}
)
}
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
254
255
256
257
258
259
260
261
262
263
264
265
tackePic(resourceType) {
const actionSheet = this.actionSheetCtrl.create({
cssClass: 'cameraAction',
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
console.log('fromCamera');
this.selectPicture(1, resourceType);
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
this.selectPicture(0, resourceType);
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
//选择图片
selectPicture(srcType, resourceType) {
if (this.fileList.length > 8) {
this.commonSer.toast('一批文章最多上传9个图片');
return false;
}
const options: CameraOptions = {
quality: 70,
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'
};
this.camera.getPicture(options).then((imagedata) => {
let filePath = imagedata;
if (filePath.indexOf('?') !== -1) { //获取文件名
filePath = filePath.split('?')[0];
}
let arr = filePath.split('/');
option.fileName = arr[arr.length - 1];
this.upload(imagedata, option, resourceType);
})
}
//选择视频
selectVideo(resourceType) {
if (this.fileList.length > 2) {
this.commonSer.toast('一批文章最多上传3个视频');
return false;
}
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'
};
this.camera.getPicture(options).then((videoData) => {
let filePath = videoData;
if (filePath.indexOf('?') !== -1) { //获取文件名
filePath = filePath.split('?')[0];
}
let arr = filePath.split('/');
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" : [ ]
// }
upload(file, options, resourceType) {
this.commonSer.log(file);
const uploadLoading = this.loadingCtrl.create({
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: resourceType, //1 标题图片 2 轮播图 3 视频
path: data.data[0].filePath,
name: data.data[0].showName,
};
if (resourceType == 2) this.caroul = obj;
if (resourceType != 2) this.fileList.push(obj);
this.commonSer.log(data);
}, err => {
uploadLoading.dismiss();
this.commonSer.toast('上传错误');
});
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 + '%');
})
}
//发布
publish(status) {
let message;
let toast;
if (status == 1) {
message = '确定当前内容保存为草稿?';
toast = "已保存为草稿";
}
if (status == 2) {
message = '确定提交审核当前内容?';
toast = "已提交审核";
}
if (status == 3) {
message = '确定直接发布当前内容?';
toast = "已发布";
}
if (!this.check()) {
return false;
}
let attachmentsArr = []; //附件
if (this.fileList.length > 0) {
if (this.type == 'image') {
attachmentsArr.push(this.fileList[0]); //将第一张图片作为标题图片,放在附件中 ,后面的图片 作为文章里面的图片
let arr = this.fileList.slice(1); //2.....
arr.forEach(e => {
content += `<br><img src="/wisdomgroup/${e.path} " alt="图片">`;
});
}
if (this.type == 'video') {
if (this.caroul) attachmentsArr.push(this.caroul); //轮播图放进附件
if (this.caroul) attachmentsArr.push(this.caroul); //轮播图放进附件
const data = {
id: this.stuffId,
title: this.obj.title, //标题
plateType: this.obj.plateType, //分类
publishStatus: status, //已提交 退回1 发布3
content: ` ` + content, //内容
submitter: this.userid, //提交者
stuffType: this.type === 'image' ? 1 : 2, //图片 1 视频 2
attachments: attachmentsArr, //标题附件
};
this.commonSer.alert(message, () => {
this.tabSer.stuffSave(data).subscribe(
(res) => {
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
setTimeout(() => {
let index = this.navCtrl.length() - 2;
this.navCtrl.remove(2, index)
}, 800)
}
)
})
}
check() {
if (!this.obj.title) {
this.commonSer.toast('请输入文章标题!');
return false;
}
if (!this.obj.content) {
this.commonSer.toast('请输入发布内容!');
return false;
}
return true;
}
//选择发布或者预览
handle() {
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,
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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);
}
};
if (this.role == 3 || this.role == 5) {
buttonArr.push(publish);
} else {
buttonArr.push(submit);
}
buttonArr.push(cancel);
const actionSheet = this.actionSheetCtrl.create({
title: '',
cssClass: 'stuffAction',
buttons: buttonArr
});
actionSheet.present();
}
//删除文件
deleteFile(i) {
this.fileList.splice(i, 1);
}
// 清空轮播
deleteCarousel() {
this.caroul = null;
}
}