Commit 77ced0f8 by liimin

部分权限代码

1 parent af9b096e
......@@ -4,7 +4,7 @@
VUE_APP_TITLE=tFIMS
# 网络请求公用地址
VUE_APP_API=/api/
VUE_APP_API=http://192.168.3.171:7300/mock/5d638b3b6fbe9a0ac59d872e/tFIMS
# 仓库地址
VUE_APP_REPO=https://github.com/d2-projects/d2-admin-start-kit
......
......@@ -9133,6 +9133,11 @@
"integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==",
"dev": true
},
"js-md5": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz",
"integrity": "sha512-ZC41vPSTLKGwIRjqDh8DfXoCrdQIyBgspJVPXHBGu4nZlAEvG3nf+jO9avM9RmLiGakg7vz974ms99nEV0tmTQ=="
},
"js-message": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
......
......@@ -24,6 +24,7 @@
"fuse.js": "^3.4.4",
"hotkeys-js": "^3.6.2",
"js-cookie": "^2.2.0",
"js-md5": "^0.7.3",
"lodash": "^4.17.11",
"lowdb": "^1.0.0",
"mockjs": "^1.0.1-beta3",
......
/*
* @Author: limin
* @Date: 2019-08-26 18:02:41
* @Last Modified by: limin
* @Last Modified time: 2019-08-26 18:02:41
*/
import axios from '@/plugin/axios'
import sign from './sign'
const request = (params,method) => {
params.source = ''
params.app_key = '48e5e13229b82c1b4e6e8c96151f0637'
params.timestamp = new Date().getTime()
params.v = '1.0.0'
params.format = 'json'
const url = process.env.NODE_ENV === 'production' ? 'router' : params.method
// return axios.post(url, { 'params': sign(params) })
return axios({
url,
method: method||'get',
data:sign(params)
})
}
export default request
/*
* @Author: limin
* @Date: 2019-08-26 18:01:59
* @Last Modified by: limin
* @Last Modified time: 2019-08-26 18:02:32
*/
const RequestMethods = {
POST:'post',
GET:'get',
PUT:'put',
DELETE:'delete'
}
export default RequestMethods
/*
* @Author: limin
* @Date: 2019-08-26 18:02:49
* @Last Modified by: limin
* @Last Modified time: 2019-08-26 18:03:46
*/
import MD5 from 'js-md5'
const secret = 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b'
const sign = params => {
delete params.sign
const keys = Object.keys(params).sort()
var str = []
for (const key in params) {
if (typeof params[key] === 'object') params[key] = JSON.stringify(params[key])
}
keys.forEach(e => {
str.push(e + params[e])
})
params.sign = MD5(secret + str.join('') + secret)
return params
}
export default sign
import request from '@/plugin/axios'
/*
* @Author: limin
* @Date: 2019-08-26 18:02:55
* @Last Modified by: limin
* @Last Modified time: 2019-08-26 18:02:55
*/
import request from './request'
import RequestMethods from "./request.methods";
const path = ''
// export function AccountLogin (data) {
// return request({
// url: '/login',
// method: 'post',
// data
// })
// }
export function AccountLogin (data) {
return request({
url: '/login',
method: 'post',
data
})
}
data.method=`${path}login`
return request(data,RequestMethods.POST)
}
\ No newline at end of file
......@@ -7,39 +7,35 @@
注销
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown> -->
</el-dropdown>-->
<div v-popover:popover-personal class="d2-mr">
<span class="btn-text">{{info.name ? `你好 ${info.name}` : '未登录'}}</span>
<span class="btn-text">{{info.name ? `你好 ${info.name}` : '未登录'}}</span>
<el-popover ref="popover-personal" placement="bottom-end" trigger="hover">
<personal-panel :user="info"></personal-panel>
</el-popover>
<personal-panel :user="info"></personal-panel>
</el-popover>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import PersonalPanel from '../personal-panel'
import { mapState, mapActions } from "vuex";
import PersonalPanel from "../personal-panel";
export default {
components:{
components: {
PersonalPanel
},
computed: {
...mapState('d2admin/user', [
'info'
])
...mapState("d2admin/user", ["info"])
},
methods: {
...mapActions('d2admin/account', [
'logout'
]),
...mapActions("d2admin/account", ["logout"]),
/**
* @description 登出
*/
logOff () {
logOff() {
this.logout({
confirm: true
})
});
}
}
}
};
</script>
......@@ -30,5 +30,48 @@ util.open = function (url) {
a.click()
document.body.removeChild(document.getElementById('d2admin-link-temp'))
}
export default util
/**
* 深克隆 所有原型链上的对象和属性
* 例: const bar=deepClone(foo)
* console.log(bar===foo) false
* @param {*} obj
*/
util.deepClone = (obj) => {
// Handle the 3 simple types, and null or undefined or function
if (obj == null || typeof obj !== 'object') return obj
// Handle Date
if (obj instanceof Date) {
const copy = new Date()
copy.setTime(obj.getTime())
return copy
}
// Handle Array or Object
if (obj instanceof Array | obj instanceof Object) {
const copy = (obj instanceof Array) ? [] : {}
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) { copy[attr] = util.deepClone(obj[attr]) }
}
return copy
}
throw new Error("Unable to clone obj! Its type isn't supported.")
}
/**
* 深度递归搜索
* @param {Array} arr 你要搜索的数组
* @param {Function} condition 回调函数,必须返回谓词,判断是否找到了。会传入(item, index, level)三个参数
* @param {String} children 子数组的key
*/
util.deepFind = function(menus,id) {
const cloneMenus= util.deepClone(menus)
for (let menu of cloneMenus) {
if(menu.id === id ){
delete menu.children
return menu
}
if (menu.children) {
return util.deepFind(menu.children,id)
}
}
return null
}
export default util
\ No newline at end of file
......@@ -11,7 +11,8 @@ import D2Crud from '@d2-projects/d2-crud'
// 菜单和路由设置
import router from './router'
// import menuHeader from '@/menu/header'
import menuAside from '@/menu/aside'
// import menuAside from '@/menu/aside'
import menuAside from '@/resources'
import { frameInRoutes } from '@/router/routes'
import VRM from 'vue-role-manager'
......
// 菜单 侧边栏
export default [
{ path: '/index', title: '首页', icon: 'home' },
{ path: '/index', title: '首页', icon: 'desktop' },
{
title: '页面',
icon: 'folder-o',
......
// 菜单 顶栏
export default [
// { path: '/index', title: '首页', icon: 'home' },
// {
// title: '页面',
// icon: 'folder-o',
// children: [
// { path: '/page1', title: '页面 1' },
// { path: '/page2', title: '页面 2' },
// { path: '/page3', title: '页面 3' }
// ]
// }
{ path: '/index', title: '首页', icon: 'home' },
{
title: '页面',
icon: 'folder-o',
children: [
{ path: '/page1', title: '页面 1' },
{ path: '/page2', title: '页面 2' },
{ path: '/page3', title: '页面 3' }
]
}
]
......@@ -68,7 +68,7 @@ service.interceptors.response.use(
return dataAxios
} else {
// 有 code 代表这是一个后端接口 可以进行进一步的判断
switch (code) {
switch (+code) {
case 0:
// [ 示例 ] code === 0 代表没有错误
return dataAxios.data
......
/*
* @Author: limin
* @Date: 2019-08-26 18:03:10
* @Last Modified by: limin
* @Last Modified time: 2019-08-26 21:45:31
*/
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
const resources = [{
id: '101',
path: '/index',
title: '首页',
icon: 'desktop'
},
{
id: '102',
title: '页面',
path: '',
icon: 'folder-o',
children: [{
id: '10201',
path: '/page1',
title: '页面 1',
component: _import('demo/page1')
},
{
id: '10202',
path: '/page2',
title: '页面 2',
component: _import('demo/page2'),
auth: {
'operation': [{ //列表操作
id: '1020101',
name: '查看',
}, { //
id: '1020102',
name: '编辑',
}],
'action': [] //按钮操作
}
},
{
id: '10203',
path: '/page3',
title: '页面 3',
component: _import('demo/page3')
}
]
}
]
export default resources
\ No newline at end of file
......@@ -2,7 +2,8 @@ import { Message, MessageBox } from 'element-ui'
import util from '@/libs/util.js'
import router from '@/router'
import { AccountLogin } from '@api/sys.login'
import routesAll from '@/resources'
import {frameInRoutes} from "@/router/routes.js";
export default {
namespaced: true,
actions: {
......@@ -17,6 +18,7 @@ export default {
username = '',
password = ''
} = {}) {
// console.log(router.addRoutes);
return new Promise((resolve, reject) => {
// 开始请求登录接口
AccountLogin({
......@@ -31,9 +33,19 @@ export default {
// 如有必要 token 需要定时更新,默认保存一天
util.cookies.set('uuid', res.uuid)
util.cookies.set('token', res.token)
const {user,resources} = res
// // console.log(resources,routesAll);
// const __routes = []
// resources.forEach(obj => {
// frameInRoutes[0].children.push(util.deepFind(routesAll,obj.id))
// });
// frameInRoutes[0].children.push(...__routes);
// console.log(frameInRoutes[0].children.push(...__routes));
// router.addRoutes(frameInRoutes)
// 设置 vuex 用户信息
await dispatch('d2admin/user/set', {
name: res.name
name: user.name
}, { root: true })
// 用户登录后从持久化数据加载一系列的设置
await dispatch('load')
......@@ -106,6 +118,7 @@ export default {
await dispatch('d2admin/menu/asideCollapseLoad', null, { root: true })
// DB -> store 持久化数据加载全局尺寸
await dispatch('d2admin/size/load', null, { root: true })
// 后台接口 -> store
// end
resolve()
})
......
......@@ -75,9 +75,9 @@
<span>注册用户</span>
</p>
<!-- quick login -->
<el-button class="page-login--quick" size="default" type="info" @click="dialogVisible = true">
<!-- <el-button class="page-login--quick" size="default" type="info" @click="dialogVisible = true">
快速选择用户(测试功能)
</el-button>
</el-button> -->
</div>
</div>
<div class="page-login--content-footer">
......
......@@ -96,12 +96,12 @@ module.exports = {
config.resolve.alias
.set('@api', resolve('src/api'))
// 判断环境加入模拟数据
const entry = config.entry('app')
if (process.env.VUE_APP_BUILD_MODE !== 'nomock') {
entry
.add('@/mock')
.end()
}
// const entry = config.entry('app')
// if (process.env.VUE_APP_BUILD_MODE !== 'nomock') {
// entry
// .add('@/mock')
// .end()
// }
},
// i18n
pluginOptions: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!