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

View File

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