Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(information): 新增校园资讯 #56

Merged
merged 13 commits into from
Aug 12, 2023
15 changes: 13 additions & 2 deletions project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@
"minifyWXSS": true,
"disableUseStrict": false,
"showES6CompileOption": false,
"useCompilerPlugins": false
"useCompilerPlugins": false,
"condition": false
},
"compileType": "miniprogram",
"condition": {}
"condition": {},
"libVersion": "2.25.3",
"srcMiniprogramRoot": "dist/",
"packOptions": {
"ignore": [],
"include": []
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
20 changes: 20 additions & 0 deletions project.private.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "WeJH-Taro",
"setting": {
"compileHotReLoad": true
},
"condition": {
"miniprogram": {
"list": [
{
"name": "",
"pathName": "pages/announcement/index",
"query": "",
"launchMode": "default",
"scene": null
}
]
}
}
}
1 change: 1 addition & 0 deletions src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
"pages/electricity/consumption/index",
"pages/electricity/subscribe/index",
"pages/lostfound/index",
"pages/information/index",
],
darkmode: false,
window: {
Expand Down
30 changes: 30 additions & 0 deletions src/components/FixedQuickView/InformationQuickView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,34 @@ const currentPost = ref<{ type: string; content: string }>({
serviceStore.announcement.announcements.length - 1 || 0
].content.replace(/\\n/g, "\n"),
});

const updateCurrentPost = () => {
const information = serviceStore.information.informationList;
const announcement = serviceStore.announcement.announcements;
const infoTime = new Date(information[information.length - 1].publish_time).getTime();
const announcementTime = new Date(announcement[announcement.length - 1].publishTime).getTime();

if (information.length !== 0) {
if (infoTime > announcementTime) {
currentPost.value = {
type: "information",
content: information[information.length - 1].content.replace(
/\\n/g,
"\n"
),
};
} else {
currentPost.value = {
type: "announcement",
content: announcement[announcement.length - 1].content.replace(
/\\n/g,
"\n"
),
};
}
}
};

updateCurrentPost();

</script>
55 changes: 54 additions & 1 deletion src/pages/announcement/InformationCard/index.module.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
@import "@/style/theme";

.container {
position: relative;
z-index: 0;
}

.title {
font-size: 1.2rem;
word-break: break-word;
font-weight: var(--wjh-font-weight-medium);
justify-content: center;
text-align: center;
padding: 12Px 0;
border-bottom: 1Px solid var(--wjh-color-border);
}

.publisher {
margin-top: 6Px;
text-align: center;
font-size: 0.75rem;
color: var(--wjh-color-week);
}

.content {
white-space: break-spaces;
font-size: 0.875rem;
color: var(--wjh-color-week);
color: var(--wjh-color-text);
line-height: 125%;
margin: 16Px auto;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
text-overflow: ellipsis;
-webkit-line-clamp: 6;
}

.link {
Expand All @@ -23,3 +48,31 @@
font-size: 0.75rem;
color: var(--wjh-color-week);
}

.img_container{
width: 60%;
height: 60%;
display: flex;
justify-content: center;
align-items: center;
margin: 16Px auto;
}

.x{
font-weight: 900;
font-size: xx-large;
width: 50%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.logo_container{
display: flex;
justify-content: center;
align-items: center;
transform: scale(0.25);
height: 40Px;
}

34 changes: 29 additions & 5 deletions src/pages/announcement/InformationCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Information } from "@/types/Information";
import styles from "./index.module.scss";
import { Card } from "@/components";
import store from "@/store";
import dayjs from "dayjs";

const props = defineProps<{
source: Information;
Expand All @@ -14,20 +15,43 @@ const handleClickLink = () => {
Taro.navigateTo({
url: "/pages/webview/index"
});
};

const handleClick = () => {
Taro.navigateTo({
url: "/pages/information/index?informationId=" + props.source.id
});
};

const timeFormat = (time: string) => {
return dayjs(time).format("YYYY年MM月DD日");
};
</script>

<template>
<card :class="styles.container">
<card :class="styles.container" @tap="handleClick">
<view :class="styles.header">
<view :class="styles.title">{{ props.source.content }}</view>
<view :class="styles.title">{{ props.source.title }}</view>
</view>
<view :class="styles.content">{{ props.source.content.replace(/\\n/g, '\n') }}</view>
<view :class="styles.img_container" v-if="props.source.img1">
<image :src="props.source.img1" alt="Card Image" :class="styles.image" mode="aspectFit"></image>
</view>
<view :class="styles.img_container" v-if="props.source.img2">
<image :src="props.source.img2" alt="Card Image" :class="styles.image" mode="aspectFit"></image>
</view>
<view :class="styles.img_container" v-if="props.source.img3">
<image :src="props.source.img3" alt="Card Image" :class="styles.image" mode="aspectFit"></image>
</view>
<view :class="styles.publisher">By: {{ props.source.publisher }}</view>
<view :class="styles.link" @tap="handleClickLink">点击跳转相关规定</view>
<view :class="styles.link" @tap="handleClickLink" v-if="props.source.link">点击跳转相关规定</view>
<template #footer>
<view :class="styles['publish-time']">发布时间: {{ props.source.publish_time }}</view>
<view :class="styles.logo_container">
<image src="https://img.cnpatrickstar.com/5eb88a00-1d66-49af-8c75-ff651a077503.png" alt="logo_fy" :class="styles.logo_fy" mode="aspectFit"></image>
<view :class="styles.x">X</view>
<image src="https://img.cnpatrickstar.com/2633992f-415a-4b6b-b54e-f24adaca7d42.png" alt="logo_jh" :class="styles.logo_jh" mode="aspectFit"></image>
</view>
<view :class="styles.publisher">信息来源: {{ props.source.publisher }}</view>
<view :class="styles['publish-time']">发布时间: {{ timeFormat(props.source.publish_time) }}</view>
</template>
</card>
</template>
1 change: 1 addition & 0 deletions src/pages/announcement/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@
font-size: 0.75rem;
text-align: end;
}

}
74 changes: 74 additions & 0 deletions src/pages/information/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@import "@/style/theme.scss";

