feat: 新增管理端demo代码
feat: 补充遗漏的文件 fix: 移除license
This commit is contained in:
120
magic-admin/server/src/controller/act.ts
Normal file
120
magic-admin/server/src/controller/act.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making MagicEditor available.
|
||||
*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// 处理活动请求
|
||||
import Koa from 'koa';
|
||||
|
||||
import ActService, { ActInfoDetail, ActListQuery, CopyInfo } from '@src/service/act';
|
||||
|
||||
class ActController {
|
||||
private service: ActService = new ActService();
|
||||
|
||||
// 获取活动列表
|
||||
getList = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
const query: ActListQuery = JSON.parse(ctx.request.body.data);
|
||||
const [actList, count] = await Promise.all([this.service.getActList(query), this.service.getCount(query)]);
|
||||
ctx.body = {
|
||||
data: actList,
|
||||
total: count,
|
||||
fetch: true,
|
||||
errorMsg: '',
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.logger.error(e);
|
||||
ctx.body = {
|
||||
data: [],
|
||||
total: 0,
|
||||
fetch: false,
|
||||
errorMsg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 新建活动
|
||||
create = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
const actInfo: ActInfoDetail = JSON.parse(ctx.request.body.data);
|
||||
const actId = await this.service.create(actInfo);
|
||||
ctx.body = {
|
||||
ret: 0,
|
||||
msg: '新建活动成功',
|
||||
data: { actId },
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 复制活动
|
||||
copy = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
const copyInfo: CopyInfo = JSON.parse(ctx.request.body.data);
|
||||
await this.service.copy(copyInfo);
|
||||
ctx.body = {
|
||||
ret: 0,
|
||||
msg: '复制成功',
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 根据id查询活动详情
|
||||
getInfo = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
const id = Number(ctx.query.id);
|
||||
const act = await this.service.getActInfo(id);
|
||||
ctx.body = {
|
||||
ret: 0,
|
||||
msg: '获取活动信息成功',
|
||||
data: act,
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 根据页面id删除活动页面
|
||||
removePage = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
const { pageId } = JSON.parse(ctx.request.body.data);
|
||||
await this.service.removePage(pageId);
|
||||
ctx.body = {
|
||||
ret: 0,
|
||||
msg: '删除活动页面成功',
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default new ActController();
|
||||
41
magic-admin/server/src/controller/editor.ts
Normal file
41
magic-admin/server/src/controller/editor.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making MagicEditor available.
|
||||
*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// 处理编辑器请求
|
||||
import Koa from 'koa';
|
||||
|
||||
import EditorService from '@src/service/editor';
|
||||
|
||||
class EditorController {
|
||||
private service: EditorService = new EditorService();
|
||||
|
||||
// 拉取编辑器左侧展示的组件列表
|
||||
getComponentList = async (ctx: Koa.Context) => {
|
||||
ctx.body = {
|
||||
ret: 0,
|
||||
msg: '获取组件列表成功',
|
||||
data: await this.service.getComponentList(),
|
||||
};
|
||||
};
|
||||
// 拉取编辑器右边活动配置的web插件
|
||||
getWebPlugins = async (ctx: Koa.Context) => {
|
||||
ctx.body = await this.service.getWebPlugins();
|
||||
};
|
||||
}
|
||||
|
||||
export default new EditorController();
|
||||
65
magic-admin/server/src/controller/publish.ts
Normal file
65
magic-admin/server/src/controller/publish.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making MagicEditor available.
|
||||
*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// 处理保存发布请求
|
||||
import Koa from 'koa';
|
||||
|
||||
import PublishService from '@src/service/publish';
|
||||
|
||||
class PublishController {
|
||||
private service: PublishService = new PublishService();
|
||||
|
||||
// 保存活动基础信息
|
||||
saveActInfo = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
// data不是真正的json对象,可能包含组件自定义code代码
|
||||
/* eslint-disable-next-line */
|
||||
const { actInfo,rootInfo } = eval(`(${ctx.request.body.data})`);
|
||||
const res = await this.service.saveActInfo({ actInfo, rootInfo });
|
||||
ctx.body = {
|
||||
ret: res.ret,
|
||||
msg: res.msg,
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
// 发布
|
||||
publish = async (ctx: Koa.Context) => {
|
||||
try {
|
||||
// data不是真正的json对象,可能包含组件自定义code代码
|
||||
/* eslint-disable-next-line */
|
||||
const { actId, publishPages,rootInfo } = eval(`(${ctx.request.body.data})`);
|
||||
const operator = ctx.cookies.get('userName');
|
||||
const res = await this.service.publish({ actId, publishPages, rootInfo, operator });
|
||||
ctx.body = {
|
||||
ret: res.ret,
|
||||
msg: res.msg,
|
||||
};
|
||||
} catch (e) {
|
||||
ctx.body = {
|
||||
ret: -1,
|
||||
msg: (e as Error).message,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
export default new PublishController();
|
||||
Reference in New Issue
Block a user