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

文本处理优化 #206

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions packages/ctool-core/src/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<slot></slot>
</main>
<footer v-if="$slots.footer || footerType !== 'none'">
<Align v-if="footerType === 'normal'">
<Button type="general" @click="show = false;emit('cancel')" :text="$t(`main_ui_cancel`)"/>
<Button :loading="loading" type="primary" @click="emit('ok')" :text="$t(`main_ui_ok`)"/>
</Align>
<Button :loading="loading" v-if="footerType === 'long'" type="primary" long @click="emit('ok')" :text="$t(`main_ui_ok`)"/>
<slot name="footer">
<Align v-if="footerType === 'normal'">
<Button type="general" @click="show = false;emit('cancel')" :text="$t(`main_ui_cancel`)"/>
<Button :loading="loading" type="primary" @click="emit('ok')" :text="$t(`main_ui_ok`)"/>
</Align>
<Button :loading="loading" v-if="footerType === 'long'" type="primary" long @click="emit('ok')" :text="$t(`main_ui_ok`)"/>
</slot>
</footer>
</article>
</Transition>
Expand Down Expand Up @@ -119,6 +121,7 @@ onMounted(() => {
dialog.ctool-modal {
backdrop-filter: unset;
background-color: transparent;
-webkit-backdrop-filter: unset;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ctool-core/src/components/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Link from "./ui/Link.vue";
import Tabs from "./ui/Tabs.vue";
import HelpTip from "./HelpTip.vue";
import Align from "./Align.vue";
import Checkbox from "./ui/Checkbox.vue";
import {App} from "vue";

const components = {
Expand Down Expand Up @@ -81,6 +82,8 @@ const components = {
ExtendPage,
// 元素排列
Align,
// 多选
Checkbox,
}


Expand Down
11 changes: 6 additions & 5 deletions packages/ctool-core/src/components/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
TextInputEncoderType,
TextOutputEncoderType,
SerializeInputEncoderType,
SerializeOutputEncoderType
SerializeOutputEncoderType,
CheckboxValue,
CheckboxOption
} from "@/types"
import {SerializeInput, SerializeOutput} from "./serialize";
import {TextInput, TextOutput} from "./text";
Expand Down Expand Up @@ -138,13 +140,12 @@ declare module '@vue/runtime-core' {
}
Checkbox: new () => {
$props: {
modelValue?: boolean,
label?: string,
modelValue?: CheckboxValue,
direction?: AlignDirection,
options: CheckboxOption,
size?: ComponentSizeType,
border?: boolean
disabled?: boolean,
}
$emit: (e: "change", value: boolean) => void
}
Textarea: new () => {
$props: {
Expand Down
84 changes: 84 additions & 0 deletions packages/ctool-core/src/components/ui/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<Align class="ctool-checkbox" :direction="direction">
<Bool v-for="key in listKeys" :key="key" :model-value="lists[key].select" :label="lists[key].label" @change="(value)=>update(key,value)" :size="size"
:border="border"/>
</Align>
</template>

<script setup lang="ts">
// 多选
import {PropType, watch} from "vue"
import {AlignDirection, ComponentSizeType, CheckboxOption, CheckboxValue} from "@/types";
import {isNumber, isString} from "lodash";
const props = defineProps({
modelValue: {
type: Array as PropType<CheckboxValue>,
default: []
},
border: {
type: Boolean,
default: false
},
direction: {
type: String as PropType<AlignDirection>,
default: "horizontal"
},
size: {
type: String as PropType<ComponentSizeType>,
default: "default"
},
options: {
type: Array as PropType<CheckboxOption>,
default: []
},
})
const serializeOptions = $computed(() => {
let items: Array<{ value: string | number, label: string }> = []
for (let item of props.options) {
if (isNumber(item) || isString(item)) {
items.push({value: item, label: `${item}`})
} else {
items.push({value: item.value, label: `${item.label}`})
}
}
return items
})
const emit = defineEmits<{ (e: 'update:modelValue', value: CheckboxValue): void }>()
type ListsValueType = Record<string, { value: string | number, select: boolean, label: string }>
let lists = $ref<ListsValueType>({})
watch(() => {
return {
options: serializeOptions,
values: props.modelValue
}
}, ({options, values}) => {
let temp: ListsValueType = {}
for (let option of options) {
temp[`${isNumber(option.value) ? 'n_' : 's_'}${option.value}`] = {
value: option.value,
select: values.includes(option.value),
label: option.label
}
}
lists = temp
}, {deep: true, immediate: true})
const listKeys = $computed(() => {
return Object.keys(lists)
})
const update = (key: string, value: boolean) => {
lists[key].select = value
emit('update:modelValue', listKeys.filter(item => lists[item].select).map(key => {
return lists[key].value
}) || [])
}
</script>
<style>
</style>
2 changes: 1 addition & 1 deletion packages/ctool-core/src/tools/ipcalc/Ipv6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {createSerializeOutput} from "@/components/serialize";
import Item from "./Item.vue";
const action = useAction(await initialize({
input: "",
input: "2404:68::",
mask0: 32,
mask1: 64,
limit: 100,
Expand Down
40 changes: 32 additions & 8 deletions packages/ctool-core/src/tools/text/Text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
@select="type=>handle('zhTran',{type})"
/>
<Button :size="size" :text="$t('text_replace')" @click="replaceShow = true"/>
<Button :size="size" :text="$t('text_escape')" @click="escapeShow = true"/>
<Button :size="size" :text="$t('text_line_remove_duplicate')" @click="handle('lineRemoveRepeat')"/>
<Dropdown :size="size" @select="(value)=>handle('rename',{type:value})" :placeholder="$t('text_rename')"
:options="renameTypeLists.filter(item=>!['spaceCase','pascalCaseSpace'].includes(item.value))"/>
<Dropdown
:size="size"
:placeholder="$t('text_line_number')"
Expand Down Expand Up @@ -145,26 +148,40 @@
/>
</Tabs>
</Modal>
<Modal v-model="escapeShow" :width="600" :title="$t('text_escape')">
<Align horizontal="center">
<Checkbox v-model="action.current.escapeChars" :options="escapeOptions"/>
</Align>
<template #footer>
<Align horizontal="center">
<Button :text="$t('text_escape_forward')" @click="handle('escape',{lists:action.current.escapeChars})"/>
<Button :text="$t('text_escape_reverse')" @click="handle('unescape',{lists:action.current.escapeChars})"/>
</Align>
</template>
</Modal>
</template>

<script lang="ts" setup>
import {initialize, useAction} from "@/store/action";
import TextHandle from "./util";
import TextHandle, {escapeChars, EscapeCharsType} from "./util";
import {ComponentSizeType, CheckboxOption} from "@/types";
import {typeLists as renameTypeLists} from "@/helper/nameConvert";
const action = useAction(await initialize({
input: "",
replace: {
search: "",
replace: "",
regular: false
}
regular: false,
},
escapeChars: Object.keys(escapeChars) as EscapeCharsType[]
}))
const size = $computed(() => {
return $t('main_locale') === 'zh_CN' ? `default` : `small`
})
const size: ComponentSizeType = 'small'
let replaceShow = $ref(false)
let statMore = $ref(false)
let escapeShow = $ref(false)
const replace = () => {
if (action.current.replace.regular) {
Expand All @@ -183,9 +200,16 @@ const handle = (method, option: Record<string, any> = {}) => {
action.success()
}
let statMore = $ref(false)
const stat = $computed(() => {
return (new TextHandle(action.current.input)).stat()
})
const escapeOptions = $computed<CheckboxOption>(() => {
return Object.keys(escapeChars).map(item => {
return {
value: item,
label: `${$t(`text_escape_${item}`)}(${escapeChars[item].string})`
}
})
})
</script>
21 changes: 17 additions & 4 deletions packages/ctool-core/src/tools/text/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"line_number": "Line Number",
"line_number_add": "Add",
"line_number_remove": "Remove",
"line_sort": "Line Sort",
"line_sort_asc": "Asc",
"line_sort_desc": "Desc",
"line_sort": "Sort",
"line_sort_asc": "Line Asc",
"line_sort_desc": "Line Desc",
"filter": "Filter",
"filter_trim": "(trim) Removes whitespace from both ends of a string",
"filter_blank_line": "Filter blank line",
Expand Down Expand Up @@ -55,5 +55,18 @@
"explain_blank_line_length_name": "Line Length",
"explain_blank_line_length_info": "Blank lines are also included in the number of lines",
"value": "value",
"stat_show": "Word: {0} UTF-8: {1} GBK: {2}"
"stat_show": "Word: {0} UTF-8: {1} GBK: {2}",
"rename": "Rename",
"escape": "Escape",
"escape_single_quote": "single quote",
"escape_double_quote": "double quote",
"escape_backslash": "backslash",
"escape_new_line": "new line",
"escape_carriage_return": "carriage return",
"escape_tab": "tab",
"escape_vertical_tab": "vertical tab",
"escape_backspace": "backspace",
"escape_form_feed": "form feed",
"escape_forward": "Escape(\\'=>')",
"escape_reverse": "Unescape('=>\\')"
}
21 changes: 17 additions & 4 deletions packages/ctool-core/src/tools/text/i18n/zh_CN.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lower_line_start": "行首小写",
"upper_word_start": "词首大写",
"lower_word_start": "词首小写",
"punctuation": "中英标点",
"punctuation": "标点",
"cn": "中文",
"en": "英文",
"simplified_traditional": "简繁",
Expand All @@ -17,9 +17,9 @@
"line_number": "行号",
"line_number_add": "添加",
"line_number_remove": "移除",
"line_sort": "行排序",
"line_sort_asc": "升序",
"line_sort_desc": "降序",
"line_sort": "排序",
"line_sort_asc": "行升序",
"line_sort_desc": "行降序",
"filter": "过滤",
"filter_trim": "过滤行首尾不可见字符(trim)",
"filter_blank_line": "过滤多余空行",
Expand Down Expand Up @@ -56,4 +56,17 @@
"explain_blank_line_length_info": "空行也会计入行数",
"value": "值",
"stat_show": "字数: {0} UTF-8: {1} GBK: {2}",
"rename": "命名",
"escape": "转义符",
"escape_single_quote": "单引号",
"escape_double_quote": "双引号",
"escape_backslash": "反斜杠",
"escape_new_line": "换行符",
"escape_carriage_return": "回车符",
"escape_tab": "水平制表符",
"escape_vertical_tab": "垂直制表符",
"escape_backspace": "退格符",
"escape_form_feed": "换页符",
"escape_forward": "正向转义(\\'=>')",
"escape_reverse": "逆向转义('=>\\')",
}
Loading