MainLayout.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div class="main-layout"
  3. :class="{'isNotAdminPage': !isAdminPage, 'isHomePage': isHomePage, 'isProfilePage': isProfilePage, 'isPublicPage': isPublicPage}">
  4. <quasar-template-builder @onResize="resize">
  5. <template #header>
  6. <template-header :type="getTemplateHeaderType" />
  7. <q-linear-progress v-if="$store.getters['loading/loading']"
  8. color="primary"
  9. reverse
  10. class="q-mt-sm"
  11. indeterminate />
  12. </template>
  13. <template #left-drawer>
  14. <template-side-bar :type="getLeftDrawerType" />
  15. </template>
  16. <template #content>
  17. <div ref="contentInside"
  18. v-scroll="onContentInsideScroll"
  19. class="content-inside">
  20. <q-dialog v-model="confirmDialogData.show"
  21. persistent>
  22. <q-card class="q-pa-md q-pb-none">
  23. <q-card-section>
  24. <q-icon name="warning"
  25. color="warning"
  26. size="2rem" />
  27. {{confirmDialogData.message}}
  28. </q-card-section>
  29. <q-separator />
  30. <q-card-actions align="right"
  31. class="q-pb-none">
  32. <q-btn v-close-popup
  33. color="green"
  34. flat
  35. @click="confirmDialogAction(true)">بله</q-btn>
  36. <q-btn v-close-popup
  37. color="red"
  38. flat
  39. @click="confirmDialogAction(false)">خیر</q-btn>
  40. </q-card-actions>
  41. </q-card>
  42. </q-dialog>
  43. <q-dialog v-model="loginDialog">
  44. <auth-login />
  45. </q-dialog>
  46. <router :include="keepAliveComponents" />
  47. </div>
  48. <floating-action-button v-if="canShowFloatingActionBtn" />
  49. </template>
  50. <template #footer>
  51. <footer-template :type="getFooterType" />
  52. </template>
  53. </quasar-template-builder>
  54. </div>
  55. </template>
  56. <script>
  57. import { User } from 'src/models/User.js'
  58. import Router from 'src/router/Router.vue'
  59. import AuthLogin from 'src/components/Auth.vue'
  60. import FooterTemplate from 'src/components/Template/Footer/FooterTemplate.vue'
  61. import KeepAliveComponents from 'src/assets/js/KeepAliveComponents.js'
  62. import templateHeader from 'src/components/Template/Header/TemplateHeader.vue'
  63. import TemplateSideBar from 'src/components/Template/SideBar/TemplateSideBar.vue'
  64. import QuasarTemplateBuilder from 'quasar-template-builder/src/quasar-template-builder.vue'
  65. import FloatingActionButton from 'components/Template/FloatingActionButton/FloatingActionButton.vue'
  66. export default {
  67. components: {
  68. Router,
  69. AuthLogin,
  70. FooterTemplate,
  71. templateHeader,
  72. TemplateSideBar,
  73. FloatingActionButton,
  74. QuasarTemplateBuilder
  75. },
  76. data () {
  77. return {
  78. user: new User(),
  79. isUserLogin: false,
  80. contentVerticalScrollPosition: 0,
  81. keepAliveComponents: KeepAliveComponents
  82. }
  83. },
  84. computed: {
  85. isPublicPage () {
  86. return this.$route.name && this.$route.name.includes('Public.')
  87. },
  88. isAdminPage () {
  89. return this.$route.name && this.$route.name.includes('Admin.')
  90. },
  91. isProfilePage () {
  92. return this.$route.name && this.$route.name.includes('UserPanel.')
  93. },
  94. isHomePage () {
  95. return this.$route.name && this.$route.name === 'Public.Home'
  96. },
  97. canShowFloatingActionBtn () {
  98. // return true
  99. return this.user.isSuperUser() && (this.hasDynamicSetting || this.hasDynamicSettingWithParams)
  100. },
  101. hasDynamicSetting () {
  102. return !!this.$route.meta?.hasDynamicSetting
  103. },
  104. hasDynamicSettingWithParams () {
  105. return !!this.$route.meta?.hasDynamicSettingWithParams
  106. },
  107. loginDialog: {
  108. get () {
  109. return this.$store.getters['AppLayout/loginDialog']
  110. },
  111. set (newValue) {
  112. if (!newValue) {
  113. this.$store.commit('AppLayout/updateLoginDialog', false)
  114. return
  115. }
  116. this.$store.dispatch('AppLayout/showLoginDialog')
  117. }
  118. },
  119. confirmDialogData () {
  120. return this.$store.getters['AppLayout/confirmDialog']
  121. },
  122. getTemplateHeaderType() {
  123. return this.$store.getters['AppLayout/layoutHeaderType']
  124. },
  125. getLeftDrawerType() {
  126. return this.$store.getters['AppLayout/layoutLeftSideBarType']
  127. },
  128. getFooterType() {
  129. return this.$store.getters['AppLayout/layoutFooterType']
  130. },
  131. calculateHeightStyle() {
  132. return this.$store.getters['AppLayout/calculateContainerFullHeight']
  133. }
  134. },
  135. mounted () {
  136. this.loadAuthData()
  137. },
  138. methods: {
  139. loadAuthData () { // prevent Hydration node mismatch
  140. this.user = this.$store.getters['Auth/user']
  141. this.isUserLogin = this.$store.getters['Auth/isUserLogin']
  142. },
  143. onContentInsideScroll (data) {
  144. this.$store.commit('AppLayout/updateLayoutHeaderElevated', data > 0)
  145. },
  146. confirmDialogAction (data) {
  147. if (this.confirmDialogData) {
  148. this.confirmDialogData.callback(data)
  149. } else {
  150. this.$store.commit('AppLayout/showConfirmDialog', {
  151. show: false
  152. })
  153. }
  154. },
  155. resize (val) {
  156. this.$store.commit('AppLayout/updateWindowSize', val)
  157. if (this.getLeftDrawerType === 'abrisham') {
  158. this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 100)
  159. if (val.width < 1200) {
  160. this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 80)
  161. } else if (val.width < 990) {
  162. this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 60)
  163. }
  164. }
  165. // if (val.width > 1439) {
  166. // this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 314)
  167. // this.$store.commit('AppLayout/updateLayoutLeftDrawerBehavior', 'mobile') && this.$store.commit('AppLayout/updateLayoutRightDrawerBehavior', 'mobile')
  168. // } else if (val.width > 599) {
  169. // this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 280)
  170. // this.$store.commit('AppLayout/updateLayoutLeftDrawerBehavior', 'mobile') && this.$store.commit('AppLayout/updateLayoutRightDrawerBehavior', 'mobile')
  171. // } else {
  172. // this.$store.commit('AppLayout/updateLayoutLeftDrawerWidth', 242)
  173. // this.$store.commit('AppLayout/updateLayoutLeftDrawerBehavior', 'mobile') && this.$store.commit('AppLayout/updateLayoutRightDrawerBehavior', 'mobile')
  174. // }
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .main-layout {
  181. :deep(.main-layout-container) {
  182. background-color: #f1f1f1;
  183. }
  184. :deep(.q-layout__section--marginal) {
  185. background-color: transparent;
  186. color: inherit;
  187. }
  188. .content-inside {
  189. //padding-top: 20px;
  190. }
  191. }
  192. </style>