GetUnits.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="row items-baseline">
  3. <div class="col-xs-12 col-sm-auto text-weight-bold text-center q-px-md q-py-sm">
  4. <div :style="flexRowTitleStyle">
  5. Units
  6. </div>
  7. </div>
  8. <div class="col-xs-grow col-sm q-px-xs">
  9. <div class="row justify-xs-center justify-sm-start items-center">
  10. <div class="col-auto" >
  11. <div class="row items-center justify-center">
  12. <div class="text-right"> length </div>
  13. <q-select
  14. v-model="units"
  15. :options="unitsOptions"
  16. class="q-pa-xs"
  17. outlined
  18. dense
  19. options-dense
  20. :style="'width: '+basicSelectorWidthStyle"
  21. behavior="menu"
  22. >
  23. </q-select>
  24. <div/>
  25. </div>
  26. </div>
  27. <div class="col-auto" >
  28. <div class="row items-center justify-center">
  29. <div class="text-right q-pl-md"> plane wave </div>
  30. <q-select
  31. v-model="sourceUnits"
  32. :options="sourceUnitsOptions"
  33. :style="'width: '+basicSelectorWidthStyle"
  34. class="q-pa-xs"
  35. :disable="isSourceSameUnits"
  36. :outlined="!isSourceSameUnits"
  37. :filled="isSourceSameUnits"
  38. dense
  39. options-dense
  40. option-value="label"
  41. option-label="label"
  42. behavior="menu"
  43. >
  44. <template #option="scope">
  45. <q-item :label="scope.opt.title" dense>
  46. <q-item-section class="text-weight-bold">{{ scope.opt.title }}</q-item-section>
  47. </q-item>
  48. <template v-for="child in scope.opt.children" :key="child.label">
  49. <q-item v-close-popup dense clickable
  50. @click="sourceUnits = child"
  51. >
  52. <q-item-section> <q-item-label class="q-ml-md"> {{child.label}} </q-item-label> </q-item-section>
  53. </q-item>
  54. </template>
  55. </template>
  56. </q-select>
  57. <div class="row q-pa-xs items-center">
  58. <q-checkbox v-model="isSourceSameUnits" size="sm"/>
  59. <div>same</div>
  60. </div>
  61. </div>
  62. </div>
  63. <!-- <div class="col-auto" >-->
  64. <!-- units: {{sourceUnits}}-->
  65. <!-- <br> store: {{$store.state.guiRuntime}}-->
  66. <!-- </div>-->
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script lang="ts">
  72. import {
  73. defineComponent,
  74. computed,
  75. watch
  76. } from 'vue'
  77. import { useStore } from 'src/store'
  78. import { flexRowTitleStyle, basicSelectorWidthStyle } from 'components/config'
  79. export default defineComponent({
  80. name: 'GetUnits',
  81. components: {},
  82. setup() {
  83. const unitsOptions = [ 'nm', 'µm', 'mm', 'cm', 'm']
  84. const sourceUnitsOptions = [
  85. { title: 'Frequency',
  86. children: [{label: 'MHz'},{label: 'GHz'},{label: 'THz'}]},
  87. { title: 'Energy',
  88. children: [{label: 'meV'}, {label: 'eV'}]},
  89. { title: 'Period duration',
  90. children: [{label: 'ps'}, {label: 'fs'}]}
  91. ]
  92. const $store = useStore()
  93. const isSourceSameUnits = computed({
  94. get: () => $store.state.guiRuntime.isSourceSameUnits,
  95. set: val => $store.commit('guiRuntime/setIsSourceSameUnits', val)
  96. })
  97. const units = computed({
  98. get: () => $store.state.guiRuntime.units,
  99. set: val => $store.commit('guiRuntime/setUnits', val)
  100. })
  101. const sourceUnits = computed({
  102. get: () => {return {label:$store.state.guiRuntime.sourceUnits}},
  103. set: val => $store.commit('guiRuntime/setSourceUnits', val.label)
  104. })
  105. let prevCustomSourceUnits = 'THz'
  106. watch(isSourceSameUnits, ()=>{
  107. if (isSourceSameUnits.value) {
  108. prevCustomSourceUnits = $store.state.guiRuntime.sourceUnits
  109. $store.commit('guiRuntime/setSourceUnits',units.value)
  110. }
  111. else $store.commit('guiRuntime/setSourceUnits',prevCustomSourceUnits)
  112. })
  113. watch(units, ()=>{
  114. if (isSourceSameUnits.value) $store.commit('guiRuntime/setSourceUnits',units.value)
  115. })
  116. return { isSourceSameUnits, flexRowTitleStyle, basicSelectorWidthStyle,
  117. unitsOptions, units,
  118. sourceUnits, sourceUnitsOptions }
  119. },
  120. })
  121. </script>