优化: 前端插件优化
							parent
							
								
									7bbb33344f
								
							
						
					
					
						commit
						44fc7e934a
					
				| 
						 | 
				
			
			@ -41,7 +41,7 @@ const router = new VueRouter({
 | 
			
		|||
 */
 | 
			
		||||
router.beforeEach(async (to, from, next) => {
 | 
			
		||||
  // 白名单
 | 
			
		||||
  const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/thirdPartyLogin']
 | 
			
		||||
  const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/oauth2']
 | 
			
		||||
  // 确认已经加载多标签页数据 https://github.com/d2-projects/d2-admin/issues/201
 | 
			
		||||
  await store.dispatch('d2admin/page/isLoaded')
 | 
			
		||||
  // 确认已经加载组件尺寸设置 https://github.com/d2-projects/d2-admin/issues/198
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -189,12 +189,12 @@ const frameOut = [
 | 
			
		|||
/**
 | 
			
		||||
 * 第三方登录
 | 
			
		||||
 */
 | 
			
		||||
const pluginsType = checkPlugins('third-party-login')
 | 
			
		||||
const pluginsType = checkPlugins('dvadmin-oauth2-web')
 | 
			
		||||
if (pluginsType) {
 | 
			
		||||
  frameOut.push({
 | 
			
		||||
    path: '/thirdPartyLogin',
 | 
			
		||||
    path: '/oauth2',
 | 
			
		||||
    name: 'login',
 | 
			
		||||
    component: pluginsType === 'local' ? _import('plugins/third-party-login/src/login/index') : pluginImport('third-party-login/src/login/index')
 | 
			
		||||
    component: pluginsType === 'local' ? _import('plugins/dvadmin-oauth2-web/src/login/index') : pluginImport('dvadmin-oauth2-web/src/login/index')
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
import Vue from 'vue'
 | 
			
		||||
 | 
			
		||||
function importAll (r) {
 | 
			
		||||
  const __modules = []
 | 
			
		||||
  r.keys().forEach(key => {
 | 
			
		||||
| 
						 | 
				
			
			@ -8,17 +10,32 @@ function importAll (r) {
 | 
			
		|||
  return __modules
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const checkPlugins = async function install (pluginName) {
 | 
			
		||||
export const checkPlugins = function install (pluginName) {
 | 
			
		||||
  let pluginsList
 | 
			
		||||
  pluginsList = importAll(require.context('./', true, /index\.js$/))
 | 
			
		||||
  if (pluginsList && pluginsList.indexOf(pluginName) !== -1) {
 | 
			
		||||
    // 本地插件
 | 
			
		||||
    return 'local'
 | 
			
		||||
    try {
 | 
			
		||||
      const Module = import('@/views/plugins/' + pluginName + '/src/index')
 | 
			
		||||
      // 注册组件
 | 
			
		||||
      if (Module.default) {
 | 
			
		||||
        Vue.use(Module.default)
 | 
			
		||||
      }
 | 
			
		||||
      // 本地插件
 | 
			
		||||
      return 'local'
 | 
			
		||||
    } catch (exception) {}
 | 
			
		||||
  }
 | 
			
		||||
  pluginsList = importAll(require.context('@great-dream/', true, /index\.js$/))
 | 
			
		||||
  if (pluginsList && pluginsList.indexOf(pluginName) !== -1) {
 | 
			
		||||
    // node_modules 封装插件
 | 
			
		||||
    return 'plugins'
 | 
			
		||||
    try {
 | 
			
		||||
      const Module = import('@great-dream/' + pluginName + '/src/index')
 | 
			
		||||
      // 注册组件
 | 
			
		||||
      if (Module.default) {
 | 
			
		||||
        Vue.use(Module.default)
 | 
			
		||||
      }
 | 
			
		||||
      // 本地插件
 | 
			
		||||
      return 'plugins'
 | 
			
		||||
    } catch (exception) {}
 | 
			
		||||
  }
 | 
			
		||||
  // 未找到插件
 | 
			
		||||
  return undefined
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue