index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar title="账号设置" />
  4. <view class="info_wrap">
  5. <setting-item
  6. :loading="loading"
  7. @switch="switchGlobalOpt"
  8. title="勿扰模式"
  9. :switchValue="globalOptEnable"
  10. :is_switch="true"
  11. :border="false"
  12. />
  13. <setting-item
  14. :loading="loadingState.beep"
  15. @switch="changeBeep"
  16. :switchValue="selfInfo.allowBeep === 1"
  17. title="新消息提示音"
  18. :is_switch="true"
  19. :border="false"
  20. />
  21. <setting-item
  22. :loading="loadingState.vibration"
  23. @switch="changeVibration"
  24. :switchValue="selfInfo.allowVibration === 1"
  25. title="新消息震动"
  26. :is_switch="true"
  27. :border="false"
  28. />
  29. </view>
  30. <view class="info_wrap">
  31. <setting-item
  32. :loading="loadingState.allowAddFriend"
  33. @switch="changeAllowAddAsFriend"
  34. :switchValue="selfInfo.allowAddFriend === 2"
  35. title="禁止添加我为好友"
  36. :is_switch="true"
  37. :border="false"
  38. />
  39. <setting-item @click="toBlockList" title="通讯录黑名单" :border="false" />
  40. </view>
  41. <view class="info_wrap">
  42. <setting-item @click="toResetPwd" title="修改密码" :border="false" />
  43. <setting-item @click="deleteAllMsg" danger title="清空聊天记录" :border="false" />
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import IMSDK, { MessageReceiveOptType } from "openim-uniapp-polyfill";
  49. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  50. import MyAvatar from "../../../components/MyAvatar/index.vue";
  51. import SettingItem from "../../../components/SettingItem/index.vue";
  52. import { businessInfoUpdate } from "../../../api/login";
  53. export default {
  54. components: {
  55. CustomNavBar,
  56. MyAvatar,
  57. SettingItem,
  58. },
  59. data() {
  60. return {
  61. newMessageNotify: true,
  62. loadingState: {
  63. beep: false,
  64. vibration: false,
  65. message: false,
  66. allowAddFriend: false
  67. },
  68. loading: false,
  69. };
  70. },
  71. computed: {
  72. selfInfo() {
  73. return this.$store.getters.storeSelfInfo;
  74. },
  75. globalOptEnable() {
  76. return (
  77. this.$store.getters.storeSelfInfo.globalRecvMsgOpt !==
  78. MessageReceiveOptType.Nomal
  79. );
  80. },
  81. },
  82. onLoad() {
  83. const disableNotify =
  84. uni.getStorageSync(
  85. `${this.$store.getters.storeCurrentUserID}_DisableNotify`,
  86. ) ?? false;
  87. this.newMessageNotify = !disableNotify;
  88. },
  89. methods: {
  90. changeBeep(flag) {
  91. this.loadingState.beep = true;
  92. this.updateSelfInfo(
  93. {
  94. allowBeep: flag ? 1 : 2,
  95. },
  96. "beep",
  97. );
  98. },
  99. changeVibration(flag) {
  100. this.loadingState.vibration = true;
  101. this.updateSelfInfo(
  102. {
  103. allowVibration: flag ? 1 : 2,
  104. },
  105. "vibration",
  106. );
  107. },
  108. changeAllowAddAsFriend(flag) {
  109. this.loadingState.addFriend = true;
  110. this.updateSelfInfo(
  111. {
  112. allowAddFriend: flag ? 2 : 1,
  113. },
  114. "allowAddFriend",
  115. );
  116. },
  117. async updateSelfInfo(data, key) {
  118. try {
  119. await businessInfoUpdate({
  120. userID: this.selfInfo.userID,
  121. ...data,
  122. });
  123. await this.$store.dispatch("user/updateBusinessInfo");
  124. uni.$u.toast("修改成功");
  125. } catch (e) {
  126. console.log("updateSelfInfo", e);
  127. uni.$u.toast("修改失败");
  128. }
  129. this.loadingState[key] = false;
  130. this.loading = false
  131. },
  132. toBlockList() {
  133. uni.navigateTo({
  134. url: "/pages_im/pages/profile/blockList/index",
  135. });
  136. },
  137. toResetPwd() {
  138. uni.navigateTo({
  139. url: "/pages_im/pages/profile/changePassword/index",
  140. });
  141. },
  142. deleteAllMsg() {
  143. uni.showModal({
  144. title: "提示",
  145. content: "确定要删除所有本地消息吗?",
  146. confirmText: "确认",
  147. cancelText: "取消",
  148. success: (res) => {
  149. if (res.confirm) {
  150. uni.showLoading({
  151. title: '删除中',
  152. mask: true
  153. })
  154. IMSDK.asyncApi(IMSDK.IMMethods.DeleteAllMsgFromLocal, IMSDK.uuid())
  155. .then(() => {
  156. uni.showToast({title:'删除成功',icon:'none'})
  157. })
  158. .catch(() => {
  159. uni.showToast({title:'删除失败',icon:'none'})
  160. })
  161. .finally(()=>{
  162. uni.hideLoading()
  163. })
  164. }
  165. },
  166. });
  167. },
  168. async switchGlobalOpt(flag) {
  169. this.loading = true;
  170. this.updateSelfInfo(
  171. {
  172. globalRecvMsgOpt: flag ? 2 : 0,
  173. },
  174. "globalRecvMsgOpt",
  175. );
  176. },
  177. toNotificationDetails() {
  178. uni.navigateTo({
  179. url: "/pages_im/pages/profile/notificationDetails/index",
  180. });
  181. },
  182. changeNotify(value) {
  183. this.loadingState.message = true;
  184. uni.setStorageSync(
  185. `${this.$store.getters.storeCurrentUserID}_DisableNotify`,
  186. !value,
  187. );
  188. this.newMessageNotify = value;
  189. this.loadingState.message = false;
  190. },
  191. },
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .page_container {
  196. background-color: #f8f8f8;
  197. .info_wrap {
  198. background-color: #fff;
  199. margin: 24rpx 24rpx 0 24rpx;
  200. border-radius: 6px;
  201. .qr_icon {
  202. width: 22px;
  203. height: 23px;
  204. }
  205. }
  206. }
  207. </style>