first commit
12
.babelrc
Executable file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"latest", {
|
||||
"es2015": {
|
||||
"modules": false,
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
16
.gitignore
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
node_modules/
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
yarn-error.log
|
||||
.vscode/
|
||||
.DS_Store
|
||||
.cache/
|
||||
src/resources/view/admin/node_modules/
|
||||
src/resources/view/admin/.cache/
|
||||
src/resources/view/admin/dist/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
233
README.md
Executable file
@@ -0,0 +1,233 @@
|
||||
## 1:项目说明
|
||||
|
||||
这是一套基于`Nodejs` + `koa2` + `Typescript` + `Routing-controllers` 纯手工搭建的项目基本框架,可以直接用在`传统网站`+`管理后台`的项目开发中。
|
||||
|
||||
就算你不会`php`,不会`java`也能够让前端的你无缝的对接和使用,独立开发网站不再是梦...
|
||||
|
||||
本项目中已经集成了:
|
||||
|
||||
- 1:`koa-log4`实现系统日志(程序日志access,运行日志application),日志放在`logs`文件夹中,当然你也可以在`/src/config`中指定日志输入路径。
|
||||
|
||||
- 2:基于`ApiDoc`实现接口帮助文档,可在方法上使用注释的方式生成接口文档,运行命令:`npm run doc` 生成文档。
|
||||
|
||||
- 3:接口测试,主要在`rest/`文件夹中,使用`*.http`进行接口调试。
|
||||
|
||||
- 4:实现`k-init cli`可以直接通过命令创建各种文件。
|
||||
|
||||
- 5:`Pm2` 实现负载均衡,上线部署使用命令:`npm run online`。
|
||||
|
||||
- 6:`七牛云` 实现资源文件的上传和存储,案例请看:[前端demo.vue](https://gitee.com/bmycode/VRofficialWebsite/blob/master/src/resources/view/admin/src/view/template/demo.vue),后端:[AdminController.ts](https://gitee.com/bmycode/VRofficialWebsite/blob/master/src/controller/admin/AdminController.ts)。
|
||||
|
||||
- 7:~~集成`支付宝支付`功能,可以直接配置然后使用(PS:支付涉及很多核心参数配置,所以该功能被删除,如需要请QQ私聊)~~。
|
||||
|
||||
- 8:基于`Java`开发的思想,设计`service层`,`dao层`,`entity层`,`model层`等,当然在`Node.js`中使用略有差异,不影响。
|
||||
|
||||
- 9:基于还未正式发布的`Vue-next` + `Element` 实现管理后台页面,管理后台已实现登录权限控制等。
|
||||
|
||||
- 10:`PC`端的前端主要使用`require.js`实现`js`模块化,`less`+`jade`实现`Css`样式和`Html`。
|
||||
|
||||
- 11:数据库基于`Mysql`,数据库操作使用`Node ORM`:`typeorm`,如果不熟悉`Mysql`又不想去学习,那么可以自己集成第三方后端云数据库,减少数据库相关的学习和开发成本。
|
||||
|
||||
- 12:~~基于新的打包工具`parcel`对管理后台的`vue`页面进行打包,后面会重新改造为`Vue3`作为项目管理后台~~
|
||||
|
||||
- 13:基于`gulp`完成对`PC`前端`less`的编译和静态资源的复制等。
|
||||
|
||||
|
||||
|
||||
## 2:技术栈
|
||||
|
||||
---
|
||||
|
||||
- 1: TypeScript
|
||||
- 2: Koa2.js(全家桶)
|
||||
- 3: jade + less
|
||||
- 4: GraphQL
|
||||
- 5: TypeOrm
|
||||
- 6: TypeDi
|
||||
- 7: class-validator
|
||||
- 8: Gulp
|
||||
- 9: Routing-controllers
|
||||
- 10: Require.js
|
||||
- 11: Vue.js(全家桶) & TypeScript
|
||||
- 12: Node.js
|
||||
- 13: Parcel
|
||||
- 14:Nginx 负载均衡
|
||||
- 15: Docker
|
||||
- 16: Mysql,主从读写分离
|
||||
- 17: Bmob 在线后端云
|
||||
- 18: 七牛视频云存储方案
|
||||
- 19: 阿里云免费 https 证书
|
||||
- 21: SpringBoot 微服务全家桶技术
|
||||
- ... 此处省略一万字
|
||||
|
||||
|
||||
## 3:k-init cli 使用帮助
|
||||
|
||||
参考`PHP`的框架`Laravel`提供的命令`artisan`实现终端创建项目中各种文件的功能,解决新增页面需要手工创建一大堆文件的麻烦!!
|
||||
|
||||
命令:
|
||||
|
||||
```bash
|
||||
$ ./bin/kinit -h
|
||||
|
||||
Usage: kinit [options]
|
||||
|
||||
Options:
|
||||
-t, --file-type <type> 文件类型: [controller,dao,entity,model,service,impl,jade,less,js]
|
||||
-n, --file-name <name> 被创建的文件名称
|
||||
-p, --file-path <path> 为 -t 参数指定 controller 文件夹名
|
||||
-i, --is-create <is> 是否为 -t 参数自动创建相关文件类型 (default: false)
|
||||
-v, --version 显示当前的版本
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
### 例子 1:
|
||||
|
||||
比如现在需要在`src/controller/api`下单独创建接口,那么可以使用命令:
|
||||
|
||||
```bash
|
||||
$ ./bin/kinit -t controller -p api -n Test
|
||||
```
|
||||
|
||||
参数说明:
|
||||
|
||||
- `-t controller`:表示创建的文件类型为`controller`
|
||||
- `-p api`:表示需要在`src/controller/`文件夹的`api/`文件夹下创建文件,因为`controller`里面有三个文件夹,所以需要指定文件夹名称
|
||||
- `-n Test`:表示创建的文件名称是`Test`
|
||||
|
||||
### 例子 2:
|
||||
|
||||
现在我需要新增一个`PC`官网前台页面,比如**详情页(Info)**,那么按照先前传统的过程我们需要手工去创建:`controller`,`dao`,`entity`,`model`,`service`,`impl`,`jade`,`less`,`js`等一堆文件!真的很烦,而且还要在这么多的文件中写入测试代码,更烦!!
|
||||
|
||||
这种需求很常见,但是现在不必忍受,因为你可以使用命令来自动化创建所有文件,文件中包含实例代码:
|
||||
|
||||
```bash
|
||||
$ ./bin/kinit -t controller -p home -n Info -i true
|
||||
```
|
||||
|
||||
参数说明(其他参数和上面一样):
|
||||
|
||||
- `-i true`:表示是否需要为`Info`自动创建其他更多的各种文件,需要:`true`,不需要:`false` 或者 不写参数`-i`即可。
|
||||
|
||||
### 例子 3:
|
||||
|
||||
创建其他类型的文件,命令都一样。例如:
|
||||
|
||||
```bash
|
||||
$ ./bin/kinit -t entity -n Test # 创建 TestEntity 数据库实体
|
||||
$ ./bin/kinit -t model -n Test # 创建 TestModel 这里主要做数据校验的功能
|
||||
$ ./bin/kinit -t dao -n Test # 创建 TestDao 数据库操作层
|
||||
$ ./bin/kinit -t service -n Test # 创建 TestService Service层
|
||||
$ ./bin/kinit -t impl -n Test # 创建 TestServiceImpl Service实现层
|
||||
$ ./bin/kinit -t jade -n Test # 创建 Test.jade 静态页面View层
|
||||
$ ./bin/kinit -t js -n Test # 创建 Test.js 静态页面的js逻辑
|
||||
$ ./bin/kinit -t less -n Test # 创建 Test.less 静态页面的css样式
|
||||
```
|
||||
|
||||
## 4:插件 routing-controllers 的坑
|
||||
|
||||
- Bug: 使用注解 `@Render` 渲染模板后,第二次访问其他页面但是展示效果还是上次的页面,页面不进行渲染
|
||||
|
||||
- 路径:`node_modules/routing-controllers/driver/koa/KoaDriver.js`
|
||||
- 行数:`250`行
|
||||
|
||||
解决: 删除下面代码:
|
||||
|
||||
```js
|
||||
// 保留,不要修改
|
||||
var renderOptions_1 = result && result instanceof Object ? result : {};
|
||||
|
||||
// 开始 - 下面的都删除
|
||||
this.koa.use(function (ctx, next) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, ctx.render(action.renderedTemplate, renderOptions_1)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// 结束 - 上面的都删除
|
||||
````
|
||||
|
||||
删除后,使用使用下面代码替换:
|
||||
|
||||
```js
|
||||
return options.response.render(action.renderedTemplate, renderOptions_1);
|
||||
```
|
||||
|
||||
最后改好的的样子如下:
|
||||
|
||||
```js
|
||||
var renderOptions_1 = result && result instanceof Object ? result : {};
|
||||
return options.response.render(action.renderedTemplate, renderOptions_1);
|
||||
```
|
||||
|
||||
- Github 问题反馈地址:[https://github.com/../434](https://github.com/typestack/routing-controllers/pull/434)
|
||||
|
||||
- Github 修复分支记录:[https://github.com/types..](https://github.com/typestack/routing-controllers/pull/434/files/001b45a416e3f1dbde33e7e91fadb09111d4061d)
|
||||
|
||||
|
||||
|
||||
├── README.md 项目帮助文档
|
||||
├── apidoc.json 插件apidoc的配置文件
|
||||
├── bin 自己实现的终端命令行,用于生成各种文件
|
||||
├── dist 正式环境下打包上线部署用的
|
||||
├── doc 基于apidoc自动扫包生成的接口帮助文档
|
||||
├── gulpfile.js gulp自动化的代码
|
||||
├── logs 程序日志文件
|
||||
├── md apidoc文档的公共部分页面
|
||||
├── package.json 项目核心依赖配置文件
|
||||
├── rest 接口 *.http 测试文件
|
||||
├── src 存放项目核心源码
|
||||
│ ├── config 站点配置文件,分为开发阶段配置文件,和 正式环境配置文件
|
||||
│ ├── controller 网站的核心控制器
|
||||
│ │ ├── admin 管理后台控制器
|
||||
│ │ ├── api 接口控制器
|
||||
│ │ └── home 官网前端控制器
|
||||
│ ├── dao 操作实体entity前的orm封装
|
||||
│ ├── entity 数据库实体,和mysql中具体的表建立关联,实现查询
|
||||
│ ├── index.ts 项目核心入口文件
|
||||
│ ├── middleware 项目中间件,主要放在装饰在controller上做一些登录检查,json数据格式化日志记录等等
|
||||
│ ├── model 主要用来自动校验api接口的参数是否符合model中的要求,比如ajax参数缺失,类型不对等!
|
||||
│ ├── plugins 第三方插件,例如七牛云,阿里云,支付宝,微信支付等,需要在这里重写第三方sdk实现封装
|
||||
│ ├── resources 存放页面字体图标等静态资源
|
||||
│ │ ├── static
|
||||
│ │ │ ├── css gulp编译less文件夹源码,自动生成的文件夹,存放这编译后的官网前端,管理后台的css
|
||||
│ │ │ ├── fonts 分别存放官网前端,管理后台的fonts
|
||||
│ │ │ ├── img 分别存放官网前端,管理后台的img
|
||||
│ │ │ ├── js 存放官网前端的js,使用require.js 实现模块化
|
||||
│ │ │ ├── less css的真正源码
|
||||
│ │ │ └── plugins 第三方插件
|
||||
│ │ └── view 网站的页面视图层
|
||||
│ │ ├── admin 基于vue ClassApi 语法的管理后台,主要Typescript实现
|
||||
│ │ │ ├── dist 管理后台打包后用于上线的,这个文件会被gulp自动复制到/dist/中
|
||||
│ │ │ ├── index.html 管理后台的根html
|
||||
│ │ │ ├── src 管理后台的源码
|
||||
│ │ │ │ ├── App.vue 核心根组件
|
||||
│ │ │ │ ├── api axios api接口的封装
|
||||
│ │ │ │ ├── assets 静态资源
|
||||
│ │ │ │ ├── config 站点配置
|
||||
│ │ │ │ ├── index.ts 启动文件
|
||||
│ │ │ │ ├── public 公共资源,不会被parcel打包的
|
||||
│ │ │ │ ├── run 核心启动文件,主要实例化vue和装载各种插件
|
||||
│ │ │ │ ├── store vuex全局状态管理
|
||||
│ │ │ │ ├── utils 公共方法
|
||||
│ │ │ │ ├── view 存放管理后台的*.vue文件
|
||||
│ │ │ └── tsconfig.json typescript 配置文件
|
||||
│ │ └── home 官网前端页面
|
||||
│ │ ├── layout.jade 公共父布局页面
|
||||
│ │ ├── page 官网前端具体的每个页面
|
||||
│ │ └── public 官网前端公共模板
|
||||
│ ├── run 整个项目的核心启动文件
|
||||
│ │ ├── app.ts 继承ini.ts,负责启动init.ts配置好的koa对象
|
||||
│ │ └── init.ts 装配koa对象,实现各种配置,看源码
|
||||
│ ├── service 接口请求的service层,主要依赖注入后调用dao层
|
||||
│ │ ├── UserService.ts 实现impl中的接口,实现具体逻辑
|
||||
│ │ └── impl 规范service代码的接口
|
||||
│ └── utils
|
||||
├── test 项目一些实验性demo的测试文件,比如测试支付宝支付
|
||||
├── tsconfig.json 整个项目的typescript配置文件
|
||||
15
apidoc.json
Executable file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "怪客课堂",
|
||||
"version": "1.1.0",
|
||||
"description": "怪客课堂,基于Nodejs + Koa2 + TypeScript 构建的网站",
|
||||
"title": "怪客课堂",
|
||||
"url" : "http://www. geekhelp.cn/bmy/api",
|
||||
"header": {
|
||||
"title": "My own header title",
|
||||
"filename": "./md/header.md"
|
||||
},
|
||||
"footer": {
|
||||
"title": "My own footer title",
|
||||
"filename": "./md/footer.md"
|
||||
}
|
||||
}
|
||||
1
bin/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
a295b73d-da90-4c93-9a60-86b6ef15a2b9
|
||||
1
bin/FileTpl/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
aaea7bf8-ca33-4943-982b-b06379a36042
|
||||
9
bin/FileTpl/conterller.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
import {Controller, Render, Get, UseBefore, Session} from "routing-controllers";
|
||||
import { utils } from "../../utils/utils";
|
||||
import { Service, Inject } from "typedi";
|
||||
|
||||
@Service()
|
||||
@Controller()
|
||||
export class ControllerName {
|
||||
|
||||
}
|
||||
7
bin/FileTpl/dao.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Service , Inject } from "typedi";
|
||||
import { getRepository } from "typeorm";
|
||||
|
||||
@Service()
|
||||
export class DaoName {
|
||||
|
||||
}
|
||||
9
bin/FileTpl/entity.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
|
||||
|
||||
@Entity("user")
|
||||
export class EntityName {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
user_id: number;
|
||||
|
||||
}
|
||||
14
bin/FileTpl/impl.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
import { UserService } from "../UserService";
|
||||
import { Service, Inject } from "typedi";
|
||||
import { UserDao } from "../../dao/UserDao";
|
||||
|
||||
@Service()
|
||||
export class ImplName implements ServiceName {
|
||||
|
||||
@Inject()
|
||||
private userDao: UserDao;
|
||||
|
||||
public async getAllUserService(): Promise<any> {
|
||||
return await this.userDao.AllUser();
|
||||
}
|
||||
}
|
||||
10
bin/FileTpl/jade.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
extends ./../layout
|
||||
|
||||
block title
|
||||
|
||||
meta(name="description" content="关于我们,企业联系,课程咨询,问题答疑")
|
||||
meta(name="keywords" content="编码猿,关于我们,怪客学堂")
|
||||
|
||||
block content
|
||||
.about(class="pages JadeName" data-module="JadeName")
|
||||
.container 测试
|
||||
12
bin/FileTpl/js.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
define(['jquery','utils'],function ($,utils) {
|
||||
function JsName() {
|
||||
|
||||
}
|
||||
|
||||
JsName.prototype = {
|
||||
init () {
|
||||
}
|
||||
};
|
||||
|
||||
return new JsName();
|
||||
});
|
||||
3
bin/FileTpl/less.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
.ClassName {
|
||||
color: red;
|
||||
}
|
||||
8
bin/FileTpl/model.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
import { MinLength,IsInt, MaxLength,Allow,Validate } from 'class-validator';
|
||||
|
||||
export class ModelName {
|
||||
@MinLength(1,{
|
||||
message: 'id参数必须有'
|
||||
})
|
||||
id: string;
|
||||
}
|
||||
3
bin/FileTpl/service.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface ServiceName {
|
||||
getOneUserService(id: string) : Promise<any>;
|
||||
}
|
||||
177
bin/kinit
Executable file
@@ -0,0 +1,177 @@
|
||||
#!/usr/bin/env node
|
||||
const { program } = require('commander');
|
||||
const package = require("../package");
|
||||
const fs = require("fs");
|
||||
const path = require('path');
|
||||
|
||||
program
|
||||
.requiredOption('-t, --file-type <type>', '文件类型: [controller,dao,entity,model,service,impl,jade,less,js]')
|
||||
.option('-n, --file-name <name>', '被创建的文件名称')
|
||||
.option('-p, --file-path <path>', '为 -t 参数指定 controller 文件夹名')
|
||||
.option('-i, --is-create <is>', '是否为 -t 参数自动创建相关文件类型', false);
|
||||
program.version(package.version, '-v, --version', '显示当前的版本');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
// 存储终端的参数
|
||||
const programOptions = program.opts();
|
||||
|
||||
/**
|
||||
* TODO 如果在Api或者Admnin文件夹下创建controller,那么也可以为他们关联创建更多的文件类型
|
||||
* @type {string}
|
||||
*/
|
||||
|
||||
// 各个文件路径
|
||||
let DaoPath = pathJoin(`../src/dao/${programOptions.fileName}Dao.ts`);
|
||||
let EntityPath = pathJoin(`../src/entity/${programOptions.fileName}Entity.ts`);
|
||||
let ModelPath = pathJoin(`../src/model/${programOptions.fileName}Model.ts`);
|
||||
let ServicePath = pathJoin(`../src/service/${programOptions.fileName}Service.ts`);
|
||||
let ServiceImplPath = pathJoin(`../src/service/impl/${programOptions.fileName}ServiceImpl.ts`);
|
||||
let JadePath = pathJoin(`../src/resources/view/home/page/${programOptions.fileName}.jade`);
|
||||
let LessPath = pathJoin(`../src/resources/static/less/home/${programOptions.fileName}.less`);
|
||||
let JsPath = pathJoin(`../src/resources/static/js/app/${programOptions.fileName}.js`);
|
||||
let ControllerPath = "";
|
||||
|
||||
// 判断是否创建 controller 并且 路径文件夹名是否不为空
|
||||
if (programOptions.fileType == 'controller' && (programOptions.filePath == 'home' || programOptions.filePath == 'api' || programOptions.filePath == 'admin') ) {
|
||||
|
||||
// 存储controller路径
|
||||
ControllerPath = path.join(__dirname, `../src/controller/${programOptions.filePath}/${programOptions.fileName}Controller${UpperCase(programOptions.filePath)}.ts`);
|
||||
|
||||
// 是否需要为 controller 联合创建所有文件
|
||||
if (programOptions.isCreate) {
|
||||
|
||||
switch (programOptions.filePath) {
|
||||
// 创建所有文件
|
||||
case 'home':
|
||||
let FileList = ['controller','dao','entity','model','service','impl','jade','less','js'];
|
||||
FileList.forEach(val => replaceTplText(val));
|
||||
console.log("成功创建所有文件...");
|
||||
break;
|
||||
|
||||
// 只创建ts文件
|
||||
case 'api':
|
||||
['controller','dao','entity','model','service','impl'].forEach(val => replaceTplText(val));
|
||||
console.log("成功创建所有文件...");
|
||||
break;
|
||||
|
||||
// 只创建ts文件
|
||||
case 'admin':
|
||||
['controller','dao','entity','model','service','impl'].forEach(val => replaceTplText(val));
|
||||
console.log("成功创建所有文件...");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break
|
||||
}
|
||||
// 只创建 controller
|
||||
} else {
|
||||
|
||||
// 生成并写入模板内容
|
||||
replaceTplText('controller');
|
||||
console.log("controller创建成功...")
|
||||
}
|
||||
}
|
||||
// 创建 dao
|
||||
if (programOptions.fileType == 'dao') replaceTplText('dao');
|
||||
// 创建 entity
|
||||
if (programOptions.fileType == 'entity') replaceTplText('entity');
|
||||
// 创建 model
|
||||
if (programOptions.fileType == 'model') replaceTplText('model');
|
||||
// 创建 service
|
||||
if (programOptions.fileType == 'service') replaceTplText('service');
|
||||
// 创建 impl
|
||||
if (programOptions.fileType == 'impl') replaceTplText('impl');
|
||||
// 创建 jade
|
||||
if (programOptions.fileType == 'jade') replaceTplText('jade');
|
||||
// 创建 less
|
||||
if (programOptions.fileType == 'less') replaceTplText('less');
|
||||
// 创建 js
|
||||
if (programOptions.fileType == 'js') replaceTplText('js');
|
||||
|
||||
|
||||
/**
|
||||
* 替换模板的内容,并将内容写入文件。
|
||||
*/
|
||||
function replaceTplText (action) {
|
||||
switch (action) {
|
||||
case 'controller':
|
||||
let text = GetFileText('./FileTpl/conterller.txt').replace(/ControllerName/g, `${programOptions.fileName}Controller${UpperCase(programOptions.filePath)}`);
|
||||
fs.writeFileSync(ControllerPath, text);
|
||||
break;
|
||||
|
||||
case 'dao':
|
||||
let dao = GetFileText('./FileTpl/dao.txt').replace(/DaoName/g, `${UpperCase(programOptions.fileName)}Dao`);
|
||||
fs.writeFileSync(DaoPath, dao);
|
||||
break;
|
||||
|
||||
case 'entity':
|
||||
let entity = GetFileText('./FileTpl/entity.txt').replace(/EntityName/g, `${UpperCase(programOptions.fileName)}Entity`);
|
||||
fs.writeFileSync(EntityPath, entity);
|
||||
break;
|
||||
|
||||
case 'model':
|
||||
let model = GetFileText('./FileTpl/model.txt').replace(/ModelName/g, `${UpperCase(programOptions.fileName)}Model`);
|
||||
fs.writeFileSync(ModelPath, model);
|
||||
break;
|
||||
|
||||
case 'service':
|
||||
let service = GetFileText('./FileTpl/service.txt').replace(/ServiceName/g, `${UpperCase(programOptions.fileName)}Service`);
|
||||
fs.writeFileSync(ServicePath, service);
|
||||
break;
|
||||
|
||||
case 'impl':
|
||||
let impl = GetFileText('./FileTpl/impl.txt').replace(/ImplName/g, `${UpperCase(programOptions.fileName)}ServiceImpl`);
|
||||
impl = impl.replace(/ServiceName/g, `${UpperCase(programOptions.fileName)}Service`);
|
||||
fs.writeFileSync(ServiceImplPath, impl);
|
||||
break;
|
||||
|
||||
case 'jade':
|
||||
let jade = GetFileText('./FileTpl/jade.txt').replace(/JadeName/g, programOptions.fileName);
|
||||
fs.writeFileSync(JadePath, jade);
|
||||
break;
|
||||
|
||||
case 'less':
|
||||
let less = GetFileText('./FileTpl/less.txt').replace(/ClassName/g, programOptions.fileName);
|
||||
fs.writeFileSync(LessPath, less);
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
let js = GetFileText('./FileTpl/js.txt').replace(/JsName/g, programOptions.fileName);
|
||||
fs.writeFileSync(JsPath, js);
|
||||
break;
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单词首字母大写
|
||||
* @param str
|
||||
* @returns {void | string | *}
|
||||
* @constructor
|
||||
*/
|
||||
function UpperCase (str) {
|
||||
return str.replace(str[0],str[0].toUpperCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件内容
|
||||
* @param path
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
function GetFileText (path) {
|
||||
return (fs.readFileSync( pathJoin(path), 'utf-8' )).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接路径
|
||||
* @param paths
|
||||
* @returns {string}
|
||||
*/
|
||||
function pathJoin (paths) {
|
||||
return path.join(__dirname, paths)
|
||||
}
|
||||
1
dist/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
e9969a45-ca59-42c6-9172-d5bf34a034e3
|
||||
1
dist/config/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1fc79af0-ea3e-49ca-afaa-ba4de792022d
|
||||
104
dist/config/dev.js
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
/**
|
||||
* 开发阶段环境配置
|
||||
*/
|
||||
exports.dev = {
|
||||
// 程序默认运行端口
|
||||
port: 80,
|
||||
// 绑定的域名
|
||||
host: "www.geekhelp.cn",
|
||||
// api接口基地址,如果改这个了,请改管理后台的axios基地址配置
|
||||
apiurl: '/bmy/api',
|
||||
// 初始化 koa2 插件需要的一些配置
|
||||
initPlugins: {
|
||||
SessionKey: '4WM7mSy5S5kkxcE1I3',
|
||||
staticPath: '../resources/static',
|
||||
viewsPath: '../resources/view' // 页面视图存放路径
|
||||
},
|
||||
// 终端的欢迎信息
|
||||
banner: {
|
||||
welcome: () => {
|
||||
return `
|
||||
👏 VR 产品介绍网站 👏
|
||||
|
||||
👉 1:PC官网: http://${exports.dev.host}:${exports.dev.port}/
|
||||
👉 2:Admin后台: http://${exports.dev.host}:3030/#/course/all
|
||||
`;
|
||||
}
|
||||
},
|
||||
logConfig: {
|
||||
appenders: {
|
||||
//系统日志
|
||||
access: {
|
||||
type: 'dateFile',
|
||||
pattern: '_yyyy-MM-dd.log',
|
||||
alwaysIncludePattern: true,
|
||||
encoding: "utf-8",
|
||||
category: "access",
|
||||
filename: path_1.default.join(__dirname, '../../logs/access')
|
||||
},
|
||||
// 应用日志
|
||||
application: {
|
||||
type: 'dateFile',
|
||||
pattern: '_yyyy-MM-dd.log',
|
||||
alwaysIncludePattern: true,
|
||||
encoding: "utf-8",
|
||||
category: "application",
|
||||
filename: path_1.default.join(__dirname, '../../logs/application')
|
||||
},
|
||||
out: {
|
||||
type: 'console'
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ['out'], level: 'info' },
|
||||
access: { appenders: ['access'], level: 'info' },
|
||||
application: { appenders: ['application'], level: 'WARN' }
|
||||
}
|
||||
},
|
||||
// 七牛的核心配置,不熟悉七牛请勿修改
|
||||
qiniu: {
|
||||
// 七牛秘钥,七牛云管理后台获得,可以改成自己的
|
||||
accessKey: '0MGmT_rkMiaOeXY09B4EhBnXuDcIYyKlGumQ-zUt',
|
||||
secretKey: '59dfmEi9Q50rMlz9sxTBCvYDhM7biERAjflBXALb',
|
||||
// 视频切片的配置
|
||||
HLSconfig: {
|
||||
// 被切片后视频存放的基路径,如果需要修改域名,请到域名管理后台 CNAME 泛解析域到七牛云
|
||||
// 然后再到七牛配置 泛子域名 将二级域名绑定到指定空间,这里 video.* 被绑定到 m3u8video 空间
|
||||
VideoBaseUrl: 'http://vsassets.geekhelp.cn/',
|
||||
// 需要被切片的源视频所在七牛云的空间名
|
||||
FromBucket: 'vrcource',
|
||||
// 视频被切片后存放的空间名
|
||||
ToBucket: 'm3u8video',
|
||||
// 视频切片规则,参考七牛云官网文档来配置,或者在 多媒体队列 中复制切片参数
|
||||
VideoHlsParams: 'avthumb/m3u8/segtime/10/ab/128k/ar/44100/acodec/libfaac/r/30/vb/1000k/vcodec/libx264/stripmeta/0/noDomain/1|saveas/'
|
||||
}
|
||||
},
|
||||
// 网站浏览器标签卡的基础标题
|
||||
title: ' | 怪客课堂',
|
||||
// 本地Mysql数据库配置
|
||||
typeorm: {
|
||||
type: 'mysql',
|
||||
host: "localhost",
|
||||
charset: "utf8_general_ci",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "lb714500",
|
||||
database: "shop",
|
||||
logging: "all",
|
||||
synchronize: false,
|
||||
logger: "advanced-console",
|
||||
cache: {
|
||||
duration: 30000
|
||||
},
|
||||
maxQueryExecutionTime: 1000,
|
||||
entities: [
|
||||
`${path_1.default.join(__dirname, '../entity/*{.js,.ts}')}`
|
||||
]
|
||||
}
|
||||
};
|
||||
7
dist/config/index.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// 开发环境配置
|
||||
const dev_1 = require("./dev");
|
||||
// 上线环境配置
|
||||
const prod_1 = require("./prod");
|
||||
exports.config = process.env.NODE_ENV == "dev" ? dev_1.dev : prod_1.prod;
|
||||
87
dist/config/prod.js
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
/**
|
||||
* 上线阶段的环境配置
|
||||
*/
|
||||
exports.prod = {
|
||||
port: 9090,
|
||||
host: "127.0.0.1",
|
||||
apiurl: '/bmy/api',
|
||||
uploadPath: '../resources/static/upload/',
|
||||
initPlugins: {
|
||||
SessionKey: '4WM7mSy5S5kkxcE1I3',
|
||||
staticPath: '../resources/static',
|
||||
viewsPath: '../resources/view'
|
||||
},
|
||||
banner: {
|
||||
welcome: () => {
|
||||
return `
|
||||
👏 VR 产品介绍网站 👏
|
||||
|
||||
👉 1:PC官网: http://${exports.prod.host}:${exports.prod.port}/
|
||||
👉 2:Admin后台: http://${exports.prod.host}:3030/#/course/all
|
||||
`;
|
||||
}
|
||||
},
|
||||
logConfig: {
|
||||
appenders: {
|
||||
access: {
|
||||
type: 'console',
|
||||
pattern: '-yyyy-MM-dd.log',
|
||||
alwaysIncludePattern: true,
|
||||
encoding: "utf-8",
|
||||
filename: path_1.default.join(__dirname, '../../logs/access.log') //生成文件路径和文件名
|
||||
},
|
||||
//系统日志
|
||||
application: {
|
||||
type: 'console',
|
||||
pattern: '-yyyy-MM-dd.log',
|
||||
alwaysIncludePattern: true,
|
||||
encoding: "utf-8",
|
||||
filename: path_1.default.join(__dirname, '../../logs/application.log') //生成文件路径和文件名
|
||||
},
|
||||
out: {
|
||||
type: 'console'
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ['out'], level: 'info' },
|
||||
access: { appenders: ['access'], level: 'info' },
|
||||
application: { appenders: ['application'], level: 'WARN' }
|
||||
}
|
||||
},
|
||||
qiniu: {
|
||||
accessKey: '0MGmT_rkMiaOeXY09B4EhBnXuDcIYyKlGumQ-zUt',
|
||||
secretKey: '59dfmEi9Q50rMlz9sxTBCvYDhM7biERAjflBXALb',
|
||||
HLSconfig: {
|
||||
VideoBaseUrl: 'http://video.geekhelp.cn/',
|
||||
FromBucket: 'guaikevideo',
|
||||
ToBucket: 'm3u8video',
|
||||
VideoHlsParams: 'avthumb/m3u8/segtime/10/ab/128k/ar/44100/acodec/libfaac/r/30/vb/640k/vcodec/libx264/stripmeta/0/noDomain/1|saveas/'
|
||||
}
|
||||
},
|
||||
title: ' | 怪客课堂',
|
||||
typeorm: {
|
||||
type: 'mysql',
|
||||
host: "localhost",
|
||||
charset: "utf8_general_ci",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "lb714500",
|
||||
database: "shop",
|
||||
logging: "error",
|
||||
logger: "file",
|
||||
synchronize: false,
|
||||
maxQueryExecutionTime: 1000,
|
||||
cache: {
|
||||
duration: 30000
|
||||
},
|
||||
entities: [
|
||||
`${path_1.default.join(__dirname, '../entity/*{.js,.ts}')}`
|
||||
]
|
||||
}
|
||||
};
|
||||
1
dist/controller/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b8aa34c8-175a-43ce-91ad-e766884dc2a0
|
||||
1
dist/controller/admin/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
2cb09cb8-309b-4514-b520-44d2e79021dd
|
||||
59
dist/controller/admin/AdminController.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const JsonResponseMiddlewares_1 = require("../../middleware/JsonResponseMiddlewares");
|
||||
const typedi_1 = require("typedi");
|
||||
const config_1 = require("../../config");
|
||||
const utils_1 = require("../../utils/utils");
|
||||
const qiniu_1 = require("../../plugins/qiniu");
|
||||
let AdminController = class AdminController {
|
||||
/**
|
||||
* 获取上传token,服务于图片,视频的上传
|
||||
* http://www.geekhelp.cn/bmy/api/admin/token
|
||||
* @param params
|
||||
* @constructor
|
||||
*/
|
||||
Token() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return { qn_token: this.qiniu.GenerateToken() };
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
typedi_1.Inject(),
|
||||
__metadata("design:type", utils_1.utils)
|
||||
], AdminController.prototype, "utils", void 0);
|
||||
__decorate([
|
||||
typedi_1.Inject(),
|
||||
__metadata("design:type", qiniu_1.QiNiu)
|
||||
], AdminController.prototype, "qiniu", void 0);
|
||||
__decorate([
|
||||
routing_controllers_1.Post("/token"),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AdminController.prototype, "Token", null);
|
||||
AdminController = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.JsonController(`${config_1.config.apiurl}/admin`),
|
||||
routing_controllers_1.UseInterceptor(JsonResponseMiddlewares_1.JsonResponseInterceptor)
|
||||
], AdminController);
|
||||
exports.AdminController = AdminController;
|
||||
1
dist/controller/api/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
098941e8-0c40-4428-8a75-a93cb6d7ab4c
|
||||
17
dist/controller/api/TestController.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const typedi_1 = require("typedi");
|
||||
let TestControllerApi = class TestControllerApi {
|
||||
};
|
||||
TestControllerApi = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.Controller()
|
||||
], TestControllerApi);
|
||||
exports.TestControllerApi = TestControllerApi;
|
||||
17
dist/controller/api/TestControllerApi.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const typedi_1 = require("typedi");
|
||||
let TestControllerApi = class TestControllerApi {
|
||||
};
|
||||
TestControllerApi = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.Controller()
|
||||
], TestControllerApi);
|
||||
exports.TestControllerApi = TestControllerApi;
|
||||
110
dist/controller/api/UserControllerApi.js
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const config_1 = require("../../config");
|
||||
const JsonResponseMiddlewares_1 = require("../../middleware/JsonResponseMiddlewares");
|
||||
const typedi_1 = require("typedi");
|
||||
const UserServiceImpl_1 = require("../../service/impl/UserServiceImpl");
|
||||
const UserModel_1 = require("../../model/UserModel");
|
||||
const LogsMiddlewares_1 = require("../../middleware/LogsMiddlewares");
|
||||
let UserControllerApi = class UserControllerApi {
|
||||
/**
|
||||
* @api {get} /user/oneUser oneUser
|
||||
* @apiVersion 1.1.0
|
||||
* @apiDescription 获取一条用户记录
|
||||
* @apiName oneUser
|
||||
* @apiGroup user
|
||||
* @apiParam {string} id 用户id
|
||||
* @apiSuccessExample {json} 请求成功的返回:
|
||||
* {
|
||||
* "status" : 200,
|
||||
* "result" : {
|
||||
* }
|
||||
* }
|
||||
* @apiErrorExample {json} 请求失败的返回
|
||||
* {
|
||||
* "status":200,
|
||||
* "result":{
|
||||
* }
|
||||
* }
|
||||
* @apiSampleRequest http://www.geekhelp.cn/bmy/api/user/oneUser
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
oneUser(query) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.userServiceImpl.getOneUserService(query.id);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @api {get} /user/allUser allUser
|
||||
* @apiVersion 1.1.0
|
||||
* @apiDescription 获取所有用户信息
|
||||
* @apiName allUser
|
||||
* @apiGroup user
|
||||
* @apiSuccessExample {json} 请求成功的返回:
|
||||
* {
|
||||
* "status" : 200,
|
||||
* "result" : {
|
||||
* }
|
||||
* }
|
||||
* @apiErrorExample {json} 请求失败的返回
|
||||
* {
|
||||
* "status":200,
|
||||
* "result":{
|
||||
* }
|
||||
* }
|
||||
* @apiSampleRequest http://www.geekhelp.cn/bmy/api/user/allUser
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
allUser() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.userServiceImpl.getAllUserService();
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
typedi_1.Inject(),
|
||||
__metadata("design:type", UserServiceImpl_1.UserServiceImpl)
|
||||
], UserControllerApi.prototype, "userServiceImpl", void 0);
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/oneUser"),
|
||||
routing_controllers_1.UseBefore(LogsMiddlewares_1.LogsMiddlewares),
|
||||
__param(0, routing_controllers_1.QueryParams()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [UserModel_1.UserModel]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserControllerApi.prototype, "oneUser", null);
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/allUser"),
|
||||
routing_controllers_1.UseBefore(LogsMiddlewares_1.LogsMiddlewares),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserControllerApi.prototype, "allUser", null);
|
||||
UserControllerApi = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.JsonController(`${config_1.config.apiurl}/user`),
|
||||
routing_controllers_1.UseInterceptor(JsonResponseMiddlewares_1.JsonResponseInterceptor)
|
||||
], UserControllerApi);
|
||||
exports.UserControllerApi = UserControllerApi;
|
||||
17
dist/controller/api/homeControllerApi.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const typedi_1 = require("typedi");
|
||||
let homeControllerApi = class homeControllerApi {
|
||||
};
|
||||
homeControllerApi = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.Controller()
|
||||
], homeControllerApi);
|
||||
exports.homeControllerApi = homeControllerApi;
|
||||
1
dist/controller/home/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
7187985f-096d-45fa-b2af-836bc0200513
|
||||
44
dist/controller/home/AboutControllerHome.js
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const utils_1 = require("../../utils/utils");
|
||||
let AboutControllerHome = class AboutControllerHome {
|
||||
About(session) {
|
||||
return {
|
||||
title: utils_1.utils.titleName("关于"),
|
||||
isShowAction: {
|
||||
header: true,
|
||||
footer: true
|
||||
},
|
||||
banner: {
|
||||
bannerTitle: '关于怪客',
|
||||
bannerUrl: '/img/banner_5.jpg',
|
||||
},
|
||||
login: session.user ? session.user : false
|
||||
};
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/about"),
|
||||
routing_controllers_1.Render("home/page/about"),
|
||||
__param(0, routing_controllers_1.Session()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AboutControllerHome.prototype, "About", null);
|
||||
AboutControllerHome = __decorate([
|
||||
routing_controllers_1.Controller()
|
||||
], AboutControllerHome);
|
||||
exports.AboutControllerHome = AboutControllerHome;
|
||||
35
dist/controller/home/ErrorControllerHome.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const utils_1 = require("../../utils/utils");
|
||||
let ErrorControllerHome = class ErrorControllerHome {
|
||||
Error() {
|
||||
return {
|
||||
title: utils_1.utils.titleName("404..."),
|
||||
isShowAction: {
|
||||
header: false,
|
||||
footer: false
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/error"),
|
||||
routing_controllers_1.Render("home/page/error"),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ErrorControllerHome.prototype, "Error", null);
|
||||
ErrorControllerHome = __decorate([
|
||||
routing_controllers_1.Controller()
|
||||
], ErrorControllerHome);
|
||||
exports.ErrorControllerHome = ErrorControllerHome;
|
||||
53
dist/controller/home/IndexControllerHome.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const utils_1 = require("../../utils/utils");
|
||||
const typedi_1 = require("typedi");
|
||||
let IndexControllerHome = class IndexControllerHome {
|
||||
Index(session) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return {
|
||||
title: utils_1.utils.titleName("首页"),
|
||||
isShowAction: {
|
||||
header: true,
|
||||
footer: true
|
||||
},
|
||||
login: session.user ? session.user : false
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/"),
|
||||
routing_controllers_1.Render("home/page/index"),
|
||||
__param(0, routing_controllers_1.Session()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], IndexControllerHome.prototype, "Index", null);
|
||||
IndexControllerHome = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.Controller()
|
||||
], IndexControllerHome);
|
||||
exports.IndexControllerHome = IndexControllerHome;
|
||||
17
dist/controller/home/TestControllerHome.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const typedi_1 = require("typedi");
|
||||
let TestControllerHome = class TestControllerHome {
|
||||
};
|
||||
TestControllerHome = __decorate([
|
||||
typedi_1.Service(),
|
||||
routing_controllers_1.Controller()
|
||||
], TestControllerHome);
|
||||
exports.TestControllerHome = TestControllerHome;
|
||||
56
dist/controller/home/UserActionController.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const routing_controllers_1 = require("routing-controllers");
|
||||
const utils_1 = require("../../utils/utils");
|
||||
let UserActionController = class UserActionController {
|
||||
reg(session, res) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!session || !session.user) {
|
||||
return {
|
||||
title: utils_1.utils.titleName("注册"),
|
||||
isShowAction: {
|
||||
header: false,
|
||||
footer: false
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
res.redirect('/error');
|
||||
return res;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
routing_controllers_1.Get("/register"),
|
||||
routing_controllers_1.Render("home/page/register"),
|
||||
__param(0, routing_controllers_1.Session()), __param(1, routing_controllers_1.Res()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserActionController.prototype, "reg", null);
|
||||
UserActionController = __decorate([
|
||||
routing_controllers_1.Controller()
|
||||
], UserActionController);
|
||||
exports.UserActionController = UserActionController;
|
||||
5
dist/controller/home/UserOperation.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class UserOperation {
|
||||
}
|
||||
exports.UserOperation = UserOperation;
|
||||
1
dist/dao/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
57ab335b-1140-4a98-977d-5aca05301cac
|
||||
42
dist/dao/UserDao.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typedi_1 = require("typedi");
|
||||
const UserEntity_1 = require("../entity/UserEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let UserDao = class UserDao {
|
||||
/**
|
||||
* 查询用户具体信息
|
||||
* @param id
|
||||
*/
|
||||
getOneUserDao(id) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield typeorm_1.getRepository(UserEntity_1.UserEntity)
|
||||
.findOne({ where: { user_id: id } });
|
||||
});
|
||||
}
|
||||
AllUser() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield typeorm_1.getRepository(UserEntity_1.UserEntity)
|
||||
.find();
|
||||
});
|
||||
}
|
||||
};
|
||||
UserDao = __decorate([
|
||||
typedi_1.Service()
|
||||
], UserDao);
|
||||
exports.UserDao = UserDao;
|
||||
15
dist/dao/testDao.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typedi_1 = require("typedi");
|
||||
let TestDao = class TestDao {
|
||||
};
|
||||
TestDao = __decorate([
|
||||
typedi_1.Service()
|
||||
], TestDao);
|
||||
exports.TestDao = TestDao;
|
||||
1
dist/entity/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
56ca8436-62b3-4234-a965-e67b67bfdc2a
|
||||
22
dist/entity/TestEntity.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typeorm_1 = require("typeorm");
|
||||
let TestEntity = class TestEntity {
|
||||
};
|
||||
__decorate([
|
||||
typeorm_1.PrimaryGeneratedColumn(),
|
||||
__metadata("design:type", Number)
|
||||
], TestEntity.prototype, "user_id", void 0);
|
||||
TestEntity = __decorate([
|
||||
typeorm_1.Entity("user")
|
||||
], TestEntity);
|
||||
exports.TestEntity = TestEntity;
|
||||
50
dist/entity/UserEntity.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typeorm_1 = require("typeorm");
|
||||
let UserEntity = class UserEntity {
|
||||
};
|
||||
__decorate([
|
||||
typeorm_1.PrimaryGeneratedColumn(),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "user_id", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_name", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_pwd", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_time", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_money", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_pic", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_address", void 0);
|
||||
__decorate([
|
||||
typeorm_1.Column(),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "user_phone", void 0);
|
||||
UserEntity = __decorate([
|
||||
typeorm_1.Entity("user")
|
||||
], UserEntity);
|
||||
exports.UserEntity = UserEntity;
|
||||
7
dist/index.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* 启动文件入口
|
||||
*/
|
||||
const app_1 = require("./run/app");
|
||||
new app_1.App();
|
||||
1
dist/middleware/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
05e72bdf-a9fa-4a35-b7f3-07070a0c3f9b
|
||||
16
dist/middleware/CheckLoginMiddleware.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* 判断用户是否登录,如果登录则继续访问,没有去登录
|
||||
*/
|
||||
class CheckLoginMiddleware {
|
||||
use(context, next) {
|
||||
if (!context.session || !context.session.user) {
|
||||
context.redirect(`/reg?from=${context.request.url}`);
|
||||
}
|
||||
else {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.CheckLoginMiddleware = CheckLoginMiddleware;
|
||||
34
dist/middleware/JsonResponseMiddlewares.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ResultDataMiddlewares_1 = require("./ResultDataMiddlewares");
|
||||
const typedi_1 = require("typedi");
|
||||
const logs_1 = require("../utils/logs");
|
||||
// 拦截controller在数据响应给前端,按照标准格式输出数据,同时session存储用户
|
||||
let JsonResponseInterceptor = class JsonResponseInterceptor {
|
||||
intercept(action, content) {
|
||||
if (content == undefined || content.length == 0) {
|
||||
logs_1.Logs.ApplicationLogger().error(action);
|
||||
return this.resultDataMiddlewares.error(action, "没有数据");
|
||||
}
|
||||
else if (content.length != 0) {
|
||||
return this.resultDataMiddlewares.success(content);
|
||||
}
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
typedi_1.Inject(),
|
||||
__metadata("design:type", ResultDataMiddlewares_1.ResultDataMiddlewares)
|
||||
], JsonResponseInterceptor.prototype, "resultDataMiddlewares", void 0);
|
||||
JsonResponseInterceptor = __decorate([
|
||||
typedi_1.Service()
|
||||
], JsonResponseInterceptor);
|
||||
exports.JsonResponseInterceptor = JsonResponseInterceptor;
|
||||
33
dist/middleware/LogsMiddlewares.js
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typedi_1 = require("typedi");
|
||||
const logs_1 = require("../utils/logs");
|
||||
const moment_1 = __importDefault(require("moment"));
|
||||
/**
|
||||
* controller 拦截器
|
||||
* 拦截 controller 被访问前,进行访问的日志记录
|
||||
*/
|
||||
let LogsMiddlewares = class LogsMiddlewares {
|
||||
use(context, next) {
|
||||
if (context.request.method == "GET") {
|
||||
logs_1.Logs.ApplicationLogger().warn(`${moment_1.default().format('YYYY-MM-DD HH:mm:ss')} ${context.request.ip} ${context.request.method} ${context.request.url} ${JSON.stringify(context.request.querystring)} ${JSON.stringify(context.request.header)} \n`);
|
||||
}
|
||||
else {
|
||||
logs_1.Logs.ApplicationLogger().warn(`${moment_1.default().format('YYYY-MM-DD HH:mm:ss')} ${context.request.ip} ${context.request.method} ${context.request.url} ${JSON.stringify(context.request.body)} ${JSON.stringify(context.request.header)} \n`);
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
||||
LogsMiddlewares = __decorate([
|
||||
typedi_1.Service()
|
||||
], LogsMiddlewares);
|
||||
exports.LogsMiddlewares = LogsMiddlewares;
|
||||
68
dist/middleware/ResultDataMiddlewares.js
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const typedi_1 = require("typedi");
|
||||
let ResultDataMiddlewares = class ResultDataMiddlewares {
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
set status(value) {
|
||||
this._status = value;
|
||||
}
|
||||
get data() {
|
||||
return this._data;
|
||||
}
|
||||
set data(value) {
|
||||
this._data = value;
|
||||
}
|
||||
get methods() {
|
||||
return this._methods;
|
||||
}
|
||||
set methods(value) {
|
||||
this._methods = value;
|
||||
}
|
||||
get url() {
|
||||
return this._url;
|
||||
}
|
||||
set url(value) {
|
||||
this._url = value;
|
||||
}
|
||||
/**
|
||||
* 数据请求成功
|
||||
* @param _data 需要返回给前端的数据
|
||||
*/
|
||||
success(_data) {
|
||||
this.status = 200;
|
||||
this.data = _data;
|
||||
return JSON.stringify({
|
||||
status: this.status,
|
||||
time: new Date(),
|
||||
result: this.data
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 数据请求失败
|
||||
* @param action 请求对象
|
||||
*/
|
||||
error(action, message) {
|
||||
this.status = action.response.status; // 状态码
|
||||
this.data = message; // 错误信息
|
||||
this.methods = action.request.method; // 请求方式
|
||||
this.url = action.request.url; // 请求地址
|
||||
return JSON.stringify({
|
||||
methods: this.methods,
|
||||
status: this.status,
|
||||
result: this.data,
|
||||
url: this.url
|
||||
});
|
||||
}
|
||||
};
|
||||
ResultDataMiddlewares = __decorate([
|
||||
typedi_1.Service()
|
||||
], ResultDataMiddlewares);
|
||||
exports.ResultDataMiddlewares = ResultDataMiddlewares;
|
||||
1
dist/model/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
62509948-3cb9-4cfd-b16c-6b716f2f10a7
|
||||
21
dist/model/TestModel.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const class_validator_1 = require("class-validator");
|
||||
class TestModel {
|
||||
}
|
||||
__decorate([
|
||||
class_validator_1.MinLength(1, {
|
||||
message: 'id参数必须有'
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], TestModel.prototype, "id", void 0);
|
||||
exports.TestModel = TestModel;
|
||||
21
dist/model/UserModel.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserModel {
|
||||
}
|
||||
__decorate([
|
||||
class_validator_1.MinLength(1, {
|
||||
message: 'id参数必须有'
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], UserModel.prototype, "id", void 0);
|
||||
exports.UserModel = UserModel;
|
||||
1
dist/plugins/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
e1d9fe15-2a0a-4008-8e49-4708275b0431
|
||||
67
dist/plugins/qiniu.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const qiniu_1 = __importDefault(require("qiniu"));
|
||||
const typedi_1 = require("typedi");
|
||||
const index_1 = require("../config/index");
|
||||
let QiNiu = class QiNiu {
|
||||
constructor() {
|
||||
this.FromBucket = index_1.config.qiniu.HLSconfig.FromBucket;
|
||||
this.ToBucket = index_1.config.qiniu.HLSconfig.ToBucket;
|
||||
this.VideoHlsParams = index_1.config.qiniu.HLSconfig.VideoHlsParams;
|
||||
this.accessKey = index_1.config.qiniu.accessKey;
|
||||
this.secretKey = index_1.config.qiniu.secretKey;
|
||||
this.mac = new qiniu_1.default.auth.digest.Mac(this.accessKey, this.secretKey);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param BucketName
|
||||
* @constructor
|
||||
*/
|
||||
GenerateToken(BucketName = "vrcource") {
|
||||
let putPolicy = new qiniu_1.default.rs.PutPolicy({
|
||||
scope: BucketName,
|
||||
expires: 7200
|
||||
});
|
||||
return putPolicy.uploadToken(this.mac);
|
||||
}
|
||||
/**
|
||||
* 根据前端传递的 filename 文件名,对需要的视频进行切片配置,
|
||||
* 返回给前端 token,前端拿到 token 后通过form data将视频和
|
||||
* token 传递给七牛,七牛会根据token开始切片任务。这里不需要
|
||||
* 配置七牛切片成功后的回调通知,因为已经可以通过基地址+m3u8文件名拿到
|
||||
* 切片后的地址
|
||||
* @param params
|
||||
* @constructor
|
||||
*/
|
||||
GenerateHlsToken(params) {
|
||||
let M3u8FileName = new Date().getTime();
|
||||
let saveHlsEntry = qiniu_1.default.util.urlsafeBase64Encode(`${this.ToBucket}:${M3u8FileName}`);
|
||||
const options = {
|
||||
scope: `${this.FromBucket}:${params['filename']}`,
|
||||
persistentOps: `${this.VideoHlsParams}${saveHlsEntry}`,
|
||||
persistentPipeline: 'guaikem3u8',
|
||||
};
|
||||
let putPolicy = new qiniu_1.default.rs.PutPolicy(options);
|
||||
return {
|
||||
filePath: `${index_1.config.qiniu.HLSconfig.VideoBaseUrl}${M3u8FileName}`,
|
||||
token: putPolicy.uploadToken(this.mac)
|
||||
};
|
||||
}
|
||||
};
|
||||
QiNiu = __decorate([
|
||||
typedi_1.Service(),
|
||||
__metadata("design:paramtypes", [])
|
||||
], QiNiu);
|
||||
exports.QiNiu = QiNiu;
|
||||
1
dist/resources/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
38915049-bd60-4d85-b3cc-1ae2601f8b2b
|
||||
1
dist/resources/static/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
365311b5-32c3-4360-939e-37b708a867d8
|
||||
1
dist/resources/static/css/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
170d6805-a0da-431b-a81c-9e6340f10c51
|
||||
0
dist/resources/static/css/base.css
vendored
Executable file
1
dist/resources/static/css/home/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b2b8dbcc-6779-4432-9b90-614361ec29bd
|
||||
3
dist/resources/static/css/home/about.css
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.about {
|
||||
color: red;
|
||||
}
|
||||
38
dist/resources/static/css/home/error.css
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
.error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: row;
|
||||
}
|
||||
.error img {
|
||||
width: 270px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.error .i-message {
|
||||
margin-left: 19px;
|
||||
}
|
||||
.error .i-message .action {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.error .i-message .action a[href="/"] {
|
||||
margin-right: 15px;
|
||||
}
|
||||
.error .i-message ul {
|
||||
padding-left: 20px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.error .i-message h3 {
|
||||
font-size: 17px;
|
||||
margin-bottom: 10px;
|
||||
line-height: 27px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
.error .i-message a {
|
||||
color: #8d8d8d;
|
||||
}
|
||||
body,
|
||||
html,
|
||||
.error {
|
||||
height: 100%;
|
||||
}
|
||||
0
dist/resources/static/css/home/index.css
vendored
Executable file
4
dist/resources/static/css/home/register.css
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.register {
|
||||
font-size: 30px;
|
||||
color: green;
|
||||
}
|
||||
3
dist/resources/static/css/home/test.css
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.Test {
|
||||
color: red;
|
||||
}
|
||||
1
dist/resources/static/css/tpl/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
01ac1c31-34b6-4927-9ea5-ac59aba566af
|
||||
0
dist/resources/static/css/tpl/colors.css
vendored
Executable file
0
dist/resources/static/css/tpl/mixins.css
vendored
Executable file
1
dist/resources/static/fonts/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
59158044-dfca-4e36-8cb9-881640318e07
|
||||
1
dist/resources/static/img/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
27366949-82a2-4b1e-996e-69b53b999cbd
|
||||
BIN
dist/resources/static/img/banner.png
vendored
Executable file
|
After Width: | Height: | Size: 340 KiB |
BIN
dist/resources/static/img/banner_1.png
vendored
Executable file
|
After Width: | Height: | Size: 232 KiB |
BIN
dist/resources/static/img/banner_2.png
vendored
Executable file
|
After Width: | Height: | Size: 492 KiB |
BIN
dist/resources/static/img/banner_3.png
vendored
Executable file
|
After Width: | Height: | Size: 492 KiB |
BIN
dist/resources/static/img/banner_4.jpg
vendored
Executable file
|
After Width: | Height: | Size: 142 KiB |
BIN
dist/resources/static/img/banner_5.jpg
vendored
Executable file
|
After Width: | Height: | Size: 200 KiB |
BIN
dist/resources/static/img/banner_6.jpg
vendored
Executable file
|
After Width: | Height: | Size: 123 KiB |
BIN
dist/resources/static/img/banner_7.png
vendored
Executable file
|
After Width: | Height: | Size: 96 KiB |
BIN
dist/resources/static/img/bgError.png
vendored
Executable file
|
After Width: | Height: | Size: 40 KiB |
BIN
dist/resources/static/img/discountbanner.png
vendored
Executable file
|
After Width: | Height: | Size: 108 KiB |
BIN
dist/resources/static/img/favicon.ico
vendored
Executable file
|
After Width: | Height: | Size: 40 KiB |
BIN
dist/resources/static/img/getbg.png
vendored
Executable file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
dist/resources/static/img/spjcdet_img1.png
vendored
Executable file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
dist/resources/static/img/spjcdet_img2.jpg
vendored
Executable file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
dist/resources/static/img/spjcdet_img3.png
vendored
Executable file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
dist/resources/static/img/spjcdet_img4.png
vendored
Executable file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
dist/resources/static/img/wx.png
vendored
Executable file
|
After Width: | Height: | Size: 114 KiB |
BIN
dist/resources/static/img/youh.png
vendored
Executable file
|
After Width: | Height: | Size: 3.9 KiB |
1
dist/resources/static/js/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
02011504-1fc5-4c66-9f5d-410cc1527d8f
|
||||
32
dist/resources/static/js/app.js
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
requirejs.config({ require.js
|
||||
baseUrl: '/js',
|
||||
waitSeconds: 0,
|
||||
paths: {
|
||||
app: 'app',
|
||||
jquery: 'lib/jquery.min',
|
||||
swiper: 'lib/swiper/swiper.min',
|
||||
zui: 'lib/zui/js/zui.min',
|
||||
utils: 'utils/index',
|
||||
config: 'config/index'
|
||||
},
|
||||
map: {
|
||||
'*': {
|
||||
'css': 'lib/css'
|
||||
}
|
||||
},
|
||||
shim : { // 按需加载css
|
||||
'app/index': { deps: ['css!/css/home/index.css','css!/js/lib/swiper/swiper.min.css'] },
|
||||
'app/about': { deps: ['css!/css/home/about.css'] },
|
||||
'app/register': { deps: ['css!/css/home/register.css'] }
|
||||
}
|
||||
});
|
||||
|
||||
// 读取每个页面自定义属性data-module获取js文件名,然后自动加载并调用非对应页面的js文件中的 init 方法
|
||||
requirejs(["jquery"],function ($) {
|
||||
var module = $('.pages').attr('data-module');
|
||||
if(module != undefined){
|
||||
requirejs([ `app/${ module }` ], function (module) {
|
||||
module.init();
|
||||
})
|
||||
}
|
||||
});
|
||||
1
dist/resources/static/js/app/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1db48167-07c0-46b2-a84c-beea2247a27e
|
||||
12
dist/resources/static/js/app/about.js
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
define(['jquery','utils'],function ($,utils) {
|
||||
function about() {
|
||||
|
||||
}
|
||||
|
||||
about.prototype = {
|
||||
init () {
|
||||
}
|
||||
};
|
||||
|
||||
return new about();
|
||||
});
|
||||
31
dist/resources/static/js/app/index.js
vendored
Executable file
@@ -0,0 +1,31 @@
|
||||
define(['jquery','swiper','utils', 'zui'],function ($,swiper,utils) {
|
||||
function Index() {
|
||||
|
||||
}
|
||||
|
||||
Index.prototype = {
|
||||
init () {
|
||||
new $.zui.Messager('zui弹窗。', {
|
||||
icon: 'heart',
|
||||
placement: 'center'
|
||||
}).show();
|
||||
},
|
||||
|
||||
|
||||
//初始化 swiper 轮播图
|
||||
newSwiper () {
|
||||
// new swiper ('.swiper-container', {
|
||||
// direction: 'horizontal',
|
||||
// loop: true,
|
||||
// autoplay: true,
|
||||
// pagination: {
|
||||
// el: '.swiper-pagination',
|
||||
// clickable :true,
|
||||
// }
|
||||
// });
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
return new Index();
|
||||
})
|
||||
14
dist/resources/static/js/app/register.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
define(['jquery','swiper','utils'],function ($,swiper,utils) {
|
||||
function Register() {
|
||||
|
||||
}
|
||||
|
||||
Register.prototype = {
|
||||
init () {
|
||||
console.log("用户注册")
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return new Register();
|
||||
});
|
||||
12
dist/resources/static/js/app/test.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
define(['jquery','utils'],function ($,utils) {
|
||||
function test() {
|
||||
|
||||
}
|
||||
|
||||
test.prototype = {
|
||||
init () {
|
||||
}
|
||||
};
|
||||
|
||||
return new test();
|
||||
});
|
||||
1
dist/resources/static/js/config/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ca35505f-8930-4df3-a682-0fd0d46d8672
|
||||
10
dist/resources/static/js/config/index.js
vendored
Executable file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* 网站前端的 config 配置文件
|
||||
*/
|
||||
define([], function () {
|
||||
return {
|
||||
|
||||
// 请求基地址
|
||||
baseURL: 'http://www.geekhelp.cn/bmy/api'
|
||||
}
|
||||
})
|
||||
1
dist/resources/static/js/lib/.pydio
vendored
Normal file
@@ -0,0 +1 @@
|
||||
4a41c117-dab4-467b-ac47-10e619694a1b
|
||||
169
dist/resources/static/js/lib/css.js
vendored
Executable file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Require-CSS RequireJS css! loader plugin
|
||||
* 0.1.10
|
||||
* Guy Bedford 2014
|
||||
* MIT
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Usage:
|
||||
* require(['css!./mycssFile']);
|
||||
*
|
||||
* Tested and working in (up to latest versions as of March 2013):
|
||||
* Android
|
||||
* iOS 6
|
||||
* IE 6 - 10
|
||||
* Chrome 3 - 26
|
||||
* Firefox 3.5 - 19
|
||||
* Opera 10 - 12
|
||||
*
|
||||
* browserling.com used for virtual testing environment
|
||||
*
|
||||
* Credit to B Cavalier & J Hann for the IE 6 - 9 method,
|
||||
* refined with help from Martin Cermak
|
||||
*
|
||||
* Sources that helped along the way:
|
||||
* - https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
|
||||
* - http://www.phpied.com/when-is-a-stylesheet-really-loaded/
|
||||
* - https://github.com/cujojs/curl/blob/master/src/curl/plugin/css.js
|
||||
*
|
||||
*/
|
||||
|
||||
define(function() {
|
||||
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
|
||||
if (typeof window == 'undefined')
|
||||
return { load: function(n, r, load){ load() } };
|
||||
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
|
||||
var engine = window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/) || 0;
|
||||
|
||||
// use <style> @import load method (IE < 9, Firefox < 18)
|
||||
var useImportLoad = false;
|
||||
|
||||
// set to false for explicit <link> load checking when onload doesn't work perfectly (webkit)
|
||||
var useOnload = true;
|
||||
|
||||
// trident / msie
|
||||
if (engine[1] || engine[7])
|
||||
useImportLoad = parseInt(engine[1]) < 6 || parseInt(engine[7]) <= 9;
|
||||
// webkit
|
||||
else if (engine[2] || engine[8] || 'WebkitAppearance' in document.documentElement.style)
|
||||
useOnload = false;
|
||||
// gecko
|
||||
else if (engine[4])
|
||||
useImportLoad = parseInt(engine[4]) < 18;
|
||||
|
||||
//>>excludeEnd('excludeRequireCss')
|
||||
//main api object
|
||||
var cssAPI = {};
|
||||
|
||||
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
|
||||
cssAPI.pluginBuilder = './css-builder';
|
||||
|
||||
// <style> @import load method
|
||||
var curStyle, curSheet;
|
||||
var createStyle = function () {
|
||||
curStyle = document.createElement('style');
|
||||
head.appendChild(curStyle);
|
||||
curSheet = curStyle.styleSheet || curStyle.sheet;
|
||||
}
|
||||
var ieCnt = 0;
|
||||
var ieLoads = [];
|
||||
var ieCurCallback;
|
||||
|
||||
var createIeLoad = function(url) {
|
||||
curSheet.addImport(url);
|
||||
curStyle.onload = function(){ processIeLoad() };
|
||||
|
||||
ieCnt++;
|
||||
if (ieCnt == 31) {
|
||||
createStyle();
|
||||
ieCnt = 0;
|
||||
}
|
||||
}
|
||||
var processIeLoad = function() {
|
||||
ieCurCallback();
|
||||
|
||||
var nextLoad = ieLoads.shift();
|
||||
|
||||
if (!nextLoad) {
|
||||
ieCurCallback = null;
|
||||
return;
|
||||
}
|
||||
|
||||
ieCurCallback = nextLoad[1];
|
||||
createIeLoad(nextLoad[0]);
|
||||
}
|
||||
var importLoad = function(url, callback) {
|
||||
if (!curSheet || !curSheet.addImport)
|
||||
createStyle();
|
||||
|
||||
if (curSheet && curSheet.addImport) {
|
||||
// old IE
|
||||
if (ieCurCallback) {
|
||||
ieLoads.push([url, callback]);
|
||||
}
|
||||
else {
|
||||
createIeLoad(url);
|
||||
ieCurCallback = callback;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// old Firefox
|
||||
curStyle.textContent = '@import "' + url + '";';
|
||||
|
||||
var loadInterval = setInterval(function() {
|
||||
try {
|
||||
curStyle.sheet.cssRules;
|
||||
clearInterval(loadInterval);
|
||||
callback();
|
||||
} catch(e) {}
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// <link> load method
|
||||
var linkLoad = function(url, callback) {
|
||||
var link = document.createElement('link');
|
||||
link.type = 'text/css';
|
||||
link.rel = 'stylesheet';
|
||||
if (useOnload)
|
||||
link.onload = function() {
|
||||
link.onload = function() {};
|
||||
// for style dimensions queries, a short delay can still be necessary
|
||||
setTimeout(callback, 7);
|
||||
}
|
||||
else
|
||||
var loadInterval = setInterval(function() {
|
||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||
var sheet = document.styleSheets[i];
|
||||
if (sheet.href == link.href) {
|
||||
clearInterval(loadInterval);
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
link.href = url;
|
||||
head.appendChild(link);
|
||||
}
|
||||
|
||||
//>>excludeEnd('excludeRequireCss')
|
||||
cssAPI.normalize = function(name, normalize) {
|
||||
if (name.substr(name.length - 4, 4) == '.css')
|
||||
name = name.substr(0, name.length - 4);
|
||||
|
||||
return normalize(name);
|
||||
}
|
||||
|
||||
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
|
||||
cssAPI.load = function(cssId, req, load, config) {
|
||||
|
||||
(useImportLoad ? importLoad : linkLoad)(req.toUrl(cssId + '.css'), load);
|
||||
|
||||
}
|
||||
|
||||
//>>excludeEnd('excludeRequireCss')
|
||||
return cssAPI;
|
||||
});
|
||||