Browse Source

icons mock 调整

daxiongYang 7 years ago
parent
commit
e2020cbfc0

+ 1 - 1
.eslintignore

3
/dist/
3
/dist/
4
/*.js
4
/*.js
5
/test/unit/coverage/
5
/test/unit/coverage/
6
/src/iconfont/iconfont.js
6
/src/icons/iconfont.js

+ 0 - 0
src/icons/iconfont.js


+ 6 - 1
src/icons/index.js

3
 *
3
 *
4
 * 使用:
4
 * 使用:
5
 *  1. 在阿里矢量图标站创建一个项目, 并添加图标(这一步非必须, 创建方便项目图标管理)
5
 *  1. 在阿里矢量图标站创建一个项目, 并添加图标(这一步非必须, 创建方便项目图标管理)
6
 *  2. 选中新增的icon图标, 复制代码 -> 下载 -> SVG下载 -> 粘贴代码(重命名)
6
 *  2-1. 添加icon, 选中新增的icon图标, 复制代码 -> 下载 -> SVG下载 -> 粘贴代码(重命名)
7
 *  2-2. 添加icons, 下载图标库对应[iconfont.js]文件, 替换项目[./iconfont.js]文件
7
 *  3. 组件模版中使用 [<icon-svg name="canyin"></icon-svg>]
8
 *  3. 组件模版中使用 [<icon-svg name="canyin"></icon-svg>]
9
 *
10
 * 注意:
11
 *  1. 通过2-2 添加icons, getNameList方法无法返回对应数据
8
 */
12
 */
9
import Vue from 'vue'
13
import Vue from 'vue'
10
import IconSvg from '@/components/icon-svg'
14
import IconSvg from '@/components/icon-svg'
15
import './iconfont.js'
11
16
12
Vue.component('IconSvg', IconSvg)
17
Vue.component('IconSvg', IconSvg)
13
18

+ 7 - 10
src/main.js

1
import Vue from 'vue'
1
import Vue from 'vue'
2
import router from '@/router'
3
import store from '@/store'
4
import VueCookie from 'vue-cookie'
5
6
import App from '@/App'
2
import App from '@/App'
7
8
import '@/element-ui'
9
import '@/icons'
3
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
4
import store from '@/store'                   // api: https://github.com/vuejs/vuex
5
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
6
import '@/element-ui'                         // api: https://github.com/ElemeFE/element
7
import '@/icons'                              // api: http://www.iconfont.cn/
10
import '@/assets/scss/index.scss'
8
import '@/assets/scss/index.scss'
11
12
import httpRequest from '@/utils/httpRequest'
9
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
13
import { isAuth } from '@/utils'
10
import { isAuth } from '@/utils'
14
11
15
Vue.use(VueCookie)
12
Vue.use(VueCookie)
16
Vue.config.productionTip = false
13
Vue.config.productionTip = false
17
14
18
// 非生产环境, 适配mockjs模拟数据
15
// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
19
if (process.env.NODE_ENV !== 'production') {
16
if (process.env.NODE_ENV !== 'production') {
20
  require('@/mock')
17
  require('@/mock')
21
}
18
}

+ 0 - 31
src/mock/create.js

1
import Mock from 'mockjs'
2
import http from '@/utils/httpRequest'
3
import merge from 'lodash/merge'
4
5
/**
6
 * 创建mock模拟数据
7
 * @param {*} mods 模块集
8
 * @param {*} isOpen 是否开启?
9
 */
10
export default function (mods, isOpen = true) {
11
  if (isOpen) {
12
    for (var key in mods) {
13
      var mod = mods[key]() || {}
14
      if (mod.isOpen !== false) {
15
        // 添加默认[mock]属性, 方便调试
16
        mod.data = merge({ 'mock': true }, mod.data)
17
18
        // 控制台输出信息
19
        console.log('\n')
20
        console.log(' url: ', mod.url)
21
        console.log('type: ', mod.type)
22
        console.log('data: ', mod.data)
23
        console.log('\n')
24
25
        // 2种url拦截方式
26
        Mock.mock(http.adornUrl(mod.url), mod.type, mod.data)
27
        Mock.mock(new RegExp(mod.url, 'g'), mod.type, mod.data)
28
      }
29
    }
30
  }
31
}

+ 39 - 9
src/mock/index.js

