Browse Source

Merge branch 'main' of github.com:DesignHhuang/vue-vben-admin

pull/3081/head
huangxiaomin 3 years ago
parent
commit
9f6d61d02c
  1. 2
      package.json
  2. 8
      packages/hooks/src/useRefs.ts
  3. 26
      src/components/ContextMenu/src/ContextMenu.vue
  4. 2
      src/components/Drawer/src/BasicDrawer.vue
  5. 6
      src/components/Drawer/src/typing.ts
  6. 10
      src/components/Drawer/src/useDrawer.ts
  7. 1
      src/components/Form/src/components/ApiSelect.vue
  8. 9
      src/components/Form/src/components/ApiTree.vue
  9. 11
      src/components/Form/src/components/ApiTreeSelect.vue
  10. 1
      src/components/Form/src/helper.ts
  11. 2
      src/components/Modal/src/components/ModalWrapper.vue
  12. 10
      src/components/Modal/src/hooks/useModal.ts
  13. 4
      src/components/Modal/src/index.less
  14. 2
      src/components/Modal/src/typing.ts
  15. 3
      src/components/Table/src/BasicTable.vue
  16. 7
      src/components/Table/src/hooks/useColumns.ts

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "vben-admin", "name": "vben-admin",
"version": "2.10.0", "version": "2.10.1",
"homepage": "https://github.com/vbenjs/vue-vben-admin", "homepage": "https://github.com/vbenjs/vue-vben-admin",
"bugs": { "bugs": {
"url": "https://github.com/vbenjs/vue-vben-admin/issues" "url": "https://github.com/vbenjs/vue-vben-admin/issues"

8
packages/hooks/src/useRefs.ts

@ -1,9 +1,9 @@
import type { Ref } from 'vue'; import type { ComponentPublicInstance, Ref } from 'vue';
import { onBeforeUpdate, shallowRef } from 'vue'; import { onBeforeUpdate, shallowRef } from 'vue';
function useRefs<T = HTMLElement>(): { function useRefs<T = HTMLElement>(): {
refs: Ref<T[]>; refs: Ref<T[]>;
setRefs: (index: number) => (el: T) => void; setRefs: (index: number) => (el: Element | ComponentPublicInstance | null) => void;
} { } {
const refs = shallowRef([]) as Ref<T[]>; const refs = shallowRef([]) as Ref<T[]>;
@ -11,8 +11,8 @@ function useRefs<T = HTMLElement>(): {
refs.value = []; refs.value = [];
}); });
const setRefs = (index: number) => (el: T) => { const setRefs = (index: number) => (el: Element | ComponentPublicInstance | null) => {
refs.value[index] = el; refs.value[index] = el as T;
}; };
return { return {

26
src/components/ContextMenu/src/ContextMenu.vue

@ -59,12 +59,12 @@
const left = body.clientWidth < x + menuWidth ? x - menuWidth : x; const left = body.clientWidth < x + menuWidth ? x - menuWidth : x;
const top = body.clientHeight < y + menuHeight ? y - menuHeight : y; const top = body.clientHeight < y + menuHeight ? y - menuHeight : y;
return { return {
...styles,
position: 'absolute', position: 'absolute',
width: `${width}px`, width: `${width}px`,
left: `${left + 1}px`, left: `${left + 1}px`,
top: `${top + 1}px`, top: `${top + 1}px`,
zIndex: 9999, zIndex: 9999,
...styles, // Not the first, fix options.styles.width not working
}; };
}); });
@ -127,11 +127,15 @@
} }
const { items } = props; const { items } = props;
return ( return (
<div class={prefixCls}> <Menu
<Menu inlineIndent={12} mode="vertical" ref={wrapRef} style={unref(getStyle)}> inlineIndent={12}
{renderMenuItem(items)} mode="vertical"
</Menu> class={prefixCls}
</div> ref={wrapRef}
style={unref(getStyle)}
>
{renderMenuItem(items)}
</Menu>
); );
}; };
}, },
@ -147,7 +151,7 @@
.item-style() { .item-style() {
li { li {
display: inline-block; display: inline-block;
width: 100%; width: 100% !important;
height: @default-height; height: @default-height;
margin: 0 !important; margin: 0 !important;
line-height: @default-height; line-height: @default-height;
@ -157,6 +161,8 @@
} }
> div { > div {
width: 100% !important;
height: 100% !important;
margin: 0 !important; margin: 0 !important;
} }
@ -176,10 +182,12 @@
width: 156px; width: 156px;
margin: 0; margin: 0;
border: 1px solid rgb(0 0 0 / 8%); border: 1px solid rgb(0 0 0 / 8%);
border-radius: 0.25rem; border-radius: 8px;
background-clip: padding-box; background-clip: padding-box;
background-color: @component-background; background-color: @component-background;
box-shadow: 0 2px 2px 0 rgb(0 0 0 / 14%), 0 3px 1px -2px rgb(0 0 0 / 10%), box-shadow:
0 2px 2px 0 rgb(0 0 0 / 14%),
0 3px 1px -2px rgb(0 0 0 / 10%),
0 1px 5px 0 rgb(0 0 0 / 6%); 0 1px 5px 0 rgb(0 0 0 / 6%);
list-style: none; list-style: none;
user-select: none; user-select: none;

2
src/components/Drawer/src/BasicDrawer.vue

@ -1,5 +1,5 @@
<template> <template>
<Drawer :rootClassName="prefixCls" @close="onClose" v-bind="getBindValues"> <Drawer @close="onClose" v-bind="getBindValues">
<template #title v-if="!$slots.title"> <template #title v-if="!$slots.title">
<DrawerHeader <DrawerHeader
:title="getMergeProps.title" :title="getMergeProps.title"

6
src/components/Drawer/src/typing.ts

@ -3,7 +3,7 @@ import type { CSSProperties, VNodeChild, ComputedRef } from 'vue';
import type { ScrollContainerOptions } from '/@/components/Container/index'; import type { ScrollContainerOptions } from '/@/components/Container/index';
export interface DrawerInstance { export interface DrawerInstance {
setDrawerProps: (props: Partial<DrawerProps> | boolean) => void; setDrawerProps: (props: Partial<DrawerProps>) => void;
emitOpen?: (open: boolean, uid: number) => void; emitOpen?: (open: boolean, uid: number) => void;
} }
@ -13,7 +13,7 @@ export interface ReturnMethods extends DrawerInstance {
getOpen?: ComputedRef<boolean>; getOpen?: ComputedRef<boolean>;
} }
export type RegisterFn = (drawerInstance: DrawerInstance, uuid?: string) => void; export type RegisterFn = (drawerInstance: DrawerInstance, uuid: number) => void;
export interface ReturnInnerMethods extends DrawerInstance { export interface ReturnInnerMethods extends DrawerInstance {
closeDrawer: () => void; closeDrawer: () => void;
@ -100,7 +100,7 @@ export interface DrawerProps extends DrawerFooterProps {
* @default 'body' * @default 'body'
* @type any ( HTMLElement| () => HTMLElement | string) * @type any ( HTMLElement| () => HTMLElement | string)
*/ */
getContainer?: () => HTMLElement | string; getContainer?: string | false | HTMLElement | (() => HTMLElement);
/** /**
* Whether to show mask or not. * Whether to show mask or not.

10
src/components/Drawer/src/useDrawer.ts

@ -34,9 +34,9 @@ export function useDrawer(): UseDrawerReturnType {
} }
const drawer = ref<DrawerInstance | null>(null); const drawer = ref<DrawerInstance | null>(null);
const loaded = ref<Nullable<boolean>>(false); const loaded = ref<Nullable<boolean>>(false);
const uid = ref<string>(''); const uid = ref<number>(0);
function register(drawerInstance: DrawerInstance, uuid: string) { function register(drawerInstance: DrawerInstance, uuid: number) {
isProdMode() && isProdMode() &&
tryOnUnmounted(() => { tryOnUnmounted(() => {
drawer.value = null; drawer.value = null;
@ -100,7 +100,7 @@ export function useDrawer(): UseDrawerReturnType {
export const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => { export const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => {
const drawerInstanceRef = ref<Nullable<DrawerInstance>>(null); const drawerInstanceRef = ref<Nullable<DrawerInstance>>(null);
const currentInstance = getCurrentInstance(); const currentInstance = getCurrentInstance();
const uidRef = ref<string>(''); const uidRef = ref<number>(0);
if (!getCurrentInstance()) { if (!getCurrentInstance()) {
throw new Error('useDrawerInner() can only be used inside setup() or functional components!'); throw new Error('useDrawerInner() can only be used inside setup() or functional components!');
@ -115,7 +115,7 @@ export const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => {
return instance; return instance;
}; };
const register = (modalInstance: DrawerInstance, uuid: string) => { const register = (modalInstance: DrawerInstance, uuid: number) => {
isProdMode() && isProdMode() &&
tryOnUnmounted(() => { tryOnUnmounted(() => {
drawerInstanceRef.value = null; drawerInstanceRef.value = null;
@ -153,7 +153,7 @@ export const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => {
getInstance()?.setDrawerProps({ open: false }); getInstance()?.setDrawerProps({ open: false });
}, },
setDrawerProps: (props: Partial<DrawerProps> | boolean) => { setDrawerProps: (props: Partial<DrawerProps>) => {
getInstance()?.setDrawerProps(props); getInstance()?.setDrawerProps(props);
}, },
}, },

1
src/components/Form/src/components/ApiSelect.vue

@ -144,6 +144,7 @@
} }
function handleChange(_, ...args) { function handleChange(_, ...args) {
emit('change', args[0] ? args[0].value : undefined);
emitData.value = args; emitData.value = args;
} }

9
src/components/Form/src/components/ApiTree.vue

@ -3,9 +3,6 @@
<template #[item]="data" v-for="item in Object.keys($slots)"> <template #[item]="data" v-for="item in Object.keys($slots)">
<slot :name="item" v-bind="data || {}"></slot> <slot :name="item" v-bind="data || {}"></slot>
</template> </template>
<template #suffixIcon v-if="loading">
<LoadingOutlined spin />
</template>
</a-tree> </a-tree>
</template> </template>
@ -16,11 +13,11 @@
import { isArray, isFunction } from '/@/utils/is'; import { isArray, isFunction } from '/@/utils/is';
import { get } from 'lodash-es'; import { get } from 'lodash-es';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
import { LoadingOutlined } from '@ant-design/icons-vue'; import { DataNode } from 'ant-design-vue/es/tree';
export default defineComponent({ export default defineComponent({
name: 'ApiTree', name: 'ApiTree',
components: { ATree: Tree, LoadingOutlined }, components: { ATree: Tree },
props: { props: {
api: { type: Function as PropType<(arg?: Recordable<any>) => Promise<Recordable<any>>> }, api: { type: Function as PropType<(arg?: Recordable<any>) => Promise<Recordable<any>>> },
params: { type: Object }, params: { type: Object },
@ -30,7 +27,7 @@
}, },
emits: ['options-change', 'change'], emits: ['options-change', 'change'],
setup(props, { attrs, emit }) { setup(props, { attrs, emit }) {
const treeData = ref<Recordable<any>[]>([]); const treeData = ref<DataNode[]>([]);
const isFirstLoaded = ref<Boolean>(false); const isFirstLoaded = ref<Boolean>(false);
const loading = ref(false); const loading = ref(false);
const getAttrs = computed(() => { const getAttrs = computed(() => {

11
src/components/Form/src/components/ApiTreeSelect.vue

@ -11,16 +11,7 @@
<script lang="ts"> <script lang="ts">
import { type Recordable } from '@vben/types'; import { type Recordable } from '@vben/types';
import { import { type PropType, computed, defineComponent, watch, ref, onMounted, unref } from 'vue';
type PropType,
computed,
defineComponent,
watchEffect,
watch,
ref,
onMounted,
unref,
} from 'vue';
import { TreeSelect } from 'ant-design-vue'; import { TreeSelect } from 'ant-design-vue';
import { isArray, isFunction } from '/@/utils/is'; import { isArray, isFunction } from '/@/utils/is';
import { get } from 'lodash-es'; import { get } from 'lodash-es';

1
src/components/Form/src/helper.ts

@ -78,7 +78,6 @@ export const NO_AUTO_LINK_COMPONENTS: ComponentType[] = [
'Upload', 'Upload',
'ApiTransfer', 'ApiTransfer',
'ApiTree', 'ApiTree',
'ApiSelect',
'ApiTreeSelect', 'ApiTreeSelect',
'ApiRadioGroup', 'ApiRadioGroup',
'ApiCascader', 'ApiCascader',

2
src/components/Modal/src/components/ModalWrapper.vue

@ -53,7 +53,7 @@
let stopElResizeFn: AnyFunction = () => {}; let stopElResizeFn: AnyFunction = () => {};
useWindowSizeFn(setModalHeight.bind(null, false)); useWindowSizeFn(setModalHeight.bind(null));
useMutationObserver( useMutationObserver(
spinRef, spinRef,

10
src/components/Modal/src/hooks/useModal.ts

@ -32,9 +32,9 @@ const openData = reactive<{ [key: number]: boolean }>({});
export function useModal(): UseModalReturnType { export function useModal(): UseModalReturnType {
const modal = ref<Nullable<ModalMethods>>(null); const modal = ref<Nullable<ModalMethods>>(null);
const loaded = ref<Nullable<boolean>>(false); const loaded = ref<Nullable<boolean>>(false);
const uid = ref<string>(''); const uid = ref<number>(0);
function register(modalMethod: ModalMethods, uuid: string) { function register(modalMethod: ModalMethods, uuid: number) {
if (!getCurrentInstance()) { if (!getCurrentInstance()) {
throw new Error('useModal() can only be used inside setup() or functional components!'); throw new Error('useModal() can only be used inside setup() or functional components!');
} }
@ -43,7 +43,7 @@ export function useModal(): UseModalReturnType {
onUnmounted(() => { onUnmounted(() => {
modal.value = null; modal.value = null;
loaded.value = false; loaded.value = false;
dataTransfer[unref(uid)] = null; dataTransfer[String(unref(uid))] = null;
}); });
if (unref(loaded) && isProdMode() && modalMethod === unref(modal)) return; if (unref(loaded) && isProdMode() && modalMethod === unref(modal)) return;
@ -103,7 +103,7 @@ export function useModal(): UseModalReturnType {
export const useModalInner = (callbackFn?: Fn): UseModalInnerReturnType => { export const useModalInner = (callbackFn?: Fn): UseModalInnerReturnType => {
const modalInstanceRef = ref<Nullable<ModalMethods>>(null); const modalInstanceRef = ref<Nullable<ModalMethods>>(null);
const currentInstance = getCurrentInstance(); const currentInstance = getCurrentInstance();
const uidRef = ref<string>(''); const uidRef = ref<number>(0);
const getInstance = () => { const getInstance = () => {
const instance = unref(modalInstanceRef); const instance = unref(modalInstanceRef);
@ -113,7 +113,7 @@ export const useModalInner = (callbackFn?: Fn): UseModalInnerReturnType => {
return instance; return instance;
}; };
const register = (modalInstance: ModalMethods, uuid: string) => { const register = (modalInstance: ModalMethods, uuid: number) => {
isProdMode() && isProdMode() &&
tryOnUnmounted(() => { tryOnUnmounted(() => {
modalInstanceRef.value = null; modalInstanceRef.value = null;

4
src/components/Modal/src/index.less

@ -11,6 +11,10 @@
height: 100%; height: 100%;
} }
} }
.ant-modal-footer {
margin-top: 0;
}
} }
.vben-basic-modal-wrap .ant-modal { .vben-basic-modal-wrap .ant-modal {

2
src/components/Modal/src/typing.ts

@ -9,7 +9,7 @@ export interface ModalMethods {
redoModalHeight?: () => void; redoModalHeight?: () => void;
} }
export type RegisterFn = (modalMethods: ModalMethods, uuid?: string) => void; export type RegisterFn = (modalMethods: ModalMethods, uuid: number) => void;
export interface ReturnMethods extends ModalMethods { export interface ReturnMethods extends ModalMethods {
openModal: <T = any>(props?: boolean, data?: T, openOnSet?: boolean) => void; openModal: <T = any>(props?: boolean, data?: T, openOnSet?: boolean) => void;

3
src/components/Table/src/BasicTable.vue

@ -21,6 +21,7 @@
:rowClassName="getRowClassName" :rowClassName="getRowClassName"
v-show="getEmptyDataIsShowTable" v-show="getEmptyDataIsShowTable"
@change="handleTableChange" @change="handleTableChange"
@resizeColumn="setColumnWidth"
> >
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item"> <template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
<slot :name="item" v-bind="data || {}"></slot> <slot :name="item" v-bind="data || {}"></slot>
@ -189,6 +190,7 @@
getColumns, getColumns,
setCacheColumnsByField, setCacheColumnsByField,
setCacheColumns, setCacheColumns,
setColumnWidth,
setColumns, setColumns,
getColumnsRef, getColumnsRef,
getCacheColumns, getCacheColumns,
@ -345,6 +347,7 @@
handleSearchInfoChange, handleSearchInfoChange,
getEmptyDataIsShowTable, getEmptyDataIsShowTable,
handleTableChange, handleTableChange,
setColumnWidth,
getRowClassName, getRowClassName,
wrapRef, wrapRef,
tableAction, tableAction,

7
src/components/Table/src/hooks/useColumns.ts

@ -264,12 +264,19 @@ export function useColumns(
if (!isArray(columns)) return; if (!isArray(columns)) return;
cacheColumns = columns.filter((item) => !item.flag); cacheColumns = columns.filter((item) => !item.flag);
} }
/**
* 拖拽列宽修改列的宽度
*/
function setColumnWidth(w: number, col: BasicColumn) {
col.width = w;
}
return { return {
getColumnsRef, getColumnsRef,
getCacheColumns, getCacheColumns,
getColumns, getColumns,
setColumns, setColumns,
setColumnWidth,
getViewColumns, getViewColumns,
setCacheColumnsByField, setCacheColumnsByField,
setCacheColumns, setCacheColumns,

Loading…
Cancel
Save