DataTiming.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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} from '@nuxtjs/composition-api'
  25. import {$useDirtyForm} from "~/use/form/useDirtyForm";
  26. import {$useMyProfileUpdater} from "~/use/updater/useMyProfileUpdater";
  27. export default defineComponent({
  28. setup() {
  29. const {store, $dataPersister} = useContext()
  30. const {markFormAsNotDirty} = $useDirtyForm(store)
  31. const {updateMyProfile, setHistorical, historical} = $useMyProfileUpdater(store, $dataPersister)
  32. const timeChoice = ref(Array<number>())
  33. const historicalArray = ['past', 'future', 'present']
  34. for(const key in historicalArray){
  35. if (historical.value[historicalArray[key]])
  36. timeChoice.value.push(parseInt(key))
  37. }
  38. const unwatch = watch(timeChoice, async (newValue) => {
  39. const historicalChoice:Array<string> = []
  40. for(const key in newValue){
  41. historicalChoice.push(historicalArray[newValue[key]])
  42. }
  43. setHistorical(historicalChoice)
  44. markFormAsNotDirty()
  45. await updateMyProfile()
  46. window.location.reload()
  47. })
  48. onUnmounted(()=>{
  49. unwatch()
  50. })
  51. return {
  52. timeChoice
  53. }
  54. }
  55. })
  56. </script>
  57. <style scoped lang="scss">
  58. .toggle-btn{
  59. z-index: 1;
  60. border-radius: 4px 0px 0px 4px;
  61. }
  62. </style>