github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/src/views/Variables/new.vue (about) 1 <script setup lang="ts"> 2 import {onMounted, onUnmounted, ref} from 'vue' 3 import {useI18n} from '@/hooks/web/useI18n' 4 import {ElButton} from 'element-plus' 5 import {useRouter} from 'vue-router' 6 import api from "@/api/api"; 7 import {ApiVariable} from "@/api/stub"; 8 import {ContentWrap} from "@/components/ContentWrap"; 9 import VariableForm from "@/views/Variables/components/VariableForm.vue"; 10 11 const {push} = useRouter() 12 const {t} = useI18n() 13 14 const currentRow = ref<Nullable<ApiVariable>>(null) 15 16 onMounted(() => { 17 currentRow.value = { 18 name: '', 19 value: '', 20 tags: [] 21 } as ApiVariable 22 }) 23 24 onUnmounted(() => { 25 26 }) 27 28 const save = async () => { 29 const res = await api.v1.variableServiceAddVariable(currentRow.value) 30 .catch(() => { 31 }) 32 .finally(() => { 33 }) 34 if (res) { 35 push(`/etc/variables/edit/${currentRow.value.name}`) 36 } 37 } 38 39 const cancel = () => { 40 push('/etc/variables') 41 } 42 43 </script> 44 45 <template> 46 <ContentWrap> 47 <VariableForm v-if="currentRow" v-model="currentRow"/> 48 49 <div style="text-align: right"> 50 51 <ElButton type="primary" @click="save()"> 52 {{ t('main.save') }} 53 </ElButton> 54 55 <ElButton type="default" @click="cancel()"> 56 {{ t('main.cancel') }} 57 </ElButton> 58 59 </div> 60 </ContentWrap> 61 62 </template> 63 64 <style lang="less" scoped> 65 66 </style>