Authored by 陈峰

init

  1 +{
  2 + "presets": [
  3 + "es2015"
  4 + ],
  5 + "plugins": [
  6 + "transform-runtime",
  7 + "transform-vue-jsx",
  8 + "transform-async-to-generator",
  9 + "transform-object-rest-spread",
  10 + "syntax-dynamic-import"
  11 + ]
  12 + }
  13 +
  1 +dist
  2 +node_modules
  1 +{
  2 + "parser": "babel-eslint",
  3 + "env": {
  4 + "es6": true
  5 + },
  6 + "parserOptions": {
  7 + "sourceType": "module"
  8 + },
  9 + "plugins": [
  10 + "html"
  11 + ],
  12 + "rules": {
  13 + "camelcase": "off",
  14 + "max-len": "off"
  15 + }
  16 +}
  1 +.DS_Store
  2 +.idea
  3 +node_modules/
  4 +
  5 +*.log
  6 +.eslintcache
  7 +.stylelintcache
  8 +.vscode/
  9 +.happypack/
  10 +dist/
  11 +storage/
  1 +sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
  2 +registry=http://npm.yohops.com
  1 +10.3.0
  1 +// .stylelintignore
  2 +*.js
  3 +*.png
  4 +*.eot
  5 +*.ttf
  6 +*.woff
  7 +*.sh
  8 +*.json
  9 +*.sql
  10 +*.md
  11 +*.lock
  12 +node_modules
  1 +{
  2 + "extends": "stylelint-config-yoho",
  3 + "plugins": ["stylelint-scss"],
  4 + "rules": {
  5 + "string-quotes": "double",
  6 + "no-empty-source": null
  7 + }
  8 +}
  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 + });
  1 +const yoBase = require('./yo.base.conf.js');
  2 +const yo = require('yo-cli');
  3 +
  4 +module.exports = yo(yoBase)
  5 + .dev({
  6 + port: 8001,
  7 + host: '0.0.0.0',
  8 + hot: true,
  9 + proxy: {
  10 + '/api': 'http://localhost:8887'
  11 + }
  12 + })
  13 + .run();
  1 +const yoBase = require('./yo.base.conf.js');
  2 +const yo = require('yo-cli');
  3 +
  4 +module.exports = yo(yoBase)
  5 + .output({
  6 + publicPath: '/'
  7 + })
  8 + .style({
  9 + extract: true
  10 + })
  11 + .sourceMap()
  12 + .run();
  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>
  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 +}
  1 +const postImport = require('postcss-import');
  2 +const autoprefixer = require('autoprefixer');
  3 +
  4 +module.exports = {
  5 + plugins: [
  6 + postImport({}),
  7 + autoprefixer()
  8 + ]
  9 +};
  1 +import Vue from 'vue';
  2 +import App from './app.vue';
  3 +import {createRouter} from './router';
  4 +
  5 +const router = createRouter();
  6 +
  7 +new Vue({
  8 + el: '#app',
  9 + router,
  10 + render: h => h(App)
  11 +});
  1 +<template>
  2 + <router-view></router-view>
  3 +</template>
  4 +
  5 +<script>
  6 +export default {
  7 + name: 'App'
  8 +};
  9 +</script>
  1 +const config = {
  2 + axiosBaseUrl: '/api',
  3 + axiosResponseType: 'json'
  4 +};
  5 +
  6 +export default config;
  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 +};
  1 +<template>
  2 + <div class="home-page">
  3 + <div>
  4 + <p class="home-title">
  5 + Home
  6 + </p>
  7 + </div>
  8 + </div>
  9 +</template>
  10 +
  11 +<script>
  12 +export default {
  13 + name: 'Home'
  14 +};
  15 +</script>
  16 +
  17 +<style lang="scss">
  18 +</style>
  1 +export default {
  2 + path: '/',
  3 + name: 'home',
  4 + component: () => import(/* webpackChunkName: "home" */ './home')
  5 +};
  1 +import home from './home';
  2 +
  3 +export default {
  4 + home,
  5 +};
  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 +}
This diff could not be displayed because it is too large.