user.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view v-if="user">
  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="bg-white flex align-center justify-center bg-img-mine margin-bottom-sm" v-if="user">
  10. <view class="padding-xl text-white">
  11. <view class="padding text-center">
  12. <vim-avatar :img="user.avatar" :name="user.name" />
  13. </view>
  14. </view>
  15. </view>
  16. <view class="cu-list menu menu-margin">
  17. <view class="cu-item">
  18. <navigator class="content" hover-class="none" url="/pages/mine/orderList" navigateTo>
  19. <text class="cuIcon-people text-pink"></text>
  20. <text class="text-black">名字</text>
  21. </navigator>
  22. <view class="action">
  23. <text class="text-black">
  24. {{ user.name }}
  25. </text>
  26. </view>
  27. </view>
  28. <view class="cu-item">
  29. <view class="content">
  30. <text class="cuIcon-mobile text-pink"></text>
  31. <text class="text-black">手机</text>
  32. </view>
  33. <view class="action">
  34. <text class="text-black">
  35. {{ user.mobile }}
  36. </text>
  37. </view>
  38. </view>
  39. <view class="cu-item">
  40. <view class="content">
  41. <text class="cuIcon-mail text-pink"></text>
  42. <text class="text-black">邮箱</text>
  43. </view>
  44. <view class="action">
  45. <text class="text-black">
  46. {{ user.email }}
  47. </text>
  48. </view>
  49. </view>
  50. <!-- <view class="cu-item">
  51. <view class="content">
  52. <text class="cuIcon-community text-cyan"></text>
  53. <text class="text-grey">部门</text>
  54. </view>
  55. <view class="action">
  56. <text class="text-grey" v-for="(item) in dept" :key="item.id">{{ item.name }},</text>
  57. </view>
  58. </view> -->
  59. <view v-if="isFriend" class="cu-item" hover-class="none" @tap="history()">
  60. <view class="content">
  61. <text class="cuIcon-text text-cyan"></text>
  62. <text class="text-black">聊天记录</text>
  63. </view>
  64. <view class="action">
  65. <text class="text-black cuIcon-right"/>
  66. </view>
  67. </view>
  68. </view>
  69. <chat-setting :chat-id='user.id' ></chat-setting>
  70. <view class="padding flex flex-direction">
  71. <view v-if="isFriend || userSetting.canSendMessage" class="cu-btn bg-zblue radius margin-tb-sm lg" @tap="send()"
  72. hover-class="none">发消息
  73. </view>
  74. <view class="cu-btn bg-cyan margin-tb-sm lg" v-if="!isFriend && userSetting.canAddFriend"
  75. @tap="addFriendHandle()">
  76. 加为好友
  77. </view>
  78. </view>
  79. <view class="cu-modal" :class="show?'show':''">
  80. <view class="cu-dialog">
  81. <view class="cu-bar bg-white justify-end">
  82. <view class="content">添加好友</view>
  83. <view class="action" @tap="show = false">
  84. <text class="cuIcon-close text-red"></text>
  85. </view>
  86. </view>
  87. <view class="padding-xl bg-gray" v-if="userSetting.addFriendValidate">
  88. <textarea v-model="message" rows="5" class="border" placeholder="请输入验证消息"></textarea>
  89. </view>
  90. <view class="cu-bar bg-white">
  91. <view class="action margin-0 flex-sub text-green solid-left" @tap="show = false">取消</view>
  92. <view class="action margin-0 flex-sub solid-left" @tap="addFriend">确定</view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script setup lang="ts">
  99. import CuCustom from '@/colorui/components/cu-custom.vue'
  100. import UserApi from '@/api/UserApi';
  101. import DeptApi from '@/api/DeptApi';
  102. import FriendApi from '@/api/FriendApi';
  103. import {onLoad} from '@dcloudio/uni-app';
  104. import type User from '@/mode/User';
  105. import type Dept from '@/mode/Dept';
  106. import {reactive, ref, toRefs} from "vue";
  107. import {useChatStore} from "@/store/chatStore";
  108. import ChatType from '@/utils/ChatType';
  109. import MessageUtils from '@/utils/MessageUtils';
  110. import {useUserStore} from "@/store/userStore";
  111. import SettingApi from "@/api/SettingApi";
  112. import ChatSetting from '@/components/ChatSetting.vue'
  113. import VimAvatar from "@/components/VimAvatar.vue";
  114. import Auth from "@/api/Auth";
  115. const fontValue=ref(Auth.getfontSize());
  116. const chatStore = useChatStore();
  117. const isFriend = ref(true);
  118. //添加好友验证消息展示
  119. const show = ref(false);
  120. //添加好友验证消息
  121. const message = ref("");
  122. interface IData {
  123. user: User | null;
  124. dept: Array<Dept>;
  125. }
  126. const data = reactive<IData>({
  127. user: null,
  128. dept: new Array<Dept>(),
  129. });
  130. const userSetting = reactive({
  131. canAddFriend: false,
  132. addFriendValidate: false,
  133. canSendMessage: false,
  134. canSoundRemind: false,
  135. canVoiceRemind: false,
  136. });
  137. //当前用户
  138. const YES = "1";
  139. const currentUser = useUserStore().getUser();
  140. onLoad((opt) => {
  141. const userId = opt?.id;
  142. UserApi.getUser(userId)
  143. .then((res) => {
  144. data.user = res.data;
  145. return DeptApi.parent(res.data.deptId);
  146. })
  147. .then((res) => {
  148. res.data.forEach((item: Dept) => {
  149. data.dept.push(item);
  150. });
  151. return FriendApi.isFriend(userId)
  152. })
  153. .then((res) => {
  154. isFriend.value = (userId === currentUser?.id || res.data)
  155. return SettingApi.get(userId);
  156. })
  157. .then((res) => {
  158. const setting_ = res.data;
  159. userSetting.canAddFriend = setting_.canAddFriend === YES;
  160. userSetting.addFriendValidate = setting_.addFriendValidate === YES;
  161. userSetting.canSendMessage = setting_.canSendMessage === YES;
  162. userSetting.canSoundRemind = setting_.canSoundRemind === YES;
  163. userSetting.canVoiceRemind = setting_.canVoiceRemind === YES;
  164. })
  165. .catch((err) => {
  166. MessageUtils.error(err)
  167. })
  168. })
  169. /**
  170. * 到聊天页面
  171. */
  172. const send = () => {
  173. if (data.user) {
  174. chatStore.openChat({
  175. id: data.user.id,
  176. name: data.user.name,
  177. avatar: data.user.avatar,
  178. type: ChatType.FRIEND,
  179. lastMessage: "",
  180. unreadCount: 0,
  181. isLoading: false,
  182. loaded: true,
  183. });
  184. console.log('/chat/chat',useUserStore().getUser())
  185. uni.navigateTo({
  186. url: '/pages/chat/chat?id=' + data.user.id + '&type=' + ChatType.FRIEND
  187. })
  188. }
  189. };
  190. const addFriendHandle = () => {
  191. show.value = true;
  192. }
  193. const addFriend = () => {
  194. if (data.user) {
  195. FriendApi.add({friendId: data.user.id, message: message.value})
  196. .then((res) => {
  197. if (res.msg === "添加成功") {
  198. isFriend.value = true;
  199. }
  200. MessageUtils.message(res.msg);
  201. })
  202. .catch(() => {
  203. MessageUtils.message("添加失败");
  204. })
  205. .finally(() => {
  206. show.value = false;
  207. })
  208. }
  209. }
  210. const history = () => {
  211. if (data.user) {
  212. console.log('history');
  213. uni.navigateTo({
  214. url: '/pages/chat/history?chatId=' + data.user.id + '&type=' + ChatType.FRIEND
  215. })
  216. }
  217. };
  218. const {user, dept} = toRefs(data);
  219. </script>
  220. <style>
  221. </style>