Skip to content

Commit

Permalink
releases 4.0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jun 28, 2024
1 parent 4a6a098 commit 0e42322
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 43 deletions.
4 changes: 3 additions & 1 deletion examples/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import { ref } from 'vue'
import { VxeUI } from '../packages'
import { VxeMenuPropTypes } from '../types'
const collapsed = ref(false)
const navList = ref([
const navList = ref<VxeMenuPropTypes.Options>([
{ name: 'Home', icon: 'vxe-icon-user-fill', routerLink: { path: '/' } },
{ name: 'TagTest', icon: 'vxe-icon-user-fill', routerLink: { name: 'TagTest' } },
{ name: 'TextTest', icon: 'vxe-icon-user-fill', routerLink: { name: 'TextTest' } },
Expand Down
15 changes: 15 additions & 0 deletions examples/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ declare global {
}
}

VxeUI.setConfig({
permissionMethod ({ code }) {
if (code === 'xx') {
return {
visible: true,
disabled: true
}
}
return {
visible: false,
disabled: true
}
}
})

VxeUI.setI18n('en-US', enUS)
VxeUI.setLanguage((localStorage.getItem('VXE_LANGUAGE') as 'zh-CN' | 'en-US') || 'zh-CN')

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-pc-ui",
"version": "4.0.38",
"version": "4.0.40",
"description": "A vue based PC component library",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand All @@ -25,7 +25,7 @@
"style": "lib/style.css",
"typings": "types/index.d.ts",
"dependencies": {
"@vxe-ui/core": "^1.0.9"
"@vxe-ui/core": "^1.0.11"
},
"devDependencies": {
"@types/resize-observer-browser": "^0.1.11",
Expand Down
12 changes: 10 additions & 2 deletions packages/button/src/button-group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, h, provide, PropType } from 'vue'
import { getConfig, createEvent, useSize } from '@vxe-ui/core'
import { defineComponent, h, provide, PropType, createCommentVNode } from 'vue'
import { getConfig, createEvent, useSize, usePermission } from '@vxe-ui/core'
import XEUtils from 'xe-utils'
import VxeButtonComponent from '../../button/src/button'

Expand All @@ -15,6 +15,8 @@ export default defineComponent({
circle: Boolean as PropType<VxeButtonGroupPropTypes.Circle>,
className: [String, Function] as PropType<VxeButtonGroupPropTypes.ClassName>,
disabled: Boolean as PropType<VxeButtonGroupPropTypes.Disabled>,
permissionCode: [String, Number] as PropType<VxeButtonGroupPropTypes.PermissionCode>,
permissionMethod: Function as PropType<VxeButtonGroupPropTypes.PermissionMethod>,
size: { type: String as PropType<VxeButtonGroupPropTypes.Size>, default: () => getConfig().buttonGroup.size || getConfig().size }
},
emits: [
Expand All @@ -37,6 +39,8 @@ export default defineComponent({

useSize(props)

const { computePermissionInfo } = usePermission(props)

const buttonGroupMethods: ButtonGroupMethods = {
dispatchEvent (type, params, evnt) {
emit(type, createEvent(evnt, { $buttonGroup: $xeButtonGroup }, params))
Expand All @@ -56,7 +60,11 @@ export default defineComponent({

const renderVN = () => {
const { className, options } = props
const permissionInfo = computePermissionInfo.value
const defaultSlot = slots.default
if (!permissionInfo.visible) {
return createCommentVNode()
}
return h('div', {
class: ['vxe-button-group', className ? (XEUtils.isFunction(className) ? className({ $buttonGroup: $xeButtonGroup }) : className) : '']
}, defaultSlot
Expand Down
36 changes: 27 additions & 9 deletions packages/button/src/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, h, ref, Ref, computed, Teleport, VNode, onUnmounted, reactive, nextTick, PropType, onMounted, inject } from 'vue'
import { defineComponent, h, ref, Ref, computed, Teleport, VNode, onUnmounted, reactive, nextTick, PropType, onMounted, inject, createCommentVNode } from 'vue'
import XEUtils from 'xe-utils'
import { getConfig, globalEvents, getIcon, createEvent, useSize } from '../../ui'
import { getConfig, globalEvents, getIcon, createEvent, useSize, usePermission } from '../../ui'
import { getAbsolutePos, getEventTargetNode } from '../../ui/src/dom'
import { getFuncText, getLastZIndex, nextZIndex } from '../../ui/src/utils'
import { warnLog } from '../../ui/src/log'
Expand All @@ -25,6 +25,11 @@ export default defineComponent({
* 用来标识这一项
*/
name: [String, Number] as PropType<VxeButtonPropTypes.Name>,
/**
* 权限码
*/
permissionCode: [String, Number] as PropType<VxeButtonPropTypes.PermissionCode>,
permissionMethod: Function as PropType<VxeButtonPropTypes.PermissionMethod>,
/**
* 按钮内容
*/
Expand Down Expand Up @@ -91,6 +96,8 @@ export default defineComponent({

const { computeSize } = useSize(props)

const { computePermissionInfo } = usePermission(props)

const reactData = reactive<ButtonReactData>({
inited: false,
visiblePanel: false,
Expand Down Expand Up @@ -138,6 +145,12 @@ export default defineComponent({
return transfer
})

const computeBtnDisabled = computed(() => {
const { disabled } = props
const permissionInfo = computePermissionInfo.value
return disabled || permissionInfo.disabled
})

const computeIsFormBtn = computed(() => {
const { type } = props
if (type) {
Expand Down Expand Up @@ -450,9 +463,9 @@ export default defineComponent({
}

const handleGlobalMousedownEvent = (evnt: MouseEvent) => {
const { disabled } = props
const btnDisabled = computeBtnDisabled.value
const { visiblePanel } = reactData
if (!disabled) {
if (!btnDisabled) {
const el = refElem.value
const panelElem = refBtnPanel.value
reactData.isActivated = getEventTargetNode(evnt, el).flag || getEventTargetNode(evnt, panelElem).flag
Expand All @@ -465,15 +478,20 @@ export default defineComponent({
Object.assign($xeButton, buttonMethods)

const renderVN = () => {
const { className, popupClassName, trigger, title, type, destroyOnClose, name, disabled, loading } = props
const { className, popupClassName, trigger, title, type, destroyOnClose, name, loading } = props
const { inited, visiblePanel } = reactData
const isFormBtn = computeIsFormBtn.value
const btnMode = computeBtnMode.value
const btnStatus = computeBtnStatus.value
const btnRound = computeBtnRound.value
const btnCircle = computeBtnCircle.value
const transfer = compTransfer.value
const btnDisabled = computeBtnDisabled.value
const permissionInfo = computePermissionInfo.value
const vSize = computeSize.value
if (!permissionInfo.visible) {
return createCommentVNode()
}
if (slots.dropdowns) {
const btnOns: Record<string, any> = {}
const panelOns: Record<string, any> = {}
Expand All @@ -499,13 +517,13 @@ export default defineComponent({
[`theme--${btnStatus}`]: btnStatus,
'is--round': btnRound,
'is--circle': btnCircle,
'is--disabled': disabled || loading,
'is--disabled': btnDisabled || loading,
'is--loading': loading
}],
title,
name,
type: isFormBtn ? type : 'button',
disabled: disabled || loading,
disabled: btnDisabled || loading,
onClick: clickTargetEvent,
...btnOns
}, renderContent().concat([
Expand Down Expand Up @@ -546,13 +564,13 @@ export default defineComponent({
[`theme--${btnStatus}`]: btnStatus,
'is--round': btnRound,
'is--circle': btnCircle,
'is--disabled': disabled || loading,
'is--disabled': btnDisabled || loading,
'is--loading': loading
}],
title,
name,
type: isFormBtn ? type : 'button',
disabled: disabled || loading,
disabled: btnDisabled || loading,
onClick: clickEvent,
onMouseenter: mouseenterEvent,
onMouseleave: mouseleaveEvent
Expand Down
13 changes: 12 additions & 1 deletion packages/link/src/link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, ref, h, reactive, PropType, createCommentVNode, resolveComponent } from 'vue'
import XEUtils from 'xe-utils'
import { getConfig } from '../../ui'
import { getConfig, usePermission } from '../../ui'
import { getSlotVNs } from '../../ui/src/vn'

import type { VxeLinkPropTypes, LinkReactData, LinkPrivateRef, VxeLinkPrivateComputed, VxeLinkConstructor, VxeLinkPrivateMethods } from '../../../types'
Expand All @@ -18,6 +18,11 @@ export default defineComponent({
type: Boolean as PropType<VxeLinkPropTypes.Underline>,
default: () => getConfig().link.underline
},
/**
* 权限码
*/
permissionCode: [String, Number] as PropType<VxeLinkPropTypes.PermissionCode>,
permissionMethod: Function as PropType<VxeLinkPropTypes.PermissionMethod>,
content: [String, Number] as PropType<VxeLinkPropTypes.Content>
},
emits: [],
Expand All @@ -26,6 +31,8 @@ export default defineComponent({

const xID = XEUtils.uniqueId()

const { computePermissionInfo } = usePermission(props)

const refElem = ref<HTMLDivElement>()

const reactData = reactive<LinkReactData>({
Expand Down Expand Up @@ -72,6 +79,10 @@ export default defineComponent({

const renderVN = () => {
const { status, target, href, title, underline, routerLink } = props
const permissionInfo = computePermissionInfo.value
if (!permissionInfo.visible) {
return createCommentVNode()
}
if (routerLink) {
return h(resolveComponent('router-link'), {
class: ['vxe-link', {
Expand Down
7 changes: 6 additions & 1 deletion packages/menu/src/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, ref, h, reactive, PropType, resolveComponent, createCommentVNode, nextTick, watch, VNode, onMounted } from 'vue'
import XEUtils from 'xe-utils'
import { getIcon, createEvent } from '../../ui'
import { getIcon, createEvent, permission } from '../../ui'

import type { VxeMenuDefines, VxeMenuPropTypes, MenuReactData, VxeMenuEmits, MenuPrivateRef, VxeMenuPrivateComputed, VxeMenuConstructor, VxeMenuPrivateMethods } from '../../../types'

Expand Down Expand Up @@ -171,6 +171,11 @@ export default defineComponent({

const renderChildren = (item: VxeMenuDefines.MenuItem): VNode => {
const { itemKey, level, hasChild, isActive, isExactActive, isExpand, routerLink, childList } = item
if (item.permissionCode) {
if (!permission.checkVisible(item.permissionCode)) {
return createCommentVNode()
}
}
return h('div', {
key: itemKey,
class: ['vxe-menu--item-wrapper', `vxe-menu--item-level${level}`, {
Expand Down
8 changes: 7 additions & 1 deletion packages/tabs/src/tab-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default defineComponent({
name: [String, Number] as PropType<VxeTabPanePropTypes.Name>,
icon: String as PropType<VxeTabPanePropTypes.Icon>,
titleWidth: [String, Number] as PropType<VxeTabPanePropTypes.TitleWidth>,
titleAlign: [String, Number] as PropType<VxeTabPanePropTypes.TitleAlign>
titleAlign: [String, Number] as PropType<VxeTabPanePropTypes.TitleAlign>,
permissionCode: [String, Number] as PropType<VxeTabPanePropTypes.PermissionCode>
},
emits: [],
setup (props, context) {
Expand All @@ -33,6 +34,7 @@ export default defineComponent({
icon: props.icon,
titleWidth: props.titleWidth,
titleAlign: props.titleAlign,
permissionCode: props.permissionCode,
slots: {
default: slots.default
}
Expand Down Expand Up @@ -67,6 +69,10 @@ export default defineComponent({
tabConfig.icon = val
})

watch(() => props.permissionCode, (val) => {
tabConfig.permissionCode = val
})

onMounted(() => {
if ($xeTabs && refElem.value) {
assembleAnchorTab($xeTabs, refElem.value, tabConfig)
Expand Down
Loading

0 comments on commit 0e42322

Please sign in to comment.