DataTiming.vue 2.5 KB

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