重构: 前端优化插件及第三方登录插件兼容性优化

pull/47/MERGE
李强 2022-04-10 00:37:56 +08:00
parent 7119854233
commit 8340ef2d56
4 changed files with 36 additions and 19 deletions

View File

@ -41,7 +41,7 @@ const router = new VueRouter({
*/
router.beforeEach(async (to, from, next) => {
// 白名单
const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/thirdPartyLogin']
// 确认已经加载多标签页数据 https://github.com/d2-projects/d2-admin/issues/201
await store.dispatch('d2admin/page/isLoaded')
// 确认已经加载组件尺寸设置 https://github.com/d2-projects/d2-admin/issues/198

View File

@ -1,5 +1,5 @@
import layoutHeaderAside from '@/layout/header-aside'
import { checkPlugins } from '@/views/plugins/index.js'
// 由于懒加载页面太多的话会造成webpack热更新太慢所以开发环境不使用懒加载只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
@ -186,7 +186,16 @@ const frameOut = [
component: _import('system/login')
}
]
/**
* 第三方登录
*/
if (checkPlugins('third-party-login')) {
frameOut.push({
path: '/thirdPartyLogin',
name: 'login',
component: _import('plugins/third-party-login/src/login/index')
})
}
/**
* 错误页面
*/

View File

@ -18,22 +18,20 @@ export default {
/**
* @description 登录
* @param {Object} context
* @param {Object} payload username {String} 用户账号
* @param {Object} payload password {String} 密码
* @param {Object} payload route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
*/
async login ({ dispatch }, {
username = '',
password = '',
captcha = '',
captchaKey = ''
} = {}) {
let res = await SYS_USER_LOGIN({
username,
password,
captcha,
captchaKey
})
* @param {Object} data
* @param {Object} data username {String} 用户账号
* @param {Object} data password {String} 密码
* @param {Object} data route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
* @param {Object} data request function 请求方法
*/
async login ({ dispatch }, data) {
let request = data.request
if (request) {
delete data.request
} else {
request = SYS_USER_LOGIN
}
let res = await request(data)
// 设置 cookie 一定要存 uuid token 两个 cookie
// 整个系统依赖这两个数据进行校验和存储
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复

View File

@ -1,3 +1,5 @@
import Vue from 'vue'
function importAll (r) {
const __modules = []
r.keys().forEach(key => {
@ -8,10 +10,18 @@ function importAll (r) {
return __modules
}
export const checkPlugins = async function install (pluginName) {
if (!window.pluginsAll) {
plugins(Vue)
}
return (window.pluginsAll && window.pluginsAll.indexOf(pluginName) !== -1)
}
export const plugins = async function install (Vue, options) {
// 查找 src/views/plugins 目录所有插件插件目录下需有 index.js 文件
// 再查找 node_modules/@great-dream/ 目录下所有插件
// 进行去重并vue注册导入
if (window.pluginsAll) return
let components = []
components = components.concat(importAll(require.context('./', true, /index\.js$/)))
components = components.concat(importAll(require.context('@great-dream/', true, /index\.js$/)))