composition: strategyselect

This commit is contained in:
Matthias 2022-04-16 14:38:33 +02:00
parent 792e3a3425
commit 50ee60042a

View File

@ -1,12 +1,7 @@
<template> <template>
<div> <div>
<div class="w-100 d-flex"> <div class="w-100 d-flex">
<b-form-select <b-form-select id="strategy-select" v-model="locStrategy" :options="strategyList">
id="strategy-select"
v-model="locStrategy"
:options="strategyList"
@change="strategyChanged"
>
</b-form-select> </b-form-select>
<div class="ml-2"> <div class="ml-2">
<b-button @click="getStrategyList">&#x21bb;</b-button> <b-button @click="getStrategyList">&#x21bb;</b-button>
@ -20,55 +15,53 @@
<script lang="ts"> <script lang="ts">
import { BotStoreGetters } from '@/store/modules/ftbot'; import { BotStoreGetters } from '@/store/modules/ftbot';
import StoreModules from '@/store/storeSubModules'; import StoreModules from '@/store/storeSubModules';
import { StrategyResult } from '@/types'; import { defineComponent, computed, onMounted } from '@vue/composition-api';
import { Component, Vue, Prop, Emit } from 'vue-property-decorator'; import { useNamespacedActions, useNamespacedGetters } from 'vuex-composition-helpers';
import { namespace } from 'vuex-class';
const ftbot = namespace(StoreModules.ftbot); export default defineComponent({
name: 'StrategySelect',
props: {
value: { type: String, required: true },
showDetails: { default: false, required: false, type: Boolean },
},
emits: ['input'],
setup(props, { emit }) {
const { getStrategyList, getStrategy } = useNamespacedActions(StoreModules.ftbot, [
'getStrategyList',
'getStrategy',
]);
@Component({}) const { strategyList, strategy } = useNamespacedGetters(StoreModules.ftbot, [
export default class StrategySelect extends Vue { BotStoreGetters.strategyList,
@Prop() value!: string; BotStoreGetters.strategy,
]);
@Prop({ default: false, required: false }) showDetails!: boolean; const strategyCode = computed((): string => strategy.value?.code);
const locStrategy = computed({
get() {
return props.value;
},
set(strategy) {
getStrategy(strategy);
emit('input', strategy);
},
});
@ftbot.Action getStrategyList; onMounted(() => {
if (strategyList.value.length === 0) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars getStrategyList();
@ftbot.Action getStrategy!: (strategy: string) => void;
@ftbot.Getter [BotStoreGetters.strategyList]!: string[];
@ftbot.Getter [BotStoreGetters.strategy]: StrategyResult;
@Emit('input')
emitStrategy(strategy: string) {
this.getStrategy(strategy);
return strategy;
}
get strategyCode(): string {
return this.strategy?.code;
}
get locStrategy() {
return this.value;
}
set locStrategy(val) {
this.emitStrategy(val);
}
strategyChanged(newVal) {
this.value = newVal;
}
mounted() {
if (this.strategyList.length === 0) {
this.getStrategyList();
}
}
} }
});
return {
getStrategyList,
getStrategy,
strategyList,
strategy,
strategyCode,
locStrategy,
};
},
});
</script> </script>
<style></style> <style></style>