Browse Source

👣 编写基础模块多租户

master
wangxiang 3 years ago
parent
commit
325b07100a
  1. 25
      kicc-ui/src/views/system/tenant/TenantModal.vue
  2. 19
      kicc-ui/src/views/system/tenant/tenant.data.ts

25
kicc-ui/src/views/system/tenant/TenantModal.vue

@ -17,14 +17,15 @@
import { ref, unref } from 'vue'; import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './tenant.data'; import { formSchema } from './tenant.data';
import { addTenant, editTenant, getTenant } from '/@/api/platform/system/controller/tenant'; import {addTenant, editTenant, getTenant, listTenant} from '/@/api/platform/system/controller/tenant';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import {isEmpty} from "/@/utils/is";
/** 通用变量统一声明区域 */ /** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>(''); const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ /** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate }] = useForm({ const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
labelWidth: 100, labelWidth: 100,
schemas: formSchema, schemas: formSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
@ -38,6 +39,26 @@
tag.value = data._tag; tag.value = data._tag;
const tenantId = data.record?.id; const tenantId = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false }; const props: Partial<ModalProps> = { confirmLoading: false };
await updateSchema({
field: 'code',
rules: [
{
required: true,
whitespace: true,
message: '请输入多租户编码'
},
{
validator: async (rule, value) => {
if (!isEmpty(value)) {
const result = await listTenant({ code: value });
const list = result.data?.filter(item => item.id != tenantId);
if(list?.length > 0) return Promise.reject('该多租户编码已存在');
}
return Promise.resolve();
},
validateTrigger: 'blur'
}]
});
// tag // tag
switch (unref(tag)) { switch (unref(tag)) {
case 'add': case 'add':

19
kicc-ui/src/views/system/tenant/tenant.data.ts

@ -20,7 +20,7 @@ export const columns: BasicColumn[] = [
}, },
{ {
title: '多租户编码', title: '多租户编码',
dataIndex: 'code', dataIndex: 'code'
}, },
{ {
title: '开始时间', title: '开始时间',
@ -47,6 +47,7 @@ export const columns: BasicColumn[] = [
{ {
title: '备注', title: '备注',
dataIndex: 'remarks', dataIndex: 'remarks',
width: 300,
customRender: ({record}) => { customRender: ({record}) => {
return record.remarks || h(Tag, { color: 'red' }, () => '暂无数据'); return record.remarks || h(Tag, { color: 'red' }, () => '暂无数据');
} }
@ -108,22 +109,6 @@ export const formSchema: FormSchema[] = [
field: 'code', field: 'code',
label: '多租户编码', label: '多租户编码',
component: 'Input', component: 'Input',
rules: [
{
required: true,
whitespace: true,
message: '请输入多租户编码',
},
{
validator: async (rule, value) => {
if (!isEmpty(value)) {
const result = await listTenant({ code: value });
if(result.data?.length > 0) return Promise.reject('该多租户编码已存在');
}
return Promise.resolve();
},
validateTrigger: 'blur'
}],
colProps: { colProps: {
span: 12 span: 12
} }

Loading…
Cancel
Save