manage-notification.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <main class="notification">
  3. <input v-if="isEdit" type="text" v-model="title" placeholder="请输入标题" maxlength="15" />
  4. <textarea v-if="isEdit" v-model="input" @keyup.enter="updateProfile" placeholder="请输入内容"></textarea>
  5. <section v-else>
  6. <p v-if="!groupList.content">
  7. {{ $t(`TUIChat.manage.暂无公告`) }}
  8. </p>
  9. <article v-else>
  10. <h2>{{ groupList.title }}</h2>
  11. {{ groupList.content }}
  12. </article>
  13. </section>
  14. <footer v-if="isAuth">
  15. <button class="btn" v-if="isEdit" @click="updateProfile">
  16. {{ $t(`TUIChat.manage.发布`) }}
  17. </button>
  18. <button class="btn" v-else @click="isEdit = !isEdit">
  19. {{ $t(`TUIChat.manage.编辑`) }}
  20. </button>
  21. </footer>
  22. </main>
  23. </template>
  24. <script lang="ts">
  25. import { defineComponent, watchEffect, reactive, toRefs, onMounted } from "vue";
  26. import { imGroupNoticePage, imGroupNoticeSave, imGroupNoticeUpdate } from "../../../../api";
  27. const ManageNotification = defineComponent({
  28. props: {
  29. data: {
  30. type: Object,
  31. default: () => ({}),
  32. },
  33. isAuth: {
  34. type: Boolean,
  35. default: false,
  36. },
  37. },
  38. setup(props: any, ctx: any) {
  39. const data: any = reactive({
  40. groupProfile: {},
  41. title: "",
  42. input: "",
  43. groupList: {},
  44. isEdit: false,
  45. });
  46. const getNotification = async () => {
  47. try {
  48. // 获取群公告
  49. let res = await imGroupNoticePage({
  50. groupId: data.groupProfile.groupID,
  51. page: 1,
  52. rows: 1,
  53. });
  54. const result = res.data.rows || [];
  55. if (result.length > 0) {
  56. data.input = result[0].content;
  57. data.title = result[0].title;
  58. data.groupList = result[0];
  59. }
  60. } catch (e: any) {
  61. //
  62. }
  63. };
  64. watchEffect(() => {
  65. data.groupProfile = props.data;
  66. // 不使用默认的数据,从我们自己的数据库中选择
  67. // data.input = data.groupProfile.notification;
  68. getNotification();
  69. });
  70. // 更新群资料
  71. const updateProfile = async () => {
  72. if (data.title && data.input) {
  73. // ctx.emit("update", { key: "notification", value: data.input });
  74. // data.groupProfile.notification = data.input;
  75. // data.input = "";
  76. try {
  77. const params = {
  78. clientType: "TEACHER",
  79. groupId: data.groupProfile.groupID,
  80. content: data.input,
  81. title: data.title,
  82. };
  83. if (data.groupList.id) {
  84. await imGroupNoticeUpdate({
  85. ...params,
  86. id: data.groupList.id,
  87. });
  88. } else {
  89. await imGroupNoticeSave(params);
  90. }
  91. data.groupList.content = data.input;
  92. ctx.emit("update", { key: "notification", value: data.title });
  93. data.groupProfile.notification = data.title;
  94. data.groupList.content = data.input;
  95. data.groupList.title = data.title;
  96. data.input = "";
  97. } catch {
  98. //
  99. }
  100. }
  101. data.isEdit = !data.isEdit;
  102. };
  103. return {
  104. ...toRefs(data),
  105. updateProfile,
  106. };
  107. },
  108. });
  109. export default ManageNotification;
  110. </script>
  111. <style lang="scss" scoped>
  112. @import url("../../../styles/common.scss");
  113. @import url("../../../styles/icon.scss");
  114. .notification {
  115. flex: 1;
  116. padding: 20px;
  117. display: flex;
  118. flex-direction: column;
  119. section {
  120. flex: 1;
  121. font-size: 14px;
  122. word-wrap: break-word;
  123. word-break: break-word;
  124. p {
  125. text-align: center;
  126. padding-bottom: 20px;
  127. }
  128. }
  129. textarea {
  130. margin-bottom: 20px;
  131. flex: 1;
  132. box-sizing: border-box;
  133. padding: 10px;
  134. border: 1px solid #e8e8e9;
  135. resize: none;
  136. font-size: 14px;
  137. }
  138. input {
  139. margin-bottom: 20px;
  140. padding: 10px;
  141. border: 1px solid #e8e8e9;
  142. resize: none;
  143. font-size: 14px;
  144. }
  145. h2 {
  146. font-size: 16px;
  147. }
  148. footer {
  149. display: flex;
  150. justify-content: flex-end;
  151. padding: 10px;
  152. }
  153. }
  154. .btn {
  155. background: #3370ff;
  156. border: 0 solid #2f80ed;
  157. padding: 4px 28px;
  158. font-weight: 400;
  159. font-size: 12px;
  160. color: #ffffff;
  161. line-height: 24px;
  162. border-radius: 4px;
  163. &-cancel {
  164. background: #ffffff;
  165. border: 1px solid #dddddd;
  166. color: #828282;
  167. }
  168. }
  169. </style>