123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- <template>
- <main class="notification">
- <div class="section">
- <div class="section-item" v-for="(item, index) in groupList" :key="index">
- <div class="userInfo">
- <img class="img" :src="item.avatar" />
- <div class="username">
- <div class="users">
- <span class="name">{{ item.username }}</span>
- <span class="tag">{{ formatJobType(item.clientType) }}</span>
- </div>
- <div class="userTime">
- <span class="time">{{ item.createTime }}</span>
- <span class="tag" v-if="item.topFlag">置顶</span>
- </div>
- </div>
- <n-popover
- v-if="isAuth"
- trigger="click"
- ref="popoverRef"
- :to="false"
- placement="bottom-end"
- width="160px"
- :show-arrow="false"
- class="popoverContainer"
- >
- <template #trigger>
- <i class="iconMorePoint iconMore"></i>
- </template>
- <div class="p-list">
- <div class="p-item" @click="onOperation(item, 'edit', index)">
- 编辑公告
- </div>
- <div class="p-item" @click="onOperation(item, 'top', index)">
- 设为置顶
- </div>
- <div
- class="p-item p-red"
- @click="onOperation(item, 'delete', index)"
- >
- 删除公告
- </div>
- </div>
- </n-popover>
- </div>
- <div class="section-content">
- <h2>{{ item.title }}</h2>
- <div class="content">
- {{ item.content }}
- </div>
- </div>
- </div>
- <div class="list-item" v-if="groupList.length < total" @click="onMore">
- 查看更多
- </div>
- </div>
- <div class="theEmpty" v-if="!loading && groupList.length <= 0">
- <img class="emptyImg" src="../../../assets/nomore.png" />
- <p>暂无群公告</p>
- <n-button
- round
- type="info"
- class="notificationBtn"
- @click="onOperation({}, 'add')"
- >发布公告</n-button
- >
- </div>
- <n-tooltip
- trigger="hover"
- :show-arrow="false"
- class="toolsNotifi"
- v-if="groupList.length > 0 && !isEdit"
- >
- <template #trigger>
- <div class="iconNotifiAdd" @click="onOperation({}, 'add')"></div>
- </template>
- 发布公告
- </n-tooltip>
- <div class="edit-notification" v-if="isEdit">
- <div class="input-section">
- <div class="input-title">
- <i class="iconNotifit1"></i>
- <span>公告标题</span>
- </div>
- <div class="input-content">
- <n-input
- v-model:value="title"
- style="
- --n-caret-color: #198cfe;
- --n-border-hover: 1px solid #198cfe;
- --n-border-focus: 1px solid #198cfe;
- --n-loading-color: #198cfe;
- --n-box-shadow-focus: 0 0 0 2px rgba(25 140 254, 0.2);
- "
- type="textarea"
- placeholder="请输入公告标题"
- show-count
- :maxlength="50"
- />
- </div>
- </div>
- <div class="input-section">
- <div class="input-title">
- <i class="iconNotifit2"></i>
- <span>公告内容</span>
- </div>
- <div class="input-content notice-content">
- <n-input
- v-model:value="input"
- style="
- --n-caret-color: #198cfe;
- --n-border-hover: 1px solid #198cfe;
- --n-border-focus: 1px solid #198cfe;
- --n-loading-color: #198cfe;
- --n-box-shadow-focus: 0 0 0 2px rgba(25 140 254, 0.2);
- "
- type="textarea"
- placeholder="请输入公告内容"
- :rows="10"
- show-count
- :maxlength="200"
- />
- </div>
- </div>
- <div class="input-section">
- <div class="input-title input-slider">
- <span>设置为置顶</span>
- <Slider :open="topFlag" />
- </div>
- <!-- :open="conversation.groupProfile.muteAllMembers" @change="setAllMuteTime" -->
- </div>
- <div
- :class="['submitBtn', !title || !input ? 'disabled' : '']"
- @click="onSubmit"
- >
- 发布
- </div>
- </div>
- </main>
- </template>
- <script lang="ts">
- import {
- defineComponent,
- watchEffect,
- reactive,
- toRefs,
- onMounted,
- ref,
- } from "vue";
- import {
- imGroupNoticePage,
- imGroupNoticeSave,
- imGroupNoticeUpdate,
- imGroupNoticeRemove,
- } from "../../../../api";
- import Slider from "../../../components/sliderTUI/index.vue";
- const ManageNotification = defineComponent({
- components: {
- Slider,
- },
- props: {
- data: {
- type: Object,
- default: () => ({}),
- },
- isAuth: {
- type: Boolean,
- default: false,
- },
- },
- setup(props: any, ctx: any) {
- const data: any = reactive({
- groupProfile: {},
- total: 0,
- id: "",
- title: "",
- input: "",
- topFlag: true, // 是否置顶
- loading: false,
- groupList: [],
- isEdit: false,
- page: 1,
- rows: 20,
- });
- const popoverRef: any = ref();
- const getNotification = async () => {
- data.loading = true;
- try {
- // 获取群公告
- let res = await imGroupNoticePage({
- groupId: data.groupProfile.groupID,
- page: data.page,
- rows: data.rows,
- });
- const result = res.data.rows || [];
- data.total = res.data.total || 0;
- if (result.length > 0) {
- data.groupList = [...data.groupList, ...result];
- }
- } catch (e: any) {
- //
- }
- data.loading = false;
- };
- const onMore = () => {
- data.page = data.page + 1;
- getNotification();
- };
- watchEffect(() => {
- data.groupProfile = props.data;
- // 不使用默认的数据,从我们自己的数据库中选择
- // data.input = data.groupProfile.notification;
- getNotification();
- });
- const formatJobType = (jobType: string) => {
- const template = {
- TEACHER: "音乐老师",
- ADMIN: "管理员",
- HEADMASTER: "校长",
- } as any;
- return template[jobType];
- };
- // 更新群资料
- // const updateProfile = async () => {
- // if (data.title && data.input) {
- // // ctx.emit("update", { key: "notification", value: data.input });
- // // data.groupProfile.notification = data.input;
- // // data.input = "";
- // try {
- // const params = {
- // clientType: "TEACHER",
- // groupId: data.groupProfile.groupID,
- // content: data.input,
- // title: data.title,
- // };
- // if (data.groupList.id) {
- // await imGroupNoticeUpdate({
- // ...params,
- // id: data.groupList.id,
- // });
- // } else {
- // await imGroupNoticeSave(params);
- // }
- // data.groupList.content = data.input;
- // ctx.emit("update", { key: "notification", value: data.title });
- // data.groupProfile.notification = data.title;
- // data.groupList.content = data.input;
- // data.groupList.title = data.title;
- // data.input = "";
- // getNotification();
- // } catch {
- // //
- // }
- // }
- // data.isEdit = !data.isEdit;
- // };
- const onOperation = async (item: any, type: string, index?: number) => {
- try {
- if (type === "edit") {
- ctx.emit("changeStatus", "edit");
- data.isEdit = true;
- data.title = item.title;
- data.input = item.content;
- data.topFlag = item.topFlag;
- data.id = item.id;
- } else if (type === "top") {
- await imGroupNoticeUpdate({
- groupId: data.groupProfile.groupID,
- topFlag: true,
- id: item.id,
- });
- data.page = 1;
- data.groupList = [];
- getNotification();
- } else if (type === "delete") {
- await imGroupNoticeRemove({
- id: item.id,
- });
- data.page = 1;
- data.groupList = [];
- getNotification();
- } else if (type === "add") {
- data.isEdit = true;
- data.title = "";
- data.input = "";
- data.topFlag = "";
- data.id = "";
- ctx.emit("changeStatus", "add");
- }
- } catch (e) {
- //
- }
- popoverRef.value[index]?.setShow(false);
- };
- const onSubmit = async () => {
- if (!data.title || !data.input) {
- return;
- }
- try {
- //
- if (data.id) {
- await imGroupNoticeUpdate({
- groupId: data.groupProfile.groupID,
- topFlag: data.topFlag,
- title: data.title,
- content: data.input,
- id: data.id,
- });
- } else {
- await imGroupNoticeSave({
- groupId: data.groupProfile.groupID,
- topFlag: data.topFlag,
- title: data.title,
- content: data.input,
- });
- }
- data.isEdit = false;
- ctx.emit("changeStatus", "submit");
- data.page = 1;
- data.groupList = [];
- getNotification();
- } catch {
- //
- }
- };
- const onCloseEdit = () => {
- data.isEdit = false;
- };
- ctx.expose({
- onCloseEdit,
- });
- return {
- ...toRefs(data),
- popoverRef,
- formatJobType,
- onMore,
- // updateProfile,
- onOperation,
- onSubmit,
- };
- },
- });
- export default ManageNotification;
- </script>
- <style lang="scss" scoped>
- @import url("../../../styles/common.scss");
- @import url("../../../styles/icon.scss");
- .notification {
- position: relative;
- flex: 1;
- // padding: 20px;
- display: flex;
- flex-direction: column;
- background: #f8f9fc;
- }
- .list-item {
- padding: 13px;
- align-items: center;
- font-size: 14px;
- overflow: hidden;
- text-align: center;
- cursor: pointer;
- }
- .section-item {
- background: #fff;
- padding: 20px;
- margin-bottom: 8px;
- .userInfo {
- position: relative;
- display: flex;
- align-items: center;
- border-bottom: 1px solid #f2f2f2;
- padding-bottom: 16px;
- margin-bottom: 16px;
- .img {
- width: 45px;
- height: 45px;
- border-radius: 6px;
- margin-right: 10px;
- }
- .iconMore {
- width: 23px;
- height: 17px;
- position: absolute;
- right: 0;
- top: 5px;
- cursor: pointer;
- }
- }
- .users {
- display: flex;
- align-items: center;
- .name {
- font-weight: 600;
- font-size: 16px;
- color: #333333;
- line-height: 22px;
- }
- .tag {
- margin-left: 5px;
- font-weight: 400;
- font-size: 12px;
- line-height: 17px;
- color: #2089ff;
- background: #e8f4ff;
- border-radius: 3px;
- border: 1px solid rgba(25, 140, 254, 0.5);
- padding: 0 4px;
- }
- }
- .userTime {
- .time {
- font-size: 13px;
- color: #777777;
- line-height: 18px;
- }
- .tag {
- font-size: 12px;
- color: #f44541;
- line-height: 17px;
- border-radius: 10px;
- border: 1px solid #f44541;
- padding: 0 8px;
- border-radius: 20px;
- margin-left: 6px;
- }
- }
- .section-content {
- h2 {
- font-weight: 600;
- font-size: 16px;
- color: #333333;
- line-height: 24px;
- }
- .content {
- font-size: 16px;
- color: #777777;
- line-height: 24px;
- word-break: break-all;
- }
- }
- }
- .iconNotifiAdd {
- position: absolute;
- bottom: 24px;
- right: 16px;
- width: 58px;
- height: 58px;
- }
- .theEmpty {
- width: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- flex: 1;
- background: #fff;
- padding-bottom: 40px;
- .emptyImg {
- width: 210px;
- height: 210px;
- }
- p {
- font-size: 16px;
- color: #aaaaaa;
- line-height: 22px;
- }
- }
- .notificationBtn {
- margin-top: 10px;
- }
- .edit-notification {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 9;
- background: #fff;
- padding: 0 20px;
- .input-section {
- padding-top: 20px;
- }
- .input-title {
- display: flex;
- align-items: center;
- font-size: 16px;
- color: #333333;
- line-height: 22px;
- padding-bottom: 10px;
- .iconNotifit1,
- .iconNotifit2 {
- width: 22px;
- height: 22px;
- margin-right: 6px;
- flex-shrink: 0;
- }
- span {
- line-height: 1;
- padding-bottom: 4px;
- }
- }
- .input-slider {
- display: flex;
- align-items: center;
- justify-content: space-between;
- span {
- padding-bottom: 0;
- }
- .slider-box {
- cursor: pointer;
- }
- }
- .n-input {
- border-radius: 6px !important;
- .n-input-wrapper {
- padding-bottom: 18px !important;
- }
- }
- }
- .submitBtn {
- margin-top: 30px;
- background: #198cfe;
- border-radius: 8px;
- font-weight: 600;
- font-size: 18px;
- color: #ffffff;
- line-height: 47px;
- text-align: center;
- cursor: pointer;
- &.disabled {
- opacity: 0.7;
- cursor: not-allowed;
- }
- }
- </style>
- <style lang="scss">
- .notice-content {
- .n-input .n-input-wrapper {
- padding-bottom: 18px !important;
- }
- }
- .popoverContainer {
- background: #ffffff;
- box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.08) !important;
- border-radius: 12px !important;
- padding: 8px !important;
- margin-top: 8px !important;
- .p-item {
- margin-bottom: 8px;
- font-size: 16px;
- color: #131415;
- border-radius: 8px;
- padding: 12px 0;
- text-align: center;
- cursor: pointer;
- &:hover {
- background: #f3f3f5;
- }
- &:last-child {
- margin-bottom: 0;
- }
- &.p-red {
- color: #f44541;
- }
- }
- }
- .toolsNotifi .n-popover__content {
- color: #fff !important;
- }
- .notificationBtn .n-button__content {
- color: #ffffff;
- }
- </style>
|