Merge pull request #5 from FleyX/dev

Dev
This commit is contained in:
FleyX 2022-04-28 15:22:42 +08:00 committed by GitHub
commit a3f8db74a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 142 deletions

View File

@ -7,7 +7,7 @@ renamer 的开源实现版本BS 应用,支持全平台部署使用
已实现如下三种处理规则: 已实现如下三种处理规则:
- 插入 - 插入(支持季号识别)
- 删除 - 删除
- 序列化 - 序列化

View File

@ -4,7 +4,6 @@ import * as fs from 'fs-extra';
import FileObj from '../vo/FileObj'; import FileObj from '../vo/FileObj';
import RuleObj from '../vo/RuleObj'; import RuleObj from '../vo/RuleObj';
import DeleteRule from '../vo/rules/DeleteRule';
import RuleInterface from '../vo/rules/RuleInterface'; import RuleInterface from '../vo/rules/RuleInterface';

View File

@ -2,6 +2,8 @@ import RuleInterface from "./RuleInterface";
import FileObj from "../FileObj"; import FileObj from "../FileObj";
import path from 'path'; import path from 'path';
let pattern = new RegExp(/s(eason)?(\d+)/);
export default class InsertRule implements RuleInterface { export default class InsertRule implements RuleInterface {
/** /**
@ -24,6 +26,10 @@ export default class InsertRule implements RuleInterface {
* true:false * true:false
*/ */
ignorePostfix: boolean; ignorePostfix: boolean;
/**
*/
autoSeason: boolean;
constructor(data: any) { constructor(data: any) {
this.insertContent = data.insertContent; this.insertContent = data.insertContent;
@ -31,6 +37,7 @@ export default class InsertRule implements RuleInterface {
this.atInput = data.atInput; this.atInput = data.atInput;
this.atIsRightToleft = data.atIsRightToleft; this.atIsRightToleft = data.atIsRightToleft;
this.ignorePostfix = data.ignorePostfix; this.ignorePostfix = data.ignorePostfix;
this.autoSeason = data.autoSeason;
} }
@ -51,6 +58,13 @@ export default class InsertRule implements RuleInterface {
str = this.insertContent; str = this.insertContent;
break; break;
} }
if (this.autoSeason) {
let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern);
if (patternRes[2]) {
str += patternRes[2];
}
}
if (this.ignorePostfix) { if (this.ignorePostfix) {
file.realName = str; file.realName = str;
} else { } else {
@ -61,6 +75,7 @@ export default class InsertRule implements RuleInterface {
file.realName = str; file.realName = str;
} }
} }
file.name = file.realName + file.expandName; file.name = file.realName + file.expandName;
} }
} }

View File

@ -1,14 +1,13 @@
<template> <template>
<el-menu <div class="app">
:default-active="activeIndex" <div class="content">
class="el-menu-demo" <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
mode="horizontal"
@select="handleSelect"
>
<el-menu-item index="dealCenter">处理中心</el-menu-item> <el-menu-item index="dealCenter">处理中心</el-menu-item>
<!-- <el-menu-item index="history">历史记录</el-menu-item> -->
</el-menu> </el-menu>
<router-view /> <router-view />
</div>
<div class="footer">版本{{ version }}&nbsp;&nbsp;开源地址:<a href="https://github.com/FleyX/open-renamer">open-renamer</a></div>
</div>
</template> </template>
<script> <script>
@ -17,12 +16,19 @@ export default {
data() { data() {
return { return {
activeIndex: "dealCenter", activeIndex: "dealCenter",
version: "0.6",
}; };
}, },
}; };
</script> </script>
<style lang="less"> <style lang="less">
html,
body {
padding: 0;
border: 0;
margin: 0;
}
#app { #app {
font-family: Avenir, Helvetica, Arial, sans-serif; font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
@ -31,6 +37,16 @@ export default {
color: #2c3e50; color: #2c3e50;
} }
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
.content {
flex: 1;
}
}
#nav { #nav {
padding: 30px; padding: 30px;

View File

@ -10,7 +10,7 @@
<div class="fileList"> <div class="fileList">
<div> <div>
<el-input style="display: inline-block; width: 150px" type="text" size="small" placeholder="关键词过滤" v-model="filterText" /> <el-input style="display: inline-block; width: 150px" type="text" size="small" placeholder="关键词过滤" v-model="filterText" clearable />
<el-button type="primary" @click="selectAll(true)" size="mini">全选</el-button> <el-button type="primary" @click="selectAll(true)" size="mini">全选</el-button>
<el-button type="primary" @click="selectAll(false)" size="mini">全不选</el-button> <el-button type="primary" @click="selectAll(false)" size="mini">全不选</el-button>
<el-button type="primary" @click="refresh" size="mini">刷新</el-button> <el-button type="primary" @click="refresh" size="mini">刷新</el-button>
@ -65,6 +65,7 @@ export default {
}); });
fileList.forEach((item) => (item.checked = false)); fileList.forEach((item) => (item.checked = false));
this.fileList = fileList; this.fileList = fileList;
this.filterText = "";
this.loading = false; this.loading = false;
return false; return false;
}, },
@ -103,6 +104,8 @@ export default {
} }
this.$emit("addData", chosedFiles); this.$emit("addData", chosedFiles);
this.fileList.forEach((item) => (item.checked = false)); this.fileList.forEach((item) => (item.checked = false));
this.fileList = [...this.fileList];
this.filterText = "";
}, },
}, },
}; };

