zhaobao před 3 roky
rodič
revize
30896d7930
8 změnil soubory, kde provedl 338 přidání a 14 odebrání
  1. 35 0
      build/index.js
  2. 57 0
      mock/index.js
  3. 81 0
      mock/mock-server.js
  4. 29 0
      mock/table.js
  5. 84 0
      mock/user.js
  6. 25 0
      mock/utils.js
  7. 0 0
      src/iconfonts/iconfont.js
  8. 27 14
      src/layout/components/Navbar.vue

+ 35 - 0
build/index.js

@@ -0,0 +1,35 @@
+const { run } = require('runjs')
+const chalk = require('chalk')
+const config = require('../vue.config.js')
+const rawArgv = process.argv.slice(2)
+const args = rawArgv.join(' ')
+
+if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
+  const report = rawArgv.includes('--report')
+
+  run(`vue-cli-service build ${args}`)
+
+  const port = 9526
+  const publicPath = config.publicPath
+
+  var connect = require('connect')
+  var serveStatic = require('serve-static')
+  const app = connect()
+
+  app.use(
+    publicPath,
+    serveStatic('./dist', {
+      index: ['index.html', '/']
+    })
+  )
+
+  app.listen(port, function () {
+    console.log(chalk.green(`> Preview at  http://localhost:${port}${publicPath}`))
+    if (report) {
+      console.log(chalk.green(`> Report at  http://localhost:${port}${publicPath}report.html`))
+    }
+
+  })
+} else {
+  run(`vue-cli-service build ${args}`)
+}

+ 57 - 0
mock/index.js

@@ -0,0 +1,57 @@
+const Mock = require('mockjs')
+const { param2Obj } = require('./utils')
+
+const user = require('./user')
+const table = require('./table')
+
+const mocks = [
+  ...user,
+  ...table
+]
+
+// 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).
+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))
+  }
+}
+
+module.exports = {
+  mocks,
+  mockXHR
+}
+

+ 81 - 0
mock/mock-server.js

@@ -0,0 +1,81 @@
+const chokidar = require('chokidar')
+const bodyParser = require('body-parser')
+const chalk = require('chalk')
+const path = require('path')
+const Mock = require('mockjs')
+
+const mockDir = path.join(process.cwd(), 'mock')
+
+function registerRoutes(app) {
+  let mockLastIndex
+  const { mocks } = require('./index.js')
+  const mocksForServer = mocks.map(route => {
+    return responseFake(route.url, route.type, route.response)
+  })
+  for (const mock of mocksForServer) {
+    app[mock.type](mock.url, mock.response)
+    mockLastIndex = app._router.stack.length
+  }
+  const mockRoutesLength = Object.keys(mocksForServer).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)]
+    }
+  })
+}
+
+// for mock server
+const responseFake = (url, type, respond) => {
+  return {
+    url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
+    type: type || 'get',
+    response(req, res) {
+      console.log('request invoke:' + req.path)
+      res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
+    }
+  }
+}
+
+module.exports = app => {
+  // 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))
+      }
+    }
+  })
+}

+ 29 - 0
mock/table.js

@@ -0,0 +1,29 @@
+const Mock = require('mockjs')
+
+const data = Mock.mock({
+  'items|30': [{
+    id: '@id',
+    title: '@sentence(10, 20)',
+    'status|1': ['published', 'draft', 'deleted'],
+    author: 'name',
+    display_time: '@datetime',
+    pageviews: '@integer(300, 5000)'
+  }]
+})
+
+module.exports = [
+  {
+    url: '/vue-admin-template/table/list',
+    type: 'get',
+    response: config => {
+      const items = data.items
+      return {
+        code: 20000,
+        data: {
+          total: items.length,
+          items: items
+        }
+      }
+    }
+  }
+]

+ 84 - 0
mock/user.js

@@ -0,0 +1,84 @@
+
+const tokens = {
+  admin: {
+    token: 'admin-token'
+  },
+  editor: {
+    token: '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'
+  }
+}
+
+module.exports = [
+  // user login
+  {
+    url: '/vue-admin-template/user/login',
+    type: 'post',
+    response: config => {
+      const { username } = config.body
+      const token = tokens[username]
+
+      // mock error
+      if (!token) {
+        return {
+          code: 60204,
+          message: 'Account and password are incorrect.'
+        }
+      }
+
+      return {
+        code: 20000,
+        data: token
+      }
+    }
+  },
+
+  // get user info
+  {
+    url: '/vue-admin-template/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: 20000,
+        data: info
+      }
+    }
+  },
+
+  // user logout
+  {
+    url: '/vue-admin-template/user/logout',
+    type: 'post',
+    response: _ => {
+      return {
+        code: 20000,
+        data: 'success'
+      }
+    }
+  }
+]

