fix(系统设置): 修改公共组件弹窗规范

This commit is contained in:
xinxin.wu 2023-08-22 18:31:19 +08:00 committed by f2c-ci-robot[bot]
parent e0ee5f415a
commit affd770918
2 changed files with 50 additions and 52 deletions

View File

@ -12,33 +12,37 @@
{{ t(props.title) }}
</template>
<slot></slot>
<!-- 自定义footer -->
<slot name="self-footer"></slot>
<!-- 默认footer -->
<template #footer>
<div class="flex" :class="[props.showSwitch ? 'justify-between' : 'justify-end']">
<div v-if="props.showSwitch" class="flex flex-row items-center justify-center">
<a-switch v-model="switchEnable" class="mr-1" size="small" />
<a-tooltip v-if="props.showSwitchTooltip" :content="t(props.showSwitchTooltip)">
<span class="flex items-center"
><span class="mr-2">{{ props.switchName }}</span>
<span><svg-icon width="16px" height="16px" :name="'infotip'" /></span
></span>
</a-tooltip>
</div>
<div class="flex justify-end">
<a-space>
<slot name="footer">
<div class="flex" :class="[props.switchProps?.showSwitch ? 'justify-between' : 'justify-end']">
<div v-if="props.switchProps?.showSwitch" class="flex flex-row items-center justify-center">
<a-switch v-model="switchEnable" class="mr-1" size="small" />
<a-tooltip v-if="props.switchProps?.switchTooltip" :content="t(props.switchProps?.switchTooltip)">
<span class="flex items-center"
><span class="mr-1">{{ props.switchProps?.switchName }}</span>
<span><svg-icon width="16px" height="16px" :name="'infotip'" /></span
></span>
</a-tooltip>
</div>
<div class="flex justify-end">
<a-button v-if="showCancel" type="secondary" @click="handleCancel">{{
props.cancelText ? t(props.cancelText) : $t('ms.dialog.cancel')
props.cancelText ? t(props.cancelText) : t('ms.dialog.cancel')
}}</a-button>
<!-- 自定义确认与取消之间其他按钮可以直接使用loading按钮插槽 -->
<slot name="self-button"></slot>
<a-button type="primary" :loading="props.loading" :disabled="props.disabledOk" @click="confirmHandler">
<a-button
class="ml-3"
type="primary"
:loading="props.loading"
:disabled="props.disabledOk"
@click="confirmHandler"
>
{{ props.okText ? t(props.okText) : t('ms.dialog.ok') }}
</a-button>
</a-space>
</div>
</div>
</div>
</slot>
</template>
</a-modal>
</template>
@ -46,44 +50,44 @@
<script setup lang="ts">
import { ref, useAttrs, watch } from 'vue';
import { useI18n } from '@/hooks/useI18n';
import { FormInstance } from '@arco-design/web-vue/es/form';
const { t } = useI18n();
export type buttontype = 'text' | 'dashed' | 'outline' | 'primary' | 'secondary' | undefined;
export type buttontype = 'text' | 'dashed' | 'outline' | 'primary' | 'secondary';
export type SizeType = 'medium' | 'large' | 'small';
export interface SwitchProps {
switchTooltip?: string; //
switchName?: string; //
enable: boolean | undefined; //
showSwitch: boolean; //
}
export type DialogType = Partial<{
dialogSize: SizeType; // medium large small
showfooter: boolean; // footer
title: string; //
showCancel: boolean; //
okText: string; //
cancelText: string; //
showSwitchTooltip: string; //
showSwitch: boolean; //
visible: boolean;
confirm: (enable: boolean | undefined) => void; //
formRef: FormInstance | null; // ref
disabledOk: boolean; //
close: () => void;
enable: boolean | undefined; //
switchName: string; //
switchProps: SwitchProps; // showSwitch
}> & {
dialogSize: SizeType; // medium large small
title: string;
confirm: (enable: boolean | undefined) => void; //
visible: boolean;
loading: boolean;
}>;
close: () => void;
};
const props = withDefaults(defineProps<DialogType>(), {
showfooter: true,
showSwitch: false,
showCancel: true,
title: '',
disabledOk: false,
close: Function,
enable: undefined,
});
const emits = defineEmits<{
(event: 'close'): void;
(event: 'update:visible', visible: boolean): void;
(event: 'update:enable', enable: boolean): void;
}>();
const attrs = useAttrs();
@ -100,17 +104,11 @@
);
watch(
() => props.enable,
() => props.switchProps?.enable,
(val) => {
switchEnable.value = val;
}
);
watch(
() => switchEnable.value,
(val) => {
emits('update:enable', val);
}
if (val) switchEnable.value = val;
},
{ deep: true }
);
const handleCancel = () => {

View File

@ -1,23 +1,23 @@
import { ref } from 'vue';
export default function useAsyncHandler() {
const confirmLoading = ref<boolean>(false);
const loading = ref<boolean>(false);
async function handleAsyncProcess<T>(reqFun: T): Promise<any> {
confirmLoading.value = true;
async function handleAsyncProcess<T>(reqAsyncFun: T): Promise<any> {
loading.value = true;
try {
await reqFun;
await reqAsyncFun;
} catch (error) {
console.log(error);
confirmLoading.value = false;
return new Promise(() => {});
loading.value = false;
return Promise.reject();
} finally {
confirmLoading.value = false;
loading.value = false;
}
}
return {
confirmLoading,
loading,
handleAsyncProcess,
};
}