manage-name.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="name">
  3. <label>群名称</label>
  4. <input class="input" v-if="isEdit" v-model="input" type="text" @blur="updateProfile">
  5. <view class="name-container" v-else>
  6. <span>{{groupProfile.name}}</span>
  7. <image
  8. src="../../../assets/icon/edit.svg"
  9. mode="scaleToFill"
  10. @click="isEdit = !isEdit"
  11. class="edit-image"
  12. />
  13. </view>
  14. </view>
  15. </template>
  16. <script lang="ts">
  17. import { defineComponent, watchEffect, reactive, toRefs } from 'vue';
  18. const manageName = defineComponent({
  19. props: {
  20. data: {
  21. type: Object,
  22. default: () => ({}),
  23. },
  24. isAuth: {
  25. type: Boolean,
  26. default: false,
  27. },
  28. },
  29. setup(props:any, ctx:any) {
  30. const TUIGroupServer: any = uni.$TUIKit.TUIGroupServer;
  31. const data:any = reactive({
  32. groupProfile: {},
  33. input: '',
  34. isEdit: false,
  35. });
  36. watchEffect(() => {
  37. data.groupProfile = props.data;
  38. data.input = data.groupProfile.name;
  39. });
  40. // 更新群资料
  41. const updateProfile = async () => {
  42. if (data.input && data.input !== data.groupProfile.name) {
  43. const params = {
  44. groupID: data.groupProfile.groupID,
  45. name: data.input,
  46. };
  47. uni.$TUIKit.updateGroupProfile(params).then((res: any) => {
  48. }).catch((err: any) => {});
  49. data.groupProfile.name = data.input;
  50. data.input = '';
  51. }
  52. data.isEdit = !data.isEdit;
  53. };
  54. return {
  55. ...toRefs(data),
  56. updateProfile,
  57. };
  58. },
  59. });
  60. export default manageName;
  61. </script>
  62. <style lang="scss" scoped>
  63. .name {
  64. padding: 14px 20px;
  65. font-weight: 400;
  66. font-size: 14px;
  67. color: #000000;
  68. display: flex;
  69. flex-direction: column;
  70. p {
  71. opacity: 0.6;
  72. display: flex;
  73. align-items: center;
  74. .icon {
  75. margin-left: 4px;
  76. }
  77. }
  78. .name-container {
  79. display: flex;
  80. align-items: center;
  81. .edit-image {
  82. width: 20px;
  83. height: 20px;
  84. margin-left: 10px;
  85. }
  86. }
  87. }
  88. .input {
  89. border: 1px solid #E8E8E9;
  90. border-radius: 4px;
  91. padding: 4px 16px;
  92. font-weight: 400;
  93. font-size: 14px;
  94. color: #000000;
  95. opacity: 0.6;
  96. }
  97. .space-top{
  98. border-top: 10px solid #F4F5F9;
  99. }
  100. </style>