- api/tenant.ts + /system/tenant 页面(ty-crud) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
2.7 KiB
Vue
84 lines
2.7 KiB
Vue
<template>
|
|
<ty-crud
|
|
entity-name="租户"
|
|
:columns="columns"
|
|
:search-schema="searchSchema"
|
|
:form-schema="formSchema"
|
|
:list="list"
|
|
:create="create"
|
|
:update="update"
|
|
:remove="remove"
|
|
id-key="id"
|
|
name-key="name"
|
|
:edit-readonly-keys="['code']"
|
|
/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { JsonSchema, PageQuery, TableColumn } from '@/types/crud'
|
|
import { createTenant, deleteTenant, listTenants, updateTenant, type TenantListQuery } from '@/api/tenant'
|
|
|
|
const STATUS_MAP = {
|
|
enabled: { label: '启用', type: 'success' },
|
|
disabled: { label: '停用', type: 'info' },
|
|
} as const
|
|
|
|
const columns: TableColumn[] = [
|
|
{ prop: 'name', label: '租户名称', minWidth: 140 },
|
|
{ prop: 'code', label: '租户编码', minWidth: 140 },
|
|
{ prop: 'status', label: '状态', width: 80, align: 'center', type: 'tag', tagMap: STATUS_MAP },
|
|
{ prop: 'remark', label: '备注', minWidth: 160 },
|
|
{ prop: 'createdAt', label: '创建时间', width: 160, type: 'datetime' },
|
|
]
|
|
|
|
const searchSchema: JsonSchema = {
|
|
type: 'object',
|
|
properties: {
|
|
name: { type: 'string', title: '租户名称', placeholder: '请输入名称' },
|
|
code: { type: 'string', title: '租户编码', placeholder: '请输入编码' },
|
|
status: {
|
|
type: 'string',
|
|
title: '状态',
|
|
enum: ['enabled', 'disabled'],
|
|
enumNames: ['启用', '停用'],
|
|
placeholder: '全部',
|
|
},
|
|
},
|
|
}
|
|
|
|
const formSchema: JsonSchema = {
|
|
type: 'object',
|
|
properties: {
|
|
code: { type: 'string', title: '租户编码', placeholder: '如 touyun', minLength: 2 },
|
|
name: { type: 'string', title: '租户名称', placeholder: '如 投云' },
|
|
status: {
|
|
type: 'string',
|
|
title: '状态',
|
|
enum: ['enabled', 'disabled'],
|
|
enumNames: ['启用', '停用'],
|
|
default: 'enabled',
|
|
},
|
|
remark: { type: 'string', title: '备注', format: 'textarea', placeholder: '请输入备注' },
|
|
},
|
|
required: ['code', 'name'],
|
|
}
|
|
|
|
function toListQuery(query: PageQuery): TenantListQuery {
|
|
const str = (v: unknown): string | undefined => (typeof v === 'string' && v !== '' ? v : undefined)
|
|
return {
|
|
page: query.page,
|
|
pageSize: query.pageSize,
|
|
name: str(query.name),
|
|
code: str(query.code),
|
|
status: str(query.status),
|
|
}
|
|
}
|
|
|
|
const list = (query: PageQuery, signal?: AbortSignal) => listTenants(toListQuery(query), signal)
|
|
const create = (data: Record<string, any>) =>
|
|
createTenant({ code: data.code, name: data.name, status: data.status, remark: data.remark })
|
|
const update = (id: string, data: Record<string, any>) =>
|
|
updateTenant(id, { name: data.name, status: data.status, remark: data.remark })
|
|
const remove = (id: string) => deleteTenant(id)
|
|
</script>
|