Skip to content

Commit 35d2bfc

Browse files
committed
fix: fix message type error
1 parent f645680 commit 35d2bfc

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

CHANGELOG.zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- 修复表格开启搜索表单折叠问题
2424
- 修复表格 size 为 samll 时候,fixed 列样式问题
2525
- 修复多标签页关闭报错问题
26+
- 修复 message 类型错误
2627

2728
## 2.0.0-rc.7 (2020-10-31)
2829

src/components/Container/src/collapse/CollapseHeader.vue

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,15 @@
1111

1212
<div class="collapse-container__action">
1313
<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')" />
1515
</div>
1616
</div>
1717
</template>
1818
<script lang="ts">
1919
import { defineComponent } from 'vue';
20-
import { BasicArrow } from '/@/components/Basic';
21-
import { BasicTitle } from '/@/components/Basic';
20+
import { BasicArrow, BasicTitle } from '/@/components/Basic';
2221
export default defineComponent({
2322
inheritAttrs: false,
2423
components: { BasicArrow, BasicTitle },
25-
setup(_, { emit }) {
26-
function handleExpand() {
27-
emit('expand');
28-
}
29-
return { handleExpand };
30-
},
3124
});
3225
</script>

src/hooks/core/asyncComputed.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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';
33

44
export type Fn<T> = () => T;
55
export type AnyFn<T> = (...arg: any) => T;
@@ -86,7 +86,7 @@ export interface MessageOptions {
8686
/** Set the distance to the top of viewport. Default is 20 px. */
8787
offset?: number;
8888
}
89-
export interface ModalOptionsEx extends Omit<ModalOptions, 'iconType'> {
89+
export interface ModalOptionsEx extends Omit<ModalFuncProps, 'iconType'> {
9090
iconType: 'warning' | 'success' | 'error' | 'info';
9191
}
9292
export type ModalOptionsPartial = Partial<ModalOptionsEx> & Pick<ModalOptionsEx, 'content'>;

src/hooks/web/useMessage.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import type { ModalOptionsEx, ModalOptionsPartial } from '/@/hooks/core/types';
2+
import type { ModalFunc, ModalFuncProps } from 'ant-design-vue/lib/modal/Modal';
23

34
import { Modal, message as Message, notification } from 'ant-design-vue';
45
import { InfoCircleFilled, CheckCircleFilled, CloseCircleFilled } from '@ant-design/icons-vue';
5-
import { ModalOptions, ModalConfirm } from 'ant-design-vue/types/modal';
66

77
import { useSetting } from '/@/hooks/core/useSetting';
88

9+
interface ConfirmOptions {
10+
info: ModalFunc;
11+
success: ModalFunc;
12+
error: ModalFunc;
13+
warn: ModalFunc;
14+
warning: ModalFunc;
15+
}
16+
917
const { projectSetting } = useSetting();
1018

1119
function getIcon(iconType: string) {
@@ -20,22 +28,22 @@ function getIcon(iconType: string) {
2028
}
2129
}
2230
function renderContent({ content }: Pick<ModalOptionsEx, 'content'>) {
23-
return <div innerHTML={`<div>${content}</div>`}></div>;
31+
return <div innerHTML={`<div>${content as string}</div>`}></div>;
2432
}
2533

2634
/**
2735
* @description: Create confirmation box
2836
*/
29-
function createConfirm(options: ModalOptionsEx): ModalConfirm {
37+
function createConfirm(options: ModalOptionsEx): ConfirmOptions {
3038
const iconType = options.iconType || 'warning';
3139
Reflect.deleteProperty(options, 'iconType');
32-
const opt: ModalOptions = {
40+
const opt: ModalFuncProps = {
3341
centered: true,
3442
icon: getIcon(iconType),
3543
...projectSetting.messageSetting,
3644
...options,
3745
};
38-
return Modal.confirm(opt);
46+
return Modal.confirm(opt) as any;
3947
}
4048
const baseOptions = {
4149
okText: '确定',

src/utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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();
15
/**
26
* @description: Set ui mount node
37
*/

0 commit comments

Comments
 (0)