feat:自动识别逻辑增加

This commit is contained in:
fanxb 2022-11-27 20:22:42 +08:00
parent 9d8a6dcbfe
commit ca6dba024f
19 changed files with 648 additions and 380 deletions

View File

@ -0,0 +1,62 @@
import RuleInterface from "./RuleInterface";
import FileObj from "../../vo/FileObj";
import path from 'path';
let pattern = new RegExp(/s(eason)?(\d+)/);
let charSet = new Set([' ', '[', '.', '(', '']);
export default class InsertRule implements RuleInterface {
/**
* seasonname/
*/
type: string;
/**
*
*/
frontAdd: string;
/**
*
*/
endAdd: string;
constructor(data: any) {
this.type = data.type;
this.frontAdd = data.frontAdd;
this.endAdd = data.endAdd;
}
deal(file: FileObj): void {
//识别到的内容
let getStr = null;
let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern);
if (this.type === 'season') {
if (patternRes && patternRes[2]) {
getStr = patternRes[2];
}
} else if (this.type === 'name') {
let originName = null;
if (patternRes && patternRes[2]) {
//说明是剧集,取父文件夹的父文件夹名称
originName = path.basename(path.resolve(file.path, '..'));
} else {
//说明是电影
originName = path.basename(file.path);
}
getStr = '';
for (let i = 0; i < originName.length; i++) {
let char = originName.charAt(i);
if (charSet.has(char)) {
break;
}
getStr += char;
}
}
if (getStr && getStr.length > 0) {
file.realName = file.realName + this.frontAdd + getStr + this.endAdd;
file.name = file.realName + file.expandName;
}
}
}

View File

