From fdf67e8336a840557a7f0324bd8b348e0a5de4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E8=90=BD=28YangLei=29?= Date: Fri, 25 Jun 2021 16:43:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8Capi=E8=AF=B7=E6=B1=82=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- package.json | 1 + src/main.js | 47 +-- .../components/header/LayoutTopHeaderLang.vue | 23 +- src/pages/frame/services/accountService.js | 32 +- src/pages/frame/store/settingModule.js | 24 +- src/pages/frame/view/login/Login.vue | 69 ++-- src/pages/frame/view/login/i18n.js | 48 +-- src/router/guards.js | 112 +++---- src/utils/demo.js | 313 ++++++++++++++++++ src/utils/index.js | 1 + src/utils/langUtils.js | 13 + src/utils/requestUtil.js | 255 +++++++------- src/utils/themeUtil.js | 148 ++++----- vue.config.js | 20 +- 15 files changed, 713 insertions(+), 395 deletions(-) create mode 100644 src/utils/demo.js create mode 100644 src/utils/index.js create mode 100644 src/utils/langUtils.js diff --git a/.env.development b/.env.development index 67b0aee..e301176 100644 --- a/.env.development +++ b/.env.development @@ -1 +1 @@ -VUE_APP_API_BASE_URL=http://dev.iczer.com +VUE_APP_API_BASE_URL=http://platform.kuopu.net:9300 diff --git a/package.json b/package.json index ed7ffba..e7e2571 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "axios": "^0.19.2", "clipboard": "^2.0.6", "core-js": "^3.6.5", + "crypto-js": "^4.0.0", "date-fns": "^2.14.0", "enquire.js": "^2.1.6", "highlight.js": "^10.2.1", diff --git a/src/main.js b/src/main.js index 1683c72..0e3c62f 100644 --- a/src/main.js +++ b/src/main.js @@ -5,30 +5,29 @@ import Viser from 'viser-vue'; import Router from 'vue-router'; import { initRouter } from './router'; import VueI18n from 'vue-i18n'; -import {accountModule, settingModule} from './pages/frame/store'; +import { accountModule, settingModule } from './pages/frame/store'; import App from './App.vue'; -import "tailwindcss/tailwind.css" +import 'tailwindcss/tailwind.css'; import 'animate.css/source/animate.css'; import './theme/index.less'; import Plugins from './plugins'; import { loadRoutes, loadGuards, setAppOptions } from './utils/routerUtil'; -import { loadInterceptors } from './utils/requestUtil'; import guards from './router/guards'; -import interceptors from './router/interceptors'; +import { loadResponseInterceptor } from './utils/requestUtil'; -import '@/mock'; +// import '@/mock'; import 'moment/locale/zh-cn'; -//设置为非生产提示 +//设置为非生产提示 Vue.config.productionTip = false; //装载Vuex控件 -Vue.use(Vuex) -//加载 框架的module包括 命名空间accountModule,settingModule +Vue.use(Vuex); +//加载 框架的module包括 命名空间accountModule,settingModule const store = new Vuex.Store({ - modules: {accountModule, settingModule} + modules: { accountModule, settingModule }, }); //装载vue-router控件 如果开发时 不用动态可直接修改这里 isAsynRount=false @@ -44,11 +43,12 @@ const localeLang = store.state.settingModule.lang; //default'EN' const fallbackLang = store.state.settingModule.fallbackLang; const i18n = new VueI18n({ - locale: localeLang, - fallbackLocale: fallbackLang, - silentFallbackWarn: true, + locale: localeLang, + fallbackLocale: fallbackLang, + silentFallbackWarn: true, }); - + + //装载antd控件 Vue.use(Antd); @@ -60,17 +60,26 @@ Vue.use(Plugins); //启动引导方法应用启动时需要执行的操作放在这里 //设置应用配置 setAppOptions({ router, store, i18n }); -// 加载 axios 拦截器 -loadInterceptors(interceptors, { router, store, i18n, message: Vue.prototype.$message }); + // 加载路由 loadRoutes(); // 加载路由守卫 loadGuards(guards, { router, store, i18n, message: Vue.prototype.$message }); +// this.$notification.open({ +// message: 'Notification Title', +// description: +// 'This is the content of the notification. This is the content of the notification. This is the content of the notification.', +// onClick: () => { +// console.log('Notification Clicked!'); +// }, +// }); + +loadResponseInterceptor(); new Vue({ - router, - store, - i18n, - render: h => h(App), + router, + store, + i18n, + render: h => h(App), }).$mount('#app'); diff --git a/src/pages/frame/components/header/LayoutTopHeaderLang.vue b/src/pages/frame/components/header/LayoutTopHeaderLang.vue index 8ceab99..1aabba5 100644 --- a/src/pages/frame/components/header/LayoutTopHeaderLang.vue +++ b/src/pages/frame/components/header/LayoutTopHeaderLang.vue @@ -1,38 +1,35 @@ - - diff --git a/src/pages/frame/services/accountService.js b/src/pages/frame/services/accountService.js index 19e8468..c33c8d8 100644 --- a/src/pages/frame/services/accountService.js +++ b/src/pages/frame/services/accountService.js @@ -1,5 +1,5 @@ -import { request, METHOD, removeAuthorization } from '@/utils/requestUtil'; -import BASE_URL from '@/utils/baseUrlUtil'; +import { request, METHOD } from '@/utils/requestUtil'; +import md5 from 'crypto-js/md5'; /** * 登录服务,登录成功后 根据用户ID 获取用户 角色 + 菜单 + 功能权限 + 用户基本信息 @@ -7,27 +7,25 @@ import BASE_URL from '@/utils/baseUrlUtil'; * @param password 账户密码 * @returns {Promise>} */ -export async function login(name, password) { - let loginApi = `${BASE_URL}/login`; - return request(loginApi, METHOD.POST, { - name: name, - password: password - }); +export async function login(userName, password) { + return request('/api/v1/login', METHOD.POST, { + userName, + password: md5(password).toString(), + }); } /** * 退出登录 */ export function logout() { - //清除所有保存的信息 - localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY); - localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY); - localStorage.removeItem(process.env.VUE_APP_ROLES_KEY); - localStorage.removeItem(process.env.VUE_APP_USER_KEY); - removeAuthorization(); + //清除所有保存的信息 + localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY); + localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY); + localStorage.removeItem(process.env.VUE_APP_ROLES_KEY); + localStorage.removeItem(process.env.VUE_APP_USER_KEY); } export default { - login, - logout, -} + login, + logout, +}; diff --git a/src/pages/frame/store/settingModule.js b/src/pages/frame/store/settingModule.js index 456e090..c74b49f 100644 --- a/src/pages/frame/store/settingModule.js +++ b/src/pages/frame/store/settingModule.js @@ -1,8 +1,9 @@ -import { globalConfig, settingConfig } from "@/config"; -import { formatFullPath } from "@/utils/i18nUtil"; -import { filterMenu } from "@/utils/authorityUtil"; -import { getLocalSetting } from "@/utils/themeUtil"; -import deepClone from "lodash.clonedeep"; +import { globalConfig, settingConfig } from '@/config'; +import { formatFullPath } from '@/utils/i18nUtil'; +import { filterMenu } from '@/utils/authorityUtil'; +import { getLocalSetting } from '@/utils/themeUtil'; +import { langUtil } from '@/utils'; +import deepClone from 'lodash.clonedeep'; const localSetting = getLocalSetting(true); const customTitlesStr = sessionStorage.getItem(process.env.VUE_APP_TBAS_TITLES_KEY); @@ -17,6 +18,7 @@ export default { pageMinHeight: 0, menuData: [], activatedFirst: undefined, + lang: '', customTitles, ...settingConfig, ...localSetting, @@ -34,7 +36,7 @@ export default { if (menuData.length > 0 && !menuData[0].fullPath) { formatFullPath(menuData); } - return menuData.map((item) => { + return menuData.map(item => { const menuItem = { ...item }; delete menuItem.children; return menuItem; @@ -45,7 +47,7 @@ export default { if (menuData.length > 0 && !menuData[0].fullPath) { formatFullPath(menuData); } - const current = menuData.find((menu) => menu.fullPath === activatedFirst); + const current = menuData.find(menu => menu.fullPath === activatedFirst); return (current && current.children) || []; }, }, @@ -73,6 +75,7 @@ export default { }, setLang(state, lang) { state.lang = lang; + langUtil.set(lang); }, setHideSetting(state, hideSetting) { state.hideSetting = hideSetting; @@ -97,13 +100,16 @@ export default { }, setCustomTitle(state, { path, title }) { if (title) { - const obj = state.customTitles.find((item) => item.path === path); + const obj = state.customTitles.find(item => item.path === path); if (obj) { obj.title = title; } else { state.customTitles.push({ path, title }); } - sessionStorage.setItem(process.env.VUE_APP_TBAS_TITLES_KEY, JSON.stringify(state.customTitles)); + sessionStorage.setItem( + process.env.VUE_APP_TBAS_TITLES_KEY, + JSON.stringify(state.customTitles), + ); } }, }, diff --git a/src/pages/frame/view/login/Login.vue b/src/pages/frame/view/login/Login.vue index 795983c..c103e3a 100644 --- a/src/pages/frame/view/login/Login.vue +++ b/src/pages/frame/view/login/Login.vue @@ -12,8 +12,12 @@ - + ]" + > - + ]" + > @@ -50,7 +61,14 @@ {{ $t('forgetPwdLink') }} - {{ $t('loginButton') }} + {{ $t('loginButton') }} @@ -60,13 +78,12 @@