manage-notification.vue 5.4 KB

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