@ -1,92 +1,92 @@
import RuleInterface from "./RuleInterface"; import RuleInterface from "./RuleInterface";
import FileObj from "../FileObj"; import FileObj from "../../vo/FileObj";
import path from 'path'; import path from 'path';
export default class DeleteRule implements RuleInterface { export default class DeleteRule implements RuleInterface {
/** /**
* deletePart:部分删除deleteAll:全部删除 * deletePart:部分删除deleteAll:全部删除
*/ */
type: string; type: string;
/** /**
* *
*/ */
start: DeleteRuleItem; start: DeleteRuleItem;
/** /**
* *
*/ */
end: DeleteRuleItem; end: DeleteRuleItem;
/** /**
* true:false * true:false
*/ */
ignorePostfix: boolean; ignorePostfix: boolean;
constructor(data: any) { constructor(data: any) {
this.type = data.type; this.type = data.type;
this.start = new DeleteRuleItem(data.start); this.start = new DeleteRuleItem(data.start);
this.end = new DeleteRuleItem(data.end); this.end = new DeleteRuleItem(data.end);
this.ignorePostfix = data.ignorePostfix; this.ignorePostfix = data.ignorePostfix;
} }
deal(file: FileObj): void { deal(file: FileObj): void {
if (this.type === 'deleteAll') { if (this.type === 'deleteAll') {
file.realName = ""; file.realName = "";
if (!this.ignorePostfix) { if (!this.ignorePostfix) {
file.expandName = ""; 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);
let endIndex = this.end.calIndex(str); let endIndex = this.end.calIndex(str);
if (startIndex < 0 || endIndex < 0) { if (startIndex < 0 || endIndex < 0) {
return; return;
} }
str = str.substring(0, startIndex) + str.substring(endIndex + 1); str = str.substring(0, startIndex) + str.substring(endIndex + 1);
if (this.ignorePostfix) { if (this.ignorePostfix) {
file.realName = str; file.realName = str;
} else { } else {
file.expandName = path.extname(str); file.expandName = path.extname(str);
if (file.expandName.length > 0) { if (file.expandName.length > 0) {
file.realName = str.substring(0, str.lastIndexOf(".")); file.realName = str.substring(0, str.lastIndexOf("."));
} else { } else {
file.realName = str; file.realName = str;
} }
} }
} }
file.name = file.realName + file.expandName; file.name = file.realName + file.expandName;
} }
} }
class DeleteRuleItem { class DeleteRuleItem {
/** /**
* location:位置text:文本end:直到末尾 * location:位置text:文本end:直到末尾
*/ */
type: string; type: string;
/** /**
* *
*/ */
value: string; value: string;
constructor(data: any) { constructor(data: any) {
this.type = data.type; this.type = data.type;
this.value = data.value; this.value = data.value;
} }
/** /**
* *
*/ */
calIndex(str: string): number { calIndex(str: string): number {
if (this.type === 'location') { if (this.type === 'location') {
return parseInt(this.value) - 1; return parseInt(this.value) - 1;
} else if (this.type === 'text') { } else if (this.type === 'text') {
return str.indexOf(this.value); return str.indexOf(this.value);
} else if (this.type === 'end') { } else if (this.type === 'end') {
return str.length - 1; return str.length - 1;
} }
return -1; return -1;
} }
} }

View File

@ -1,83 +1,98 @@
import RuleInterface from "./RuleInterface"; import RuleInterface from "./RuleInterface";
import FileObj from "../FileObj"; import FileObj from "../../vo/FileObj";
import path from 'path'; import path from 'path';
let pattern = new RegExp(/s(eason)?(\d+)/); let pattern = new RegExp(/s(eason)?(\d+)/);
export default class InsertRule implements RuleInterface { export default class InsertRule implements RuleInterface {
/** /**
* *
*/ */
insertContent: string; insertContent: string;
/** /**
* frontbackendat:位置replace:替换当前文件名 * frontbackendat:位置replace:替换当前文件名
*/ */
type: string; type: string;
/** /**
* type为at,,1 * type为at,,1
*/ */
atInput: number; atInput: number;
/** /**
* type为at,true:false: * type为at,true:false:
*/ */
atIsRightToleft: boolean; atIsRightToleft: boolean;
/** /**
* true:false * true:false
*/ */
ignorePostfix: boolean; ignorePostfix: boolean;
/** /**
*/ */
autoSeason: boolean; autoSeason: boolean;
/**
constructor(data: any) {
this.insertContent = data.insertContent; */
this.type = data.type; endFilter: boolean;
this.atInput = data.atInput; /**
this.atIsRightToleft = data.atIsRightToleft;
this.ignorePostfix = data.ignorePostfix; */
this.autoSeason = data.autoSeason; validEnd: Array<String>;
}
constructor(data: any) {
this.insertContent = data.insertContent;
deal(file: FileObj): void { this.type = data.type;
let str = this.ignorePostfix ? file.realName : file.name; this.atInput = data.atInput;
let season = ''; this.atIsRightToleft = data.atIsRightToleft;
if (this.autoSeason) { this.ignorePostfix = data.ignorePostfix;
let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern); this.autoSeason = data.autoSeason;
if (patternRes && patternRes[2]) { this.endFilter = data.endFilter;
season = patternRes[2]; this.validEnd = data.validEnd;
} }
}
switch (this.type) {
case "front": deal(file: FileObj): void {
str = this.insertContent + season + str; if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) {
break; //拓展名不符,跳过
case "backend": return;
str = str + this.insertContent + season; }
break; let str = this.ignorePostfix ? file.realName : file.name;
case "at": let season = '';
let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1;
str = str.substring(0, index) + this.insertContent + season + str.substring(index); if (this.autoSeason) {
break; let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern);
case "replace": if (patternRes && patternRes[2]) {
str = this.insertContent + season; season = patternRes[2];
break; }
} }
switch (this.type) {
case "front":
if (this.ignorePostfix) { str = this.insertContent + season + str;
file.realName = str; break;
} else { case "backend":
file.expandName = path.extname(str); str = str + this.insertContent + season;
if (file.expandName.length > 0) { break;
file.realName = str.substring(0, str.lastIndexOf(".")); case "at":
} else { let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1;
file.realName = str; str = str.substring(0, index) + this.insertContent + season + str.substring(index);
} break;
} case "replace":
str = this.insertContent + season;
file.name = file.realName + file.expandName; break;
} }
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;
}
}
file.name = file.realName + file.expandName;
}
} }