.container {
position: relative;
z-index: 0;
}

.title {
font-size: 1.35rem;
word-break: break-word;
font-weight: var(--wjh-font-weight-medium);
justify-content: center;
text-align: center;
padding: 12Px 0;
border-bottom: 1Px solid var(--wjh-color-border);
}

.publisher {
text-align: center;
font-size: 0.85rem;
color: var(--wjh-color-week);
}

.content {
white-space: break-spaces;
font-size: 1rem;
color: var(--wjh-color-week);
color: var(--wjh-color-text);
line-height: 125%;
margin: 16Px auto;
display: -webkit-box;
-webkit-box-orient: vertical;
}

.link {
padding-top: 16Px;
margin-top: 16Px;
font-size: .9rem;
text-align: center;
color: var(--wjh-color-green);
}

.publish-time {
text-align: center;
font-size: 0.85rem;
color: var(--wjh-color-week);
}

.img_container {
width: 60%;
height: 60%;
display: flex;
justify-content: center;
align-items: center;
margin: 16Px auto;
}

.x {
font-weight: 900;
font-size: xx-large;
width: 50%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.logo_container {
display: flex;
justify-content: center;
align-items: center;
transform: scale(0.25);
height: 40Px;
}
57 changes: 57 additions & 0 deletions src/pages/information/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<view class="background">
<title-bar title="资讯" back-button />
<scroll-view :scrollY="true">
<card class="container">
<view class="header">
<view class="title">{{ information.title }}</view>
</view>
<view class="content">{{ information.content.replace(/\\n/g, '\n') }}</view>
<view class="img_container" v-if="information.img1">
<image :src="information.img1" alt="Card Image" class="image" mode="aspectFit"></image>
</view>
<view class="img_container" v-if="information.img2">
<image :src="information.img2" alt="Card Image" class="image" mode="aspectFit"></image>
</view>
<view class="img_container" v-if="information.img3">
<image :src="information.img3" alt="Card Image" class="image" mode="aspectFit"></image>
</view>
<view class="link" v-if="information.link">点击跳转相关规定</view>
<template #footer>
<view class="logo_container">
<image src="https://img.cnpatrickstar.com/5eb88a00-1d66-49af-8c75-ff651a077503.png" alt="logo_fy" class="logo_fy" mode="aspectFit"></image>
<view class="x">X</view>
<image src="https://img.cnpatrickstar.com/2633992f-415a-4b6b-b54e-f24adaca7d42.png" alt="logo_jh" class="logo_jh" mode="aspectFit"></image>
</view>
<view class="publisher">信息来源: {{ information.publisher }}</view>
<view class="publish-time">发布时间: {{ timeFormat(information.publish_time) }}</view>
</template>
</card>
</scroll-view>
</view>
</template>

<script setup lang="ts">
import { Card, TitleBar } from "@/components";
import { serviceStore } from "@/store";
import { computed } from "vue";
import Taro from "@tarojs/taro";
import dayjs from "dayjs";
import "./index.scss";

const instance = Taro.getCurrentInstance();

const informationList = computed(() => {
return [...serviceStore.information.informationList].reverse();
});

const { informationId } = instance.router?.params as { informationId?: number };

const information = informationList.value.find((information) => information.id == informationId);
Tong030905 marked this conversation as resolved.
Show resolved Hide resolved

const timeFormat = (time: string) => {
return dayjs(time).format("YYYY年MM月DD日");
};

</script>

1 change: 1 addition & 0 deletions src/services/api/apiList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const api = {
},
applist: "/api/applist",
info: "/api/info",
information: "/api/information",
announcement: "/api/announcement"
};

Expand Down
6 changes: 6 additions & 0 deletions src/services/services/systemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { api } from "../api/apiList";
import { updateDateState } from "../utils/updateDateState";
import { AppListItem } from "@/types/AppList";
import { Announcement } from "@/types/Announcement";
import { Information } from "@/types/Information";

// comment: 这里的所有请求无需 session
export default class SystemService {
Expand All @@ -18,6 +19,11 @@ export default class SystemService {
);
}

// comment: 校园资讯
static async getInformation(): Promise<Information> {
return updateDateState(api.information, null, "setInformation", null);
}

// comment: 首页应用列表
static async getAppList(): Promise<AppListItem[]> {
// comment: 缓存 applist
Expand Down
1 change: 0 additions & 1 deletion src/store/service/information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface InformationStoreType {
export const InformationStore = {
state: () => ({
informationList: [],
updateCounter: 0
}),
mutations: {
setInformationList(
Expand Down
Loading