View File

@ -5,60 +5,26 @@
<div> <div>
<div>开始</div> <div>开始</div>
<div class="line"> <div class="line">
<el-radio <el-radio v-model="ruleObj.data.start.type" label="location" :disabled="deleteAll">位置</el-radio>
v-model="ruleObj.data.start.type" <el-input-number :min="1" size="small" :disabled="deleteAll" v-model="startIndex" />
label="location"
:disabled="deleteAll"
>位置</el-radio
>
<el-input-number
:min="1"
size="small"
:disabled="deleteAll"
v-model="startIndex"
/>
</div> </div>
<div class="line"> <div class="line">
<el-radio <el-radio v-model="ruleObj.data.start.type" label="text" :disabled="deleteAll">文本:</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>
</div> </div>
<div style="margin-left: 4em"> <div style="margin-left: 4em">
<div>结束</div> <div>结束</div>
<div class="line"> <div class="line">
<el-radio <el-radio v-model="ruleObj.data.end.type" label="location" :disabled="deleteAll">位置</el-radio>
v-model="ruleObj.data.end.type" <el-input-number size="small" :disabled="deleteAll" v-model="endIndex" />
label="location"
:disabled="deleteAll"
>位置</el-radio
>
<el-input-number
size="small"
:disabled="deleteAll"
v-model="endIndex"
/>
</div> </div>
<div class="line"> <div class="line">
<el-radio <el-radio v-model="ruleObj.data.end.type" label="text" :disabled="deleteAll">文本:</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>
<div class="line"> <div class="line">
<el-radio <el-radio v-model="ruleObj.data.end.type" label="end" :disabled="deleteAll">直到末尾</el-radio>
v-model="ruleObj.data.end.type"
label="end"
:disabled="deleteAll"
>直到末尾</el-radio
>
</div> </div>
</div> </div>
</div> </div>
@ -93,7 +59,7 @@ export default {
type: "location", type: "location",
value: "", value: "",
}, },
ignorePostfix: false, ignorePostfix: true,
}, },
}, },
startIndex: 1, startIndex: 1,
@ -130,8 +96,7 @@ export default {
} }
if (this.ruleObj.data.type == "deletePart") { if (this.ruleObj.data.type == "deletePart") {
if ( if (
(this.ruleObj.data.start.type == "text" && (this.ruleObj.data.start.type == "text" && this.startText.length == 0) ||
this.startText.length == 0) ||
(this.ruleObj.data.start.type == "text" && this.startText.length == 0) (this.ruleObj.data.start.type == "text" && this.startText.length == 0)
) { ) {
this.$message({ this.$message({
@ -141,23 +106,13 @@ export default {
return null; return null;
} }
} }
this.ruleObj.data.start.value = this.ruleObj.data.start.value = this.ruleObj.data.start.type == "location" ? this.startIndex.toString() : this.startText;
this.ruleObj.data.start.type == "location" this.ruleObj.data.end.value = this.ruleObj.data.end.type == "location" ? this.endIndex.toString() : this.endText;
? this.startIndex.toString()
: this.startText;
this.ruleObj.data.end.value =
this.ruleObj.data.end.type == "location"
? this.endIndex.toString()
: this.endText;
let message = `删除:`; let message = `删除:`;
if (this.deleteAll) { if (this.deleteAll) {
message += "全部删除"; message += "全部删除";
} else { } else {
message += `从"${this.ruleObj.data.start.value}"到"${ message += `从"${this.ruleObj.data.start.value}"到"${this.ruleObj.data.end.type == "untilEnd" ? "末尾" : this.ruleObj.data.end.value}"`;
this.ruleObj.data.end.type == "untilEnd"
? "末尾"
: this.ruleObj.data.end.value
}"`;
} }
this.ruleObj.message = message; this.ruleObj.message = message;
return this.ruleObj; return this.ruleObj;

View File

@ -6,40 +6,25 @@
<div class="flex"> <div class="flex">
<span class="left">位置</span> <span class="left">位置</span>
<div class="location"> <div class="location">
<el-radio <el-radio style="margin-top: 1em" v-model="ruleObj.data.type" label="front">前缀</el-radio>
style="margin-top: 1em" <el-radio style="margin-top: 1em" v-model="ruleObj.data.type" label="backend">后缀</el-radio>
v-model="ruleObj.data.type"
label="front"
>前缀</el-radio
>
<el-radio
style="margin-top: 1em"
v-model="ruleObj.data.type"
label="backend"
>后缀</el-radio
>
<el-radio style="margin-top: 1em" v-model="ruleObj.data.type" label="at" <el-radio style="margin-top: 1em" v-model="ruleObj.data.type" label="at"
>位置:<el-input-number size="mini" v-model="ruleObj.data.atInput" /> >位置:<el-input-number size="mini" v-model="ruleObj.data.atInput" />
&nbsp;&nbsp; &nbsp;&nbsp;
<el-switch <el-switch v-model="ruleObj.data.atIsRightToleft" :min="1" active-text="从右到左" inactive-text="从左到右" />
v-model="ruleObj.data.atIsRightToleft"
:min="1"
active-text="从右到左"
inactive-text="从左到右"
/>
</el-radio> </el-radio>
<el-radio <el-radio style="margin-top: 1em" v-model="ruleObj.data.type" label="replace">替换当前文件名</el-radio>
style="margin-top: 1em"
v-model="ruleObj.data.type"
label="replace"
>替换当前文件名</el-radio
>
</div> </div>
</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>
<div class="flex">
<div class="left">季号识别:</div>
<el-switch v-model="ruleObj.data.autoSeason" />
通过识别文件夹名称获取季号放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的
</div>
</template> </template>
<script> <script>
@ -56,7 +41,8 @@ export default {
type: "", type: "",
atInput: 0, atInput: 0,
atIsRightToleft: false, atIsRightToleft: false,
ignorePostfix: false, ignorePostfix: true,
autoSeason: false,
}, },
}, },
}; };
@ -69,10 +55,7 @@ export default {
}, },
methods: { methods: {
exportObj() { exportObj() {
if ( if (this.ruleObj.data.insertContent.length == 0 || this.ruleObj.data.type.length == 0) {
this.ruleObj.data.insertContent.length == 0 ||
this.ruleObj.data.type.length == 0
) {
this.$message({ message: "请填写完整", type: "warning" }); this.$message({ message: "请填写完整", type: "warning" });
return null; return null;
} }

View File

@ -15,39 +15,16 @@
<span class="left">填充0补足</span> <span class="left">填充0补足</span>
<div class="right"> <div class="right">
<el-switch v-model="ruleObj.data.addZero" /> <el-switch v-model="ruleObj.data.addZero" />
<el-input-number <el-input-number size="small" :min="1" :disabled="!ruleObj.data.addZero" v-model="ruleObj.data.numLength" />
size="small"
:min="1"
:disabled="!ruleObj.data.addZero"
v-model="ruleObj.data.numLength"
/>
</div> </div>
</div> </div>
<div class="flex"> <div class="flex">
<span class="left">位置</span> <span class="left">位置</span>
<div class="location"> <div class="location">
<el-radio <el-radio style="margin-top: 1em" v-model="ruleObj.data.insertType" label="front">前缀</el-radio>
style="margin-top: 1em" <el-radio style="margin-top: 1em" v-model="ruleObj.data.insertType" label="backend">后缀</el-radio>
v-model="ruleObj.data.insertType" <el-radio style="margin-top: 1em" v-model="ruleObj.data.insertType" label="at"
label="front" >位置:<el-input-number size="mini" :min="1" :disabled="ruleObj.data.insertType !== 'at'" v-model="ruleObj.data.insertValue" />
>前缀</el-radio
>
<el-radio
style="margin-top: 1em"
v-model="ruleObj.data.insertType"
label="backend"
>后缀</el-radio
>
<el-radio
style="margin-top: 1em"
v-model="ruleObj.data.insertType"
label="at"
>位置:<el-input-number
size="mini"
:min="1"
:disabled="ruleObj.data.insertType !== 'at'"
v-model="ruleObj.data.insertValue"
/>
</el-radio> </el-radio>
</div> </div>
</div> </div>
@ -73,7 +50,7 @@ export default {
increment: 1, increment: 1,
addZero: false, addZero: false,
numLength: 1, numLength: 1,
ignorePostfix: false, ignorePostfix: true,
insertType: "front", insertType: "front",
insertValue: 1, insertValue: 1,
}, },

View File

@ -7,15 +7,7 @@ const routes = [
name: "Home", name: "Home",
component: Home, component: Home,
}, },
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue"),
},
]; ];
const router = createRouter({ const router = createRouter({

View File

@ -1,5 +0,0 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>