294 lines
6.8 KiB
TypeScript
294 lines
6.8 KiB
TypeScript
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 aliyunModerationEnabled = 0; // 是否启用阿里云内容审核
|
|
public localModerationEnabled = 0; // 是否启用本地内容审核
|
|
public messageEncryptionEnabled = 0; // 是否启用消息加密
|
|
public realnameReviewPolicy = 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<State>) {
|
|
if (state) {
|
|
Object.assign(this, state);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class UsageState {
|
|
public id = 0;
|
|
public code = '';
|
|
public name = '';
|
|
public dbName = '';
|
|
public dbDsnConfigured = false;
|
|
public dbReachable = false;
|
|
public dbCheckError = '';
|
|
public schemaVersion = '';
|
|
public userCount = 0;
|
|
public activeUserCount = 0;
|
|
public groupCount = 0;
|
|
public deviceCount = 0;
|
|
public pushTokenCount = 0;
|
|
public inviteUseCount = 0;
|
|
public outboxPendingCount = 0;
|
|
public warnings: string[] = [];
|
|
}
|
|
|
|
export function newState(state: State | Record<string, any> | 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<FormSchema[]>([
|
|
{
|
|
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: dict.getOption('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: 'aliyunModerationEnabled',
|
|
align: 'left',
|
|
width: 120,
|
|
render(row: State) {
|
|
return h(
|
|
NTag,
|
|
{ type: row.aliyunModerationEnabled === 1 ? 'success' : 'default', bordered: false },
|
|
{ default: () => (row.aliyunModerationEnabled === 1 ? '已启用' : '未启用') }
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '本地审核',
|
|
key: 'localModerationEnabled',
|
|
align: 'left',
|
|
width: 120,
|
|
render(row: State) {
|
|
return h(
|
|
NTag,
|
|
{ type: row.localModerationEnabled === 1 ? 'success' : 'default', bordered: false },
|
|
{ default: () => (row.localModerationEnabled === 1 ? '已启用' : '未启用') }
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '消息加密',
|
|
key: 'messageEncryptionEnabled',
|
|
align: 'left',
|
|
width: 120,
|
|
render(row: State) {
|
|
return h(
|
|
NTag,
|
|
{ type: row.messageEncryptionEnabled === 1 ? 'success' : 'default', bordered: false },
|
|
{ default: () => (row.messageEncryptionEnabled === 1 ? '已启用' : '未启用') }
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '实名审核',
|
|
key: 'realnameReviewPolicy',
|
|
align: 'left',
|
|
width: 150,
|
|
render(row: State) {
|
|
return h(
|
|
NTag,
|
|
{ type: row.realnameReviewPolicy === 1 ? 'success' : 'default', bordered: false },
|
|
{ default: () => (row.realnameReviewPolicy === 1 ? '自动审核' : '人工审核') }
|
|
);
|
|
},
|
|
},
|
|
{
|
|
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']);
|
|
}
|