From b795f89b8654fe24c4d9220ce4e8820e7e1c6076 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 6 Oct 2024 16:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=BB=99=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.js | 12 +++++ src/views/UserList.vue | 107 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index 99d1861..1bf46fc 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -88,6 +88,18 @@ export const DelFGService =(Data) =>{ }) } +export const updateUserInfoService = (Data) => { + const params = new URLSearchParams(); + for (let key in Data) { + params.append(key, Data[key]) + } + return request.post('/user/update', params, { + headers: { + 'token': Data.token, // 将 token ��换为您的令牌值 + } + }) +} + export const acceptInviteService =(Data)=> { const params = new URLSearchParams(); for (let key in Data) { diff --git a/src/views/UserList.vue b/src/views/UserList.vue index 94ec56c..6eabd44 100644 --- a/src/views/UserList.vue +++ b/src/views/UserList.vue @@ -2,6 +2,7 @@ import axios from "axios"; import { SearchUserService } from "@/api/user.js"; import { getFriendReqService } from "@/api/user.js"; +import {updateUserInfoService} from "@/api/user.js"; import {acceptInviteService } from "@/api/user.js"; import { rejectInviteService } from "@/api/user.js"; import { addGroupRequestService } from "@/api/user.js"; @@ -27,6 +28,7 @@ export default { FriendsGList:[], GroupList:[], groups:[], + role: "", tokenData: { token: localStorage.getItem("token"), ip: localStorage.getItem("ip"), @@ -71,6 +73,10 @@ export default { this.tableData = data; this.groups= result.group; }, + async setUserPermission(index) { + var id = this.tableData[index].ID; + await this.displayUserInfo(id); + }, async requestFriend(index) { var id = this.tableData[index].ID; var name = this.tableData[index].Name; @@ -185,6 +191,26 @@ export default { console.log(e); } }, + async updateUserInfo(){ + let result ={} + try{ + let req={}; + req.token=localStorage.getItem("token"); + for(var key in this.UserUpdateForm){ + req[key] = this.UserUpdateForm[key]; + } + result = await updateUserInfoService(req) + if (result.code === 0) { + ElMessage.success("更新成功"); + this.updateDialogVisible = false; + } else { + ElMessage.error("更新失败"); + } + + }catch(e){ + console.log(e); + } + }, async RefuseFriendsOrGroup(index){ var id = this.FriendsGRequestList[index].id; var im_id = this.FriendsGRequestList[index].im_id; @@ -243,24 +269,44 @@ export default { router.push("/im"); }, - - async displayMyInfo() { + async getMyUserInfo(id){ let result = {}; try{ //获取用户信息 + this.tokenData.id = id; + if(this.tokenData.id === undefined){ + this.tokenData.id = localStorage.getItem("userId"); + } result = await GetUserInfoService(this.tokenData) if(result.code ===0){ this.UserUpdateForm.id = result.data.ID; this.UserUpdateForm.name = result.data.Name; this.UserUpdateForm.email = result.data.Email; + this.UserUpdateForm.redis = result.data.Redis; + this.UserUpdateForm.run = result.data.Run; + this.UserUpdateForm.upload = result.data.Upload; this.UserUpdateForm.age = result.data.Age; this.UserUpdateForm.role = result.data.Role; this.UserUpdateForm.gender = result.data.Gender; this.UserUpdateForm.create_time = result.data.CreatedAt; + this.UserUpdateForm.update_time = result.data.UpdatedAt; + //console.log("token data:",this.tokenData) + if(result.data.ID === parseInt(this.tokenData.userId)){ + this.role = result.data.Role; + //console.log("my role:",this.role); + } } }catch(e){ console.log(e); } + }, + + async displayMyInfo() { + await this.getMyUserInfo(this.tokenData.user_id) + this.updateDialogVisible= true; + }, + async displayUserInfo(id) { + await this.getMyUserInfo(id) this.updateDialogVisible= true; }, @@ -289,6 +335,7 @@ export default { if (localStorage.getItem("token") === null) { router.push("/login"); } + await this.getMyUserInfo(localStorage.getItem("userId")); this.search_id = Cookies.get("search_id")?Cookies.get("search_id"):2002; this.keyword = Cookies.get("keyword")?Cookies.get("keyword"):""; }, @@ -384,7 +431,7 @@ export default { > - + @@ -392,11 +439,44 @@ export default { - - + + + + - - + + + + + + + + + + + + + + + + + 管理员 + 普通用户 + + + + + + + + + @@ -405,13 +485,14 @@ export default { 取消 - 确定 + @@ -538,6 +619,16 @@ export default { @click.prevent="requestFriend(scope.$index)" >请求加好友 + + + 设置权限 + +