搭建PVB架构,实现前端的基础布局、菜单、表格、图示等功能

This commit is contained in:
lixiaoyuan
2025-08-20 19:00:22 +08:00
parent 5de7687bcc
commit 7e965b6fb4
142 changed files with 28270 additions and 411 deletions

151
src/common/Crypto.cpp Normal file
View File

@@ -0,0 +1,151 @@
#include "Crypto.h"
#define MD5_A 0x67452301
#define MD5_B 0xefcdab89
#define MD5_C 0x98badcfe
#define MD5_D 0x10325476
const char MD5_S16[] = "0123456789abcdef";
const unsigned int T[] = {
0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,
0xf57c0faf,0x4787c62a,0xa8304613,0xfd469501,
0x698098d8,0x8b44f7af,0xffff5bb1,0x895cd7be,
0x6b901122,0xfd987193,0xa679438e,0x49b40821,
0xf61e2562,0xc040b340,0x265e5a51,0xe9b6c7aa,
0xd62f105d,0x02441453,0xd8a1e681,0xe7d3fbc8,
0x21e1cde6,0xc33707d6,0xf4d50d87,0x455a14ed,
0xa9e3e905,0xfcefa3f8,0x676f02d9,0x8d2a4c8a,
0xfffa3942,0x8771f681,0x6d9d6122,0xfde5380c,
0xa4beea44,0x4bdecfa9,0xf6bb4b60,0xbebfbc70,
0x289b7ec6,0xeaa127fa,0xd4ef3085,0x04881d05,
0xd9d4d039,0xe6db99e5,0x1fa27cf8,0xc4ac5665,
0xf4292244,0x432aff97,0xab9423a7,0xfc93a039,
0x655b59c3,0x8f0ccc92,0xffeff47d,0x85845dd1,
0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,
0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391 };
const unsigned int MD5_OFFSET[] = {
7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,
5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,
4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,
6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21
};
// 填充字符串
vector<unsigned int> padding(string src, unsigned int& len)
{
// 以512位,64个字节为一组
unsigned int num = ((src.length() + 8) / 64) + 1;
vector<unsigned int> rec(num * 16);
len = num * 16;
for (unsigned int i = 0; i < src.length(); i++) {
// 一个unsigned int对应4个字节保存4个字符信息
rec[i >> 2] |= (int)(src[i]) << ((i % 4) * 8);
}
// 补充1000...000
rec[src.length() >> 2] |= (0x80 << ((src.length() % 4) * 8));
// 填充原文长度
rec[rec.size() - 2] = (src.length() << 3);
return rec;
}
// 整理输出
string md5_format(unsigned int num)
{
string res = "";
unsigned int base = 1 << 8;
for (int i = 0; i < 4; i++) {
string tmp = "";
unsigned int b = (num >> (i * 8)) % base & 0xff;
for (int j = 0; j < 2; j++) {
tmp = MD5_S16[b % 16] + tmp;
b /= 16;
}
res += tmp;
}
return res;
}
// F函数
unsigned int F(unsigned int b, unsigned int c, unsigned int d)
{
return (b & c) | ((~b) & d);
}
// G函数
unsigned int G(unsigned int b, unsigned int c, unsigned int d)
{
return (b & d) | (c & (~d));
}
// H函数
unsigned int H(unsigned int b, unsigned int c, unsigned int d)
{
return b ^ c ^ d;
}
// I函数
unsigned int I(unsigned int b, unsigned int c, unsigned int d)
{
return c ^ (b | (~d));
}
// 移位操作函数
unsigned int shift(unsigned int a, unsigned int n)
{
return (a << n) | (a >> (32 - n));
}
// 循环压缩
void md5_encode(unsigned int* X, int size, unsigned int& tempA, unsigned int& tempB, unsigned int& tempC, unsigned int& tempD)
{
unsigned int a = tempA,
b = tempB,
c = tempC,
d = tempD,
rec = 0,
g, k;
for (int i = 0; i < 64; i++) {
if (i < 16) {
// F迭代
g = F(b, c, d);
k = i;
} else if (i < 32) {
// G迭代
g = G(b, c, d);
k = (1 + 5 * i) % 16;
} else if (i < 48) {
// H迭代
g = H(b, c, d);
k = (5 + 3 * i) % 16;
} else {
// I迭代
g = I(b, c, d);
k = (7 * i) % 16;
}
rec = d;
d = c;
c = b;
b = b + shift(a + g + X[k] + T[i], MD5_OFFSET[i]);
a = rec;
}
tempA += a;
tempB += b;
tempC += c;
tempD += d;
}
string Crypto::md5(string src)
{
unsigned int tempA = MD5_A;
unsigned int tempB = MD5_B;
unsigned int tempC = MD5_C;
unsigned int tempD = MD5_D;
unsigned int len = 0;
vector<unsigned int> rec = padding(src, len);
for (unsigned int i = 0; i < len / 16; i++) {
unsigned int num[16];
for (int j = 0; j < 16; j++) {
num[j] = rec[i * 16 + j];
}
md5_encode(num, 16, tempA, tempB, tempC, tempD);
}
return md5_format(tempA) + md5_format(tempB) + md5_format(tempC) + md5_format(tempD);
}

