Commit e30a8d8f by cwq0219

合并

2 parents acd0d193 69ed5484
......@@ -3,7 +3,7 @@
# 页面 title 前缀
VUE_APP_TITLE=tFIMS
# 网络请求公用地址
# 网络请求公用地址 http://192.168.3.191:8944/router
VUE_APP_API=http://192.168.3.171:7300/mock/5d638b3b6fbe9a0ac59d872e/tFIMS
# 仓库地址
......
......@@ -26,7 +26,7 @@
"lodash": "^4.17.11",
"lowdb": "^1.0.0",
"nprogress": "^0.2.0",
"qs": "^6.7.0",
"qs": "^6.8.0",
"screenfull": "^4.2.0",
"ua-parser-js": "^0.7.19",
"vue": "^2.6.10",
......
<template>
<div id="app">
<router-view/>
<router-view />
</div>
</template>
......@@ -24,5 +24,5 @@ export default {
</script>
<style lang="scss">
@import '~@/assets/style/public-class.scss';
@import "~@/assets/style/public-class.scss";
</style>
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-26 18:02:41
* @Last Modified by: limin
* @Last Modified time: 2019-09-01 15:33:02
* @Last Modified time: 2019-09-05 19:03:24
*/
import axios from '@/plugin/axios'
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-26 18:02:55
* @Last Modified by: limin
* @Last Modified time: 2019-09-03 14:07:41
* @Last Modified time: 2019-09-05 18:22:50
*/
import request from './request'
......@@ -12,12 +12,16 @@ const user_path = 'fims.user.'
// 角色相关
const role_path = 'fims.role.'
export const LOGIN_URL = `${user_path}login`
export const Reg_URL = `${user_path}register`
export const Role_LIST_URL = `${role_path}list`
/**
* 用户登录
* @param {*} data 参数
*/
export function AccountLogin (data) {
data.method = `${user_path}login`
data.method = LOGIN_URL
return request(data, RequestMethods.POST)
}
......@@ -26,7 +30,7 @@ export function AccountLogin (data) {
* @param {*} data 参数
*/
export function Reg (data = {}) {
data.method = `${user_path}register`
data.method = Reg_URL
return request(data, RequestMethods.GET)
}
......@@ -40,6 +44,51 @@ export function UserList (data = {}) {
}
/**
* 重置密码
* @param {*} data 参数
*/
export function PassWordReset (data = {}) {
data.method = `${user_path}password.reset`
return request(data, RequestMethods.GET)
}
/**
* 帐户编辑
* @param {*} data 参数
*/
export function AccountModify (data = {}) {
data.method = `${user_path}modify`
return request(data, RequestMethods.GET)
}
/**
* 帐户延期
* @param {*} data 参数
*/
export function AccountIncrease (data = {}) {
data.method = `${user_path}validity.increase`
return request(data, RequestMethods.GET)
}
/**
* 帐户禁用
* @param {*} data 参数
*/
export function AccountForbidden (data = {}) {
data.method = `${user_path}forbidden`
return request(data, RequestMethods.GET)
}
/**
* 帐户审核
* @param {*} data 参数
*/
export function AccountValidate (data = {}) {
data.method = `${user_path}check`
return request(data, RequestMethods.GET)
}
/**
* 获取角色权限资源列表
* @param {*} data 参数
*/
......@@ -66,13 +115,12 @@ export function RoleModify (data = {}) {
return request(data, RequestMethods.GET)
}
/**
* 权限列表
* @param {*} data 参数
*/
export function RoleList (data = {}) {
data.method = `${role_path}list`
data.method = Role_LIST_URL
return request(data, RequestMethods.GET)
}
......
......@@ -2,12 +2,13 @@
* @Author: limin
* @Date: 2019-08-26 18:02:55
* @Last Modified by: limin
* @Last Modified time: 2019-09-02 10:49:21
* @Last Modified time: 2019-09-05 18:01:21
*/
import request from './request'
import RequestMethods from './request.methods'
export const BaseDataURL='fims.configuration.from.conftype'
// 基础数据
const path = 'fims.base.'
......@@ -59,6 +60,6 @@ export function PostList (data = {}) {
* @param {*} data 参数
*/
export function BaseDataApi (data = {}) {
data.method = `fims.configuration.from.conftype`
data.method = BaseDataURL
return request(data, RequestMethods.GET)
}
/*
* @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) {
data.method = `${path}login`
return request(data, RequestMethods.POST)
}
......@@ -22,4 +22,15 @@
}
.el-color-picker__trigger{
border-color:rgba(255,255,255,.1)
}
.el-table{
margin:4px 0 !important;
}
.el-dialog{
margin-top: 6vh !important;
&__footer {
.el-button {
width: 200px;
}
}
}
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-09-01 19:06:01
* @Author: limin
* @Date: 2019-09-01 19:06:01
* @Last Modified by: limin
* @Last Modified time: 2019-09-04 12:11:33
* @Last Modified time: 2019-09-06 12:22:40
*/
/**
* 前端基础数据管理对应的接口名称的key
*/
export const TYPE_NAME='confType'
import {LOGIN_URL,REG_URL,Role_LIST_URL} from '@/api/sys.account'
import {BaseDataURL} from '@/api/sys.base'
export const TYPE_NAME = 'confType'
/**
* 后台提供一个接 通过类型获取对应数据
* 此处定义类型
*/
export const ConfigType ={
STATION: 'STATION_TYPE',
POST:'POST_TYPE',
SUBSYS:'SUBSYSTEM_TYPE'
export const ConfigType = {
STATION: 'STATION_TYPE',
POST: 'POST_TYPE',
SUBSYS: 'SUBSYSTEM_TYPE'
}
/**
* 前端基础数据管理对应的接口名称的key
*/
export const BaseData = {
ROLE: {KEY:'role',TYPE:''},
// COMPANY: 'company',
// DEPART: 'depart',
STATION: {KEY:'station',TYPE:ConfigType.STATION},
POST:{KEY:'post',TYPE:ConfigType.POST},
SUBSYS:{KEY:'subsys',TYPE:ConfigType.SUBSYS}
ROLE: { KEY: 'role', TYPE: '' },
STATION: { KEY: 'station', TYPE: ConfigType.STATION },
POST: { KEY: 'post', TYPE: ConfigType.POST },
SUBSYS: { KEY: 'subsys', TYPE: ConfigType.SUBSYS }
}
/**
* 注册类型
*/
export const RegistType = {
BY_SELF: '1', // 自注册
BY_ADMIN: '2' // 管理员创建
}
/**
* 前端免登录验证接口名
*/
export const LogExternals = [
LOGIN_URL, //登录
REG_URL, // 注册
BaseDataURL, //基础数据
Role_LIST_URL //角色列表
]
/**
* 登录来源
*/
export const LOGIN_TYPE = 1 //1pc,2小程序
/**
* 超级管理员类型
*/
export const SUPPER_ADMIN = 1 //
\ No newline at end of file
......@@ -13,7 +13,7 @@ export default {
// type: String,
// default: 'text'
// },
category:{
category: {
type: String,
default: 'operation'
},
......@@ -37,60 +37,60 @@ export default {
type: Object,
default: null
},
data: Object,
data: Object
},
functional: true , // 开启函数化组件
functional: true, // 开启函数化组件
render: (h, ctx) => {
const _this = ctx.parent //获取 vue this 实例
const _this = ctx.parent // 获取 vue this 实例
// console.log(ctx);
/**
* 获取传入参数
* category 非必填 button 类别 暂时两种 1 表格操作:operation ,2 Button 按钮: action 默认 operation ----- route 中不标明 视为默认值 operation
* 获取传入参数
* category 非必填 button 类别 暂时两种 1 表格操作:operation ,2 Button 按钮: action 默认 operation ----- route 中不标明 视为默认值 operation
* data 点击按钮时 需要得到的参数 比如 table 中的 当前行数据 row
* mapping 非必填 但: 当列表中的操作选项 根据 某个字段 变化的话 必填 且 必须 注明 field: 字段名
* label 当传入label 字段时 标识明确指定渲染该label 的按钮
* label 当传入label 字段时 标识明确指定渲染该label 的按钮
*/
const { category , data , mapping, label } = ctx.props
const { category, data, mapping, label } = ctx.props
let curBtns = []
/**
* 判断一个按钮(btn)是否存在与当前行(data) 的映射关系(mapping)中
* @param {*} btn
* @param {*} btn
*/
const filter = btn => mapping ? mapping[data[mapping['field']]].includes(btn.label):true
const filter = btn => mapping ? mapping[data[mapping['field']]].includes(btn.label) : true
const $store = _this.$store.getters['d2admin/auth/curBtns']
if(!$store) return h('div')
if(label){ //指定label
const __item = $store.find(btn => (btn.label === label) && filter(btn))
if (!$store) return h('div')
if (label) { // 指定label
const __item = $store.find(btn => (btn.label === label) && filter(btn))
__item && curBtns.push(__item)
}else {
} else {
/**
* 拿到当前模块(页面) 所拥有按钮列表 过滤type属性 与 映射关系 返回需要显示的按钮列表
*/
curBtns = $store.filter(btn => {
if(category === 'operation'){
curBtns = $store.filter(btn => {
if (category === 'operation') {
return (btn.category === 'operation' || !btn.category) && filter(btn)
}
return (btn.category === category) && filter(btn)
})
}
if(curBtns.length===0) return h('div')
if (curBtns.length === 0) return h('div')
const __aBtns = []
/**
* 循环最终显示的按钮列表
* 循环最终显示的按钮列表
* 并渲染到页面
*/
curBtns.forEach(btn =>
__aBtns.push(h('el-button', {
props: {
type:btn.type||'text',
type: btn.type || 'text'
},
style:{
color:btn.color
style: {
color: btn.color
},
on: {
click: ()=>btn.handle && _this[btn.handle](data)
click: (e) => btn.handle && _this[btn.handle](data, e)
}
}, [btn.label])))
return h('div', {}, [...__aBtns,ctx.children])
return h('div', {}, [...__aBtns, ctx.children])
}
}
\ No newline at end of file
}
/*
* @Author: limin
* @Date: 2019-09-06 10:12:23
* @Last Modified by: limin
* @Last Modified time: 2019-09-06 13:23:25
*/
import Vue from 'vue'
import * as filters from './src'
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key])
})
/*
* @Author: limin
* @Date: 2019-09-06 10:11:24
* @Last Modified by: limin
* @Last Modified time: 2019-09-06 13:30:14
*/
const dateFormat = (dateStr,time)=>{
//得到特定的时间
var date = new Date(dateStr);
var year = date.getFullYear();
//ES6语法填充:var month = (date.getMonth()+1).toString().padStart(2, '0');
var month = date.getMonth()+1<10 ? '0'+ (date.getMonth()+1) : date.getMonth()+1;
var day = date.getDate()<10 ? '0' + date.getDate() : date.getDate();
var hh = date.getHours()<10 ? '0' + date.getHours() : date.getHours();
var mm = date.getMinutes()<10 ? '0' + date.getMinutes() : date.getMinutes();
var ss = date.getSeconds()<10 ? '0' + date.getSeconds() : date.getSeconds();
//return `${year}-${month}-${day}`;
if(time&&time.toLowerCase() === 'yyyy-mm-dd'){
return `${year}-${month}-${day}`;
}else if(time&&time.toLowerCase() === 'hh:mm:ss'){
return `${hh}:${mm}:${ss}`;
}else{
console.log(1);
return `${year}-${month}-${day} ${hh}:${mm}:${ss}`;
}
}
export { dateFormat }
......@@ -11,7 +11,7 @@
</el-dropdown-menu>
</el-dropdown>-->
<div v-popover:popover-personal class="d2-mr personal-wrap">
<span class="btn-text">{{info.name ? `${info.name}` : '未登录'}}</span>
<span class="btn-text">{{info.userName ? `${info.userName}` : '未登录'}}</span>
<el-popover ref="popover-personal" placement="bottom-end" trigger="hover">
<personal-panel :user="info"></personal-panel>
</el-popover>
......
......@@ -8,12 +8,12 @@
></el-avatar>
</div>
<div class="name-role">
<span class="sender">{{ user.name }} - {{ user.role||'超级管理员' }}</span>
<span class="sender">{{ user.userName }} - {{ user.roleType||'' }}</span>
</div>
<div class="registe-info">
<span class="registe-info">
<li class="fa fa-clock-o"></li>
注册时间:{{ user.registeInfo|| '2019-08-08' }}
有效期:{{user.validTime || '未知' }}
</span>
</div>
</div>
......@@ -51,15 +51,7 @@ import { Message, MessageBox } from 'element-ui'
export default {
name: 'PersonalPanel',
props: {
user: {
type: Object,
default: {
name: 'admin',
avatar: '@/assets/user.png',
role: '超级管理员',
registeInfo: '注册时间:2018-12-25 '
}
}
user: Object
},
computed: {
...mapState('d2admin/user', ['info'])
......@@ -99,7 +91,7 @@ export default {
type: 'warning'
}).then(async () => {
await this.$store.commit('d2admin/gray/set', false)
localStorage.clear();
localStorage.clear()
window.location.reload()
})
.catch(() => {
......
......@@ -3,7 +3,10 @@ import LocalStorage from 'lowdb/adapters/LocalStorage'
import util from '@/libs/util'
import { cloneDeep } from 'lodash'
const adapter = new LocalStorage(`d2admin-${process.env.VUE_APP_VERSION}`)
const adapter = new LocalStorage(`d2admin-${process.env.VUE_APP_VERSION}`, {
serialize: (data) => escape(JSON.stringify(data)),
deserialize: (data) => JSON.parse(unescape(data))
})
const db = low(adapter)
db
......
......@@ -106,4 +106,31 @@ util.colorToRgb = (sColor, alpha) => {
}
}
/**
* 重置form
* 用法: util.resetForm.call(this,'formName')
*/
util.resetForm = function (formName) {
this.$nextTick(() => {
for (var key in this[formName]) {
if (this[formName].hasOwnProperty(key)) {
this[formName][key] = ''
}
}
this.$refs[formName] && this.$refs[formName].resetFields()
})
}
/**
* 扁平化 routes (@/router/routes)
*/
util.flatten=function(arr) {
return arr.reduce((result, item)=> {
item.authId= item.authId || item.meta.authId
item.parentId= item.parentId || item.meta.parentId
const cloneItem= util.deepClone(item)
delete cloneItem.auth
return result.concat(item.auth ? util.flatten([...item.auth,cloneItem]) : item);
}, []);
}
export default util
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-27 19:16:26
* @Last Modified by: limin
* @Last Modified time: 2019-09-04 00:48:28
* @Last Modified time: 2019-09-06 13:08:53
*/
const permision = {}
/**
......@@ -93,7 +93,7 @@ permision.packMenusBtns = function (resources) {
}
let __aParent = []
let __aSub = []
let __aAll =[]
let __aAll = []
/**
* 第一次循环 分出一级菜单与所有子菜单
*/
......@@ -104,10 +104,10 @@ permision.packMenusBtns = function (resources) {
}
if (__oMenu.parentId === '0') { // 取出1级菜单
__aParent.push(__oMenu)
__aAll.push(__oMenu)
if (__oMenu.auth){
__aAll = [...__aAll,...__oMenu.auth]
}
// __aAll.push(__oMenu)
// if (__oMenu.auth) {
// __aAll = [...__aAll, ...__oMenu.auth]
// }
} else { // 取出子菜单
__aSub.push(__oMenu)
}
......@@ -117,10 +117,10 @@ permision.packMenusBtns = function (resources) {
*/
let __parent = null
__aSub.forEach(obj => {
__aAll.push(obj)
if (obj.auth){
__aAll = [...__aAll,...obj.auth]
}
// __aAll.push(obj)
// if (obj.auth) {
// __aAll = [...__aAll, ...obj.auth]
// }
__parent = __aParent.find(menu => menu.authId === obj.parentId)
if (__parent.children) {
__parent.children.push(obj)
......@@ -128,7 +128,7 @@ permision.packMenusBtns = function (resources) {
__parent.children = [obj]
}
})
return {menus:__aParent,all:__aAll}
return { menus: __aParent, all: __aAll }
}
/**
......@@ -136,14 +136,14 @@ permision.packMenusBtns = function (resources) {
*/
permision.format2Menu = function (oMenu) {
if (!oMenu) return null
const {icon, path, meta} = oMenu
const {title, authId, parentId} = meta
const { icon, path, meta } = oMenu
const { title, authId, parentId } = meta
return {
title,
icon,
path,
authId,
parentId}
parentId }
}
/**
......@@ -151,14 +151,14 @@ permision.format2Menu = function (oMenu) {
*/
permision.format2ResourceMenu = function (oMenu) {
if (!oMenu) return null
const {icon, meta, auth} = oMenu
const {title, authId, parentId} = meta
const { icon, meta, auth } = oMenu
const { title, authId, parentId } = meta
return {
label:title,
label: title,
icon,
authId,
parentId,
auth}
auth }
}
export default permision
import store from '@/store'
import axios from 'axios'
import { Message } from 'element-ui'
import {
Message
} from 'element-ui'
import util from '@/libs/util'
import router from '@/router'
import {
LogExternals
} from '@/common/constants'
axios.defaults.withCredentials = true
import qs from 'qs'
const expiresMinute = 10
// 创建一个错误
function errorCreate (msg) {
function errorCreate(msg) {
const error = new Error(msg)
errorLog(error)
throw error
}
// 记录和显示错误
function errorLog (error) {
function errorLog(error) {
// 添加到日志
store.dispatch('d2admin/log/push', {
message: '数据请求异常',
......@@ -42,11 +50,27 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
config => {
// 在请求发送之前做一些处理
const token = util.cookies.get('token')
// 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
config.headers['X-Token'] = token
return config
config.transformRequest = [function (data) {
return qs.stringify(data)
}]
return new Promise(async resolve => {
const {
url,
data
} = config
if (!LogExternals.some(u => u === url || u === data.method)) {
const token = util.cookies.get('token')
if (!token || token === 'undefined') {
await store.dispatch('d2admin/account/logout')
router.replace('/login')
}
}
const inExpiresMinutes = new Date(new Date().getTime() + expiresMinute * 60 * 1000);
util.cookies.set('token', 'token', {
expires: inExpiresMinutes
})
resolve(config)
})
},
error => {
// 发送失败
......@@ -61,43 +85,58 @@ service.interceptors.response.use(
// dataAxios 是 axios 返回数据中的 data
const dataAxios = response.data
// 这个状态码是和后端约定的
const { code } = dataAxios
// 根据 code 进行判断
if (code === undefined) {
// 如果没有 code 代表这不是项目后端开发的接口 比如可能是 D2Admin 请求最新版本
return dataAxios
} else {
// 有 code 代表这是一个后端接口 可以进行进一步的判断
switch (+code) {
case 0:
// [ 示例 ] code === 0 代表没有错误
return dataAxios.data
case 'xxx':
// [ 示例 ] 其它和后台约定的 code
errorCreate(`[ code: xxx ] ${dataAxios.msg}: ${response.config.url}`)
break
default:
// 不是正确的 code
errorCreate(`${dataAxios.msg}: ${response.config.url}`)
break
}
const {
code,data
} = dataAxios
// 有 code 代表这是一个后端接口 可以进行进一步的判断
switch (+code) {
case 0:
// [ 示例 ] code === 0 代表没有错误
return data
default:
// 不是正确的 code
errorCreate(`code:${code} ${dataAxios.message}---${dataAxios.solution}`)
break
}
},
error => {
if (error && error.response) {
switch (error.response.status) {
case 400: error.message = '请求错误'; break
case 401: error.message = '未授权,请登录'; break
case 403: error.message = '拒绝访问'; break
case 404: error.message = `请求地址出错: ${error.response.config.url}`; break
case 408: error.message = '请求超时'; break
case 500: error.message = '服务器内部错误'; break
case 501: error.message = '服务未实现'; break
case 502: error.message = '网关错误'; break
case 503: error.message = '服务不可用'; break
case 504: error.message = '网关超时'; break
case 505: error.message = 'HTTP版本不受支持'; break
default: break
case 400:
error.message = '请求错误';
break
case 401:
error.message = '未授权,请登录';
break
case 403:
error.message = '拒绝访问';
break
case 404:
error.message = `请求地址出错: ${error.response.config.url}`;
break
case 408:
error.message = '请求超时';
break
case 500:
error.message = '服务器内部错误';
break
case 501:
error.message = '服务未实现';
break
case 502:
error.message = '网关错误';
break
case 503:
error.message = '服务不可用';
break
case 504:
error.message = '网关超时';
break
case 505:
error.message = 'HTTP版本不受支持';
break
default:
break
}
}
errorLog(error)
......@@ -105,4 +144,4 @@ service.interceptors.response.use(
}
)
export default service
export default service
\ No newline at end of file
......@@ -10,6 +10,9 @@ import '@/assets/svg-icons'
// 指令
import '@/directives'
// 过滤器
import '@/filters'
// 功能插件
import pluginError from '@/plugin/error'
import pluginLog from '@/plugin/log'
......
......@@ -41,25 +41,7 @@ router.beforeEach(async (to, from, next) => {
await store.dispatch('d2admin/auth/init')
await store.dispatch('d2admin/account/load')
next(to.path)
} else if (to.matched.some(r => r.meta.auth)) { // 验证当前路由所有的匹配中是否需要有登录验证的
// 这里暂时将cookie里是否存有token作为验证是否登录的条件
// 请根据自身业务需要修改
const token = util.cookies.get('token')
if (token && token !== 'undefined') {
next()
} else {
// 没有登录的时候跳转到登录界面
// 携带上登陆成功之后需要跳转的页面完整路径
next({
name: 'login',
query: {
redirect: to.fullPath
}
})
NProgress.done()
}
} else {
// 不需要身份校验 直接通过
next()
}
})
......
......@@ -31,11 +31,11 @@ export const home = {
auth: [{
authId: '10101',
parentId: '101',
label: '导出',
type: 'button',
category:'Button',
handle: 'exportFile'
}]
label: '导出',
type: 'button',
category: 'Button',
handle: 'exportFile'
}]
}
export const sys = [
// 系统 前端日志
......@@ -68,71 +68,6 @@ export const sys = [
* 所有需动态过滤的资源点
*/
export const resources = {
// '102': {
// path: '/page',
// icon: 'folder-o',
// name: '页面',
// meta: {
// auth: true,
// title: '页面',
// authId: '102',
// parentId: '0',
// cache: true
// }
// },
// '10201': {
// path: '/page1',
// name: 'page1',
// meta: {
// auth: true,
// title: '页面 1',
// authId: '10201',
// parentId: '102',
// cache: true
// },
// component: _import('demo/page1')
// },
// '10202': {
// path: '/page2',
// name: 'page2',
// meta: {
// auth: true,
// title: '页面 2',
// authId: '10202',
// parentId: '102',
// cache: true
// },
// component: _import('demo/page2'),
// auth: [{ // 列表操作
// authId: '1020201',
// parentId: '10202',
// label: '查看'
// }, { //
// authId: '1020202',
// parentId: '10202',
// label: '编辑'
// }],
// },
// '10203': {
// path: '/page3',
// name: '页面 3',
// meta: {
// auth: true,
// title: '页面 3',
// authId: '10203',
// parentId: '102'
// },
// auth: [{ // 列表操作
// authId: '1020301',
// parentId: '10203',
// label: '查看'
// }, { //
// authId: '1020302',
// parentId: '10203',
// label: '编辑'
// }],
// component: _import('demo/page3')
// },
'102': {
path: '/trafficManagement',
icon: 'train',
......@@ -147,21 +82,21 @@ export const resources = {
auth: [{
authId: '10201',
parentId: '102',
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10202',
parentId: '102',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10203',
parentId: '102',
label: '添加车辆',
category: 'Button',
type: 'button',
handle: 'handleEdit'
}]
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10202',
parentId: '102',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10203',
parentId: '102',
label: '添加车辆',
category: 'Button',
type: 'button',
handle: 'handleEdit'
}]
},
'103': {
path: '/subSysManagement',
......@@ -177,21 +112,21 @@ export const resources = {
auth: [{
authId: '10301',
parentId: '103',
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10302',
parentId: '103',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10303',
parentId: '103',
label: '添加子系统',
category: 'Button',
type: 'button',
handle: 'handleEdit'
}]
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10302',
parentId: '103',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10303',
parentId: '103',
label: '添加子系统',
category: 'Button',
type: 'button',
handle: 'handleEdit'
}]
},
'104': {
path: '/deviceManagement',
......@@ -207,27 +142,27 @@ export const resources = {
auth: [{
authId: '10401',
parentId: '104',
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10402',
parentId: '104',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10403',
parentId: '104',
label: '导出',
type:'button',
category:'Button',
handle: 'exportFile'
}, {
authId: '10404',
parentId: '104',
label: '导入',
type:'button',
category:'Button'
}]
label: '编辑',
handle: 'handleEdit'
}, {
authId: '10402',
parentId: '104',
label: '删除',
handle: 'handleDelete'
}, {
authId: '10403',
parentId: '104',
label: '导出',
type: 'button',
category: 'Button',
handle: 'exportFile'
}, {
authId: '10404',
parentId: '104',
label: '导入',
type: 'button',
category: 'Button'
}]
},
'105': {
path: 'materialList',
......@@ -240,7 +175,7 @@ export const resources = {
authId: '105',
parentId: '0'
},
component: _import('materialList'),
component: _import('materialList')
},
'106': {
path: '/bb',
......@@ -267,21 +202,21 @@ export const resources = {
auth: [{
authId: '1060101',
parentId: '10601',
label: '查看详情',
handle: 'handleDetail'
}, {
authId: '1060102',
parentId: '10601',
label: '删除',
handle: 'handleDelete'
}, {
authId: '1060103',
parentId: '10601',
label: '订单下载',
category: 'Button',
type: 'button',
handle: 'exportFile'
}]
label: '查看详情',
handle: 'handleDetail'
}, {
authId: '1060102',
parentId: '10601',
label: '删除',
handle: 'handleDelete'
}, {
authId: '1060103',
parentId: '10601',
label: '订单下载',
category: 'Button',
type: 'button',
handle: 'exportFile'
}]
},
'10602': {
path: '/maintainManagement',
......@@ -297,16 +232,16 @@ export const resources = {
auth: [{
authId: '1060201',
parentId: '10602',
label: '删除',
handle: 'handleDelete'
}, {
authId: '1060202',
parentId: '10602',
label: '导出订单',
category: 'Button',
type: 'button',
handle: 'exportOrder'
}]
label: '删除',
handle: 'handleDelete'
}, {
authId: '1060202',
parentId: '10602',
label: '导出订单',
category: 'Button',
type: 'button',
handle: 'exportOrder'
}]
},
'107': {
path: '/users',
......@@ -333,35 +268,40 @@ export const resources = {
authId: '1070101',
parentId: '10701',
label: '审核',
handle:'handleEdit'
handle: 'handleOperation'
}, { //
authId: '1070102',
parentId: '10701',
label: '重置密码'
label: '重置密码',
handle: 'handleOperation'
}, { //
authId: '1070103',
parentId: '10701',
label: '编辑'
label: '编辑',
handle: 'handleEdit'
}, { //
authId: '1070104',
parentId: '10701',
label: '延期'
label: '延期',
handle: 'handleOperation'
}, { //
authId: '1070105',
parentId: '10701',
label: '禁用',
color:'#FF0000'
color: '#FF0000',
handle: 'handleOperation'
}, { //
authId: '1070106',
parentId: '10701',
label: '激活'
label: '激活',
handle: 'handleOperation'
}, { // 列表操作
authId: '1070107',
parentId: '10701',
label: '创建用户',
category:'action',
type:'button',
handle:'handleRegister'
category: 'action',
type: 'button',
handle: 'handleRegister'
}],
component: _import('userManage/user')
},
......@@ -375,18 +315,18 @@ export const resources = {
authId: '10702',
parentId: '107'
},
auth:[{
authId:'1070201',
parentId:'10702',
label:'创建角色',
handle: "handleEdit",
type:'button'
},{
authId:'1070202',
parentId:'10702',
label:'权限编辑',
handle: "handleEdit",
type:'text'
auth: [{
authId: '1070201',
parentId: '10702',
label: '创建角色',
handle: 'handleEdit',
type: 'button'
}, {
authId: '1070202',
parentId: '10702',
label: '权限编辑',
handle: 'handleEdit',
type: 'text'
}],
component: _import('userManage/role')
},
......@@ -440,6 +380,10 @@ export const errorPage = {
// 导出需要显示菜单的
export const frameInRoutes = frameIn
export const localRoutes ={
...resources, [home.meta.authId]: home
}
// 重新组织后导出
export default [
// ...resources,
......@@ -447,4 +391,4 @@ export default [
// dashboard,
...frameOut,
errorPage
]
\ No newline at end of file
]
import util from '@/libs/util.js'
import router from '@/router'
import { cloneDeep } from 'lodash'
import { AccountLogin } from '@api/sys.account'
import { SUPPER_ADMIN } from '@/common/constants'
import { resources as sources, home } from '@/router/routes'
export default {
namespaced: true,
actions: {
......@@ -21,21 +23,20 @@ export default {
AccountLogin({
username,
password
})
.then(async res => {
}).then(async (data={}) => {
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
// 整个系统依赖这两个数据进行校验和存储
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
// token 代表用户当前登录状态 建议在网络请求中携带 token
// 如有必要 token 需要定时更新,默认保存一天
util.cookies.set('uuid', res.uuid)
util.cookies.set('token', res.token)
const { user, authes } = res
util.cookies.set('uuid', data.loginName)
const authes = data.roleType === SUPPER_ADMIN ?
util.flatten(Object.values({...sources, [home.meta.authId]: home }))
.map(obj=>({authId:obj.authId,parentId:obj.parentId}))
:cloneDeep(data.authes) && delete data.authes
await dispatch('d2admin/auth/set', authes, { root: true })
// 设置 vuex 用户信息
await dispatch('d2admin/user/set', {
name: user.name
}, { root: true })
await dispatch('d2admin/user/set', data, { root: true })
// 强制初始化基础数据
dispatch('d2admin/base/init', null, { root: true })
// 用户登录后从持久化数据加载一系列的设置
......
......@@ -2,11 +2,11 @@
* @Author: limin
* @Date: 2019-08-27 17:25:12
* @Last Modified by: limin
* @Last Modified time: 2019-09-04 10:44:27
* @Last Modified time: 2019-09-06 13:12:51
*/
import util from '@/libs/util.js'
import router from '@/router'
import { resources as sources, home, frameInRoutes, sys } from '@/router/routes'
import { localRoutes, home, frameInRoutes, sys } from '@/router/routes'
export default {
namespaced: true,
state: {
......@@ -118,12 +118,12 @@ export default {
// 获取权限资源点
const __source = await dispatch('load')
// 过滤资源点 并动态添加到路由
const { route, btn } = util.permision.packRoutesBtns({...sources,[home.meta.authId]:home}, __source)
const { route, btn } = util.permision.packRoutesBtns(localRoutes, __source)
frameInRoutes[0].children = [home, ...route, ...sys]
router.addRoutes(frameInRoutes)
state.btns = btn
await commit('d2admin/page/init', frameInRoutes, { root: true })
const __aMenus = [util.permision.format2Menu(home), ...util.permision.packAsideMenus(sources, __source)]
const __aMenus = util.permision.packAsideMenus(localRoutes, __source)
// 过滤左侧菜单栏
await commit('d2admin/menu/asideSet', __aMenus, { root: true })
// 初始化页面搜索
......
......@@ -5,8 +5,8 @@
* @Last Modified time: 2019-09-04 14:06:32
*/
import { FetchRoleList, CompanyList, DepartList, StationList,PostList , BaseDataApi } from '@/api/sys.base'
import { BaseData,TYPE_NAME,ConfigType } from '@/common/constants'
import { FetchRoleList, CompanyList, DepartList, StationList, PostList, BaseDataApi } from '@/api/sys.base'
import { BaseData, TYPE_NAME, ConfigType } from '@/common/constants'
const map = {
[BaseData.ROLE.KEY]: FetchRoleList,
// [BaseData.COMPANY]: CompanyList,
......@@ -22,16 +22,16 @@ export default {
role: [],
// 站点
station: [],
//职务
post:[],
//子系统
subsys:[]
// 职务
post: [],
// 子系统
subsys: []
},
actions: {
/**
* 初始化获取 基础数据 并 前端持久化
* 每次登录会强制 初始化
* @param {*} param0
* @param {*} param0
*/
init ({ state, dispatch, commit }) {
return new Promise(async resolve => {
......@@ -39,17 +39,17 @@ export default {
FetchRoleList(),
// CompanyList(),
// DepartList(),
BaseDataApi({[TYPE_NAME]:ConfigType.STATION}),
BaseDataApi({[TYPE_NAME]:ConfigType.POST}),
BaseDataApi({[TYPE_NAME]:ConfigType.SUBSYS})
BaseDataApi({ [TYPE_NAME]: ConfigType.STATION }),
BaseDataApi({ [TYPE_NAME]: ConfigType.POST }),
BaseDataApi({ [TYPE_NAME]: ConfigType.SUBSYS })
]).then( async ([role,station, post,subsys] = res) => {
]).then(async ([role, station, post, subsys] = res) => {
state.role = role
state.station = station
state.subsys = subsys
state.post = post
await dispatch('save2db', {path: `base`,value: {role, station,post,subsys}})
resolve({role, station,post,subsys})
await dispatch('save2db', { path: `base`, value: { role, station, post, subsys } })
resolve({ role, station, post, subsys })
})
})
},
......@@ -62,11 +62,11 @@ export default {
*/
get ({ state, dispatch }, name) {
return new Promise(async resolve => {
let __data = state[name]
let __data = state[name]
if (!__data.length) {
__data = await dispatch('getFromdb', `base.${name}`) || await dispatch('getFromAjax', name)
state[name] = __data
await dispatch('save2db', {path: `base.${name}`,value: __data})
await dispatch('save2db', { path: `base.${name}`, value: __data })
}
resolve(__data)
})
......@@ -75,20 +75,20 @@ export default {
* 获取所有基础数据
* 获取步骤:
* 内存 -> 前端持久化数据库 -> 后台接口
* @param {*} param0
* @param {*} param0
*/
load ({ state,dispatch }) {
load ({ state, dispatch }) {
return new Promise(async resolve => {
if (state.role.length === 0) {
state = await dispatch('getFromdb','base') || await dispatch('init')
state = await dispatch('getFromdb', 'base') || await dispatch('init')
}
const {role, station,post,subsys} = state
resolve({role, station,post,subsys})
const { role, station, post, subsys } = state
resolve({ role, station, post, subsys })
})
},
/**
* 内部方法 从前端持久化数据库 获取指定数据
* @param {*} param0
* @param {*} param0
* @param {*} path 数据 路径
*/
getFromdb ({ dispatch }, path) {
......@@ -104,10 +104,10 @@ export default {
/**
* 内部方法 前端持久化 一个 数据
* @param {*} param0
* @param {*} param0
* @param {*} param1 value 需要持久化的数据 path 需要持久化的数据路径
*/
save2db ({ dispatch }, {value,path}) {
save2db ({ dispatch }, { value, path }) {
return new Promise(async resolve => {
await dispatch('d2admin/db/set', {
dbName: 'database',
......@@ -120,12 +120,12 @@ export default {
},
/**
* 从后端获取一个数据
* @param {*} param0
* @param {*} param0
* @param {*} name @/common/constants/BaseData 中的常量
*/
getFromAjax ({ state, dispatch, commit }, name) {
return new Promise(async resolve => {
const value = await map[name]({[TYPE_NAME]:BaseData.find(data=>data.KEY===name).TYPE})
const value = await map[name]({ [TYPE_NAME]: BaseData.find(data => data.KEY === name).TYPE })
resolve(value)
})
}
......
......@@ -45,7 +45,12 @@ export default {
clear ({ state, dispatch }) {
return new Promise(async resolve => {
await dispatch('set', {})
await dispatch('d2admin/db/set', {
dbName: 'database',
path: 'user',
value: {},
user: true
}, { root: true })
resolve()
})
}
......
......@@ -248,7 +248,7 @@ export default {
notice.errorTips()
})
},
exportFile () {
const params = this.getParams()
exportApi(params).then(res => {
......
......@@ -28,7 +28,7 @@ export default {
type: Boolean,
default: false
},
title: ''
// title:
},
mounted () {},
......
......@@ -4,7 +4,7 @@
title="用户注册"
:visible.sync="dialogVisible"
:before-close="handleClose"
width="720px"
width="680px"
custom-class="reg-dialog"
>
<el-form
......@@ -15,33 +15,33 @@
:rules="rules"
>
<el-form-item label="用户名:" prop="loginName">
<el-input v-model="regForm.loginName" requred maxlength="10" placeholder="请输入用户名"></el-input>
<el-input v-model="regForm.loginName" requred maxlength="10" clearable placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item label="密码:" prop="password">
<el-input type="password" v-model="regForm.password" placeholder="请输入密码"></el-input>
<el-input type="password" v-model="regForm.password" placeholder="请输入密码" clearable></el-input>
</el-form-item>
<el-form-item label="确认密码:" prop="confirm">
<el-input type="password" v-model="regForm.confirm" placeholder="请再输入一次密码"></el-input>
<el-input type="password" v-model="regForm.confirm" placeholder="请再输入一次密码" clearable ></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="姓名:" prop="userName">
<el-input v-model="regForm.userName" placeholder="请输入姓名"></el-input>
<el-input v-model="regForm.userName" placeholder="请输入姓名" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系方式:" prop="mobile">
<el-input v-model="regForm.mobile" placeholder="请输入联系方式"></el-input>
<el-input v-model="regForm.mobile" placeholder="请输入联系方式" clearable></el-input>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="所属公司:" prop="companyName">
<el-input v-model="regForm.companyName" placeholder="请输入公司名称"></el-input>
<el-input v-model="regForm.companyName" placeholder="请输入公司名称" clearable ></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="部门:" prop="departName">
<el-input v-model="regForm.departName" placeholder="请输入部门名称"></el-input>
<el-input v-model="regForm.departName" placeholder="请输入部门名称" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
......@@ -71,6 +71,7 @@
</el-form>
<div slot="footer">
<el-button @click="submit" type="primary" class="button-submit">提交</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
</div>
</el-dialog>
</template>
......@@ -78,6 +79,7 @@
import { Reg } from '@/api/sys.account'
import { mapActions } from 'vuex'
import notice from '@/common/notice'
import { RegistType } from '@/common/constants'
export default {
name: 'DialogReg',
props: {
......@@ -95,12 +97,13 @@ export default {
return {
company: [],
regForm: {
createType: RegistType.BY_SELF, // 1 自注册 2 管理员创建
loginName: '',
password: '',
confirm: '',
userName: '',
mobile: '',
companyName: [],
companyName: '',
departName: '',
postCode: '',
stationCode: ''
......@@ -144,10 +147,10 @@ export default {
mobile: [
{ required: true, message: '联系方式不能为空', trigger: ['blur'] }
],
companyCode: [
companyName: [
{ required: true, message: '所属公司不能为空', trigger: ['blur'] }
],
departCode: [
departName: [
{ required: true, message: '部门不能为空', trigger: ['blur'] }
],
postCode: [
......@@ -158,37 +161,19 @@ export default {
]
}),
// //职务列表
// posts:Object.freeze([{
// id:'1',name:'站长'
// },{
// id:'2',name:'维修人员'
// },{
// id:'3',name:'部门经理'
// },{
// id:'4',name:'仓库管理'
// },{
// id:'5',name:'副总经理'
// },{
// id:'6',name:'总经理'
// }]),
/* -----------------------基础数据---------------------- */
baseData: {
// 所属站点
stations: [],
// 职务
posts: [],
// 部门
departs: [],
// 公司
companys: []
}
}
},
methods: {
...mapActions('d2admin/base', ['load']),
handleClose (done) {
handleClose () {
this.$refs.regForm.resetFields()
this.$event.$emit('e-reg-dialog', false)
},
// 提交注册数据
......@@ -198,32 +183,17 @@ export default {
var __p = this.regForm
Reg(__p).then(res => {
notice.okTips('注册信息已提交,请等待管理员审核')
this.$refs.regForm.resetFields()
this.$event.$emit('e-reg-dialog', false)
this.handleClose()
})
}
})
},
// 加载业务所需所有数据
async fetchData () {
const { role, company, depart, station,post } = await this.load()
const { role, company, depart, station, post } = await this.load()
this.baseData.posts = post
this.baseData.stations = station
this.baseData.departs = depart
this.baseData.companys = company
Object.freeze(this.baseData)
// Promise.all([
// FetchRoleList(),
// CompanyList(),
// DepartList(),
// StationList()
// ]).then(([role, company, depart, station] = res) => {
// this.baseData.roles = role
// this.baseData.stations = station
// this.baseData.departs = depart
// this.baseData.companys = company
// Object.freeze(this.baseData)
// })
}
},
mounted () {
......@@ -239,7 +209,7 @@ $login-dialog-font: 13px;
box-shadow: 0 8px 20px 0 rgba(0, 0, 0, 0.06);
border-radius: 9px;
.reg-dialog-form {
width: 500px;
width: 600px;
.el-form-item {
margin-bottom: 20px;
.el-input__inner {
......@@ -268,24 +238,13 @@ $login-dialog-font: 13px;
// }
}
.el-dialog__footer {
padding: 0 0 50px 230px !important;
.button-submit {
width: 145px;
height: 35px;
border-radius: 2px;
letter-spacing: 2px;
font-size: 14px;
line-height: 35px;
padding-top:0;
display: flex;
justify-content: center;
box-sizing: border-box;
span {
transform: translateY(-12px);
}
}
justify-content: flex-end;
// padding: 0 0 38px 0 !important;
}
.sigle-select {
width: 380px;
width: 100%;
}
}
</style>
import page from './page'
export default page
......@@ -42,6 +42,7 @@
v-on:keyup.native.13="submit"
v-model="formLogin.loginName"
placeholder="请输入用户名"
clearable
v-focus >
<i slot="prepend" class="fa fa-user-circle-o"></i>
</el-input>
......@@ -51,22 +52,21 @@
type="password"
v-model="formLogin.password"
v-on:keyup.native.13="submit"
clearable
placeholder="请输入密码">
<i slot="prepend" class="fa fa-keyboard-o"></i>
</el-input>
</el-form-item>
<el-form-item class="form-action">
<el-button
size="default"
@click="submit"
type="primary"
class="button-login">
登录
</el-button>
<el-button
size="default"
@click.prevent="openRegisterDialog"
type="primary"
@click.prevent="registerDialogVisible = true"
plain
class="button-reg">
注册
</el-button>
......@@ -95,10 +95,11 @@
<script>
import dayjs from 'dayjs'
import { mapActions } from 'vuex'
import { mapActions,mapState } from 'vuex'
import { LOGIN_TYPE } from '@/common/constants'
export default {
components: {
'DialogReg': () => import('./dialogReg')
'DialogReg': () => import('./dialogReg'),
},
data () {
return {
......@@ -109,7 +110,7 @@ export default {
formLogin: {
loginName: 'admin',
password: 'admin',
code: 'v9am'
loginType: LOGIN_TYPE
},
// 表单校验
rules: Object.freeze({
......@@ -144,43 +145,19 @@ export default {
refreshTime () {
this.time = dayjs().format('HH:mm:ss')
},
/**
* @description 接收选择一个用户快速登录的事件
* @param {Object} user 用户信息
*/
handleUserBtnClick (user) {
this.formLogin.loginName = user.loginName
this.formLogin.password = user.password
this.submit()
},
openRegisterDialog () {
this.registerDialogVisible = !this.registerDialogVisible
},
/**
* @description 提交表单
*/
// 提交登录信息
submit () {
// console.log(navigator.userAgent.toLocaleLowerCase())
this.$refs.loginForm.validate((valid) => {
if (valid) {
const { browser , os } = this.$store.state.d2admin.ua.data
const _p = {...this.formLogin,deviceCode:`${os.name}${os.version}-${browser.name}${browser.version}`}
// 登录
// 注意 这里的演示没有传验证码
// 具体需要传递的数据请自行修改代码
this.login({
loginName: this.formLogin.loginName,
password: this.formLogin.password,
loginType: 1,
deviceCode: 'chrome'
})
.then(() => {
this.$store.dispatch('d2admin/auth/init').then(_ => {
// 重定向对象不存在则返回顶层路径
console.log(this.$route.query.redirect)
console.log(this.$route)
this.$router.replace(this.$route.query.redirect || '/')
})
})
this.login(_p)
.then(() => this.$store.dispatch('d2admin/auth/init'))
.then(_ => this.$router.replace(this.$route.query.redirect || '/'))
} else {
// 登录表单校验失败
this.$message.error('表单校验失败,请检查')
......@@ -192,6 +169,7 @@ export default {
</script>
<style lang="scss">
@import '~@/components/d2-icon/font-awesome-4.7.0/css/font-awesome.min.css';
.page-login {
@extend %unable-select;
$backgroundColor: #2A343D;
......
......@@ -122,7 +122,7 @@ import notice from '@/common/notice'
import { mapActions } from 'vuex'
// import { BaseData } from '@/common/constants'
require('echarts/lib/chart/pie')
require("echarts/lib/component/tooltip");
require('echarts/lib/component/tooltip')
let echarts = require('echarts/lib/echarts')
......
<template>
<el-dialog
center
title="添加角色"
:visible.sync="dialogVisible"
:title="roleForm.roleId?'编辑角色':'创建角色'"
:before-close="handleClose"
:visible.sync="dialogVisible"
width="720px"
custom-class="edit-dialog"
custom-class="edit-role-dialog"
v-if="dialogVisible"
>
<el-form
ref="editForm"
:model="editForm"
ref="roleForm"
:model="roleForm"
label-width="120px"
class="edit-dialog-form"
:rules="rules"
>
<el-form-item label="角色名:" prop="roleName">
<el-input v-model="editForm.roleName" requred maxlength="10" placeholder="请输入角色名"></el-input>
<el-input v-model="roleForm.roleName" requred maxlength="10" clearable placeholder="请输入角色名"></el-input>
</el-form-item>
<el-form-item label="描述:">
<el-input
type="textarea"
:rows="2"
placeholder="角色描述"
v-model="editForm.description">
clearable
v-model="roleForm.description">
</el-input>
</el-form-item>
</el-form>
<span>权限设置</span>
<RoleTree :resources="resources" :checkedNodes.sync="checkedNodes" :defaultCheck="checked" :close="dialogVisible"></RoleTree>
<el-divider content-position="left">权限设置</el-divider>
<RoleTree :resources="resources" :checkedNodes.sync="checkedNodes" :defaultCheck="defaultCheck" :close="dialogVisible"></RoleTree>
<div slot="footer">
<el-button @click="submit" type="primary" class="button-submit">保存</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
......@@ -38,8 +39,8 @@
import { Reg } from '@/api/sys.account'
import { mapActions } from 'vuex'
import notice from '@/common/notice'
import RoleTree from "./roleTree"
import { resources as sources, home } from '@/router/routes'
import RoleTree from './roleTree'
import { localRoutes } from '@/router/routes'
import util from '@/libs/util.js'
export default {
name: 'editDialog',
......@@ -48,30 +49,42 @@ export default {
type: Boolean,
default: false
},
datas: {
editData: {
type: Object,
default: {},
default: {}
}
},
components:{
components: {
RoleTree
},
watch: {
editData: {
handler: function (value) {
Object.assign(this.roleForm, value)
this.defaultCheck = this.roleForm.roles
},
immediate: true
}
},
computed: {
dialogVisible () {
if (!this.isVisible) {
util.resetForm.call(this, 'roleForm')
}
return this.isVisible
},
resources() {
return util.permision.packMenusBtns(util.deepClone(Object.values({...sources,[home.meta.id]:home})))
},
checked() {
return this.datas.roles
resources () {
const clone = util.deepClone(Object.values(localRoutes))
const { menus }= util.permision.packMenusBtns(clone)
const all = util.flatten(clone)
return { menus,all }
}
},
data () {
return {
key:new Date(),
checkedNodes:[],
editForm: {
defaultCheck: '',
checkedNodes: [],
roleForm: {
roleName: '',
description: ''
},
......@@ -84,7 +97,6 @@ export default {
},
methods: {
handleClose (done) {
this.$refs.editForm.resetFields();
this.$event.$emit('e-reg-dialog', false)
},
// 提交注册数据
......@@ -100,25 +112,16 @@ export default {
// })
// }
// })
},
}
},
mounted () {
this.$event.$on('e-role-data',(data)=>{
console.log(2);
this.$event.$emit('e-default-role-check',data.roles)
})
// this.checkedNodes = this.data.roles
// console.log(this.checkedNodes);
// this.fetchData()
}
}
</script>
<style lang="scss">
.edit-dialog {
.el-dialog__footer{
.el-button{
width: 200px;
}
.edit-role-dialog {
.el-divider--horizontal{
margin: 30px 0px 20px;
}
}
</style>
......@@ -27,99 +27,101 @@
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:current-page="page.pageCount"
:page-sizes="[10,20,30,40]"
:page-size="pageSize"
:total="total"
:page-size="page.pageSize"
:total="page.total"
layout="sizes,total,->,prev,pager,next,jumper"
></el-pagination>
<edit-dialog
:isVisible="editVisible"
:datas="editData"
:editData="editData"
></edit-dialog>
</d2-container>
</template>
<script>
import { RoleList } from "@/api/sys.account";
import notice from "@/common/notice";
import { RoleList } from '@/api/sys.account'
import notice from '@/common/notice'
import util from '@/libs/util'
export default {
name: "FimsRoles",
name: 'FimsRoles',
components: {
'EditDialog':() => import('./editDialog')
'EditDialog': () => import('./editDialog')
},
data() {
data () {
return {
// 新增/编辑弹窗
editVisible: false,
editData:{
roles:[],
editData: {
roles: []
},
// 表格
tableLoading: false,
tableData: [],
tableColumns:Object.freeze([
tableColumns: Object.freeze([
{
label: "角色名称",
prop: "roleName"
label: '角色名称',
prop: 'roleName'
},
{
label: "描述",
prop: "description"
label: '描述',
prop: 'description'
},
{
label: "创建时间",
prop: "createTime"
label: '创建时间',
prop: 'createTime'
}
]),
page: {
// 页码
pageCount: 1,
pageSize: 10
pageCount: 1, // 每页条数
pageSize: 10, // 页码
total: 100
}
};
}
},
mounted() {
this.fetchData();
mounted () {
this.fetchData()
this.$event.$on('e-reg-dialog', res => this.editVisible = res)
},
methods: {
fetchData() {
this.loadRoleList();
fetchData () {
this.loadRoleList()
},
loadRoleList() {
this.tableLoading = true;
loadRoleList () {
this.tableLoading = true
RoleList()
.then(res => {
this.tableData = res;
// Object.freeze(this.tableData)
this.tableLoading = false;
this.tableData = res
// Object.freeze(this.tableData)
this.tableLoading = false
})
.catch(err => {
notice.errorTips(err);
this.tableLoading = false;
});
notice.errorTips(err)
this.tableLoading = false
})
},
// 页码
handleSizeChange(value) {
this.page.pageSize = value;
handleSizeChange (value) {
this.page.pageSize = value
// 调接口
this.loadRoleList();
this.loadRoleList()
},
handleCurrentChange(value) {
this.page.pageCount = value;
handleCurrentChange (value) {
this.page.pageCount = value
// 调接口
this.loadRoleList();
this.loadRoleList()
},
handleEdit(row = {}) {
row.roles = [{authId:'101',parentId:'0'},{authId:'10601',parentId:'106'},{authId:'1060101',parentId:'10601'}]
this.editVisible = true;
this.editData = row
handleEdit (row ) {
row && (row.roles = [{ authId: '101', parentId: '0' }, { authId: '10601', parentId: '106' }, { authId: '1060101', parentId: '10601' }])
this.editVisible = true
this.editData = util.deepClone(row)
}
}
};
}
</script>
<style scoped>
</style>
......@@ -5,9 +5,10 @@
show-checkbox
ref="tree"
node-key="authId"
default-expand-all
@check-change="checkChange"
:expand-on-click-node="false"
:default-expand-all="false"
:check-on-click-node="true"
@check-change="treeCheckChange"
:expand-on-click-node="true"
>
<span class="role-tree-node" slot-scope="{ node, data }">
<span>{{ node.label }}</span>
......@@ -18,7 +19,7 @@
v-for="(btn,index) in data.auth"
:key="index"
:label="btn.authId"
@change="(sta)=>change(node,btn,sta)"
@change="(sta)=>btnChange(node,btn,sta)"
>{{btn.label}}</el-checkbox>
</el-checkbox-group>
</template>
......@@ -28,10 +29,10 @@
</div>
</template>
<script>
import util from "@/libs/util.js";
import util from '@/libs/util.js'
export default {
data() {
return { checked: [] };
data () {
return { checked: [] }
},
props: {
resources: {
......@@ -41,70 +42,70 @@ export default {
defaultCheck: [],
close: false
},
mounted() {
// this.$event.$on("e-default-role-check", roles => {
// console.log(3);
// });
},
watch: {
close(value) {
close (value) {
// !value && this.reset();
},
defaultCheck: {
handler(value) {
let chk = [],
treeChk = [];
handler (value) {
if (!value) return
let chk = []
let treeChk = []
value.forEach(v => {
if (v.parentId.length >= 5) {
// TODO 不科学
chk.push(v.authId);
chk.push(v.authId)
} else {
treeChk.push(v.authId);
treeChk.push(v.authId)
}
});
setTimeout(() => {
this.$refs.tree.setCheckedKeys(treeChk);
this.checked = chk;
}, 0);
})
this.$nextTick(() => {
this.$refs.tree.setCheckedKeys(treeChk)
this.checked = chk
})
},
immediate: true
}
},
methods: {
checkChange(node, checked, childChecked) {
treeCheckChange (node, checked, childChecked) {
// if(node.parentId ==='0') return
// this.checked=checked?[...this.resources.all.filter(res=> res.parentId === node.authId),...this.checked]:this.checked.filter(obj=>obj.parentId!==node.authId)
this.setCheckedNodes();
// !checked && (this.checked = this.checked.filter(obj=>this.resources.all.find( res => res.authId === obj).parentId!==node.authId))
this.setCheckedNodes()
},
change(node, data, sta) {
// let checked = sta //|| this.checked.some(child => child.parentId === node.key && child.authId !== data.authId);
// checked && this.$refs.tree.setChecked(node.key, checked, true);
this.setCheckedNodes();
btnChange (node, data, sta) {
let checked = sta //|| this.checked.some(child => child.parentId === node.key && child.authId !== data.authId);
checked && this.$refs.tree.setChecked(node.key, checked, true);
this.setCheckedNodes()
},
setCheckedNodes() {
setCheckedNodes () {
const { getCheckedKeys, getHalfCheckedKeys } = this.$refs.tree
let checkedNodes = [
...this.$refs.tree.getCheckedKeys(),
...this.$refs.tree.getHalfCheckedKeys(),
...getCheckedKeys(),
...getHalfCheckedKeys(),
...this.checked
];
]
checkedNodes = checkedNodes.map(node => {
const { authId, parentId } = this.resources.all.find(res => res.authId === node);
return { authId, parentId };
});
this.$emit("update:checkedNodes", checkedNodes);
const { authId, parentId } = this.resources.all.find(
res => res.authId === node
)
return { authId, parentId }
})
this.$emit('update:checkedNodes', checkedNodes)
},
reset() {
this.checked = [];
this.$refs.tree.setCheckedKeys([]);
this.$emit("update:checkedNodes", []);
reset () {
this.checked = []
this.$refs.tree.setCheckedKeys([])
this.$emit('update:checkedNodes', [])
}
}
};
}
</script>
<style lang="scss">
.role-tree {
padding-left: 30px;
padding-left: 30px;
.role-tree-node {
flex: 1;
display: flex;
......@@ -117,8 +118,8 @@ export default {
height: 34px;
.el-checkbox {
margin-right: 5px;
.el-checkbox__label{
padding: 0;
.el-checkbox__label {
padding: 0;
}
}
}
......@@ -128,8 +129,8 @@ export default {
white-space: normal;
position: absolute;
left: 200px;
background-color: rgba(0,0,0,.05);
background-color: rgba(0, 0, 0, 0.05);
padding: 5px 0;
}
}
</style>
\ No newline at end of file
</style>
<template>
<el-dialog
:title="regForm.id?'编辑用户':'创建用户'"
:visible.sync="dialogVisible"
:before-close="handleClose"
width="720px"
custom-class="reg-dialog-admin"
v-if="dialogVisible"
:append-to-body="true"
:lock-scroll="false"
>
<el-form
ref="regForm"
:model="regForm"
label-width="120px"
class="reg-dialog-form"
:rules="rules"
>
<el-form-item label="用户名:" prop="loginName">
<el-input v-model="regForm.loginName" requred maxlength="10" placeholder="请输入用户名" clearable ></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="姓名:" prop="userName">
<el-input v-model="regForm.userName" placeholder="请输入姓名" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系方式:" prop="mobile">
<el-input v-model="regForm.mobile" placeholder="请输入联系方式" clearable></el-input>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="所属公司:" prop="companyName">
<el-input v-model="regForm.companyName" placeholder="请输入公司名称" clearable></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="部门:" prop="departName">
<el-input v-model="regForm.departName" placeholder="请输入部门名称" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="职务:" prop="postCode">
<el-select v-model="regForm.postCode" placeholder="请选择">
<el-option
:label="post.confValue"
:value="post.confCode"
v-for="(post,index) in baseData.posts"
:key="index"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="角色:" prop="roleId">
<el-select v-model="regForm.roleId" placeholder="请选择">
<el-option
:label="role.roleName"
:value="role.roleId"
v-for="(role,index) in baseData.roles"
:key="index"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="所属站点:" prop="stationCode">
<el-select v-model="regForm.stationCode" placeholder="请选择">
<el-option
:label="station.confValue"
:value="station.confCode"
v-for="(station,index) in baseData.stations"
:key="index"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer">
<el-button @click="submit" type="primary" class="button-submit">提交</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
</div>
</el-dialog>
</template>
<script>
import { Reg } from '@/api/sys.account'
import { mapActions } from 'vuex'
import notice from '@/common/notice'
import { RegistType } from '@/common/constants'
import util from '@/libs/util'
export default {
name: 'DialogReg',
props: {
isVisible: {
type: Boolean,
default: false
},
editData: {
type: Object,
default: {}
}
},
watch: {
editData: {
handler: function (value) {
Object.assign(this.regForm, value)
console.log(this.regForm)
},
immediate: true
}
},
computed: {
dialogVisible () {
if (!this.isVisible) {
util.resetForm.call(this, 'regForm')
}
return this.isVisible
}
},
data () {
return {
regForm: {
createType: RegistType.BY_ADMIN, // 1 自注册 2 管理员创建
loginName: '',
userName: '',
mobile: '',
companyName: '',
departName: '',
postCode: '',
stationCode: '',
roleId: ''
},
resetForm: {},
rules: Object.freeze({
loginName: [
{ required: true, message: '用户名不能为空', trigger: ['blur'] }
],
userName: [
{ required: true, message: '姓名不能为空', trigger: ['blur'] }
],
mobile: [
{ required: true, message: '联系方式不能为空', trigger: ['blur'] }
],
companyName: [
{ required: true, message: '所属公司不能为空', trigger: ['blur'] }
],
departName: [
{ required: true, message: '部门不能为空', trigger: ['blur'] }
],
postCode: [
{ required: true, message: '职务不能为空', trigger: ['blur'] }
],
stationCode: [
{ required: true, message: '所属站点不能为空', trigger: ['blur'] }
],
roleId: [{ required: true, message: '角色不能为空', trigger: ['blur'] }]
}),
/* -----------------------基础数据---------------------- */
baseData: {
// 所属站点
stations: [],
// 职务
posts: [],
// roles
roles: []
}
}
},
methods: {
...mapActions('d2admin/base', ['load']),
handleClose (done) {
this.$event.$emit('e-reg-dialog', false)
},
// 提交注册数据
submit () {
this.$refs.regForm.validate(vaild => {
if (vaild) {
var __p = this.regForm
Reg(__p).then(res => {
notice.okTips('创建成功')
this.$event.$emit('e-reg-dialog', false)
})
}
})
},
// 加载业务所需所有数据
async fetchData () {
const { role, station, post } = await this.load()
this.baseData.posts = post
this.baseData.stations = station
this.baseData.roles = role
Object.freeze(this.baseData)
}
},
mounted () {
this.fetchData()
}
}
</script>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!