setting.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view>
  4. <cu-custom bgImage="/static/bg.png" :isBack="true">
  5. <template v-slot:content>
  6. <text class="text-black">聊天设置</text>
  7. </template>
  8. </cu-custom>
  9. <view class="padding">
  10. <form>
  11. <view class="cu-form-group margin-top">
  12. <view class="title text-bold text-black">允许加好友:</view>
  13. <switch @change="switchChange('canAddFriend',$event)" :class="settingTemp.canAddFriend?'checked':''" :checked="settingTemp.canAddFriend"/>
  14. </view>
  15. <view class="cu-form-group margin-top">
  16. <view class="title text-bold text-black">好友审核:</view>
  17. <switch @change="switchChange('addFriendValidate',$event)" :class="settingTemp.addFriendValidate?'checked':''" :checked="settingTemp.addFriendValidate"/>
  18. </view>
  19. <view class="cu-form-group margin-top">
  20. <view class="title text-bold text-black">允许私聊:</view>
  21. <switch @change="switchChange('canSendMessage',$event)" :class="settingTemp.canSendMessage?'checked':''" :checked="settingTemp.canSendMessage"/>
  22. </view>
  23. <view class="cu-form-group margin-top">
  24. <view class="title text-bold text-black">语音消息提醒:</view>
  25. <switch @change="switchChange('canSoundRemind',$event)" :class="settingTemp.canSoundRemind?'checked':''" :checked="settingTemp.canSoundRemind"/>
  26. </view>
  27. <!-- <view class="cu-form-group margin-top">-->
  28. <!-- <view class="title">通话消息提醒:</view>-->
  29. <!-- <switch @change="switchChange('canVoiceRemind',$event)" :class="settingTemp.canVoiceRemind?'checked':''" :checked="settingTemp.canVoiceRemind"/>-->
  30. <!-- </view>-->
  31. <view class="cu-form-group margin-top">
  32. <view class="title text-bold text-black">展示手机:</view>
  33. <switch @change="switchChange('showMobile',$event)" :class="settingTemp.showMobile?'checked':''" :checked="settingTemp.showMobile"/>
  34. </view>
  35. <view class="cu-form-group margin-top">
  36. <view class="title text-bold text-black">展示邮箱:</view>
  37. <switch @change="switchChange('showEmail',$event)" :class="settingTemp.showEmail?'checked':''" :checked="settingTemp.showEmail"/>
  38. </view>
  39. <view class="margin-top text-center">
  40. <button class="cu-btn bg-zblue border lg margin-top" style="width: 100%;" @tap="submit">保存</button>
  41. </view>
  42. </form>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup lang="ts">
  47. import CuCustom from '@/colorui/components/cu-custom.vue'
  48. import {reactive, ref} from "vue";
  49. import MessageUtils from "@/utils/MessageUtils";
  50. import SettingApi from "@/api/SettingApi";
  51. import type Setting from "@/mode/Setting";
  52. import {useUserStore} from "@/store/userStore";
  53. import Auth from "@/api/Auth";
  54. const fontValue=ref(Auth.getfontSize());
  55. const YES = "1";
  56. const NO = "0";
  57. const settingTemp = reactive({
  58. canAddFriend: false,
  59. addFriendValidate: false,
  60. canSendMessage: false,
  61. canSoundRemind: false,
  62. canVoiceRemind: false,
  63. showMobile: false,
  64. showEmail: false,
  65. });
  66. const userId = useUserStore().getUser()?.id;
  67. const loadData = () => {
  68. if (userId) {
  69. SettingApi.get(userId).then((res) => {
  70. const setting_ = res.data;
  71. settingTemp.canAddFriend = setting_.canAddFriend === "1";
  72. settingTemp.addFriendValidate = setting_.addFriendValidate === "1";
  73. settingTemp.canSendMessage = setting_.canSendMessage === "1";
  74. settingTemp.canSoundRemind = setting_.canSoundRemind === "1";
  75. settingTemp.canVoiceRemind = setting_.canVoiceRemind === "1";
  76. settingTemp.showMobile = setting_.showMobile === "1";
  77. settingTemp.showEmail = setting_.showEmail === "1";
  78. });
  79. }
  80. };
  81. loadData();
  82. /** 提交按钮 */
  83. function submit() {
  84. //userId必须传回,清理缓存用
  85. if (userId) {
  86. const setting: Setting = {
  87. canAddFriend: settingTemp.canAddFriend ? YES : NO,
  88. addFriendValidate: settingTemp.addFriendValidate ? YES : NO,
  89. canSendMessage: settingTemp.canSendMessage ? YES : NO,
  90. canSoundRemind: settingTemp.canSoundRemind ? YES : NO,
  91. canVoiceRemind: settingTemp.canVoiceRemind ? YES : NO,
  92. showMobile: settingTemp.showMobile ? YES : NO,
  93. showEmail: settingTemp.showEmail ? YES : NO,
  94. createBy: userId,
  95. };
  96. SettingApi.update(setting).then(() => {
  97. MessageUtils.success("修改成功");
  98. });
  99. }
  100. }
  101. const switchChange = (name:string,e: any) => {
  102. if(name === 'canAddFriend'){
  103. settingTemp.canAddFriend = e.detail.value
  104. }else if (name === 'addFriendValidate'){
  105. settingTemp.addFriendValidate = e.detail.value
  106. }else if (name === 'canSendMessage'){
  107. settingTemp.canSendMessage = e.detail.value
  108. }else if (name === 'canSoundRemind'){
  109. settingTemp.canSoundRemind = e.detail.value
  110. }else if (name === 'canVoiceRemind'){
  111. settingTemp.canVoiceRemind = e.detail.value
  112. }else if (name === 'showMobile'){
  113. settingTemp.showMobile = e.detail.value
  114. }else if (name === 'showEmail'){
  115. settingTemp.showEmail = e.detail.value
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. </style>