Files
boursecu_admin/src/pages/menuPages/configuration/components/SwitchConfigs.vue
T

72 lines
1.8 KiB
Vue
Raw Normal View History

<template>
2026-05-25 10:49:08 +03:30
<div class="mb-2 justify-between items-center border-1 border-gray-300 border-solid rounded-lg p-3">
<div>
<div class="flex justify-between">
<div>{{ item.title_fa ?? item.name ?? '-' }}</div>
<div>
<a-switch
checked-children="فعال"
un-checked-children="غیرفعال"
v-model:checked="isActive"
@change="ok"
/>
</div>
</div>
</div>
2026-05-25 10:49:08 +03:30
<div class="flex justify-between items-center mt-2">
<div class="text-xs items-center">کلید: {{ item.key }}</div>
<div class="flex">
<a-switch
checked-children="نمایش"
un-checked-children="عدم نمایش"
2026-04-29 16:24:50 +03:30
v-model:checked="value"
@change="ok"
2026-05-25 10:49:08 +03:30
/>
</div>
</div>
2026-05-25 10:49:08 +03:30
</div>
</template>
<script setup lang="ts">
2026-05-25 10:49:08 +03:30
import { loading } from '@/utils'
import { setConfiguration } from '@/api/configuration'
import { message } from 'ant-design-vue'
import { onMounted } from 'vue'
import type { TagItem } from '@/components/BasicTags/model'
interface Prop {
2026-04-29 16:24:50 +03:30
item: TagItem
}
const props = defineProps<Prop>()
2026-05-25 10:49:08 +03:30
const value = ref<boolean>(false)
const isActive = ref<boolean>(false)
async function ok() {
let obj = {
id: props.item.id,
key: props.item.key,
2026-05-25 10:49:08 +03:30
value: value.value ? 'true' : 'false',
type: props.item.type,
title_fa: props.item.title_fa ?? props.item.name,
2026-04-29 16:24:50 +03:30
description: props.item.description,
2026-05-25 10:49:08 +03:30
is_active: isActive.value
}
try {
loading.value = true
await setConfiguration(obj)
message.success('تغییر با موفقیت انجام شد')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
2026-04-29 16:24:50 +03:30
onMounted(() => {
value.value = props.item.value === 'true'
2026-05-25 10:49:08 +03:30
isActive.value = props.item.is_active === true
2026-04-29 16:24:50 +03:30
})
</script>