refactor:优化代码生成

This commit is contained in:
JaguarJack 2023-07-19 17:32:53 +08:00
parent 78c25497d6
commit d5ed1dd461
2 changed files with 15 additions and 23 deletions

View File

@ -60,6 +60,20 @@ import { Delete } from '@element-plus/icons-vue'
const generateStore = useGenerateStore()
const structures = computed(() => {
generateStore.getStructures.forEach(struct => {
if (struct.field === 'id' || struct.field === 'created_at' || struct.field === 'updated_at') {
struct.form = false
}
if (struct.field === 'sort') {
struct.form_component = 'input-number'
}
if (struct.field === 'status') {
struct.form_component = 'select'
}
})
return generateStore.getStructures
})

View File

@ -88,14 +88,13 @@
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, Ref, ref } from 'vue'
import { computed, Ref, ref } from 'vue'
import { useSchemaStore, Structure } from '../store'
import { Delete, Plus, Edit } from '@element-plus/icons-vue'
import type { FormInstance } from 'element-plus'
import Message from '/admin/support/message'
import http from '/admin/support/http'
import { Code } from '/admin/enum/app'
import Sortable from 'sortablejs'
const schemaStore = useSchemaStore()
const emits = defineEmits(['prev', 'next'])
@ -120,27 +119,6 @@ const updateField = (id: number) => {
})
}
onMounted(() => {
const tbody = document.querySelector('.draggable .el-table__body-wrapper tbody')
const structures = schemaStore.getStructures
Sortable.create(tbody, {
draggable: 'tr',
onEnd({ newIndex, oldIndex }) {
const newStructures = []
const s = structures.splice(oldIndex, newIndex - oldIndex)
s.concat(structures).forEach(item => {
newStructures.push(item)
})
schemaStore.setStructures(newStructures)
// console.log(structure)
// structures[newIndex] = structures[oldIndex]
// structures[oldIndex] = temp
},
})
})
const form = ref<FormInstance>()
const submitStructure = (formEl: FormInstance | undefined) => {
if (!formEl) return