DataTiming.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="historicalBtn"
  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 {useFormStore} from "~/stores/form";
  25. import {useAccessProfileStore} from "~/stores/accessProfile";
  26. import {Ref} from "@vue/reactivity";
  27. import {WatchStopHandle} from "@vue/runtime-core";
  28. const { setDirty } = useFormStore()
  29. const accessProfileStore = useAccessProfileStore()
  30. const historicalBtn: Ref<Array<number>> = initHistoricalBtn(accessProfileStore.historical as Array<any>)
  31. const unwatch: WatchStopHandle = watch(historicalBtn, async (newValue) => {
  32. const historicalChoice: Array<string> = initHistoricalChoice(newValue)
  33. accessProfileStore.setHistorical(historicalChoice)
  34. setDirty(false)
  35. await updateMyProfile()
  36. window.location.reload()
  37. })
  38. onUnmounted(() => {
  39. unwatch()
  40. })
  41. /**
  42. * Prépare le tableau de valeur numéraire devant être passé au component v-btn-toggle
  43. * @param historical
  44. */
  45. function initHistoricalBtn (historical: Array<any>) {
  46. const timeChoice:Ref<Array<number>> = ref(Array<number>())
  47. const historicalArray:Array<any> = ['past', 'present', 'future']
  48. for (const key in historicalArray) {
  49. if (historical[historicalArray[key]]) { timeChoice.value.push(parseInt(key)) }
  50. }
  51. return timeChoice
  52. }
  53. /**
  54. * Transforme le résultat renvoyé par le component v-btn-toggle pour l'enregistrer coté AccessProfile
  55. * @param historical
  56. */
  57. function initHistoricalChoice (historical: Array<any>) {
  58. const historicalArray:Array<any> = ['past', 'present', 'future']
  59. const historicalChoice:Array<string> = []
  60. for (const key in historical) {
  61. historicalChoice.push(historicalArray[historical[key]])
  62. }
  63. return historicalChoice
  64. }
  65. </script>
  66. <style scoped lang="scss">
  67. .toggle-btn{
  68. z-index: 1;
  69. border-radius: 4px 0 0 4px;
  70. }
  71. </style>