Commit 35d2bfc5623fcf3a608ae12e9781b2e23ff4130d

Authored by vben
1 parent f645680a

fix: fix message type error

CHANGELOG.zh_CN.md
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 - 修复表格开启搜索表单折叠问题 23 - 修复表格开启搜索表单折叠问题
24 - 修复表格 size 为 samll 时候,fixed 列样式问题 24 - 修复表格 size 为 samll 时候,fixed 列样式问题
25 - 修复多标签页关闭报错问题 25 - 修复多标签页关闭报错问题
  26 +- 修复 message 类型错误
26 27
27 ## 2.0.0-rc.7 (2020-10-31) 28 ## 2.0.0-rc.7 (2020-10-31)
28 29
src/components/Container/src/collapse/CollapseHeader.vue
@@ -11,22 +11,15 @@ @@ -11,22 +11,15 @@
11 11
12 <div class="collapse-container__action"> 12 <div class="collapse-container__action">
13 <slot name="action" /> 13 <slot name="action" />
14 - <BasicArrow v-if="$attrs.canExpan" :expand="$attrs.show" @click="handleExpand" /> 14 + <BasicArrow v-if="$attrs.canExpan" :expand="$attrs.show" @click="$emit('expand')" />
15 </div> 15 </div>
16 </div> 16 </div>
17 </template> 17 </template>
18 <script lang="ts"> 18 <script lang="ts">
19 import { defineComponent } from 'vue'; 19 import { defineComponent } from 'vue';
20 - import { BasicArrow } from '/@/components/Basic';  
21 - import { BasicTitle } from '/@/components/Basic'; 20 + import { BasicArrow, BasicTitle } from '/@/components/Basic';
22 export default defineComponent({ 21 export default defineComponent({
23 inheritAttrs: false, 22 inheritAttrs: false,
24 components: { BasicArrow, BasicTitle }, 23 components: { BasicArrow, BasicTitle },
25 - setup(_, { emit }) {  
26 - function handleExpand() {  
27 - emit('expand');  
28 - }  
29 - return { handleExpand };  
30 - },  
31 }); 24 });
32 </script> 25 </script>
src/hooks/core/asyncComputed.ts 0 → 100644
  1 +import { ref, watchEffect, Ref } from 'vue';
  2 +
  3 +/**
  4 + * Handle overlapping async evaluations
  5 + *
  6 + * @param cancelCallback The provided callback is invoked when a re-evaluation of the computed value is triggered before the previous one finished
  7 + */
  8 +export type AsyncComputedOnCancel = (cancelCallback: () => void) => void;
  9 +
  10 +/**
  11 + * A two-item tuple with the first item being a ref to the computed value and the second item holding a boolean ref, indicating whether the async computed value is currently (re-)evaluated
  12 + */
  13 +export type AsyncComputedResult<T> = [Ref<T>, Ref<boolean>];
  14 +
  15 +/**
  16 + * Create an asynchronous computed dependency
  17 + *
  18 + * @param evaluationCallback The promise-returning callback which generates the computed value
  19 + * @param defaultValue A default value, used until the first evaluation finishes
  20 + */
  21 +export function asyncComputed<T>(
  22 + evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,
  23 + defaultValue?: T
  24 +): AsyncComputedResult<T> {
  25 + let counter = 0;
  26 + const current = ref(defaultValue) as Ref<T>;
  27 + const evaluating = ref<boolean>(false);
  28 +
  29 + watchEffect(async (onInvalidate: Fn) => {
  30 + counter++;
  31 + const counterAtBeginning = counter;
  32 + let hasFinished = false;
  33 +
  34 + try {
  35 + // Defer initial setting of `evaluating` ref
  36 + // to avoid having it as a dependency
  37 + Promise.resolve().then(() => {
  38 + evaluating.value = true;
  39 + });
  40 +
  41 + const result = await evaluationCallback((cancelCallback) => {
  42 + onInvalidate(() => {
  43 + evaluating.value = false;
  44 + if (!hasFinished) cancelCallback();
  45 + });
  46 + });
  47 +
  48 + if (counterAtBeginning === counter) current.value = result;
  49 + } finally {
  50 + evaluating.value = false;
  51 + hasFinished = true;
  52 + }
  53 + });
  54 +
  55 + return [current, evaluating];
  56 +}
