<template>
	<el-dialog title="代码预览" v-model="visible" :width="1200" destroy-on-close @closed="$emit('closed')">
		<el-tabs v-model="type" style="width: 100%;">
			<el-tab-pane name="model" label="model.php">
				<pi-pre-code lang="php" copy>{{ data['model.php'] }}</pi-pre-code>
			</el-tab-pane>
			<el-tab-pane name="request" label="request.php">
				<pi-pre-code lang="php" copy>{{ data['request.php'] }}</pi-pre-code>
			</el-tab-pane>
			<el-tab-pane name="controller" label="controller.php">
				<pi-pre-code lang="php" copy>{{ data['controller.php'] }}</pi-pre-code>
			</el-tab-pane>
			<el-tab-pane name="api.ts" label="api.ts">
				<pi-pre-code lang="typescript" copy>{{ data['api.ts'] }}</pi-pre-code>
			</el-tab-pane>
			<el-tab-pane name="index" label="index.vue">
				<pi-pre-code lang="typescript" copy>{{ data['index.vue'] }}</pi-pre-code>
			</el-tab-pane>
			<el-tab-pane name="save" label="save.vue">
				<pi-pre-code lang="typescript" copy>{{ data['save.vue'] }}</pi-pre-code>
			</el-tab-pane>
		</el-tabs>
	</el-dialog>
</template>

<script setup>
import {ref} from 'vue'
import api from "@/api/index.js"
import piPreCode from "@/components/piPreCode"

defineExpose({
	open
})

let visible = ref(false)
let type = ref("model")
let data = ref({})

function open(id) {
	initData(id)
	visible.value = true
}

async function initData(id) {
	const res = await api.tools.gen_table.show({id: id})
	data.value = res.data
}
</script>
