manage-notification.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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">暂无公告</p>
  6. <article v-else>{{groupProfile.notification}}</article>
  7. </section>
  8. <footer v-if="isAuth">
  9. <button class="btn" v-if="isEdit" @click="updateProfile">发布</button>
  10. <button class="btn" v-else @click="isEdit = !isEdit">编辑</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. .notification {
  56. flex: 1;
  57. padding: 20px;
  58. display: flex;
  59. flex-direction: column;
  60. section {
  61. font-size: 14px;
  62. p {
  63. text-align: center;
  64. padding-bottom: 20px;
  65. }
  66. }
  67. textarea {
  68. margin-bottom: 20px;
  69. flex: 1;
  70. box-sizing: border-box;
  71. padding: 10px;
  72. border: 1px solid #E8E8E9;
  73. resize: none;
  74. font-size: 14px;
  75. }
  76. footer {
  77. display: flex;
  78. justify-content: flex-end;
  79. padding: 10px;
  80. }
  81. }
  82. .btn {
  83. background: #3370FF;
  84. border: 0 solid #2F80ED;
  85. padding: 4px 28px;
  86. font-weight: 400;
  87. font-size: 12px;
  88. color: #FFFFFF;
  89. line-height: 24px;
  90. border-radius: 4px;
  91. &-cancel {
  92. background: #FFFFFF;
  93. border: 1px solid #DDDDDD;
  94. color: #828282;
  95. }
  96. }
  97. </style>