src/hooks/core/types.ts
1 import type { VNode, Ref } from 'vue'; 1 import type { VNode, Ref } from 'vue';
2 -import type { ModalOptions } from 'ant-design-vue/types/modal'; 2 +import type { ModalFuncProps } from 'ant-design-vue/lib/modal/index';
3 3
4 export type Fn<T> = () => T; 4 export type Fn<T> = () => T;
5 export type AnyFn<T> = (...arg: any) => T; 5 export type AnyFn<T> = (...arg: any) => T;
@@ -86,7 +86,7 @@ export interface MessageOptions { @@ -86,7 +86,7 @@ export interface MessageOptions {
86 /** Set the distance to the top of viewport. Default is 20 px. */ 86 /** Set the distance to the top of viewport. Default is 20 px. */
87 offset?: number; 87 offset?: number;
88 } 88 }
89 -export interface ModalOptionsEx extends Omit<ModalOptions, 'iconType'> { 89 +export interface ModalOptionsEx extends Omit<ModalFuncProps, 'iconType'> {
90 iconType: 'warning' | 'success' | 'error' | 'info'; 90 iconType: 'warning' | 'success' | 'error' | 'info';
91 } 91 }
92 export type ModalOptionsPartial = Partial<ModalOptionsEx> & Pick<ModalOptionsEx, 'content'>; 92 export type ModalOptionsPartial = Partial<ModalOptionsEx> & Pick<ModalOptionsEx, 'content'>;
src/hooks/web/useMessage.tsx
1 import type { ModalOptionsEx, ModalOptionsPartial } from '/@/hooks/core/types'; 1 import type { ModalOptionsEx, ModalOptionsPartial } from '/@/hooks/core/types';
  2 +import type { ModalFunc, ModalFuncProps } from 'ant-design-vue/lib/modal/Modal';
2 3
3 import { Modal, message as Message, notification } from 'ant-design-vue'; 4 import { Modal, message as Message, notification } from 'ant-design-vue';
4 import { InfoCircleFilled, CheckCircleFilled, CloseCircleFilled } from '@ant-design/icons-vue'; 5 import { InfoCircleFilled, CheckCircleFilled, CloseCircleFilled } from '@ant-design/icons-vue';
5 -import { ModalOptions, ModalConfirm } from 'ant-design-vue/types/modal';  
6 6
7 import { useSetting } from '/@/hooks/core/useSetting'; 7 import { useSetting } from '/@/hooks/core/useSetting';
8 8
  9 +interface ConfirmOptions {
  10 + info: ModalFunc;
  11 + success: ModalFunc;
  12 + error: ModalFunc;
  13 + warn: ModalFunc;
  14 + warning: ModalFunc;
  15 +}
  16 +
9 const { projectSetting } = useSetting(); 17 const { projectSetting } = useSetting();
10 18
11 function getIcon(iconType: string) { 19 function getIcon(iconType: string) {
@@ -20,22 +28,22 @@ function getIcon(iconType: string) { @@ -20,22 +28,22 @@ function getIcon(iconType: string) {
20 } 28 }
21 } 29 }
22 function renderContent({ content }: Pick<ModalOptionsEx, 'content'>) { 30 function renderContent({ content }: Pick<ModalOptionsEx, 'content'>) {
23 - return <div innerHTML={`<div>${content}</div>`}></div>; 31 + return <div innerHTML={`<div>${content as string}</div>`}></div>;
24 } 32 }
25 33
26 /** 34 /**
27 * @description: Create confirmation box 35 * @description: Create confirmation box
28 */ 36 */
29 -function createConfirm(options: ModalOptionsEx): ModalConfirm { 37 +function createConfirm(options: ModalOptionsEx): ConfirmOptions {
30 const iconType = options.iconType || 'warning'; 38 const iconType = options.iconType || 'warning';
31 Reflect.deleteProperty(options, 'iconType'); 39 Reflect.deleteProperty(options, 'iconType');
32 - const opt: ModalOptions = { 40 + const opt: ModalFuncProps = {
33 centered: true, 41 centered: true,
34 icon: getIcon(iconType), 42 icon: getIcon(iconType),
35 ...projectSetting.messageSetting, 43 ...projectSetting.messageSetting,
36 ...options, 44 ...options,
37 }; 45 };
38 - return Modal.confirm(opt); 46 + return Modal.confirm(opt) as any;
39 } 47 }
40 const baseOptions = { 48 const baseOptions = {
41 okText: '确定', 49 okText: '确定',
src/utils/index.ts
  1 +export const timestamp = () => +Date.now();
  2 +export const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n));
  3 +export const noop = () => {};
  4 +export const now = () => Date.now();
1 /** 5 /**
2 * @description: Set ui mount node 6 * @description: Set ui mount node
3 */ 7 */