Compare commits

..

No commits in common. "652105f534c8f2709359d2d9dcee1b56c2e0acf4" and "f85890bda82b77dc8d49e5be1794be8c21216a5f" have entirely different histories.

9 changed files with 4252 additions and 5198 deletions

View File

@ -1,5 +1,4 @@
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';
@ -21,9 +20,6 @@ export default class DeleteRule implements RuleInterface {
* true:false * true:false
*/ */
ignorePostfix: boolean; ignorePostfix: boolean;
/*
*
*/
regI: boolean; regI: boolean;
constructor(data: any) { constructor(data: any) {
@ -36,9 +32,11 @@ export default class DeleteRule implements RuleInterface {
deal(file: FileObj): void { deal(file: FileObj): void {
let target = "";
if (this.type === 'deleteAll') { if (this.type === 'deleteAll') {
target = ""; file.realName = "";
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, false); let startIndex = this.start.calIndex(str, false);
@ -47,9 +45,19 @@ export default class DeleteRule implements RuleInterface {
return; return;
} }
str = str.substring(0, startIndex) + str.substring(endIndex + 1); str = str.substring(0, startIndex) + str.substring(endIndex + 1);
target = str; if (this.ignorePostfix) {
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;
} }
} }
@ -86,13 +94,12 @@ class DeleteRuleItem {
let val = parseInt(this.value); let val = parseInt(this.value);
return val > 0 ? val - 1 : str.length + val; return val > 0 ? val - 1 : str.length + val;
} else if (this.type === 'text') { } else if (this.type === 'text') {
let index = str.indexOf(this.value); return 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') { } else if (this.type === 'reg') {
let res = this.reg.exec(str); let res = this.reg.exec(str);
return res == null ? -1 : (res.index + (end ? res[0].length - 1 : 0)); return res == null ? -1 : (res.index + (end ? 0 : res[0].length));
} }
return -1; return -1;
} }

View File

@ -1,7 +1,5 @@
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';
@ -12,101 +10,45 @@ 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 arr: number[] = []; let changed = false;
for (let i = 0; i < (this.type == 1 ? 1 : 1000); i++) { for (; ;) {
let one = targetStr.indexOf(this.source, start); let index = this.type == 1 || this.type == 3 ? file.name.indexOf(this.source, start) : file.name.lastIndexOf(this.source);
if (one == -1) { if (index > -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;
}
} else {
break; break;
} }
arr.push(one);
start = one + this.source.length;
} }
if (arr.length == 0) { if (changed) {
return targetStr; file.originName = file.name;
} file.expandName = path.extname(file.name);
let res = ""; if (file.expandName && file.expandName.length > 0) {
let needDealArr: number[] = this.type === 1 ? [arr[0]] : this.type === 2 ? [arr[arr.length - 1]] : arr; file.realName = file.name.substring(0, file.name.lastIndexOf("."));
let lastIndex = 0; } else {
for (let i = 0; i < needDealArr.length; i++) { file.realName = file.name;
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;
} }
templateArr.push([one[0], one[1]]);
} }
let reg = new RegExp(this.source, this.regI ? "g" : "ig");
let arr: RegExpExecArray[] = [];
for (let i = 0; i < (this.type == 1 ? 1 : 1000); i++) {
let one = reg.exec(targetStr);
if (one == null) {
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;
} }
} }

View File

@ -1,27 +1,6 @@
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;
} }

View File

@ -3,22 +3,21 @@ 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;
/** /**
* *
*/ */

View File

@ -1,8 +0,0 @@
/**
* null to default
* @param value
* @param defaultVal
*/
export function nullToDefault(value: any, defaultVal: any): any {
return value === undefined || value == null ? defaultVal : value;
}

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@ export default {
name: "Home", name: "Home",
data() { data() {
return { return {
version: "1.8.0", version: "1.7.1",
latestVersion: null, latestVersion: null,
activeIndex: location.pathname, activeIndex: location.pathname,
showNewVersion: false showNewVersion: false

View File

@ -1,24 +1,11 @@
<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>
@ -26,38 +13,31 @@
<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",
@ -66,37 +46,31 @@ export default {
source: "", source: "",
target: "", target: "",
type: 1, //1:23 type: 1, //1:23
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>

View File

@ -1,9 +0,0 @@
/**
* 空转default
* @param val
* @param defaultVal
* @returns {*}
*/
export function nullToDefault(val, defaultVal) {
return val === undefined || val == null ? defaultVal : val;
}