set.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <div>
  3. <ChatHeaderBar title="聊天设置" />
  4. <div class="w-full min-h-300 pt-60 box-border bg-[#F7F8FA]">
  5. <van-cell-group
  6. style="margin-bottom: 12px; padding-top: 12px; padding-left: 16px"
  7. class="box-border"
  8. inset
  9. >
  10. <van-row>
  11. <van-col
  12. style="width: 54px"
  13. v-for="(item, index) in setData?.memberList"
  14. :key="index"
  15. span="4"
  16. class="mb-12 mr-10"
  17. >
  18. <div class="w-40 h-40 rounded-full border mx-auto overflow-hidden mb-4">
  19. <img
  20. v-if="item.headImageUrl"
  21. class="w-full h-full object-cover"
  22. :src="item.headImageUrl"
  23. alt=""
  24. />
  25. <img
  26. v-else
  27. class="w-full h-full object-cover"
  28. src="~/assets/img/default_avatar.png"
  29. alt=""
  30. />
  31. </div>
  32. <p class="w-full line-clamp-1 lin text-sm text-center text-black-6">
  33. {{ item.groupNickname ? item.groupNickname : userInfo.showName }}
  34. </p>
  35. </van-col>
  36. <van-col span="4" class="mb-12 mr-10" @click="navigateTo('/chat/group-add')">
  37. <div
  38. class="w-40 h-40 rounded-full flex justify-center items-center bg-[#F3F3F3] border mx-auto overflow-hidden mb-4"
  39. >
  40. <span class="iconfont icon-plus text-black-6" style="font-size: 24px"></span>
  41. </div>
  42. <p class="w-full line-clamp-1 lin text-sm text-center text-black-6">添加成员</p>
  43. </van-col>
  44. <van-col v-if="isRankAndFiler(userGroupData?.groupRole)" span="4 mb-12 mr-10">
  45. <div
  46. class="w-40 h-40 rounded-full flex justify-center items-center bg-[#F3F3F3] border mx-auto overflow-hidden mb-4"
  47. >
  48. <van-icon name="minus" size="24" color="#666666" />
  49. </div>
  50. <p class="w-full line-clamp-1 lin text-sm text-center text-black-6">删除成员</p>
  51. </van-col>
  52. </van-row>
  53. <div
  54. v-if="changeState(userGroupData?.groupRole) && setData?.memberList?.lenght == 13"
  55. @click="navigateTo('/chat/group-member')"
  56. class="w-full flex pb-5 box-border justify-center items-center leading-3xl text-sm text-black"
  57. >
  58. 查看更多群成员
  59. <van-icon name="arrow" class="-mt-2" size="16" />
  60. </div>
  61. </van-cell-group>
  62. <van-cell-group style="margin-bottom: 12px" inset>
  63. <van-cell
  64. size="large"
  65. @click="
  66. changeState(userGroupData?.groupRole)
  67. ? openDialog({
  68. title: '修改群名称',
  69. value: setData?.groupName,
  70. isRemark: 0,
  71. placeholder: '未命名',
  72. subTitle: '最多不能超过12个字'
  73. })
  74. : showDialog({
  75. title: '群名称',
  76. message: setData.groupName,
  77. confirmButtonColor: '#FF9300',
  78. showCancelButton: false
  79. })
  80. .then(() => {
  81. // on close
  82. })
  83. .catch(() => {
  84. // on cancel
  85. })
  86. "
  87. center
  88. is-link
  89. title="群名称"
  90. >
  91. <template #value>
  92. <p class="w-full line-clamp-2 text-xl text-black/[0.4] leading-5xl">
  93. {{ setData?.groupName ? setData?.groupName : '未命名' }}
  94. </p>
  95. </template>
  96. </van-cell>
  97. <van-cell
  98. @click="
  99. navigateTo({
  100. path: '/chat/qr-code',
  101. query: {
  102. groupName: setData.groupName,
  103. groupAvatar: setData.groupAvatar,
  104. groupId: setData?.id
  105. }
  106. })
  107. "
  108. size="large"
  109. center
  110. is-link
  111. title="群二维码"
  112. >
  113. <template #value>
  114. <div class="w-full flex justify-end items-center">
  115. <img class="w-16 h-16 shrink-0" src="~/assets/img/chat/chat-code.svg" alt="" />
  116. </div>
  117. </template>
  118. </van-cell>
  119. <van-cell
  120. :clickable="isRankAndFiler(userGroupData?.groupRole)"
  121. @click="handleAnnouncement"
  122. size="large"
  123. center
  124. is-link
  125. title="群公告"
  126. :value="setData?.groupNotice ? '' : '未设置'"
  127. ></van-cell>
  128. <van-cell size="large" center>
  129. <template #title>
  130. <p class="w-full line-clamp-1">群介绍:{{ setData?.description }}</p>
  131. </template>
  132. </van-cell>
  133. <van-cell size="large" center title="群聊类型">
  134. <template #value>
  135. <p class="w-full line-clamp-1">{{ setData?.belongTypeIdDictMap?.name }}</p>
  136. </template>
  137. </van-cell>
  138. <van-cell
  139. @click="
  140. openDialog({
  141. title: '群备注',
  142. value: userGroupData?.groupRemark, //groupRemark
  143. isRemark: 1,
  144. placeholder: '备注',
  145. subTitle: '群备注仅自己可见'
  146. })
  147. "
  148. size="large"
  149. is-link
  150. center
  151. title="群备注"
  152. >
  153. <template #value>
  154. <p class="w-full line-clamp-1">
  155. {{ userGroupData?.groupRemark ? userGroupData?.groupRemark : '未设置' }}
  156. </p>
  157. </template>
  158. </van-cell>
  159. </van-cell-group>
  160. <van-cell-group
  161. v-if="isRankAndFiler(userGroupData?.groupRole)"
  162. style="margin-bottom: 12px"
  163. inset
  164. >
  165. <van-cell size="large" center title="个人主页展示">
  166. <template #label>
  167. <!-- class="text-base text-black/[0.4]" -->
  168. <span>开启后,在群聊广场和个人主页</span>
  169. </template>
  170. <template #right-icon>
  171. <van-switch v-model="isPublic" active-color="#FF9300" inactive-color="#dcdee0" />
  172. </template>
  173. </van-cell>
  174. <van-cell size="large" center title="群聊邀请确认">
  175. <template #label>
  176. <!-- class="text-base text-black/[0.4]" -->
  177. <span>
  178. 启用后,群成员需群主或群管理员确认才能邀请朋友进群。扫描二维码进群将同时停用
  179. </span>
  180. </template>
  181. <template #right-icon>
  182. <van-switch v-model="isNeedConfirm" active-color="#FF9300" inactive-color="#dcdee0" />
  183. </template>
  184. </van-cell>
  185. <van-cell
  186. @click="
  187. navigateTo({
  188. path: '/chat/examine',
  189. query: {
  190. groupId: setData?.id
  191. }
  192. })
  193. "
  194. size="large"
  195. is-link
  196. center
  197. title="收到的进群申请"
  198. ></van-cell>
  199. </van-cell-group>
  200. <van-cell-group style="margin-bottom: 12px" inset>
  201. <van-cell
  202. @click="
  203. openDialog({
  204. title: '我在群里的昵称',
  205. value: userGroupData?.groupNickname,
  206. placeholder: '昵称',
  207. isRemark: 2,
  208. subTitle: '昵称修改之后,只会在此群内显示,群内成员都可以看见'
  209. })
  210. "
  211. size="large"
  212. is-link
  213. center
  214. title="我在群里的昵称"
  215. >
  216. <template #value>
  217. <p class="w-full line-clamp-1">
  218. {{ userGroupData?.groupNickname }}
  219. </p>
  220. </template>
  221. </van-cell>
  222. </van-cell-group>
  223. <van-cell-group style="margin-bottom: 12px" inset>
  224. <van-cell
  225. @click="
  226. navigateTo({
  227. path: '/chat/set-sub',
  228. query: {
  229. tab: 'records',
  230. groupId: setData?.id
  231. }
  232. })
  233. "
  234. size="large"
  235. is-link
  236. center
  237. title="查找聊天记录"
  238. ></van-cell>
  239. </van-cell-group>
  240. <van-cell-group style="margin-bottom: 12px" inset>
  241. <van-cell size="large" is-link center title="消息免打扰">
  242. <template #right-icon>
  243. <van-switch
  244. v-model="isNotDisturb"
  245. @click="handleIsNotDisturb"
  246. active-color="#FF9300"
  247. inactive-color="#dcdee0"
  248. />
  249. <!-- @change="
  250. (val) => {
  251. isNotDisturb = val
  252. }
  253. " -->
  254. </template>
  255. </van-cell>
  256. <van-cell size="large" is-link center title="置顶聊天">
  257. <template #right-icon>
  258. <van-switch
  259. v-model="isTop"
  260. @click="handleIsTop"
  261. active-color="#FF9300"
  262. inactive-color="#dcdee0"
  263. />
  264. </template>
  265. </van-cell>
  266. <van-cell
  267. @click="
  268. navigateTo({
  269. path: '/chat/background',
  270. query: {
  271. groupId: setData?.id
  272. }
  273. })
  274. "
  275. size="large"
  276. is-link
  277. center
  278. title="设置当前聊天背景"
  279. ></van-cell>
  280. </van-cell-group>
  281. <van-cell-group style="margin-bottom: 12px" inset>
  282. <van-cell
  283. @click="
  284. navigateTo({
  285. path: '/chat/report',
  286. query: {
  287. groupId: setData?.id,
  288. objectType: 2
  289. }
  290. })
  291. "
  292. size="large"
  293. is-link
  294. center
  295. title="举报"
  296. ></van-cell>
  297. <van-cell
  298. @click="clearChatHistory"
  299. size="large"
  300. is-link
  301. center
  302. title="清空聊天记录"
  303. ></van-cell>
  304. </van-cell-group>
  305. <div class="w-full pt-10 pb-40 px-16 box-border">
  306. <van-button @click="handleExitGroupChat" color="#FF9300" round block>退出群聊</van-button>
  307. </div>
  308. </div>
  309. <ChatDialog
  310. v-model:show="showDialog"
  311. v-model:title="dialogTitle"
  312. @confirm="confirm"
  313. @cancel="cancel"
  314. >
  315. <div class="w-full px-12 text-center mt-4">
  316. <p class="mx-auto w-[80%] text-sm text-black-9 mb-16">{{ dialogSubTitle }}</p>
  317. <van-field
  318. class=""
  319. style="height: 40px; background: #f5f5f5; border-radius: 8px; margin-bottom: 30px"
  320. clearable
  321. :placeholder="dialogPlaceholder"
  322. v-model="groupName"
  323. maxlength="12"
  324. />
  325. </div>
  326. </ChatDialog>
  327. </div>
  328. </template>
  329. <script setup>
  330. const route = useRoute()
  331. const router = useRouter()
  332. const userInfoStore = useUserInfoStore()
  333. const { userInfo } = storeToRefs(userInfoStore)
  334. definePageMeta({
  335. layout: false
  336. })
  337. useSeoMeta({
  338. title: '我的消息'
  339. })
  340. onMounted(() => {
  341. userInfoStore.getUserInfo()
  342. getGroupSetData()
  343. })
  344. // computed(() => route.query.userId ?? '')
  345. let setData = reactive({
  346. // groupId: computed(() => route.query.groupId ?? ''),
  347. userId: userInfo.value.userId
  348. // groupRole: 1
  349. // groupNotice:
  350. // '群公告模版 1.本群提倡友好理性交流,鼓励群友多发言,多互动 2.禁止无意义刷屏、发送广告信息以及谩骂等不良消息 3.为了保证群活跃不经常发言的群友,可能会被定时清理出群'
  351. })
  352. watch([() => route.query.groupId, () => route.query.userId], () => {}, {
  353. immediate: true
  354. })
  355. const userGroupData = ref(null)
  356. const groupName = ref('')
  357. // isPublic 是否公开展示 0隐藏 1公开。
  358. // isNeedConfirm 是否开启群聊邀请确认 0不开启 1开启。
  359. // 是否显示到个人主页
  360. const isPublic = ref(false)
  361. const isNeedConfirm = ref(false)
  362. const isNotDisturb = ref(false)
  363. const isTop = ref(false)
  364. // 弹出窗
  365. const showDialog = ref(false)
  366. const isRemark = ref(0) //0 群名称 1备注 2 我在群里的昵称
  367. const dialogTitle = ref('')
  368. const dialogPlaceholder = ref('')
  369. const dialogSubTitle = ref('')
  370. // 弹窗的方法
  371. const openDialog = (item) => {
  372. showDialog.value = true
  373. dialogTitle.value = item?.title
  374. isRemark.value = item.isRemark
  375. groupName.value = item?.value
  376. dialogPlaceholder.value = item?.placeholder
  377. dialogSubTitle.value = item?.subTitle
  378. }
  379. // 弹窗确认的事件
  380. const confirm = () => {
  381. if (userGroupData.value?.groupRole == 1 && isRemark.value == 0) {
  382. changeGroupName()
  383. } else {
  384. }
  385. if (isRemark.value == 1) changeTourMember({ groupId: setData.id, remark: groupName.value })
  386. if (isRemark.value == 2)
  387. changeGroupName({
  388. groupId: setData.id,
  389. groupNickname: groupName.value
  390. })
  391. // showDialog.value = false
  392. }
  393. // 修改群名称
  394. const changeGroupName = async () => {
  395. try {
  396. const { data } = await request('/website/tourGroup/updateGroup', {
  397. method: 'post',
  398. body: {
  399. groupId: setData.id,
  400. groupName: groupName.value
  401. }
  402. })
  403. if (data) {
  404. showSuccessToast('修改成功')
  405. } else {
  406. showFailToast('修改失败')
  407. }
  408. } catch (error) {}
  409. }
  410. // 修改备注名 和修改自己在群里的备注
  411. const changeTourMember = async (body) => {
  412. try {
  413. const { data } = await request('/website/tourMember/updateTourMember', {
  414. method: 'post',
  415. body
  416. })
  417. console.log(data, '修改自己在群里的备注')
  418. if (data) {
  419. //修改成功
  420. if ((Object.keys(body)[1] = 'remark')) {
  421. userGroupData.groupRemark = groupName.value
  422. } else {
  423. userGroupData[Object.keys(body)[1]] = groupName.value
  424. }
  425. showSuccessToast('操作成功')
  426. } else {
  427. // showSuccessToast('操作失败')
  428. }
  429. } catch (error) {}
  430. }
  431. const cancel = () => {
  432. showDialog.value = false
  433. }
  434. // 改变状态的公用方法
  435. const changeState = (state) => {
  436. if (state == 1) return true
  437. if (state == 0) return false
  438. }
  439. const changeStateBoolean = (state) => {
  440. if (state) {
  441. return 1
  442. } else {
  443. return 0
  444. }
  445. }
  446. // 是否置顶
  447. const handleIsTop = () => {
  448. handleBoolean({ isTop: changeStateBoolean(isTop.value) })
  449. }
  450. // 是否免打扰
  451. const handleIsNotDisturb = () => {
  452. handleBoolean({ isNotDisturb: changeStateBoolean(isNotDisturb.value) })
  453. }
  454. const handleBoolean = async (params) => {
  455. try {
  456. let { data } = await request('/website/tourMember/updateSingleTourMember', {
  457. method: 'post',
  458. body: {
  459. groupId: userGroupData.value.groupId,
  460. ...params
  461. }
  462. })
  463. if (data) {
  464. if (Object.keys(params)[0] == 'isTop') {
  465. isTop.value ? showToast('已置顶') : showToast('置顶取消')
  466. }
  467. if (Object.keys(params)[0] == 'isNotDisturb') {
  468. isNotDisturb.value ? showToast('已开启面打扰') : showToast('已关闭面打扰')
  469. }
  470. }
  471. } catch (error) {}
  472. }
  473. // 获取群设置的配置信息
  474. const getGroupSetData = async () => {
  475. const { data } = await request('/website/tourGroup/getGroupInfoAndMemberByGroupId', {
  476. query: {
  477. groupId: route.query.groupId
  478. }
  479. })
  480. if (typeof data == 'object') {
  481. setData = data
  482. console.log(setData.id, 'setDataid')
  483. console.log(setData, 'setData')
  484. console.log(data.memberList, '555')
  485. console.log(userInfo.value.userId, 'userInfo')
  486. userGroupData.value = data.memberList.find((item) => item.userId == userInfo.value.userId)
  487. console.log()
  488. console.log(userGroupData.value, '4444')
  489. console.log(userGroupData.value.groupRole, 'userGroupData groupRole')
  490. isPublic.value = changeState(setData.isPublic)
  491. isNeedConfirm.value = changeState(setData.isNeedConfirm)
  492. isNotDisturb.value = changeState(userGroupData.value?.isNotDisturb)
  493. isTop.value = changeState(userGroupData.value.isTop)
  494. }
  495. }
  496. // 返回上一页
  497. const onClickLeft = () => {
  498. router.back()
  499. }
  500. // 是否是普通成员
  501. const isRankAndFiler = (role) => {
  502. return role == 1 || role == 2 ? true : false
  503. }
  504. // 清空聊天记录
  505. const clearChatHistory = () => {
  506. showConfirmDialog({
  507. width: 260,
  508. title: '提示',
  509. message: '清空聊天记录',
  510. confirmButtonColor: '#FF9300'
  511. })
  512. .then(async () => {
  513. try {
  514. const res = await request('/website/tourMessage/clearGroupMessage', {
  515. query: {
  516. groupId: setData?.id
  517. }
  518. })
  519. if (res && res?.success) return
  520. } catch (error) {}
  521. })
  522. .catch(() => {})
  523. }
  524. // 点击公告
  525. const handleAnnouncement = () => {
  526. console.log(userGroupData.value?.groupRole, 'userGroupData?.groupRole')
  527. console.log(!isRankAndFiler(3))
  528. // && !setData?.groupNotice
  529. if (isRankAndFiler(userGroupData.value?.groupRole)) {
  530. // navigateTo({
  531. // path: '/chat/announcement',
  532. // query: {
  533. // groupId: setData?.id,
  534. // userId: userInfo.value.userId,
  535. // groupRole: userGroupData.value?.groupRole
  536. // }
  537. // })
  538. }
  539. if (!isRankAndFiler(userGroupData.value?.groupRole)) {
  540. showConfirmDialog({
  541. width: 260,
  542. message: `只有群主${setData?.groupName ? setData?.groupName : ''}或群管理员才能修改公告`,
  543. showCancelButton: false,
  544. confirmButtonColor: '#FF9300',
  545. confirmButtonText: '我知道了'
  546. }).then(() => {})
  547. return
  548. }
  549. }
  550. // 退出群聊
  551. async function handleExitGroupChat() {
  552. let { data } = await request('/website/tourGroup/exitGroup', {
  553. query: {
  554. groupId: setData.groupId,
  555. userId: user
  556. }
  557. })
  558. navigateTo({
  559. path: '/profile/my-news',
  560. replace: true
  561. })
  562. }
  563. </script>
  564. <style lang="scss" scoped>
  565. ::v-deep .van-dialog__header {
  566. padding-top: 21px;
  567. }
  568. </style>