View File

@ -1,6 +1,6 @@
import FileObj from "../FileObj"; import FileObj from "../../vo/FileObj";
export default interface RuleInterface { export default interface RuleInterface {
deal(file: FileObj): void; deal(file: FileObj): void;
} }

View File

@ -1,80 +1,80 @@
import RuleInterface from "./RuleInterface"; import RuleInterface from "./RuleInterface";
import FileObj from "../FileObj"; import FileObj from "../../vo/FileObj";
import path from 'path'; import path from 'path';
export default class InsertRule implements RuleInterface { export default class InsertRule implements RuleInterface {
/** /**
* *
*/ */
start: number; start: number;
/** /**
* *
*/ */
currentIndex: number; currentIndex: number;
/** /**
* *
*/ */
increment: number; increment: number;
/** /**
* 0 * 0
*/ */
addZero: boolean; addZero: boolean;
/** /**
* *
*/ */
numLength: number; numLength: number;
/** /**
* ,front:前缀backendat * ,front:前缀backendat
*/ */
insertType: string; insertType: string;
/** /**
* *
*/ */
insertValue: number; insertValue: number;
/** /**
* *
*/ */
ignorePostfix: boolean; ignorePostfix: boolean;
constructor(data: any) { constructor(data: any) {
this.start = data.start; this.start = data.start;
this.currentIndex = data.start; this.currentIndex = data.start;
this.increment = data.increment; this.increment = data.increment;
this.addZero = data.addZero; this.addZero = data.addZero;
this.numLength = data.numLength; this.numLength = data.numLength;
this.insertType = data.insertType; this.insertType = data.insertType;
this.insertValue = data.insertValue; this.insertValue = data.insertValue;
this.ignorePostfix = data.ignorePostfix; this.ignorePostfix = data.ignorePostfix;
} }
deal(file: FileObj): void { deal(file: FileObj): void {
let length = this.currentIndex.toString().length; let length = this.currentIndex.toString().length;
let numStr = (this.addZero && this.numLength > length ? "0".repeat(this.numLength - length) : "") + this.currentIndex; let numStr = (this.addZero && this.numLength > length ? "0".repeat(this.numLength - length) : "") + this.currentIndex;
let str = this.ignorePostfix ? file.realName : file.name; let str = this.ignorePostfix ? file.realName : file.name;
switch (this.insertType) { switch (this.insertType) {
case "front": case "front":
str = numStr + str; str = numStr + str;
break; break;
case "backend": case "backend":
str = str + numStr; str = str + numStr;
break; break;
case "at": case "at":
str = str.substring(0, this.insertValue - 1) + numStr + str.substring(this.insertValue - 1); str = str.substring(0, this.insertValue - 1) + numStr + str.substring(this.insertValue - 1);
break; break;
} }
this.currentIndex += this.increment; this.currentIndex += this.increment;
if (this.ignorePostfix) { if (this.ignorePostfix) {
file.realName = str; file.realName = str;
} else { } else {
file.expandName = path.extname(str); file.expandName = path.extname(str);
if (file.expandName.length > 0) { if (file.expandName.length > 0) {
file.realName = str.substring(0, str.lastIndexOf(".")); file.realName = str.substring(0, str.lastIndexOf("."));
} else { } else {
file.realName = str; file.realName = str;
} }
} }
file.name = file.realName + file.expandName; file.name = file.realName + file.expandName;
} }
} }

View File

