Main.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <script lang="ts">
  2. import { appName } from "@/env";
  3. import { reactive } from "vue";
  4. import type { RouteLocationNormalized, NavigationGuardNext } from "vue-router";
  5. import { onBeforeRouteUpdate } from "vue-router";
  6. import { useMainStore } from "@/stores/main";
  7. import { storeToRefs } from "pinia";
  8. import { useI18n } from "vue-i18n";
  9. export default {
  10. setup() {
  11. onBeforeRouteUpdate((to, from, next) => {
  12. routeGuardAdmin(to, from, next);
  13. });
  14. const { t, locale } = useI18n();
  15. const mainStore = useMainStore();
  16. const mainStoreRef = storeToRefs(mainStore);
  17. const hasAdminAccess = mainStoreRef.readhasAdminAccess;
  18. const miniDrawer = mainStoreRef.readDashboardMiniDrawer;
  19. const showDrawer = mainStoreRef.readDashboardShowDrawer;
  20. function switchMiniDrawer() {
  21. mainStore.setDashboardMiniDrawer(
  22. !mainStoreRef.readDashboardMiniDrawer.value
  23. );
  24. }
  25. function switchShowDrawer() {
  26. mainStore.setDashboardShowDrawer(
  27. !mainStoreRef.readDashboardShowDrawer.value
  28. );
  29. }
  30. (function () {
  31. if (window.innerWidth < 600) {
  32. switchShowDrawer();
  33. }
  34. })();
  35. function logout() {
  36. mainStore.logOut();
  37. }
  38. const lang = reactive([
  39. { title: "English", text: "en" },
  40. { title: "中文", text: "zh" },
  41. ]);
  42. function setLang(lang: String) {
  43. locale.value = `${lang}`;
  44. localStorage.setItem("lang", `${lang}`);
  45. }
  46. return {
  47. t,
  48. locale,
  49. hasAdminAccess,
  50. miniDrawer,
  51. showDrawer,
  52. switchMiniDrawer,
  53. switchShowDrawer,
  54. logout,
  55. lang,
  56. setLang,
  57. appName,
  58. };
  59. },
  60. beforeRouteEnter(to, from, next) {
  61. routeGuardAdmin(to, from, next);
  62. },
  63. };
  64. const routeGuardAdmin = async (
  65. to: RouteLocationNormalized,
  66. from: RouteLocationNormalized,
  67. next: NavigationGuardNext
  68. ) => {
  69. const mainStore = useMainStore();
  70. const mainStoreRef = storeToRefs(mainStore);
  71. if (!mainStoreRef.readhasAdminAccess) {
  72. next("/main");
  73. } else {
  74. next();
  75. }
  76. };
  77. </script>
  78. <template>
  79. <div>
  80. <v-navigation-drawer persistent :rail="miniDrawer" v-model="showDrawer">
  81. <v-sheet class="d-flex flex-column fill-height">
  82. <v-sheet>
  83. <!-- <a href="https://ai.choozmo.com/ai-presenter/info/" class="d-flex justify-center mt-3">
  84. <img src="@/assets/img/Choozmo-logo.png" alt="" class="logo-img" />
  85. </a> -->
  86. <v-list>
  87. <v-list-item
  88. class="py-4"
  89. @click="switchShowDrawer"
  90. :prepend-icon="miniDrawer ? 'chevron_right' : 'chevron_left'"
  91. >
  92. </v-list-item>
  93. <!-- <v-list-subheader><span v-show="!miniDrawer">Main menu</span></v-list-subheader> -->
  94. <v-list-item to="/main/dashboard" prepend-icon="dashboard">
  95. <v-list-item-title>{{ t("dashboard") }}</v-list-item-title>
  96. </v-list-item>
  97. <v-list-item to="/main/make-video" prepend-icon="video_call">
  98. <v-list-item-title>{{ t("makeVideo") }}</v-list-item-title>
  99. </v-list-item>
  100. <v-list-item to="/main/progress" prepend-icon="list">
  101. <v-list-item-title>{{ t("progress") }}</v-list-item-title>
  102. </v-list-item>
  103. <!-- <v-list-item to="/main/make-image" prepend-icon="image">
  104. <v-list-item-title>圖片優化</v-list-item-title>
  105. </v-list-item> -->
  106. <!-- <v-list-item to="/main/make-article" prepend-icon="article">
  107. <v-list-item-title>{{ t("article") }}</v-list-item-title>
  108. </v-list-item> -->
  109. <!-- <v-list-item to="/main/profile/view" prepend-icon="person">
  110. <v-list-item-title>{{ t("userProfile") }}</v-list-item-title>
  111. </v-list-item> -->
  112. <!-- <v-list-item to="/main/yt-views" prepend-icon="ondemand_video">
  113. <v-list-item-title>{{ t("ytViews") }}</v-list-item-title>
  114. </v-list-item> -->
  115. <v-list-item to="/main/contact" prepend-icon="email">
  116. <v-list-item-title>{{ t("contactUs") }}</v-list-item-title>
  117. </v-list-item>
  118. <v-list-item to="/main/profile/edit" prepend-icon="edit">
  119. <v-list-item-title>{{ t("editProfile") }}</v-list-item-title>
  120. </v-list-item>
  121. <!-- <v-list-item to="/main/profile/password" prepend-icon="key">
  122. <v-list-item-title>{{ t("changePassword") }}</v-list-item-title>
  123. </v-list-item> -->
  124. </v-list>
  125. </v-sheet>
  126. <!-- <v-divider></v-divider> -->
  127. <v-sheet class="">
  128. <v-list subheader v-show="hasAdminAccess">
  129. <v-list-subheader
  130. ><span v-show="!miniDrawer">Admin</span></v-list-subheader
  131. >
  132. <v-list-item to="/main/admin/users/all" prepend-icon="people">
  133. <v-list-item-title>Manage Users</v-list-item-title>
  134. </v-list-item>
  135. <v-list-item
  136. to="/main/admin/users/create"
  137. prepend-icon="person_add"
  138. >
  139. <v-list-item-title>Create User</v-list-item-title>
  140. </v-list-item>
  141. <v-list-item
  142. to="/main/admin/test-celery"
  143. prepend-icon="engineering"
  144. >
  145. <v-list-item-title>Test Celery</v-list-item-title>
  146. </v-list-item>
  147. <v-list-item to="/main/admin/test-ecpay" prepend-icon="payments">
  148. <v-list-item-title>Test ECPay</v-list-item-title>
  149. </v-list-item>
  150. <v-list-item
  151. to="/main/admin/test-style-preview"
  152. prepend-icon="preview"
  153. >
  154. <v-list-item-title>Test Style Preview</v-list-item-title>
  155. </v-list-item>
  156. <v-list-item
  157. to="/main/admin/test-payment"
  158. prepend-icon="payments"
  159. >
  160. <v-list-item-title>Test Payment</v-list-item-title>
  161. </v-list-item>
  162. </v-list>
  163. </v-sheet>
  164. <!-- <v-spacer></v-spacer> -->
  165. <v-sheet class="mt-auto">
  166. <v-list>
  167. <v-list-item @click="logout" prepend-icon="logout">
  168. <v-list-item-title>{{ t("logout") }}</v-list-item-title>
  169. </v-list-item>
  170. <v-divider></v-divider>
  171. <a
  172. href="https://ai.choozmo.com/ai-presenter/info/"
  173. class="d-flex justify-center mt-3"
  174. target="_blank"
  175. >
  176. <img
  177. src="@/assets/img/Choozmo-logo.png"
  178. alt="Choozmo-logo"
  179. class="logo-img"
  180. />
  181. </a>
  182. <!-- <v-list-item
  183. @click="switchMiniDrawer"
  184. :prepend-icon="miniDrawer ? 'chevron_right' : 'chevron_left'"
  185. >
  186. <v-list-item-title>{{ t("collapse") }}</v-list-item-title>
  187. </v-list-item> -->
  188. </v-list>
  189. </v-sheet>
  190. </v-sheet>
  191. </v-navigation-drawer>
  192. <v-main>
  193. <v-toolbar class="navbar">
  194. <v-app-bar-nav-icon @click.stop="switchShowDrawer"></v-app-bar-nav-icon>
  195. <v-toolbar-title v-text="appName"></v-toolbar-title>
  196. <v-spacer></v-spacer>
  197. <v-menu bottom left offset-y :close-on-content-click="false">
  198. <template v-slot:activator="{ props }">
  199. <v-btn icon="more_vert" v-bind="props" />
  200. </template>
  201. <v-list>
  202. <!-- <v-list-item to="/main/profile" append-icon="person">
  203. <v-list-item-title>{{ t("userProfile") }}</v-list-item-title>
  204. </v-list-item> -->
  205. <!-- <v-list-item to="/main/profile" append-icon="language">
  206. <v-list-item-title>{{ t("language") }}</v-list-item-title>
  207. </v-list-item> -->
  208. <v-list-group value="Admin">
  209. <template v-slot:activator="{ props }">
  210. <v-list-item v-bind="props">
  211. <v-list-item-title>{{ t("language") }}</v-list-item-title>
  212. </v-list-item>
  213. </template>
  214. <v-list-item
  215. v-for="(item, index) in lang"
  216. :key="index"
  217. :value="item.text"
  218. @click="setLang(item.text)"
  219. >
  220. <v-list-item-title>{{ item.title }}</v-list-item-title>
  221. </v-list-item>
  222. </v-list-group>
  223. <v-list-item @click="logout" append-icon="logout">
  224. <v-list-item-title>{{ t("logout") }}</v-list-item-title>
  225. </v-list-item>
  226. </v-list>
  227. </v-menu>
  228. </v-toolbar>
  229. <router-view></router-view>
  230. </v-main>
  231. <v-footer class="pa-3" app>
  232. <v-spacer></v-spacer>
  233. <div class="contact-icon">
  234. <a href="https://discord.gg/C6Yk83ZA" target="_blank">
  235. <img src="@/assets/img/icon/discord.png" alt="discord" />
  236. </a>
  237. <a href="mailto:service@choozmo.com">
  238. <img src="@/assets/img/icon/mail.png" alt="mail" />
  239. </a>
  240. <a href="https://line.me/R/ti/p/@choozmo?from=page" target="_blank">
  241. <img src="@/assets/img/icon/line.png" alt="line" />
  242. </a>
  243. <a href="https://www.facebook.com/choozmo/" target="_blank">
  244. <img src="@/assets/img/icon/facebook.png" alt="facebook" />
  245. </a>
  246. <a href="https://www.instagram.com/choozmo_cmm/" target="_blank">
  247. <img src="@/assets/img/icon/instagram.png" alt="instagram" />
  248. </a>
  249. </div>
  250. <v-spacer></v-spacer>
  251. <span>&copy; ChoozMo</span>
  252. </v-footer>
  253. </div>
  254. </template>
  255. <style lang="scss">
  256. .navbar {
  257. color: #fff;
  258. background-image: linear-gradient(
  259. -225deg,
  260. rgb(234, 84, 19) 35%,
  261. rgb(178, 69, 146) 100%
  262. );
  263. }
  264. .logo-img {
  265. max-width: 150px;
  266. }
  267. .card-title {
  268. letter-spacing: 1px !important;
  269. }
  270. .contact-icon {
  271. margin-top: 10px;
  272. img {
  273. width: 30px;
  274. margin: 0 5px;
  275. }
  276. }
  277. </style>