Move-Item 帮助信息

本文介绍 PowerShell 中 Move-Item 命令的详细使用方法,包括命令语法、参数说明及示例。Move-Item 用于在不同位置间移动文件或目录,并能更改目标名称。
如下说明是翻译PowerShell: help Move-Item 产生的帮助信息.
译者: Edengundam(马涛)
 
Move-Item
 
大纲
从一个位置移动项到另一个位置.
 
语法
Move-Item [-path] <string[]> [[-destination] <string>] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]
 
Move-Item [-literalPath] <string[]> [[-destination] <string>] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]
 
详细描述
Move-Item cmdlet从一个位置移动一项(包括属性, 内容和子项)到另一个位置. 这些位置必须由同一提供程序支持. 例如, 它能够从一个目录移动一个文件或子目录到另一个目录; 或者从注册表项中移动注册表子项到另一项中. 当你移动一项时, 它被添加到新的位置并从原始位置删除.
 
参数
 
-path <string[]>
指定项的当前位置路径. 默认值为当前目录. 允许使用通配符.
 
强制参数?
true
参数位置?
1
默认值
<当前位置>
允许从管道绑定输入?
true (根据值, 根据属性名)
允许通配符扩展?
true
 
-destination <string>
制定项目被移动到的位置路径. 默认值为当前目录. 允许使用通配符, 但是通配符匹配结果必须是单一的路径.
 
要改变移动的项名称, 在参数Destination的值中指定一个新的名称.
 
强制参数?
false
参数位置?
2
默认值
<当前位置>
允许从管道绑定输入?
true (根据属性名)
允许通配符扩展?
true
 
-include <string[]>
移动指定的项. 此参数值用于限定Path参数. 输入一个路径元素或模式, 例如"*.txt"(此参数允许通配符).允许使用通配符.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
false
允许通配符扩展?
true
 
-exclude <string[]>
忽略指定的项. 此参数值用于限定Path参数. 输入一个路径元素或模式, 例如"*.txt"(此参数允许通配符).允许使用通配符.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
false
允许通配符扩展?
true
 
-filter <string>
指定特定provider格式或语言的过滤器.此参数值用于限定Path参数. 过滤器的语法取决于provider(是否支持通配符也依赖provider). 过滤器相比其他参数更加有效, 主要因为provider取值时候使用过滤器, 而不是等到provider将所有内容返回后, Windows PowerShell 过滤对象.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
false
允许通配符扩展?
false
 
-force <SwitchParameter>
在不破坏安全性的前提下, 能够避免影响命令成功执行的限制条件, 例如: Force参数能够覆盖具有只读属性的文件或创建路径中的必要成分, 但是不会改变任何文件的权限.
 
强制参数?
false
参数位置?
named
默认值
False
允许从管道绑定输入?
false
允许通配符扩展?
false
 
-passThru <SwitchParameter>
输出此命令创建的对象到管道中. 默认情况下, 此命令不会将对象输出到管道.
 
强制参数?
false
参数位置?
named
默认值
False
允许从管道绑定输入?
false
允许通配符扩展?
false
 
-credential <PSCredential>
使用其他凭证进行资源访问认证. <Credential>代表着用户名(例如: "User01""Domain01/User01") 或者PSCredential对象(例如: 通过Get-Credential cmdlet取得的对象). 如果此处使用用户名, 命令执行时会提示输入该用户密码. 尽管此参数出现, 但是并非所有Windows PowerShell核心cmdletsproviders支持此功能.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
true (根据属性名)
允许通配符扩展?
false
 
-literalPath <string[]>
指定项的当前位置路径. Path不同, LiteralPath的值被直接使用, 不会对任何通配符进行解释. 如果路径中包含了转义字符, 需要将路径用单引号保护. 单引号指示Windows PowerShell不对字符串中的转义字符进行处理.
 
强制参数?
true
参数位置?
1
默认值
 
允许从管道绑定输入?
true (根据属性名)
允许通配符扩展?
false
 
-whatIf
描述执行此命令将会发生的现象, 不会真正执行此命令.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
false
允许通配符扩展?
false
 
-confirm
执行命令前提示你进行确认.
 
强制参数?
false
参数位置?
named
默认值
 
允许从管道绑定输入?
false
允许通配符扩展?
false
 
<公共参数>
此命令支持公共参数: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. 更多信息, 输入, "get-help about_commonparameters".
 
输入类型
String
 
注意
 
更多信息, 输入"Get-Help Move-Item -detailed". 需要技术信息, 输入"Get-Help Move-Item -full".
 
Move-Item能够在相同提供程序支持的不同驱动器上移动文件, 但是只能在同一个驱动器上移动目录.
 
由于Move-Item命令能够移动项的属性, 内容和子项, 默认情况下所有移动都是递归的.
 
如果需要为该命令提供多个参数, 请使用逗号进行分隔. 例如, "<parameter-name> <value1>, <value2>".
 
你可以使用Move-Item内建别名, "move", "mv""mi". 需要更多信息, 查看 About_Alias.
 
1
 
