重构: 前端优化插件及第三方登录插件兼容性优化
parent
7119854233
commit
8340ef2d56
|
@ -41,7 +41,7 @@ const router = new VueRouter({
|
||||||
*/
|
*/
|
||||||
router.beforeEach(async (to, from, next) => {
|
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
|
// 确认已经加载多标签页数据 https://github.com/d2-projects/d2-admin/issues/201
|
||||||
await store.dispatch('d2admin/page/isLoaded')
|
await store.dispatch('d2admin/page/isLoaded')
|
||||||
// 确认已经加载组件尺寸设置 https://github.com/d2-projects/d2-admin/issues/198
|
// 确认已经加载组件尺寸设置 https://github.com/d2-projects/d2-admin/issues/198
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import layoutHeaderAside from '@/layout/header-aside'
|
import layoutHeaderAside from '@/layout/header-aside'
|
||||||
|
import { checkPlugins } from '@/views/plugins/index.js'
|
||||||
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
|
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
|
||||||
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
|
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
|
||||||
|
|
||||||
|
@ -186,7 +186,16 @@ const frameOut = [
|
||||||
component: _import('system/login')
|
component: _import('system/login')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
/**
|
||||||
|
* 第三方登录
|
||||||
|
*/
|
||||||
|
if (checkPlugins('third-party-login')) {
|
||||||
|
frameOut.push({
|
||||||
|
path: '/thirdPartyLogin',
|
||||||
|
name: 'login',
|
||||||
|
component: _import('plugins/third-party-login/src/login/index')
|
||||||
|
})
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 错误页面
|
* 错误页面
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,22 +18,20 @@ export default {
|
||||||
/**
|
/**
|
||||||
* @description 登录
|
* @description 登录
|
||||||
* @param {Object} context
|
* @param {Object} context
|
||||||
* @param {Object} payload username {String} 用户账号
|
* @param {Object} data
|
||||||
* @param {Object} payload password {String} 密码
|
* @param {Object} data username {String} 用户账号
|
||||||
* @param {Object} payload route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
|
* @param {Object} data password {String} 密码
|
||||||
*/
|
* @param {Object} data route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
|
||||||
async login ({ dispatch }, {
|
* @param {Object} data request function 请求方法
|
||||||
username = '',
|
*/
|
||||||
password = '',
|
async login ({ dispatch }, data) {
|
||||||
captcha = '',
|
let request = data.request
|
||||||
captchaKey = ''
|
if (request) {
|
||||||
} = {}) {
|
delete data.request
|
||||||
let res = await SYS_USER_LOGIN({
|
} else {
|
||||||
username,
|
request = SYS_USER_LOGIN
|
||||||
password,
|
}
|
||||||
captcha,
|
let res = await request(data)
|
||||||
captchaKey
|
|
||||||
})
|
|
||||||
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
||||||
// 整个系统依赖这两个数据进行校验和存储
|
// 整个系统依赖这两个数据进行校验和存储
|
||||||
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
function importAll (r) {
|
function importAll (r) {
|
||||||
const __modules = []
|
const __modules = []
|
||||||
r.keys().forEach(key => {
|
r.keys().forEach(key => {
|
||||||
|
@ -8,10 +10,18 @@ function importAll (r) {
|
||||||
return __modules
|
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) {
|
export const plugins = async function install (Vue, options) {
|
||||||
// 查找 src/views/plugins 目录所有插件,插件目录下需有 index.js 文件
|
// 查找 src/views/plugins 目录所有插件,插件目录下需有 index.js 文件
|
||||||
// 再查找 node_modules/@great-dream/ 目录下所有插件
|
// 再查找 node_modules/@great-dream/ 目录下所有插件
|
||||||
// 进行去重并vue注册导入
|
// 进行去重并vue注册导入
|
||||||
|
if (window.pluginsAll) return
|
||||||
let components = []
|
let components = []
|
||||||
components = components.concat(importAll(require.context('./', true, /index\.js$/)))
|
components = components.concat(importAll(require.context('./', true, /index\.js$/)))
|
||||||
components = components.concat(importAll(require.context('@great-dream/', true, /index\.js$/)))
|
components = components.concat(importAll(require.context('@great-dream/', true, /index\.js$/)))
|
||||||
|
|
Loading…
Reference in New Issue