將isTop从属性改为了状态
This commit is contained in:
parent
a9d5edaf8a
commit
2d22e67ff3
|
|
@ -1,2 +1,3 @@
|
||||||
{
|
{
|
||||||
|
"github.copilot.editor.enableAutoCompletions": true
|
||||||
}
|
}
|
||||||
|
|
@ -14,24 +14,7 @@ const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
|
||||||
$or: [{ iState: 'unpublished' }, { iState: 'withdrawn' }],
|
$or: [{ iState: 'unpublished' }, { iState: 'withdrawn' }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// settop的时候只能是isTop为false的
|
|
||||||
{
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'setTop',
|
|
||||||
type: 'row',
|
|
||||||
filter: {
|
|
||||||
isTop: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// cancelTop的时候只能是isTop为true的
|
|
||||||
{
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'cancelTop',
|
|
||||||
type: 'row',
|
|
||||||
filter: {
|
|
||||||
isTop: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// 在删除essay的时候,同步删除extraFile和essayLabels还有log
|
// 在删除essay的时候,同步删除extraFile和essayLabels还有log
|
||||||
// 注意,在checker中为非异步环境,这点与trigger不同
|
// 注意,在checker中为非异步环境,这点与trigger不同
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export default OakComponent({
|
||||||
// 先按置顶排序
|
// 先按置顶排序
|
||||||
sorter: {
|
sorter: {
|
||||||
$attr: {
|
$attr: {
|
||||||
isTop: 1,
|
topState: 1,
|
||||||
},
|
},
|
||||||
$direction: 'desc',
|
$direction: 'desc',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ const EssayItem = (props: {
|
||||||
</div>
|
</div>
|
||||||
<div className={Styles.body}>
|
<div className={Styles.body}>
|
||||||
<div className={Styles.title}>
|
<div className={Styles.title}>
|
||||||
{item.isTop && (
|
{item.topState && (
|
||||||
<div className={Styles.top}>
|
<div className={Styles.top}>
|
||||||
{t('common::top')}
|
{t('common::top')}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ const i18ns: I18n[] = [
|
||||||
position: "src/pages/console/comment/list",
|
position: "src/pages/console/comment/list",
|
||||||
data: {
|
data: {
|
||||||
"pageTitle": "评论管理",
|
"pageTitle": "评论管理",
|
||||||
"content": "",
|
"content": "内容",
|
||||||
"creator": "",
|
"creator": "创建者",
|
||||||
"essay": ""
|
"essay": "文章"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -208,6 +208,14 @@ const i18ns: I18n[] = [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "29381bca365eb7ac4abcf1d6dee6b61c",
|
||||||
|
namespace: "new-demo-c-console-likes",
|
||||||
|
language: "zh-CN",
|
||||||
|
module: "new-demo",
|
||||||
|
position: "src/components/console/likes",
|
||||||
|
data: {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "052936d351c8e58f6eb07d0a2e74d806",
|
id: "052936d351c8e58f6eb07d0a2e74d806",
|
||||||
namespace: "new-demo-c-console-menu",
|
namespace: "new-demo-c-console-menu",
|
||||||
|
|
@ -333,7 +341,8 @@ const i18ns: I18n[] = [
|
||||||
"change": "修改",
|
"change": "修改",
|
||||||
"finish": "完成",
|
"finish": "完成",
|
||||||
"creator": "创建人",
|
"creator": "创建人",
|
||||||
"top": "置顶"
|
"top": "置顶",
|
||||||
|
"like": "点赞"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -653,19 +662,25 @@ const i18ns: I18n[] = [
|
||||||
"logs": "修改记录",
|
"logs": "修改记录",
|
||||||
"category": "分类",
|
"category": "分类",
|
||||||
"iState": "状态",
|
"iState": "状态",
|
||||||
"isTop": "是否置顶"
|
"topState": "是否置顶"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"publish": "发布",
|
"publish": "发布",
|
||||||
"withdraw": "撤回",
|
"withdraw": "撤回",
|
||||||
"setTop": "置顶",
|
"setTop": "置顶",
|
||||||
"cancelTop": "取消置顶"
|
"cancelTop": "取消置顶",
|
||||||
|
"like": "点赞",
|
||||||
|
"unlike": "取消点赞"
|
||||||
},
|
},
|
||||||
"v": {
|
"v": {
|
||||||
"iState": {
|
"iState": {
|
||||||
"unpublished": "未发布",
|
"unpublished": "未发布",
|
||||||
"published": "已发布",
|
"published": "已发布",
|
||||||
"withdrawn": "已撤回"
|
"withdrawn": "已撤回"
|
||||||
|
},
|
||||||
|
"topState": {
|
||||||
|
"Top": "已置顶",
|
||||||
|
"unTop": "未置顶"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -784,6 +799,24 @@ const i18ns: I18n[] = [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "25a720a152eb939d9835e630788e7dc1",
|
||||||
|
namespace: "likes",
|
||||||
|
language: "zh-CN",
|
||||||
|
module: "",
|
||||||
|
position: "oak-app-domain/Likes",
|
||||||
|
data: {
|
||||||
|
"name": "点赞",
|
||||||
|
"attr": {
|
||||||
|
"creator": "创建者",
|
||||||
|
"essay": "文章"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"like": "点赞",
|
||||||
|
"unlike": "取消点赞"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "f3c966c0e1deb4ca4c10e10117143849",
|
id: "f3c966c0e1deb4ca4c10e10117143849",
|
||||||
namespace: "livestream",
|
namespace: "livestream",
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,13 @@ export interface Schema extends EntityShape {
|
||||||
images: ExtraFile[];
|
images: ExtraFile[];
|
||||||
logs: Log[];
|
logs: Log[];
|
||||||
category?: Category;
|
category?: Category;
|
||||||
isTop: Boolean;
|
//isTop: Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TopState = 'Top' | 'unTop';
|
||||||
|
|
||||||
|
export type TopAction = 'setTop' | 'cancelTop';
|
||||||
|
|
||||||
export type IState = 'unpublished' | 'published' | 'withdrawn';
|
export type IState = 'unpublished' | 'published' | 'withdrawn';
|
||||||
|
|
||||||
export type IAction = 'publish' | 'withdraw';
|
export type IAction = 'publish' | 'withdraw';
|
||||||
|
|
@ -32,14 +36,19 @@ export const IActionDef: ActionDef<IAction, IState> = {
|
||||||
is: 'unpublished',
|
is: 'unpublished',
|
||||||
};
|
};
|
||||||
|
|
||||||
// 用户行为操作
|
export const TopActionDef: ActionDef<TopAction, TopState> = {
|
||||||
export type CommonAction = 'setTop' | 'cancelTop';
|
stm: {
|
||||||
|
setTop: ['unTop', 'Top'],
|
||||||
|
cancelTop: ['Top', 'unTop']
|
||||||
|
},
|
||||||
|
is: 'unTop',
|
||||||
|
}
|
||||||
|
|
||||||
export type LikeAction =
|
export type LikeAction =
|
||||||
| 'like'
|
| 'like'
|
||||||
| 'unlike';
|
| 'unlike';
|
||||||
|
|
||||||
export type Action = IAction | CommonAction | LikeAction;
|
export type Action = IAction | LikeAction | TopAction;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,6 +58,7 @@ export const entityDesc: EntityDesc<
|
||||||
'',
|
'',
|
||||||
{
|
{
|
||||||
iState: IState;
|
iState: IState;
|
||||||
|
topState: TopState;
|
||||||
}
|
}
|
||||||
> = {
|
> = {
|
||||||
locales: {
|
locales: {
|
||||||
|
|
@ -64,7 +74,7 @@ export const entityDesc: EntityDesc<
|
||||||
logs: '修改记录',
|
logs: '修改记录',
|
||||||
category: '分类',
|
category: '分类',
|
||||||
iState: '状态',
|
iState: '状态',
|
||||||
isTop: '是否置顶',
|
topState: '是否置顶',
|
||||||
},
|
},
|
||||||
action: {
|
action: {
|
||||||
publish: '发布',
|
publish: '发布',
|
||||||
|
|
@ -80,6 +90,10 @@ export const entityDesc: EntityDesc<
|
||||||
published: '已发布',
|
published: '已发布',
|
||||||
withdrawn: '已撤回',
|
withdrawn: '已撤回',
|
||||||
},
|
},
|
||||||
|
topState: {
|
||||||
|
Top: '已置顶',
|
||||||
|
unTop: '未置顶',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -91,6 +105,10 @@ export const entityDesc: EntityDesc<
|
||||||
published: '#87d068',
|
published: '#87d068',
|
||||||
withdrawn: '#2db7f5',
|
withdrawn: '#2db7f5',
|
||||||
},
|
},
|
||||||
|
topState: {
|
||||||
|
Top: '#ff0',
|
||||||
|
unTop: '#ccc',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
indexes: [
|
indexes: [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { essayProjection } from '@project/utils/projection';
|
import { essayProjection } from '@project/utils/projection';
|
||||||
|
import { TopState } from '@project/entities/Essay';
|
||||||
|
|
||||||
export default OakComponent({
|
export default OakComponent({
|
||||||
entity: 'essay',
|
entity: 'essay',
|
||||||
|
|
@ -9,7 +10,7 @@ export default OakComponent({
|
||||||
// 先按置顶排序
|
// 先按置顶排序
|
||||||
sorter: {
|
sorter: {
|
||||||
$attr: {
|
$attr: {
|
||||||
isTop: 1,
|
topState: 1,
|
||||||
},
|
},
|
||||||
$direction: 'desc',
|
$direction: 'desc',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ const EssayList = (
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{row.isTop ? (
|
{row.topState === "Top" ? (
|
||||||
<Tag color='#f50'>{t('essay.isTop')}</Tag>
|
<Tag color='#f50'>{t('essay.isTop')}</Tag>
|
||||||
) : (
|
) : (
|
||||||
<Tag color='#108ee9'>{t('essay.notTop')}</Tag>
|
<Tag color='#108ee9'>{t('essay.notTop')}</Tag>
|
||||||
|
|
@ -245,7 +245,7 @@ const EssayList = (
|
||||||
/>
|
/>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Modal
|
<Modal
|
||||||
title={t('label:selectLabels')}
|
title={t('label.selectLabels')}
|
||||||
open={showSelectLabels}
|
open={showSelectLabels}
|
||||||
onCancel={() => setShowSelectLabels(false)}
|
onCancel={() => setShowSelectLabels(false)}
|
||||||
onOk={() => {
|
onOk={() => {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ const triggers: Trigger<EntityDict, 'essay', BackendRuntimeContext>[] = [
|
||||||
assert(data && !(data instanceof Array));
|
assert(data && !(data instanceof Array));
|
||||||
// 若不存在meta,则初始化一个空对象
|
// 若不存在meta,则初始化一个空对象
|
||||||
data.meta = data.meta || {};
|
data.meta = data.meta || {};
|
||||||
data.isTop = data.isTop || false;
|
|
||||||
assert(data.content, 'content is required');
|
assert(data.content, 'content is required');
|
||||||
if (!data.summary) {
|
if (!data.summary) {
|
||||||
// 自动截取前面100个字符,加上省略号
|
// 自动截取前面100个字符,加上省略号
|
||||||
|
|
@ -26,87 +26,8 @@ const triggers: Trigger<EntityDict, 'essay', BackendRuntimeContext>[] = [
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// action: setTop的时候设置isTop为true
|
|
||||||
{
|
|
||||||
name: '置顶时设置isTop为true',
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'setTop',
|
|
||||||
when: 'before',
|
|
||||||
fn: async ({ operation }, context, option) => {
|
|
||||||
const { id, data } = operation;
|
|
||||||
assert(data && !(data instanceof Array));
|
|
||||||
data.isTop = true;
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// action: cancelTop的时候设置isTop为false
|
|
||||||
{
|
|
||||||
name: '取消置顶时设置isTop为false',
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'cancelTop',
|
|
||||||
when: 'before',
|
|
||||||
fn: async ({ operation }, context, option) => {
|
|
||||||
const { id, data } = operation;
|
|
||||||
assert(data && !(data instanceof Array));
|
|
||||||
data.isTop = false;
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: '点赞',
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'create', // 假设我们有一个 action 名称 `createLike` 表示点赞
|
|
||||||
when: 'after',
|
|
||||||
fn: async ({ operation }, context, option) => {
|
|
||||||
const { data } = operation;
|
|
||||||
assert(data && !Array.isArray(data));
|
|
||||||
|
|
||||||
// 获取当前用户 ID
|
|
||||||
const userId = context.getCurrentUserId();
|
|
||||||
// 初始化 meta 和 likes 列表
|
|
||||||
data.meta = data.meta || {};
|
|
||||||
data.meta.likes = data.meta.likes || [];
|
|
||||||
|
|
||||||
// 检查用户是否已点赞
|
|
||||||
if (!data.meta.likes.includes(userId)) {
|
|
||||||
// 添加用户 ID 到 likes 列表
|
|
||||||
data.meta.likes.push(userId);
|
|
||||||
// 增加点赞计数
|
|
||||||
data.likesCount = (data.likesCount || 0) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: '取消点赞',
|
|
||||||
entity: 'essay',
|
|
||||||
action: 'create', // 假设我们有一个 action 名称 `removeLike` 表示取消点赞
|
|
||||||
when: 'after',
|
|
||||||
fn: async ({ operation }, context, option) => {
|
|
||||||
const { data } = operation;
|
|
||||||
assert(data && !Array.isArray(data));
|
|
||||||
|
|
||||||
// 获取当前用户 ID
|
|
||||||
const userId = context.getCurrentUserId();
|
|
||||||
// 初始化 meta 和 likes 列表
|
|
||||||
data.meta = data.meta || {};
|
|
||||||
data.meta.likes = data.meta.likes || [];
|
|
||||||
|
|
||||||
// 检查用户是否已点赞
|
|
||||||
const index = data.meta.likes.indexOf(userId);
|
|
||||||
if (index !== -1) {
|
|
||||||
// 从 likes 列表中移除用户 ID
|
|
||||||
data.meta.likes.splice(index, 1);
|
|
||||||
// 减少点赞计数
|
|
||||||
data.likesCount = (data.likesCount || 0) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export default triggers;
|
export default triggers;
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ export const essayProjection: EntityDict['essay']['Selection']['data'] = {
|
||||||
name: 1,
|
name: 1,
|
||||||
},
|
},
|
||||||
iState: 1,
|
iState: 1,
|
||||||
isTop: 1,
|
topState: 1,
|
||||||
// 相关labels
|
// 相关labels
|
||||||
essayLabels$essay: {
|
essayLabels$essay: {
|
||||||
$entity: 'essayLabels',
|
$entity: 'essayLabels',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue