commit
51c6ec9986
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "electron",
|
"name": "renamer",
|
||||||
"version": "1.1.0",
|
"version": "1.8.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import RuleInterface from "./RuleInterface";
|
import RuleInterface from "./RuleInterface";
|
||||||
|
import {dealFileName} from "./RuleInterface";
|
||||||
import FileObj from "../../vo/FileObj";
|
import FileObj from "../../vo/FileObj";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
@ -20,43 +21,35 @@ export default class DeleteRule implements RuleInterface {
|
|||||||
* 忽略拓展名,true:忽略,false:不忽略
|
* 忽略拓展名,true:忽略,false:不忽略
|
||||||
*/
|
*/
|
||||||
ignorePostfix: boolean;
|
ignorePostfix: boolean;
|
||||||
|
/*
|
||||||
|
* 是否区分大小写
|
||||||
|
*/
|
||||||
|
regI: boolean;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any) {
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.start = new DeleteRuleItem(data.start);
|
this.regI = data.regI != undefined && data.regI;
|
||||||
this.end = new DeleteRuleItem(data.end);
|
this.start = new DeleteRuleItem(data.start, this.regI);
|
||||||
|
this.end = new DeleteRuleItem(data.end, this.regI);
|
||||||
this.ignorePostfix = data.ignorePostfix;
|
this.ignorePostfix = data.ignorePostfix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deal(file: FileObj): void {
|
deal(file: FileObj): void {
|
||||||
|
let target = "";
|
||||||
if (this.type === 'deleteAll') {
|
if (this.type === 'deleteAll') {
|
||||||
file.realName = "";
|
target = "";
|
||||||
if (!this.ignorePostfix) {
|
|
||||||
file.expandName = "";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let str = file.realName + (this.ignorePostfix ? "" : file.expandName);
|
let str = file.realName + (this.ignorePostfix ? "" : file.expandName);
|
||||||
let startIndex = this.start.calIndex(str);
|
let startIndex = this.start.calIndex(str, false);
|
||||||
let endIndex = this.end.calIndex(str);
|
let endIndex = this.end.calIndex(str, true);
|
||||||
if (startIndex < 0 || endIndex < 0) {
|
if (startIndex < 0 || endIndex < 0 || startIndex > endIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
str = str.substring(0, startIndex) + str.substring(endIndex + 1);
|
str = str.substring(0, startIndex) + str.substring(endIndex + 1);
|
||||||
if (this.ignorePostfix) {
|
target = str;
|
||||||
file.realName = str;
|
|
||||||
} else {
|
|
||||||
file.expandName = path.extname(str);
|
|
||||||
if (file.expandName.length > 0) {
|
|
||||||
file.realName = str.substring(0, str.lastIndexOf("."));
|
|
||||||
} else {
|
|
||||||
file.realName = str;
|
|
||||||
}
|
}
|
||||||
}
|
dealFileName(file, target, this.ignorePostfix);
|
||||||
}
|
|
||||||
|
|
||||||
file.name = file.realName + file.expandName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -70,22 +63,36 @@ class DeleteRuleItem {
|
|||||||
* 对应的值
|
* 对应的值
|
||||||
*/
|
*/
|
||||||
value: string;
|
value: string;
|
||||||
|
/**
|
||||||
|
* 正则对象
|
||||||
|
*/
|
||||||
|
reg: RegExp;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any, regI: boolean) {
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.value = data.value;
|
this.value = data.value;
|
||||||
|
if (this.type === 'reg') {
|
||||||
|
this.reg = regI ? new RegExp(this.value) : new RegExp(this.value, 'i');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算位置
|
* 计算位置
|
||||||
|
* @param str 字符串
|
||||||
|
* @param end 是否末尾计算
|
||||||
*/
|
*/
|
||||||
calIndex(str: string): number {
|
calIndex(str: string, end: boolean): number {
|
||||||
if (this.type === 'location') {
|
if (this.type === 'location') {
|
||||||
return parseInt(this.value) - 1;
|
let val = parseInt(this.value);
|
||||||
|
return val > 0 ? val - 1 : str.length + val;
|
||||||
} else if (this.type === 'text') {
|
} else if (this.type === 'text') {
|
||||||
return str.indexOf(this.value);
|
let index = str.indexOf(this.value);
|
||||||
|
return index + (end ? this.value.length - 1 : 0);
|
||||||
} else if (this.type === 'end') {
|
} else if (this.type === 'end') {
|
||||||
return str.length - 1;
|
return str.length - 1;
|
||||||
|
} else if (this.type === 'reg') {
|
||||||
|
let res = this.reg.exec(str);
|
||||||
|
return res == null ? -1 : (res.index + (end ? res[0].length - 1 : 0));
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import RuleInterface from "./RuleInterface";
|
import RuleInterface from "./RuleInterface";
|
||||||
|
import * as ValUtil from "../../../util/ValUtil";
|
||||||
import FileObj from "../../vo/FileObj";
|
import FileObj from "../../vo/FileObj";
|
||||||
|
import {dealFileName} from './RuleInterface';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
|
||||||
@ -10,45 +12,101 @@ export default class ReplaceRule implements RuleInterface {
|
|||||||
*/
|
*/
|
||||||
type: number;
|
type: number;
|
||||||
/**
|
/**
|
||||||
* 前面追加
|
* 源
|
||||||
*/
|
*/
|
||||||
source: string;
|
source: string;
|
||||||
/**
|
/**
|
||||||
* 后面追加
|
* 目标
|
||||||
*/
|
*/
|
||||||
target: string;
|
target: string;
|
||||||
|
/**
|
||||||
|
* 是否正则模式
|
||||||
|
*/
|
||||||
|
regFlag: boolean;
|
||||||
|
/**
|
||||||
|
* 是否区分大小写
|
||||||
|
*/
|
||||||
|
regI: boolean;
|
||||||
|
/**
|
||||||
|
* 是否护理拓展名
|
||||||
|
*/
|
||||||
|
ignorePostfix: boolean;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any) {
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.source = data.source;
|
this.source = data.source;
|
||||||
this.target = data.target;
|
this.target = data.target;
|
||||||
|
this.regFlag = ValUtil.nullToDefault(data.regFlag, false);
|
||||||
|
this.regI = ValUtil.nullToDefault(data.regI, false);
|
||||||
|
this.ignorePostfix = ValUtil.nullToDefault(data.ignorePostfix, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
deal(file: FileObj): void {
|
deal(file: FileObj): void {
|
||||||
|
let targetStr = this.ignorePostfix ? file.realName : file.name;
|
||||||
|
let res = this.regFlag ? this.dealReg(targetStr) : this.dealNoReg(targetStr);
|
||||||
|
dealFileName(file, res, this.ignorePostfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
private dealNoReg(targetStr: string): string {
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let changed = false;
|
let arr: number[] = [];
|
||||||
for (; ;) {
|
for (let i = 0; i < (this.type == 1 ? 1 : 1000); i++) {
|
||||||
let index = this.type == 1 || this.type == 3 ? file.name.indexOf(this.source, start) : file.name.lastIndexOf(this.source);
|
let one = targetStr.indexOf(this.source, start);
|
||||||
if (index > -1) {
|
if (one == -1) {
|
||||||
file.name = file.name.substring(0, index) + this.target + file.name.substring(index + this.source.length);
|
|
||||||
start = index + this.target.length;
|
|
||||||
changed = true;
|
|
||||||
if (this.type != 3) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
arr.push(one);
|
||||||
|
start = one + this.source.length;
|
||||||
|
}
|
||||||
|
if (arr.length == 0) {
|
||||||
|
return targetStr;
|
||||||
|
}
|
||||||
|
let res = "";
|
||||||
|
let needDealArr: number[] = this.type === 1 ? [arr[0]] : this.type === 2 ? [arr[arr.length - 1]] : arr;
|
||||||
|
let lastIndex = 0;
|
||||||
|
for (let i = 0; i < needDealArr.length; i++) {
|
||||||
|
res += targetStr.substring(lastIndex, needDealArr[i]) + this.target;
|
||||||
|
lastIndex = needDealArr[i] + this.source.length;
|
||||||
|
}
|
||||||
|
res += targetStr.substring(lastIndex);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private dealReg(targetStr: string): string {
|
||||||
|
let templateReg = new RegExp("#\{group(\\d+\)}", "g");
|
||||||
|
let templateArr: string[][] = [];
|
||||||
|
while (true) {
|
||||||
|
let one = templateReg.exec(this.target);
|
||||||
|
if (one == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
templateArr.push([one[0], one[1]]);
|
||||||
}
|
}
|
||||||
if (changed) {
|
|
||||||
file.originName = file.name;
|
let reg = new RegExp(this.source, this.regI ? "g" : "ig");
|
||||||
file.expandName = path.extname(file.name);
|
let arr: RegExpExecArray[] = [];
|
||||||
if (file.expandName && file.expandName.length > 0) {
|
for (let i = 0; i < (this.type == 1 ? 1 : 1000); i++) {
|
||||||
file.realName = file.name.substring(0, file.name.lastIndexOf("."));
|
let one = reg.exec(targetStr);
|
||||||
} else {
|
if (one == null) {
|
||||||
file.realName = file.name;
|
break;
|
||||||
}
|
}
|
||||||
|
arr.push(one);
|
||||||
}
|
}
|
||||||
|
if (arr.length == 0) {
|
||||||
|
return targetStr;
|
||||||
|
}
|
||||||
|
let res = "";
|
||||||
|
let needDealReg: RegExpExecArray[] = this.type === 1 ? [arr[0]] : this.type === 2 ? [arr[arr.length - 1]] : arr;
|
||||||
|
let lastIndex = 0;
|
||||||
|
for (let i = 0; i < needDealReg.length; i++) {
|
||||||
|
let reg = needDealReg[i];
|
||||||
|
let target = this.target;
|
||||||
|
templateArr.forEach(item => target = target.replace(item[0], ValUtil.nullToDefault(reg[parseInt(item[1])], '')));
|
||||||
|
res += targetStr.substring(lastIndex, reg.index) + target;
|
||||||
|
lastIndex = reg.index + reg[0].length;
|
||||||
|
}
|
||||||
|
res += targetStr.substring(lastIndex);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,27 @@
|
|||||||
import FileObj from "../../vo/FileObj";
|
import FileObj from "../../vo/FileObj";
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
export default interface RuleInterface {
|
export default interface RuleInterface {
|
||||||
|
|
||||||
deal(file: FileObj): void;
|
deal(file: FileObj): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重新处理文件名
|
||||||
|
* @param file
|
||||||
|
* @param newFileName
|
||||||
|
* @param ignorePostfix
|
||||||
|
*/
|
||||||
|
export function dealFileName(file: FileObj, newFileName: string, ignorePostfix: boolean) {
|
||||||
|
if (ignorePostfix) {
|
||||||
|
file.realName = newFileName;
|
||||||
|
} else {
|
||||||
|
file.expandName = path.extname(newFileName);
|
||||||
|
if (file.expandName.length > 0) {
|
||||||
|
file.realName = newFileName.substring(0, newFileName.lastIndexOf("."));
|
||||||
|
} else {
|
||||||
|
file.realName = newFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.name = file.realName + file.expandName;
|
||||||
|
}
|
@ -3,21 +3,22 @@ import {isVideo, isSub, isNfo} from "../../util/MediaUtil"
|
|||||||
|
|
||||||
export default class FileObj {
|
export default class FileObj {
|
||||||
/**
|
/**
|
||||||
* 文件名
|
* 变更后的文件名(包含拓展名)
|
||||||
*/
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
/**
|
/**
|
||||||
原始名字
|
* 去掉拓展名后的名字(不包含拓展名)
|
||||||
|
*/
|
||||||
|
realName: string;
|
||||||
|
/**
|
||||||
|
原始文件名(不变)
|
||||||
*/
|
*/
|
||||||
originName: string;
|
originName: string;
|
||||||
/**
|
/**
|
||||||
* 拓展名
|
* 拓展名(最新的拓展名,每次应用规则后重新计算)
|
||||||
*/
|
*/
|
||||||
expandName: string;
|
expandName: string;
|
||||||
/**
|
|
||||||
* 去掉拓展名后的名字
|
|
||||||
*/
|
|
||||||
realName: string;
|
|
||||||
/**
|
/**
|
||||||
* 所属路径
|
* 所属路径
|
||||||
*/
|
*/
|
||||||
|
8
openRenamerBackend/util/ValUtil.ts
Normal file
8
openRenamerBackend/util/ValUtil.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* null to default
|
||||||
|
* @param value
|
||||||
|
* @param defaultVal
|
||||||
|
*/
|
||||||
|
export function nullToDefault(value: any, defaultVal: any): any {
|
||||||
|
return value === undefined || value == null ? defaultVal : value;
|
||||||
|
}
|
9130
openRenamerFront/pnpm-lock.yaml
generated
9130
openRenamerFront/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,7 @@ export default {
|
|||||||
name: "Home",
|
name: "Home",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
version: "1.7.1",
|
version: "1.8.0",
|
||||||
latestVersion: null,
|
latestVersion: null,
|
||||||
activeIndex: location.pathname,
|
activeIndex: location.pathname,
|
||||||
showNewVersion: false
|
showNewVersion: false
|
||||||
|
@ -6,22 +6,30 @@
|
|||||||
<div>开始</div>
|
<div>开始</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<el-radio v-model="ruleObj.data.start.type" label="location" :disabled="deleteAll">位置:</el-radio>
|
<el-radio v-model="ruleObj.data.start.type" label="location" :disabled="deleteAll">位置:</el-radio>
|
||||||
<el-input-number :min="1" size="small" :disabled="deleteAll" v-model="startIndex" />
|
<el-input-number :min="1" size="small" :disabled="deleteAll" v-model="startIndex"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<el-radio v-model="ruleObj.data.start.type" label="text" :disabled="deleteAll">文本:</el-radio>
|
<el-radio v-model="ruleObj.data.start.type" label="text" :disabled="deleteAll">文本:</el-radio>
|
||||||
<el-input v-model="startText" size="small" :disabled="deleteAll" />
|
<el-input v-model="startText" size="small" :disabled="deleteAll"/>
|
||||||
|
</div>
|
||||||
|
<div class="line">
|
||||||
|
<el-radio v-model="ruleObj.data.start.type" label="reg" :disabled="deleteAll">正则:</el-radio>
|
||||||
|
<el-input v-model="startReg" size="small" :disabled="deleteAll"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-left: 4em">
|
<div style="margin-left: 4em">
|
||||||
<div>结束</div>
|
<div>结束</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<el-radio v-model="ruleObj.data.end.type" label="location" :disabled="deleteAll">位置:</el-radio>
|
<el-radio v-model="ruleObj.data.end.type" label="location" :disabled="deleteAll">位置:</el-radio>
|
||||||
<el-input-number size="small" :disabled="deleteAll" v-model="endIndex" />
|
<el-input-number size="small" :disabled="deleteAll" v-model="endIndex"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<el-radio v-model="ruleObj.data.end.type" label="text" :disabled="deleteAll">文本:</el-radio>
|
<el-radio v-model="ruleObj.data.end.type" label="text" :disabled="deleteAll">文本:</el-radio>
|
||||||
<el-input v-model="endText" size="small" :disabled="deleteAll" />
|
<el-input v-model="endText" size="small" :disabled="deleteAll"/>
|
||||||
|
</div>
|
||||||
|
<div class="line">
|
||||||
|
<el-radio v-model="ruleObj.data.end.type" label="reg" :disabled="deleteAll">正则:</el-radio>
|
||||||
|
<el-input v-model="endReg" size="small" :disabled="deleteAll"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="line">
|
<div class="line">
|
||||||
<el-radio v-model="ruleObj.data.end.type" label="end" :disabled="deleteAll">直到末尾</el-radio>
|
<el-radio v-model="ruleObj.data.end.type" label="end" :disabled="deleteAll">直到末尾</el-radio>
|
||||||
@ -29,14 +37,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="ruleObj.data.start.type==='reg' || ruleObj.data.end.type==='reg'" class="flex">
|
||||||
|
<div class="left">区分大小写:</div>
|
||||||
|
<el-switch v-model="ruleObj.data.regI"/>
|
||||||
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="left">全部删除:</div>
|
<div class="left">全部删除:</div>
|
||||||
<el-switch v-model="deleteAll" @change="allDeleteChange" />
|
<el-switch v-model="deleteAll" @change="allDeleteChange"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="left">忽略拓展名:</div>
|
<div class="left">忽略拓展名:</div>
|
||||||
<el-switch v-model="ruleObj.data.ignorePostfix" />
|
<el-switch v-model="ruleObj.data.ignorePostfix"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -60,28 +72,36 @@ export default {
|
|||||||
value: "",
|
value: "",
|
||||||
},
|
},
|
||||||
ignorePostfix: true,
|
ignorePostfix: true,
|
||||||
|
regI: false,//reg是否区分大小写
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
startIndex: 1,
|
startIndex: 1,
|
||||||
endIndex: 1,
|
endIndex: 1,
|
||||||
startText: "",
|
startText: "",
|
||||||
|
startReg: "",
|
||||||
endText: "",
|
endText: "",
|
||||||
|
endReg: "",
|
||||||
deleteAll: false,
|
deleteAll: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.editRule) {
|
if (this.editRule) {
|
||||||
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
|
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
|
||||||
if (this.ruleObj.data.type == "deletePart") {
|
if (this.ruleObj.data.type === "deletePart") {
|
||||||
if (this.ruleObj.data.start.type == "location") {
|
if (this.ruleObj.data.start.type === "location") {
|
||||||
this.startIndex = parseInt(this.ruleObj.data.start.value);
|
this.startIndex = parseInt(this.ruleObj.data.start.value);
|
||||||
} else {
|
} else if (this.ruleObj.data.start.type === "text") {
|
||||||
this.startText = this.ruleObj.data.start.value;
|
this.startText = this.ruleObj.data.start.value;
|
||||||
}
|
|
||||||
if (this.ruleObj.data.end.type == "location") {
|
|
||||||
this.endIndex = parseInt(this.ruleObj.data.end.value);
|
|
||||||
} else {
|
} else {
|
||||||
|
this.startReg = this.ruleObj.data.start.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.ruleObj.data.end.type === "location") {
|
||||||
|
this.endIndex = parseInt(this.ruleObj.data.end.value);
|
||||||
|
} else if (this.ruleObj.data.end.type === "text") {
|
||||||
this.endText = this.ruleObj.data.end.value;
|
this.endText = this.ruleObj.data.end.value;
|
||||||
|
} else {
|
||||||
|
this.endReg = this.ruleObj.data.end.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.deleteAll = true;
|
this.deleteAll = true;
|
||||||
@ -91,13 +111,15 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
exportObj() {
|
exportObj() {
|
||||||
if (this.ruleObj.data.type.length == 0) {
|
if (this.ruleObj.data.type.length == 0) {
|
||||||
this.$message({ message: "请填写完整", type: "warning" });
|
this.$message({message: "请填写完整", type: "warning"});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this.ruleObj.data.type == "deletePart") {
|
if (this.ruleObj.data.type === "deletePart") {
|
||||||
if (
|
if (
|
||||||
(this.ruleObj.data.start.type == "text" && this.startText.length == 0) ||
|
('text' === this.ruleObj.data.start.type && this.startText.length === 0) ||
|
||||||
(this.ruleObj.data.start.type == "text" && this.startText.length == 0)
|
('text' === this.ruleObj.data.end.type && this.endText.length === 0) ||
|
||||||
|
('reg' === this.ruleObj.data.start.type && this.startReg.length === 0) ||
|
||||||
|
('reg' === this.ruleObj.data.end.type && this.endReg.length === 0)
|
||||||
) {
|
) {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: "开始或者结束文本不能为空",
|
message: "开始或者结束文本不能为空",
|
||||||
@ -106,19 +128,20 @@ export default {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.ruleObj.data.start.value = this.ruleObj.data.start.type == "location" ? this.startIndex.toString() : this.startText;
|
let startType = this.ruleObj.data.start.type;
|
||||||
this.ruleObj.data.end.value = this.ruleObj.data.end.type == "location" ? this.endIndex.toString() : this.endText;
|
this.ruleObj.data.start.value = startType === "location" ? this.startIndex.toString() : startType === 'text' ? this.startText : this.startReg;
|
||||||
|
let endType = this.ruleObj.data.end.type;
|
||||||
|
this.ruleObj.data.end.value = endType === "location" ? this.endIndex.toString() : endType === 'text' ? this.endText : this.endReg;
|
||||||
let message = `删除:`;
|
let message = `删除:`;
|
||||||
if (this.deleteAll) {
|
if (this.deleteAll) {
|
||||||
message += "全部删除";
|
message += "全部删除";
|
||||||
} else {
|
} else {
|
||||||
message += `从"${this.ruleObj.data.start.value}"到"${this.ruleObj.data.end.type == "untilEnd" ? "末尾" : this.ruleObj.data.end.value}"`;
|
message += `从"${this.ruleObj.data.start.value}"到"${this.ruleObj.data.end.type === "end" ? "末尾" : this.ruleObj.data.end.value}"`;
|
||||||
}
|
}
|
||||||
this.ruleObj.message = message;
|
this.ruleObj.message = message;
|
||||||
return this.ruleObj;
|
return this.ruleObj;
|
||||||
},
|
},
|
||||||
allDeleteChange(val) {
|
allDeleteChange(val) {
|
||||||
console.log(val);
|
|
||||||
this.deleteAll = val;
|
this.deleteAll = val;
|
||||||
this.ruleObj.data.type = val ? "deleteAll" : "deletePart";
|
this.ruleObj.data.type = val ? "deleteAll" : "deletePart";
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span class="left">源:</span>
|
<span class="left">源:</span>
|
||||||
<el-input style="width:20em" v-model="ruleObj.data.source"/>
|
<el-input style="width:20em" v-model="ruleObj.data.source" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span class="left">目标:</span>
|
<span class="left">目标:</span>
|
||||||
<el-input style="width:20em" v-model="ruleObj.data.target"/>
|
<el-input style="width:20em" v-model="ruleObj.data.target" />
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<div class="left">正则模式:</div>
|
||||||
|
<el-switch v-model="ruleObj.data.regFlag" />
|
||||||
|
<el-tooltip effect="dark" :content="regTip" placement="right">
|
||||||
|
<el-icon>
|
||||||
|
<InfoFilled />
|
||||||
|
</el-icon>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<div class="left">区分大小写:</div>
|
||||||
|
<el-switch v-model="ruleObj.data.regI" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span class="left">替换选项:</span>
|
<span class="left">替换选项:</span>
|
||||||
@ -13,31 +26,38 @@
|
|||||||
<el-radio v-for="item in radioList" :key="item.code" v-model="ruleObj.data.type" :label="item.code"
|
<el-radio v-for="item in radioList" :key="item.code" v-model="ruleObj.data.type" :label="item.code"
|
||||||
>{{ item.label }}
|
>{{ item.label }}
|
||||||
</el-radio>
|
</el-radio>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<div class="left">忽略拓展名:</div>
|
||||||
|
<el-switch v-model="ruleObj.data.ignorePostfix"/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { InfoFilled } from "@element-plus/icons-vue";
|
||||||
|
import { nullToDefault } from "@/utils/ValUtil";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ReplaceRule",
|
name: "ReplaceRule",
|
||||||
|
components: { InfoFilled },
|
||||||
props: ["editRule"],
|
props: ["editRule"],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
regTip: `开启支持js正则匹配,支持分组匹配,目标字符串支持模板#{groupN},N表示匹配到的第几组。比如#{group1}将被替换为匹配到的第一组数据`,
|
||||||
radioList: [
|
radioList: [
|
||||||
{
|
{
|
||||||
label: "替换第一个",
|
label: "替换第一个",
|
||||||
code: 1,
|
code: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "替换最后一个",
|
label: "替换最后一个",
|
||||||
code: 2,
|
code: 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "全部替换",
|
label: "全部替换",
|
||||||
code: 3,
|
code: 3
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
ruleObj: {
|
ruleObj: {
|
||||||
type: "replace",
|
type: "replace",
|
||||||
@ -46,31 +66,37 @@ export default {
|
|||||||
source: "",
|
source: "",
|
||||||
target: "",
|
target: "",
|
||||||
type: 1, //1:替换第一个,2:替换最后一个,3:全部替换
|
type: 1, //1:替换第一个,2:替换最后一个,3:全部替换
|
||||||
},
|
ignorePostfix: true, //忽略拓展名
|
||||||
},
|
regFlag: false, //正则模式
|
||||||
|
regI: false //是否区分大小写
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.editRule) {
|
if (this.editRule) {
|
||||||
console.log(this.editRule);
|
console.log(this.editRule);
|
||||||
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
|
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
|
||||||
|
//兼容历史数据
|
||||||
|
this.ruleObj.data.ignorePostfix = nullToDefault(this.ruleObj.data.ignorePostfix, true);
|
||||||
|
this.ruleObj.data.regFlag = nullToDefault(this.ruleObj.data.regFlag, false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
exportObj() {
|
exportObj() {
|
||||||
if (!this.ruleObj.data.source) {
|
if (!this.ruleObj.data.source) {
|
||||||
this.$message({message: "源不能为空", type: "warning"});
|
this.$message({ message: "源不能为空", type: "warning" });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!this.ruleObj.data.type) {
|
if (!this.ruleObj.data.type) {
|
||||||
this.$message({message: "请选择替换选项", type: "warning"});
|
this.$message({ message: "请选择替换选项", type: "warning" });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.ruleObj.message = `替换:将${this.ruleObj.data.source}替换为${this.ruleObj.data.target};`
|
this.ruleObj.message = `替换:将${this.ruleObj.data.source}替换为${this.ruleObj.data.target};`
|
||||||
+ this.radioList.filter(item => item.code === this.ruleObj.data.type)[0].label;
|
+ this.radioList.filter(item => item.code === this.ruleObj.data.type)[0].label;
|
||||||
return this.ruleObj;
|
return this.ruleObj;
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
9
openRenamerFront/src/utils/ValUtil.js
Normal file
9
openRenamerFront/src/utils/ValUtil.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* 空转default
|
||||||
|
* @param val
|
||||||
|
* @param defaultVal
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export function nullToDefault(val, defaultVal) {
|
||||||
|
return val === undefined || val == null ? defaultVal : val;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user