1
import create from './create'
1
import Mock from 'mockjs'
2
import http from '@/utils/httpRequest'
3
import merge from 'lodash/merge'
2
import * as common from './modules/common'
4
import * as common from './modules/common'
3
import * as user from './modules/user'
5
import * as user from './modules/user'
4
import * as role from './modules/role'
6
import * as role from './modules/role'
14
// 1. 关闭[业务模块集]拦截, create方法[第2个参数]设置. (默认开启)
16
// 1. 关闭[业务模块集]拦截, create方法[第2个参数]设置. (默认开启)
15
// 2. 关闭[业务模块对象]拦截, 通过模块返回对象中的[isOpen属性, 默认开启]设置. (默认开启)
17
// 2. 关闭[业务模块对象]拦截, 通过模块返回对象中的[isOpen属性, 默认开启]设置. (默认开启)
16
18
17
create(common, false)      // 公共
18
create(user, false)        // 管理员管理
19
create(role, false)        // 角色管理
20
create(menu, false)        // 菜单管理
21
create(log, false)         // 系统日志
22
create(config, false)      // 参数管理
23
create(oss, false)         // 文件服务
24
create(schedule, false)    // 定时任务
19
fnCreate(common, false)      // 公共
20
fnCreate(user, false)        // 管理员管理
21
fnCreate(role, false)        // 角色管理
22
fnCreate(menu, false)        // 菜单管理
23
fnCreate(log, false)         // 系统日志
24
fnCreate(config, false)      // 参数管理
25
fnCreate(oss, false)         // 文件服务
26
fnCreate(schedule, false)    // 定时任务
25
27
26
console.log('%c!<-------------------- 接口拦截, mock模拟数据 e -------------------->\n\n', 'color:blue')
28
console.log('%c!<-------------------- 接口拦截, mock模拟数据 e -------------------->\n\n', 'color:blue')
29
30
/**
31
 * 创建mock模拟数据
32
 * @param {*} mods 模块集
33
 * @param {*} isOpen 是否开启?
34
 */
35
function fnCreate (mods, isOpen = true) {
36
  if (isOpen) {
37
    for (var key in mods) {
38
      var mod = mods[key]() || {}
39
      if (mod.isOpen !== false) {
40
        // 添加默认[mock]属性, 方便调试
41
        mod.data = merge({ 'mock': true }, mod.data)
42
43
        // 控制台输出信息
44
        console.log('\n')
45
        console.log(' url: ', mod.url)
46
        console.log('type: ', mod.type)
47
        console.log('data: ', mod.data)
48
        console.log('\n')
49
50
        // 2种url拦截方式
51
        Mock.mock(http.adornUrl(mod.url), mod.type, mod.data)
52
        Mock.mock(new RegExp(mod.url, 'g'), mod.type, mod.data)
53
      }
54
    }
55
  }
56
}

+ 9 - 17
src/utils/index.js

1
/**
2
 * 获取uuid
3
 */
4
export function getUUID () {
5
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
6
    return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
7
  })
8
}
9
1
/**
10
/**
2
 * 是否有权限
11
 * 是否有权限
3
 * @param {*} key
12
 * @param {*} key
34
  }
43
  }
35
  return res
44
  return res
36
}
45
}
37
38
/**
39
 * 获取字符串字节长度
40
 * @param {*} s
41
 */
42
export function getStringLength (s) {
43
  return s.replace(/[\u4e00-\u9fa5\uff00-\uffff]/g, '**').length
44
}
45
46
/**
47
 * 获取uuid
48
 */
49
export function getUUID () {
50
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
51
    return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
52
  })
53
}

+ 1 - 1
src/views/main-navbar.vue

17
      <el-menu
17
      <el-menu
18
        class="site-navbar__menu site-navbar__menu--right"
18
        class="site-navbar__menu site-navbar__menu--right"
19
        mode="horizontal">
19
        mode="horizontal">
20
        <el-menu-item index="1" @click="$router.push({ name: 'setting' })">
20
        <el-menu-item index="1" @click="$router.push({ name: 'theme' })">
21
          <template slot="title">
21
          <template slot="title">
22
            <el-badge value="new">
22
            <el-badge value="new">
23
              <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
23
              <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>

+ 2 - 2
src/views/modules/sys/menu-add-or-update.vue

30
        </el-popover>
30
        </el-popover>
31
        <el-input v-model="dataForm.parentName" v-popover:menuListPopover :readonly="true" placeholder="点击选择上级菜单" class="menu-list__input"></el-input>
31
        <el-input v-model="dataForm.parentName" v-popover:menuListPopover :readonly="true" placeholder="点击选择上级菜单" class="menu-list__input"></el-input>
32
      </el-form-item>
32
      </el-form-item>
33
      <el-form-item v-if="dataForm.type === 1" label="菜单URL" prop="url">
34
        <el-input v-model="dataForm.url" placeholder="菜单URL"></el-input>
33
      <el-form-item v-if="dataForm.type === 1" label="菜单路由" prop="url">
34
        <el-input v-model="dataForm.url" placeholder="菜单路由"></el-input>
35
      </el-form-item>
35
      </el-form-item>
36
      <el-form-item v-if="dataForm.type !== 0" label="授权标识" prop="perms">
36
      <el-form-item v-if="dataForm.type !== 0" label="授权标识" prop="perms">
37
        <el-input v-model="dataForm.perms" placeholder="多个用逗号分隔, 如: user:list,user:create"></el-input>
37
        <el-input v-model="dataForm.perms" placeholder="多个用逗号分隔, 如: user:list,user:create"></el-input>

+ 1 - 1
static/config/init.js

11
      window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
11
      window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
12
      window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
12
      window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
13
      window.SITE_CONFIG.cdnUrl + '/static/js/app.js',
13
      window.SITE_CONFIG.cdnUrl + '/static/js/app.js',
14
      window.SITE_CONFIG.cdnUrl + '/static/plugins/mock-1.0.0-beta3/mock-min.js'
14
      // window.SITE_CONFIG.cdnUrl + '/static/plugins/mock-1.0.0-beta3/mock-min.js'
15
    ]
15
    ]
16
  };
16
  };
17
17