Add plugin SQL工具箱 v1.0.28#161
Conversation
- Initial commit - 删除文件 .trae - build: 🛠️ 同时兼容uTools和ZTools的配置 - feat(Excel转SQL、生成测试数据): ✨ 功能优化 - docs: 📝 修改版本号 - docs: 📝 CHANGELOG.md - feat(Excel转SQL): ✨ 优化表格,支持拖拽排序 - docs: 格式化CHANGELOG.md
There was a problem hiding this comment.
Code Review
This pull request implements a comprehensive SQL utility plugin for uTools, including features for text manipulation, data conversion, and code generation. The review identifies several high-priority issues, such as a dangerous global modification of ResizeObserver and context errors in exported utility functions. Critical bugs were found in the SQL export logic regarding quote escaping and in the ID card generation algorithm. Additionally, the feedback suggests performance optimizations for DDL parsing, more robust Vue instance management, and better support for multi-table DDL inputs.
| const _ResizeObserver = window.ResizeObserver; | ||
| window.ResizeObserver = class ResizeObserver extends _ResizeObserver{ | ||
| constructor(callback) { | ||
| callback = debounce(callback, 50); | ||
| super(callback); | ||
| } | ||
| } |
| */ | ||
| export function getAvatarUrl() { | ||
| const avatarStyle = commonConsts.avatarStyles[Math.floor(Math.random() * commonConsts.avatarStyles.length)]; | ||
| return `https://api.dicebear.com/9.x/${avatarStyle}/svg?seed=` + this.getStr(this.getNumber(4, 16), true, true, true, false); |
There was a problem hiding this comment.
在导出的函数 getAvatarUrl 中直接使用 this.getStr 和 this.getNumber 会导致运行时错误,因为在 ES 模块中,导出函数的 this 通常是 undefined。由于这些函数在同一个文件中定义,应该直接调用它们。
| return `https://api.dicebear.com/9.x/${avatarStyle}/svg?seed=` + this.getStr(this.getNumber(4, 16), true, true, true, false); | |
| return "https://api.dicebear.com/9.x/" + avatarStyle + "/svg?seed=" + getStr(getNumber(4, 16), true, true, true, false); |
| const columns = currentFields.map(field => field.name).join(', '); | ||
| const values = currentFields.map(field => `'${row[field.id]}'`).join(', '); | ||
| return `INSERT INTO ${tableName} (${columns}) | ||
| VALUES (${values});`; |
| return 'NULL'; | ||
| } | ||
| if (typeof value === 'string') { | ||
| return `'${value}'`; |
| let sequenceCode; | ||
| do { | ||
| sequenceCode = ('00' + Math.floor(Math.random() * 999)).slice(-3); | ||
| } while (sequenceCode.startsWith('0')); |
There was a problem hiding this comment.
身份证顺序码(第15-17位)的生成逻辑存在偏差:\n1. Math.random() * 999 只能生成 0-998 的随机数,无法生成 999。\n2. startsWith('0') 的过滤逻辑是不正确的,顺序码可以是 000 到 999 之间的任何值。建议直接生成 0-999 的随机数并补齐位数。
| let sequenceCode; | |
| do { | |
| sequenceCode = ('00' + Math.floor(Math.random() * 999)).slice(-3); | |
| } while (sequenceCode.startsWith('0')); | |
| const sequenceCode = Math.floor(Math.random() * 1000).toString().padStart(3, '0'); |
| let typeMapping = DEFAULT_TYPE_MAPPING; | ||
| try { | ||
| const savedMappings = localStorage.getItem('typeMappings'); | ||
| if (savedMappings) { | ||
| const customMappings = JSON.parse(savedMappings); | ||
| // 将自定义映射转换为对象形式 | ||
| typeMapping = {}; | ||
| customMappings.forEach(mapping => { | ||
| if (mapping.mysqlType && mapping.javaType) { | ||
| typeMapping[mapping.mysqlType] = mapping.javaType; | ||
| } | ||
| }); | ||
| // 合并默认映射,确保未自定义的类型有默认值 | ||
| Object.keys(DEFAULT_TYPE_MAPPING).forEach(key => { | ||
| if (!typeMapping[key]) { | ||
| typeMapping[key] = DEFAULT_TYPE_MAPPING[key]; | ||
| } | ||
| }); | ||
| } | ||
| } catch (e) { | ||
| console.error('加载类型映射失败,使用默认映射:', e); | ||
| typeMapping = DEFAULT_TYPE_MAPPING; | ||
| } |
| return null; | ||
| } | ||
|
|
||
| // 从原始数据中取出第一个对象,这里假设原始数据数组中只有一个对象 |
| // 拷贝为SQL | ||
| copyAsSQL() { | ||
| const sqlStatements = this.generatedData.map(row => { | ||
| const tableName = 'tableName'; |
| // 如果无法获取全局Vue实例,尝试通过document获取当前活跃的Vue实例 | ||
| const app = document.querySelector('#app'); | ||
| if (app && app.__vue__) { | ||
| return app.__vue__; |
|
你好👋 开发者 请问你是如何 改变 ztools 宿主窗口宽度 的 在我尝试更改 弹出窗口的宽度 发现无法修改窗口宽度 |









插件信息
本次变更
优化
截图 / 演示
自检清单
plugins/sql-utils/目录此 PR 由 ztools-plugin-cli 自动管理:每次
ztools publish在分支上追加一个 commit,PR 链接保持不变。