Commit e30a8d8f by cwq0219

合并

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