88</template >
99
1010<script setup lang="ts">
11- import { ref , watch } from " vue" ;
11+ import { computed , watchEffect } from " vue" ;
12+ import { useVModel } from " @vueuse/core" ;
1213
1314import { useSubscribeState } from " @/api" ;
1415import { useCtrlExceptionQuery } from " @/graphql/codegen/generated" ;
@@ -24,36 +25,27 @@ type Emits = {
2425const props = defineProps <Props >();
2526const emit = defineEmits <Emits >();
2627
28+ const alert = useVModel (props , " modelValue" , emit );
29+
2730const stateSubscription = useSubscribeState ();
2831const { state } = stateSubscription ;
2932
30- const pause = ref (true );
31-
32- const query = useCtrlExceptionQuery ({ pause: pause .value });
33+ const query = useCtrlExceptionQuery ({ pause: true , variables: {} });
3334
34- watch ( state , ( val ) => {
35- pause .value = val !== " finished" ;
36- if ( ! pause .value ) {
37- query . executeQuery () ;
35+ watchEffect (( ) => {
36+ if ( state .value !== " finished" ) {
37+ alert .value = false ;
38+ return ;
3839 }
40+ query .executeQuery ();
3941});
4042
41- const exception = ref (null as string | null | undefined );
42-
43- const alert = ref (false );
44-
45- watch (props , (val ) => {
46- alert .value = val .modelValue ;
47- });
48-
49- watch (query .data , (val ) => {
50- alert .value = !! val ?.ctrl .exception ;
51- exception .value = val ?.ctrl .exception ;
52- });
43+ const exception = computed (() =>
44+ state .value !== " finished" ? null : query .data .value ?.ctrl .exception
45+ );
5346
54- watch (alert , (val ) => {
55- if (! val ) exception .value = null ;
56- emit (" update:modelValue" , val );
47+ watchEffect (() => {
48+ alert .value = !! exception .value ;
5749});
5850
5951await stateSubscription ;
0 commit comments