20
src/common/Crypto.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef _Crypto_H_
#define _Crypto_H_
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
class Crypto
{
public:
static string md5(string src);
};
#endif // ! _Crypto_H_

View File

@@ -32,10 +32,17 @@ int DataFields::getInt(string key)
{
return mapFields_.count(key) > 0 ? Utils::toInt(mapFields_[key]) : 0;
}
float DataFields::getFloat(string key)
{
return mapFields_.count(key) > 0 ? Utils::toFloat(mapFields_[key]) : 0.0f;
}
double DataFields::getDouble(string key)
{
return mapFields_.count(key) > 0 ? Utils::toDouble(mapFields_[key]) : 0.0;
}
void DataFields::remove(string key)
{
auto it = mapFields_.find(key);
@@ -143,7 +150,7 @@ string DataFields::get_update_sql(string tbname, std::vector<std::string> vec_ke
return oss.str();
}
void DataFields::foreach_item(function<void(string key, string val)> on_foraach)
void DataFields::foreachItem(function<void(string key, string val)> on_foraach)
{
for (auto it = mapFields_.begin(); it != mapFields_.end(); it++)
{
@@ -176,12 +183,12 @@ bool DataFields::is_float_number(string key)
return true;
}
string DataFields::to_str()
string DataFields::toStr()
{
string s;
for (auto it = mapFields_.begin(); it != mapFields_.end(); it++)
{
s += ("[" + it->first + ":" + it->second + "] ");
s += ("{" + it->first + ":" + it->second + "} ");
}
return s;
}

View File

@@ -10,10 +10,10 @@ using namespace std;
struct PageInfo
{
int total = 0;
int page_id = 1;
int page_size = 10;
int page_max = 0;
int total {0};
int pageIndex {0};
int pageSize {10};
int pageCount {0};
};
class DataFields
@@ -64,7 +64,13 @@ public:
* @param: [string key] 索引名称
*/
float getFloat(string key);
/**
* 获取 double 值
* @param: [string key] 索引名称
*/
double getDouble(string key);
/**
* 删除指定索引的值
* @param: [string key] 索引名称
@@ -116,7 +122,7 @@ public:
* 遍历数据项
* @param: [function... on_foraach] 回调函数
*/
void foreach_item(function<void(string key, string val)> on_foraach);
void foreachItem(function<void(string key, string val)> on_foraach);
/**
* 判断是否含有数据项
@@ -133,7 +139,7 @@ public:
/**
* 转换成键值对的字符串格式
*/
string to_str();
string toStr();
/**
* 获取数据项的大小

View File

@@ -7,7 +7,7 @@
std::mutex g_mutex;
Logger::Logger(Logger::ELogType logtype, std::string filename, int line) : line_(line)
Logger::Logger(Logger::ELogType logtype, std::string filename, int lineEdit) : line_(lineEdit)
{
auto index = filename.find_last_of('\\');
if (index != std::string::npos)
@@ -64,7 +64,7 @@ Logger::~Logger()
}
//std::cout << "[" << filename_ << ":" << line_ << "] [" << Utils::time_now_string_ms() << "][" << strLogType[int(log_type_)] << "] ";
std::cout << "[" << Utils::timeNowStrMS() << "][" << strLogType[int(log_type_)] << "] ";
std::cout << "[" << Utils::timeStrMS() << "][" << strLogType[int(log_type_)] << "] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
std::cout << "- " << text << std::endl << std::flush;
g_mutex.unlock();

View File

@@ -19,7 +19,7 @@ public:
};
public:
Logger(Logger::ELogType logType, std::string filename, int line);
Logger(Logger::ELogType logType, std::string filename, int lineEdit);
~Logger();
std::stringstream& Stream() { return oss_; }

View File

@@ -195,34 +195,13 @@ void parse_from_string()
cout << tp.time_since_epoch().count() << endl;
}
int64_t Utils::timeNow()
{
// return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
return std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}
int64_t Utils::timeNowMS()
int64_t Utils::time()
{
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
//return std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}
int64_t Utils::timeNowDate()
{
// 获取当前时间
auto now = std::chrono::system_clock::now();
time_t t = std::chrono::system_clock::to_time_t(now);
// 转换为本地时间结构体
struct tm* tmlocal = localtime(&t);
// 设置时分秒为0
tmlocal->tm_hour = 0;
tmlocal->tm_min = 0;
tmlocal->tm_sec = 0;
// 转换回time_t
return mktime(tmlocal);
}
string Utils::timeNowStr(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
string Utils::timeStr(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
{
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::stringstream ss;
@@ -230,7 +209,28 @@ string Utils::timeNowStr(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
return ss.str();
}
string Utils::timeNowStrMS(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
int64_t Utils::date()
{
// 获取当前时间戳
std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
// 转换为本地时间结构体设置时分秒为0
std::tm* tmlocal = localtime(&t);
tmlocal->tm_hour = 0;
tmlocal->tm_min = 0;
tmlocal->tm_sec = 0;
auto tp = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::from_time_t(mktime(tmlocal)));
return tp.time_since_epoch().count();
}
string Utils::dateStr(std::string fmt /*= "%Y-%m-%d %H:%M:%S"*/)
{
return Utils::timeStr(fmt).substr(0, 10);
}
string Utils::timeStrMS(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
{
auto tpNow = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(tpNow);
@@ -238,109 +238,110 @@ string Utils::timeNowStrMS(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
std::stringstream ss;
ss << std::put_time(std::localtime(&time), fmt.c_str());
auto tms = std::chrono::duration_cast<std::chrono::milliseconds>(tpNow.time_since_epoch());
auto tseconds = std::chrono::duration_cast<std::chrono::seconds>(tpNow.time_since_epoch());
auto epoch = tpNow.time_since_epoch();
auto tms = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
auto tseconds = std::chrono::duration_cast<std::chrono::seconds>(epoch);
ss << "." << std::setfill('0') << std::setw(3) << (tms - tseconds).count();
return ss.str();
}
string Utils::timeStr(int64_t ts, std::string fmt /*= "%Y-%m-%d %H:%M:%S"*/)
{
// std::localtime : 本地时区的时间
// std::gmtime : 格林威治时间
time_t t(ts);
std::stringstream ss;
ss << std::put_time(std::localtime(&t), fmt.c_str());
return ss.str();
}
string Utils::time_to_string(int64_t dt, std::string fmt /*= "%Y-%m-%d %H:%M:%S"*/)
{
auto ms = std::chrono::milliseconds(dt);
auto tp = std::chrono::time_point<std::chrono::system_clock>(ms);
time_t t = std::chrono::system_clock::to_time_t(tp);
std::stringstream ss;
ss << std::put_time(std::localtime(&t), fmt.c_str());
return ss.str();
}
// 2023-12-12 12:12:12
int64_t Utils::time(string dt, int zone)
{
if (dt.empty())
{
return std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}
else
{
static string FMT_D = "yyyy-MM-dd";
static string FMT_DT = "yyyy-MM-dd HH:mm:ss";
static string FMT_DS = "yyyy-MM-dd HH:mm:ss.SSS";
string fmt;
if (dt.size() == FMT_D.size())
{
fmt = "%Y-%m-%d";
dt[4] = dt[7] = '-';
}
else if (dt.size() == FMT_DT.size())
{
fmt = "%Y-%m-%d %H:%M:%S";
dt[4] = dt[7] = '-';
dt[10] = ' ';
dt[13] = dt[16] = ':';
}
else if (dt.size() == FMT_DT.size())
{
}
else
{
return -1;
}
stringstream ss(dt);
std::tm t {};
ss >> std::get_time(&t, fmt.c_str());
t.tm_hour += zone;
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&t));
return std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
//return std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()).count();
}
}
bool Utils::time_string_to_tm(string dt, std::tm& t)
{
t.tm_year = 1900;
t.tm_mon = 1;
t.tm_mday = 1;
static string FORMAT_D = "yyyy-mm-dd";
static string FORMAT_DT = "yyyy-mm-dd HH:MM:SS";
string fmt;
if (dt.size() == FORMAT_D.size())
{
fmt = "%Y-%m-%d";
dt[4] = dt[7] = '-';
}
else if (dt.size() >= FORMAT_DT.size())
{
fmt = "%Y-%m-%d %H:%M:%S";
dt[4] = dt[7] = '-';
dt[10] = ' ';
dt[13] = dt[16] = ':';
}
else
{
return false;
}
stringstream ss;
ss << dt;
ss >> std::get_time(&t, fmt.c_str());
t.tm_year += 1900;
t.tm_mon += 1;
return true;
}
//
//string Utils::timeStr(int64_t ts, std::string fmt /*= "%Y-%m-%d %H:%M:%S"*/)
//{
// // std::localtime : 本地时区的时间
// // std::gmtime : 格林威治时间
// time_t t(ts);
// std::stringstream ss;
// ss << std::put_time(std::localtime(&t), fmt.c_str());
// return ss.str();
//}
//
//string Utils::time_to_string(int64_t dt, std::string fmt /*= "%Y-%m-%d %H:%M:%S"*/)
//{
// auto ms = std::chrono::milliseconds(dt);
// auto tp = std::chrono::time_point<std::chrono::system_clock>(ms);
// time_t t = std::chrono::system_clock::to_time_t(tp);
// std::stringstream ss;
// ss << std::put_time(std::localtime(&t), fmt.c_str());
// return ss.str();
//}
//
//// 2023-12-12 12:12:12
//int64_t Utils::time(string dt, int zone)
//{
// if (dt.empty())
// {
// return std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
// }
// else
// {
// static string FMT_D = "yyyy-MM-dd";
// static string FMT_DT = "yyyy-MM-dd HH:mm:ss";
// static string FMT_DS = "yyyy-MM-dd HH:mm:ss.SSS";
// string fmt;
// if (dt.size() == FMT_D.size())
// {
// fmt = "%Y-%m-%d";
// dt[4] = dt[7] = '-';
// }
// else if (dt.size() == FMT_DT.size())
// {
// fmt = "%Y-%m-%d %H:%M:%S";
// dt[4] = dt[7] = '-';
// dt[10] = ' ';
// dt[13] = dt[16] = ':';
// }
// else if (dt.size() == FMT_DT.size())
// {
// }
// else
// {
// return -1;
// }
//
// stringstream ss(dt);
//
// std::tm t {};
// ss >> std::get_time(&t, fmt.c_str());
// t.tm_hour += zone;
// auto tp = std::chrono::system_clock::from_time_t(std::mktime(&t));
// return std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
// //return std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()).count();
// }
//}
//
//
//
//bool Utils::time_string_to_tm(string dt, std::tm& t)
//{
// t.tm_year = 1900;
// t.tm_mon = 1;
// t.tm_mday = 1;
// static string FORMAT_D = "yyyy-mm-dd";
// static string FORMAT_DT = "yyyy-mm-dd HH:MM:SS";
// string fmt;
// if (dt.size() == FORMAT_D.size())
// {
// fmt = "%Y-%m-%d";
// dt[4] = dt[7] = '-';
// }
// else if (dt.size() >= FORMAT_DT.size())
// {
// fmt = "%Y-%m-%d %H:%M:%S";
// dt[4] = dt[7] = '-';
// dt[10] = ' ';
// dt[13] = dt[16] = ':';
// }
// else
// {
// return false;
// }
// stringstream ss;
// ss << dt;
// ss >> std::get_time(&t, fmt.c_str());
// t.tm_year += 1900;
// t.tm_mon += 1;
// return true;
//}
void Utils::sleep_ms(int ms)
{

View File

@@ -39,19 +39,22 @@ public:
memcpy_s(&dest[start], len, &src, len);
}
static int64_t timeNow();
static int64_t timeNowMS();
static int64_t timeNowDate();
static string timeNowStr(std::string fmt = "%Y-%m-%d %H:%M:%S");
static string timeNowStrMS(std::string fmt = "%Y-%m-%d %H:%M:%S");
static string timeStr(int64_t ts, std::string fmt = "%Y-%m-%d %H:%M:%S");
// 获取当前时间的时间戳(毫秒)
static int64_t time();
// 获取当前时间的格式字符串
static string timeStr(std::string fmt = "%Y-%m-%d %H:%M:%S");
// 获取当前日期的时间戳(毫秒)
static int64_t date();
// 获取当前日期的格式字符串
static string dateStr(std::string fmt = "%Y-%m-%d %H:%M:%S");
static int64_t time(string dt="", int zone = 0);
static string time_to_string(int64_t dt, std::string fmt="%Y-%m-%d %H:%M:%S");
static bool time_string_to_tm(string dt, std::tm& t);
static string timeStrMS(std::string fmt = "%Y-%m-%d %H:%M:%S");
//static string timeStr(int64_t ts, std::string fmt = "%Y-%m-%d %H:%M:%S");
//static int64_t time(string dt="", int zone = 0);
//static string time_to_string(int64_t dt, std::string fmt="%Y-%m-%d %H:%M:%S");
//static bool time_string_to_tm(string dt, std::tm& t);
std::string duration_str(int64_t t)
{
@@ -89,12 +92,12 @@ public:
TimeTick()
{
tickMS_ = Utils::timeNowMS();
tickMS_ = Utils::time();
}
bool elapse(int64_t ms, bool reset = true)
{
auto tick_now = Utils::timeNowMS();
auto tick_now = Utils::time();
bool res = tick_now - tickMS_ > ms;
if (res && reset)
{
@@ -105,7 +108,7 @@ public:
void reset()
{
tickMS_ = Utils::timeNowMS();
tickMS_ = Utils::time();
}
};