zhangdechen 7 năm trước cách đây
commit
92d03ea753
66 tập tin đã thay đổi với 12381 bổ sung và 0 xóa
  1. 2 0
      .browserslistrc
  2. 5 0
      .editorconfig
  3. 3 0
      .env
  4. 4 0
      .env.development
  5. 3 0
      .env.production
  6. 17 0
      .eslintrc.js
  7. 21 0
      .gitignore
  8. 199 0
      README.md
  9. 17 0
      babel.config.js
  10. 115 0
      mock/article.js
  11. 71 0
      mock/index.js
  12. 68 0
      mock/mock-server.js
  13. 51 0
      mock/remote-search.js
  14. 98 0
      mock/role/index.js
  15. 525 0
      mock/role/routes.js
  16. 81 0
      mock/user.js
  17. 51 0
      package.json
  18. 11 0
      postcss.config.js
  19. BIN
      public/favicon.ico
  20. 25 0
      public/index.html
  21. 50 0
      src/App.vue
  22. 15 0
      src/api/article.js
  23. 24 0
      src/api/user.js
  24. BIN
      src/assets/logo.png
  25. 22 0
      src/components/FooterTabbar.vue
  26. 62 0
      src/components/SvgIcon.vue
  27. 52 0
      src/components/VerifyCodeBtn.vue
  28. 9 0
      src/icons/index.js
  29. 1 0
      src/icons/svg/404.svg
  30. 1 0
      src/icons/svg/dashboard.svg
  31. 1 0
      src/icons/svg/example.svg
  32. 1 0
      src/icons/svg/eye-open.svg
  33. 1 0
      src/icons/svg/eye.svg
  34. 1 0
      src/icons/svg/form.svg
  35. 1 0
      src/icons/svg/link.svg
  36. 1 0
      src/icons/svg/nested.svg
  37. 1 0
      src/icons/svg/password.svg
  38. 1 0
      src/icons/svg/table.svg
  39. 1 0
      src/icons/svg/tree.svg
  40. 1 0
      src/icons/svg/user.svg
  41. 22 0
      src/icons/svgo.yml
  42. 54 0
      src/main.js
  43. 12 0
      src/router/article.js
  44. 94 0
      src/router/index.js
  45. 22 0
      src/router/user.js
  46. 18 0
      src/settings.js
  47. 39 0
      src/store/index.js
  48. 31 0
      src/store/modules/test.js
  49. 87 0
      src/store/modules/user.js
  50. 208 0
      src/style/_mixin.scss
  51. 1 0
      src/style/_variables.scss
  52. 60 0
      src/style/common.scss
  53. 15 0
      src/utils/auth.js
  54. 10 0
      src/utils/get-page-title.js
  55. 34 0
      src/utils/index.js
  56. 48 0
      src/utils/permission.js
  57. 74 0
      src/utils/request.js
  58. 88 0
      src/utils/validate.js
  59. 82 0
      src/utils/vuex-loading.js
  60. 11 0
      src/views/404.vue
  61. 159 0
      src/views/Article.vue
  62. 144 0
      src/views/Home.vue
  63. 137 0
      src/views/user/Login.vue
  64. 13 0
      src/views/user/Register.vue
  65. 197 0
      vue.config.js
  66. 9108 0
      yarn.lock

+ 2 - 0
.browserslistrc

@@ -0,0 +1,2 @@
+> 1%
+last 2 versions

+ 5 - 0
.editorconfig

@@ -0,0 +1,5 @@
+[*.{js,jsx,ts,tsx,vue}]
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true

+ 3 - 0
.env

@@ -0,0 +1,3 @@
+NODE_ENV = 'development'
+BASE_URL = '/'
+VUE_APP_BASE_API = '/dev-api'

+ 4 - 0
.env.development

@@ -0,0 +1,4 @@
+VUE_CLI_BABEL_TRANSPILE_MODULES = true
+NODE_ENV = 'development'
+BASE_URL = '/'
+VUE_APP_BASE_API = '/dev-api'

+ 3 - 0
.env.production

@@ -0,0 +1,3 @@
+NODE_ENV = 'production'
+BASE_URL = './'
+VUE_APP_BASE_API = '/prod-api'

+ 17 - 0
.eslintrc.js

@@ -0,0 +1,17 @@
+module.exports = {
+  root: true,
+  env: {
+    node: true
+  },
+  'extends': [
+    'plugin:vue/essential',
+    '@vue/standard'
+  ],
+  rules: {
+    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
+    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
+  },
+  parserOptions: {
+    parser: 'babel-eslint'
+  }
+}

+ 21 - 0
.gitignore

@@ -0,0 +1,21 @@
+.DS_Store
+node_modules
+/dist
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 199 - 0
README.md

