From d3614f4dd365474a8bd55dbbb0781c542a7eb380 Mon Sep 17 00:00:00 2001 From: Yuhang Wu Date: Tue, 28 Jul 2026 18:06:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(role):=20=E4=BF=AE=E5=A4=8D=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=9A=84SQL=E6=8B=BC=E6=8E=A5=E7=A9=BA=E6=A0=BC=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修正了count查询SQL拼接时缺少前置空格的问题,避免出现"WHERE1=1"的语法错误 2. 新增了系统用户和角色的初始数据库脚本 --- rust.sql | 46 ++++++++++++++++++++++++++++++++++ src-tauri/src/commands/role.rs | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 rust.sql diff --git a/rust.sql b/rust.sql new file mode 100644 index 0000000..2a4c082 --- /dev/null +++ b/rust.sql @@ -0,0 +1,46 @@ +-- Database export: rust +-- Date: 2026-07-28 17:51:45 +-- Generated by DBX + +SET FOREIGN_KEY_CHECKS = 0; + +DROP TABLE IF EXISTS `sys_user`; + +CREATE TABLE `sys_user` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `nick_name` varchar(64) NOT NULL DEFAULT '' COMMENT '昵称', + `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像', + `user_name` varchar(64) NOT NULL DEFAULT '' COMMENT '用户名', + `password` varchar(128) NOT NULL DEFAULT '' COMMENT '密码', + `email` varchar(128) NOT NULL DEFAULT '' COMMENT '邮箱', + `phone` varchar(32) NOT NULL DEFAULT '' COMMENT '手机号', + `age` bigint(20) NOT NULL DEFAULT '0' COMMENT '年龄', + `sex` bigint(20) NOT NULL DEFAULT '0' COMMENT '性别 0未知 1男 2女', + `creater` bigint(20) NOT NULL DEFAULT '0' COMMENT '创建人ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`), + KEY `idx_user_name` (`user_name`), + KEY `idx_nick_name` (`nick_name`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COMMENT='系统用户表'; + +INSERT INTO `sys_user` (`id`, `nick_name`, `avatar`, `user_name`, `password`, `email`, `phone`, `age`, `sex`, `creater`, `create_time`) VALUES +(1, '管理员', '', 'admin', '123456', 'wu434425608@163.com', '18866668888', 18, 1, 1, '2026-07-27 14:37:35'), +(2, '用户', '', 'user', '123456', '122', '1', 0, 0, 0, '2026-07-27 07:20:45'); + +DROP TABLE IF EXISTS `sys_role`; + +CREATE TABLE `sys_role` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `role_key` varchar(50) DEFAULT '', + `role_name` varchar(50) DEFAULT '', + `sort` int(11) DEFAULT '0', + `creater` bigint(20) DEFAULT '0', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COMMENT='系统角色'; + +INSERT INTO `sys_role` (`id`, `role_key`, `role_name`, `sort`, `creater`, `create_time`) VALUES +(1, 'admin', '管理员', 10, 0, '2026-07-28 09:25:19'), +(3, 'user', '用户', 30, 0, '2026-07-28 09:32:13'); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src-tauri/src/commands/role.rs b/src-tauri/src/commands/role.rs index b3dbac9..8ebf5b4 100644 --- a/src-tauri/src/commands/role.rs +++ b/src-tauri/src/commands/role.rs @@ -96,7 +96,7 @@ pub async fn role_page( .map_or(false, |role_name| !role_name.is_empty()); if has_role_key || has_role_name { - count_builder.push("WHERE 1=1"); + count_builder.push(" WHERE 1=1"); if has_role_key { count_builder.push(" AND role_key LIKE "); count_builder.push_bind(format!("%{}%", params.role_key.as_deref().unwrap()));