import { computed, h, ref } from 'vue'; import { NTag } from 'naive-ui'; import { cloneDeep } from 'lodash-es'; import { FormSchema } from '@/components/Form'; import { defRangeShortcuts } from '@/utils/dateUtil'; import { renderPopoverMemberSumma, MemberSumma } from '@/utils'; import { useDictStore } from '@/store/modules/dict'; const dict = useDictStore(); export class State { public id = 0; // ID public code = ''; // 租户编码 public name = ''; // 租户名称 public tenantDesc = ''; // 租户描述 public dbName = ''; // 业务库名 public dbDsn = ''; // 独立连接串 public state = 1; // 状态 public maxUsers = 0; // 最大用户数 public maxGroups = 0; // 最大群组数 public maxGroupMembers = 0; // 最大群成员数 public dbDsnConfigured = false; // 是否配置独立连接串 public createdBy = 0; // 创建者 public createdBySumma?: null | MemberSumma = null; // 创建者摘要信息 public updatedBy = 0; // 更新者 public updatedBySumma?: null | MemberSumma = null; // 更新者摘要信息 public createdAt = ''; // 创建时间 public updatedAt = ''; // 修改时间 constructor(state?: Partial) { if (state) { Object.assign(this, state); } } } export function newState(state: State | Record | null): State { if (state !== null) { if (state instanceof State) { return cloneDeep(state); } return new State(state); } return new State(); } // 表单验证规则 export const rules = { code: { required: true, trigger: ['blur', 'input'], type: 'string', message: '请输入租户编码', }, name: { required: true, trigger: ['blur', 'input'], type: 'string', message: '请输入租户名称', }, state: { required: true, trigger: ['blur', 'change'], type: 'number', message: '请选择租户状态', }, }; // 表格搜索表单 export const schemas = ref([ { field: 'code', component: 'NInput', label: '租户编码', componentProps: { placeholder: '请输入租户编码', }, }, { field: 'name', component: 'NInput', label: '租户名称', componentProps: { placeholder: '请输入租户名称', }, }, { field: 'dbName', component: 'NInput', label: '业务库名', componentProps: { placeholder: '请输入业务库名', }, }, { field: 'state', component: 'NSelect', label: '状态', componentProps: { clearable: true, options: computed(() => dict.getOptions('ImTenantStateOptions')), placeholder: '请选择状态', }, }, { field: 'createdAt', component: 'NDatePicker', label: '创建时间', componentProps: { type: 'datetimerange', clearable: true, shortcuts: defRangeShortcuts(), }, }, ]); // 表格列 export const columns = [ { title: 'ID', key: 'id', align: 'left', width: 70, }, { title: '租户编码', key: 'code', align: 'left', width: 150, }, { title: '租户名称', key: 'name', align: 'left', width: 180, }, { title: '状态', key: 'state', align: 'left', width: 120, render(row: State) { return dict.getLabel('ImTenantStateOptions', row.state); }, }, { title: '业务库名', key: 'dbName', align: 'left', width: 160, }, { title: '独立连接串', key: 'dbDsnConfigured', align: 'left', width: 120, render(row: State) { return h( NTag, { type: row.dbDsnConfigured ? 'success' : 'default', bordered: false }, { default: () => (row.dbDsnConfigured ? '已配置' : '未配置') } ); }, }, { title: '最大用户', key: 'maxUsers', align: 'left', width: 110, render(row: State) { return row.maxUsers > 0 ? row.maxUsers : '不限'; }, }, { title: '最大群组', key: 'maxGroups', align: 'left', width: 110, render(row: State) { return row.maxGroups > 0 ? row.maxGroups : '不限'; }, }, { title: '群成员上限', key: 'maxGroupMembers', align: 'left', width: 120, render(row: State) { return row.maxGroupMembers > 0 ? row.maxGroupMembers : '不限'; }, }, { title: '创建者', key: 'createdBy', align: 'left', width: 150, render(row: State) { return renderPopoverMemberSumma(row.createdBySumma); }, }, { title: '创建时间', key: 'createdAt', align: 'left', width: 180, }, { title: '修改时间', key: 'updatedAt', align: 'left', width: 180, }, ]; // 加载字典数据选项 export function loadOptions() { dict.loadOptions(['ImTenantStateOptions']); }