@ -1,50 +1,55 @@
import * as pathUtil from "path"; import * as pathUtil from "path";
export default class FileObj { export default class FileObj {
/** /**
* *
*/ */
name: string; name: string;
/** /**
*
*/ */
expandName: string; originName: string;
/** /**
* *
*/ */
realName: string; expandName: string;
/** /**
* *
*/ */
path: string; realName: string;
/** /**
* *
*/ */
isFolder: boolean; path: string;
/** /**
* *
*/ */
errorMessage: string; isFolder: boolean;
/** /**
* ms *
*/ */
createdTime: number; errorMessage: string;
/** /**
* ms * ms
*/ */
updatedTime: number; createdTime: number;
/**
* ms
constructor(name: string, path, isFolder, createdTime, updatedTime) { */
this.name = name; updatedTime: number;
this.expandName = pathUtil.extname(name);
if (this.expandName.length > 0) {
this.realName = name.substring(0, name.lastIndexOf(".")); constructor(name: string, path, isFolder, createdTime, updatedTime) {
} else { this.name = name;
this.realName = name; this.originName = name;
} this.expandName = pathUtil.extname(name);
this.path = path; if (this.expandName.length > 0) {
this.isFolder = isFolder; this.realName = name.substring(0, name.lastIndexOf("."));
this.createdTime = createdTime; } else {
this.updatedTime = updatedTime; this.realName = name;
} }
this.path = path;
this.isFolder = isFolder;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
}
} }

View File

@ -1,27 +1,35 @@
import DeleteRule from "./rules/DeleteRule"; import DeleteRule from "../bo/rules/DeleteRule";
import InsertRule from "./rules/InsertRule"; import InsertRule from "../bo/rules/InsertRule";
import SerializationRule from "./rules/SerializationRule"; import SerializationRule from "../bo/rules/SerializationRule";
import AutoRule from "../bo/rules/AutoRule";
export default class RuleObj {
type: string; export default class RuleObj {
message: string; type: string;
/** message: string;
* /**
*/ *
data: any; */
data: any;
constructor(data: any) {
this.type = data.type; constructor(data: any) {
this.message = data.message; this.type = data.type;
switch (this.type) { this.message = data.message;
case "delete": switch (this.type) {
this.data = new DeleteRule(data.data); case "delete":
break; this.data = new DeleteRule(data.data);
case "insert": break;
this.data = new InsertRule(data.data); case "insert":
break; this.data = new InsertRule(data.data);
default: break;
this.data = new SerializationRule(data.data); case "serialization":
} this.data = new SerializationRule(data.data);
} break;
case "auto":
this.data = new AutoRule(data.data);
break;
default:
throw new Error("不支持的规则:" + this.type);
}
}
} }

View File

@ -3,7 +3,7 @@ import * as path from 'path';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import ProcessHelper from '../util/ProcesHelper'; import ProcessHelper from '../util/ProcesHelper';
import FileObj from '../vo/FileObj'; import FileObj from '../entity/vo/FileObj';
import SavePathDao from '../dao/SavePathDao'; import SavePathDao from '../dao/SavePathDao';
import SavePath from '../entity/dto/SavePath'; import SavePath from '../entity/dto/SavePath';
@ -28,6 +28,9 @@ class FileService {
fileList = await fs.readdir(pathStr); fileList = await fs.readdir(pathStr);
} }
} else { } else {
if (!(fs.pathExists(pathStr))) {
throw new Error("路径不存在");
}
fileList = await fs.readdir(pathStr); fileList = await fs.readdir(pathStr);
} }
let folderList: Array<FileObj> = new Array(); let folderList: Array<FileObj> = new Array();

View File

