DataTiming.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <main class="d-flex align-baseline">
  3. <span class="mr-2 ot_dark_grey--text font-weight-bold">{{$t('display_data')}} : </span>
  4. <v-btn-toggle
  5. v-model="timeChoice"
  6. dense
  7. class="ot_light_grey toggle-btn"
  8. active-class="ot_green ot_white--text"
  9. multiple
  10. >
  11. <v-btn max-height="25" class="font-weight-normal text-caption">
  12. {{$t('past')}}
  13. </v-btn>
  14. <v-btn max-height="25" class="font-weight-normal text-caption">
  15. {{$t('present')}}
  16. </v-btn>
  17. <v-btn max-height="25" class="font-weight-normal text-caption">
  18. {{$t('future')}}
  19. </v-btn>
  20. </v-btn-toggle>
  21. </main>
  22. </template>
  23. <script lang="ts">
  24. import {defineComponent, onUnmounted, ref, useContext, watch, Ref} from '@nuxtjs/composition-api'
  25. import {$useDirtyForm} from "~/use/form/useDirtyForm";
  26. import {$useMyProfileUpdater} from "~/use/updater/useMyProfileUpdater";
  27. import {WatchStopHandle} from "@vue/composition-api";
  28. export default defineComponent({
  29. setup() {
  30. const {store, $dataPersister} = useContext()
  31. const {markFormAsNotDirty} = $useDirtyForm(store)
  32. const {updateMyProfile, setHistorical, historical} = $useMyProfileUpdater(store, $dataPersister)
  33. const timeChoice:Ref<Array<number>> = ref(Array<number>())
  34. const historicalArray:Array<string> = ['past', 'present', 'future']
  35. for(const key in historicalArray){
  36. if (historical.value[historicalArray[key]])
  37. timeChoice.value.push(parseInt(key))
  38. }
  39. const unwatch:WatchStopHandle = watch(timeChoice, async (newValue) => {
  40. const historicalChoice:Array<string> = []
  41. for(const key in newValue){
  42. historicalChoice.push(historicalArray[newValue[key]])
  43. }
  44. setHistorical(historicalChoice)
  45. markFormAsNotDirty()
  46. await updateMyProfile()
  47. window.location.reload()
  48. })
  49. onUnmounted(()=>{
  50. unwatch()
  51. })
  52. return {
  53. timeChoice
  54. }
  55. }
  56. })
  57. </script>
  58. <style scoped lang="scss">
  59. .toggle-btn{
  60. z-index: 1;
  61. border-radius: 4px 0px 0px 4px;
  62. }
  63. </style>