Commit cc99477e by musnow

update indexOf rewrite to includes

parent cdb1ac7c
...@@ -26,7 +26,7 @@ export default { ...@@ -26,7 +26,7 @@ export default {
default: false default: false
} }
}, },
data () { data() {
return { return {
openKeys: [], openKeys: [],
selectedKeys: [], selectedKeys: [],
...@@ -34,17 +34,17 @@ export default { ...@@ -34,17 +34,17 @@ export default {
} }
}, },
computed: { computed: {
rootSubmenuKeys: (vm) => { rootSubmenuKeys: vm => {
const keys = [] const keys = []
vm.menu.forEach(item => keys.push(item.path)) vm.menu.forEach(item => keys.push(item.path))
return keys return keys
} }
}, },
created () { created() {
this.updateMenu() this.updateMenu()
}, },
watch: { watch: {
collapsed (val) { collapsed(val) {
if (val) { if (val) {
this.cachedOpenKeys = this.openKeys this.cachedOpenKeys = this.openKeys
this.openKeys = [] this.openKeys = []
...@@ -52,94 +52,79 @@ export default { ...@@ -52,94 +52,79 @@ export default {
this.openKeys = this.cachedOpenKeys this.openKeys = this.cachedOpenKeys
} }
}, },
'$route': function () { $route: function() {
this.updateMenu() this.updateMenu()
} }
}, },
methods: { methods: {
renderIcon: function (h, icon) { renderIcon: function(h, icon) {
return icon === 'none' || icon === undefined ? null return icon === 'none' || icon === undefined ? null : h(Icon, { props: { type: icon !== undefined ? icon : '' } })
: h(Icon, { props: { type: icon !== undefined ? icon : '' } }) },
}, renderMenuItem: function(h, menu, pIndex, index) {
renderMenuItem: function (h, menu, pIndex, index) { return h(Item, { key: menu.path ? menu.path : 'item_' + pIndex + '_' + index }, [
return h(Item, { key: menu.path ? menu.path : 'item_' + pIndex + '_' + index }, h('router-link', { attrs: { to: { name: menu.name } } }, [
[
h(
'router-link',
{ attrs: { to: { name: menu.name } } },
[
this.renderIcon(h, menu.meta.icon), this.renderIcon(h, menu.meta.icon),
h('span', [ menu.meta.title ]) h('span', [menu.meta.title])
] ])
) ])
]
)
}, },
renderSubMenu: function (h, menu, pIndex, index) { renderSubMenu: function(h, menu, pIndex, index) {
const this2_ = this const this2_ = this
const subItem = [ h('span', const subItem = [h('span', { slot: 'title' }, [this.renderIcon(h, menu.meta.icon), h('span', [menu.meta.title])])]
{ slot: 'title' },
[
this.renderIcon(h, menu.meta.icon),
h('span', [ menu.meta.title ])
]
) ]
const itemArr = [] const itemArr = []
const pIndex_ = pIndex + '_' + index const pIndex_ = pIndex + '_' + index
if (!menu.alwaysShow) { if (!menu.alwaysShow) {
menu.children.forEach(function (item, i) { menu.children.forEach(function(item, i) {
itemArr.push(this2_.renderItem(h, item, pIndex_, i)) itemArr.push(this2_.renderItem(h, item, pIndex_, i))
}) })
} }
return h( return h(SubMenu, { key: menu.path ? menu.path : 'submenu_' + pIndex + '_' + index }, subItem.concat(itemArr))
SubMenu,
{ key: menu.path ? menu.path : 'submenu_' + pIndex + '_' + index },
subItem.concat(itemArr)
)
}, },
renderItem: function (h, menu, pIndex, index) { renderItem: function(h, menu, pIndex, index) {
if (!menu.hidden) { if (!menu.hidden) {
return menu.children && !menu.alwaysShow ? this.renderSubMenu(h, menu, pIndex, index) : this.renderMenuItem(h, menu, pIndex, index) return menu.children && !menu.alwaysShow
? this.renderSubMenu(h, menu, pIndex, index)
: this.renderMenuItem(h, menu, pIndex, index)
} }
}, },
renderMenu: function (h, menuTree) { renderMenu: function(h, menuTree) {
const this2_ = this const this2_ = this
const menuArr = [] const menuArr = []
menuTree.forEach(function (menu, i) { menuTree.forEach(function(menu, i) {
if (!menu.hidden) { if (!menu.hidden) {
menuArr.push(this2_.renderItem(h, menu, '0', i)) menuArr.push(this2_.renderItem(h, menu, '0', i))
} }
}) })
return menuArr return menuArr
}, },
onOpenChange (openKeys) { onOpenChange(openKeys) {
const latestOpenKey = openKeys.find(key => this.openKeys.indexOf(key) === -1) const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key))
if (this.rootSubmenuKeys.indexOf(latestOpenKey) === -1) { if (!this.rootSubmenuKeys.includes(latestOpenKey)) {
this.openKeys = openKeys this.openKeys = openKeys
} else { } else {
this.openKeys = latestOpenKey ? [ latestOpenKey ] : [] this.openKeys = latestOpenKey ? [latestOpenKey] : []
} }
}, },
updateMenu () { updateMenu() {
const routes = this.$route.matched.concat() const routes = this.$route.matched.concat()
if (routes.length >= 4 && this.$route.meta.hidden) { if (routes.length >= 4 && this.$route.meta.hidden) {
routes.pop() routes.pop()
this.selectedKeys = [ routes[2].path ] this.selectedKeys = [routes[2].path]
} else { } else {
this.selectedKeys = [ routes.pop().path ] this.selectedKeys = [routes.pop().path]
} }
const openKeys = [] const openKeys = []
if (this.mode === 'inline') { if (this.mode === 'inline') {
routes.forEach((item) => { routes.forEach(item => {
openKeys.push(item.path) openKeys.push(item.path)
}) })
} }
this.collapsed ? this.cachedOpenKeys = openKeys : this.openKeys = openKeys this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
} }
}, },
render (h) { render(h) {
return h( return h(
Menu, Menu,
{ {
...@@ -151,12 +136,13 @@ export default { ...@@ -151,12 +136,13 @@ export default {
}, },
on: { on: {
openChange: this.onOpenChange, openChange: this.onOpenChange,
select: (obj) => { select: obj => {
this.selectedKeys = obj.selectedKeys this.selectedKeys = obj.selectedKeys
this.$emit('select', obj) this.$emit('select', obj)
} }
} }
}, this.renderMenu(h, this.menu) },
this.renderMenu(h, this.menu)
) )
} }
} }
...@@ -9,10 +9,10 @@ import { asyncRouterMap, constantRouterMap } from '@/config/router.config' ...@@ -9,10 +9,10 @@ import { asyncRouterMap, constantRouterMap } from '@/config/router.config'
*/ */
function hasPermission(permission, route) { function hasPermission(permission, route) {
if (route.meta && route.meta.permission) { if (route.meta && route.meta.permission) {
let flag = -1 let flag = false
for (let i = 0, len = permission.length; i < len; i++) { for (let i = 0, len = permission.length; i < len; i++) {
flag = route.meta.permission.indexOf(permission[i]) flag = route.meta.permission.includes(permission[i])
if (flag >= 0) { if (flag) {
return true return true
} }
} }
...@@ -31,7 +31,7 @@ function hasPermission(permission, route) { ...@@ -31,7 +31,7 @@ function hasPermission(permission, route) {
// eslint-disable-next-line // eslint-disable-next-line
function hasRole(roles, route) { function hasRole(roles, route) {
if (route.meta && route.meta.roles) { if (route.meta && route.meta.roles) {
return route.meta.roles.indexOf(roles.id) return route.meta.roles.includes(roles.id)
} else { } else {
return true return true
} }
......
<template> <template>
<div class="page-header-index-wide page-header-wrapper-grid-content-main"> <div class="page-header-index-wide page-header-wrapper-grid-content-main">
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :md="24" :lg="7"> <a-col :md="24" :lg="7">
<a-card :bordered="false"> <a-card :bordered="false">
<div class="account-center-avatarHolder"> <div class="account-center-avatarHolder">
<div class="avatar"> <div class="avatar">
<img :src="avatar()"/> <img :src="avatar()">
</div> </div>
<div class="username">{{ nickname() }}</div> <div class="username">{{ nickname() }}</div>
<div class="bio">海纳百川,有容乃大</div> <div class="bio">海纳百川,有容乃大</div>
...@@ -19,21 +18,30 @@ ...@@ -19,21 +18,30 @@
<i class="group"></i>蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED <i class="group"></i>蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED
</p> </p>
<p> <p>
<i class="address"></i><span>浙江省</span><span>杭州市</span> <i class="address"></i>
<span>浙江省</span>
<span>杭州市</span>
</p> </p>
</div> </div>
<a-divider /> <a-divider/>
<div class="account-center-tags"> <div class="account-center-tags">
<div class="tagsTitle">标签</div> <div class="tagsTitle">标签</div>
<div> <div>
<template v-for="(tag, index) in tags"> <template v-for="(tag, index) in tags">
<a-tooltip v-if="tag.length > 20" :key="tag" :title="tag"> <a-tooltip v-if="tag.length > 20" :key="tag" :title="tag">
<a-tag :key="tag" :closable="index !== 0" :afterClose="() => handleTagClose(tag)"> <a-tag
{{ `${tag.slice(0, 20)}...` }} :key="tag"
</a-tag> :closable="index !== 0"
:afterClose="() => handleTagClose(tag)"
>{{ `${tag.slice(0, 20)}...` }}</a-tag>
</a-tooltip> </a-tooltip>
<a-tag v-else :key="tag" :closable="index !== 0" :afterClose="() => handleTagClose(tag)">{{ tag }}</a-tag> <a-tag
v-else
:key="tag"
:closable="index !== 0"
:afterClose="() => handleTagClose(tag)"
>{{ tag }}</a-tag>
</template> </template>
<a-input <a-input
v-if="tagInputVisible" v-if="tagInputVisible"
...@@ -47,11 +55,11 @@ ...@@ -47,11 +55,11 @@
@keyup.enter="handleTagInputConfirm" @keyup.enter="handleTagInputConfirm"
/> />
<a-tag v-else @click="showTagInput" style="background: #fff; borderStyle: dashed;"> <a-tag v-else @click="showTagInput" style="background: #fff; borderStyle: dashed;">
<a-icon type="plus" /> New Tag <a-icon type="plus"/>New Tag
</a-tag> </a-tag>
</div> </div>
</div> </div>
<a-divider :dashed="true" /> <a-divider :dashed="true"/>
<div class="account-center-team"> <div class="account-center-team">
<div class="teamTitle">团队</div> <div class="teamTitle">团队</div>
...@@ -60,7 +68,7 @@ ...@@ -60,7 +68,7 @@
<a-row> <a-row>
<a-col :span="12" v-for="(item, index) in teams" :key="index"> <a-col :span="12" v-for="(item, index) in teams" :key="index">
<a> <a>
<a-avatar size="small" :src="item.avatar" /> <a-avatar size="small" :src="item.avatar"/>
<span class="member">{{ item.name }}</span> <span class="member">{{ item.name }}</span>
</a> </a>
</a-col> </a-col>
...@@ -84,20 +92,17 @@ ...@@ -84,20 +92,17 @@
</a-card> </a-card>
</a-col> </a-col>
</a-row> </a-row>
</div> </div>
</template> </template>
<script> <script>
import PageLayout from '@/components/page/PageLayout' import PageLayout from '@/components/page/PageLayout'
import RouteView from '@/components/layouts/RouteView' import RouteView from '@/components/layouts/RouteView'
import { AppPage, ArticlePage, ProjectPage } from './page' import { AppPage, ArticlePage, ProjectPage } from './page'
import { mapGetters } from 'vuex'
import { mapGetters } from 'vuex' export default {
export default {
components: { components: {
RouteView, RouteView,
PageLayout, PageLayout,
...@@ -115,58 +120,60 @@ ...@@ -115,58 +120,60 @@
teams: [], teams: [],
teamSpinning: true, teamSpinning: true,
tabListNoTitle: [{ tabListNoTitle: [
{
key: 'article', key: 'article',
tab: '文章(8)', tab: '文章(8)'
}, { },
{
key: 'app', key: 'app',
tab: '应用(8)', tab: '应用(8)'
}, { },
{
key: 'project', key: 'project',
tab: '项目(8)', tab: '项目(8)'
} }
], ],
noTitleKey: 'app', noTitleKey: 'app'
} }
}, },
mounted () { mounted() {
this.getTeams() this.getTeams()
}, },
methods: { methods: {
...mapGetters(['nickname', 'avatar']), ...mapGetters(['nickname', 'avatar']),
getTeams() { getTeams() {
this.$http.get('/workplace/teams') this.$http.get('/workplace/teams').then(res => {
.then(res => {
this.teams = res.result this.teams = res.result
this.teamSpinning = false this.teamSpinning = false
}) })
}, },
handleTabChange (key, type) { handleTabChange(key, type) {
this[type] = key this[type] = key
}, },
handleTagClose (removeTag) { handleTagClose(removeTag) {
const tags = this.tags.filter(tag => tag != removeTag) const tags = this.tags.filter(tag => tag != removeTag)
this.tags = tags this.tags = tags
}, },
showTagInput () { showTagInput() {
this.tagInputVisible = true this.tagInputVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.tagInput.focus() this.$refs.tagInput.focus()
}) })
}, },
handleInputChange (e) { handleInputChange(e) {
this.tagInputValue = e.target.value this.tagInputValue = e.target.value
}, },
handleTagInputConfirm () { handleTagInputConfirm() {
const inputValue = this.tagInputValue const inputValue = this.tagInputValue
let tags = this.tags let tags = this.tags
if (inputValue && tags.indexOf(inputValue) === -1) { if (inputValue && !tags.includes(inputValue)) {
tags = [...tags, inputValue] tags = [...tags, inputValue]
} }
...@@ -176,16 +183,16 @@ ...@@ -176,16 +183,16 @@
tagInputValue: '' tagInputValue: ''
}) })
} }
},
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.page-header-wrapper-grid-content-main { .page-header-wrapper-grid-content-main {
width: 100%; width: 100%;
height: 100%; height: 100%;
min-height: 100%; min-height: 100%;
transition: .3s; transition: 0.3s;
.account-center-avatarHolder { .account-center-avatarHolder {
text-align: center; text-align: center;
...@@ -214,7 +221,6 @@ ...@@ -214,7 +221,6 @@
} }
.account-center-detail { .account-center-detail {
p { p {
margin-bottom: 8px; margin-bottom: 8px;
padding-left: 26px; padding-left: 26px;
...@@ -227,7 +233,7 @@ ...@@ -227,7 +233,7 @@
width: 14px; width: 14px;
left: 0; left: 0;
top: 4px; top: 4px;
background: url(https://gw.alipayobjects.com/zos/rmsportal/pBjWzVAHnOOtAUvZmZfy.svg) background: url(https://gw.alipayobjects.com/zos/rmsportal/pBjWzVAHnOOtAUvZmZfy.svg);
} }
.title { .title {
...@@ -248,7 +254,6 @@ ...@@ -248,7 +254,6 @@
} }
.account-center-team { .account-center-team {
.members { .members {
a { a {
display: block; display: block;
...@@ -257,7 +262,7 @@ ...@@ -257,7 +262,7 @@
height: 24px; height: 24px;
.member { .member {
font-size: 14px; font-size: 14px;
color: rgba(0, 0, 0, .65); color: rgba(0, 0, 0, 0.65);
line-height: 24px; line-height: 24px;
max-width: 100px; max-width: 100px;
vertical-align: top; vertical-align: top;
...@@ -274,12 +279,11 @@ ...@@ -274,12 +279,11 @@
} }
} }
.tagsTitle, .teamTitle { .tagsTitle,
.teamTitle {
font-weight: 500; font-weight: 500;
color: rgba(0,0,0,.85); color: rgba(0, 0, 0, 0.85);
margin-bottom: 12px; margin-bottom: 12px;
} }
}
}
</style> </style>
\ No newline at end of file
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