@ -2,9 +2,9 @@ import config from '../config';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import FileObj from '../vo/FileObj'; import FileObj from '../entity/vo/FileObj';
import RuleObj from '../vo/RuleObj'; import RuleObj from '../entity/vo/RuleObj';
import RuleInterface from '../vo/rules/RuleInterface'; import RuleInterface from '../entity/bo/rules/RuleInterface';
class RenamerService { class RenamerService {

View File

@ -8,7 +8,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"@element-plus/icons": "^0.0.11", "@element-plus/icons-vue": "^2.0.10",
"axios": "^0.21.1", "axios": "^0.21.1",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"dayjs": "^1.10.7", "dayjs": "^1.10.7",

View File

@ -1,15 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang=""> <html lang="">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title><%= htmlWebpackPlugin.options.title %></title> <title>renamer</title>
</head> </head>
<body> <body>
<noscript> <noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> <strong
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong
>
</noscript> </noscript>
<div id="app"></div> <div id="app"></div>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->

View File

@ -1,5 +1,6 @@
<template> <template>
<div class="app"> <div class="app">
<div class="head">菜单栏</div>
<div class="content"> <div class="content">
<router-view /> <router-view />
</div> </div>

View File

@ -36,8 +36,10 @@
<script> <script>
import HttpUtil from "../utils/HttpUtil"; import HttpUtil from "../utils/HttpUtil";
import Bus from "../utils/Bus";
export default { export default {
name: "FileChose", name: "FileChose",
props: ["curChoosePath"],
data() { data() {
return { return {
isWindows: false, isWindows: false,
@ -61,9 +63,20 @@ export default {
return targetList.length > 0 ? targetList[0].id : null; return targetList.length > 0 ? targetList[0].id : null;
}, },
}, },
watch: {
async curChoosePath(newVal) {
console.log("变更路径:", newVal);
this.pathList = newVal;
await this.breadcrumbClick(this.pathList.length - 1);
},
},
async created() { async created() {
if (this.curChoosePath && this.curChoosePath.length > 0) {
this.pathList = this.curChoosePath;
}
await this.breadcrumbClick(this.pathList.length - 1); await this.breadcrumbClick(this.pathList.length - 1);
await this.refreshSavePathList(); await this.refreshSavePathList();
Bus.$on("refreshSavePathList", this.refreshSavePathList);
}, },
methods: { methods: {
@ -77,15 +90,18 @@ export default {
// //
async breadcrumbClick(index) { async breadcrumbClick(index) {
this.loading = true; this.loading = true;
let path = this.createPath(index); try {
let fileList = await HttpUtil.get("/file/query", { let path = this.createPath(index);
path: encodeURIComponent(path), let fileList = await HttpUtil.get("/file/query", {
showHidden: false, path: encodeURIComponent(path),
}); showHidden: false,
fileList.forEach((item) => (item.checked = false)); });
this.fileList = fileList; fileList.forEach((item) => (item.checked = false));
this.filterText = ""; this.fileList = fileList;
this.loading = false; this.filterText = "";
} finally {
this.loading = false;
}
return false; return false;
}, },
// //
@ -130,9 +146,8 @@ export default {
}, },
// //
async savePath() { async savePath() {
let res = await HttpUtil.post("/file/path/save", null, { name: this.saveName, content: JSON.stringify(this.pathList) }); await HttpUtil.post("/file/path/save", null, { name: this.saveName, content: JSON.stringify(this.pathList) });
this.$emit("refreshSavePathList"); Bus.$emit("refreshSavePathList");
this.refreshSavePathList();
this.saveName = ""; this.saveName = "";
this.showSave = false; this.showSave = false;
this.$message.success("操作成功"); this.$message.success("操作成功");
@ -140,15 +155,9 @@ export default {
// //
async cancelSavePath() { async cancelSavePath() {
await HttpUtil.delete("/file/path/delete", { id: this.curSavePathId }); await HttpUtil.delete("/file/path/delete", { id: this.curSavePathId });
this.refreshSavePathList(); Bus.$emit("refreshSavePathList");
this.$emit("refreshSavePathList");
this.$message.success("操作成功"); this.$message.success("操作成功");
}, },
//
changePath(item) {
this.pathList = JSON.parse(item.content);
this.breadcrumbClick(this.pathList.length - 1);
},
}, },
}; };
</script> </script>

View File

@ -5,11 +5,13 @@
<el-menu-item :disabled="editRule != null" index="delete">删除</el-menu-item> <el-menu-item :disabled="editRule != null" index="delete">删除</el-menu-item>
<!-- <el-menu-item index="replace">替换</el-menu-item> --> <!-- <el-menu-item index="replace">替换</el-menu-item> -->
<el-menu-item :disabled="editRule != null" index="serialization">序列化</el-menu-item> <el-menu-item :disabled="editRule != null" index="serialization">序列化</el-menu-item>
<el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item>
</el-menu> </el-menu>
<div class="rule"> <div class="rule">
<insert-rule ref="rule" :editRule="editRule" v-if="currentIndex == 'insert'" /> <insert-rule ref="rule" :editRule="editRule" v-if="currentIndex == 'insert'" />
<delete-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'delete'" /> <delete-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'delete'" />
<serialization-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'serialization'" /> <serialization-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'serialization'" />
<auto-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'auto'" />
</div> </div>
</div> </div>
<div style="text-align: center"> <div style="text-align: center">
@ -21,9 +23,11 @@
import InsertRule from "./rules/InsertRule.vue"; import InsertRule from "./rules/InsertRule.vue";
import DeleteRule from "./rules/DeleteRule.vue"; import DeleteRule from "./rules/DeleteRule.vue";
import SerializationRule from "./rules/SerializationRule.vue"; import SerializationRule from "./rules/SerializationRule.vue";
import AutoRule from "./rules/AutoRule";
export default { export default {
components: { InsertRule, DeleteRule, SerializationRule }, components: { InsertRule, DeleteRule, SerializationRule, AutoRule },
props: ["editRule"], props: ["editRule"],
emits: ["ruleAdd"],
name: "Rule", name: "Rule",
data() { data() {
return { return {

View File

@ -0,0 +1,93 @@
<template>
<div class="flex">
<span class="left">识别类型</span>
<div class="location">
<el-radio v-model="ruleObj.data.type" label="season"
>季号识别
<el-tooltip effect="dark" :content="message2" placement="top">
<el-icon><InfoFilled /></el-icon>
</el-tooltip>
</el-radio>
<el-radio v-model="ruleObj.data.type" label="name"
>剧名/电影名识别
<el-tooltip effect="dark" :content="message2" placement="top">
<el-icon><InfoFilled /></el-icon>
</el-tooltip>
</el-radio>
</div>
</div>
<div class="flex">
<div class="left">前面追加:</div>
<el-input v-model="ruleObj.data.frontAdd" placeholder="识别内容前面追加,未识别到不会追加" style="width: 20em" />
</div>
<div class="flex">
<div class="left">后面追加:</div>
<el-input v-model="ruleObj.data.endAdd" placeholder="识别内容后面追加,未识别到不会追加" style="width: 20em" />
</div>
</template>
<script>
import { InfoFilled } from "@element-plus/icons-vue";
export default {
name: "AutoRule",
props: ["editRule"],
components: { InfoFilled },
data() {
return {
message1: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的',
message2:
"如果父文件夹包含season字段那么会从父文件夹的父文件夹名称中取剧名否则将从父文件夹名称中取电影名。规则为从开头开始取直到遇见第一个空格/./[等符号",
ruleObj: {
type: "auto",
message: "",
data: {
type: "",
frontAdd: "",
endAdd: "",
},
},
};
},
created() {
if (this.editRule) {
console.log(this.editRule);
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
}
},
methods: {
exportObj() {
if (this.ruleObj.data.type === "") {
this.$message({ message: "请选择识别类型", type: "warning" });
return null;
}
this.ruleObj.message = `自动识别:"${this.ruleObj.data.type == "season" ? "季号" : "剧名/电影名识别"}";`;
if (this.ruleObj.data.frontAdd.length > 0) {
this.ruleObj.message += `前缀添加:${this.ruleObj.data.frontAdd}`;
}
if (this.ruleObj.data.endAdd.length > 0) {
this.ruleObj.message += `后缀添加:${this.ruleObj.data.endAdd}`;
}
return this.ruleObj;
},
},
};
</script>
<style lang="less" scoped>
.flex {
display: flex;
justify-content: left;
align-items: center;
padding-top: 1em;
.left {
width: 6em;
}
.location {
justify-content: left;
flex-direction: column;
display: flex;
}
}
</style>

View File

@ -23,16 +23,36 @@
<div class="flex"> <div class="flex">
<div class="left">季号识别:</div> <div class="left">季号识别:</div>
<el-switch v-model="ruleObj.data.autoSeason" /> <el-switch v-model="ruleObj.data.autoSeason" />
通过识别文件夹名称获取季号放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的 <el-tooltip effect="dark" :content="message1" placement="top">
<el-icon><InfoFilled /></el-icon>
</el-tooltip>
</div>
<div class="flex">
<div class="left">有效后缀:</div>
<el-switch v-model="ruleObj.data.endFilter" />
<template v-if="ruleObj.data.endFilter">
<el-tag v-for="item in ruleObj.data.validEnd" closable :key="item" @close="deleteEnd(item)" text>{{ item }}</el-tag>
<el-input v-if="validEndInputShow" v-model="validEndInput" style="width: 5em" size="small" @keyup.enter="validEndAdd" @blur="validEndAdd" />
<el-button v-else class="button-new-tag ml-1" size="small" @click="validEndInputShow = true">+ 新增</el-button>
</template>
<el-tooltip effect="dark" :content="message2" placement="top">
<el-icon><InfoFilled /></el-icon>
</el-tooltip>
</div> </div>
</template> </template>
<script> <script>
import { InfoFilled } from "@element-plus/icons-vue";
export default { export default {
name: "InsertRule", name: "InsertRule",
props: ["editRule"], props: ["editRule"],
components: { InfoFilled },
data() { data() {
return { return {
message1: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的',
message2: '开启本选项后,本规则只在后缀匹配时才会生效.(输入后缀不包含".")',
validEndInputShow: false,
validEndInput: "",
ruleObj: { ruleObj: {
type: "insert", type: "insert",
message: "", message: "",
@ -43,6 +63,8 @@ export default {
atIsRightToleft: false, atIsRightToleft: false,
ignorePostfix: true, ignorePostfix: true,
autoSeason: false, autoSeason: false,
endFilter: false,
validEnd: ["srt", "ass"],
}, },
}, },
}; };
@ -62,6 +84,14 @@ export default {
this.ruleObj.message = `插入:"${this.ruleObj.data.insertContent}"`; this.ruleObj.message = `插入:"${this.ruleObj.data.insertContent}"`;
return this.ruleObj; return this.ruleObj;
}, },
validEndAdd() {
this.ruleObj.data.validEnd.push(this.validEndInput);
this.validEndInput = "";
this.validEndInputShow = false;
},
deleteEnd(item) {
this.ruleObj.data.validEnd.splice(this.ruleObj.data.validEnd.indexOf(item), 1);
},
}, },
}; };
</script> </script>

View File

@ -0,0 +1,33 @@
class Bus {
constructor() {
this.list = {
}; // 收集订阅
}
// 订阅
$on (name, fn) {
this.list[name] = this.list[name] || [];
this.list[name].push(fn);
}
// 发布
$emit (name, data) {
if (this.list[name]) {
this.list[name].forEach((fn) => {
fn(data);
});
}
}
// 取消订阅
$off (name) {
if (this.list[name]) {
delete this.list[name];
}
}
}
export default new Bus;

View File

@ -1,7 +1,7 @@
<template> <template>
<div v-loading="loading" element-loading-text="后台处理中,请稍候"> <div v-loading="loading" element-loading-text="后台处理中,请稍候">
<br /> <br />
<el-button type="primary" @click="submit" size="default">重命名</el-button> <el-button type="success" @click="submit" size="default">开始重命名</el-button>
<br /><br /> <br /><br />
<!-- 规则列表 --> <!-- 规则列表 -->
<rule-block @ruleUpdate="ruleUpdate" /> <rule-block @ruleUpdate="ruleUpdate" />
@ -20,7 +20,6 @@
:key="item.id" :key="item.id"
@click="clickSavePath(item)" @click="clickSavePath(item)"
@close="deleteSavePath(item)" @close="deleteSavePath(item)"
type="primary"
text text
>{{ item.name }}</el-tag >{{ item.name }}</el-tag
> >
@ -56,17 +55,18 @@
<!-- 新增文件弹窗 --> <!-- 新增文件弹窗 -->
<el-dialog title="新增文件" v-model="dialogVisible" width="70%"> <el-dialog title="新增文件" v-model="dialogVisible" width="70%">
<file-chose ref="fileChose" :curSavePath="curSavePath" @addData="addData" @refreshSavePathList="refreshSavePathList" /> <file-chose ref="fileChose" :curChoosePath="curChoosePath" @addData="addData" @refreshSavePathList="refreshSavePathList" />
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
// @ is an alias to /src // @ is an alias to /src
import { ArrowDownBold, ArrowUpBold } from "@element-plus/icons"; import { ArrowDownBold, ArrowUpBold } from "@element-plus/icons-vue";
import HttpUtil from "../../utils/HttpUtil"; import HttpUtil from "../../utils/HttpUtil";
import FileChose from "@/components/FileChose"; import FileChose from "@/components/FileChose";
import RuleBlock from "./components/RuleBlock.vue"; import RuleBlock from "./components/RuleBlock.vue";
import Bus from "../../utils/Bus";
let numberSet = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]); let numberSet = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
@ -88,12 +88,13 @@ export default {
needPreview: false, // needPreview: false, //
applicationRule: null, // applicationRule: null, //
savePathList: [], // savePathList: [], //
curSavePath: null, // curChoosePath: null, //
}; };
}, },
async created() { async created() {
this.savePathList = await HttpUtil.get("/file/path"); this.savePathList = await HttpUtil.get("/file/path");
window.isWindows = await HttpUtil.get("/file/isWindows"); window.isWindows = await HttpUtil.get("/file/isWindows");
Bus.$on("refreshSavePathList", this.refreshSavePathList);
}, },
methods: { methods: {
// //
@ -181,17 +182,14 @@ export default {
this.dialogVisible = true; this.dialogVisible = true;
}, },
// //
clickSavePath(item) { async clickSavePath(item) {
this.curChoosePath = JSON.parse(item.content);
this.dialogVisible = true; this.dialogVisible = true;
console.log(item);
this.$nextTick(() => {
this.$refs["fileChose"].changePath(item);
});
}, },
async deleteSavePath(item) { async deleteSavePath(item) {
console.log(item); console.log(item);
await HttpUtil.delete("/file/path/delete", { id: item.id }); await HttpUtil.delete("/file/path/delete", { id: item.id });
await this.refreshSavePathList(); Bus.$emit("refreshSavePathList");
}, },
async refreshSavePathList() { async refreshSavePathList() {
this.savePathList = await HttpUtil.get("/file/path"); this.savePathList = await HttpUtil.get("/file/path");

View File

@ -12,7 +12,7 @@
> >
</div> </div>
<div class="ruleBlock"> <div class="ruleBlock">
<el-checkbox v-model="item.checked" v-for="(item, index) in ruleList" :key="index"> <el-checkbox v-model="item.checked" v-for="(item, index) in ruleList" :key="index" @dblclick="editClick(item)">
<s v-if="item.blocked">{{ item.message }}</s> <s v-if="item.blocked">{{ item.message }}</s>
<span v-else>{{ item.message }}</span> <span v-else>{{ item.message }}</span>
</el-checkbox> </el-checkbox>
@ -21,7 +21,7 @@
</div> </div>
</div> </div>
<!-- 弹窗 --> <!-- 弹窗 -->
<el-dialog title="新增规则" v-model="addRuleDialogShow" width="70%"> <el-dialog title="新增规则" v-model="addRuleDialogShow" width="70%" @close="ruleDialogClose">
<rule :editRule="editRule" @ruleAdd="ruleAdd" v-if="addRuleDialogShow" /> <rule :editRule="editRule" @ruleAdd="ruleAdd" v-if="addRuleDialogShow" />
</el-dialog> </el-dialog>
<el-dialog title="选择规则模板" v-model="ruleTemplateShow" width="70%"> <el-dialog title="选择规则模板" v-model="ruleTemplateShow" width="70%">
@ -142,10 +142,14 @@ export default {
this.ruleUpdate(); this.ruleUpdate();
}, },
// //
editClick() { editClick(rule) {
this.editRule = this.checkedRules[0]; this.editRule = rule && rule.data ? rule : this.checkedRules[0];
this.addRuleDialogShow = true; this.addRuleDialogShow = true;
}, },
ruleDialogClose() {
this.editRule = null;
this.addRuleDialogShow = false;
},
}, },
}; };
</script> </script>