2 Star 1 Fork 0

fyl080801 / seed-ui-ng

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

seed-ui-ng

基于 webpack 打包的 angular 框架

原 seed-ui-angular 基于 webpack 打包重写,使用typescript开发

要问现在rectvue满天飞为什么非得用angular老版本,支持ie8

基于组件的路由

angular路由是不支持组件的,只能分着设置templatecontroller,现在把这个过程做成类似vue那种用组件形式定义,支持子路由

使用webpacktext-loader,在controller定义中导出html模板

import mod from '../module'

class Controller {
  constructor(private $scope: any) { }
}

Controller.$inject = ['$scope']

mod.controller('sample/components/home', Controller)

// 这里导出模板
export = require('./home.html')

在路由初始化时候require引用组件

$routerProvider
  .add({
    name: 'index',
    component: require('./components/index')
  })
  .add({
    name: 'home',
    component: require('./components/home'),
    children: [
      { name: 'part1', component: require('./components/parts/part1') },
      { name: 'part2', component: require('./components/parts/part2') }
    ]
  })
  .other('index')

模块入口定义和模块引用

每个模块在文件夹下定义一个module.ts文件,用于模块的初始化和导出模块定义

'use strict'

import { createModule } from '../../app/application'

class SampleModule {
  static $inject = ['$routerProvider']

  constructor($routerProvider: seed.IRouterProvider) {
    $routerProvider
      .add({
        name: 'index',
        title: '首页',
        component: require('./components/index')
      })
      .add({
        name: 'home',
        component: require('./components/home'),
        children: [
          {
            name: 'part1',
            title: '标题1',
            component: require('./components/parts/part1')
          },
          {
            name: 'part2',
            component: require('./components/parts/part2')
          }
        ]
      })
      .other('index')
  }
}

// 使用 application 的 createModule 创建模块
export default createModule('modules.sample').config(SampleModule)

在模块中直接使用导出创建angular对象

import mod from '../../module'

mod.controller('part2Controller', () => {})

export = require('./part2.html')

在模块目录下定义require.ts,统一模块下所有定义,在应用入口引用

import './components/index'
import './components/home'
import './components/parts/part1'
import './components/parts/part2'

应用初始化

目录中 index.ts 文件定义

'use strict'

import './app/polyfill'
// 引用模块 requires
import './modules/sample/requires'
import application from './app/application'

// 初始化
application().run()

集成bootstrap

自带bootstrap并对弹模态窗进行包装,使模态窗的加载也支持通过组件引用实现,在原有bootstrap模态窗样式基础上增加侧边滑出样式及动画效果

// 引用组件
const SimpleModal = require('./modals/simpleModal')

class Controller {
  constructor(private $scope: any, private $modal: seed.IModalService) {
    $scope.vm = this
  }

  click1() {
    alert('clicked!!')
  }

  click2() {
    // 模态窗使用基于组件
    this.$modal
      .open({
        component: SimpleModal,
        windowClass: 'right',
        backdrop: 'static',
        size: 'lg'
      })
      .result.then(() => {})
  }

  click3() {
    this.$modal.open({
      component: SimpleModal,
      size: 'sm'
    })
  }
}

Controller.$inject = ['$scope', '$modal']

集成小功能

定义了一些常用的功能函数,具体看注释吧

$delayTimer: 查询时输入文字 throttle

$router: 基于组件的路由

$popup: 弹出消息和提示框

$request: 链式调用的 ajax 请求

$tree: 根据数组元素包含 parentId 将数组转化成树对象,转换完后每一个对象具有 parent、children、data 属性

其他

去掉了原来通过模块打包按需加载 js 功能,费那么大工夫实现还不如直接新打包一个模块作为单独页面分片加载,至于模块页面间共享数据及公共视图,将来直接从node端输出到 js 结果里

要是想实现vue那种模板和脚手架的话以后再说吧,我就一个人而且只有晚上有时间,那么多功能得一点点来呀

MIT License Copyright (c) 2019 fyl080801 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于webpack打包的angular框架 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/fyl080801/seed-ui-ng.git
git@gitee.com:fyl080801/seed-ui-ng.git
fyl080801
seed-ui-ng
seed-ui-ng
master

搜索帮助