|
|
|
import {Component, OnInit} from '@angular/core';
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
import {NzMessageService, NzModalService, NzUploadFile} from 'ng-zorro-antd';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {LocalStorageService} from '../../../services/local-storage.service';
|
|
|
|
import {ADMIN_INFO_OBJECT} from '../../../services/local-storage.namespace';
|
|
|
|
import {environment} from '../../../../environments/environment';
|
|
|
|
import {CmsService} from '../../../services/cms.service';
|
|
|
|
import {CommonsService} from '../../../services/commons.service';
|
|
|
|
|
|
|
|
function getBase64(file: File): Promise<string | ArrayBuffer | null> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
reader.onload = () => resolve(reader.result);
|
|
|
|
reader.onerror = error => reject(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-cms-content',
|
|
|
|
templateUrl: './cms-content.component.html',
|
|
|
|
styleUrls: ['./cms-content.component.less']
|
|
|
|
})
|
|
|
|
export class CmsContentComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
WEB_SERVE_URL = environment.imageUrl;
|
|
|
|
POST_URL = environment.baseUrl;
|
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
validateForm: FormGroup; // 添加框
|
|
|
|
requestData = []; // 列表数据
|
|
|
|
nodes = []; // 类型树
|
|
|
|
total: number; // 页码
|
|
|
|
pageNum = 1; // 页码
|
|
|
|
pageSize = 10; // 条码
|
|
|
|
loading = true;
|
|
|
|
editFlag = false;
|
|
|
|
isVisible = false;
|
|
|
|
imgFile = [];
|
|
|
|
previewImage: string | undefined = '';
|
|
|
|
previewVisible = false;
|
|
|
|
id: number;
|
|
|
|
constructor(
|
|
|
|
private fb: FormBuilder,
|
|
|
|
private http: HttpClient, // http请求
|
|
|
|
private message: NzMessageService, // 信息提示
|
|
|
|
private router: Router,
|
|
|
|
private common: CommonsService,
|
|
|
|
private cms: CmsService,
|
|
|
|
) {
|
|
|
|
this.WEB_SERVE_URL = environment.baseUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
this.searchForm = this.fb.group({
|
|
|
|
title: [null],
|
|
|
|
categoryId: [null],
|
|
|
|
platform: [null],
|
|
|
|
status: [null],
|
|
|
|
});
|
|
|
|
|
|
|
|
this.validateForm = this.fb.group({
|
|
|
|
categoryId: [null, [Validators.required]],
|
|
|
|
title: [null, [Validators.required]],
|
|
|
|
platform: [null],
|
|
|
|
platformArray: [null],
|
|
|
|
sortId: [null, [Validators.required]],
|
|
|
|
description: [null, [Validators.required]],
|
|
|
|
jumpType: [null],
|
|
|
|
jumpUrl: [null],
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const roleType = 1;
|
|
|
|
this.findCategoryTree(roleType);
|
|
|
|
this.getRequest(true, this.searchForm.value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询列表
|
|
|
|
public getRequest(reset: boolean = false, whereObject: object) {
|
|
|
|
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
this.pageNum = 1;
|
|
|
|
}
|
|
|
|
whereObject['pageNum'] = this.pageNum;
|
|
|
|
whereObject['pageSize'] = this.pageSize;
|
|
|
|
this.cms.getListContent(whereObject, data => {
|
|
|
|
console.log(data);
|
|
|
|
this.loading = false;
|
|
|
|
if (data['return_code'] === '000000') {
|
|
|
|
this.requestData = data['return_data'].list;
|
|
|
|
this.total = data['return_data'].total;
|
|
|
|
} else {
|
|
|
|
this.message.error(data['return_msg']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
public resetForm(): void {
|
|
|
|
this.searchForm.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询分类树
|
|
|
|
findCategoryTree(roleType) {
|
|
|
|
this.cms.getOwnCategoryTree(roleType , data => {
|
|
|
|
if (data['return_code'] === '000000') {
|
|
|
|
this.nodes = data['return_data'];
|
|
|
|
if (this.nodes.length !== 0) {
|
|
|
|
this.generateComment(this.nodes);
|
|
|
|
} else {
|
|
|
|
this.nodes = [];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.message.create('error', data['return_msg']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 递归分类树
|
|
|
|
generateComment(data) {
|
|
|
|
for (const i in data) {
|
|
|
|
if (data[i].nodes == null) {
|
|
|
|
const item = {
|
|
|
|
isLeaf: true,
|
|
|
|
title: data[i].text,
|
|
|
|
key: data[i].id,
|
|
|
|
children: data[i].nodes,
|
|
|
|
};
|
|
|
|
data[i] = item;
|
|
|
|
} else {
|
|
|
|
const item = {
|
|
|
|
isLeaf: false,
|
|
|
|
title: data[i].text,
|
|
|
|
key: data[i].id,
|
|
|
|
children: data[i].nodes,
|
|
|
|
};
|
|
|
|
data[i] = item;
|
|
|
|
this.generateComment(data[i].children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.nodes = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 新增
|
|
|
|
getAdd() {
|
|
|
|
this.isVisible = true;
|
|
|
|
this.editFlag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 编辑
|
|
|
|
getEdit(data: object) {
|
|
|
|
console.log(data);
|
|
|
|
if (data['imgData'] != null && data['imgData'] !== '') {
|
|
|
|
const logo = String(data['imgData']);
|
|
|
|
const logoArray = [];
|
|
|
|
logoArray.push(
|
|
|
|
{
|
|
|
|
uid: 1,
|
|
|
|
name: logo,
|
|
|
|
status: 'done',
|
|
|
|
url: environment.imageUrl + logo
|
|
|
|
});
|
|
|
|
this.imgFile = logoArray;
|
|
|
|
}
|
|
|
|
this.id = data['id'];
|
|
|
|
this.validateForm.patchValue(data);
|
|
|
|
this.editFlag = true;
|
|
|
|
this.isVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 提交内容
|
|
|
|
handleOk() {
|
|
|
|
// tslint:disable-next-line:forin
|
|
|
|
for (const i in this.validateForm.controls) {
|
|
|
|
this.validateForm.controls[i].markAsDirty();
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity();
|
|
|
|
if (this.validateForm.controls[i].errors != null) {
|
|
|
|
this.message.error('必填项不能为空');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.imgFile.length !== 0) {
|
|
|
|
if (this.imgFile[0]['response'] != null) {
|
|
|
|
this.validateForm.value.imgData = this.imgFile[0]['response']['return_data'][0];
|
|
|
|
} else {
|
|
|
|
this.validateForm.value.imgData = this.imgFile[0].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.editFlag) {
|
|
|
|
this.validateForm.value.id = this.id;
|
|
|
|
this.cms.updateCmsContent(this.validateForm.value , data => {
|
|
|
|
if (data['return_code'] === '000000') {
|
|
|
|
this.isVisible = false;
|
|
|
|
this.getRequest(false, this.searchForm.value);
|
|
|
|
this.message.success('修改成功');
|
|
|
|
} else {
|
|
|
|
this.message.create('error', '修改失败');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.cms.insertCmsContent(this.validateForm.value , data => {
|
|
|
|
if (data['return_code'] === '000000') {
|
|
|
|
this.isVisible = false;
|
|
|
|
this.getRequest(false, this.searchForm.value);
|
|
|
|
this.message.success('新增成功');
|
|
|
|
} else {
|
|
|
|
this.message.create('error', '修改失败');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 图片查看
|
|
|
|
handlePreview = async (file: NzUploadFile) => {
|
|
|
|
if (!file.url && !file.preview) {
|
|
|
|
// tslint:disable-next-line:no-non-null-assertion
|
|
|
|
file.preview = await getBase64(file.originFileObj!);
|
|
|
|
}
|
|
|
|
this.previewImage = file.url || file.preview;
|
|
|
|
this.previewVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteConfirmDelete(id: number): void {
|
|
|
|
this.common.showConfirm('是否确定删除!' , dataR => {
|
|
|
|
if (dataR) {
|
|
|
|
this.cms.deleteById(id, data => {
|
|
|
|
if (data['return_code'] === '000000') {
|
|
|
|
this.getRequest(true, this.searchForm.value);
|
|
|
|
this.message.success(data['return_data']);
|
|
|
|
} else {
|
|
|
|
this.message.error(data['return_msg']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public getForbiddenUser(id, status: any): void {
|
|
|
|
const message = (status === 2 ? '是否下架当前内容' : '是否上架当前内容');
|
|
|
|
const s = status === 2 ? 1 : 2;
|
|
|
|
this.common.showConfirm(message, data => {
|
|
|
|
if (data) {
|
|
|
|
this.cms.updateContentStatus(id, s , dataUser => {
|
|
|
|
if (dataUser['return_code'] === '000000') {
|
|
|
|
this.message.success(dataUser['return_data']);
|
|
|
|
} else {
|
|
|
|
this.message.error(dataUser['return_msg']);
|
|
|
|
}
|
|
|
|
this.getRequest(false , this.searchForm.value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|