Authored by 陈峰

init

{
"presets": [
"es2015"
],
"plugins": [
"transform-runtime",
"transform-vue-jsx",
"transform-async-to-generator",
"transform-object-rest-spread",
"syntax-dynamic-import"
]
}
\ No newline at end of file
... ...
dist
node_modules
\ No newline at end of file
... ...
{
"parser": "babel-eslint",
"env": {
"es6": true
},
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"html"
],
"rules": {
"camelcase": "off",
"max-len": "off"
}
}
... ...
.DS_Store
.idea
node_modules/
*.log
.eslintcache
.stylelintcache
.vscode/
.happypack/
dist/
storage/
\ No newline at end of file
... ...
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=http://npm.yohops.com
\ No newline at end of file
... ...
10.3.0
\ No newline at end of file
... ...
// .stylelintignore
*.js
*.png
*.eot
*.ttf
*.woff
*.sh
*.json
*.sql
*.md
*.lock
node_modules
\ No newline at end of file
... ...
{
"extends": "stylelint-config-yoho",
"plugins": ["stylelint-scss"],
"rules": {
"string-quotes": "double",
"no-empty-source": null
}
}
... ...
const yo = require('yo-cli');
const path = require('path');
module.exports = yo()
.entry('./src/app.js')
.style({
preLoaders: {
scss: true
}
})
.resolve({
alias: {
'create-api': 'common/create-api',
config: 'common/config'
},
modules: [
path.join(__dirname, '../src'),
'node_modules'
]
})
.html({
filename: 'index.html',
template: 'index.html',
inject: true
})
.js({
babel: {
include: [
path.join(__dirname, '../src'),
]
}
})
.vue({
loaders: [
{
loader: 'iview-loader',
options: {
prefix: true
}
}
]
})
.merge({
optimization: {
splitChunks: {
chunks() {
return false;
},
cacheGroups: {
commons: {
chunks: 'initial',
name: 'vendors',
test: /node_modules/,
}
}
}
}
});
... ...
const yoBase = require('./yo.base.conf.js');
const yo = require('yo-cli');
module.exports = yo(yoBase)
.dev({
port: 8001,
host: '0.0.0.0',
hot: true,
proxy: {
'/api': 'http://localhost:8887'
}
})
.run();
... ...
const yoBase = require('./yo.base.conf.js');
const yo = require('yo-cli');
module.exports = yo(yoBase)
.output({
publicPath: '/'
})
.style({
extract: true
})
.sourceMap()
.run();
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<body>
<div id="app">
</div>
</body>
</html>
... ...
{
"name": "yoho-bi",
"version": "1.0.1",
"description": "",
"main": "app.js",
"scripts": {
"static": "yo-cli dev --config ./build/yo.dev.conf.js",
"build": "yo-cli build --config ./build/yo.prod.conf.js",
"lint-js": "lint-js",
"lint-css": "lint-css",
"precommit": "lint-commit",
"lint-all": "lint-all",
"lint-fix:js": "eslint . --ext .js --ext .vue --fix",
"lint-fix:css": "stylelint . --fix"
},
"config": {
"lintJs": [
{
"title": "JS Front-end",
"path": [
"./app"
]
},
{
"title": "JS Server",
"path": [
"./server"
]
}
],
"lintCss": [
{
"title": "CSS",
"path": [
"**/*.vue"
]
}
]
},
"dependencies": {
"axios": "^0.15.3",
"dayjs": "^1.5.16",
"font-awesome": "^4.7.0",
"lodash": "^4.17.4",
"vue": "^2.5.17",
"vue-echarts": "^3.0.9",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
"yo-cli": "^2.1.9"
},
"devDependencies": {
"autoprefixer-loader": "^3.2.0",
"babel-core": "^6.22.1",
"babel-eslint": "^8.2.6",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^5.1.0",
"eslint-config-standard": "^11.0.0",
"eslint-config-yoho": "^1.1.0",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^3.1.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^2.1.0",
"iview-loader": "^1.0.0",
"stylelint": "^8.0.0",
"stylelint-config-yoho": "^1.4.0",
"stylelint-formatter-table": "^1.0.3",
"stylelint-scss": "^3.1.0",
"vue-loader": "^15.4.2",
"yoho-lint": "^1.0.4"
},
"author": "陈峰 <feng.chen@yoho.cn>",
"license": "ISC",
"repository": "http://git.yoho.cn/fe/yoho-bi"
}
... ...
const postImport = require('postcss-import');
const autoprefixer = require('autoprefixer');
module.exports = {
plugins: [
postImport({}),
autoprefixer()
]
};
... ...
import Vue from 'vue';
import App from './app.vue';
import {createRouter} from './router';
const router = createRouter();
new Vue({
el: '#app',
router,
render: h => h(App)
});
... ...
<template>
<router-view></router-view>
</template>
<script>
export default {
name: 'App'
};
</script>
... ...
const config = {
axiosBaseUrl: '/api',
axiosResponseType: 'json'
};
export default config;
... ...
import axios from 'axios';
import config from 'config';
axios.defaults.baseURL = config.axiosBaseUrl;
axios.defaults.responseType = config.axiosResponseType;
axios.defaults.headers = {
'X-Requested-With': 'XMLHttpRequest'
};
const errHandle = ({response}) => {
let error = {
code: 500,
message: response.data && response.data.message || '接口异常'
};
if (response.status === 401) {
const {data} = response;
if (data) {
error = data;
}
}
return Promise.reject(error);
};
const request = async(options) => {
try {
return await axios(options).then(res => res.data, errHandle);
} catch ({message}) {
console.error(message);
return void 0;
}
};
export default {
async get(url, params, options) {
return await request(Object.assign({
url,
params,
method: 'get'
}), options);
},
async post(url, data, options) {
return await request(Object.assign({
url,
data,
method: 'post'
}, options));
}
};
... ...
<template>
<div class="home-page">
<div>
<p class="home-title">
Home
</p>
</div>
</div>
</template>
<script>
export default {
name: 'Home'
};
</script>
<style lang="scss">
</style>
... ...
export default {
path: '/',
name: 'home',
component: () => import(/* webpackChunkName: "home" */ './home')
};
... ...
import home from './home';
export default {
home,
};
... ...
import Vue from 'vue';
import Router from 'vue-router';
import pages from '../pages';
import _ from 'lodash/core';
Vue.use(Router);
const loadRoutes = (rous, paths, children) => {
if (_.has(rous, 'path')) {
let ps = _.flattenDeep(paths).filter(p => p);
if (_.last(ps) === rous.name) {
ps.splice(ps.length - 1, 1);
}
if (!children) {
if (rous.path) {
rous.path = ps.join('/') + (rous.path[0] === '/' ? '' : '/') + rous.path;
} else {
rous.path = ps.join('/') + '.html';
}
}
rous.name = _.concat(ps, [rous.name]).join('.');
if (rous.children) {
_.each(rous.children, child => loadRoutes(child, [paths, child.name], true));
return [rous];
}
return [rous];
}
if (rous.length) {
return _.map(rous, r => {
return loadRoutes(r, [paths]);
});
} else {
return _.map(rous, (rou, k) => {
return loadRoutes(rou, [paths, k]);
});
}
};
export function createRouter() {
const routes = _.flattenDeep(loadRoutes(pages));
const router = new Router({
mode: 'history',
routes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else {
return { x: 0, y: 0 };
}
}
});
return router;
}
... ...
This diff could not be displayed because it is too large.