manage-notification.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <main :class="['notification', isEdit ? 'overflowHidden' : '']">
  3. <div class="section">
  4. <div class="section-item" v-for="(item, index) in groupList" :key="index">
  5. <div class="userInfo">
  6. <img class="img" :src="item.avatar" />
  7. <div class="username">
  8. <div class="users">
  9. <span class="name">{{ item.username }}</span>
  10. </div>
  11. <div class="userTime">
  12. <span class="time">{{ item.updateTime }}</span>
  13. <span class="tag" v-if="item.isTop">置顶</span>
  14. </div>
  15. </div>
  16. <n-popover
  17. v-if="isAuth"
  18. trigger="hover"
  19. ref="popoverRef"
  20. :to="false"
  21. placement="bottom-end"
  22. width="160px"
  23. :show-arrow="false"
  24. class="popoverContainer"
  25. >
  26. <template #trigger>
  27. <span class="iconMore"><i class="iconMorePoint "></i></span>
  28. </template>
  29. <div class="p-list">
  30. <div class="p-item" @click="onOperation(item, 'edit', index)">
  31. 编辑公告
  32. </div>
  33. <div class="p-item" @click="onOperation(item, 'top', index)">
  34. {{item.topFlag ? '取消置顶': '设为置顶'}}
  35. </div>
  36. <div
  37. class="p-item p-red"
  38. @click="onOperation(item, 'delete', index)"
  39. >
  40. 删除公告
  41. </div>
  42. </div>
  43. </n-popover>
  44. </div>
  45. <div class="section-content">
  46. <h2>{{ item.title }}</h2>
  47. <div class="content">
  48. {{ item.content }}
  49. </div>
  50. </div>
  51. </div>
  52. <div class="list-item" v-if="groupList.length < total" @click="onMore">
  53. 查看更多
  54. </div>
  55. </div>
  56. <div class="theEmpty" v-if="!loading && groupList.length <= 0">
  57. <img class="emptyImg" src="../../../assets/nomore.png" />
  58. <p>暂无群公告</p>
  59. <n-button
  60. round
  61. type="info"
  62. class="notificationBtn"
  63. @click="onOperation({}, 'add')"
  64. >发布公告</n-button
  65. >
  66. </div>
  67. <n-tooltip
  68. trigger="hover"
  69. :show-arrow="false"
  70. class="toolsNotifi"
  71. v-if="groupList.length > 0 && !isEdit"
  72. >
  73. <template #trigger>
  74. <div class="iconNotifiAdd" @click="onOperation({}, 'add')"></div>
  75. </template>
  76. 发布公告
  77. </n-tooltip>
  78. <div class="edit-notification" v-if="isEdit">
  79. <div class="input-section">
  80. <div class="input-title">
  81. <i class="iconNotifit1"></i>
  82. <span>公告标题</span>
  83. </div>
  84. <div class="input-content">
  85. <n-input
  86. v-model:value="title"
  87. style="
  88. --n-caret-color: #198cfe;
  89. --n-border-hover: 1px solid #198cfe;
  90. --n-border-focus: 1px solid #198cfe;
  91. --n-loading-color: #198cfe;
  92. --n-box-shadow-focus: 0 0 0 2px rgba(25 140 254, 0.2);
  93. "
  94. type="textarea"
  95. placeholder="请输入公告标题"
  96. show-count
  97. :maxlength="50"
  98. />
  99. </div>
  100. </div>
  101. <div class="input-section">
  102. <div class="input-title">
  103. <i class="iconNotifit2"></i>
  104. <span>公告内容</span>
  105. </div>
  106. <div class="input-content notice-content">
  107. <n-input
  108. v-model:value="input"
  109. style="
  110. --n-caret-color: #198cfe;
  111. --n-border-hover: 1px solid #198cfe;
  112. --n-border-focus: 1px solid #198cfe;
  113. --n-loading-color: #198cfe;
  114. --n-box-shadow-focus: 0 0 0 2px rgba(25 140 254, 0.2);
  115. "
  116. type="textarea"
  117. placeholder="请输入公告内容"
  118. :rows="10"
  119. show-count
  120. :maxlength="200"
  121. />
  122. </div>
  123. </div>
  124. <div class="input-section">
  125. <div class="input-title input-slider">
  126. <span>设为置顶</span>
  127. <Slider :open="isTop" @change="onIsTop" />
  128. </div>
  129. </div>
  130. <div
  131. :class="['submitBtn', !title || !input ? 'disabled' : '']"
  132. @click="onSubmit"
  133. >
  134. 发布
  135. </div>
  136. </div>
  137. </main>
  138. </template>
  139. <script lang="ts">
  140. import {
  141. defineComponent,
  142. watchEffect,
  143. reactive,
  144. toRefs,
  145. onMounted,
  146. ref,
  147. } from "vue";
  148. import {
  149. imGroupNoticePage,
  150. imGroupNoticeSave,
  151. imGroupNoticeUpdate,
  152. imGroupNoticeRemove,
  153. } from "../../../../api";
  154. import Slider from "../../../components/sliderTUI/index.vue";
  155. import TUIMessage from "../../../components/messageTUI/index";
  156. const ManageNotification = defineComponent({
  157. components: {
  158. Slider,
  159. },
  160. props: {
  161. data: {
  162. type: Object,
  163. default: () => ({}),
  164. },
  165. isAuth: {
  166. type: Boolean,
  167. default: false,
  168. },
  169. },
  170. setup(props: any, ctx: any) {
  171. const data: any = reactive({
  172. groupProfile: {},
  173. total: 0,
  174. id: "",
  175. title: "",
  176. input: "",
  177. isTop: true, // 是否置顶
  178. loading: false,
  179. groupList: [],
  180. isEdit: false,
  181. page: 1,
  182. rows: 20,
  183. });
  184. const popoverRef: any = ref();
  185. const getNotification = async () => {
  186. data.loading = true;
  187. try {
  188. // 获取群公告
  189. let res = await imGroupNoticePage({
  190. imGroupId: data.groupProfile.groupID,
  191. page: data.page,
  192. rows: data.rows,
  193. });
  194. const result = res.data.rows || [];
  195. data.total = res.data.total || 0;
  196. if (result.length > 0) {
  197. data.groupList = [...data.groupList, ...result];
  198. }
  199. } catch (e: any) {
  200. //
  201. }
  202. data.loading = false;
  203. };
  204. const onMore = () => {
  205. if(data.loading) return
  206. data.page = data.page + 1;
  207. };
  208. watchEffect(() => {
  209. data.groupProfile = props.data;
  210. // 不使用默认的数据,从我们自己的数据库中选择
  211. // data.input = data.groupProfile.notification;
  212. getNotification();
  213. });
  214. const onOperation = async (item: any, type: string, index?: number) => {
  215. try {
  216. if (type === "edit") {
  217. data.isEdit = true;
  218. data.title = item.title;
  219. data.input = item.content;
  220. data.isTop = item.isTop;
  221. data.id = item.id;
  222. } else if (type === "top") {
  223. await imGroupNoticeUpdate({
  224. imGroupId: data.groupProfile.groupID,
  225. isTop: true,
  226. id: item.id,
  227. });
  228. data.page = 1;
  229. data.groupList = [];
  230. TUIMessage({
  231. message: item.topFlag ? '取消置顶成功' : '设为置顶成功',
  232. isH5: false,
  233. type: "success",
  234. });
  235. } else if (type === "delete") {
  236. await imGroupNoticeRemove({
  237. id: item.id,
  238. });
  239. data.page = 1;
  240. data.groupList = [];
  241. TUIMessage({
  242. message: '删除成功',
  243. isH5: false,
  244. type: "success",
  245. });
  246. getNotification();
  247. } else if (type === "add") {
  248. data.isEdit = true;
  249. data.title = "";
  250. data.input = "";
  251. data.isTop = true;
  252. data.id = "";
  253. ctx.emit("changeStatus", "add");
  254. }
  255. } catch(e) {
  256. //
  257. TUIMessage({
  258. message: e.message,
  259. isH5: false,
  260. type: "error",
  261. });
  262. }
  263. popoverRef.value[index]?.setShow(false);
  264. };
  265. const onSubmit = async () => {
  266. if (!data.title || !data.input) {
  267. return;
  268. }
  269. try {
  270. //
  271. if (data.id) {
  272. await imGroupNoticeUpdate({
  273. imGroupId: data.groupProfile.groupID,
  274. isTop: data.isTop,
  275. title: data.title,
  276. content: data.input,
  277. id: data.id,
  278. });
  279. } else {
  280. await imGroupNoticeSave({
  281. imGroupId: data.groupProfile.groupID,
  282. title: data.title,
  283. content: data.input,
  284. isTop: data.isTop,
  285. });
  286. }
  287. TUIMessage({
  288. message: '发布成功',
  289. isH5: false,
  290. type: "success",
  291. });
  292. data.isEdit = false;
  293. ctx.emit("changeStatus", "submit");
  294. data.page = 1;
  295. data.groupList = [];
  296. getNotification();
  297. } catch(e) {
  298. //
  299. TUIMessage({
  300. message: e.message,
  301. isH5: false,
  302. type: "error",
  303. });
  304. }
  305. };
  306. const onIsTop = (val: any) => {
  307. data.isTop = val
  308. }
  309. const onCloseEdit = () => {
  310. data.isEdit = false;
  311. };
  312. ctx.expose({
  313. onCloseEdit,
  314. });
  315. return {
  316. ...toRefs(data),
  317. popoverRef,
  318. onMore,
  319. onIsTop,
  320. // updateProfile,
  321. onOperation,
  322. onSubmit,
  323. };
  324. },
  325. });
  326. export default ManageNotification;
  327. </script>
  328. <style lang="scss" scoped>
  329. @import url("../../../styles/common.scss");
  330. @import url("../../../styles/icon.scss");
  331. .notification {
  332. position: relative;
  333. flex: 1;
  334. background: #ffffff;
  335. overflow-y: auto;
  336. overflow-x: hidden;
  337. height: 100%;
  338. // padding: 20px;
  339. display: flex;
  340. flex-direction: column;
  341. background: #f8f9fc;
  342. &.overflowHidden {
  343. overflow: hidden;
  344. }
  345. }
  346. .list-item {
  347. padding: 13px;
  348. align-items: center;
  349. font-size: 14px;
  350. overflow: hidden;
  351. text-align: center;
  352. cursor: pointer;
  353. }
  354. .section-item {
  355. background: #fff;
  356. padding: 20px;
  357. margin-bottom: 8px;
  358. .userInfo {
  359. position: relative;
  360. display: flex;
  361. align-items: center;
  362. border-bottom: 1px solid #f2f2f2;
  363. padding-bottom: 16px;
  364. margin-bottom: 16px;
  365. .img {
  366. width: 45px;
  367. height: 45px;
  368. border-radius: 6px;
  369. margin-right: 10px;
  370. }
  371. .iconMore {
  372. width: 25px;
  373. height: 25px;
  374. position: absolute;
  375. right: 0;
  376. top: 5px;
  377. cursor: pointer;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. .iconMorePoint {
  382. display: inline-block;
  383. width: 23px;
  384. height: 17px;
  385. }
  386. &:hover {
  387. background: #f2f2f2;
  388. border-radius: 4px;
  389. }
  390. }
  391. }
  392. .users {
  393. display: flex;
  394. align-items: center;
  395. .name {
  396. font-weight: 600;
  397. font-size: 16px;
  398. color: #333333;
  399. line-height: 22px;
  400. }
  401. .tag {
  402. margin-left: 5px;
  403. font-weight: 400;
  404. font-size: 12px;
  405. line-height: 17px;
  406. color: #2089ff;
  407. background: #e8f4ff;
  408. border-radius: 3px;
  409. border: 1px solid rgba(25, 140, 254, 0.5);
  410. padding: 0 4px;
  411. }
  412. }
  413. .userTime {
  414. .time {
  415. font-size: 13px;
  416. color: #777777;
  417. line-height: 18px;
  418. }
  419. .tag {
  420. font-size: 12px;
  421. color: #f44541;
  422. line-height: 17px;
  423. border-radius: 10px;
  424. border: 1px solid #f44541;
  425. padding: 0 8px;
  426. border-radius: 20px;
  427. margin-left: 6px;
  428. }
  429. }
  430. .section-content {
  431. h2 {
  432. font-weight: 600;
  433. font-size: 14px;
  434. color: #333333;
  435. line-height: 24px;
  436. word-wrap: break-word;
  437. word-break: break-all;
  438. }
  439. .content {
  440. font-size: 14px;
  441. color: #777777;
  442. line-height: 24px;
  443. word-wrap: break-word;
  444. word-break: break-all;
  445. }
  446. }
  447. }
  448. .iconNotifiAdd {
  449. position: fixed;
  450. bottom: 24px;
  451. right: 16px;
  452. width: 58px;
  453. height: 58px;
  454. }
  455. .theEmpty {
  456. width: 100%;
  457. display: flex;
  458. justify-content: center;
  459. align-items: center;
  460. flex-direction: column;
  461. flex: 1;
  462. background: #fff;
  463. padding-bottom: 40px;
  464. .emptyImg {
  465. width: 210px;
  466. height: 210px;
  467. }
  468. p {
  469. font-size: 14px;
  470. color: #aaaaaa;
  471. line-height: 22px;
  472. }
  473. }
  474. .notificationBtn {
  475. margin-top: 10px;
  476. }
  477. .edit-notification {
  478. position: fixed;
  479. width: 360px;
  480. height: calc(100% - 109Px);
  481. top: 109Px;
  482. right: 0;
  483. z-index: 9;
  484. background: #fff;
  485. padding: 0 20px;
  486. overflow-x: hidden;
  487. overflow-y: auto;
  488. .input-section {
  489. padding-top: 20px;
  490. }
  491. .input-title {
  492. display: flex;
  493. align-items: center;
  494. font-size: 14px;
  495. color: #333333;
  496. font-weight: 600;
  497. line-height: 22px;
  498. padding-bottom: 10px;
  499. .iconNotifit1,
  500. .iconNotifit2 {
  501. width: 22px;
  502. height: 22px;
  503. margin-right: 6px;
  504. flex-shrink: 0;
  505. }
  506. span {
  507. line-height: 1;
  508. padding-bottom: 2px;
  509. }
  510. }
  511. .input-slider {
  512. display: flex;
  513. align-items: center;
  514. justify-content: space-between;
  515. span {
  516. padding-bottom: 0;
  517. }
  518. .slider-box {
  519. cursor: pointer;
  520. }
  521. }
  522. .n-input {
  523. border-radius: 6px !important;
  524. .n-input-wrapper {
  525. padding-bottom: 18px !important;
  526. }
  527. }
  528. }
  529. .submitBtn {
  530. margin-top: 30px;
  531. margin-bottom: 20px;
  532. background: #198cfe;
  533. border-radius: 8px;
  534. font-weight: 600;
  535. font-size: 18px;
  536. color: #ffffff;
  537. line-height: 47px;
  538. text-align: center;
  539. cursor: pointer;
  540. &.disabled {
  541. opacity: 0.7;
  542. cursor: not-allowed;
  543. }
  544. }
  545. </style>
  546. <style lang="scss">
  547. .notice-content {
  548. .n-input .n-input-wrapper {
  549. padding-bottom: 18px !important;
  550. }
  551. }
  552. .popoverContainer {
  553. background: #ffffff;
  554. box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.08) !important;
  555. border-radius: 12px !important;
  556. padding: 8px !important;
  557. margin-top: 8px !important;
  558. .p-item {
  559. margin-bottom: 6px;
  560. font-size: 14px;
  561. color: #131415;
  562. border-radius: 8px;
  563. padding: 8px 0;
  564. text-align: center;
  565. cursor: pointer;
  566. &:hover {
  567. background: #f3f3f5;
  568. }
  569. &:last-child {
  570. margin-bottom: 0;
  571. }
  572. &.p-red {
  573. color: #f44541;
  574. }
  575. }
  576. }
  577. .toolsNotifi .n-popover__content {
  578. color: #fff !important;
  579. }
  580. .notificationBtn .n-button__content {
  581. color: #ffffff;
  582. }
  583. </style>