Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
refactor: optimize structure
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 4, 2023
1 parent b23fbd1 commit 4d278db
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const treeHeight = computed(() => {
v-model:selected-keys="selectedKeysFilter"
block-line
selectable
default-expand-all
expand-on-click
:pattern="searchText"
:show-irrelevant-nodes="false"
:cancelable="false"
Expand Down
161 changes: 85 additions & 76 deletions src/components/ActionEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,80 +53,89 @@ const taskCustomActParam = wrapProp(task, 'custom_action_param')
</script>

<template>
<ClearButton v-model="taskAct"> 动作 </ClearButton>
<NSelect
v-model:value="taskAct"
:options="actOptions"
:placeholder="actOptions[0].label"
></NSelect>
<template v-if="taskActValue === 'Click'">
<TargetEdit
name="目标"
v-model:offset="taskTargetOfs"
:value="taskTarget === true ? 1 : taskTarget"
:navigate="navigate"
@update:value="
v => {
taskTarget = v === 1 ? true : v
}
"
></TargetEdit>
</template>
<template v-else-if="taskActValue === 'Swipe'">
<TargetEdit
name="起点"
v-model:offset="taskBeginOfs"
:value="taskBegin === true ? 1 : taskBegin"
:navigate="navigate"
@update:value="
v => {
taskBegin = v === 1 ? true : v
}
"
></TargetEdit>
<TargetEdit
required
name="终点"
v-model:offset="taskEndOfs"
:value="taskEnd === true ? 1 : taskEnd"
:navigate="navigate"
@update:value="
v => {
taskEnd = v === 1 ? true : v
}
"
></TargetEdit>
</template>
<template v-else-if="taskActValue === 'Key'">
<ClearButton v-model="taskKey"> 按键 </ClearButton>
<span> {{ taskKey }} </span>
</template>
<template v-else-if="taskActValue === 'StartApp'">
<ClearButton v-model="taskPackage"> 包名 </ClearButton>
<StringArrayEdit
type="single"
:nullable="true"
def=""
:value="taskPackage"
@update:value="v => {taskPackage = v as string}"
placeholder="package/activity"
></StringArrayEdit>
</template>
<template v-else-if="taskActValue === 'StopApp'">
<ClearButton v-model="taskPackage"> 包名 </ClearButton>
<StringArrayEdit
type="single"
:nullable="true"
def=""
:value="taskPackage"
@update:value="v => {taskPackage = v as string}"
placeholder="package"
></StringArrayEdit>
</template>
<template v-else-if="taskActValue === 'Custom'">
<ClearButton v-model="taskCustomAct" invalid> 任务名 </ClearButton>
<NInput v-model:value="taskCustomAct" placeholder="task"></NInput>
<ClearButton v-model="taskCustomActParam"> 任务参数 </ClearButton>
<JsonEdit v-model:value="taskCustomActParam"></JsonEdit>
</template>
<div
class="grid items-center"
style="
grid-template-columns: max-content minmax(0, 1fr);
column-gap: 0.5rem;
row-gap: 1rem;
"
>
<ClearButton v-model="taskAct"> 动作 </ClearButton>
<NSelect
v-model:value="taskAct"
:options="actOptions"
:placeholder="actOptions[0].label"
></NSelect>
<template v-if="taskActValue === 'Click'">
<TargetEdit
name="目标"
v-model:offset="taskTargetOfs"
:value="taskTarget === true ? 1 : taskTarget"
:navigate="navigate"
@update:value="
v => {
taskTarget = v === 1 ? true : v
}
"
></TargetEdit>
</template>
<template v-else-if="taskActValue === 'Swipe'">
<TargetEdit
name="起点"
v-model:offset="taskBeginOfs"
:value="taskBegin === true ? 1 : taskBegin"
:navigate="navigate"
@update:value="
v => {
taskBegin = v === 1 ? true : v
}
"
></TargetEdit>
<TargetEdit
required
name="终点"
v-model:offset="taskEndOfs"
:value="taskEnd === true ? 1 : taskEnd"
:navigate="navigate"
@update:value="
v => {
taskEnd = v === 1 ? true : v
}
"
></TargetEdit>
</template>
<template v-else-if="taskActValue === 'Key'">
<ClearButton v-model="taskKey"> 按键 </ClearButton>
<span> {{ taskKey }} </span>
</template>
<template v-else-if="taskActValue === 'StartApp'">
<ClearButton v-model="taskPackage"> 包名 </ClearButton>
<StringArrayEdit
type="single"
:nullable="true"
def=""
:value="taskPackage"
@update:value="v => {taskPackage = v as string}"
placeholder="package/activity"
></StringArrayEdit>
</template>
<template v-else-if="taskActValue === 'StopApp'">
<ClearButton v-model="taskPackage"> 包名 </ClearButton>
<StringArrayEdit
type="single"
:nullable="true"
def=""
:value="taskPackage"
@update:value="v => {taskPackage = v as string}"
placeholder="package"
></StringArrayEdit>
</template>
<template v-else-if="taskActValue === 'Custom'">
<ClearButton v-model="taskCustomAct" invalid> 任务名 </ClearButton>
<NInput v-model:value="taskCustomAct" placeholder="task"></NInput>
<ClearButton v-model="taskCustomActParam"> 任务参数 </ClearButton>
<JsonEdit v-model:value="taskCustomActParam"></JsonEdit>
</template>
</div>
</template>
181 changes: 95 additions & 86 deletions src/components/RecognizerEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,92 +42,101 @@ const taskCustomRecoParam = wrapProp(task, 'custom_recognizer_param')
</script>

<template>
<ClearButton v-model="taskReco"> 识别 </ClearButton>
<NSelect
v-model:value="taskReco"
:options="recoOptions"
:placeholder="recoOptions[0].label"
></NSelect>
<template v-if="taskRecoValue !== 'Custom'">
<ClearButton v-model="taskRoi"> 识别区域 </ClearButton>
<SingleArrayEdit
v-model:value="taskRoi"
:nullable="true"
:def="() => [0, 0, 0, 0] as Rect"
:is-t="
v => v instanceof Array && v.length === 4 && typeof v[0] === 'number'
"
>
<template #edit="{ value, update }">
<RectEdit :value="value" @update:value="update"></RectEdit>
</template>
</SingleArrayEdit>
</template>
<template v-if="taskRecoValue === 'TemplateMatch'">
<TemplateEdit
v-model:template="taskTemplate"
v-model:threshold="taskThreshold"
></TemplateEdit>
<ClearButton v-model="taskMethod"> 匹配算法 </ClearButton>
<div
class="grid items-center"
style="
grid-template-columns: max-content minmax(0, 1fr);
column-gap: 0.5rem;
row-gap: 1rem;
"
>
<ClearButton v-model="taskReco"> 识别 </ClearButton>
<NSelect
:options="templMethodOptions"
v-model:value="taskMethod"
placeholder="5"
v-model:value="taskReco"
:options="recoOptions"
:placeholder="recoOptions[0].label"
></NSelect>
<ClearButton v-model="taskGMask"> 绿色掩码 </ClearButton>
<div>
<NSwitch
:value="taskGMask ?? false"
@update:value="(v: boolean) => taskGMask = v"
></NSwitch>
</div>
</template>
<template v-if="taskRecoValue === 'OCR'">
<ClearButton v-model="taskText" invalid> 文本 </ClearButton>
<StringArrayEdit
v-model:value="taskText"
:def="''"
placeholder="text"
></StringArrayEdit>
<ClearButton v-model="taskReplace"> 文本替换 </ClearButton>
<SingleArrayEdit
v-model:value="taskReplace"
:nullable="true"
:def="() => (['', ''] as TextRepl)"
:is-t="(v: TextRepl | TextRepl[]) => (v.length === 2 && typeof v[0] === 'string')"
>
<template #edit="{ value, update }">
<div class="flex gap-2">
<NInput
:value="value[0]"
@update:value="(v: string) => update([v, value[1]])"
placeholder="替换"
>
</NInput>
<NInput
:value="value[1]"
@update:value="(v: string) => update([value[0], v])"
placeholder=""
>
</NInput>
</div>
</template>
</SingleArrayEdit>
<ClearButton v-model="taskOnlyRec"> 仅识别 </ClearButton>
<div>
<NSwitch
:value="taskOnlyRec ?? false"
@update:value="(v: boolean) => taskOnlyRec = v"
></NSwitch>
</div>
</template>
<template v-if="taskRecoValue === 'Custom'">
<ClearButton v-model="taskCustomReco" invalid> 识别器 </ClearButton>
<NInput
:value="taskCustomReco ?? ''"
@update:value="v => (taskCustomReco = v)"
></NInput>
<ClearButton v-model="taskCustomRecoParam"> 识别参数 </ClearButton>
<JsonEdit v-model:value="taskCustomRecoParam"></JsonEdit>
</template>
<template v-if="taskRecoValue !== 'Custom'">
<ClearButton v-model="taskRoi"> 识别区域 </ClearButton>
<SingleArrayEdit
v-model:value="taskRoi"
:nullable="true"
:def="() => [0, 0, 0, 0] as Rect"
:is-t="
v => v instanceof Array && v.length === 4 && typeof v[0] === 'number'
"
>
<template #edit="{ value, update }">
<RectEdit :value="value" @update:value="update"></RectEdit>
</template>
</SingleArrayEdit>
</template>
<template v-if="taskRecoValue === 'TemplateMatch'">
<TemplateEdit
v-model:template="taskTemplate"
v-model:threshold="taskThreshold"
></TemplateEdit>
<ClearButton v-model="taskMethod"> 匹配算法 </ClearButton>
<NSelect
:options="templMethodOptions"
v-model:value="taskMethod"
placeholder="5"
></NSelect>
<ClearButton v-model="taskGMask"> 绿色掩码 </ClearButton>
<div>
<NSwitch
:value="taskGMask ?? false"
@update:value="(v: boolean) => taskGMask = v"
></NSwitch>
</div>
</template>
<template v-if="taskRecoValue === 'OCR'">
<ClearButton v-model="taskText" invalid> 文本 </ClearButton>
<StringArrayEdit
v-model:value="taskText"
:def="''"
placeholder="text"
></StringArrayEdit>
<ClearButton v-model="taskReplace"> 文本替换 </ClearButton>
<SingleArrayEdit
v-model:value="taskReplace"
:nullable="true"
:def="() => (['', ''] as TextRepl)"
:is-t="(v: TextRepl | TextRepl[]) => (v.length === 2 && typeof v[0] === 'string')"
>
<template #edit="{ value, update }">
<div class="flex gap-2">
<NInput
:value="value[0]"
@update:value="(v: string) => update([v, value[1]])"
placeholder="替换"
>
</NInput>
<NInput
:value="value[1]"
@update:value="(v: string) => update([value[0], v])"
placeholder=""
>
</NInput>
</div>
</template>
</SingleArrayEdit>
<ClearButton v-model="taskOnlyRec"> 仅识别 </ClearButton>
<div>
<NSwitch
:value="taskOnlyRec ?? false"
@update:value="(v: boolean) => taskOnlyRec = v"
></NSwitch>
</div>
</template>
<template v-if="taskRecoValue === 'Custom'">
<ClearButton v-model="taskCustomReco" invalid> 识别器 </ClearButton>
<NInput
:value="taskCustomReco ?? ''"
@update:value="v => (taskCustomReco = v)"
></NInput>
<ClearButton v-model="taskCustomRecoParam"> 识别参数 </ClearButton>
<JsonEdit v-model:value="taskCustomRecoParam"></JsonEdit>
</template>
</div>
</template>
28 changes: 5 additions & 23 deletions src/components/TaskEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,31 +180,13 @@ function tryDelete() {
<div class="flex gap-2">
<NCollapse :default-expanded-names="['reco', 'act', 'misc']">
<NCollapseItem title="识别" name="reco">
<div
class="grid items-center"
style="
grid-template-columns: max-content minmax(0, 1fr);
column-gap: 0.5rem;
row-gap: 1rem;
"
>
<RecognizerEdit v-model:value="task"></RecognizerEdit>
</div>
<RecognizerEdit v-model:value="task"></RecognizerEdit>
</NCollapseItem>
<NCollapseItem title="动作" name="act">
<div
class="grid items-center"
style="
grid-template-columns: max-content minmax(0, 1fr);
column-gap: 0.5rem;
row-gap: 1rem;
"
>
<ActionEdit
v-model:value="task"
:navigate="s => $emit('navigate', s)"
></ActionEdit>
</div>
<ActionEdit
v-model:value="task"
:navigate="s => $emit('navigate', s)"
></ActionEdit>
</NCollapseItem>
<NCollapseItem title="其他" name="misc">
<div
Expand Down

0 comments on commit 4d278db

Please sign in to comment.