feat: 新增业务组件

This commit is contained in:
xlsea
2024-09-11 17:34:31 +08:00
parent 9cbbaff297
commit 0a62e4dcaa
6 changed files with 107 additions and 70 deletions

View File

@ -0,0 +1,61 @@
<script setup lang="ts">
import { useBoolean } from '@sa/hooks';
import { enableStatusRecord } from '@/constants/business';
defineOptions({
name: 'StatusSwitch'
});
interface Props {
disabled?: boolean;
info?: string;
}
const props = withDefaults(defineProps<Props>(), {
disabled: false,
info: ''
});
const value = defineModel<Api.Common.EnableStatus>('value', { default: '0' });
interface Emits {
(e: 'submitted', value: Api.Common.EnableStatus, callback: (flag: boolean) => void): void;
}
const emit = defineEmits<Emits>();
/** 状态切换过程的 loading 状态 */
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean();
const handleUpdateValue = (val: Api.Common.EnableStatus) => {
value.value = val === '0' ? '1' : '0';
window.$dialog?.warning({
title: '系统提示',
content: `确定要${enableStatusRecord[val]} ${props.info} 吗?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
startLoading();
emit('submitted', val, flag => {
if (flag) value.value = val;
endLoading();
});
},
onNegativeClick: () => {}
});
};
</script>
<template>
<NSwitch
v-model:value="value"
:loading="loading"
:rubber-band="false"
checked-value="1"
unchecked-value="0"
:disabled="props.disabled"
@update:value="handleUpdateValue"
/>
</template>
<style scoped></style>

View File

@ -1,31 +0,0 @@
<script setup lang="ts">
import type { TagProps } from 'naive-ui';
import { useAttrs } from 'vue';
import { enableStatusRecord } from '@/constants/business';
import { isNotNull } from '@/utils/common';
defineOptions({
name: 'StatusTag'
});
interface Props {
[key: string]: any;
}
defineProps<Props>();
const status = defineModel<Api.Common.EnableStatus>('value', { required: true });
const tagMap: Record<Api.Common.EnableStatus, NaiveUI.ThemeColor> = {
'0': 'success',
'1': 'warning'
};
const attrs: TagProps = useAttrs();
</script>
<template>
<NTag v-if="isNotNull(status)" :type="tagMap[status]" v-bind="attrs">{{ enableStatusRecord[status] }}</NTag>
</template>
<style scoped></style>