@@ -0,0 +1,199 @@
+# 基于vue+vant搭建H5通用架子
+
+### 项目初衷
+
+开发一个H5的通用架子,让前端同学开箱即用,迅速投入战斗。
+
+----
+
+项目源码跟线上预览地址在文章结尾处,记得查收哦~**
+
+### 主要功能
+1. 常用目录别名
+2. Vant/Rem适配
+3. scss支持、_mixin.scss、_variables.scss
+4. 页面切换动画+keepAlive
+5. 页面标题
+6. 自动注册:自动注册路由表/自动注册Vuex/svg图标引入
+7. mock server
+8. axios封装、api管理
+9. 用户鉴权
+10. vuex-loading
+11. vo-pages/dayjs/vconsole
+12. 生产环境优化
+
+### 常用目录别名
+![alias配置](http://img.cixi518.com/alias.png)
+### Vant/Rem适配
+按照Vant官网推荐自动按需引入组件,同样,Vant官网中也有对Rem适配的推荐配置,按照官网说明的使用。需要注意的是postcss的配置中,autoprefixer下的`browsers`需要替换成`overrideBrowserslist`,否则会有报错信息。具体如图<br>
+![postcss配置](http://img.cixi518.com/postcss.png)
+### scss支持、_mixin.scss、_variables.scss
+选择scss作为css预处理,并对mixin、variables、common.scss作全局引入。
+```js
+css: {
+    // 是否使用css分离插件 ExtractTextPlugin
+    extract: !!IS_PRODUCTION,
+    // 开启 CSS source maps?
+    sourceMap: false,
+    // css预设器配置项
+    // 启用 CSS modules for all css / pre-processor files.
+    modules: false,
+    loaderOptions: {
+      sass: {
+        data: '@import "style/_mixin.scss";@import "style/_variables.scss";@import "style/common.scss";' // 全局引入
+      }
+    }
+  }
+```
+### 页面切换动画+keepAlive
+利用vuex存取/更新页面切换方向,配合vue的transition做页面切换动画,router设置keepAlive判断页面是否需要缓冲。
+```js
+// vuex中
+state: {
+  direction: 'forward' // 页面切换方向
+},
+mutations: {
+  // 更新页面切换方向
+  updateDirection (state, direction) {
+    state.direction = direction
+  }
+},
+// App.vue
+<template>
+  <div id="app">
+    <transition :name="transitionName">
+      <keep-alive v-if="$route.meta.keepAlive">
+        <router-view class="router"></router-view>
+      </keep-alive>
+      <router-view class="router" v-else></router-view>
+    </transition>
+  </div>
+</template>
+```
+### 页面标题
+在vue-router页面配置中添加meta的title信息,配合`vue-router`的`beforeEach`注册一个前置守卫用户获取到页面配置的title
+```js
+// get-page-title.js
+import defaultSettings from '@/settings'
+
+const title = defaultSettings.title || 'H5Vue'
+
+export default function getPageTitle (pageTitle) {
+  if (pageTitle) {
+    return `${pageTitle} - ${title}`
+  }
+  return `${title}`
+}
+// permission.js
+router.beforeEach((to, from, next) => {
+  // set page title
+  document.title = getPageTitle(to.meta.title)
+}
+```
+### 自动注册
+
+先来了解一下`require.context()`:
+
+> 你可以通过 `require.context()` 函数来创建自己的 context。
+>
+> 可以给这个函数传入三个参数:一个要搜索的目录,一个标记表示是否还搜索其子目录, 以及一个匹配文件的正则表达式。
+>
+> webpack 会在构建中解析代码中的 `require.context()` 。
+
+上面的是官网原话,可能你跟我一样没太看懂,说白了,他可以用来导入模块。
+
+来看一下如何使用,我的router下的文件结构是这样的:<br>
+
+![router-tree](http://img.cixi518.com/router-tree.png)<br>
+```js
+// 利用require.context()自动引入article.js和user.js
+const routerContext = require.context('./', true, /\.js$/)
+routerContext.keys().forEach(route => {
+  // 如果是根目录的 index.js 、不处理
+  if (route.startsWith('./index')) {
+    return
+  }
+  const routerModule = routerContext(route)
+  /**
+   * 兼容 import export 和 require module.export 两种规范
+   */
+  routes = routes.concat(routerModule.default || routerModule)
+})
+```
+需要额外注意的是,404页面需要在自动引入后向路由数组concat上去,否则会提前匹配到404页面。
+
+对于vuex也同样引入,记得把引入的vuex按照文件名注册为对应的模块中。
+
+### mock server
+
+Mock server部分可直接参看[vue-element-admin](https://panjiachen.gitee.io/vue-element-admin-site/zh/guide/essentials/mock-api.html)的mock方案
+
+### axios封装
+
+axios部分,配置了baseUrl、超时时间,利用拦截器对header添加了用户的Token,方便下一步的用户鉴权,并对错误做了Toast提示。具体错误的code需要视各业务而定,本项目只做为示例参考。
+
+### 用户鉴权
+在`vue-router`的`beforeEach`中,添加用户鉴权功能。当用户登录后使用cookie持续化保存用户token,并赋值到vuex,后续可利用token获取用户信息。具体代码如下图:
+![permission](http://img.cixi518.com/permission.png)
+### vuex-loading
+在vuex3.1.0中对[vuex.subscribeAction](https://vuex.vuejs.org/zh/api/#subscribe)做了改动,使其拥有了before/after钩子函数。
+```js
+// subscribeAction官网示例
+store.subscribeAction({
+  before: (action, state) => {
+    console.log(`before action ${action.type}`)
+  },
+  after: (action, state) => {
+    console.log(`after action ${action.type}`)
+  }
+})
+```
+有了它,配合`vuex`的[插件](https://vuex.vuejs.org/zh/guide/plugins.html)功能,实现对应action的状态监听也不再是难题。
+
+[点击查看具体实现代码](https://github.com/Ljhhhhhh/h5vue/blob/master/src/utils/vuex-loading.js)
+
+> 参照自[vue 在移动端体验上的优化解决方案](https://juejin.im/post/5cdd2457f265da034e7eb2f9#heading-2)
+
+```vue
+// 使用方法
+computed: {
+  ...mapState({
+    loading: state => state['@@loading'].effects['test/onePlusAction']
+  })
+}
+// 其中 test对应的是vuex中的模块名,onePlusAction对应模块内的actions
+```
+具体效果:<br>![loading](http://img.cixi518.com/loading.gif)
+### 列表页(vo-pages的使用)
+
+列表页这里,使用了本人自己写的组件`vo-pages`,详细使用可查看[一款易用、高可定制的vue翻页组件](https://juejin.im/post/5d81da4551882556ba55e50e)
+
+实现效果:<br>
+![vo-pages](http://img.cixi518.com/Kapture%202019-10-27%20at%2013.36.21.gif)
+
+### 生产环境优化
+上线前,得优化一下资源了,该项目做了如下几步操作
+1. 通用库改用CDN
+2. 关闭sourcemap防止源码泄露
+3. 丑化html/css/js
+4. 生成gzip 
+5. 移除掉debugger/console
+6. 利用webpack-bundle-analyzer做资源分析,提供进一步优化的数据分析
+想对性能、资源了解更多的,推荐[Vue SPA 项目webpack打包优化指南](https://juejin.im/post/5bd2b60e6fb9a05d27794c5e)这篇文章。
+
+### 更多
+花了不少时间开发了这个项目,希望能提高您的H5开发效率。也欢迎大家跟我一起交流学习。
+
+### 相关链接
+* [源码地址](https://github.com/Ljhhhhhh/h5vue)
+* [在线预览](http://h5vue.cixi518.com)
+
+### 文章参考
+* [基于vue-cli3.0构建功能完善的移动端架子](https://juejin.im/post/5cbf32bc6fb9a03236393379)
+* [Vue SPA 项目webpack打包优化指南](https://juejin.im/post/5bd2b60e6fb9a05d27794c5e)
+* [vue 在移动端体验上的优化解决方案](https://juejin.im/post/5cdd2457f265da034e7eb2f9)
+* [vue-element-admin](https://panjiachen.gitee.io/vue-element-admin-site/zh/guide/)
+* [手摸手,带你优雅的使用 icon](https://juejin.im/post/59bb864b5188257e7a427c09)
+* [一款易用、高可定制的vue翻页组件](https://juejin.im/post/5d81da4551882556ba55e50e)
+
+

+ 17 - 0
babel.config.js

@@ -0,0 +1,17 @@
+module.exports = {
+  presets: [
+    '@vue/app'
+  ],
+  plugins: [
+    ['import', {
+      libraryName: 'vant',
+      libraryDirectory: 'es',
+      style: true
+    }, 'vant']
+  ]
+}
+/*
+'postcss-pxtorem': {
+      rootValue: 37.5,
+      propList: ['*']
+    } */

+ 115 - 0
mock/article.js

@@ -0,0 +1,115 @@
+import Mock from 'mockjs'
+
+const List = []
+const count = 20
+
+const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
+const imageUri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
+
+for (let i = 0; i < count; i++) {
+  List.push(Mock.mock({
+    id: '@increment',
+    timestamp: +Mock.Random.date('T'),
+    author: '@first',
+    reviewer: '@first',
+    title: '@title(5, 10)',
+    content_short: 'mock data',
+    content: baseContent,
+    forecast: '@float(0, 100, 2, 2)',
+    importance: '@integer(1, 3)',
+    'type|1': ['CN', 'US', 'JP', 'EU'],
+    'status|1': ['published', 'draft', 'deleted'],
+    display_time: '@datetime',
+    comment_disabled: true,
+    pageviews: '@integer(300, 5000)',
+    imageUri,
+    platforms: ['a-platform']
+  }))
+}
+
+export default [
+  {
+    url: '/article/list',
+    type: 'post',
+    response: config => {
+      const { importance, type, title, page = 1, pageSize = 20, sort } = config.body
+
+      let mockList = List.filter(item => {
+        if (importance && item.importance !== +importance) return false
+        if (type && item.type !== type) return false
+        if (title && item.title.indexOf(title) < 0) return false
+        return true
+      })
+
+      if (sort === '-id') {
+        mockList = mockList.reverse()
+      }
+
+      const pageList = mockList.filter((item, index) => index < pageSize * page && index >= pageSize * (page - 1))
+
+      return {
+        code: 200,
+        data: {
+          total: mockList.length,
+          items: pageList
+        }
+      }
+    }
+  },
+
+  {
+    url: '/article/detail',
+    type: 'get',
+    response: config => {
+      const { id } = config.query
+      for (const article of List) {
+        if (article.id === +id) {
+          return {
+            code: 200,
+            data: article
+          }
+        }
+      }
+    }
+  },
+
+  {
+    url: '/article/pv',
+    type: 'get',
+    response: _ => {
+      return {
+        code: 200,
+        data: {
+          pvData: [
+            { key: 'PC', pv: 1024 },
+            { key: 'mobile', pv: 1024 },
+            { key: 'ios', pv: 1024 },
+            { key: 'android', pv: 1024 }
+          ]
+        }
+      }
+    }
+  },
+
+  {
+    url: '/article/create',
+    type: 'post',
+    response: _ => {
+      return {
+        code: 200,
+        data: 'success'
+      }
+    }
+  },
+
+  {
+    url: '/article/update',
+    type: 'post',
+    response: _ => {
+      return {
+        code: 200,
+        data: 'success'
+      }
+    }
+  }
+]

+ 71 - 0
mock/index.js

@@ -0,0 +1,71 @@
+import Mock from 'mockjs'
+import { param2Obj } from '../src/utils'
+
+import user from './user'
+import role from './role'
+import article from './article'
+import search from './remote-search'
+
+const mocks = [
+  ...user,
+  ...role,
+  ...article,
+  ...search
+]
+
+// for front mock
+// please use it cautiously, it will redefine XMLHttpRequest,
+// which will cause many of your third-party libraries to be invalidated(like progress event).
+export function mockXHR () {
+  // mock patch
+  // https://github.com/nuysoft/Mock/issues/300
+  Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
+  Mock.XHR.prototype.send = function () {
+    if (this.custom.xhr) {
+      this.custom.xhr.withCredentials = this.withCredentials || false
+
+      if (this.responseType) {
+        this.custom.xhr.responseType = this.responseType
+      }
+    }
+    this.proxy_send(...arguments)
+  }
+
+  function XHR2ExpressReqWrap (respond) {
+    return function (options) {
+      let result = null
+      if (respond instanceof Function) {
+        const { body, type, url } = options
+        // https://expressjs.com/en/4x/api.html#req
+        result = respond({
+          method: type,
+          body: JSON.parse(body),
+          query: param2Obj(url)
+        })
+      } else {
+        result = respond
+      }
+      return Mock.mock(result)
+    }
+  }
+
+  for (const i of mocks) {
+    Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response))
+  }
+}
+
+// for mock server
+const responseFake = (url, type, respond) => {
+  return {
+    url: new RegExp(`/mock${url}`),
+    type: type || 'get',
+    response (req, res) {
+      res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
+    }
+  }
+}
+
+const d = mocks.map(route => {
+  return responseFake(route.url, route.type, route.response)
+})
+export default d

+ 68 - 0
mock/mock-server.js

@@ -0,0 +1,68 @@
+const chokidar = require('chokidar')
+const bodyParser = require('body-parser')
+const chalk = require('chalk')
+const path = require('path')
+
+const mockDir = path.join(process.cwd(), 'mock')
+
+function registerRoutes (app) {
+  let mockLastIndex
+  const { default: mocks } = require('./index.js')
+  for (const mock of mocks) {
+    app[mock.type](mock.url, mock.response)
+    mockLastIndex = app._router.stack.length
+  }
+  const mockRoutesLength = Object.keys(mocks).length
+  return {
+    mockRoutesLength: mockRoutesLength,
+    mockStartIndex: mockLastIndex - mockRoutesLength
+  }
+}
+
+function unregisterRoutes () {
+  Object.keys(require.cache).forEach(i => {
+    if (i.includes(mockDir)) {
+      delete require.cache[require.resolve(i)]
+    }
+  })
+}
+
+module.exports = app => {
+  // es6 polyfill
+  require('@babel/register')
+
+  // parse app.body
+  // https://expressjs.com/en/4x/api.html#req.body
+  app.use(bodyParser.json())
+  app.use(bodyParser.urlencoded({
+    extended: true
+  }))
+
+  const mockRoutes = registerRoutes(app)
+  var mockRoutesLength = mockRoutes.mockRoutesLength
+  var mockStartIndex = mockRoutes.mockStartIndex
+
+  // watch files, hot reload mock server
+  chokidar.watch(mockDir, {
+    ignored: /mock-server/,
+    ignoreInitial: true
+  }).on('all', (event, path) => {
+    if (event === 'change' || event === 'add') {
+      try {
+        // remove mock routes stack
+        app._router.stack.splice(mockStartIndex, mockRoutesLength)
+
+        // clear routes cache
+        unregisterRoutes()
+
+        const mockRoutes = registerRoutes(app)
+        mockRoutesLength = mockRoutes.mockRoutesLength
+        mockStartIndex = mockRoutes.mockStartIndex
+
+        console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed  ${path}`))
+      } catch (error) {
+        console.log(chalk.redBright(error))
+      }
+    }
+  })
+}

+ 51 - 0
mock/remote-search.js

@@ -0,0 +1,51 @@
+import Mock from 'mockjs'
+
+const NameList = []
+const count = 100
+
+for (let i = 0; i < count; i++) {
+  NameList.push(Mock.mock({
+    name: '@first'
+  }))
+}
+NameList.push({ name: 'mock-Pan' })
+
+export default [
+  // username search
+  {
+    url: '/search/user',
+    type: 'get',
+    response: config => {
+      const { name } = config.query
+      const mockNameList = NameList.filter(item => {
+        const lowerCaseName = item.name.toLowerCase()
+        return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
+      })
+      return {
+        code: 200,
+        data: { items: mockNameList }
+      }
+    }
+  },
+
+  // transaction list
+  {
+    url: '/transaction/list',
+    type: 'get',
+    response: _ => {
+      return {
+        code: 200,
+        data: {
+          total: 20,
+          'items|20': [{
+            order_no: '@guid()',
+            timestamp: +Mock.Random.date('T'),
+            username: '@name()',
+            price: '@float(1000, 15000, 0, 2)',
+            'status|1': ['success', 'pending']
+          }]
+        }
+      }
+    }
+  }
+]

+ 98 - 0
mock/role/index.js

@@ -0,0 +1,98 @@
+import Mock from 'mockjs'
+import { deepClone } from '../../src/utils/index.js'
+import { asyncRoutes, constantRoutes } from './routes.js'
+
+const routes = deepClone([...constantRoutes, ...asyncRoutes])
+
+const roles = [
+  {
+    key: 'admin',
+    name: 'admin',
+    description: 'Super Administrator. Have access to view all pages.',
+    routes: routes
+  },
+  {
+    key: 'editor',
+    name: 'editor',
+    description: 'Normal Editor. Can see all pages except permission page',
+    routes: routes.filter(i => i.path !== '/permission')// just a mock
+  },
+  {
+    key: 'visitor',
+    name: 'visitor',
+    description: 'Just a visitor. Can only see the home page and the document page',
+    routes: [{
+      path: '',
+      redirect: 'dashboard',
+      children: [
+        {
+          path: 'dashboard',
+          name: 'Dashboard',
+          meta: { title: 'dashboard', icon: 'dashboard' }
+        }
+      ]
+    }]
+  }
+]
+
+export default [
+  // mock get all routes form server
+  {
+    url: '/routes',
+    type: 'get',
+    response: _ => {
+      return {
+        code: 200,
+        data: routes
+      }
+    }
+  },
+
+  // mock get all roles form server
+  {
+    url: '/roles',
+    type: 'get',
+    response: _ => {
+      return {
+        code: 200,
+        data: roles
+      }
+    }
+  },
+
+  // add role
+  {
+    url: '/role',
+    type: 'post',
+    response: {
+      code: 200,
+      data: {
+        key: Mock.mock('@integer(300, 5000)')
+      }
+    }
+  },
+
+  // update role
+  {
+    url: '/role/[A-Za-z0-9]',
+    type: 'put',
+    response: {
+      code: 200,
+      data: {
+        status: 'success'
+      }
+    }
+  },
+
+  // delete role
+  {
+    url: '/role/[A-Za-z0-9]',
+    type: 'delete',
+    response: {
+      code: 200,
+      data: {
+        status: 'success'
+      }
+    }
+  }
+]

+ 525 - 0
mock/role/routes.js

@@ -0,0 +1,525 @@
+// Just a mock data
+
+export const constantRoutes = [
+  {
+    path: '/redirect',
+    component: 'layout/Layout',
+    hidden: true,
+    children: [
+      {
+        path: '/redirect/:path*',
+        component: 'views/redirect/index'
+      }
+    ]
+  },
+  {
+    path: '/login',
+    component: 'views/login/index',
+    hidden: true
+  },
+  {
+    path: '/auth-redirect',
+    component: 'views/login/auth-redirect',
+    hidden: true
+  },
+  {
+    path: '/404',
+    component: 'views/error-page/404',
+    hidden: true
+  },
+  {
+    path: '/401',
+    component: 'views/error-page/401',
+    hidden: true
+  },
+  {
+    path: '',
+    component: 'layout/Layout',
+    redirect: 'dashboard',
+    children: [
+      {
+        path: 'dashboard',
+        component: 'views/dashboard/index',
+        name: 'Dashboard',
+        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
+      }
+    ]
+  },
+  {
+    path: '/documentation',
+    component: 'layout/Layout',
+    children: [
+      {
+        path: 'index',
+        component: 'views/documentation/index',
+        name: 'Documentation',
+        meta: { title: 'Documentation', icon: 'documentation', affix: true }
+      }
+    ]
+  },
+  {
+    path: '/guide',
+    component: 'layout/Layout',
+    redirect: '/guide/index',
+    children: [
+      {
+        path: 'index',
+        component: 'views/guide/index',
+        name: 'Guide',
+        meta: { title: 'Guide', icon: 'guide', noCache: true }
+      }
+    ]
+  }
+]
+
+export const asyncRoutes = [
+  {
+    path: '/permission',
+    component: 'layout/Layout',
+    redirect: '/permission/index',
+    alwaysShow: true,
+    meta: {
+      title: 'Permission',
+      icon: 'lock',
+      roles: ['admin', 'editor']
+    },
+    children: [
+      {
+        path: 'page',
+        component: 'views/permission/page',
+        name: 'PagePermission',
+        meta: {
+          title: 'Page Permission',
+          roles: ['admin']
+        }
+      },
+      {
+        path: 'directive',
+        component: 'views/permission/directive',
+        name: 'DirectivePermission',
+        meta: {
+          title: 'Directive Permission'
+        }
+      },
+      {
+        path: 'role',
+        component: 'views/permission/role',
+        name: 'RolePermission',
+        meta: {
+          title: 'Role Permission',
+          roles: ['admin']
+        }
+      }
+    ]
+  },
+
+  {
+    path: '/icon',
+    component: 'layout/Layout',
+    children: [
+      {
+        path: 'index',
+        component: 'views/icons/index',
+        name: 'Icons',
+        meta: { title: 'Icons', icon: 'icon', noCache: true }
+      }
+    ]
+  },
+
+  {
+    path: '/components',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    name: 'ComponentDemo',
+    meta: {
+      title: 'Components',
+      icon: 'component'
+    },
+    children: [
+      {
+        path: 'tinymce',
+        component: 'views/components-demo/tinymce',
+        name: 'TinymceDemo',
+        meta: { title: 'Tinymce' }
+      },
+      {
+        path: 'markdown',
+        component: 'views/components-demo/markdown',
+        name: 'MarkdownDemo',
+        meta: { title: 'Markdown' }
+      },
+      {
+        path: 'json-editor',
+        component: 'views/components-demo/json-editor',
+        name: 'JsonEditorDemo',
+        meta: { title: 'Json Editor' }
+      },
+      {
+        path: 'split-pane',
+        component: 'views/components-demo/split-pane',
+        name: 'SplitpaneDemo',
+        meta: { title: 'SplitPane' }
+      },
+      {
+        path: 'avatar-upload',
+        component: 'views/components-demo/avatar-upload',
+        name: 'AvatarUploadDemo',
+        meta: { title: 'Avatar Upload' }
+      },
+      {
+        path: 'dropzone',
+        component: 'views/components-demo/dropzone',
+        name: 'DropzoneDemo',
+        meta: { title: 'Dropzone' }
+      },
+      {
+        path: 'sticky',
+        component: 'views/components-demo/sticky',
+        name: 'StickyDemo',
+        meta: { title: 'Sticky' }
+      },
+      {
+        path: 'count-to',
+        component: 'views/components-demo/count-to',
+        name: 'CountToDemo',
+        meta: { title: 'Count To' }
+      },
+      {
+        path: 'mixin',
+        component: 'views/components-demo/mixin',
+        name: 'ComponentMixinDemo',
+        meta: { title: 'componentMixin' }
+      },
+      {
+        path: 'back-to-top',
+        component: 'views/components-demo/back-to-top',
+        name: 'BackToTopDemo',
+        meta: { title: 'Back To Top' }
+      },
+      {
+        path: 'drag-dialog',
+        component: 'views/components-demo/drag-dialog',
+        name: 'DragDialogDemo',
+        meta: { title: 'Drag Dialog' }
+      },
+      {
+        path: 'drag-select',
+        component: 'views/components-demo/drag-select',
+        name: 'DragSelectDemo',
+        meta: { title: 'Drag Select' }
+      },
+      {
+        path: 'dnd-list',
+        component: 'views/components-demo/dnd-list',
+        name: 'DndListDemo',
+        meta: { title: 'Dnd List' }
+      },
+      {
+        path: 'drag-kanban',
+        component: 'views/components-demo/drag-kanban',
+        name: 'DragKanbanDemo',
+        meta: { title: 'Drag Kanban' }
+      }
+    ]
+  },
+  {
+    path: '/charts',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    name: 'Charts',
+    meta: {
+      title: 'Charts',
+      icon: 'chart'
+    },
+    children: [
+      {
+        path: 'keyboard',
+        component: 'views/charts/keyboard',
+        name: 'KeyboardChart',
+        meta: { title: 'Keyboard Chart', noCache: true }
+      },
+      {
+        path: 'line',
+        component: 'views/charts/line',
+        name: 'LineChart',
+        meta: { title: 'Line Chart', noCache: true }
+      },
+      {
+        path: 'mixchart',
+        component: 'views/charts/mixChart',
+        name: 'MixChart',
+        meta: { title: 'Mix Chart', noCache: true }
+      }
+    ]
+  },
+  {
+    path: '/nested',
+    component: 'layout/Layout',
+    redirect: '/nested/menu1/menu1-1',
+    name: 'Nested',
+    meta: {
+      title: 'Nested',
+      icon: 'nested'
+    },
+    children: [
+      {
+        path: 'menu1',
+        component: 'views/nested/menu1/index',
+        name: 'Menu1',
+        meta: { title: 'Menu1' },
+        redirect: '/nested/menu1/menu1-1',
+        children: [
+          {
+            path: 'menu1-1',
+            component: 'views/nested/menu1/menu1-1',
+            name: 'Menu1-1',
+            meta: { title: 'Menu1-1' }
+          },
+          {
+            path: 'menu1-2',
+            component: 'views/nested/menu1/menu1-2',
+            name: 'Menu1-2',
+            redirect: '/nested/menu1/menu1-2/menu1-2-1',
+            meta: { title: 'Menu1-2' },
+            children: [
+              {
+                path: 'menu1-2-1',
+                component: 'views/nested/menu1/menu1-2/menu1-2-1',
+                name: 'Menu1-2-1',
+                meta: { title: 'Menu1-2-1' }
+              },
+              {
+                path: 'menu1-2-2',
+                component: 'views/nested/menu1/menu1-2/menu1-2-2',
+                name: 'Menu1-2-2',
+                meta: { title: 'Menu1-2-2' }
+              }
+            ]
+          },
+          {
+            path: 'menu1-3',
+            component: 'views/nested/menu1/menu1-3',
+            name: 'Menu1-3',
+            meta: { title: 'Menu1-3' }
+          }
+        ]
+      },
+      {
+        path: 'menu2',
+        name: 'Menu2',
+        component: 'views/nested/menu2/index',
+        meta: { title: 'Menu2' }
+      }
+    ]
+  },
+
+  {
+    path: '/example',
+    component: 'layout/Layout',
+    redirect: '/example/list',
+    name: 'Example',
+    meta: {
+      title: 'Example',
+      icon: 'example'
+    },
+    children: [
+      {
+        path: 'create',
+        component: 'views/example/create',
+        name: 'CreateArticle',
+        meta: { title: 'Create Article', icon: 'edit' }
+      },
+      {
+        path: 'edit/:id(\\d+)',
+        component: 'views/example/edit',
+        name: 'EditArticle',
+        meta: { title: 'Edit Article', noCache: true },
+        hidden: true
+      },
+      {
+        path: 'list',
+        component: 'views/example/list',
+        name: 'ArticleList',
+        meta: { title: 'Article List', icon: 'list' }
+      }
+    ]
+  },
+
+  {
+    path: '/tab',
+    component: 'layout/Layout',
+    children: [
+      {
+        path: 'index',
+        component: 'views/tab/index',
+        name: 'Tab',
+        meta: { title: 'Tab', icon: 'tab' }
+      }
+    ]
+  },
+
+  {
+    path: '/error',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    name: 'ErrorPages',
+    meta: {
+      title: 'Error Pages',
+      icon: '404'
+    },
+    children: [
+      {
+        path: '401',
+        component: 'views/error-page/401',
+        name: 'Page401',
+        meta: { title: 'Page 401', noCache: true }
+      },
+      {
+        path: '404',
+        component: 'views/error-page/404',
+        name: 'Page404',
+        meta: { title: 'Page 404', noCache: true }
+      }
+    ]
+  },
+
+  {
+    path: '/error-log',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    children: [
+      {
+        path: 'log',
+        component: 'views/error-log/index',
+        name: 'ErrorLog',
+        meta: { title: 'Error Log', icon: 'bug' }
+      }
+    ]
+  },
+
+  {
+    path: '/excel',
+    component: 'layout/Layout',
+    redirect: '/excel/export-excel',
+    name: 'Excel',
+    meta: {
+      title: 'Excel',
+      icon: 'excel'
+    },
+    children: [
+      {
+        path: 'export-excel',
+        component: 'views/excel/export-excel',
+        name: 'ExportExcel',
+        meta: { title: 'Export Excel' }
+      },
+      {
+        path: 'export-selected-excel',
+        component: 'views/excel/select-excel',
+        name: 'SelectExcel',
+        meta: { title: 'Select Excel' }
+      },
+      {
+        path: 'export-merge-header',
+        component: 'views/excel/merge-header',
+        name: 'MergeHeader',
+        meta: { title: 'Merge Header' }
+      },
+      {
+        path: 'upload-excel',
+        component: 'views/excel/upload-excel',
+        name: 'UploadExcel',
+        meta: { title: 'Upload Excel' }
+      }
+    ]
+  },
+
+  {
+    path: '/zip',
+    component: 'layout/Layout',
+    redirect: '/zip/download',
+    alwaysShow: true,
+    meta: { title: 'Zip', icon: 'zip' },
+    children: [
+      {
+        path: 'download',
+        component: 'views/zip/index',
+        name: 'ExportZip',
+        meta: { title: 'Export Zip' }
+      }
+    ]
+  },
+
+  {
+    path: '/pdf',
+    component: 'layout/Layout',
+    redirect: '/pdf/index',
+    children: [
+      {
+        path: 'index',
+        component: 'views/pdf/index',
+        name: 'PDF',
+        meta: { title: 'PDF', icon: 'pdf' }
+      }
+    ]
+  },
+  {
+    path: '/pdf/download',
+    component: 'views/pdf/download',
+    hidden: true
+  },
+
+  {
+    path: '/theme',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    children: [
+      {
+        path: 'index',
+        component: 'views/theme/index',
+        name: 'Theme',
+        meta: { title: 'Theme', icon: 'theme' }
+      }
+    ]
+  },
+
+  {
+    path: '/clipboard',
+    component: 'layout/Layout',
+    redirect: 'noRedirect',
+    children: [
+      {
+        path: 'index',
+        component: 'views/clipboard/index',
+        name: 'ClipboardDemo',
+        meta: { title: 'Clipboard Demo', icon: 'clipboard' }
+      }
+    ]
+  },
+
+  {
+    path: '/i18n',
+    component: 'layout/Layout',
+    children: [
+      {
+        path: 'index',
+        component: 'views/i18n-demo/index',
+        name: 'I18n',
+        meta: { title: 'I18n', icon: 'international' }
+      }
+    ]
+  },
+
+  {
+    path: 'external-link',
+    component: 'layout/Layout',
+    children: [
+      {
+        path: 'https://github.com/PanJiaChen/vue-element-admin',
+        meta: { title: 'External Link', icon: 'link' }
+      }
+    ]
+  },
+
+  { path: '*', redirect: '/404', hidden: true }
+]

+ 81 - 0
mock/user.js

@@ -0,0 +1,81 @@
+
+const tokens = {
+  '13216698987': 'admin-token',
+  '123456': 'editor-token'
+}
+
+const users = {
+  'admin-token': {
+    roles: ['admin'],
+    introduction: 'I am a super administrator',
+    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
+    name: 'Super Admin'
+  },
+  'editor-token': {
+    roles: ['editor'],
+    introduction: 'I am an editor',
+    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
+    name: 'Normal Editor'
+  }
+}
+
+export default [
+  // user login
+  {
+    url: '/user/login',
+    type: 'post',
+    response: config => {
+      const { phoneNumber } = config.body
+      const token = tokens[phoneNumber]
+
+      // mock error
+      if (!token) {
+        return {
+          code: 60204,
+          message: 'Account and password are incorrect.'
+        }
+      }
+
+      return {
+        code: 200,
+        data: token
+      }
+    }
+  },
+
+  // get user info
+  {
+    // eslint-disable-next-line
+    url: '/user/info\.*',
+    type: 'get',
+    response: config => {
+      const { token } = config.query
+      const info = users[token]
+
+      // mock error
+      if (!info) {
+        return {
+          code: 50008,
+          message: 'Login failed, unable to get user details.'
+        }
+      }
+
+      return {
+        code: 200,
+        data: info
+      }
+    }
+  },
+
+  // user logout
+  {
+    url: '/user/logout',
+    type: 'post',
+    response: _ => {
+      return {
+        code: 200,
+        data: 'success'
+      }
+    }
+  }
+]

+ 51 - 0
package.json

@@ -0,0 +1,51 @@
+{
+  "name": "vue-cli-h5",
+  "version": "0.1.0",
+  "private": true,
+  "scripts": {
+    "serve": "vue-cli-service serve",
+    "build": "vue-cli-service build",
+    "lint": "vue-cli-service lint",
+    "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"
+  },
+  "dependencies": {
+    "axios": "^0.19.0",
+    "core-js": "2.6.5",
+    "dayjs": "^1.8.16",
+    "fastclick": "^1.0.6",
+    "js-cookie": "^2.2.1",
+    "lib-flexible": "^0.3.2",
+    "vant": "^2.2.5",
+    "vo-pages": "^1.0.8",
+    "vue": "^2.6.10",
+    "vue-router": "^3.0.3",
+    "vuex": "3.1.0"
+  },
+  "devDependencies": {
+    "@babel/register": "^7.6.2",
+    "@vue/cli-plugin-babel": "^3.11.0",
+    "@vue/cli-plugin-eslint": "^3.11.0",
+    "@vue/cli-service": "^3.11.0",
+    "@vue/eslint-config-standard": "^4.0.0",
+    "amfe-flexible": "^2.2.1",
+    "babel-eslint": "^10.0.1",
+    "babel-plugin-import": "^1.12.2",
+    "body-parser": "^1.19.0",
+    "chalk": "^2.4.2",
+    "chokidar": "^3.2.1",
+    "compression-webpack-plugin": "^3.0.0",
+    "eslint": "^5.16.0",
+    "eslint-plugin-vue": "^5.0.0",
+    "mockjs": "^1.0.1-beta3",
+    "postcss-pxtorem": "^4.0.1",
+    "sass": "^1.18.0",
+    "sass-loader": "^7.1.0",
+    "script-ext-html-webpack-plugin": "^2.1.4",
+    "svg-sprite-loader": "^4.1.6",
+    "svgo": "^1.3.0",
+    "uglifyjs-webpack-plugin": "^2.2.0",
+    "vconsole": "^3.3.4",
+    "vue-template-compiler": "^2.6.10",
+    "webpack-bundle-analyzer": "^3.5.2"
+  }
+}

+ 11 - 0
postcss.config.js

@@ -0,0 +1,11 @@
+module.exports = {
+  plugins: {
+    autoprefixer: {
+      overrideBrowserslist: ['Android >= 4.0', 'iOS >= 7']
+    },
+    'postcss-pxtorem': {
+      rootValue: 37.5,
+      propList: ['*']
+    }
+  }
+}

BIN
public/favicon.ico


+ 25 - 0
public/index.html

@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
+    <% if (process.env.NODE_ENV === 'production') { %> <% for(var css of
+      htmlWebpackPlugin.options.cdn.css) { %>
+      <link href="<%=css%>" rel="preload" as="style" />
+      <link rel="stylesheet" href="<%=css%>" as="style" />
+      <% } %> <% for(var js of htmlWebpackPlugin.options.cdn.js) { %>
+      <link href="<%=js%>" rel="preload" as="script" />
+      <script src="<%=js%>"></script>
+      <% } %> <% } %>
+    <title>H5Vue</title>
+  </head>
+  <body>
+    <noscript>
+      <strong>We're sorry but H5Vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
+    </noscript>
+    <div id="app"></div>
+    <!-- built files will be auto injected -->
+  </body>
+</html>

+ 50 - 0
src/App.vue

@@ -0,0 +1,50 @@
+<template>
+  <div id="app">
+    <transition :name="transitionName">
+      <keep-alive v-if="$route.meta.keepAlive">
+        <router-view class="router"></router-view>
+      </keep-alive>
+      <router-view class="router" v-else></router-view>
+    </transition>
+  </div>
+</template>
+<script>
+import defaultSetting from './settings'
+export default {
+  name: 'app',
+  computed: {
+    transitionName () {
+      if (defaultSetting.needPageTrans) {
+        return this.$store.state.direction
+      }
+      return ''
+    }
+  }
+}
+</script>
+
+<style lang="scss">
+#app {
+  font-family: "Avenir", Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  color: #2c3e50;
+  width: 100%;
+  height: 100%;
+  position: relative;
+}
+
+.router {
+  width: 100%;
+  height: 100%;
+  position: absolute;
+  overflow-x: hidden;
+  overflow-y: auto;
+  -webkit-overflow-scrolling: touch;
+  top: 0;
+  right: 0;
+  bottom: 0;
+  left: 0;
+  // background-color: #fff;
+}
+</style>

+ 15 - 0
src/api/article.js

@@ -0,0 +1,15 @@
+import request from '@/utils/request'
+
+export function fetchList (query) {
+  const { pageSize = 10, page = 1, ...rest } = query || {}
+  return request({
+    url: '/article/list',
+    method: 'post',
+    data: {
+      pageSize,
+      page,
+      ...rest
+    },
+    showLoading: false
+  })
+}

+ 24 - 0
src/api/user.js

@@ -0,0 +1,24 @@
+import request from '@/utils/request'
+
+export function login (data) {
+  return request({
+    url: '/user/login',
+    method: 'post',
+    data
+  })
+}
+
+export function getInfo (token) {
+  return request({
+    url: '/user/info',
+    method: 'get',
+    params: { token }
+  })
+}
+
+export function logout () {
+  return request({
+    url: '/user/logout',
+    method: 'post'
+  })
+}

BIN
src/assets/logo.png


+ 22 - 0
src/components/FooterTabbar.vue

@@ -0,0 +1,22 @@
+<template>
+  <van-tabbar route
+              :safe-area-inset-bottom="true">
+    <van-tabbar-item icon="home-o"
+                     replace
+                     to="/">首页</van-tabbar-item>
+    <van-tabbar-item icon="orders-o"
+                     replace
+                     to="/article">文章</van-tabbar-item>
+  </van-tabbar>
+
+</template>
+<script>
+import { Tabbar, TabbarItem } from 'vant'
+export default {
+  name: 'FooterTabbar',
+  components: {
+    [Tabbar.name]: Tabbar,
+    [TabbarItem.name]: TabbarItem
+  }
+}
+</script>

+ 62 - 0
src/components/SvgIcon.vue

@@ -0,0 +1,62 @@
+<template>
+  <div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" />
+  <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
+    <use :xlink:href="iconName" />
+  </svg>
+</template>
+
+<script>
+// doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
+import { isExternal } from '@/utils/validate'
+
+export default {
+  name: 'SvgIcon',
+  props: {
+    iconClass: {
+      type: String,
+      required: true
+    },
+    className: {
+      type: String,
+      default: ''
+    }
+  },
+  computed: {
+    isExternal () {
+      return isExternal(this.iconClass)
+    },
+    iconName () {
+      return `#icon-${this.iconClass}`
+    },
+    svgClass () {
+      if (this.className) {
+        return 'svg-icon ' + this.className
+      } else {
+        return 'svg-icon'
+      }
+    },
+    styleExternalIcon () {
+      return {
+        mask: `url(${this.iconClass}) no-repeat 50% 50%`,
+        '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
+      }
+    }
+  }
+}
+</script>
+
+<style scoped>
+.svg-icon {
+  width: 1em;
+  height: 1em;
+  vertical-align: -0.15em;
+  fill: currentColor;
+  overflow: hidden;
+}
+
+.svg-external-icon {
+  background-color: currentColor;
+  mask-size: cover!important;
+  display: inline-block;
+}
+</style>

+ 52 - 0
src/components/VerifyCodeBtn.vue

@@ -0,0 +1,52 @@
+<template>
+  <van-button class="verify-btn"
+              @click="btnClick"
+              size="mini"
+              type="primary"
+              :disabled="!!codeRestTime">
+    {{codeRestTime ? `${codeRestTime}S` : '发送验证码'}}
+  </van-button>
+</template>
+<script>
+import { Button } from 'vant'
+export default {
+  name: 'VerifyCodeBtn',
+  components: {
+    [Button.name]: Button
+  },
+  props: {
+    btnMsg: {
+      type: String,
+      default: '发送验证码'
+    },
+    restTime: {
+      type: Number,
+      default: 30
+    }
+  },
+  data () {
+    return {
+      codeRestTime: 0
+    }
+  },
+  methods: {
+    btnClick () {
+      this.codeRestTime = this.restTime
+      let timer = setInterval(() => {
+        --this.codeRestTime
+        if (!this.codeRestTime) {
+          clearInterval(timer)
+          timer = null
+        }
+      }, 1000)
+      this.$emit('sendVerifyCode')
+    }
+  }
+}
+</script>
+<style lang="scss" scoped>
+.verify-btn{
+    padding: 0 5px;
+    min-width: 6.5em;
+  }
+</style>

+ 9 - 0
src/icons/index.js

@@ -0,0 +1,9 @@
+import Vue from 'vue'
+import SvgIcon from '@/components/SvgIcon'// svg component
+
+// register globally
+Vue.component('svg-icon', SvgIcon)
+
+const req = require.context('./svg', false, /\.svg$/)
+const requireAll = requireContext => requireContext.keys().map(requireContext)
+requireAll(req)

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/404.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/dashboard.svg


+ 1 - 0
src/icons/svg/example.svg

@@ -0,0 +1 @@
+<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg"><path d="M96.258 57.462h31.421C124.794 27.323 100.426 2.956 70.287.07v31.422a32.856 32.856 0 0125.971 25.97zm-38.796-25.97V.07C27.323 2.956 2.956 27.323.07 57.462h31.422a32.856 32.856 0 0125.97-25.97zm12.825 64.766v31.421c30.46-2.885 54.507-27.253 57.713-57.712H96.579c-2.886 13.466-13.146 23.726-26.292 26.291zM31.492 70.287H.07c2.886 30.46 27.253 54.507 57.713 57.713V96.579c-13.466-2.886-23.726-13.146-26.291-26.292z"/></svg>

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/eye-open.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/eye.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/form.svg


+ 1 - 0
src/icons/svg/link.svg

@@ -0,0 +1 @@
+<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg"><path d="M115.625 127.937H.063V12.375h57.781v12.374H12.438v90.813h90.813V70.156h12.374z"/><path d="M116.426 2.821l8.753 8.753-56.734 56.734-8.753-8.745z"/><path d="M127.893 37.982h-12.375V12.375H88.706V0h39.187z"/></svg>

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/nested.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/password.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/table.svg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
src/icons/svg/tree.svg


+ 1 - 0
src/icons/svg/user.svg

@@ -0,0 +1 @@
+<svg width="130" height="130" xmlns="http://www.w3.org/2000/svg"><path d="M63.444 64.996c20.633 0 37.359-14.308 37.359-31.953 0-17.649-16.726-31.952-37.359-31.952-20.631 0-37.36 14.303-37.358 31.952 0 17.645 16.727 31.953 37.359 31.953zM80.57 75.65H49.434c-26.652 0-48.26 18.477-48.26 41.27v2.664c0 9.316 21.608 9.325 48.26 9.325H80.57c26.649 0 48.256-.344 48.256-9.325v-2.663c0-22.794-21.605-41.271-48.256-41.271z" stroke="#979797"/></svg>

+ 22 - 0
src/icons/svgo.yml

@@ -0,0 +1,22 @@
+# replace default config
+
+# multipass: true
+# full: true
+
+plugins:
+
+  # - name
+  #
+  # or:
+  # - name: false
+  # - name: true
+  #
+  # or:
+  # - name:
+  #     param1: 1
+  #     param2: 2
+
+- removeAttrs:
+    attrs:
+      - 'fill'
+      - 'fill-rule'

+ 54 - 0
src/main.js

@@ -0,0 +1,54 @@
+import Vue from 'vue'
+import 'lib-flexible'
+import App from './App.vue'
+import router from '@/router'
+import store from '@/store'
+import FastClick from 'fastclick'
+import 'utils/permission'
+import SvgIcon from 'components/SvgIcon'
+import '@/icons' // icon
+import '@/style/common.scss'
+import { Lazyload } from 'vant'
+import defaultSettings from '@/settings'
+import * as Sentry from '@sentry/browser'
+import * as Integrations from '@sentry/integrations'
+
+/**
+ * If you don't want to use mock-server
+ * you want to use MockJs for mock api
+ * you can execute: mockXHR()
+ *
+ * Currently MockJs will be used in the production environment,
+ * please remove it before going online! ! !
+ */
+import { mockXHR } from '../mock'
+
+Sentry.init({
+  dsn: 'https://8754d430a56949cda312695f5586b2df@sentry.io/1800421',
+  integrations: [new Integrations.Vue({ Vue, attachProps: true })]
+})
+if (process.env.NODE_ENV === 'production') {
+  mockXHR()
+}
+
+FastClick.attach(document.body)
+
+// options 为可选参数,无则不传
+Vue.use(Lazyload)
+
+Vue.component('svg-icon', SvgIcon)
+
+if (process.env.NODE_ENV === 'development' && defaultSettings.vconsole) {
+  const VConsole = require('vconsole')
+  // eslint-disable-next-line
+  const my_console = new VConsole()
+}
+// var vConsole = new VConsole(option)
+
+Vue.config.productionTip = false
+
+new Vue({
+  router,
+  store,
+  render: h => h(App)
+}).$mount('#app')

+ 12 - 0
src/router/article.js

@@ -0,0 +1,12 @@
+export default [
+  {
+    path: '/article',
+    name: 'article',
+    component: () => import(/* webpackChunkName: "article" */ 'views/Article.vue'),
+    meta: {
+      auth: true,
+      title: '文章',
+      keepAlive: true
+    }
+  }
+]

+ 94 - 0
src/router/index.js

@@ -0,0 +1,94 @@
+import Vue from 'vue'
+import Router from 'vue-router'
+import Home from 'views/Home.vue'
+import store from '@/store'
+
+Vue.use(Router)
+
+let routes = [
+  {
+    path: '/',
+    name: 'home',
+    component: Home,
+    meta: {
+      title: '首页',
+      keepAlive: true
+    }
+  },
+  {
+    path: '/404',
+    name: '404',
+    component: () => import(/* webpackChunkName: "404" */ 'views/404.vue'),
+    meta: {
+      title: '404',
+      keepAlive: true
+    }
+  }
+]
+
+const routerContext = require.context('./', true, /\.js$/)
+routerContext.keys().forEach(route => {
+  // 如果是根目录的 index.js 、不处理
+  if (route.startsWith('./index')) {
+    return
+  }
+  const routerModule = routerContext(route)
+  /**
+   * 兼容 import export 和 require module.export 两种规范
+   */
+  routes = routes.concat(routerModule.default || routerModule)
+})
+
+routes = routes.concat({
+  path: '*',
+  redirect: '/404'
+})
+
+const createRouter = () => new Router({
+  mode: 'history', // require service support
+  base: process.env.BASE_URL,
+  scrollBehavior: () => ({ y: 0 }),
+  routes
+})
+
+const myRouter = createRouter()
+
+// const myRouter = new Router({
+//   mode: 'history',
+//   base: process.env.BASE_URL,
+//   routes
+// })
+
+const history = window.sessionStorage
+history.clear()
+let historyCount = history.getItem('count') * 1 || 0
+history.setItem('/', 0)
+
+myRouter.beforeEach((to, from, next) => {
+  if (to.params.direction) {
+    store.commit('updateDirection', to.params.direction)
+  } else {
+    const toIndex = history.getItem(to.path)
+    const fromIndex = history.getItem(from.path)
+    // 判断并记录跳转页面是否访问过,以此判断跳转过渡方式
+    if (toIndex) {
+      if (!fromIndex || parseInt(toIndex, 10) > parseInt(fromIndex, 10) || (toIndex === '0' && fromIndex === '0')) {
+        store.commit('updateDirection', 'forward')
+      } else {
+        store.commit('updateDirection', 'back')
+      }
+    } else {
+      ++historyCount
+      history.setItem('count', historyCount)
+      to.path !== '/' && history.setItem(to.path, historyCount)
+      store.commit('updateDirection', 'forward')
+    }
+  }
+  next()
+})
+
+export function resetRouter () {
+  myRouter.replace('/login')
+}
+
+export default myRouter

+ 22 - 0
src/router/user.js

@@ -0,0 +1,22 @@
+export default [
+  {
+    path: '/login',
+    name: 'login',
+    component: () => import(/* webpackChunkName: "login" */ 'views/user/Login.vue'),
+    meta: {
+      title: '登录'
+      // auth: true,
+      // keepAlive: true
+    }
+  },
+  {
+    path: '/register',
+    name: 'register',
+    component: () => import(/* webpackChunkName: "register" */ 'views/user/Register.vue'),
+    meta: {
+      title: '注册'
+      // auth: true,
+      // keepAlive: true
+    }
+  }
+]

+ 18 - 0
src/settings.js

@@ -0,0 +1,18 @@
+module.exports = {
+
+  title: 'H5Vue',
+
+  /**
+   * @type {boolean} true | false
+   * @description Whether fix the header
+   */
+  fixedHeader: false,
+  vconsole: true,
+  needPageTrans: true,
+
+  /**
+   * @type {boolean} true | false
+   * @description Whether show the logo in sidebar
+   */
+  sidebarLogo: false
+}

+ 39 - 0
src/store/index.js

@@ -0,0 +1,39 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+import createLoadingPlugin from 'utils/vuex-loading'
+
+Vue.use(Vuex)
+
+const files = require.context('./modules', false, /\.js$/)
+const modules = {}
+
+files.keys().forEach(key => {
+  modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
+})
+
+export default new Vuex.Store({
+  plugins: [createLoadingPlugin()],
+  state: {
+    direction: 'forward' // 页面切换方向
+  },
+  getters: {
+    userData (state, getters) {
+      return state.user.user
+      // return getters['user/user']
+    }
+    // vuex 全局getters引入局部
+    // token () {
+    //   return store.getters['user/token']
+    // }
+  },
+  mutations: {
+    // 更新页面切换方向
+    updateDirection (state, direction) {
+      state.direction = direction
+    }
+  },
+  actions: {
+
+  },
+  modules
+})

+ 31 - 0
src/store/modules/test.js

@@ -0,0 +1,31 @@
+const state = {
+  number: 1
+}
+const actions = {
+  onePlusAsync: ({ commit }, { val }) => {
+    // commit('setLoading', true, { root: true }) // 调用全局vuex的setLoading方法
+    // 需要使用promise用来配合loading
+    return new Promise((resolve, reject) => {
+      setTimeout(() => {
+        commit('onePlus', val)
+        resolve()
+      // commit('setLoading', false, { root: true })
+      }, 1500)
+    })
+  }
+}
+const mutations = {
+  onePlus (state, val = 1) {
+    state.number = state.number + val
+  }
+}
+const getters = {
+
+}
+export default {
+  namespaced: true,
+  state,
+  actions,
+  mutations,
+  getters
+}

+ 87 - 0
src/store/modules/user.js

@@ -0,0 +1,87 @@
+import { login, getInfo } from 'api/user'
+import { Toast } from 'vant'
+import { getToken, setToken, removeToken } from '@/utils/auth'
+import { resetRouter } from '@/router'
+// import router from '@/router'
+
+const LOGIN = 'LOGIN'// 获取用户信息
+const SetUserData = 'SetUserData'// 获取用户信息
+const LOGOUT = 'LOGOUT'// 退出登录、清除用户数据
+const USER_DATA = 'userDate'// 用户数据
+
+export default {
+  namespaced: true,
+  state: {
+    token: getToken() || '',
+    user: JSON.parse(localStorage.getItem(USER_DATA) || null)
+  },
+  mutations: {
+
+    [LOGIN] (state, data) {
+      let userToken = data.data
+      state.token = userToken
+      setToken(userToken)
+    },
+
+    [SetUserData] (state, userData = {}) {
+      state.user = userData
+      localStorage.setItem(USER_DATA, JSON.stringify(userData))
+    },
+    [LOGOUT] (state) {
+      state.user = null
+      state.token = null
+      removeToken()
+      localStorage.removeItem(USER_DATA)
+      resetRouter()
+    }
+
+  },
+  actions: {
+    async login (state, data) {
+      try {
+        let res = await login({
+          phoneNumber: data.phoneNumber,
+          password: data.password
+        })
+        state.commit(LOGIN, res)
+        Toast({
+          message: '登录成功',
+          position: 'middle',
+          duration: 1500
+        })
+        setTimeout(() => {
+          const redirect = data.$route.query.redirect || '/'
+          data.$router.replace({
+            path: redirect
+          })
+        }, 1500)
+      } catch (error) {
+      }
+    },
+    // get user info
+    getInfo ({ commit, state }) {
+      return new Promise((resolve, reject) => {
+        getInfo(state.token).then(response => {
+          const { data } = response
+
+          if (!data) {
+            // eslint-disable-next-line
+            reject('Verification failed, please Login again.')
+          }
+          commit(SetUserData, data)
+          resolve(data)
+        }).catch(error => {
+          reject(error)
+        })
+      })
+    }
+  },
+  getters: {
+    token (state) {
+      return state.token
+    },
+    user (state) {
+      return state.user
+    }
+  }
+}

+ 208 - 0
src/style/_mixin.scss

@@ -0,0 +1,208 @@
+@mixin center($width: null, $height: null) {
+    position: absolute;
+    top: 50%;
+    left: 50%;
+
+    @if not $width and not $height {
+        transform: translate(-50%, -50%);
+    }
+
+    @else if $width and $height {
+        width: $width;
+        height: $height;
+        margin: -($height / 2) #{0 0} -($width / 2);
+    }
+
+    @else if not $height {
+        width: $width;
+        margin-left: -($width / 2);
+        transform: translateY(-50%);
+    }
+
+    @else {
+        height: $height;
+        margin-top: -($height / 2);
+        transform: translateX(-50%);
+    }
+}
+
+
+
+@mixin opacity($opacity) {
+    opacity: $opacity;
+    $opacity-ie: $opacity * 100;
+    filter: alpha(opacity=$opacity-ie);
+}
+
+@mixin ell() {
+    //
+    overflow: hidden;
+    -ms-text-overflow: ellipsis;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+}
+
+//多行超出省略号
+@mixin ell2() {
+    word-break: break-all;
+    text-overflow: ellipsis;
+    display: -webkit-box;
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 2;
+    overflow: hidden;
+}
+
+//.arrow{
+// @include arrow(bottom,10px,#F00);
+//
+@mixin arrow($direction, $size, $color) {
+    width: 0;
+    height: 0;
+    line-height: 0;
+    font-size: 0;
+    overflow: hidden;
+    border-width: $size;
+    cursor: pointer;
+
+    @if $direction==top {
+        border-style: dashed dashed solid dashed;
+        border-color: transparent transparent $color transparent;
+        border-top: none;
+    }
+
+    @else if $direction==bottom {
+        border-style: solid dashed dashed dashed;
+        border-color: $color transparent transparent transparent;
+        border-bottom: none;
+    }
+
+    @else if $direction==right {
+        border-style: dashed dashed dashed solid;
+        border-color: transparent transparent transparent $color;
+        border-right: none;
+    }
+
+    @else if $direction==left {
+        border-style: dashed solid dashed dashed;
+        border-color: transparent $color transparent transparent;
+        border-left: none;
+    }
+}
+
+// clearfix 
+@mixin clr {
+    &:after {
+        clear: both;
+        content: '.';
+        display: block;
+        height: 0;
+        line-height: 0;
+        overflow: hidden;
+    }
+
+    *height: 1%;
+}
+
+/*渐变(从上到下)*/
+@mixin linear-gradient($direction:bottom, $color1:transparent, $color2:#306eff, $color3:transparent) {
+    //background: -webkit-linear-gradient($direction,$colorTop, $colorCenter, $colorBottom); /* Safari 5.1 - 6.0 */
+    background: -o-linear-gradient($direction, $color1, $color2, $color3);
+    /* Opera 11.1 - 12.0 */
+    background: -moz-linear-gradient($direction, $color1, $color2, $color3);
+    /* Firefox 3.6 - 15 */
+    background: linear-gradient(to $direction, $color1, $color2, $color3);
+    /* 标准的语法 */
+
+}
+
+/* 行高 */
+@mixin line-height($height:30px, $line-height:30px) {
+    @if ($height !=null) {
+        height: $height;
+    }
+
+    @if ($line-height !=null) {
+        line-height: $line-height;
+    }
+}
+
+/* 定义滚动条样式 圆角和阴影不需要则传入null */
+@mixin scrollBar($width:10px, $height:10px, $outColor:$bgColor, $innerColor:$bgGrey, $radius:5px, $shadow:null) {
+
+    /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
+    &::-webkit-scrollbar {
+        width: $width;
+        height: $height;
+        background-color: $outColor;
+    }
+
+    /*定义滚动条轨道 内阴影+圆角*/
+    &::-webkit-scrollbar-track {
+        @if ($shadow !=null) {
+            -webkit-box-shadow: $shadow;
+        }
+
+        @if ($radius !=null) {
+            border-radius: $radius;
+        }
+
+        background-color: $outColor;
+    }
+
+    /*定义滑块 内阴影+圆角*/
+    &::-webkit-scrollbar-thumb {
+        @if ($shadow !=null) {
+            -webkit-box-shadow: $shadow;
+        }
+
+        @if ($radius !=null) {
+            border-radius: $radius;
+        }
+
+        background-color: $innerColor;
+        border: 1px solid $innerColor;
+    }
+}
+
+/* css3动画 默认3s宽度到200px */
+@mixin animation($from:(width:0px), $to:(width:200px), $name:mymove, $animate:mymove 2s 1 linear infinite) {
+    -webkit-animation: $animate;
+    -o-animation: $animate;
+    animation: $animate;
+
+    @keyframes #{$name} {
+        from {
+
+            @each $key,
+            $value in $from {
+                #{$key}: #{$value};
+            }
+        }
+
+        to {
+
+            @each $key,
+            $value in $to {
+                #{$key}: #{$value};
+            }
+        }
+    }
+
+    @-webkit-keyframes #{$name} {
+        from {
+
+            @each $key,
+            $value in $from {
+                $key: $value;
+            }
+        }
+
+        to {
+
+            @each $key,
+            $value in $to {
+                $key: $value;
+            }
+        }
+    }
+}

+ 1 - 0
src/style/_variables.scss

@@ -0,0 +1 @@
+$tabbarHeight: 50px;

+ 60 - 0
src/style/common.scss

@@ -0,0 +1,60 @@
+html,
+body {
+  width: 100%;
+  height: 100%;
+  overflow-x: hidden;
+  overflow-y: auto;
+  -webkit-overflow-scrolling: touch;
+}
+
+.clearfix:after {
+  display: block;
+  clear: both;
+  content: '';
+  visibility: hidden;
+  height: 0;
+}
+input,
+button,
+select,
+textarea {
+  outline: none;
+}
+
+/* page change */
+$--transition-time: 300ms;
+.back-enter-active,
+.back-leave-active,
+.forward-enter-active,
+.forward-leave-active {
+  will-change: transform;
+  transition: transform $--transition-time;
+  position: absolute;
+  height: 100%;
+  backface-visibility: hidden;
+  perspective: 1000;
+}
+.back-enter {
+  opacity: 0.75;
+  transform: translate3d(-50%, 0, 0) !important;
+}
+.back-enter-active {
+  z-index: -1 !important;
+  transition: transform $--transition-time;
+}
+.back-leave-active {
+  transform: translate3d(100%, 0, 0) !important;
+  transition: transform $--transition-time;
+}
+.forward-enter {
+  transform: translate3d(100%, 0, 0) !important;
+}
+.forward-enter-active {
+  transition: transform $--transition-time;
+}
+.forward-leave-active {
+  z-index: -1;
+  opacity: 0.65;
+  transform: translate3d(-50%, 0, 0) !important;
+  transition: transform $--transition-time;
+}

+ 15 - 0
src/utils/auth.js

@@ -0,0 +1,15 @@
+import Cookies from 'js-cookie'
+
+const TokenKey = 'h5-vue-cli_token'
+
+export function getToken () {
+  return Cookies.get(TokenKey)
+}
+
+export function setToken (token) {
+  return Cookies.set(TokenKey, token)
+}
+
+export function removeToken () {
+  return Cookies.remove(TokenKey)
+}

+ 10 - 0
src/utils/get-page-title.js

@@ -0,0 +1,10 @@
+import defaultSettings from '@/settings'
+
+const title = defaultSettings.title || 'H5Vue'
+
+export default function getPageTitle (pageTitle) {
+  if (pageTitle) {
+    return `${pageTitle} - ${title}`
+  }
+  return `${title}`
+}

+ 34 - 0
src/utils/index.js

@@ -0,0 +1,34 @@
+/**
+ * @param {string} url
+ * @returns {Object}
+ */
+export function param2Obj (url) {
+  const search = url.split('?')[1]
+  if (!search) {
+    return {}
+  }
+  return JSON.parse(
+    '{"' +
+      decodeURIComponent(search)
+        .replace(/"/g, '\\"')
+        .replace(/&/g, '","')
+        .replace(/=/g, '":"')
+        .replace(/\+/g, ' ') +
+      '"}'
+  )
+}
+
+export function deepClone (source) {
+  if (!source && typeof source !== 'object') {
+    throw new Error('error arguments', 'deepClone')
+  }
+  const targetObj = source.constructor === Array ? [] : {}
+  Object.keys(source).forEach(keys => {
+    if (source[keys] && typeof source[keys] === 'object') {
+      targetObj[keys] = deepClone(source[keys])
+    } else {
+      targetObj[keys] = source[keys]
+    }
+  })
+  return targetObj
+}

+ 48 - 0
src/utils/permission.js

@@ -0,0 +1,48 @@
+import router from '@/router'
+import store from '@/store'
+import { Notify } from 'vant'
+import { getToken } from '@/utils/auth' // get token from cookie
+import getPageTitle from '@/utils/get-page-title'
+
+const whiteList = ['/login', '/register'] // 白名单列表
+
+router.beforeEach(async (to, from, next) => {
+  // 设置页面标题
+  document.title = getPageTitle(to.meta.title)
+
+  // determine whether the user has logged in
+  const hasToken = getToken()
+
+  if (hasToken) {
+    if (to.path === '/login') {
+      // 已经登录,跳转到首页
+      next({ path: '/' })
+    } else {
+      // 获取用户信息
+      const hasGetUserInfo = store.getters.userData && store.getters.userData.name
+      if (hasGetUserInfo) {
+        next()
+      } else {
+        try {
+          // get user info
+          await store.dispatch('user/getInfo')
+          next()
+        } catch (error) {
+          // 清除用户信息,退出登录,跳转登录页
+          store.commit('user/LOGOUT')
+          Notify.error(error || 'Has Error')
+          next(`/login?redirect=${to.path}`)
+        }
+      }
+    }
+  } else {
+    /* has no token */
+    if (whiteList.indexOf(to.path) !== -1) {
+      // 白名单中,无需验证
+      next()
+    } else {
+      // other pages that do not have permission to access are redirected to the login page.
+      next(`/login?redirect=${to.path}`)
+    }
+  }
+})

+ 74 - 0
src/utils/request.js

@@ -0,0 +1,74 @@
+import axios from 'axios'
+import { Toast } from 'vant'
+import store from '@/store'
+import { getToken } from '@/utils/auth'
+
+// create an axios instance
+const service = axios.create({
+  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
+  // withCredentials: true, // send cookies when cross-domain requests
+  timeout: 5000 // request timeout
+})
+
+// request interceptor
+service.interceptors.request.use(
+  config => {
+    // do something before request is sent
+    if (store.getters.token) {
+      config.headers['X-Token'] = getToken()
+    }
+    return config
+  },
+  error => {
+    // do something with request error
+    console.log(error, 'err') // for debug
+    return Promise.reject(error)
+  }
+)
+
+// response interceptor
+service.interceptors.response.use(
+  /**
+   * If you want to get http information such as headers or status
+   * Please return  response => response
+  */
+
+  /**
+   * Determine the request status by custom code
+   * Here is just an example
+   * You can also judge the status by HTTP Status Code
+   */
+  response => {
+    const res = response.data
+
+    // if the custom code is not 20000, it is judged as an error.
+    if (res.code !== 200) {
+      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+      if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
+        // to re-login
+        Toast.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
+          confirmButtonText: 'Re-Login',
+          cancelButtonText: 'Cancel',
+          type: 'warning'
+        }).then(() => {
+          store.dispatch('user/resetToken').then(() => {
+            location.reload()
+          })
+        })
+      }
+      return Promise.reject(new Error(res.message || 'Error'))
+    } else {
+      return res
+    }
+  },
+  error => {
+    console.log('err' + error) // for debug
+    Toast.fail({
+      message: error.message,
+      duration: 1.5 * 1000
+    })
+    return Promise.reject(error)
+  }
+)
+
+export default service

+ 88 - 0
src/utils/validate.js

@@ -0,0 +1,88 @@
+/**
+ * Created by PanJiaChen on 16/11/18.
+ */
+
+/**
+ * @param {string} path
+ * @returns {Boolean}
+ */
+export function isExternal (path) {
+  return /^(https?:|mailto:|tel:)/.test(path)
+}
+
+/**
+ * @param {string} str
+ * @returns {Boolean}
+ */
+export function validUsername (str) {
+  const validMap = ['admin', 'editor']
+  return validMap.indexOf(str.trim()) >= 0
+}
+
+/**
+ * @param {string} url
+ * @returns {Boolean}
+ */
+export function validURL (url) {
+  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
+  return reg.test(url)
+}
+
+/**
+ * @param {string} str
+ * @returns {Boolean}
+ */
+export function validLowerCase (str) {
+  const reg = /^[a-z]+$/
+  return reg.test(str)
+}
+
+/**
+ * @param {string} str
+ * @returns {Boolean}
+ */
+export function validUpperCase (str) {
+  const reg = /^[A-Z]+$/
+  return reg.test(str)
+}
+
+/**
+ * @param {string} str
+ * @returns {Boolean}
+ */
+export function validAlphabets (str) {
+  const reg = /^[A-Za-z]+$/
+  return reg.test(str)
+}
+
+/**
+ * @param {string} email
+ * @returns {Boolean}
+ */
+export function validEmail (email) {
+  // eslint-disable-next-line
+  const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
+  return reg.test(email)
+}
+
+/**
+ * @param {string} str
+ * @returns {Boolean}
+ */
+export function isString (str) {
+  if (typeof str === 'string' || str instanceof String) {
+    return true
+  }
+  return false
+}
+
+/**
+ * @param {Array} arg
+ * @returns {Boolean}
+ */
+export function isArray (arg) {
+  if (typeof Array.isArray === 'undefined') {
+    return Object.prototype.toString.call(arg) === '[object Array]'
+  }
+  return Array.isArray(arg)
+}

+ 82 - 0
src/utils/vuex-loading.js

@@ -0,0 +1,82 @@
+// 相关文档 https://vuex.vuejs.org/zh/api/#subscribeaction
+const NAMESPACE = '@@loading'
+
+const createLoadingPlugin = ({
+  namespace = NAMESPACE,
+  includes = [],
+  excludes = []
+} = {}) => {
+  return store => {
+    if (store.state[namespace]) {
+      throw new Error(
+        `createLoadingPlugin: ${namespace} exited in current store`
+      )
+    }
+
+    store.registerModule(namespace, {
+      namespaced: true,
+      state: {
+        global: false,
+        effects: {
+
+        }
+      },
+      mutations: {
+        SHOW (state, { payload }) {
+          state.global = true
+          state.effects = {
+            ...state.effects,
+            [payload]: true
+          }
+        },
+        HIDE (state, { payload }) {
+          state.global = false
+          state.effects = {
+            ...state.effects,
+            [payload]: false
+          }
+        }
+      }
+    })
+
+    store.subscribeAction({
+      before: action => {
+        console.log(`before action ${action.type}`)
+        if (shouldEffect(action, includes, excludes)) {
+          store.commit({ type: namespace + '/SHOW', payload: action.type })
+        }
+      },
+      after: action => {
+        console.log(`after action ${action.type}`)
+        if (shouldEffect(action, includes, excludes)) {
+          store.commit({ type: namespace + '/HIDE', payload: action.type })
+        }
+      }
+    })
+  }
+}
+
+function shouldEffect ({ type }, includes, excludes) {
+  if (includes.length === 0 && excludes.length === 0) {
+    return true
+  }
+
+  if (includes.length > 0) {
+    return includes.indexOf(type) > -1
+  }
+
+  return excludes.length > 0 && excludes.indexOf(type) === -1
+}
+
+export default createLoadingPlugin
+// 需要在vuex中引入并注册成插件:
+/**
+import createLoadingPlugin from 'utils/vuex-loading'
+export default new Vuex.Store({
+  plugins: [createLoadingPlugin()],
+  state: {
+    // loading: false,
+    direction: 'forward'
+  }
+})
+**/

+ 11 - 0
src/views/404.vue

@@ -0,0 +1,11 @@
+<template>
+  <div>
+    404
+    <router-link replace to="/">返回首页</router-link>
+  </div>
+</template>
+<script>
+export default {
+  name: 'page404'
+}
+</script>

+ 159 - 0
src/views/Article.vue

@@ -0,0 +1,159 @@
+<template>
+  <div class="container">
+    <div class="list-wrap">
+      <vo-pages :data="list"
+                @pullingUp="pullingUp"
+                @pullingDown="pullingDown"
+                :loadedAll="loadedAll">
+        <ul class="article-list">
+          <li class="article"
+              v-for="article in list"
+              :key="article.id">
+            <div class="left">
+              <img v-lazy="article.imageUri"
+                   alt="thumb" />
+            </div>
+            <div class="right">
+              <p>{{ article.title }}</p>
+              <p class="more-info">
+                <span class="author">作者:{{ article.author }}</span>
+                <span class="time">发布时间:{{article.displayTimeFormart}}</span>
+              </p>
+            </div>
+          </li>
+        </ul>
+      </vo-pages>
+    </div>
+    <footer-tabbar/>
+  </div>
+</template>
+<script>
+import { Tabbar, TabbarItem } from 'vant'
+import { fetchList } from 'api/article'
+import dayjs from 'dayjs'
+import FooterTabbar from 'components/FooterTabbar'
+import VoPages from 'vo-pages'
+import 'vo-pages/lib/vo-pages.css'
+export default {
+  name: 'Article',
+  data () {
+    return {
+      active: 1,
+      list: [],
+      total: 0,
+      page: 1,
+      loadedAll: false
+    }
+  },
+  mounted () {
+    this.getList()
+  },
+  components: {
+    [Tabbar.name]: Tabbar,
+    [TabbarItem.name]: TabbarItem,
+    VoPages,
+    FooterTabbar
+  },
+  methods: {
+    pullingDown () {
+      this.beforePullDown = false
+      this.page = 1
+      this.getList(false)
+    },
+    pullingUp () {
+      this.page += 1
+      this.getList()
+    },
+    async getList (loadMore = true) {
+      const data = {
+        page: this.page
+      }
+      const result = await fetchList(data)
+      this.total = result.data.total
+      const newList = result.data.items.map(article => {
+        article.displayTimeFormart = dayjs(article.display_time).format('YYYY-MM-DD')
+        return article
+      })
+      if (loadMore) {
+        this.list = this.list.concat(newList)
+      } else {
+        this.list = newList
+      }
+      if (!this.beforePullDown) {
+        this.beforePullDown = true
+      }
+      this.loadedAll = this.total <= this.list.length
+    }
+  }
+}
+</script>
+<style lang="scss" scoped>
+p{
+  margin-block-start: 0;
+  margin-block-end: 0;
+}
+.container{
+  height: 100%;
+  width: 100%;
+  background: #f5f5f5;
+  .list-wrap{
+    height: calc(100% - 50px);
+    overflow-y: hidden;
+  }
+}
+
+.article-list {
+  width: 100%;
+  height: auto;
+  box-sizing: border-box;
+  padding: 15px 15px 0;
+  .article {
+    display: flex;
+    width: 100%;
+    justify-content: space-between;
+    align-items: center;
+    margin-bottom: 20px;
+    padding: 10px 15px;
+    box-sizing: border-box;
+    background: #FFF;
+    border-radius: 5px;
+    box-shadow: 0 0 6px #e3e3e3;
+    .left {
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      img {
+        width: 80px;
+        height: 80px;
+        border-radius: 50%;
+      }
+    }
+    .right {
+      padding-left: 15px;
+      box-sizing: border-box;
+      display: flex;
+      width: 235px;
+      height: 80px;
+      flex-direction: column;
+      align-items: flex-start;
+      justify-content: space-around;
+      p {
+        width: 100%;
+        line-height: 20px;
+        overflow: hidden;
+        text-overflow: ellipsis;
+        white-space: nowrap;
+        font-size: 16px;
+      }
+      .more-info{
+        display: flex;
+        justify-content: space-between;
+        align-items: center;
+        font-size: 14px;
+        color: #666;
+      }
+    }
+  }
+}
+
+</style>

+ 144 - 0
src/views/Home.vue

@@ -0,0 +1,144 @@
+<template>
+  <div class="container">
+    <div class="banner">
+      <van-swipe :autoplay="3000">
+        <van-swipe-item v-for="(image, index) in images"
+                        :key="index">
+          <img v-lazy="image" />
+        </van-swipe-item>
+      </van-swipe>
+    </div>
+    <div class="now-value">
+      <span>当前数值{{$store.state.test.number}}</span>
+      <div>
+        <van-button type="info"
+                    @click="add"
+                    :loading="loading"
+                    size="small">异步+1</van-button>
+        <van-button type="primary"
+                    size="small"
+                    @click="addOne">+1</van-button>
+      </div>
+    </div>
+    <div class="icon-list">
+      <svg-icon v-for="icon in iconList"
+                :key="icon"
+                class="icon"
+                :icon-class="icon" />
+    </div>
+    <div class="buttons">
+      <van-button type="warning"
+                  @click="logout">退出登录</van-button>
+      <router-link to="/404">
+        <svg-icon icon-class="404" />前往404页面</router-link>
+    </div>
+    <footer-tabbar />
+  </div>
+</template>
+
+<script>
+import { Button, Tabbar, TabbarItem, Swipe, SwipeItem } from 'vant'
+import { mapActions, mapMutations, mapState } from 'vuex' // createNamespacedHelpers
+import FooterTabbar from 'components/FooterTabbar'
+// const { mapActions } = createNamespacedHelpers('test') // 可使用这种方式直接获得test模板
+
+export default {
+  name: 'home',
+  data () {
+    return {
+      value: 1,
+      images: [
+        'https://img.yzcdn.cn/vant/apple-1.jpg',
+        'https://img.yzcdn.cn/vant/apple-2.jpg'
+      ],
+      iconList: [
+        'dashboard',
+        'example',
+        'eye-open',
+        'eye',
+        'form',
+        'link',
+        'nested',
+        'password',
+        'table',
+        'tree',
+        'user',
+        '404'
+      ]
+    }
+  },
+  components: {
+    [Button.name]: Button,
+    [Tabbar.name]: Tabbar,
+    [TabbarItem.name]: TabbarItem,
+    [Swipe.name]: Swipe,
+    [SwipeItem.name]: SwipeItem,
+    FooterTabbar
+  },
+  computed: {
+    ...mapState({
+      loading: state => state['@@loading'].effects['test/onePlusAsync']
+    })
+  },
+  methods: {
+    add () {
+      this.onePlusAsync(this.value)
+    },
+    addOne () {
+      this.onePlus(1)
+    },
+    // ...mapActions('home', ['initData', 'plusPage', 'initPage']),
+    ...mapActions({
+      onePlusAsync: 'test/onePlusAsync'
+    }),
+    ...mapMutations({
+      onePlus: 'test/onePlus',
+      logout: 'user/LOGOUT'
+    })
+  }
+}
+</script>
+<style lang="scss" scoped>
+.container{
+  height: auto;
+  width: 100%;
+  padding-bottom: 50px;
+}
+.banner {
+  width: 100%;
+  height: auto;
+  img {
+    width: 100%;
+    height: auto;
+  }
+}
+.now-value {
+  padding: 0 15px;
+  box-sizing: border-box;
+  font-size: 16px;
+  // line-height: 30px;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
+
+.icon-list {
+  margin: 15px;
+  font-size: 24px;
+  .icon {
+    margin: 0 10px;
+  }
+}
+.buttons {
+  padding: 0 15px;
+  font-size: 18px;
+  width: 100%;
+  box-sizing: border-box;
+  display: flex;
+  justify-content: space-around;
+  align-items: center;
+  a {
+    color: #333;
+  }
+}
+</style>

+ 137 - 0
src/views/user/Login.vue

@@ -0,0 +1,137 @@
+<template>
+  <div>
+    <div class="header">
+      <div class="logo">
+        <img src="http://img.cixi518.com/ljh_logo.jpeg" alt="default_logo">
+      </div>
+    </div>
+    <div class="content">
+      <van-field placeholder="手机号码" v-model="phoneNumber" left-icon="phone-o" :error-message="phoneNumberError" />
+      <!-- eye -->
+      <van-field v-if="loginWay==='password'" placeholder="登录密码" v-model="password" left-icon="lock" :type="passwordType">
+         <van-icon slot="right-icon" @click="switchPasswordType" :name="passwordIcon"/>
+      </van-field>
+      <van-field v-else placeholder="短信验证码" v-model="password" left-icon="comment-o" type="text">
+        <VerifyCodeBtn slot="button" @sendVerifyCode="sendVerifyCode" />
+      </van-field>
+      <div class="button-wrap">
+        <van-button size="large" @click="handleLogin" type="info">登录</van-button>
+      </div>
+      <div class="more-wrap">
+        <router-link class="link" to="/register">没有账号?去注册</router-link>
+        <div class="switch-way" @click="switchLoginWay">{{loginWayObj.toggleMsg}}</div>
+      </div>
+    </div>
+  </div>
+</template>
+<script>
+import { Field, Icon, Button } from 'vant'
+import { mapActions } from 'vuex'
+import VerifyCodeBtn from '@/components/VerifyCodeBtn'
+export default {
+  name: 'Login',
+  data () {
+    return {
+      phoneNumber: '13216698987',
+      password: '123456',
+      code: '',
+      loginWay: 'password',
+      passwordType: 'password',
+      phoneNumberError: ''
+    }
+  },
+  methods: {
+    sendVerifyCode () {
+      this.phoneNumberError = ''
+      if (!this.phoneNumber) { // 根据需求做判断
+        this.phoneNumberError = '手机号码必填'
+      }
+    },
+    switchPasswordType () {
+      this.passwordType = this.passwordType === 'password' ? 'text' : 'password'
+    },
+    switchLoginWay () {
+      this.password = this.code = ''
+      this.loginWay = this.loginWay === 'password' ? 'verifyCode' : 'password'
+    },
+    handleLogin () {
+      const data = {
+        phoneNumber: this.phoneNumber,
+        password: this.password,
+        $router: this.$router,
+        $route: this.$route
+      }
+      this.login(data)
+    },
+    ...mapActions({
+      login: 'user/login'
+    })
+  },
+  computed: {
+    loginWayObj: function () {
+      if (this.loginWay === 'password') {
+        return {
+          icon: 'closed-eye',
+          toggleMsg: '验证码登录'
+        }
+      }
+      return {
+        icon: 'eye',
+        toggleMsg: '密码登录'
+      }
+    },
+    passwordIcon: function () {
+      return this.passwordType === 'password' ? 'closed-eye' : 'eye'
+    }
+  },
+  components: {
+    [Field.name]: Field,
+    [Icon.name]: Icon,
+    [Button.name]: Button,
+    VerifyCodeBtn
+  }
+}
+</script>
+<style lang="scss" scoped>
+  .header{
+    width: 100%;
+    height: 165px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    .logo{
+      width: 60px;
+      height: 60px;
+      border-radius: 50%;
+      overflow: hidden;
+      img{
+        width: 100%;
+      }
+    }
+  }
+  .content{
+    width: 100%;
+    height: auto;
+    padding: 0 15px;
+    box-sizing: border-box;
+    .button-wrap{
+      width: 100%;
+      height: auto;
+      margin-top: 15px;
+    }
+  }
+  .more-wrap{
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    margin-top: 15px;
+    font-size: 14px;
+    a.link{
+      color: #1989fa;
+    }
+    .switch-way{
+      color: #333;
+    }
+  }
+
+</style>

+ 13 - 0
src/views/user/Register.vue

@@ -0,0 +1,13 @@
+<template>
+  <div>
+    this is register page
+  </div>
+</template>
+<script>
+export default {
+
+}
+</script>
+<style lang="scss" scoped>
+
+</style>

+ 197 - 0
vue.config.js

@@ -0,0 +1,197 @@
+const path = require('path')
+const CompressionWebpackPlugin = require('compression-webpack-plugin')
+const UglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin')
+const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
+const port = process.env.port || process.env.npm_config_port || 8888
+const cdnDomian = './' // cdn域名,如果有cdn修改成对应的cdn
+const name = 'H5Vue' // page title
+const IS_PRODUCTION = process.env.NODE_ENV === 'production'
+const cdn = {
+  css: [],
+  js: [
+    'https://cdn.bootcss.com/vue/2.6.10/vue.min.js',
+    'https://cdn.bootcss.com/vue-router/3.0.3/vue-router.min.js',
+    'https://cdn.bootcss.com/vuex/3.1.0/vuex.min.js',
+    'https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.min.js',
+    'https://cdn.bootcss.com/js-cookie/2.2.1/js.cookie.min.js'
+  ]
+}
+
+const externals = {
+  vue: 'Vue',
+  'vue-router': 'VueRouter',
+  vuex: 'Vuex',
+  axios: 'axios',
+  'js-cookie': 'Cookies'
+}
+
+function resolve (dir) {
+  return path.join(__dirname, dir)
+}
+
+module.exports = {
+  publicPath: IS_PRODUCTION ? cdnDomian : './',
+  outputDir: 'dist',
+  assetsDir: 'static',
+  lintOnSave: process.env.NODE_ENV === 'development',
+  productionSourceMap: false,
+  devServer: {
+    port: port,
+    open: true,
+    overlay: {
+      warnings: false,
+      errors: true
+    },
+    proxy: {
+      // change xxx-api/login => mock/login
+      // detail: https://cli.vuejs.org/config/#devserver-proxy
+      [process.env.VUE_APP_BASE_API]: {
+        target: `http://127.0.0.1:${port}/mock`,
+        changeOrigin: true,
+        pathRewrite: {
+          ['^' + process.env.VUE_APP_BASE_API]: ''
+        }
+      }
+    },
+    after: require('./mock/mock-server.js')
+  },
+  configureWebpack: {
+    // provide the app's title in webpack's name field, so that
+    // it can be accessed in index.html to inject the correct title.
+    name: name,
+    resolve: {
+      alias: {
+        '@': resolve('src'), // 主目录
+        'views': resolve('src/views'), // 页面
+        'components': resolve('src/components'), // 组件
+        'api': resolve('src/api'), // 接口
+        'utils': resolve('src/utils'), // 通用功能
+        'assets': resolve('src/assets'), // 静态资源
+        'style': resolve('src/style') // 通用样式
+      }
+    }
+  },
+  chainWebpack (config) {
+    config.plugins.delete('preload') // TODO: need test
+    config.plugins.delete('prefetch') // TODO: need test
+
+    // set svg-sprite-loader
+    config.module
+      .rule('svg')
+      .exclude.add(resolve('src/icons'))
+      .end()
+    config.module
+      .rule('icons')
+      .test(/\.svg$/)
+      .include.add(resolve('src/icons'))
+      .end()
+      .use('svg-sprite-loader')
+      .loader('svg-sprite-loader')
+      .options({
+        symbolId: 'icon-[name]'
+      })
+      .end()
+
+    // set preserveWhitespace
+    config.module
+      .rule('vue')
+      .use('vue-loader')
+      .loader('vue-loader')
+      .tap(options => {
+        options.compilerOptions.preserveWhitespace = true
+        return options
+      })
+      .end()
+
+    config
+    // https://webpack.js.org/configuration/devtool/#development
+      .when(process.env.NODE_ENV === 'development',
+        config => config.devtool('cheap-source-map')
+      )
+
+    config
+      .when(process.env.NODE_ENV !== 'development',
+        config => {
+          config
+            .plugin('ScriptExtHtmlWebpackPlugin')
+            .after('html')
+            .use('script-ext-html-webpack-plugin', [{
+            // `runtime` must same as runtimeChunk name. default is `runtime`
+              inline: /runtime\..*\.js$/
+            }])
+            .end()
+          config
+            .optimization.splitChunks({
+              chunks: 'all',
+              cacheGroups: {
+                libs: {
+                  name: 'chunk-libs',
+                  test: /[\\/]node_modules[\\/]/,
+                  priority: 10,
+                  chunks: 'initial' // only package third parties that are initially dependent
+                },
+                commons: {
+                  name: 'chunk-commons',
+                  test: resolve('src/components'), // can customize your rules
+                  minChunks: 3, //  minimum common number
+                  priority: 5,
+                  reuseExistingChunk: true
+                }
+              }
+            })
+          config.optimization.runtimeChunk('single')
+        }
+      )
+    if (IS_PRODUCTION) {
+      config.plugin('analyzer').use(BundleAnalyzerPlugin)
+      config.plugin('html').tap(args => {
+        args[0].cdn = cdn
+        return args
+      })
+      config.externals(externals)
+      config.plugin('html').tap(args => {
+        args[0].minify.minifyCSS = true // 压缩html中的css
+        return args
+      })
+      // gzip需要nginx进行配合
+      config
+        .plugin('compression')
+        .use(CompressionWebpackPlugin)
+        .tap(() => [
+          {
+            test: /\.js$|\.html$|\.css/, // 匹配文件名
+            threshold: 10240, // 超过10k进行压缩
+            deleteOriginalAssets: false // 是否删除源文件
+          }
+        ])
+      config.optimization.minimizer([
+        new UglifyjsWebpackPlugin({
+          // 生产环境推荐关闭 sourcemap 防止源码泄漏
+          // 服务端通过前端发送的行列,根据 sourcemap 转为源文件位置
+          // sourceMap: true,
+          uglifyOptions: {
+            warnings: false,
+            compress: {
+              drop_console: true,
+              drop_debugger: true
+            }
+          }
+        })
+      ])
+    }
+  },
+  css: {
+    // 是否使用css分离插件 ExtractTextPlugin
+    extract: !!IS_PRODUCTION,
+    // 开启 CSS source maps?
+    sourceMap: false,
+    // css预设器配置项
+    // 启用 CSS modules for all css / pre-processor files.
+    modules: false,
+    loaderOptions: {
+      sass: {
+        data: '@import "style/_mixin.scss";@import "style/_variables.scss";@import "style/common.scss";' // 全局引入
+      }
+    }
+  }
+}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 9108 - 0
yarn.lock