manage-notification.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <main class="notification">
  3. <textarea v-if="isEdit" v-model="input" @keyup.enter="updateProfile"></textarea>
  4. <section v-else>
  5. <p v-if="!groupProfile.notification">{{$t(`TUIChat.manage.暂无公告`)}}</p>
  6. <article v-else>{{groupProfile.notification}}</article>
  7. </section>
  8. <footer v-if="isAuth">
  9. <button class="btn" v-if="isEdit" @click="updateProfile">{{$t(`TUIChat.manage.发布`)}}</button>
  10. <button class="btn" v-else @click="isEdit = !isEdit">{{$t(`TUIChat.manage.编辑`)}}</button>
  11. </footer>
  12. </main>
  13. </template>
  14. <script lang="ts">
  15. import { defineComponent, watchEffect, reactive, toRefs } from 'vue';
  16. const ManageNotification = defineComponent({
  17. props: {
  18. data: {
  19. type: Object,
  20. default: () => ({}),
  21. },
  22. isAuth: {
  23. type: Boolean,
  24. default: false,
  25. },
  26. },
  27. setup(props:any, ctx:any) {
  28. const data:any = reactive({
  29. groupProfile: {},
  30. input: '',
  31. isEdit: false,
  32. });
  33. watchEffect(() => {
  34. data.groupProfile = props.data;
  35. data.input = data.groupProfile.notification;
  36. });
  37. // 更新群资料
  38. const updateProfile = async () => {
  39. if (data.input && data.input !== data.groupProfile.notification) {
  40. ctx.emit('update', { key: 'notification', value: data.input });
  41. data.groupProfile.notification = data.input;
  42. data.input = '';
  43. }
  44. data.isEdit = !data.isEdit;
  45. };
  46. return {
  47. ...toRefs(data),
  48. updateProfile,
  49. };
  50. },
  51. });
  52. export default ManageNotification;
  53. </script>
  54. <style lang="scss" scoped>
  55. @import url('../../../styles/common.scss');
  56. @import url('../../../styles/icon.scss');
  57. .notification {
  58. flex: 1;
  59. padding: 20px;
  60. display: flex;
  61. flex-direction: column;
  62. section {
  63. flex: 1;
  64. font-size: 14px;
  65. p {
  66. text-align: center;
  67. padding-bottom: 20px;
  68. }
  69. }
  70. textarea {
  71. margin-bottom: 20px;
  72. flex: 1;
  73. box-sizing: border-box;
  74. padding: 10px;
  75. border: 1px solid #E8E8E9;
  76. resize: none;
  77. font-size: 14px;
  78. }
  79. footer {
  80. display: flex;
  81. justify-content: flex-end;
  82. padding: 10px;
  83. }
  84. }
  85. .btn {
  86. background: #3370FF;
  87. border: 0 solid #2F80ED;
  88. padding: 4px 28px;
  89. font-weight: 400;
  90. font-size: 12px;
  91. color: #FFFFFF;
  92. line-height: 24px;
  93. border-radius: 4px;
  94. &-cancel {
  95. background: #FFFFFF;
  96. border: 1px solid #DDDDDD;
  97. color: #828282;
  98. }
  99. }
  100. </style>