LeftMenuLayout.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <q-drawer
  3. v-bind="$attrs"
  4. :model-value="true"
  5. show-if-above
  6. no-swipe-close
  7. no-swipe-open
  8. :width="250"
  9. :mini-width="64"
  10. :breakpoint="500"
  11. :mini="miniState"
  12. :behavior="'desktop'"
  13. class="detached-container"
  14. >
  15. <div class="column full-height q-pa-sm no-wrap">
  16. <div
  17. v-if="!$q.screen.lt.md"
  18. class="toggle-button-wrapper absolute"
  19. style="top: 50%; right: -32px; z-index: 1"
  20. >
  21. <q-btn
  22. flat
  23. round
  24. size="sm"
  25. padding="8px 8px"
  26. @click="miniState = !miniState"
  27. >
  28. <q-icon
  29. :name="miniState ? 'mdi-chevron-right' : 'mdi-chevron-left'"
  30. />
  31. <q-tooltip
  32. anchor="center right"
  33. self="center left"
  34. :offset="[10, 10]"
  35. >{{
  36. miniState
  37. ? $t("ui.navigation.expand_menu")
  38. : $t("ui.navigation.collapse_menu")
  39. }}</q-tooltip
  40. >
  41. </q-btn>
  42. </div>
  43. <q-list class="column no-wrap">
  44. <template v-for="item in navigationItems">
  45. <template v-if="item.permission">
  46. <q-item
  47. v-if="item.type === 'single'"
  48. :key="item.name"
  49. v-ripple
  50. clickable
  51. exact-active-class="menu-selected"
  52. exact
  53. active-class="menu-selected"
  54. :to="{ name: item.name }"
  55. class="q-my-xs"
  56. >
  57. <q-item-section avatar>
  58. <q-icon :name="item.icon" style="font-size: 18px" />
  59. </q-item-section>
  60. <q-item-section>{{ $t(item.title) }}</q-item-section>
  61. <q-tooltip
  62. v-if="miniState"
  63. anchor="center right"
  64. self="center left"
  65. :offset="[10, 10]"
  66. >{{ $t(item.title) }}</q-tooltip
  67. >
  68. </q-item>
  69. <!-- Expansive Menu with children -->
  70. <div v-else :key="item.title">
  71. <template v-if="!miniState">
  72. <q-tooltip
  73. v-if="miniState"
  74. anchor="center right"
  75. self="center left"
  76. :offset="[10, 10]"
  77. >{{ $t(item.title) }}</q-tooltip
  78. >
  79. <q-expansion-item
  80. v-model="isExpasionItemExpanded"
  81. header-class="menu-item--spaced"
  82. :class="{
  83. 'menu-selected':
  84. childrenAreActive(item.children) &&
  85. !isExpasionItemExpanded,
  86. }"
  87. class="menu-item--spaced"
  88. >
  89. <template #header>
  90. <q-item-section avatar>
  91. <q-icon :name="item.icon" style="font-size: 18px" />
  92. </q-item-section>
  93. <q-item-section>{{ $t(item.title) }}</q-item-section>
  94. </template>
  95. <div v-for="child in item.childrens" :key="child.name">
  96. <q-item
  97. v-ripple
  98. clickable
  99. :to="{ name: child.name }"
  100. exact
  101. exact-active-class="menu-selected"
  102. class="menu-item--spaced q-pl-lg"
  103. >
  104. <q-item-section avatar>
  105. <q-icon :name="child.icon" style="font-size: 18px" />
  106. </q-item-section>
  107. <q-item-section>{{ $t(child.title) }}</q-item-section>
  108. <q-tooltip
  109. v-if="miniState"
  110. anchor="center right"
  111. self="center left"
  112. :offset="[10, 10]"
  113. >{{ $t(child.title) }}</q-tooltip
  114. >
  115. </q-item>
  116. </div>
  117. </q-expansion-item>
  118. </template>
  119. <template v-else>
  120. <q-item
  121. v-ripple
  122. clickable
  123. exact
  124. exact-active-class="menu-selected"
  125. class="menu-item--spaced"
  126. >
  127. <q-item-section avatar>
  128. <q-icon :name="item.icon" style="font-size: 18px" />
  129. </q-item-section>
  130. <q-item-section>{{ $t(item.title) }}</q-item-section>
  131. <q-tooltip
  132. v-if="miniState"
  133. anchor="center right"
  134. self="center left"
  135. :offset="[10, 10]"
  136. >{{ $t(item.title) }}</q-tooltip
  137. >
  138. <q-menu anchor="center right" self="top start">
  139. <q-list>
  140. <q-item
  141. v-for="child in item.childrens"
  142. :key="child.name"
  143. v-ripple
  144. v-close-popup
  145. clickable
  146. :to="{ name: child.name }"
  147. exact
  148. exact-active-class="menu-selected"
  149. >
  150. <q-item-section avatar>
  151. <q-icon :name="child.icon" style="font-size: 18px" />
  152. </q-item-section>
  153. <q-item-section>{{ $t(child.title) }}</q-item-section>
  154. </q-item>
  155. </q-list>
  156. </q-menu>
  157. </q-item>
  158. </template>
  159. </div>
  160. </template>
  161. </template>
  162. </q-list>
  163. <q-list class="column q-mb-md no-wrap" style="border-radius: 6px">
  164. </q-list>
  165. <q-list class="q-mt-auto">
  166. <q-item v-ripple clickable>
  167. <div class="flex">
  168. <q-item-section avatar>
  169. <template #default>
  170. <q-icon
  171. name="mdi-account"
  172. color="primary"
  173. style="font-size: 20px"
  174. />
  175. </template>
  176. </q-item-section>
  177. <q-item-section>{{ user_store.user.name }}</q-item-section>
  178. </div>
  179. <q-tooltip
  180. v-if="miniState"
  181. anchor="center right"
  182. self="center left"
  183. :offset="[10, 10]"
  184. >{{ user_store.user.name }}</q-tooltip
  185. >
  186. <q-menu anchor="center right" self="top start">
  187. <q-list class="column no-wrap overflow-hidden">
  188. <q-item
  189. v-ripple
  190. v-close-popup
  191. clickable
  192. :to="{ name: 'ProfilePage' }"
  193. exact
  194. exact-active-class="menu-selected"
  195. >
  196. <div class="flex">
  197. <q-item-section avatar>
  198. <q-icon
  199. name="account_circle"
  200. color="primary"
  201. style="font-size: 18px"
  202. />
  203. </q-item-section>
  204. <q-item-section>{{
  205. $t("user.profile.singular")
  206. }}</q-item-section>
  207. </div>
  208. </q-item>
  209. </q-list>
  210. </q-menu>
  211. </q-item>
  212. <q-item v-ripple clickable @click="logoutFn">
  213. <div class="flex">
  214. <q-item-section avatar>
  215. <q-icon
  216. name="logout"
  217. color="negative"
  218. style="font-size: 18px"
  219. />
  220. </q-item-section>
  221. <q-item-section>{{ $t("auth.logout") }}</q-item-section>
  222. </div>
  223. </q-item>
  224. <q-item v-ripple>
  225. <div class="flex full-width justify-center">
  226. <q-img
  227. :src="
  228. miniState || $q.screen.lt.md
  229. ? LogoSoftparMini
  230. : $q.dark.isActive
  231. ? LogoSoftparLight
  232. : LogoSoftparDark
  233. "
  234. style="width: 100%; height: 30px; max-width: 114px"
  235. />
  236. </div>
  237. </q-item>
  238. </q-list>
  239. <div class="full-width text-center text-subtitle3">
  240. <span class="text-caption text-weight-light">{{ version }}</span>
  241. </div>
  242. </div>
  243. </q-drawer>
  244. </template>
  245. <script setup>
  246. import { ref, watch, watchEffect } from "vue";
  247. import { useAuth } from "src/composables/useAuth";
  248. import { useRouter, useRoute } from "vue-router";
  249. import { userStore } from "src/stores/user";
  250. import { navigationStore } from "src/stores/navigation";
  251. import LogoSoftparLight from "src/assets/softpar_logo_light.svg";
  252. import LogoSoftparDark from "src/assets/softpar_logo_dark.svg";
  253. import LogoSoftparMini from "src/assets/softpar_logo_mini.svg";
  254. import { Cookies } from "quasar";
  255. import { useQuasar } from "quasar";
  256. const $q = useQuasar();
  257. const { logout } = useAuth();
  258. const router = useRouter();
  259. const route = useRoute();
  260. const user_store = userStore();
  261. const { navigationItems } = navigationStore();
  262. const version = "0.0.1";
  263. const miniStateCookies = Cookies.get("miniState")
  264. const miniState = ref(miniStateCookies === "true" ? true : false);
  265. const childrenAreActive = (children) => {
  266. if (!children) return false;
  267. return children.some((child) => {
  268. return route.path.includes(child.path);
  269. });
  270. };
  271. // const someAvatar = () => {
  272. // return "https://cdn.quasar.dev/img/avatar4.jpg";
  273. // };
  274. const isExpasionItemExpanded = ref(false);
  275. watchEffect(() => {
  276. if ($q.screen.lt.md) {
  277. miniState.value = true;
  278. if (Array.isArray(isExpasionItemExpanded.value)) {
  279. isExpasionItemExpanded.value.forEach((expansion, index) => {
  280. isExpasionItemExpanded.value[index] = false;
  281. });
  282. } else {
  283. isExpasionItemExpanded.value = false;
  284. }
  285. }
  286. });
  287. const logoutFn = async () => {
  288. await logout();
  289. router.push({ name: "LoginPage" });
  290. };
  291. // const openUrl = (url) => {
  292. // window.open(url, "_blank");
  293. // };
  294. watch(miniState, () => {
  295. Cookies.set("miniState", miniState.value);
  296. });
  297. </script>
  298. <style lang="scss" scoped>
  299. @import "/src/css/quasar.variables.scss";
  300. .text-subtitle3 {
  301. font-size: 1.1rem !important;
  302. font-weight: 400 !important;
  303. }
  304. .menu-selected {
  305. background-color: rgba($primary, 0.1);
  306. color: $primary;
  307. }
  308. .toggle-button-wrapper {
  309. transition: transform 0.3s ease;
  310. }
  311. .toggle-button-wrapper:hover {
  312. transform: scale(1.1);
  313. }
  314. .menu-item--spaced {
  315. margin-top: 5px;
  316. margin-bottom: 5px;
  317. }
  318. </style>