<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="base-sys-datasource" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			prop: "name",
			label: "数据源名",
			required: true,
			component: { name: "el-input" }
		},
		{ prop: "host", label: "IP地址", component: { name: "el-input" } },
		{ prop: "port", label: "端口", component: { name: "el-input" } },
		{ prop: "user", label: "用户名", component: { name: "el-input" } },
		{ prop: "password", label: "密码", component: { name: "el-input" } },
		{
			prop: "database",
			label: "实例名(地址)",
			required: true,
			component: { name: "el-input" }
		},
		{
			prop: "type",
			label: "类型",
			component: {
				name: "el-radio-group",
				options: [
					{ label: "postgresql", value: 1, color: "#67C23A" },
					{ label: "oracle", value: 0 },
					{ label: "mysql", value: 2, color: "#E6A23C" },
					{ label: "sqlite", value: 3, color: "#F56C6C" }
				]
			},
			value: 1,
			required: true
		},
		{
			prop: "remark",
			label: "备注",
			component: { name: "el-input", props: { type: "textarea", rows: 4 } }
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		// { prop: "id", label: "ID" },
		{ prop: "name", label: "数据源名" },
		{ prop: "host", label: "IP地址" },
		{ prop: "port", label: "端口" },
		{ prop: "user", label: "用户名" },
		{ prop: "password", label: "密码" },
		{ prop: "database", label: "实例名(地址)" },
		{
			prop: "type",
			label: "数据库类型",
			dict: [
				{ value: "0：oracle" },
				{ value: "1：pgsql", color: "#67C23A" },
				{ value: "2：mysql", color: "#E6A23C" },
				{ value: "3：sqlite", color: "#F56C6C" }
			]
		},
		{ prop: "remark", label: "备注", showOverflowTooltip: true },
		{ prop: "createTime", label: "创建时间", sortable: "desc", width: 160 },
		{ prop: "updateTime", label: "更新时间", sortable: "custom", width: 160 },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.base.sys.datasource
	},
	(app) => {
		app.refresh();
	}
);
</script>
