Skip to content

Commit

Permalink
perf: 推送
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaviilee committed May 11, 2024
1 parent 8fd4706 commit 2d5e06b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jquery": "^3.5.1",
"localforage": "^1.7.3",
"lodash": "^4.17.15",
"mitt": "^3.0.1",
"vue": "^2.6.11",
"vue-codemirror": "^4.0.6",
"vue-router": "^3.1.3",
Expand Down
30 changes: 30 additions & 0 deletions src/assets/css/list.less
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,29 @@
font-weight: normal;
.lh(2);
font-weight: 400;

.u-push {
.pa;
.rt(0);
.flex;
align-items: center;
gap: 2px;
}
.u-push__time {
.fz(12px);
color: #999;
border:1px solid #eee;
background-color:@bg-light;
margin-right: 5px;
.r(3px);
padding: 0 5px;

&.is-recent {
color: #48C10F;
border-color: #48C10F;
background-color: #f8fff5;
}
}
}

// 角标
Expand All @@ -222,6 +245,7 @@
.db;
padding-left: 20px;
.pr;
min-height: 64px;
}

// 内容·描述类
Expand Down Expand Up @@ -384,6 +408,12 @@
.u-desc {
.none;
}

.u-post {
.u-push {
.none;
}
}
}
}

Expand Down
29 changes: 28 additions & 1 deletion src/components/list/list_item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<span class="u-marks" v-if="item.mark && item.mark.length">
<i v-for="mark in item.mark" class="u-mark" :key="mark">{{ showMark(mark) }}</i>
</span>

<span class="u-push" v-if="hasPermission">
<time v-if="showPushDate" class="u-push__time" :class="{'is-recent': isRecent()}">{{ pushDate }} 已推送</time>
<el-button class="u-push__btn" size="mini" type="warning" @click="onPush" icon="el-icon-s-promotion">推送</el-button>
</span>
</h2>

<!-- 字段 -->
Expand Down Expand Up @@ -80,6 +85,9 @@ import { __imgPath, __visibleMap } from "@jx3box/jx3box-common/data/jx3box.json"
import { cms as mark_map } from "@jx3box/jx3box-common/data/mark.json";
import { showDate } from "@jx3box/jx3box-common/js/moment.js";
import xfmap from "@jx3box/jx3box-data/data/xf/xf.json";
import User from "@jx3box/jx3box-common/js/user";
import dayjs from "dayjs";
import bus from "@/utils/bus";
export default {
name: "ListItem",
props: ["item", "order"],
Expand All @@ -98,7 +106,17 @@ export default {
},
client: function (){
return this.item?.client || 'std'
}
},
hasPermission() {
return User.hasPermission('push_banner');
},
pushDate({item}) {
const date = item?.log?.push_at
return showDate(new Date(date));
},
showPushDate() {
return Boolean(this.item?.log);
},
},
watch: {},
methods: {
Expand Down Expand Up @@ -137,6 +155,15 @@ export default {
const prefix = this.client == 'std' ? 'www' : 'origin'
return`${prefix}:/${appKey}/` + val;
},
showDate,
// 是否为30天内
isRecent: function () {
const date = this.item?.log?.push_at
return dayjs().diff(dayjs(date), "day") < 30;
},
onPush() {
bus.emit("design-task", this.item);
},
},
created: function () {},
mounted: function () {},
Expand Down
6 changes: 3 additions & 3 deletions src/layout/SingleLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Breadcrumb name="云端宏" slug="macro" root="/macro" :publishEnable="true" :adminEnable="true" :feedbackEnable="true" :crumbEnable="true">
<template #op-prepend>
<!-- <AdminDirectMessage v-if="post && post.ID" :user-id="user_id" :sourceId="String(post.ID)" :sourceType="post.post_type"></AdminDirectMessage> -->
<AdminDrop v-if="isEditor" :post="post" :user-id="user_id" />
<AdminDrop v-if="isTeammate" :post="post" :user-id="user_id" />
</template>
<template #title>
<span>{{ title }}</span>
Expand Down Expand Up @@ -47,8 +47,8 @@ export default {
title() {
return this.post.post_title || document.title;
},
isEditor() {
return User.isEditor()
isTeammate() {
return User.isTeammate();
},
},
components: {
Expand Down
9 changes: 9 additions & 0 deletions src/service/design.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { $cms } from "@jx3box/jx3box-common/js/https";

export const getDesignLog = (params) => {
return $cms().get(`/api/cms/design/task/log`, { params });
};

export const getBannerList = (params) => {
return $cms().get(`/api/cms/news/v2`, { params });
}
5 changes: 5 additions & 0 deletions src/utils/bus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import mitt from "mitt";

const bus = mitt();

export default bus;
30 changes: 28 additions & 2 deletions src/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
</a>
</div>
</el-drawer>

<design-task v-model="showDesignTask" :post="currentPost"></design-task>
</div>
</template>
<script>
Expand All @@ -70,6 +72,10 @@ import recTable from "@/components/list/rec_table.vue";
import CommonHeader from "@/components/common-header.vue";
import { reportNow } from "@jx3box/jx3box-common/js/reporter";
import {getDesignLog} from "@/service/design";
import DesignTask from "@jx3box/jx3box-common-ui/src/bread/DesignTask.vue";
import bus from "@/utils/bus";
import User from "@jx3box/jx3box-common/js/user";
export default {
name: "Index",
props: [],
Expand Down Expand Up @@ -102,6 +108,9 @@ export default {
cn: "简体中文",
tr: "繁體中文",
},
showDesignTask: false,
currentPost: {},
};
},
computed: {
Expand Down Expand Up @@ -170,7 +179,7 @@ export default {
this.loading = true;
return getPosts(query)
.then((res) => {
.then(async (res) => {
if (appendMode) {
this.data = this.data.concat(res.data?.data?.list);
} else {
Expand All @@ -186,6 +195,17 @@ export default {
this.total = res.data?.data?.total;
this.pages = res.data?.data?.pages;
if (User.hasPermission('push_banner') && !this.isPhone) {
const ids = this.data.map(item => item.ID);
const logs = await getDesignLog({ source_type: 'macro', ids: ids.join(',') }).then(res => res.data.data);
this.data = this.data.map(item => {
const log = logs.find(log => log.source_id == item.ID) || null;
this.$set(item, 'log', log);
return item;
});
}
})
.finally(() => {
this.loading = false;
Expand Down Expand Up @@ -268,12 +288,18 @@ export default {
},
},
mounted: function () {},
mounted: function () {
bus.on("design-task", (post) => {
this.currentPost = post;
this.showDesignTask = true;
});
},
components: {
listItem,
recTable,
macro,
CommonHeader,
DesignTask,
},
};
</script>
Expand Down

0 comments on commit 2d5e06b

Please sign in to comment.