Skip to content

Commit 482a14f

Browse files
author
caoli
committed
fix: import for typescript
1 parent 79c377c commit 482a14f

File tree

4 files changed

+134
-4
lines changed

4 files changed

+134
-4
lines changed

app/controller/app/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Controller } from "egg";
2-
const Model = require('../../mocks/article/list');
2+
import * as Model from '../../mocks/article/list';
33
export default class AppController extends Controller {
4-
54
async index() {
65
const { ctx } = this;
76
await ctx.render('app/app.js', { url: this.ctx.url.replace(/\/app/, '')});

app/controller/home/home.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller } from 'egg';
2-
const Model = require('../../mocks/article/list');
2+
import * as Model from '../../mocks/article/list';
33
export default class AppController extends Controller {
44
async index() {
55
const { ctx } = this;

app/mocks/article/list.ts

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
'use strict';
2+
const data = {
3+
list: [{
4+
id: 0,
5+
title: `Egg + React 服务端渲染骨架`,
6+
summary: '基于Egg + React + Webpack3/Webpack2 多页面和单页面服务器渲染同构工程骨架项目',
7+
hits: 550,
8+
url: 'https://github.com/hubcarl/egg-react-webpack-boilerplate'
9+
}, {
10+
id: 1,
11+
title: '前端工程化解决方案easywebpack',
12+
summary: 'programming instead of configuration, webpack is so easy',
13+
hits: 550,
14+
url: 'https://github.com/hubcarl/easywebpack'
15+
}, {
16+
id: 2,
17+
title: '前端工程化解决方案脚手架easywebpack-cli',
18+
summary: 'easywebpack command tool, support init Vue/Reac/Weex boilerplate',
19+
hits: 278,
20+
url: 'https://github.com/hubcarl/easywebpack-cli'
21+
}, {
22+
id: 3,
23+
title: 'react-渐进式JavaScript 框架',
24+
summary: '简单小巧的核心,渐进式技术栈,足以应付任何规模的应用',
25+
hits: 200,
26+
url: 'https://cn.reactjs.org'
27+
}, {
28+
id: 4,
29+
title: 'webpack配置官方文档',
30+
summary: 'webpack is a module bundler for modern JavaScript applications.',
31+
hits: 550,
32+
url: 'https://webpack.js.org/configuration/'
33+
}, {
34+
id: 5,
35+
title: 'egg-为企业级框架和应用而生',
36+
summary: 'Born to buildbetter enterprise frameworks and apps with Node.js & Koa',
37+
hits: 278,
38+
url: 'https://eggjs.org/'
39+
}, {
40+
id: 5,
41+
title: 'axios-基于 Promise 的 HTTP 请求客户端',
42+
summary: '基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用',
43+
hits: 998,
44+
url: 'https://www.awesomes.cn/repo/mzabriskie/axios'
45+
}, {
46+
id: 5,
47+
title: 'Centralized State Management for react.js',
48+
summary: 'reactx 是一个专为react.js 应用程序开发的状态管理模式',
49+
hits: 232,
50+
url: 'https://github.com/reactjs/reactx'
51+
}, {
52+
id: 5,
53+
title: 'react服务器渲染',
54+
summary: '服务器渲染可以加快首屏速度,利于SEO',
55+
hits: 565,
56+
url: 'http://csbun.github.io/blog/2016/08/react-2-0-server-side-rendering/'
57+
}, {
58+
id: 5,
59+
title: 'webpack服务器构建',
60+
summary: 'Webpack is an amazing tool.',
61+
hits: 988,
62+
url: 'http://jlongster.com/Backend-Apps-with-Webpack--Part-I'
63+
}, {
64+
id: 5,
65+
title: 'react component loader for Webpack',
66+
summary: 'Webpack loader for react.js components',
67+
hits: 322,
68+
url: 'https://github.com/reactjs/react-loader'
69+
}, {
70+
id: 5,
71+
title: 'react-router--The official router for react.js',
72+
summary: 'It deeply integrates with react.js core to make building Single Page Applications with react.js a breeze',
73+
hits: 566,
74+
url: 'https://github.com/reactjs/react-router'
75+
}, {
76+
id: 5,
77+
title: 'react生命周期',
78+
summary: 'react.js 生命周期和route的生命周期讲解',
79+
hits: 434,
80+
url: 'http://www.jianshu.com/p/e9f884b6ba6c'
81+
}, {
82+
id: 5,
83+
title: 'babel到底将代码转换成什么鸟样',
84+
summary: '将babel捧作前端一个划时代的工具一定也不为过,它的出现让许多程序员幸福地用上了es6新语法',
85+
hits: 432,
86+
url: 'https://github.com/lcxfs1991/blog/issues/9'
87+
}, {
88+
id: 5,
89+
title: 'HTTP2 的真正性能到底如何',
90+
summary: 'HTTP2 的真正性能到底如何',
91+
hits: 565,
92+
url: 'https://segmentfault.com/a/1190000007219256?utm_source=weekly&utm_medium=email&utm_campaign=email_weekly'
93+
}, {
94+
id: 5,
95+
title: 'HTTP,HTTP2.0,SPDY,HTTPS讲解',
96+
summary: '使用SPDY加快你的网站速度',
97+
hits: 787,
98+
url: 'http://www.alloyteam.com/2016/07/httphttp2-0spdyhttps-reading-this-is-enough/'
99+
}, {
100+
id: 5,
101+
title: 'git - 简明指南',
102+
summary: '助你入门 git 的简明指南',
103+
hits: 121,
104+
url: 'http://rogerdudler.github.io/git-guide/index.zh.html'
105+
}, {
106+
id: 5,
107+
title: 'react从1升级到2',
108+
summary: 'Migrating from v1 to v2',
109+
hits: 555,
110+
url: 'https://webpack.js.org/guides/migrating/'
111+
}]
112+
};
113+
114+
let id = 1;
115+
116+
data.list.forEach(item => {
117+
item.id = id++;
118+
});
119+
120+
121+
const total = data.list.length;
122+
export function getPage(pageIndex = 1, pageSize = 10) {
123+
const start = (pageIndex - 1) * pageSize;
124+
const end = start + Number(pageSize);
125+
return { list: data.list.slice(start, end), total };
126+
};
127+
export function getDetail(id) {
128+
return data.list.filter(item => {
129+
return item.id === id;
130+
}).slice(0, 1);
131+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egg-react-typescript-boilerplate",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "基于 egg + react + typescript + webpack 服务端渲染工程骨架项目",
55
"scripts": {
66
"tsc": "tsc -p tsconfig.json",

0 commit comments

Comments
 (0)