manage-name.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="name">
  3. <label>{{ TUITranslateService.t(`TUIGroup.群名称`) }}</label>
  4. <div v-if="isEdit" :class="[!isPC ? 'edit-h5' : '']">
  5. <main>
  6. <header v-if="!isPC" class="edit-h5-header">
  7. <aside class="left">
  8. <h1>{{ TUITranslateService.t(`TUIGroup.修改群聊名称`) }}</h1>
  9. <span>{{
  10. TUITranslateService.t(
  11. `TUIGroup.修改群聊名称后,将在群内通知其他成员`
  12. )
  13. }}</span>
  14. </aside>
  15. <span class="close" @click="close">{{
  16. TUITranslateService.t(`关闭`)
  17. }}</span>
  18. </header>
  19. <div class="input-box">
  20. <input
  21. v-if="isEdit"
  22. ref="nameInputRef"
  23. v-model="inputGroupName"
  24. class="input"
  25. type="text"
  26. @blur="updateProfile"
  27. />
  28. <span v-if="!isPC">{{
  29. TUITranslateService.t(
  30. `TUIGroup.仅限中文、字母、数字和下划线,2-20个字`
  31. )
  32. }}</span>
  33. </div>
  34. <footer v-if="!isPC" class="edit-h5-footer">
  35. <button class="btn" @click="updateProfile">
  36. {{ TUITranslateService.t(`确认`) }}
  37. </button>
  38. </footer>
  39. </main>
  40. </div>
  41. <p v-if="!isEdit || !isPC" @click="close">
  42. <span>{{ groupProfile.name }}</span>
  43. <Icon v-if="isAuthor" :file="editIcon" width="14px" height="14px" />
  44. </p>
  45. </div>
  46. </template>
  47. <script lang="ts" setup>
  48. import { watchEffect, ref, nextTick, watch } from "../../../adapter-vue";
  49. import {
  50. TUITranslateService,
  51. IGroupModel,
  52. } from "@tencentcloud/chat-uikit-engine";
  53. import Icon from "../../common/Icon.vue";
  54. import editIcon from "../../../assets/icon/edit.svg";
  55. import { Toast, TOAST_TYPE } from "../../common/Toast/index";
  56. import { isPC } from "../../../utils/env";
  57. const props = defineProps({
  58. data: {
  59. type: Object,
  60. default: () => ({}),
  61. },
  62. isAuthor: {
  63. type: Boolean,
  64. default: false,
  65. },
  66. });
  67. const groupProfile = ref<IGroupModel>({});
  68. const inputGroupName = ref("");
  69. const isEdit = ref(false);
  70. const nameInputRef = ref<HTMLInputElement>(null);
  71. watchEffect(() => {
  72. groupProfile.value = props.data;
  73. });
  74. const emit = defineEmits(["update"]);
  75. const updateProfile = () => {
  76. if (!inputGroupName.value) {
  77. Toast({
  78. message: TUITranslateService.t("TUIGroup.群名称不能为空"),
  79. type: TOAST_TYPE.ERROR,
  80. });
  81. } else {
  82. if (inputGroupName.value !== groupProfile.value.name) {
  83. emit("update", { key: "name", value: inputGroupName.value });
  84. groupProfile.value.name = inputGroupName.value;
  85. inputGroupName.value = "";
  86. Toast({
  87. message: TUITranslateService.t("TUIGroup.群名称修改成功"),
  88. type: TOAST_TYPE.SUCCESS,
  89. });
  90. }
  91. close();
  92. }
  93. };
  94. const close = () => {
  95. if (props.isAuthor) {
  96. isEdit.value = !isEdit.value;
  97. }
  98. if (isEdit.value) {
  99. inputGroupName.value = groupProfile.value.name;
  100. }
  101. };
  102. watch(
  103. () => isEdit.value,
  104. (newVal: boolean) => {
  105. if (newVal) {
  106. nextTick(() => {
  107. nameInputRef.value?.focus();
  108. });
  109. }
  110. }
  111. );
  112. </script>
  113. <style lang="scss" scoped>
  114. @import "../../../assets/styles/common";
  115. .name {
  116. padding: 14px 20px;
  117. font-weight: 400;
  118. font-size: 14px;
  119. color: #000;
  120. display: flex;
  121. flex-direction: column;
  122. p {
  123. opacity: 0.6;
  124. display: flex;
  125. align-items: center;
  126. .icon {
  127. margin-left: 4px;
  128. }
  129. }
  130. }
  131. .input-box {
  132. display: flex;
  133. .input {
  134. flex: 1;
  135. border: 1px solid #e8e8e9;
  136. border-radius: 4px;
  137. padding: 4px 16px;
  138. font-weight: 400;
  139. font-size: 14px;
  140. color: #000;
  141. opacity: 0.6;
  142. }
  143. }
  144. .space-top {
  145. border-top: 10px solid #f4f5f9;
  146. }
  147. .edit-h5 {
  148. position: fixed;
  149. width: 100%;
  150. height: 100%;
  151. top: 0;
  152. left: 0;
  153. background: rgba(0, 0, 0, 0.5);
  154. display: flex;
  155. align-items: flex-end;
  156. z-index: 1;
  157. main {
  158. background: #fff;
  159. flex: 1;
  160. padding: 18px;
  161. border-radius: 12px 12px 0 0;
  162. width: 80vw;
  163. .input-box {
  164. flex-direction: column;
  165. padding: 18px 0;
  166. .input {
  167. background: #f8f8f8;
  168. padding: 10px 12px;
  169. }
  170. span {
  171. font-family: PingFangSC-Regular;
  172. font-weight: 400;
  173. font-size: 12px;
  174. color: #888;
  175. letter-spacing: 0;
  176. padding-top: 8px;
  177. }
  178. }
  179. }
  180. &-header {
  181. display: flex;
  182. align-items: center;
  183. justify-content: space-between;
  184. .close {
  185. font-family: PingFangSC-Regular;
  186. font-weight: 400;
  187. font-size: 18px;
  188. color: #3370ff;
  189. letter-spacing: 0;
  190. line-height: 27px;
  191. }
  192. }
  193. &-footer {
  194. display: flex;
  195. .btn {
  196. flex: 1;
  197. border: none;
  198. background: #405eff;
  199. border-radius: 5px;
  200. font-family: PingFangSC-Regular;
  201. font-weight: 400;
  202. font-size: 16px;
  203. color: #fff;
  204. letter-spacing: 0;
  205. line-height: 27px;
  206. padding: 8px 0;
  207. &:disabled {
  208. opacity: 0.3;
  209. }
  210. }
  211. }
  212. }
  213. </style>