refactor: codegen

This commit is contained in:
xingyu
2022-07-28 21:40:15 +08:00
parent 607f6e4bb5
commit 291f31be98
9 changed files with 127 additions and 126 deletions

View File

@ -1,47 +1,34 @@
<script lang="ts">
import { defineComponent, onMounted, onUpdated, PropType, ref } from 'vue'
<script setup lang="ts">
import { onMounted, onUpdated, PropType, ref } from 'vue'
import { getDictOptions, DictDataType } from '@/utils/dict'
import { ElTag } from 'element-plus'
export default defineComponent({
name: 'DictTag',
components: {
ElTag
const props = defineProps({
type: {
type: String as PropType<string>,
required: true
},
props: {
type: {
type: String as PropType<string>,
required: true
},
value: {
type: [String, Number] as PropType<string | number>,
required: true
}
},
setup(props) {
const dictData = ref<DictDataType>()
function getDictObj(dictType: string, value: string) {
const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) {
dictData.value = dict
}
})
}
onMounted(() => {
return getDictObj(props.type, props.value?.toString())
})
onUpdated(() => {
getDictObj(props.type, props.value?.toString())
})
return {
props,
dictData
}
value: {
type: [String, Number] as PropType<string | number>,
required: true
}
})
const dictData = ref<DictDataType>()
const getDictObj = (dictType: string, value: string) => {
const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) {
dictData.value = dict
}
})
}
onMounted(() => {
return getDictObj(props.type, props.value?.toString())
})
onUpdated(() => {
getDictObj(props.type, props.value?.toString())
})
</script>
<template>
<!-- 默认样式 -->