1 Star 1 Fork 0

yxyc-137/Team collaboration calendar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
manage_interface.h 5.00 KB
一键复制 编辑 原始数据 按行查看 历史
yxyc-137 提交于 2023-07-11 09:08 . 修复了一些bug
#ifndef MANAGE_INTERFACE
#define MANAGE_INTERFACE
#include<iostream>
#include<vector>
#include<string>
#include"user.h"
extern std::vector<user>user_vec;
void list_chengyuan(std::vector<user>& user_vec);
void mk(std::vector<user>& user_vec)
{
std::cout << "(按q退出)请输入其用户名:";
while(std::cin.peek() == '\n')
{
std::cout << "(按q退出)请输入其用户名:";
std::cin.ignore();
}
std::string user_name;
getline(std::cin, user_name);
if(user_name == "q")
{
return;
}
auto iter = find_if(user_vec.begin(), user_vec.end(), [&user_name](const user& u)->bool{return u.get_user_name() == user_name; });
if(user_vec.end() == iter)//没找到
{
std::cout << f_red << "操作失败:未找到该用户!" << reset << std::endl;
return;
}
else if(iter->get_user_shenfen() == "群主")
{
std::cout << f_red << "操作失败:您当前已是群主!" << reset << std::endl;
return;
}
else if(iter->get_user_shenfen() == "管理员")
{
std::cout << f_red << "操作失败:该用户当前已是管理员!" << reset << std::endl;
return;
}
iter->set_user_shenfen("管理员");
system("cls");
std::string text = "*manage*";
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
list_chengyuan(user_vec);
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
std::cout << f_green << "添加管理员成功!" << reset<<std::endl;
}
void rm(std::vector<user>& user_vec)
{
std::cout << "(按q退出)请输入其用户名:";
while(std::cin.peek() == '\n')
{
std::cout << "(按q退出)请输入其用户名:";
std::cin.ignore();
}
std::string user_name;
getline(std::cin, user_name);
if(user_name == "q")
{
return;
}
auto iter = find_if(user_vec.begin(), user_vec.end(), [&user_name](const user& u)->bool{return u.get_user_name() == user_name; });
if(user_vec.end() == iter)//没找到
{
std::cout << f_red << "操作失败:未找到该用户!" << reset << std::endl;
return;
}
else if(iter->get_user_shenfen() == "群主")
{
std::cout << f_red << "操作失败:不能删除您自己!" << reset << std::endl;
return;
}
else if(iter->get_user_shenfen() == "群成员")
{
std::cout << f_red << "操作失败:该用户当前已是群成员!" << reset << std::endl;
return;
}
iter->set_user_shenfen("群成员");
system("cls");
std::string text = "*manage*";
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
list_chengyuan(user_vec);
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
std::cout << f_green << "删除管理员成功!" << reset << std::endl;
}
void help_manage_interface()
{
std::cout << f_qingse;
std::cout << "mk:添加管理员\nrm:删除管理员\nback/b:回到上一级\n";
std::cout << reset;
}
void acceptcommand(std::string com, std::vector<user>& user_vec)
{
if(com == "mk")
{
mk(user_vec);
}
else if(com == "rm")
{
rm(user_vec);
}
else if(com == "help"||com=="h")
{
help_manage_interface();
}
else
{
std::cout << f_red << "操作失败:未找到此命令!" << reset << std::endl;
}
}
void manage_interface(std::vector<user>& user_vec, std::string user_name)
{
std::cin.ignore();
system("cls");
std::string text = "*manage*";
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
list_chengyuan(user_vec);
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
std::string com;
while(true)
{
std::cout << "@" << user_name << ":~$ ";
while(std::cin.peek() == '\n')
{
std::cin.ignore();
std::cout << "@" << user_name << ":~$ ";
}
getline(std::cin, com);
if(com == "back"||com=="b")
{
break;
}
acceptcommand(com, user_vec);
}
}
#endif // !MANAGE_INTERFACE
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yxyc-137/Team_collaboration_calendar.git
git@gitee.com:yxyc-137/Team_collaboration_calendar.git
yxyc-137
Team_collaboration_calendar
Team collaboration calendar
master

搜索帮助