C:/PS>move-item -path C:/test.txt -destination E:/Temp/tst.txt
 
此命令从C:驱动器上, 移动Test.txt文件到E:/Temp目录并将名称"test.txt"改为" tst.txt".
 
2
 
C:/PS>move-item -path C:/Temp -destination C:/Logs
 
此命令移动目录C:/Temp及其所有内容到目录C:/Logs. 目录Temp以及其所有子目录和文件, 都出现在目录Logs.
 
3
 
C:/PS>move-item -path ./*.txt -destination C:/Logs
 
此命令移动当前目录((.)表示当前目录)下所有文本文件(*.txt)到目录C:/Logs.
 
4
 
C:/PS>gci . -recurse -include *.txt | move-item -dest C:/ps-test/TextFiles
 
此命令递归地将当前目录及其子目录下的所有文本文件移动到目录C:/TextFiles.
 
命令使用了Get-Childitem cmdlet取得当前目录((.)表示当前目录)下及其所有子目录下具有*.txt文件扩展名的文件. 它通过指定参数Recurse来进行递归操作, 通过参数Include来限制只取得*.txt文件.
 
管道运算符(|)将命令的输出发送给Move-Item, 后者将文本文件移动到目录TextFiles.
 
如果要移动的文件在C:/Textfiles中存在同名文件, Move-Item显示一个错误信息并继续执行, 但是只移动那些在C:/Textfiles中没有重名的文件. 其他的文件则保留在原始的目录中.
 
默认情况下Get-Childitem是不会列出隐藏文件. 要移动隐藏文件, 使用Get-Childitem 的参数Force.
 
5
 
C:/PS>move-item hklm:/software/mycompany/* hklm:/software/mynewcompany
 
此命令将HKLM/Software下的MyCompany注册表项的注册表项和值移动到MyNewCompany项中. 通配符(*)指出MyCompany项中的所有内容都需要被移动, 但是不包括项本身. 此命令中, 参数PathDestination的名称都可以被省略.
 
6
 
C:/PS>move-item -literalpath 'Logs[Sept`06]' -destination 'Logs[2006]'
 
此命令移动Logs[Sept`06]目录(及其内容)到目录Logs[2006].
 
使用参数LiteralPath代替Path, 这是因为原始的目录名中包含通配符[]. 路径使用了单引号(' ')括起来, 这样反引号符号(`)就不会被曲解.
 
参数Destination不需要是路径的字面值(译注: literal path, 就是改路径本身, 不经过任何的通配符匹配), Destination也必须被括在单引号中, 因为方括号也可能导致被曲解.
 
相关链接
Clear-Item
Get-Item
Invoke-Item
Set-Item
New-Item
Remove-Item
Rename-Item
Copy-Item
about_namespace
 
PS C:\Users\Administrator> # Ultimate-ProjectCleanup.ps1 >> $projectRoot = "E:\ProjectEcosystem\ProjectMonitor" >> >> # 1. 创建完整的文件夹结构 >> $folders = @( >> "SQLite", >> "Logs", >> "Database", >> "Scripts", >> "Config", >> "Binaries", >> "SourceFiles", >> "Documentation", >> "Libraries", >> "BuildOutputs" >> ) >> >> foreach ($folder in $folders) { >> $path = Join-Path $projectRoot $folder >> if (-not (Test-Path $path)) { >> New-Item -ItemType Directory -Path $path -Force | Out-Null >> } >> } >> >> # 2. 增强的SQLite文件移动(包含PDB和XML) >> $sqlitePatterns = @( >> "System.Data.SQLite.*", >> "SQLite.Interop.*", >> "sqlite3.*", >> "SQLite.NET.*" >> ) >> >> foreach ($pattern in $sqlitePatterns) { >> $files = Get-ChildItem -Path $projectRoot -Filter $pattern -File >> foreach ($file in $files) { >> $destDir = Join-Path $projectRoot "SQLite" >> $destPath = Join-Path $destDir $file.Name >> >> if (-not (Test-Path $destDir)) { >> New-Item -ItemType Directory -Path $destDir -Force | Out-Null >> } >> >> Move-Item -Path $file.FullName -Destination $destPath -Force -ErrorAction SilentlyContinue >> if ($?) { >> Write-Host "✅ 已移动SQLite文件: $($file.Name) -> SQLite\" -ForegroundColor Cyan >> } >> } >> } >> >> # 3. 移动所有程序数据库文件(PDB)到BuildOutputs >> $pdbFiles = Get-ChildItem -Path $projectRoot -Filter "*.pdb" -File >> foreach ($pdb in $pdbFiles) { >> $destDir = Join-Path $projectRoot "BuildOutputs" >> $destPath = Join-Path $destDir $pdb.Name >> >> Move-Item -Path $pdb.FullName -Destination $destPath -Force >> Write-Host "✅ 已移动PDB文件: $($pdb.Name) -> BuildOutputs\" -ForegroundColor Cyan >> } >> >> # 4. 移动所有XML文档文件到Documentation >> $xmlFiles = Get-ChildItem -Path $projectRoot -Filter "*.xml" -File >> foreach ($xml in $xmlFiles) { >> $destDir = Join-Path $projectRoot "Documentation" >> $destPath = Join-Path $destDir $xml.Name >> >> Move-Item -Path $xml.FullName -Destination $destPath -Force >> Write-Host "✅ 已移动文档: $($xml.Name) -> Documentation\" -ForegroundColor Cyan >> } >> >> # 5. 移动其他库文件到Libraries >> $libraryPatterns = @("*.dll", "*.lib", "*.a") >> foreach ($pattern in $libraryPatterns) { >> $files = Get-ChildItem -Path $projectRoot -Filter $pattern -File >> foreach ($file in $files) { >> # 排除已处理的SQLite文件 >> if ($file.FullName -notlike "*\SQLite\*") { >> $destDir = Join-Path $projectRoot "Libraries" >> $destPath = Join-Path $destDir $file.Name >> >> Move-Item -Path $file.FullName -Destination $destPath -Force >> Write-Host "✅ 已移动库文件: $($file.Name) -> Libraries\" -ForegroundColor Cyan >> } >> } >> } >> >> # 6. 项目感知型清理 - 保留项目结构 >> $projectFolders = @("APIServer", "BackendService", "DataAnalysis", "EcoMonitor", "MyApp", "MyWebApp") >> foreach ($project in $projectFolders) { >> $projectPath = Join-Path $projectRoot $project >> if (Test-Path $projectPath) { >> Write-Host "🔍 清理项目: $project" -ForegroundColor Yellow >> >> # 清理项目中的临时文件 >> $tempPatterns = @("*.tmp", "*.bak", "Thumbs.db") >> foreach ($pattern in $tempPatterns) { >> Get-ChildItem -Path $projectPath -Filter $pattern -File -Recurse -ErrorAction SilentlyContinue | >> Remove-Item -Force -ErrorAction SilentlyContinue >> } >> >> # 清理项目中的空文件夹 >> Get-ChildItem -Path $projectPath -Directory -Recurse | >> Where-Object { >> $_.GetFiles().Count -eq 0 -and >> $_.GetDirectories().Count -eq 0 >> } | >> Remove-Item -Force -Recurse -ErrorAction SilentlyContinue >> } >> } >> >> # 7. 生成目录结构报告 >> $structureReport = Join-Path $projectRoot "Project_Structure_Report.txt" >> tree $projectRoot /F /A | Out-File -FilePath $structureReport -Encoding UTF8 >> >> # 8. 最终结果展示 >> Write-Host "✨ 终极清理完成!项目目录完美整理 ✨" -ForegroundColor Green >> Write-Host "当前目录结构:" >> tree $projectRoot /F /A >> Write-Host "完整报告已保存至: $structureReport" -ForegroundColor Yellow >> ✅ 已移动PDB文件: Installer.pdb -> BuildOutputs\ ✅ 已移动PDB文件: SQLite.Designer.pdb -> BuildOutputs\ ✅ 已移动PDB文件: test.pdb -> BuildOutputs\ ✅ 已移动PDB文件: testef6.pdb -> BuildOutputs\ ✅ 已移动PDB文件: testlinq.pdb -> BuildOutputs\ ✅ 已移动文档: SQLite.Designer.xml -> Documentation\ ✅ 已移动库文件: SQLite.Designer.dll -> Libraries\ 🔍 清理项目: APIServer 🔍 清理项目: BackendService 🔍 清理项目: DataAnalysis 🔍 清理项目: EcoMonitor 🔍 清理项目: MyApp 🔍 清理项目: MyWebApp ✨ 终极清理完成!项目目录完美整理 ✨ 当前目录结构: 卷 ="模型响应", 的文件夹 PATH 列表 卷序列号为 7648-2CD3 E:\PROJECTECOSYSTEM\PROJECTMONITOR | Project_Structure_Report.txt | +---APIServer | | .gitignore | | APIServer.code-workspace | | package.json | | | \---src | index.js | +---BackendService | | .gitignore | | BackendService.code-workspace | | BackendService.sln | | | \---src | \---BackendService | BackendService.csproj | Program.cs | +---Binaries | Installer.exe | test.exe | testef6.exe | testlinq.exe | +---BuildOutputs | Installer.pdb | SQLite.Designer.pdb | test.pdb | testef6.pdb | testlinq.pdb | +---Config | System.Data.SQLite.dll.config | test.exe.config | testef6.exe.config | testlinq.exe.config | +---DataAnalysis | | .gitignore | | DataAnalysis.code-workspace | | requirements.txt | | | \---src | main.py | +---Database | northwindEF.db | project_state.db | +---Documentation | SQLite.Designer.xml | +---EcoMonitor | | .gitignore | | README.md | | | \---config | settings.psd1 | +---Libraries | SQLite.Designer.dll | +---Logs +---MyApp | | .gitignore | | MyApp.code-workspace | | | \---src | index.html | main.js | style.css | +---MyWebApp | | .gitignore | | MyWebApp.code-workspace | | | \---src | index.html | main.js | style.css | +---Scripts | Initialize-DevEnv.psm1 | Monitor-Project.ps1 | Start-Ecosystem.ps1 | +---SourceFiles | db_init.py | monitor.py | state_analyzer.py | \---SQLite System.Data.SQLite.dll System.Data.SQLite.EF6.dll System.Data.SQLite.EF6.pdb System.Data.SQLite.EF6.xml System.Data.SQLite.Linq.dll System.Data.SQLite.Linq.pdb System.Data.SQLite.Linq.xml System.Data.SQLite.pdb System.Data.SQLite.xml 完整报告已保存至: E:\ProjectEcosystem\ProjectMonitor\Project_Structure_Report.txt PS C:\Users\Administrator> # 处理PDB文件 >> Get-ChildItem -Path $projectRoot -Filter "*.pdb" -File | >> Move-Item -Destination "$projectRoot\BuildOutputs" >> >> # 处理XML文档 >> Get-ChildItem -Path $projectRoot -Filter "*.xml" -File | >> Move-Item -Destination "$projectRoot\Documentation" >> PS C:\Users\Administrator> # 只清理项目目录中的临时文件,保留项目结构 >> $projectFolders | ForEach-Object { >> Get-ChildItem -Path (Join-Path $projectRoot $_) -Filter "*.tmp" -Recurse | >> Remove-Item -Force >> } >> PS C:\Users\Administrator> # 创建目录结构报告 >> tree $projectRoot /F /A | Out-File "Project_Structure_Report.txt" >> PS C:\Users\Administrator> # Permanent-ProjectOrganizer.ps1 >> $organizerScript = @" >> # 自动维护脚本 - 每天运行 >> `$projectRoot = "E:\ProjectEcosystem\ProjectMonitor" >> >> # 1. 清理临时文件 >> Get-ChildItem -Path `$projectRoot -Include *.tmp, *.bak, Thumbs.db -Recurse | >> Remove-Item -Force -ErrorAction SilentlyContinue >> >> # 2. 自动分类新文件 >> `$watcher = @{ >> "*.ps*1" = "Scripts" >> "*.exe" = "Binaries" >> "*.dll" = "Libraries" >> "*.pdb" = "BuildOutputs" >> "*.xml" = "Documentation" >> "*.db" = "Database" >> "*.py" = "SourceFiles" >> "*.json" = "Config" >> } >> >> Get-ChildItem -Path `$projectRoot -File | ForEach-Object { >> foreach (`$rule in `$watcher.GetEnumerator()) { >> if (`$_.Name -like `$rule.Key) { >> `$targetDir = Join-Path `$projectRoot `$rule.Value >> if (-not (Test-Path `$targetDir)) { >> New-Item -ItemType Directory -Path `$targetDir | Out-Null >> } >> Move-Item -Path `$_.FullName -Destination `$targetDir -Force >> break >> } >> } >> } >> >> # 3. 每周生成报告 >> if ((Get-Date).DayOfWeek -eq [System.DayOfWeek]::Monday) { >> tree `$projectRoot /F /A | Out-File (Join-Path `$projectRoot "Weekly_Structure_Report.txt") >> } >> "@ >> >> Set-Content -Path "E:\ProjectEcosystem\ProjectOrganizer.ps1" -Value $organizerScript >> PS C:\Users\Administrator> # 创建Windows计划任务 >> $action = New-ScheduledTaskAction -Execute "PowerShell.exe" ` >> -Argument "-ExecutionPolicy Bypass -File `"E:\ProjectEcosystem\ProjectOrganizer.ps1`"" >> >> $trigger = New-ScheduledTaskTrigger -Daily -At 3am >> >> Register-ScheduledTask -Action $action -Trigger $trigger ` >> -TaskName "ProjectMonitor_Organizer" -Description "每日自动整理项目目录" ` >> -User "SYSTEM" -RunLevel Highest >> TaskPath TaskName State -------- -------- ----- \ ProjectMonitor_Organizer Ready PS C:\Users\Administrator>
最新发布
08-14
<template> <div v-show="active === flag" class="step-main"> <div class="step-content"> <el-form ref="baseForm" :model="baseFormCurr" :rules="rules" label-width="105px"> <el-row :gutter="10"> <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24"> <el-form-item label="表名称" prop="tableName"> <el-input v-model="baseFormCurr.tableName" autocomplete="off"></el-input> </el-form-item> </el-col> <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24"> <el-form-item label="表类型" prop="tableType"> <el-select v-model="baseFormCurr.tableType" :disabled="formState.tableType" placeholder="请选择" style="width: 100%" @change="tableTypeChange"> <el-option v-for="item in dictCurr.table_type" :key="item.dictValue" :label="item.dictName" :value="item.dictValue" ></el-option> </el-select> </el-form-item> </el-col> <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24"> <el-form-item label="描述" prop="comments"> <el-input v-model="baseFormCurr.comments" autocomplete="off" maxlength="100" show-word-limit ></el-input> </el-form-item> </el-col> <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24"> <el-form-item label="数据库类型" prop="jdbcType"> <el-select ref="jdbcType" v-model="baseFormCurr.jdbcType" :disabled="formState.jdbcType" placeholder="请选择" style="width: 100%" @change="jdbcTypeChange"> <el-option v-for="item in dictCurr.jdbc_type" :key="item.dictValue" :label="item.dictName" :value="item.dictValue" ></el-option> </el-select> </el-form-item> </el-col> <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24"> <el-form-item label="备注" prop="remark"> <el-input v-model="baseFormCurr.remark" autocomplete="off" maxlength="120" show-word-limit ></el-input> </el-form-item> </el-col> </el-row> </el-form> <vab-query-form> <vab-query-form-left-panel> <el-button :disabled="!baseFormCurr.jdbcType" icon="el-icon-plus" type="primary" @click="columnHandleAdd"> 添加 </el-button> <el-button icon="el-icon-plus" type="primary" @click="dialogVisible = true"> 常用字段 </el-button> <el-button :disabled="!selectRows.length > 0" icon="el-icon-delete" type="danger" @click="columnHandleDelete" > 删除 </el-button> </vab-query-form-left-panel> </vab-query-form> <el-form ref="tableForm" :model="{'tableForm': tableFormCurr}"> <el-table :data="tableFormCurr" :element-loading-text="elementLoadingText" border @selection-change="setSelectRows" > <el-table-column show-overflow-tooltip type="selection"></el-table-column> <el-table-column align="center" label="拖动" show-overflow-tooltip width="60" > <template v-slot="scope"> <el-button circle class="move-btn" icon="el-icon-d-caret" ></el-button> </template> </el-table-column> <el-table-column label="字段名称" min-width="200" prop="fieldName" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.fieldName'" :rules="columnRules.fieldName" class="el-form-item-table" > <el-input v-model="scope.row.fieldName" :disabled="scope.row.disabled" style="width: 100%"/> </el-form-item> </template> </el-table-column> <el-table-column label="字段类型" min-width="180" prop="fieldType" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.fieldType'" :rules="columnRules.fieldType" class="el-form-item-table" > <el-select v-model="scope.row.fieldType" :disabled="scope.row.disabled" default-first-option="" filterable placeholder="请选择" style="width: 100%"> <el-option v-for="item in baseDictData.fieldList" :key="item" :label="item" :value="item" ></el-option> </el-select> </el-form-item> </template> </el-table-column> <el-table-column label="字段长度" min-width="140" prop="fieldLength" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.fieldLength'" class="el-form-item-table" > <el-input-number v-model="scope.row.fieldLength" :disabled="scope.row.disabled" :max="20000" :min="0" controls-position="right" style="width: 100%" ></el-input-number> </el-form-item> </template> </el-table-column> <el-table-column label="字段精度" min-width="140" prop="fieldPrecision" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.fieldComments'" class="el-form-item-table" > <el-input-number v-model="scope.row.fieldPrecision" :disabled="scope.row.disabled" :max="100" :min="0" controls-position="right" style="width: 100%" ></el-input-number> </el-form-item> </template> </el-table-column> <el-table-column label="字段描述" min-width="240" prop="fieldComments" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.fieldComments'" :rules="columnRules.fieldComments" class="el-form-item-table" > <el-input v-model="scope.row.fieldComments" :disabled="scope.row.disabled" maxlength="100" show-word-limit style="width: 100%"/> </el-form-item> </template> </el-table-column> <el-table-column label="主键" min-width="80" prop="izPk" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.izPk'" class="el-form-item-table" > <el-switch v-model="scope.row.izPk" :active-value="1" :disabled="scope.row.disabled" :inactive-value="0" @change="pKChange(scope.row)" > </el-switch> </el-form-item> </template> </el-table-column> <el-table-column label="非空" min-width="80" prop="izNotNull" show-overflow-tooltip > <template v-slot="scope"> <el-form-item :prop="'tableForm.'+scope.$index+'.izNotNull'" class="el-form-item-table" > <el-switch v-model="scope.row.izNotNull" :active-value="1" :disabled="scope.row.disabled || scope.row.izPk === 1" :inactive-value="0" > </el-switch> </el-form-item> </template> </el-table-column> </el-table> </el-form> </div> <step-footer ref="step-footer" :flag="flag" :info-data="{ obj: this, baseForm: baseFormCurr, tableForm: tableFormCurr }" :max-flag="maxFlag" :min-flag="minFlag" ></step-footer> <!-- 选择预制字段--> <el-dialog :before-close="handleClose" :visible.sync="dialogVisible" append-to-body title="选择常见字段" width="30%"> <div> <template v-for="item in BuiltInFields"> <el-checkbox v-model="BuiltInFieldsSelect" :label="item.fieldName" border style="margin: 5px" @change="changeBuiltInFieldsSelect"></el-checkbox> </template> </div> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="AddDefaultFields">确 定</el-button> </span> </el-dialog> </div> </template> <script> import {isCode, isNull} from "@/utils/validate"; import StepFooter from "./footer/StepFooter.vue" import {deepClone} from "@/utils/clone"; import Sortable from "sortablejs"; import {uuid} from "@/utils"; import {getFieldTypes, getJavaFieldTypesBySafety} from "@/api/generator/tableManagement"; import {isNotNull} from "@/utils/valiargs"; import { useGlobalStore } from '@/pinia/global'; let state = useGlobalStore(); export default { name: "TableDataStep", components: {Sortable, StepFooter}, props: { active: { type: Number, default: () => { return 1; }, }, minFlag: { type: Number, default: () => { return 1; }, }, maxFlag: { type: Number, default: () => { return 1; }, }, baseForm: { type: Object, default: () => { return {}; }, }, tableForm: { type: Array, default: () => { return []; }, }, dict: { type: Object, default: () => { return {}; }, }, baseDictData: { type: Object, default: () => { return { fieldList: [], JavaFieldMap: {}, }; }, } }, data() { const validateTableName = (rule, value, callback) => { if (isNull(value)) { callback(new Error("请输入表名")); } if (!isCode(value)) { callback(new Error("表名只能为字母、数字或下划线")); } else { callback(); } }; const validateName = (rule, value, callback) => { if (!isCode(value)) { callback(new Error("只能为字母、数字或下划线")); } else { callback(); } }; return { BuiltInFieldsSelect: [],//已选中的字段 BuiltInFields: [ { "encryptData": null, "fieldName": "id", "fieldType": "bigint", "fieldLength": 19, "fieldPrecision": 0, "fieldComments": "唯一主键", "izPk": 1, "izNotNull": 1, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 0, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "org_ids", "fieldType": "varchar", "fieldLength": 500, "fieldPrecision": 0, "fieldComments": "父级主键集合", "izPk": 0, "izNotNull": 0, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 1, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "tenant_id", "fieldType": "bigint", "fieldLength": 19, "fieldPrecision": 0, "fieldComments": "多租户ID", "izPk": 0, "izNotNull": 0, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 8, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "create_by", "fieldType": "bigint", "fieldLength": 19, "fieldPrecision": 0, "fieldComments": "创建者", "izPk": 0, "izNotNull": 1, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 10, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "create_time", "fieldType": "datetime", "fieldLength": 0, "fieldPrecision": 0, "fieldComments": "创建时间", "izPk": 0, "izNotNull": 1, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 11, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "update_by", "fieldType": "bigint", "fieldLength": 19, "fieldPrecision": 0, "fieldComments": "修改人", "izPk": 0, "izNotNull": 1, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 12, "validateType": null, "queryType": null, "disabled": false }, { "encryptData": null, "fieldName": "update_time", "fieldType": "datetime", "fieldLength": 0, "fieldPrecision": 0, "fieldComments": "修改时间", "izPk": 0, "izNotNull": 1, "izShowList": null, "izShowForm": null, "javaType": "String", "showType": null, "dictTypeCode": null, "sort": 13, "validateType": null, "queryType": null, "disabled": false }, { "fieldName": "delected", "sort": 8, "izPk": 0, "izNotNull": 1, "izShowList": 0, "izShowForm": 0, "queryType": "", "fieldType": "int", "fieldLength": 1, "fieldPrecision": 0, "fieldComments": "删除", "javaType": "", "validateType": "", "showType": "", "dictTypeCode": "", "disabled": false }, { "fieldName": "version", "sort": 8, "izPk": 0, "izNotNull": 1, "izShowList": 0, "izShowForm": 0, "queryType": "", "fieldType": "int", "fieldLength": 1, "fieldPrecision": 0, "fieldComments": "乐观锁", "javaType": "", "validateType": "", "showType": "", "dictTypeCode": "", "disabled": false } ], dialogVisible: false,//选址内置字段 // 标示 flag: 1, title: "数据库表设置", dictCurr: [], baseFormCurr: {}, tableFormCurr: [], formState: { jdbcType: false, tableType: false, }, rules: { tableName: [ {required: true, trigger: "blur", validator: validateTableName}, ], tableType: [ {required: true, trigger: "change", message: "请选择表类型"}, ], jdbcType: [ {required: true, trigger: "change", message: "请选择数据库类型"}, ], comments: [ {required: true, trigger: "blur", message: "请输入描述"}, ], }, treeName: "parent_id", // 新增字段模版 columnFormTemp: { id: "", sort: 0, izPk: 0, izNotNull: 0, izShowList: 0, izShowForm: 0, queryType: "", fieldName: "", fieldType: "", fieldLength: 0, fieldPrecision: 0, fieldComments: "", javaType: "", validateType: "", showType: "", dictTypeCode: "", disabled: false, }, columnRules: { fieldName: [ {required: true, message: "请选择字段名称", trigger: "blur"}, {required: true, trigger: "blur", validator: validateName}, ], fieldType: [ {required: true, message: "请选择字段类型", trigger: "change"}, ], fieldComments: [ {required: true, message: "请输入字段描述", trigger: "blur"}, ] }, layout: "total, sizes, prev, pager, next, jumper", selectRows: "", elementLoadingText: "正在加载...", }; }, created() { // 告诉父节点 自己的 flag 编号 this.$emit("inform-flag", this.flag, this.title); }, mounted() { // 拷贝 props this.baseFormCurr = deepClone(this.baseForm); this.tableFormCurr = deepClone(this.tableForm); this.dictCurr = deepClone(this.dict); // 数据库字段类型 // this.dictCurr.field_type = this.$getDictList(this.baseFormCurr.jdbcType + "_data_type"); // 改成自己项目的字典项获取方式 // this.dict = state.sysDict; // this.dictCurr.field_type = state.sysDict.table_type; let dataType = this.baseFormCurr.jdbcType + "_data_type"; // JavaScript 对象支持两种属性访问方式:1点符号:object.propertyName ,适用于静态属性名。 2方括号符号:object[propertyName] ,适用于动态属性名,propertyName 可以是一个变量或表达式。 this.dictCurr.field_type = state.sysDict[dataType]; // 表拖动 this.rowDrop(); // 初始化数据 this.doGetFieldData(); }, watch: { baseForm(newV, oldV) { this.baseFormCurr = deepClone(newV); }, tableForm(newV, oldV) { this.tableFormCurr = deepClone(newV); }, dict(newV, oldV) { this.dictCurr = deepClone(newV); // 数据库字段类型 // this.dictCurr.field_type = this.$getDictList(this.baseFormCurr.jdbcType + "_data_type"); // 改成自己项目的字典项获取方式 // this.dict = state.sysDict; // this.dictCurr.field_type = state.sysDict.table_type; let dataType = this.baseFormCurr.jdbcType + "_data_type"; // JavaScript 对象支持两种属性访问方式:1点符号:object.propertyName ,适用于静态属性名。 2方括号符号:object[propertyName] ,适用于动态属性名,propertyName 可以是一个变量或表达式。 this.dictCurr.field_type = state.sysDict[dataType]; }, }, methods: { handleClose() { this.dialogVisible = false }, changeBuiltInFieldsSelect(e) { this.BuiltInFieldsSelect = this.removeElementsFromArray(this.BuiltInFieldsSelect, this.tableFormCurr) }, removeElementsFromArray(A, B) { A = A.filter(a => { let isEqual = B.some(b => b.fieldName === a); if (isEqual) { this.$message.error(`已存在字段:${a}`) } return !isEqual; }); return A; }, //添加默认字段 AddDefaultFields(params) { console.log(this.BuiltInFieldsSelect) for (const param of this.BuiltInFieldsSelect) { this.AddDefaultFields2(param) } this.dialogVisible = false }, //方法2 AddDefaultFields2(title) { let temp = null for (const tempElement of this.BuiltInFields) { if (tempElement.fieldName == title) { temp = tempElement } } this.tableFormCurr.push(temp); }, // 数据库类型发生改动 jdbcTypeChange(newValue) { const _this = this; this.tableFormCurr.jdbcType = this.$refs.jdbcType.value; this.$baseConfirm("更换数据库类型将会清空当前已设字段,你确定要更换吗", null, () => { // 改为新值 _this.tableFormCurr.jdbcType = newValue; // 加载字典 // _this.dictCurr.field_type = _this.$getDictList(_this.baseFormCurr.jdbcType + "_data_type"); // 改成自己项目的字典项获取方式 // this.dict = state.sysDict; // this.dictCurr.field_type = state.sysDict.table_type; let dataType = this.baseFormCurr.jdbcType + "_data_type"; // JavaScript 对象支持两种属性访问方式:1点符号:object.propertyName ,适用于静态属性名。 2方括号符号:object[propertyName] ,适用于动态属性名,propertyName 可以是一个变量或表达式。 this.dictCurr.field_type = state.sysDict[dataType]; // 清空已有字段数据 _this.tableFormCurr = []; // 初始化数据 this.doGetFieldData(); }); }, // 表类型发生改动 tableTypeChange(newValue) { if (newValue === '0') { // 删除 parent_id 字段 for (let i = this.tableFormCurr.length - 1; i >= 0; i--) { let item = this.tableFormCurr[i]; if (item.fieldName === this.treeName) { this.tableFormCurr.splice(i, 1); break; } } } else if (newValue === '1') { // 删除 parent_id 字段 for (let i = this.tableFormCurr.length - 1; i >= 0; i--) { let item = this.tableFormCurr[i]; if (item.fieldName === this.treeName) { this.tableFormCurr.splice(i, 1); break; } } // 增加 parent_id 字段 let tmp = deepClone(this.columnFormTemp); tmp.disabled = true; tmp.fieldName = this.treeName; tmp.fieldType = "bigint"; tmp.fieldLength = 20; tmp.fieldComments = "上级ID"; tmp.javaType = "Integer"; tmp.izNotNull = 1; this.columnHandleAdd(tmp); } }, // 主键改动 pKChange(el) { if (!isNull(el)) { // 如果主键选中 则默认选中不可为空 if (el.izPk === 1) { el.izNotNull = 1; } else { el.izNotNull = 0; } } }, // ============================== async doGetFieldData() { this.$emit("loading"); // 通知父级 锁定当前表 this.$emit("inform-data", { fieldList: await this.doGetFieldTypes(), JavaFieldMap: await this.doGetJavaFieldTypesBySafety(), }); this.$emit("unLoading"); }, // 获得 数据类型 async doGetFieldTypes() { // const { data } = await getFieldTypes(); // 改成自己项目的数据返回格式 const res = await getFieldTypes(); const data = res.result.opsliData.data; if (isNotNull(data)) { return data; } return null; }, // 获得 Java 类型 (安全兜底模式) async doGetJavaFieldTypesBySafety() { // const { data } = await getJavaFieldTypesBySafety(); // 改成自己项目的数据返回格式 const res = await getJavaFieldTypesBySafety(); const data = res.result.opsliData.data; if (isNotNull(data)) { return data; } return null; }, // 行添加 columnHandleAdd(params) { let temp; if (!isNull(params) && !(params instanceof MouseEvent)) { temp = params; } else { temp = deepClone(this.columnFormTemp); } temp.id = "temp_" + uuid() if (this.tableFormCurr == null || this.tableFormCurr.length === 0) { temp.sort = 0; } else { temp.sort = this.tableFormCurr.length; } this.tableFormCurr.push(temp); }, // 行删除 columnHandleDelete(row) { if (row.id) { this.$baseConfirm("你确定要删除当前字段吗", null, () => { for (let i = this.tableFormCurr.length - 1; i >= 0; i--) { let item = this.tableFormCurr[i]; if (item.id === row.id) { // 树装接口 不允许删除 parent_id 字段 if (this.tableFormCurr.tableType === '1') { if (item.fieldName !== this.treeName) { this.tableFormCurr.splice(i, 1); } } else { this.tableFormCurr.splice(i, 1); } break; } } }); } else if (this.selectRows.length > 0) { const ids = this.selectRows.map((item) => item.id); this.$baseConfirm("你确定要删除当前字段吗", null, () => { for (let i = this.tableFormCurr.length - 1; i >= 0; i--) { let item = this.tableFormCurr[i]; if (ids.indexOf(item.id) !== -1) { // 树装接口 不允许删除 parent_id 字段 if (this.tableFormCurr.tableType === '1') { if (item.fieldName !== this.treeName) { this.tableFormCurr.splice(i, 1); } } else { this.tableFormCurr.splice(i, 1); } } } }); } else { this.$baseMessage("未选中任何行", "error"); return false; } }, // 行选中 setSelectRows(val) { this.selectRows = val; }, //行拖拽 rowDrop() { const tbody = this.$refs["tableForm"].$el .querySelector(".el-table__body-wrapper tbody"); const _this = this Sortable.create(tbody, { // 只能纵向拖动 axis: "y", // 限制触发事件只能某个元素可以触发 handle: ".move-btn", // 如果设置成true,则被拖拽的元素在返回新位置时,会有一个动画效果。 revert: true, // 如果设置成true,则元素被拖动到页面边缘时,会自动滚动。 scroll: true, onEnd({oldIndex, newIndex}) { _this.tableFormCurr[oldIndex].sort = newIndex; // 如果是 从后往前 移动 则 当前项改为newIndex 而 原newIndex 往后的所有内容全部向后顺产移动 if (oldIndex > newIndex) { for (let i = oldIndex; i > newIndex; i--) { _this.tableFormCurr[i - 1].sort = i; } } // 如果是 从前往后 移动 则 当前项改为newIndex 而 原newIndex 往后的所有内容全部向前顺产移动 else { for (let i = oldIndex; i < newIndex; i++) { _this.tableFormCurr[i + 1].sort = i; } } } }) }, }, }; </script> 这段代码是一个vue文件, 代码语法的框架是element-ui, 版本是2.15.13。我的前端项目vue版本是3.4.21, 框架ant-design-vue版本是4.2.1。现在的问题是文件内容和项目框架语法不一样, 请帮我把整个文件的代码内容修改成适配我项目框架的语法(注意:我的前端项目vue版本是3.4.21, 框架ant-design-vue版本是4.2.1,必须生成对应版本的语法)。 不要删除里边已经注释的代码, 即使有相同的代码, 你也不要省略代码, 把所有内容全部输出来, 需要保持原有的布局样式而调整转换代码。如果这个文件引入的别的文件, 不用你关心别的文件, 你不要给我生成别的文件内容, 最后生成一个vue文件给我, 如果输出内容过长而被终止截断了,请接着输出剩余的部分。转换后要求代码不报错, 按钮方法和底部方法名称要对应起来, 转换过程中不要遗漏代码, 注意:如果之前代码有$baseConfirm, 给我替换成Modal.confirm , 并且引入import { message, Modal } from “ant-design-vue”; 如果之前代码有$baseMessage, 给我替换成message.success或message.warning或message.error。 你好好思考分析下我的需求,不是将把Element UI组件替换为Ant Design Vue组件,你考虑转换后的版本了吗,不同版本语法api不一样,否则转换后的代码根本不能用。不要给我进行简化处理,方法内容不要给我留空,不要等着我补充,你都给我转换处理好。
08-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值