1 #10

Merged
fanxb merged 6 commits from main into dev 2022-05-26 23:19:41 +08:00
9 changed files with 201 additions and 41 deletions
Showing only changes of commit b0f1901731 - Show all commits

View File

@ -1,7 +1,9 @@
FROM node:lts-buster-slim
WORKDIR /app
COPY ./openRenamerBackend /app
RUN chmod 777 -R /app && npm install -g pnpm typescript --registry https://registry.npmmirror.com
# RUN chmod 777 -R /app && npm install -g pnpm typescript --registry https://registry.npmmirror.com
# 注意此处未添加npm代理
RUN chmod 777 -R /app && npm install -g pnpm typescript
ENV PORT 80
CMD ["bash", "start.sh"]

View File

@ -2,7 +2,9 @@
base=$(cd "$(dirname "$0")";pwd)
cd $base
rm -rf openRenamerBackend/dist
docker run -it --rm --name buildOpenRenamer --user ${UID} -v $base/openRenamerFront:/opt/front node:lts-slim bash -c "cd /opt/front && npm install -g pnpm --registry https://registry.npmmirror.com && pnpm install --registry https://registry.npmmirror.com && pnpm run build"
# 注意此处未添加npm代理
# docker run -it --rm --name buildOpenRenamer --user ${UID} -v $base/openRenamerFront:/opt/front node:lts-slim bash -c "cd /opt/front && npm install -g pnpm --registry https://registry.npmmirror.com && pnpm install --registry https://registry.npmmirror.com && pnpm run build"
docker run -it --rm --name buildOpenRenamer --user ${UID} -v $base/openRenamerFront:/opt/front node:lts-slim bash -c "cd /opt/front && npm install -g pnpm && pnpm install && pnpm run build"
rm -rf openRenamerBackend/static/*
touch openRenamerBackend/static/.gitkeep

View File

@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/.vscode" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View File

@ -0,0 +1,54 @@
import RuleInterface from "./RuleInterface";
import FileObj from "../../vo/FileObj";
import path from 'path';
export default class ReplaceRule implements RuleInterface {
/**
* 1:替换第一个23
*/
type: number;
/**
*
*/
source: string;
/**
*
*/
target: string;
constructor(data: any) {
this.type = data.type;
this.source = data.source;
this.target = data.target;
}
deal(file: FileObj): void {
let start = 0;
let changed = false;
for (; ;) {
let index = this.type == 1 || this.type == 3 ? file.name.indexOf(this.source, start) : file.name.lastIndexOf(this.source);
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;
}
}
if (changed) {
file.originName = file.name;
file.expandName = path.extname(file.name);
if (file.expandName && file.expandName.length > 0) {
file.realName = file.name.substring(0, file.name.lastIndexOf("."));
} else {
file.realName = file.name;
}
}
}
}

View File

@ -2,6 +2,7 @@ import DeleteRule from "../bo/rules/DeleteRule";
import InsertRule from "../bo/rules/InsertRule";
import SerializationRule from "../bo/rules/SerializationRule";
import AutoRule from "../bo/rules/AutoRule";
import ReplaceRule from "../bo/rules/ReplaceRule";
export default class RuleObj {
type: string;
@ -27,6 +28,9 @@ export default class RuleObj {
case "auto":
this.data = new AutoRule(data.data);
break;
case "replace":
this.data = new ReplaceRule(data.data);
break;
default:
throw new Error("不支持的规则:" + this.type);

View File

@ -17,7 +17,7 @@ class RenamerService {
if (newNameSet.has(obj.name)) {
obj.errorMessage = "重名";
}
newNameSet.add(obj.name);
newNameSet.add(obj.path + obj.name);
}
return fileList;
}

View File

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

View File

@ -3,15 +3,16 @@
<el-menu style="width: 8em" mode="vertical" :default-active="currentIndex" @select="menuChange">
<el-menu-item :disabled="editRule != null" index="insert">插入</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 :disabled="editRule != null" index="replace">替换</el-menu-item>
<el-menu-item :disabled="editRule != null || isAutoPlan" index="serialization">序列化</el-menu-item>
<el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item>
</el-menu>
<div class="rule">
<insert-rule ref="rule" :editRule="editRule" v-if="currentIndex == 'insert'" />
<delete-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'delete'" />
<serialization-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'serialization'" />
<auto-rule ref="rule" :editRule="editRule" v-else-if="currentIndex == 'auto'" />
<insert-rule ref="rule" :editRule="editRule" v-if="currentIndex === 'insert'"/>
<delete-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'delete'"/>
<replace-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'replace'"/>
<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 style="text-align: center">
@ -24,8 +25,10 @@ import InsertRule from "./rules/InsertRule.vue";
import DeleteRule from "./rules/DeleteRule.vue";
import SerializationRule from "./rules/SerializationRule.vue";
import AutoRule from "./rules/AutoRule";
import ReplaceRule from "@/components/rules/ReplaceRule";
export default {
components: { InsertRule, DeleteRule, SerializationRule, AutoRule },
components: {InsertRule, DeleteRule, SerializationRule, AutoRule, ReplaceRule},
props: ["editRule", "isAutoPlan"],
emits: ["ruleAdd"],
name: "Rule",

View File

@ -0,0 +1,94 @@
<template>
<div class="flex">
<span class="left"></span>
<el-input style="width:20em" v-model="ruleObj.data.source"/>
</div>
<div class="flex">
<span class="left">目标</span>
<el-input style="width:20em" v-model="ruleObj.data.target"/>
</div>
<div class="flex">
<span class="left">替换选项</span>
<div class="location">
<el-radio v-for="item in radioList" :key="item.code" v-model="ruleObj.data.type" :label="item.code"
>{{ item.label }}
</el-radio>
</div>
</div>
</template>
<script>
export default {
name: "ReplaceRule",
props: ["editRule"],
data() {
return {
radioList: [
{
label: "替换第一个",
code: 1,
},
{
label: "替换最后一个",
code: 2,
},
{
label: "全部替换",
code: 3,
},
],
ruleObj: {
type: "replace",
message: "",
data: {
source: "",
target: "",
type: 1, //1:23
},
},
};
},
created() {
if (this.editRule) {
console.log(this.editRule);
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
}
},
methods: {
exportObj() {
if (!this.ruleObj.data.source) {
this.$message({message: "源不能为空", type: "warning"});
return null;
}
if (!this.ruleObj.data.type) {
this.$message({message: "请选择替换选项", type: "warning"});
return null;
}
this.ruleObj.message = `替换:将${this.ruleObj.data.source}替换为${this.ruleObj.data.target};`
+ this.radioList.filter(item => item.code === this.ruleObj.data.type)[0].label;
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>