manage-notification.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <main v-if="!isUniFrameWork" class="notification">
  3. <textarea
  4. v-if="isEdit"
  5. v-model="input"
  6. class="textarea"
  7. @keyup.enter="updateProfile"
  8. />
  9. <section v-else>
  10. <p v-if="!groupProfile.notification">
  11. {{ TUITranslateService.t(`TUIGroup.暂无公告`) }}
  12. </p>
  13. <article v-else>
  14. {{ groupProfile.notification }}
  15. </article>
  16. </section>
  17. <footer v-if="isAuthorNotification">
  18. <button v-if="isEdit" class="btn" @click="updateProfile">
  19. {{ TUITranslateService.t(`TUIGroup.发布`) }}
  20. </button>
  21. <button v-else class="btn" @click="isEdit = !isEdit">
  22. {{ TUITranslateService.t(`TUIGroup.编辑`) }}
  23. </button>
  24. </footer>
  25. </main>
  26. <div v-else class="edit-h5">
  27. <main class="edit-h5-main">
  28. <header class="edit-h5-header">
  29. <aside class="left">
  30. <h1>{{ TUITranslateService.t(`TUIGroup.群公告`) }}</h1>
  31. </aside>
  32. <span class="close" @click="close('notification')">{{
  33. TUITranslateService.t(`关闭`)
  34. }}</span>
  35. </header>
  36. <div class="notification">
  37. <textarea
  38. v-if="isEdit"
  39. v-model="input"
  40. :class="[isUniFrameWork ? 'uni-height' : '', 'textarea']"
  41. @keyup.enter="updateProfile"
  42. />
  43. <section v-else class="row">
  44. <p v-if="!groupProfile.notification" class="row-p">
  45. {{ TUITranslateService.t(`TUIGroup.暂无公告`) }}
  46. </p>
  47. <article v-else>
  48. {{ groupProfile.notification }}
  49. </article>
  50. </section>
  51. <footer v-if="isAuthorNotification" class="footer">
  52. <button v-if="isEdit" class="btn" @click="updateProfile">
  53. {{ TUITranslateService.t(`TUIGroup.发布`) }}
  54. </button>
  55. <button v-else class="btn" @click="isEdit = !isEdit">
  56. {{ TUITranslateService.t(`TUIGroup.编辑`) }}
  57. </button>
  58. </footer>
  59. </div>
  60. </main>
  61. </div>
  62. </template>
  63. <script lang="ts" setup>
  64. import { nextTick } from "../../../adapter-vue";
  65. import {
  66. TUITranslateService,
  67. IGroupModel,
  68. } from "@tencentcloud/chat-uikit-engine";
  69. import { watchEffect, ref } from "../../../adapter-vue";
  70. import { Toast, TOAST_TYPE } from "../../common/Toast/index";
  71. import { isUniFrameWork } from "../../../utils/env";
  72. const props = defineProps({
  73. data: {
  74. type: Object,
  75. default: () => ({}),
  76. },
  77. isAuthor: {
  78. type: Boolean,
  79. default: false,
  80. },
  81. });
  82. const groupProfile = ref<IGroupModel>({});
  83. const input = ref("");
  84. const isAuthorNotification = ref(false);
  85. const isEdit = ref(false);
  86. watchEffect(() => {
  87. groupProfile.value = props.data;
  88. input.value = groupProfile.value.notification;
  89. isAuthorNotification.value = props.isAuthor;
  90. });
  91. const emits = defineEmits(["update", "close"]);
  92. // 更新群资料
  93. const updateProfile = () => {
  94. if (input.value.length > 150) {
  95. Toast({
  96. message: TUITranslateService.t(
  97. "TUIGroup.群公告字数超出限制,最大长度为150"
  98. ),
  99. type: TOAST_TYPE.ERROR,
  100. });
  101. return;
  102. }
  103. if (input.value && input.value !== groupProfile.value.notification) {
  104. emits("update", { key: "notification", value: input.value });
  105. nextTick(() => {
  106. input.value = "";
  107. });
  108. }
  109. isEdit.value = !isEdit.value;
  110. };
  111. const close = (tabName: string) => {
  112. emits("close", tabName);
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. @import "../../../assets/styles/common";
  117. .notification {
  118. flex: 1;
  119. padding: 20px;
  120. display: flex;
  121. flex-direction: column;
  122. word-break: break-all;
  123. .row {
  124. flex: 1;
  125. font-size: 14px;
  126. .row-p {
  127. text-align: center;
  128. padding-bottom: 20px;
  129. }
  130. }
  131. .textarea {
  132. margin-bottom: 20px;
  133. box-sizing: border-box;
  134. padding: 10px;
  135. border: 1px solid #e8e8e9;
  136. resize: none;
  137. font-size: 14px;
  138. height: 100%;
  139. }
  140. .uni-height {
  141. height: 20vh;
  142. }
  143. .footer {
  144. display: flex;
  145. justify-content: flex-end;
  146. padding: 20px 10px;
  147. }
  148. }
  149. .btn {
  150. background: #3370ff;
  151. border: 0 solid #2f80ed;
  152. padding: 4px 28px;
  153. font-weight: 400;
  154. font-size: 12px;
  155. color: #fff;
  156. line-height: 24px;
  157. border-radius: 4px;
  158. &-cancel {
  159. background: #fff;
  160. border: 1px solid #ddd;
  161. color: #828282;
  162. }
  163. }
  164. .edit-h5 {
  165. position: fixed;
  166. width: 100%;
  167. height: 100%;
  168. top: 0;
  169. left: 0;
  170. background: rgba(0, 0, 0, 0.5);
  171. display: flex;
  172. align-items: flex-end;
  173. z-index: 1;
  174. .edit-h5-main {
  175. background: #fff;
  176. flex: 1;
  177. padding: 18px;
  178. border-radius: 12px 12px 0 0;
  179. width: 80vw;
  180. }
  181. &-header {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. .close {
  186. font-family: PingFangSC-Regular;
  187. font-weight: 400;
  188. font-size: 18px;
  189. color: #3370ff;
  190. letter-spacing: 0;
  191. line-height: 27px;
  192. }
  193. }
  194. &-footer {
  195. display: flex;
  196. .btn {
  197. flex: 1;
  198. border: none;
  199. background: #405eff;
  200. border-radius: 5px;
  201. font-family: PingFangSC-Regular;
  202. font-weight: 400;
  203. font-size: 16px;
  204. color: #fff;
  205. letter-spacing: 0;
  206. line-height: 27px;
  207. padding: 8px 0;
  208. &:disabled {
  209. opacity: 0.3;
  210. }
  211. }
  212. }
  213. }
  214. </style>