Showing
23 changed files
with
407 additions
and
0 deletions
.babelrc
0 → 100644
.eslintignore
0 → 100644
.eslintrc
0 → 100644
.gitignore
0 → 100644
.npmrc
0 → 100644
.stylelintignore
0 → 100644
.stylelintrc
0 → 100644
build/yo.base.conf.js
0 → 100644
1 | +const yo = require('yo-cli'); | ||
2 | +const path = require('path'); | ||
3 | + | ||
4 | +module.exports = yo() | ||
5 | + .entry('./src/app.js') | ||
6 | + .style({ | ||
7 | + preLoaders: { | ||
8 | + scss: true | ||
9 | + } | ||
10 | + }) | ||
11 | + .resolve({ | ||
12 | + alias: { | ||
13 | + 'create-api': 'common/create-api', | ||
14 | + config: 'common/config' | ||
15 | + }, | ||
16 | + modules: [ | ||
17 | + path.join(__dirname, '../src'), | ||
18 | + 'node_modules' | ||
19 | + ] | ||
20 | + }) | ||
21 | + .html({ | ||
22 | + filename: 'index.html', | ||
23 | + template: 'index.html', | ||
24 | + inject: true | ||
25 | + }) | ||
26 | + .js({ | ||
27 | + babel: { | ||
28 | + include: [ | ||
29 | + path.join(__dirname, '../src'), | ||
30 | + ] | ||
31 | + } | ||
32 | + }) | ||
33 | + .vue({ | ||
34 | + loaders: [ | ||
35 | + { | ||
36 | + loader: 'iview-loader', | ||
37 | + options: { | ||
38 | + prefix: true | ||
39 | + } | ||
40 | + } | ||
41 | + ] | ||
42 | + }) | ||
43 | + .merge({ | ||
44 | + optimization: { | ||
45 | + splitChunks: { | ||
46 | + chunks() { | ||
47 | + return false; | ||
48 | + }, | ||
49 | + cacheGroups: { | ||
50 | + commons: { | ||
51 | + chunks: 'initial', | ||
52 | + name: 'vendors', | ||
53 | + test: /node_modules/, | ||
54 | + } | ||
55 | + } | ||
56 | + } | ||
57 | + } | ||
58 | + }); |
build/yo.dev.conf.js
0 → 100644
build/yo.prod.conf.js
0 → 100644
index.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="en"> | ||
3 | +<head> | ||
4 | + <meta charset="UTF-8"> | ||
5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
6 | + <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
7 | + <title></title> | ||
8 | +</head> | ||
9 | +<body> | ||
10 | + <div id="app"> | ||
11 | + </div> | ||
12 | +</body> | ||
13 | +</html> |
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "yoho-bi", | ||
3 | + "version": "1.0.1", | ||
4 | + "description": "", | ||
5 | + "main": "app.js", | ||
6 | + "scripts": { | ||
7 | + "static": "yo-cli dev --config ./build/yo.dev.conf.js", | ||
8 | + "build": "yo-cli build --config ./build/yo.prod.conf.js", | ||
9 | + "lint-js": "lint-js", | ||
10 | + "lint-css": "lint-css", | ||
11 | + "precommit": "lint-commit", | ||
12 | + "lint-all": "lint-all", | ||
13 | + "lint-fix:js": "eslint . --ext .js --ext .vue --fix", | ||
14 | + "lint-fix:css": "stylelint . --fix" | ||
15 | + }, | ||
16 | + "config": { | ||
17 | + "lintJs": [ | ||
18 | + { | ||
19 | + "title": "JS Front-end", | ||
20 | + "path": [ | ||
21 | + "./app" | ||
22 | + ] | ||
23 | + }, | ||
24 | + { | ||
25 | + "title": "JS Server", | ||
26 | + "path": [ | ||
27 | + "./server" | ||
28 | + ] | ||
29 | + } | ||
30 | + ], | ||
31 | + "lintCss": [ | ||
32 | + { | ||
33 | + "title": "CSS", | ||
34 | + "path": [ | ||
35 | + "**/*.vue" | ||
36 | + ] | ||
37 | + } | ||
38 | + ] | ||
39 | + }, | ||
40 | + "dependencies": { | ||
41 | + "axios": "^0.15.3", | ||
42 | + "dayjs": "^1.5.16", | ||
43 | + "font-awesome": "^4.7.0", | ||
44 | + "lodash": "^4.17.4", | ||
45 | + "vue": "^2.5.17", | ||
46 | + "vue-echarts": "^3.0.9", | ||
47 | + "vue-router": "^3.0.1", | ||
48 | + "vuex": "^3.0.1", | ||
49 | + "yo-cli": "^2.1.9" | ||
50 | + }, | ||
51 | + "devDependencies": { | ||
52 | + "autoprefixer-loader": "^3.2.0", | ||
53 | + "babel-core": "^6.22.1", | ||
54 | + "babel-eslint": "^8.2.6", | ||
55 | + "babel-plugin-syntax-jsx": "^6.18.0", | ||
56 | + "babel-preset-es2015": "^6.24.1", | ||
57 | + "eslint": "^5.1.0", | ||
58 | + "eslint-config-standard": "^11.0.0", | ||
59 | + "eslint-config-yoho": "^1.1.0", | ||
60 | + "eslint-friendly-formatter": "^2.0.7", | ||
61 | + "eslint-loader": "^1.9.0", | ||
62 | + "eslint-plugin-html": "^3.1.1", | ||
63 | + "eslint-plugin-import": "^2.7.0", | ||
64 | + "eslint-plugin-standard": "^3.0.1", | ||
65 | + "eslint-plugin-vue": "^2.1.0", | ||
66 | + "iview-loader": "^1.0.0", | ||
67 | + "stylelint": "^8.0.0", | ||
68 | + "stylelint-config-yoho": "^1.4.0", | ||
69 | + "stylelint-formatter-table": "^1.0.3", | ||
70 | + "stylelint-scss": "^3.1.0", | ||
71 | + "vue-loader": "^15.4.2", | ||
72 | + "yoho-lint": "^1.0.4" | ||
73 | + }, | ||
74 | + "author": "陈峰 <feng.chen@yoho.cn>", | ||
75 | + "license": "ISC", | ||
76 | + "repository": "http://git.yoho.cn/fe/yoho-bi" | ||
77 | +} |
postcss.config.js
0 → 100644
src/app.js
0 → 100644
src/app.vue
0 → 100644
src/common/config.js
0 → 100644
src/common/create-api.js
0 → 100644
1 | +import axios from 'axios'; | ||
2 | +import config from 'config'; | ||
3 | + | ||
4 | +axios.defaults.baseURL = config.axiosBaseUrl; | ||
5 | +axios.defaults.responseType = config.axiosResponseType; | ||
6 | +axios.defaults.headers = { | ||
7 | + 'X-Requested-With': 'XMLHttpRequest' | ||
8 | +}; | ||
9 | + | ||
10 | +const errHandle = ({response}) => { | ||
11 | + let error = { | ||
12 | + code: 500, | ||
13 | + message: response.data && response.data.message || '接口异常' | ||
14 | + }; | ||
15 | + | ||
16 | + if (response.status === 401) { | ||
17 | + const {data} = response; | ||
18 | + | ||
19 | + if (data) { | ||
20 | + error = data; | ||
21 | + } | ||
22 | + } | ||
23 | + return Promise.reject(error); | ||
24 | +}; | ||
25 | +const request = async(options) => { | ||
26 | + try { | ||
27 | + return await axios(options).then(res => res.data, errHandle); | ||
28 | + } catch ({message}) { | ||
29 | + console.error(message); | ||
30 | + return void 0; | ||
31 | + } | ||
32 | +}; | ||
33 | + | ||
34 | +export default { | ||
35 | + async get(url, params, options) { | ||
36 | + return await request(Object.assign({ | ||
37 | + url, | ||
38 | + params, | ||
39 | + method: 'get' | ||
40 | + }), options); | ||
41 | + }, | ||
42 | + async post(url, data, options) { | ||
43 | + return await request(Object.assign({ | ||
44 | + url, | ||
45 | + data, | ||
46 | + method: 'post' | ||
47 | + }, options)); | ||
48 | + } | ||
49 | +}; |
src/pages/home/home.vue
0 → 100644
src/pages/home/index.js
0 → 100644
src/router/index.js
0 → 100644
1 | +import Vue from 'vue'; | ||
2 | +import Router from 'vue-router'; | ||
3 | +import pages from '../pages'; | ||
4 | +import _ from 'lodash/core'; | ||
5 | + | ||
6 | +Vue.use(Router); | ||
7 | + | ||
8 | +const loadRoutes = (rous, paths, children) => { | ||
9 | + if (_.has(rous, 'path')) { | ||
10 | + let ps = _.flattenDeep(paths).filter(p => p); | ||
11 | + | ||
12 | + if (_.last(ps) === rous.name) { | ||
13 | + ps.splice(ps.length - 1, 1); | ||
14 | + } | ||
15 | + if (!children) { | ||
16 | + if (rous.path) { | ||
17 | + rous.path = ps.join('/') + (rous.path[0] === '/' ? '' : '/') + rous.path; | ||
18 | + } else { | ||
19 | + rous.path = ps.join('/') + '.html'; | ||
20 | + } | ||
21 | + } | ||
22 | + rous.name = _.concat(ps, [rous.name]).join('.'); | ||
23 | + | ||
24 | + if (rous.children) { | ||
25 | + _.each(rous.children, child => loadRoutes(child, [paths, child.name], true)); | ||
26 | + return [rous]; | ||
27 | + } | ||
28 | + return [rous]; | ||
29 | + } | ||
30 | + if (rous.length) { | ||
31 | + return _.map(rous, r => { | ||
32 | + return loadRoutes(r, [paths]); | ||
33 | + }); | ||
34 | + } else { | ||
35 | + return _.map(rous, (rou, k) => { | ||
36 | + return loadRoutes(rou, [paths, k]); | ||
37 | + }); | ||
38 | + } | ||
39 | +}; | ||
40 | + | ||
41 | +export function createRouter() { | ||
42 | + const routes = _.flattenDeep(loadRoutes(pages)); | ||
43 | + | ||
44 | + const router = new Router({ | ||
45 | + mode: 'history', | ||
46 | + routes, | ||
47 | + scrollBehavior(to, from, savedPosition) { | ||
48 | + if (savedPosition) { | ||
49 | + return savedPosition; | ||
50 | + } else { | ||
51 | + return { x: 0, y: 0 }; | ||
52 | + } | ||
53 | + } | ||
54 | + }); | ||
55 | + | ||
56 | + return router; | ||
57 | +} |
yarn.lock
0 → 100644
This diff could not be displayed because it is too large.
-
Please register or login to post a comment