manage-notification-detail.vue 13 KB

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