Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加BCC/CRC/LRC校验功能 #199

Merged
merged 7 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bcc
  • Loading branch information
baiy committed Jan 17, 2023
commit 90f63bd410c61d01ce03c3a5125ea7e4bb19b394
7 changes: 6 additions & 1 deletion packages/ctool-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,17 @@ export let _tools = {
parent_directory: "",
keywords: []
},
dataValidation: {
feature: ['bcc', 'crc', 'lrc'],
parent_directory: "",
keywords: ['异或校验', '循环冗余校验', '纵向冗余校验']
},
} as const;

// 分类 配置
export const _categoryTool: Record<CategoryType, ToolType[]> = {
encryption: ["hash", "aes", "des", "tripleDes", "rc4", "rabbit", "sm2", "sm4", "sign", "base64", "bcrypt"],
check: ["sign", "regex", "diffs", "crontab", "bcrypt"],
check: ["sign", "regex", "diffs", "crontab", "bcrypt", "dataValidation"],
encoder_decoder: ["base64", "url", "unicode", "jwt", "hexString", "html"],
conversion: ["json", "pinyin", "radix", "serialize", "unit", "time", "ascii", "variableConversion", "hexString", "arm", "httpSnippet"],
generate: ["qrCode", "barcode", "randomString", "uuid", "binary", "ipcalc", "sqlFillParameter", "httpSnippet"],
Expand Down
6 changes: 5 additions & 1 deletion packages/ctool-core/src/i18n/locales/en/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@
"bcrypt": "Bcrypt",
"ipcalc": "Ipcalc",
"sqlFillParameter": 'Fill SQL Parameters',
"httpSnippet": 'Http Request Code'
"httpSnippet": 'Http Request Code',
"dataValidation": 'BCC/CRC/LRC Validation',
"dataValidation_bcc": 'BCC',
"dataValidation_crc": 'CRC',
"dataValidation_lrc": 'LRC'
}
4 changes: 4 additions & 0 deletions packages/ctool-core/src/i18n/locales/zh_CN/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@
"ipcalc": "IP网络计算器",
"sqlFillParameter": 'SQL参数填充',
"httpSnippet": 'Http请求代码',
"dataValidation": 'BCC/CRC/LRC校验',
"dataValidation_bcc": 'BCC',
"dataValidation_crc": 'CRC',
"dataValidation_lrc": 'LRC',
}
49 changes: 49 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/Bcc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<HeightResize v-slot="{height}" v-row="'10-14'">
<TextInput v-model="action.current.input" upload="file" :height="height" :allow="['text','hex']"/>
<Align direction="vertical">
<template v-for="key in ['Hex','Dec','Oct','Bin']">
<Textarea
:model-value="output[key]"
:height="(height - 15) / 4"
:placeholder="`${$t('main_ui_output')} ${key}`"
:copy="key"
/>
</template>
</Align>
</HeightResize>
</template>

<script lang="ts" setup>
import {initialize, useAction} from "@/store/action";
import {createTextInput} from "@/components/text";
import {Bcc} from "./util";

const action = useAction(await initialize({
input: createTextInput('hex', ""),
}, {paste: false}))

const output = $computed(() => {
if (action.current.input.text.isEmpty()) {
return {
Hex: "",
Dec: "",
Oct: "",
Bin: "",
Count: "",
}
}

const handle = new Bcc(action.current.input.text)
if (!handle.isError()){
action.save()
}
return {
Hex: handle.isError() ? handle.error : handle.hex,
Dec: handle.isError() ? handle.error : handle.dec,
Oct: handle.isError() ? handle.error : handle.oct,
Bin: handle.isError() ? handle.error : handle.bin,
Count: handle.count,
}
})
</script>
7 changes: 7 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/Crc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>

</template>

<script lang="ts" setup>

</script>
7 changes: 7 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/Lrc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>

</template>

<script lang="ts" setup>

</script>
3 changes: 3 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/i18n/en.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
3 changes: 3 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/i18n/zh_CN.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
42 changes: 42 additions & 0 deletions packages/ctool-core/src/tools/dataValidation/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Text from "@/helper/text";
import {padStart} from "lodash";
import radix from "@/helper/radix";

// 算法来源: http://www.ip33.com/bcc.html
export class Bcc {
private _dec: number = 0
private _count: number = 0
private readonly _error: string = ""

constructor(input: Text) {

}

isError() {
return this._error !== ""
}

get error() {
return this._error
}

get dec() {
return `${this._dec}`
}

get oct() {
return radix(this._dec, 10, 8)
}

get hex() {
return padStart(radix(this._dec, 10, 16), 2, "0")
}

get bin() {
return padStart(radix(this._dec, 10, 2), 8, "0")
}

get count() {
return `${this._count} Bytes`;
}
}