广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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="0"
    unchecked-value="1"
    :disabled="props.disabled"
    @update:value="handleUpdateValue"
  />
</template>
 
<style scoped></style>