Skip to content

Commit

Permalink
feat: 用户配置支持动态多选
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 9, 2021
1 parent 693c410 commit 6bf5b29
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/model/do/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ export const SCRIPT_RUN_STATUS_RETRY: SCRIPT_RUN_STATUS = 'retry';

export type Metadata = { [key: string]: string[] };

export type ConfigType = 'text' | 'boolean' | 'select' | 'number';
export type ConfigType = 'text' | 'checkbox' | 'select' | 'mult-select' | 'number';

export interface Config {
[key: string]: any
title: string
description: string
default?: any
type?: ConfigType
bind?: string
values?: any[]
}

export type UserConfig = { [key: string]: { [key: string]: Config } };
Expand Down
50 changes: 40 additions & 10 deletions src/views/pages/Option/tabs/ScriptList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
hide-details
v-model="item.value"
color="success"
v-else-if="item.type === 'boolean'"
v-else-if="item.type === 'checkbox'"
style="margin-top: 0; margin-bottom: 12px; padding: 0"
>
<template v-slot:label>
Expand All @@ -372,6 +372,16 @@
:hint="item.description"
>
</v-select>
<v-select
v-model="item.value"
v-else-if="item.type === 'mult-select'"
:items="item.values"
:suffix="item.unit"
:label="item.title"
:hint="item.description"
chips
>
</v-select>
</div>
<v-card-actions class="justify-end">
<v-btn
Expand Down Expand Up @@ -862,21 +872,41 @@ export default class ScriptList extends Vue {
for (const gkey in val.config) {
let group = val.config[gkey];
for (const key in group) {
if (typeof group[key].default == "boolean") {
group[key].type = "boolean";
} else if (group[key].values) {
group[key].type = "select";
} else if (typeof group[key].default == "number") {
group[key].type = "number";
} else {
group[key].type = "text";
if (!group[key].type) {
if (typeof group[key].default == "boolean") {
group[key].type = "checkbox";
} else if (group[key].values) {
group[key].type = "select";
if (typeof group[key].values == "object") {
group[key].type = "mult-select";
}
} else if (typeof group[key].default == "number") {
group[key].type = "number";
} else {
group[key].type = "text";
}
}
let where: any = { key: gkey + "." + key };
let where: any = {};
if (val.metadata["storagename"]) {
where["storageName"] = val.metadata["storagename"][0];
} else {
where["scriptId"] = val.id;
}
// 动态values
if (group[key].bind) {
where.key = group[key].bind!.substr(1);
console.log(where);
this.valueModel
.findOne(where)
.then((val) => {
// 读取value
console.log(val);
if (val) {
group[key].values = val.value;
}
});
}
where.key = gkey + "." + key;
this.valueModel.findOne(where).then((val) => {
// 读取value
if (val) {
Expand Down

0 comments on commit 6bf5b29

Please sign in to comment.