Skip to content

Commit

Permalink
Merge pull request 'dev' (#43) from dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
FleyX committed May 10, 2023
2 parents ae9a2d5 + faedc09 commit b0f1901
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 41 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions openRenamerBackend/.idea/openRenamerBackend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions openRenamerBackend/entity/bo/rules/ReplaceRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import RuleInterface from "./RuleInterface";
import FileObj from "../../vo/FileObj";
import path from 'path';


export default class ReplaceRule implements RuleInterface {

/**
* 1:替换第一个,2:替换最后一个,3:全部替换
*/
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;
}
}
}
}
56 changes: 30 additions & 26 deletions openRenamerBackend/entity/vo/RuleObj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,38 @@ 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;
message: string;
/**
* 具体参数
*/
data: any;
type: string;
message: string;
/**
* 具体参数
*/
data: any;

constructor(data: any) {
this.type = data.type;
this.message = data.message;
switch (this.type) {
case "delete":
this.data = new DeleteRule(data.data);
break;
case "insert":
this.data = new InsertRule(data.data);
break;
case "serialization":
this.data = new SerializationRule(data.data);
break;
case "auto":
this.data = new AutoRule(data.data);
break;
default:
throw new Error("不支持的规则:" + this.type);
constructor(data: any) {
this.type = data.type;
this.message = data.message;
switch (this.type) {
case "delete":
this.data = new DeleteRule(data.data);
break;
case "insert":
this.data = new InsertRule(data.data);
break;
case "serialization":
this.data = new SerializationRule(data.data);
break;
case "auto":
this.data = new AutoRule(data.data);
break;
case "replace":
this.data = new ReplaceRule(data.data);
break;
default:
throw new Error("不支持的规则:" + this.type);

}
}
}
}
}
2 changes: 1 addition & 1 deletion openRenamerBackend/service/RenamerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion openRenamerFront/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
name: "Home",
data() {
return {
version: "1.5",
version: "1.6",
latestVersion: null,
activeIndex: location.pathname,
showNewVersion: false
Expand Down
25 changes: 14 additions & 11 deletions openRenamerFront/src/components/Rule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -24,27 +25,29 @@ 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",
data () {
data() {
return {
currentIndex: "insert",
options: [{ label: "插入", value: "insert" }],
options: [{label: "插入", value: "insert"}],
};
},
created () {
created() {
if (this.editRule) {
this.currentIndex = this.editRule.type;
}
},
methods: {
menuChange (index) {
menuChange(index) {
this.currentIndex = index;
},
submit () {
submit() {
let data = this.$refs["rule"].exportObj();
if (data != null) {
this.$emit("ruleAdd", data);
Expand Down
94 changes: 94 additions & 0 deletions openRenamerFront/src/components/rules/ReplaceRule.vue
Original file line number Diff line number Diff line change
@@ -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:替换第一个,2:替换最后一个,3:全部替换
},
},
};
},
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>

0 comments on commit b0f1901

Please sign in to comment.