+ 25 - 0
mock/utils.js

@@ -0,0 +1,25 @@
+/**
+ * @param {string} url
+ * @returns {Object}
+ */
+function param2Obj(url) {
+  const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
+  if (!search) {
+    return {}
+  }
+  const obj = {}
+  const searchArr = search.split('&')
+  searchArr.forEach(v => {
+    const index = v.indexOf('=')
+    if (index !== -1) {
+      const name = v.substring(0, index)
+      const val = v.substring(index + 1, v.length)
+      obj[name] = val
+    }
+  })
+  return obj
+}
+
+module.exports = {
+  param2Obj
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
src/iconfonts/iconfont.js


+ 27 - 14
src/layout/components/Navbar.vue

@@ -80,13 +80,13 @@ export default {
       logo: require('@/assets/images/logo/logo_nhc.png'),
       sideMenuTabIndex: 0,
       sideMenuTabList: [
-        { name: '数据总览', icon: 'el-icon-s-platform', path: '/nhc/overview' },
-        { name: '平安医院', icon: 'icon-common_satisfaction', path: '/nhc/safe' },
-        { name: '质量医院', icon: 'icon-common_quality', path: '/nhc/quality' },
-        { name: '满意医院', icon: 'icon-common_safety', path: '/nhc/satisfy' },
-        { name: '智慧医院', icon: 'icon-common_wisdom1', path: '/nhc/smart' },
-        { name: '健康医院', icon: 'icon-common_health', path: '/nhc/health' },
-        { name: '节约型医院', icon: 'icon-common_saving', path: '/nhc/economic' }
+        { name: '数据总览', icon: 'el-icon-s-platform', path: '/nhc/overview', permit: 'nhc_platform' },
+        { name: '平安医院', icon: 'icon-common_satisfaction', path: '/nhc/safe', permit: 'nhc_safe_platform' },
+        { name: '质量医院', icon: 'icon-common_quality', path: '/nhc/quality', permit: 'nhc_quality_platform' },
+        { name: '满意医院', icon: 'icon-common_safety', path: '/nhc/satisfy', permit: 'nhc_satisfy_platform' },
+        { name: '智慧医院', icon: 'icon-common_wisdom1', path: '/nhc/smart', permit: 'nhc_smart_platform' },
+        { name: '健康医院', icon: 'icon-common_health', path: '/nhc/health', permit: 'nhc_health_platform' },
+        { name: '节约型医院', icon: 'icon-common_saving', path: '/nhc/economic', permit: 'nhc_economic_platform' }
       ]
     }
   },
@@ -97,7 +97,8 @@ export default {
       'avatar',
       'userData',
       'permission_routes',
-      'menuSideTab'
+      'menuSiderTab',
+      'permits'
     ])
   },
   watch: {
@@ -108,12 +109,8 @@ export default {
   },
   created() {
     this.getUnReadMsg()
-    const permission_routes = localStorage.getItem('permission_routes')
-    if (!permission_routes) {
-      const index = 0
-      const item = this.sideMenuTabList[0]
-      this.sideTabChange(index, item)
-    }
+    this.initSideMenu()
+    this.initsideTab()
   },
   methods: {
     getUnReadMsg() {
@@ -121,6 +118,22 @@ export default {
         this.unReadCount = resp.data
       })
     },
+    initSideMenu() {
+      const permits = JSON.parse(JSON.stringify(this.permits))
+      let sideMenuTabList = JSON.parse(JSON.stringify(this.sideMenuTabList))
+      sideMenuTabList = sideMenuTabList.filter(item => permits.includes(item.permit))
+      this.sideMenuTabList = sideMenuTabList
+      console.log({ sideMenuTabList, permits })
+    },
+    initsideTab() {
+      let index = 0
+      if (this.isNotNull(localStorage.getItem('tabIndex'))) {
+        index = parseFloat(localStorage.getItem('tabIndex'))
+      }
+      this.sideTabChange(index, {
+        path: this.$route.fullPath
+      })
+    },    
     toggleSideBar() {
       this.$store.dispatch('app/toggleSideBar')
     },

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů