From ca6dba024f966726d099c91088d220c6fd9dad54 Mon Sep 17 00:00:00 2001 From: fanxb Date: Sun, 27 Nov 2022 20:22:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/bo/rules/AutoRule.ts | 62 ++++++ .../{vo => entity/bo}/rules/DeleteRule.ts | 184 +++++++++--------- .../{vo => entity/bo}/rules/InsertRule.ts | 179 +++++++++-------- .../{vo => entity/bo}/rules/RuleInterface.ts | 10 +- .../bo}/rules/SerializationRule.ts | 158 +++++++-------- openRenamerBackend/{ => entity}/vo/FileObj.ts | 103 +++++----- openRenamerBackend/{ => entity}/vo/RuleObj.ts | 60 +++--- openRenamerBackend/service/FileService.ts | 5 +- openRenamerBackend/service/RenamerService.ts | 6 +- openRenamerFront/package.json | 2 +- openRenamerFront/public/index.html | 15 +- openRenamerFront/src/App.vue | 1 + openRenamerFront/src/components/FileChose.vue | 47 +++-- openRenamerFront/src/components/Rule.vue | 6 +- .../src/components/rules/AutoRule.vue | 93 +++++++++ .../src/components/rules/InsertRule.vue | 32 ++- openRenamerFront/src/utils/Bus.js | 33 ++++ openRenamerFront/src/views/home/Home.vue | 20 +- .../src/views/home/components/RuleBlock.vue | 12 +- 19 files changed, 648 insertions(+), 380 deletions(-) create mode 100644 openRenamerBackend/entity/bo/rules/AutoRule.ts rename openRenamerBackend/{vo => entity/bo}/rules/DeleteRule.ts (93%) rename openRenamerBackend/{vo => entity/bo}/rules/InsertRule.ts (84%) rename openRenamerBackend/{vo => entity/bo}/rules/RuleInterface.ts (64%) rename openRenamerBackend/{vo => entity/bo}/rules/SerializationRule.ts (93%) rename openRenamerBackend/{ => entity}/vo/FileObj.ts (92%) rename openRenamerBackend/{ => entity}/vo/RuleObj.ts (53%) create mode 100644 openRenamerFront/src/components/rules/AutoRule.vue create mode 100644 openRenamerFront/src/utils/Bus.js diff --git a/openRenamerBackend/entity/bo/rules/AutoRule.ts b/openRenamerBackend/entity/bo/rules/AutoRule.ts new file mode 100644 index 0000000..adc1243 --- /dev/null +++ b/openRenamerBackend/entity/bo/rules/AutoRule.ts @@ -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 { + + /** + * 识别类型,season:季号,name:剧名/电影名识别 + */ + 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; + } + + } +} \ No newline at end of file diff --git a/openRenamerBackend/vo/rules/DeleteRule.ts b/openRenamerBackend/entity/bo/rules/DeleteRule.ts similarity index 93% rename from openRenamerBackend/vo/rules/DeleteRule.ts rename to openRenamerBackend/entity/bo/rules/DeleteRule.ts index 3a63cb8..530f9a1 100644 --- a/openRenamerBackend/vo/rules/DeleteRule.ts +++ b/openRenamerBackend/entity/bo/rules/DeleteRule.ts @@ -1,92 +1,92 @@ -import RuleInterface from "./RuleInterface"; -import FileObj from "../FileObj"; -import path from 'path'; - -export default class DeleteRule implements RuleInterface { - /** - * 类别:deletePart:部分删除,deleteAll:全部删除 - */ - type: string; - /** - * 部分删除时的开始信息 - */ - start: DeleteRuleItem; - /** - * 部分删除时的结束信息 - - */ - end: DeleteRuleItem; - /** - * 忽略拓展名,true:忽略,false:不忽略 - */ - ignorePostfix: boolean; - - constructor(data: any) { - this.type = data.type; - this.start = new DeleteRuleItem(data.start); - this.end = new DeleteRuleItem(data.end); - this.ignorePostfix = data.ignorePostfix; - } - - - - deal(file: FileObj): void { - if (this.type === 'deleteAll') { - file.realName = ""; - if (!this.ignorePostfix) { - file.expandName = ""; - } - } else { - let str = file.realName + (this.ignorePostfix ? "" : file.expandName); - let startIndex = this.start.calIndex(str); - let endIndex = this.end.calIndex(str); - if (startIndex < 0 || endIndex < 0) { - return; - } - str = str.substring(0, startIndex) + str.substring(endIndex + 1); - 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; - } - -} - -class DeleteRuleItem { - /** - * location:位置,text:文本,end:直到末尾 - */ - type: string; - /** - * 对应的值 - */ - value: string; - - constructor(data: any) { - this.type = data.type; - this.value = data.value; - } - - /** - * 计算位置 - */ - calIndex(str: string): number { - if (this.type === 'location') { - return parseInt(this.value) - 1; - } else if (this.type === 'text') { - return str.indexOf(this.value); - } else if (this.type === 'end') { - return str.length - 1; - } - return -1; - } -} +import RuleInterface from "./RuleInterface"; +import FileObj from "../../vo/FileObj"; +import path from 'path'; + +export default class DeleteRule implements RuleInterface { + /** + * 类别:deletePart:部分删除,deleteAll:全部删除 + */ + type: string; + /** + * 部分删除时的开始信息 + */ + start: DeleteRuleItem; + /** + * 部分删除时的结束信息 + + */ + end: DeleteRuleItem; + /** + * 忽略拓展名,true:忽略,false:不忽略 + */ + ignorePostfix: boolean; + + constructor(data: any) { + this.type = data.type; + this.start = new DeleteRuleItem(data.start); + this.end = new DeleteRuleItem(data.end); + this.ignorePostfix = data.ignorePostfix; + } + + + + deal(file: FileObj): void { + if (this.type === 'deleteAll') { + file.realName = ""; + if (!this.ignorePostfix) { + file.expandName = ""; + } + } else { + let str = file.realName + (this.ignorePostfix ? "" : file.expandName); + let startIndex = this.start.calIndex(str); + let endIndex = this.end.calIndex(str); + if (startIndex < 0 || endIndex < 0) { + return; + } + str = str.substring(0, startIndex) + str.substring(endIndex + 1); + 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; + } + +} + +class DeleteRuleItem { + /** + * location:位置,text:文本,end:直到末尾 + */ + type: string; + /** + * 对应的值 + */ + value: string; + + constructor(data: any) { + this.type = data.type; + this.value = data.value; + } + + /** + * 计算位置 + */ + calIndex(str: string): number { + if (this.type === 'location') { + return parseInt(this.value) - 1; + } else if (this.type === 'text') { + return str.indexOf(this.value); + } else if (this.type === 'end') { + return str.length - 1; + } + return -1; + } +} diff --git a/openRenamerBackend/vo/rules/InsertRule.ts b/openRenamerBackend/entity/bo/rules/InsertRule.ts similarity index 84% rename from openRenamerBackend/vo/rules/InsertRule.ts rename to openRenamerBackend/entity/bo/rules/InsertRule.ts index df7ae7c..965f11a 100644 --- a/openRenamerBackend/vo/rules/InsertRule.ts +++ b/openRenamerBackend/entity/bo/rules/InsertRule.ts @@ -1,83 +1,98 @@ -import RuleInterface from "./RuleInterface"; -import FileObj from "../FileObj"; -import path from 'path'; - - -let pattern = new RegExp(/s(eason)?(\d+)/); -export default class InsertRule implements RuleInterface { - - /** - * 插入内容 - */ - insertContent: string; - /** - * 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名 - */ - type: string; - /** - * 当type为at,时的位置,从1开始 - */ - atInput: number; - /** - * 当type为at,时的方向,true:从右到左,false:从左到右 - */ - atIsRightToleft: boolean; - /** - * 忽略拓展名,true:忽略,false:不忽略 - */ - ignorePostfix: boolean; - /** - 自动识别季号 - */ - autoSeason: boolean; - - constructor(data: any) { - this.insertContent = data.insertContent; - this.type = data.type; - this.atInput = data.atInput; - this.atIsRightToleft = data.atIsRightToleft; - this.ignorePostfix = data.ignorePostfix; - this.autoSeason = data.autoSeason; - } - - - deal(file: FileObj): void { - let str = this.ignorePostfix ? file.realName : file.name; - let season = ''; - if (this.autoSeason) { - let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern); - if (patternRes && patternRes[2]) { - season = patternRes[2]; - } - } - switch (this.type) { - case "front": - str = this.insertContent + season + str; - break; - case "backend": - str = str + this.insertContent + season; - break; - case "at": - let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1; - str = str.substring(0, index) + this.insertContent + season + str.substring(index); - break; - case "replace": - str = this.insertContent + season; - 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; - } +import RuleInterface from "./RuleInterface"; +import FileObj from "../../vo/FileObj"; +import path from 'path'; + + +let pattern = new RegExp(/s(eason)?(\d+)/); +export default class InsertRule implements RuleInterface { + + /** + * 插入内容 + */ + insertContent: string; + /** + * 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名 + */ + type: string; + /** + * 当type为at,时的位置,从1开始 + */ + atInput: number; + /** + * 当type为at,时的方向,true:从右到左,false:从左到右 + */ + atIsRightToleft: boolean; + /** + * 忽略拓展名,true:忽略,false:不忽略 + */ + ignorePostfix: boolean; + /** + 自动识别季号 + */ + autoSeason: boolean; + /** + 后缀过滤是否开启 + */ + endFilter: boolean; + /** + 有效后缀 + */ + validEnd: Array; + + constructor(data: any) { + this.insertContent = data.insertContent; + this.type = data.type; + this.atInput = data.atInput; + this.atIsRightToleft = data.atIsRightToleft; + this.ignorePostfix = data.ignorePostfix; + this.autoSeason = data.autoSeason; + this.endFilter = data.endFilter; + this.validEnd = data.validEnd; + } + + + deal(file: FileObj): void { + if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) { + //拓展名不符,跳过 + return; + } + let str = this.ignorePostfix ? file.realName : file.name; + let season = ''; + + if (this.autoSeason) { + let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern); + if (patternRes && patternRes[2]) { + season = patternRes[2]; + } + } + switch (this.type) { + case "front": + str = this.insertContent + season + str; + break; + case "backend": + str = str + this.insertContent + season; + break; + case "at": + let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1; + str = str.substring(0, index) + this.insertContent + season + str.substring(index); + break; + case "replace": + str = this.insertContent + season; + 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; + } } \ No newline at end of file diff --git a/openRenamerBackend/vo/rules/RuleInterface.ts b/openRenamerBackend/entity/bo/rules/RuleInterface.ts similarity index 64% rename from openRenamerBackend/vo/rules/RuleInterface.ts rename to openRenamerBackend/entity/bo/rules/RuleInterface.ts index 4d4a3f8..cdd3030 100644 --- a/openRenamerBackend/vo/rules/RuleInterface.ts +++ b/openRenamerBackend/entity/bo/rules/RuleInterface.ts @@ -1,6 +1,6 @@ -import FileObj from "../FileObj"; - -export default interface RuleInterface { - - deal(file: FileObj): void; +import FileObj from "../../vo/FileObj"; + +export default interface RuleInterface { + + deal(file: FileObj): void; } \ No newline at end of file diff --git a/openRenamerBackend/vo/rules/SerializationRule.ts b/openRenamerBackend/entity/bo/rules/SerializationRule.ts similarity index 93% rename from openRenamerBackend/vo/rules/SerializationRule.ts rename to openRenamerBackend/entity/bo/rules/SerializationRule.ts index 3b5b569..e99f116 100644 --- a/openRenamerBackend/vo/rules/SerializationRule.ts +++ b/openRenamerBackend/entity/bo/rules/SerializationRule.ts @@ -1,80 +1,80 @@ -import RuleInterface from "./RuleInterface"; -import FileObj from "../FileObj"; -import path from 'path'; - -export default class InsertRule implements RuleInterface { - /** - * 开始位置 - */ - start: number; - /** - * 记录当前的值是多少 - */ - currentIndex: number; - /** - * 增量 - */ - increment: number; - /** - * 是否填充0 - */ - addZero: boolean; - /** - * 填充后长度 - */ - numLength: number; - /** - * 插入位置,front:前缀,backend:后缀,at:位置 - */ - insertType: string; - /** - * 插入的位置 - */ - insertValue: number; - /** - * 忽略拓展名 - */ - ignorePostfix: boolean; - - constructor(data: any) { - this.start = data.start; - this.currentIndex = data.start; - this.increment = data.increment; - this.addZero = data.addZero; - this.numLength = data.numLength; - this.insertType = data.insertType; - this.insertValue = data.insertValue; - this.ignorePostfix = data.ignorePostfix; - } - - deal(file: FileObj): void { - let length = this.currentIndex.toString().length; - let numStr = (this.addZero && this.numLength > length ? "0".repeat(this.numLength - length) : "") + this.currentIndex; - let str = this.ignorePostfix ? file.realName : file.name; - switch (this.insertType) { - case "front": - str = numStr + str; - break; - case "backend": - str = str + numStr; - break; - case "at": - str = str.substring(0, this.insertValue - 1) + numStr + str.substring(this.insertValue - 1); - break; - } - this.currentIndex += this.increment; - - 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; - } +import RuleInterface from "./RuleInterface"; +import FileObj from "../../vo/FileObj"; +import path from 'path'; + +export default class InsertRule implements RuleInterface { + /** + * 开始位置 + */ + start: number; + /** + * 记录当前的值是多少 + */ + currentIndex: number; + /** + * 增量 + */ + increment: number; + /** + * 是否填充0 + */ + addZero: boolean; + /** + * 填充后长度 + */ + numLength: number; + /** + * 插入位置,front:前缀,backend:后缀,at:位置 + */ + insertType: string; + /** + * 插入的位置 + */ + insertValue: number; + /** + * 忽略拓展名 + */ + ignorePostfix: boolean; + + constructor(data: any) { + this.start = data.start; + this.currentIndex = data.start; + this.increment = data.increment; + this.addZero = data.addZero; + this.numLength = data.numLength; + this.insertType = data.insertType; + this.insertValue = data.insertValue; + this.ignorePostfix = data.ignorePostfix; + } + + deal(file: FileObj): void { + let length = this.currentIndex.toString().length; + let numStr = (this.addZero && this.numLength > length ? "0".repeat(this.numLength - length) : "") + this.currentIndex; + let str = this.ignorePostfix ? file.realName : file.name; + switch (this.insertType) { + case "front": + str = numStr + str; + break; + case "backend": + str = str + numStr; + break; + case "at": + str = str.substring(0, this.insertValue - 1) + numStr + str.substring(this.insertValue - 1); + break; + } + this.currentIndex += this.increment; + + 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; + } } \ No newline at end of file diff --git a/openRenamerBackend/vo/FileObj.ts b/openRenamerBackend/entity/vo/FileObj.ts similarity index 92% rename from openRenamerBackend/vo/FileObj.ts rename to openRenamerBackend/entity/vo/FileObj.ts index 79e3cee..4246849 100644 --- a/openRenamerBackend/vo/FileObj.ts +++ b/openRenamerBackend/entity/vo/FileObj.ts @@ -1,50 +1,55 @@ -import * as pathUtil from "path"; -export default class FileObj { - /** - * 文件名 - */ - name: string; - /** - * 拓展名 - */ - expandName: string; - /** - * 去掉拓展名后的名字 - */ - realName: string; - /** - * 所属路径 - */ - path: string; - /** - * 是否文件夹 - */ - isFolder: boolean; - /** - * 重命名错误原因 - */ - errorMessage: string; - /** - * 创建时间ms - */ - createdTime: number; - /** - * 更新时间ms - */ - updatedTime: number; - - - constructor(name: string, path, isFolder, createdTime, updatedTime) { - this.name = name; - this.expandName = pathUtil.extname(name); - if (this.expandName.length > 0) { - this.realName = name.substring(0, name.lastIndexOf(".")); - } else { - this.realName = name; - } - this.path = path; - this.isFolder = isFolder; - this.createdTime = createdTime; - this.updatedTime = updatedTime; - } +import * as pathUtil from "path"; +export default class FileObj { + /** + * 文件名 + */ + name: string; + /** + 原始名字 + */ + originName: string; + /** + * 拓展名 + */ + expandName: string; + /** + * 去掉拓展名后的名字 + */ + realName: string; + /** + * 所属路径 + */ + path: string; + /** + * 是否文件夹 + */ + isFolder: boolean; + /** + * 重命名错误原因 + */ + errorMessage: string; + /** + * 创建时间ms + */ + createdTime: number; + /** + * 更新时间ms + */ + updatedTime: number; + + + constructor(name: string, path, isFolder, createdTime, updatedTime) { + this.name = name; + this.originName = name; + this.expandName = pathUtil.extname(name); + if (this.expandName.length > 0) { + this.realName = name.substring(0, name.lastIndexOf(".")); + } else { + this.realName = name; + } + this.path = path; + this.isFolder = isFolder; + this.createdTime = createdTime; + this.updatedTime = updatedTime; + } } \ No newline at end of file diff --git a/openRenamerBackend/vo/RuleObj.ts b/openRenamerBackend/entity/vo/RuleObj.ts similarity index 53% rename from openRenamerBackend/vo/RuleObj.ts rename to openRenamerBackend/entity/vo/RuleObj.ts index 8a1e925..5444998 100644 --- a/openRenamerBackend/vo/RuleObj.ts +++ b/openRenamerBackend/entity/vo/RuleObj.ts @@ -1,27 +1,35 @@ -import DeleteRule from "./rules/DeleteRule"; -import InsertRule from "./rules/InsertRule"; -import SerializationRule from "./rules/SerializationRule"; - -export default class RuleObj { - 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; - default: - this.data = new SerializationRule(data.data); - } - } +import DeleteRule from "../bo/rules/DeleteRule"; +import InsertRule from "../bo/rules/InsertRule"; +import SerializationRule from "../bo/rules/SerializationRule"; +import AutoRule from "../bo/rules/AutoRule"; + +export default class RuleObj { + 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); + + } + } } \ No newline at end of file diff --git a/openRenamerBackend/service/FileService.ts b/openRenamerBackend/service/FileService.ts index 4d4b8cf..ac7d1d5 100644 --- a/openRenamerBackend/service/FileService.ts +++ b/openRenamerBackend/service/FileService.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import ProcessHelper from '../util/ProcesHelper'; -import FileObj from '../vo/FileObj'; +import FileObj from '../entity/vo/FileObj'; import SavePathDao from '../dao/SavePathDao'; import SavePath from '../entity/dto/SavePath'; @@ -28,6 +28,9 @@ class FileService { fileList = await fs.readdir(pathStr); } } else { + if (!(fs.pathExists(pathStr))) { + throw new Error("路径不存在"); + } fileList = await fs.readdir(pathStr); } let folderList: Array = new Array(); diff --git a/openRenamerBackend/service/RenamerService.ts b/openRenamerBackend/service/RenamerService.ts index d9d534a..546c4d0 100644 --- a/openRenamerBackend/service/RenamerService.ts +++ b/openRenamerBackend/service/RenamerService.ts @@ -2,9 +2,9 @@ import config from '../config'; import * as path from 'path'; import * as fs from 'fs-extra'; -import FileObj from '../vo/FileObj'; -import RuleObj from '../vo/RuleObj'; -import RuleInterface from '../vo/rules/RuleInterface'; +import FileObj from '../entity/vo/FileObj'; +import RuleObj from '../entity/vo/RuleObj'; +import RuleInterface from '../entity/bo/rules/RuleInterface'; class RenamerService { diff --git a/openRenamerFront/package.json b/openRenamerFront/package.json index a26eb13..cb1b59c 100644 --- a/openRenamerFront/package.json +++ b/openRenamerFront/package.json @@ -8,7 +8,7 @@ "lint": "vue-cli-service lint" }, "dependencies": { - "@element-plus/icons": "^0.0.11", + "@element-plus/icons-vue": "^2.0.10", "axios": "^0.21.1", "core-js": "^3.6.5", "dayjs": "^1.10.7", diff --git a/openRenamerFront/public/index.html b/openRenamerFront/public/index.html index 3e5a139..478ac5f 100644 --- a/openRenamerFront/public/index.html +++ b/openRenamerFront/public/index.html @@ -1,15 +1,18 @@ - - - - - <%= htmlWebpackPlugin.options.title %> + + + + + renamer
diff --git a/openRenamerFront/src/App.vue b/openRenamerFront/src/App.vue index 9f4751b..9bb76f9 100644 --- a/openRenamerFront/src/App.vue +++ b/openRenamerFront/src/App.vue @@ -1,5 +1,6 @@ diff --git a/openRenamerFront/src/utils/Bus.js b/openRenamerFront/src/utils/Bus.js new file mode 100644 index 0000000..5a49f8e --- /dev/null +++ b/openRenamerFront/src/utils/Bus.js @@ -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; \ No newline at end of file diff --git a/openRenamerFront/src/views/home/Home.vue b/openRenamerFront/src/views/home/Home.vue index 8b3022e..e6a026e 100644 --- a/openRenamerFront/src/views/home/Home.vue +++ b/openRenamerFront/src/views/home/Home.vue @@ -1,7 +1,7 @@