Commit af8b3205 authored by 高宇's avatar 高宇

优化级联菜单用户体验;

parent 9804c50d
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
<img v-for="(source, index) in images" :key="index" :src="source" class="image"> <img v-for="(source, index) in images" :key="index" :src="source" class="image">
</div> </div>
<button type="button" class="button" @click="show">Show</button> <button type="button" class="button" @click="show">Show</button>
<el-cascader
v-model="cascader"
:options="filter[0].value"
:props="props"></el-cascader>
</div> </div>
</template> </template>
...@@ -15,15 +19,28 @@ ...@@ -15,15 +19,28 @@
} }
import 'viewerjs/dist/viewer.css' import 'viewerjs/dist/viewer.css'
import Viewer from 'viewerjs' import Viewer from 'viewerjs'
import {
requestAPI,
api
} from '@/lib/commonMixin'
export default { export default {
name: '', name: '',
data () { data () {
return { return {
filter: [{
value: []
}],
cascader: [],
options: { options: {
toolbar: true, toolbar: true,
url: 'data-source' url: 'data-source'
}, },
images: [] images: [],
props: {
value: 'id',
label: 'name',
children: 'value'
}
} }
}, },
methods: { methods: {
...@@ -44,6 +61,15 @@ ...@@ -44,6 +61,15 @@
mounted () { mounted () {
}, },
created () { created () {
requestAPI(api.getFilter).then(res => {
this.filter = res
console.log(this.filter)
})
},
watch: {
'cascader' (val) {
console.log(val)
}
} }
} }
</script> </script>
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
} from '@/lib/commonMixin' } from '@/lib/commonMixin'
import 'viewerjs/dist/viewer.css' import 'viewerjs/dist/viewer.css'
import Viewer from 'viewerjs' import Viewer from 'viewerjs'
export default { export default {
name: '', name: '',
components: { components: {
...@@ -241,11 +242,13 @@ ...@@ -241,11 +242,13 @@
item.cascader = [] item.cascader = []
} }
}) })
console.log(res)
return res return res
}, },
getFilter () { getFilter () {
requestAPI(api.getFilter).then(res => { requestAPI(api.getFilter).then(res => {
this.filter = this.updateOptions(res) this.filter = this.updateOptions(res)
console.log(this.filter)
}) })
} }
}, },
......
<template> <template>
<div> <div>
<el-row class="form-content"> <el-row class="form-content">
<el-form ref="clientForm" size="mini" :model="clientForm" label-width="0" label-position="top"> <el-form size="mini" :model="clientForm" label-width="0" label-position="top">
<el-col :span="4" v-for="(item, key) in filter" :key="key"> <el-col :span="4" v-for="(item, key) in filter" :key="key">
<el-form-item> <el-form-item>
<span slot="label" v-if="item.key !== 'Filter[sort]'"> <span slot="label" v-if="item.key !== 'Filter[sort]'">
...@@ -25,13 +25,14 @@ ...@@ -25,13 +25,14 @@
</el-option> </el-option>
</el-select> </el-select>
<el-cascader <el-cascader
:ref="'elCasc' + key"
v-model="item.cascader" v-model="item.cascader"
change-on-select :props="props"
clearable clearable
change-on-select
v-if="item.itemKey" v-if="item.itemKey"
:options="item.value" :options="item.value"
:props="cascaderOption" @change="setCascader(item, key)"
@change="setCascader(item)"
></el-cascader> ></el-cascader>
</el-form-item> </el-form-item>
</el-col> </el-col>
...@@ -42,22 +43,25 @@ ...@@ -42,22 +43,25 @@
<script> <script>
import {findWhere} from '../../lib/viewHelper' import {findWhere} from '../../lib/viewHelper'
import $ from 'jquery'
export default { export default {
name: 'client-form', name: 'client-form',
data () { data () {
return { return {
clientForm: {}, clientForm: {},
cascaderOption: { props: {
value: 'key',
label: 'name', label: 'name',
children: 'value' value: 'key',
children: 'child'
} }
} }
}, },
props: ['filter'], props: ['filter'],
methods: { methods: {
setCascader (item) { hideCascader (key) {
// this.$refs['elCasc' + key][0].menuVisible = false
},
setCascader (item, key) {
if (item.cascader.length === 1) { if (item.cascader.length === 1) {
this.clientForm[item.key] = item.cascader[0] this.clientForm[item.key] = item.cascader[0]
this.clientForm[item.itemKey] = '' this.clientForm[item.itemKey] = ''
...@@ -77,14 +81,13 @@ ...@@ -77,14 +81,13 @@
if (keys.parentNode) { if (keys.parentNode) {
this.clientForm[item.itemKey] = keys.parentNode.key this.clientForm[item.itemKey] = keys.parentNode.key
this.clientForm[item.key] = keys.node.key this.clientForm[item.key] = keys.node.key
item.cascader = [keys.parentNode.id, keys.node.key] item.cascader = [keys.parentNode.key, keys.node.key]
} else { } else {
this.clientForm[item.itemKey] = '' this.clientForm[item.itemKey] = ''
this.clientForm[item.key] = keys.node.key this.clientForm[item.key] = keys.node.key
item.cascader = [keys.node.key] item.cascader = [keys.node.key]
} }
} }
console.log(item.cascader)
} }
}) })
}, },
...@@ -92,6 +95,14 @@ ...@@ -92,6 +95,14 @@
this.$watch('clientForm', (val) => { this.$watch('clientForm', (val) => {
this.$emit('update:clientList', val) this.$emit('update:clientList', val)
}, {deep: true}) }, {deep: true})
let _this = this
$(document).ready(() => {
$(document).on('mouseleave', '.el-cascader-menus', () => {
Object.keys(_this.$refs).forEach(item => {
_this.$refs[item][0].menuVisible = false
})
})
})
}, },
setSortIcon () { setSortIcon () {
if (this.clientForm['Filter[sort]'] === '') { if (this.clientForm['Filter[sort]'] === '') {
...@@ -112,7 +123,7 @@ ...@@ -112,7 +123,7 @@
} }
} }
}, },
created () { mounted () {
}, },
watch: { watch: {
'filter' (val) { 'filter' (val) {
......
...@@ -64,11 +64,11 @@ let getNode = function (json, nodeId, type, nodeObj) { ...@@ -64,11 +64,11 @@ let getNode = function (json, nodeId, type, nodeObj) {
break break
} else { } else {
// 3.如果有子节点就开始找 // 3.如果有子节点就开始找
if (obj.value) { if (obj.child) {
// 4.递归前,记录当前节点,作为parent 父亲 // 4.递归前,记录当前节点,作为parent 父亲
nodeObj.parentNode = obj nodeObj.parentNode = obj
// 递归往下找 // 递归往下找
getNode(obj.value, nodeId, type, nodeObj) getNode(obj.child, nodeId, type, nodeObj)
} else { } else {
// 跳出当前递归,返回上层递归 // 跳出当前递归,返回上层递归
continue continue
......
...@@ -2,6 +2,7 @@ import clientList from '../components/workLog/list' ...@@ -2,6 +2,7 @@ import clientList from '../components/workLog/list'
import workLogOfClient from '../components/workLog/logOfClient/workLogOfClient' import workLogOfClient from '../components/workLog/logOfClient/workLogOfClient'
import workLogAdd from '../components/workLog/work/addLog' import workLogAdd from '../components/workLog/work/addLog'
import workLogEdit from '../components/workLog/work/editLog' import workLogEdit from '../components/workLog/work/editLog'
import test from '../components/test'
const projectTitle = '金畅逍BMS - ' const projectTitle = '金畅逍BMS - '
const routes = [ const routes = [
{ {
...@@ -34,6 +35,11 @@ const routes = [ ...@@ -34,6 +35,11 @@ const routes = [
path: '/workLogEdit/:id', path: '/workLogEdit/:id',
name: 'workLogEdit', name: 'workLogEdit',
component: workLogEdit component: workLogEdit
},
{
path: '/test',
name: 'test',
component: test
} }
] ]
export default routes export default routes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment