Commit 398e987f by cwq0219

合并

2 parents 1154bc3f 553ccc5a
...@@ -7,9 +7,11 @@ import GlsxVueCommon from 'glsx-vue-common' ...@@ -7,9 +7,11 @@ import GlsxVueCommon from 'glsx-vue-common'
import { common } from '@/config' import { common } from '@/config'
import './styles/role-user-common.scss' import './styles/role-user-common.scss'
import './styles/index.scss' import './styles/index.scss'
import './date.js'
// import _ from 'lodash' // import _ from 'lodash'
import { Tree } from '@/components' import { MenuManager, Tree } from '@/components'
Vue.use(GlsxVueComponents) Vue.use(GlsxVueComponents)
Vue.component('menuManager', MenuManager)
Vue.component('tree', Tree) Vue.component('tree', Tree)
Vue.use(GlsxVueCommon, common) Vue.use(GlsxVueCommon, common)
......
import MenuManager from './src/main'
MenuManager.install = Vue => Vue.components(MenuManager.name, MenuManager)
export default MenuManager
<template>
<gl-row :gutter="150">
<gl-col :span='8'>
<div class="menu-box box">
<div class="title" v-html="title"></div>
<div class="console-btn">
<div><gl-button @click="openAll(openOrClose)">{{openOrClose ? '全部展开' : '全部收起'}}</gl-button></div>
<div><gl-button @click="pushSublings" type='primary' :disabled="push">添加同级菜单</gl-button></div>
<div><gl-button @click="pushChildren" type='primary' :disabled="push">添加子菜单</gl-button></div>
</div>
<tree
ref='tree'
@node-click='nodeClick'
></tree>
</div>
</gl-col>
<gl-col :span='16' v-show="showDetails">
<div class="details box">
<div class="title">详情</div>
<gl-form :model='form' class="content" label-width="150px">
<gl-form-item label="名称" >
<gl-input v-model="form.name" ref="name"></gl-input>
</gl-form-item>
<gl-form-item label="主机自定义名称">
<gl-input v-model="form.newName"></gl-input>
</gl-form-item>
<gl-form-item label="打开模式">
<gl-select v-model="form.open" style="width:100%">
<gl-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="功能类型">
<gl-select v-model="form.type" style="width:100%" placeholder="请选择功能类型">
<gl-option
v-for="item in options2"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="上级菜单">
<gl-input v-model="form.upMenu" disabled></gl-input>
</gl-form-item>
<gl-form-item label="菜单路径">
<gl-input v-model="form.url" disabled></gl-input>
</gl-form-item>
<gl-form-item label="路由">
<gl-input v-model="form.router"></gl-input>
</gl-form-item>
<gl-form-item label="基础路径">
<gl-input v-model="form.defaultUrl"></gl-input>
</gl-form-item>
<gl-form-item label="排序">
<gl-input v-model="form.index"></gl-input>
</gl-form-item>
<gl-form-item label="是否隐藏">
<gl-switch v-model="form.Show"></gl-switch>
</gl-form-item>
<gl-form-item label="创建时间">
<gl-input v-model="form.createTime" disabled></gl-input>
</gl-form-item>
<gl-form-item label="修改时间">
<gl-input v-model="form.changeTime" disabled></gl-input>
</gl-form-item>
<gl-form-item>
<gl-button type="primary" @click="submit">{{btnTxt}}</gl-button>
<gl-button type="danger" v-show='del' @click="delData">删除</gl-button>
<gl-button @click="showDetails = false" style="float:right">取消</gl-button>
</gl-form-item>
</gl-form>
</div>
</gl-col>
</gl-row>
</template>
<script>
var timeTip = '系统自动生成(格式yyyy-MM-dd HH:mm:ss)'
export default {
name: 'MenuManager',
data() {
return {
data: [],
props: null,
openOrClose: true,
node: null,
btnTxt: '修改',
allNode: null,
push: true,
del: true,
showDetails: false,
_children: false,
_sublings: false,
form: {
name: '',
newName: '',
open: '新系统',
type: '',
upMenu: '',
url: '',
router: '',
defaultUrl: '',
index: '',
Show: true,
createTime: null,
changeTime: null
},
options: [
{
value: '选项1',
label: '本系统'
},
{
value: '选项2',
label: '新系统'
}
],
options2: [
{
value: '选项1',
label: '菜单路由'
},
{
value: '选项2',
label: '菜单'
},
{
value: '选项3',
label: '按钮'
}
]
}
},
props: {
title: {
type: String,
default: '标题'
}
},
watch: {
'form.name'(val) {
if (val !== '') this.$refs.name.$el.classList.remove('err')
}
},
methods: {
nodeClick(data, node, that, props) {
if (node.level === 1) this.data = node.parent.data
this.btnTxt = '修改'
this.node = node
this.allNode = data
this.props = props
this._sublings = false
this._children = false
this.del = true
this.push = false
this.showDetails = true
this.form.name = data.label || data[props.label]
this.form.upMenu = node.level === 1 ? '顶级菜单' : node.parent.data.label || node.parent.data[props.label]
this.form.defaultUrl = data.path
this.form.index = node.data.id
this.form.createTime = data.createTime
this.form.changeTime = data.changeTime
},
// 展开与关闭
openAll(val) {
this.searchChildren(this.$refs.tree.$children[0].$children[0].store._getAllNodes(), val)
this.openOrClose = !this.openOrClose
},
searchChildren(data, val) {
data.forEach(el => {
el.expanded = val
if (el.childNodes) {
this.searchChildren(el.childNodes, val)
}
})
},
// 添加同级菜单
pushSublings() {
this.btnTxt = '保存'
this._sublings = true
this._children = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 添加子菜单
pushChildren() {
this.btnTxt = '保存'
this._children = true
this._sublings = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 删除
delData() {
for (let index = 0; index < this.node.parent.childNodes.length; index++) {
if (this.node.parent.childNodes[index] === this.node) this.node.level === 1 ? this.node.parent.data.splice(index, 1) : this.node.parent.data.children.splice(index, 1)
}
this.$notify({
title: '删除成功',
type: 'success'
})
this.$set_session_config(this.data)
this.showDetails = false
},
// 保存修改
submit() {
if (this.form.name !== '' && this.form.name !== null) {
let arr = {}
// 添加同级
if (this._sublings) {
arr = {
id: this.form.index,
level: this.node.level,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.node.level === 1) {
this.data.push(arr)
} else {
if (this.node.parent.data.children === undefined) this.$set(this.node.parent.data, 'children', [])
this.node.parent.data.children.push(arr)
}
} else if (this._children) { // 添加子级
arr = {
id: this.form.index,
level: this.node.level + 1,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.allNode.children === undefined) this.$set(this.allNode, 'children', [])
this.allNode.children.push(arr)
} else { // 修改
this.node.data.id = this.form.index
this.node.data[this.props.label] = this.form.name
if (this.node.data.changeTime === undefined) this.$set(this.node.data, 'changeTime', '')
this.node.data.changeTime = new Date().format('yyyy-MM-dd HH:mm:ss')
}
this.showDetails = false
this.$notify({
title: '操作成功',
type: 'success'
})
this.$set_session_config(this.data)
} else {
this.$refs.name.$el.classList.add('err')
}
}
}
}
</script>
<style scoped>
.content{
padding: 15px;
}
.box{
margin-bottom: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
}
.title{
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
padding: 10px 15px;
border-bottom: 1px solid transparent;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
.el-form-item{
margin-bottom: 15px;
}
.console-btn{
padding: 15px;
display: flex;
flex-wrap:wrap;
width: 100%;
box-sizing: border-box;
}
.console-btn div{
flex: 1;
height: 40px;
margin-bottom: 10px;
}
.err::after{
content: '请填写列表名称';
display: block;
color: red;
}
</style>
<template> <template>
<gl-row :gutter="150"> <div class="tree" :style="treeStyle">
<gl-col :span='8'> <gl-tree
<div class="menu-box box"> ref='tree'
<div class="title" v-html="title"></div> highlight-current
<gl-row v-if="consoleItem" class="console-btn"> :data='data'
<gl-col :span='8'><gl-button @click="openAll(openOrClose)">{{openOrClose ? '全部展开' : '全部收起'}}</gl-button></gl-col> :show-checkbox='showCheckbox'
<gl-col :span='16'> node-key='id'
<gl-button @click="pushSublings" type='primary' :disabled="push">添加同级菜单</gl-button> :props='props'
<gl-button @click="pushChildren" type='primary' :disabled="push">添加子菜单</gl-button> :default-expand-all='defaultExpandAll'
</gl-col> @check='check'
</gl-row> @node-click='nodeClick'
<div class="tree"> ></gl-tree>
<gl-tree </div>
ref='tree'
highlight-current
:data='data'
@node-click='nodeClick'
:show-checkbox='showCheckbox'
node-key='id'
:props='props'
></gl-tree>
</div>
</div>
</gl-col>
<gl-col :span='16' v-show="showDetails">
<div class="details box">
<div class="title">详情</div>
<gl-form :model='form' class="content" label-width="150px">
<gl-form-item label="名称" >
<gl-input v-model="form.name" ref="name"></gl-input>
</gl-form-item>
<gl-form-item label="主机自定义名称">
<gl-input v-model="form.newName"></gl-input>
</gl-form-item>
<gl-form-item label="打开模式">
<gl-select v-model="form.open" style="width:100%">
<gl-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="功能类型">
<gl-select v-model="form.type" style="width:100%" placeholder="请选择功能类型">
<gl-option
v-for="item in options2"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="上级菜单">
<gl-input v-model="form.upMenu" disabled></gl-input>
</gl-form-item>
<gl-form-item label="菜单路径">
<gl-input v-model="form.url" disabled></gl-input>
</gl-form-item>
<gl-form-item label="路由">
<gl-input v-model="form.router"></gl-input>
</gl-form-item>
<gl-form-item label="基础路径">
<gl-input v-model="form.defaultUrl"></gl-input>
</gl-form-item>
<gl-form-item label="排序">
<gl-input v-model="form.index"></gl-input>
</gl-form-item>
<gl-form-item label="是否隐藏">
<gl-switch v-model="form.Show"></gl-switch>
</gl-form-item>
<gl-form-item label="创建时间">
<gl-input v-model="form.createTime" disabled></gl-input>
</gl-form-item>
<gl-form-item label="修改时间">
<gl-input v-model="form.changeTime" disabled></gl-input>
</gl-form-item>
<gl-form-item>
<gl-button type="primary" @click="submit">{{btnTxt}}</gl-button>
<gl-button type="danger" v-show='del' @click="delData">删除</gl-button>
<gl-button @click="showDetails = false" style="float:right">取消</gl-button>
</gl-form-item>
</gl-form>
</div>
</gl-col>
</gl-row>
</template> </template>
<script> <script>
var timeTip = '系统自动生成(格式yyyy-MM-dd HH:mm:ss)'
export default { export default {
name: 'Tree', name: 'Tree',
data() { data() {
return { return {
openOrClose: true, data: this.$get_session_config().resources || this.$get_session_config(),
node: null, props: {
btnTxt: '修改', label: 'title'
allNode: null,
push: true,
del: true,
showDetails: false,
_children: false,
_sublings: false,
form: {
name: '',
newName: '',
open: '新系统',
type: '',
upMenu: '',
url: '',
router: '',
defaultUrl: '',
index: '',
Show: true,
createTime: null,
changeTime: null
},
options: [
{
value: '选项1',
label: '本系统'
},
{
value: '选项2',
label: '新系统'
}
],
options2: [
{
value: '选项1',
label: '菜单路由'
},
{
value: '选项2',
label: '菜单'
},
{
value: '选项3',
label: '按钮'
}
]
}
},
props: {
title: {
type: String,
default: '标题'
},
consoleItem: {
type: Boolean
},
data: {
type: Array,
default: () => []
},
showCheckbox: {
type: Boolean,
default: false
},
props: {
type: Object,
default: () => {
return {
lebel: 'label',
children: 'children'
}
} }
} }
}, },
watch: { props: {
'form.name'(val) { showCheckbox: Boolean,
if (val !== '') this.$refs.name.$el.classList.remove('err') value: null,
} defaultExpandAll: Boolean,
treeStyle: null
}, },
methods: { methods: {
nodeClick(data, node, that) { nodeClick(data, treeData, vue) {
this.btnTxt = '修改' this.$emit('node-click', data, treeData, vue, this.props)
this.node = node
this.allNode = data
this._sublings = false
this._children = false
this.del = true
this.push = false
this.showDetails = true
this.form.name = data.label || data[this.props.label]
this.form.upMenu = node.level === 1 ? '顶级菜单' : node.parent.data.label || node.parent.data[this.props.label]
this.form.defaultUrl = data.path
this.form.index = node.data.id
this.form.createTime = data.createTime
this.form.changeTime = data.changeTime
}, },
// 展开与关闭 check(data, treeData) {
openAll(val) { this.$emit('input', { data, treeData })
this.searchChildren(this.$refs.tree.$children[0].store._getAllNodes(), val)
this.openOrClose = !this.openOrClose
},
searchChildren(data, val) {
data.forEach(el => {
el.expanded = val
if (el.childNodes) {
this.searchChildren(el.childNodes, val)
}
})
},
// 添加同级菜单
pushSublings() {
this.btnTxt = '保存'
this._sublings = true
this._children = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 添加子菜单
pushChildren() {
this.btnTxt = '保存'
this._children = true
this._sublings = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 删除
delData() {
for (let index = 0; index < this.node.parent.childNodes.length; index++) {
if (this.node.parent.childNodes[index] === this.node) this.node.level === 1 ? this.node.parent.data.splice(index, 1) : this.node.parent.data.children.splice(index, 1)
}
this.$notify({
title: '删除成功',
type: 'success'
})
this.$set_session_config(this.data)
this.showDetails = false
},
// 保存修改
submit() {
if (this.form.name !== '' && this.form.name !== null) {
let arr = {}
if (this._sublings) {
arr = {
id: this.form.index,
level: this.node.level,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.node.level === 1) {
this.data.push(arr)
} else {
if (this.node.parent.data.children === undefined) this.$set(this.node.parent.data, 'children', [])
this.node.parent.data.children.push(arr)
}
} else if (this._children) {
arr = {
id: this.form.index,
level: this.node.level + 1,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.allNode.children === undefined) this.$set(this.allNode, 'children', [])
this.allNode.children.push(arr)
} else {
this.node.data.id = this.form.index
this.node.data[this.props.label] = this.form.name
if (this.node.data.changeTime === undefined) this.$set(this.node.data, 'changeTime', '')
this.node.data.changeTime = new Date().format('yyyy-MM-dd HH:mm:ss')
}
this.showDetails = false
this.$notify({
title: '操作成功',
type: 'success'
})
this.$set_session_config(this.data)
} else {
this.$refs.name.$el.classList.add('err')
}
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.tree{ .tree{
height: 650px; height: 550px;
overflow-y: scroll; overflow-y: scroll;
} }
.content{
padding: 15px;
}
.box{
margin-bottom: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
}
.title{
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
padding: 10px 15px;
border-bottom: 1px solid transparent;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
.el-form-item{
margin-bottom: 15px;
}
.console-btn{
padding: 15px;
}
.err::after{
content: '请填写列表名称';
display: block;
color: red;
}
</style> </style>
...@@ -3,10 +3,12 @@ import UserDetail from './UserDetail' ...@@ -3,10 +3,12 @@ import UserDetail from './UserDetail'
import RoleCreate from './RoleCreate' import RoleCreate from './RoleCreate'
import RoleDetail from './RoleDetail' import RoleDetail from './RoleDetail'
import Tree from './Tree' import Tree from './Tree'
import MenuManager from './MenuManager'
export { export {
UserCreate, UserCreate,
UserDetail, UserDetail,
RoleCreate, RoleCreate,
RoleDetail, RoleDetail,
Tree Tree,
MenuManager
} }
function format(formatStr) {
const date = this
var zeroize = function(value, length) {
if (!length) {
length = 2
}
for (var i = 0, zeros = ''; i < (length - value.length); i++) {
zeros += '0'
}
return zeros + value
}
return formatStr.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|M{1,4}|yy(?:yy)?|([hHmstT])\1?|[lLZ])\b/g, function($0) {
switch ($0) {
case 'd': return date.getDate()
case 'dd': return zeroize(date.getDate())
case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][date.getDay()]
case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getDay()]
case 'M': return date.getMonth() + 1
case 'MM': return zeroize(date.getMonth() + 1)
case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][date.getMonth()]
case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][date.getMonth()]
case 'yy': return date.getFullYear().substr(2)
case 'yyyy': return date.getFullYear()
case 'h': return date.getHours() % 12 || 12
case 'hh': return zeroize(date.getHours() % 12 || 12)
case 'H': return date.getHours()
case 'HH': return zeroize(date.getHours())
case 'm': return date.getMinutes()
case 'mm': return zeroize(date.getMinutes())
case 's': return date.getSeconds()
case 'ss': return zeroize(date.getSeconds())
case 'l': return date.getMilliseconds()
case 'll': return zeroize(date.getMilliseconds())
case 'tt': return date.getHours() < 12 ? 'am' : 'pm'
case 'TT': return date.getHours() < 12 ? 'AM' : 'PM'
}
})
}
const time = Date
time.prototype.format = format
<template> <template>
<div> <div>
<tree :data='res' :title="'菜单列表'" :props='props' consoleItem></tree> <menu-manager :title="'菜单列表'"></menu-manager>
</div> </div>
</template> </template>
...@@ -9,10 +9,6 @@ export default { ...@@ -9,10 +9,6 @@ export default {
name: 'menuMG', name: 'menuMG',
data() { data() {
return { return {
res: this.$get_session_config().resources,
props: {
label: 'title'
}
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!