137 lines
3.4 KiB
TypeScript
137 lines
3.4 KiB
TypeScript
import { computed, ref } from 'vue';
|
||
import { cloneDeep } from 'lodash-es';
|
||
import { FormSchema } from '@/components/Form';
|
||
import { useDictStore } from '@/store/modules/dict';
|
||
import { List as TenantList } from '@/api/imTenant';
|
||
|
||
const dict = useDictStore();
|
||
|
||
export const tenantOptions = ref<any[]>([]);
|
||
|
||
export class State {
|
||
public tenantId = 0;
|
||
public tenantName = '';
|
||
public id = 0;
|
||
public purpose = '';
|
||
public maxSize = 0;
|
||
public retentionDays = 0;
|
||
public allowedMimes = '[]';
|
||
public autoCleanup = 0;
|
||
public scanEnabled = 0;
|
||
public remark = '';
|
||
public updatedAt = '';
|
||
|
||
constructor(state?: Partial<State>) {
|
||
if (state) Object.assign(this, state);
|
||
}
|
||
}
|
||
|
||
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 schemas = ref<FormSchema[]>([
|
||
{
|
||
field: 'tenantId',
|
||
component: 'NSelect',
|
||
label: '租户',
|
||
componentProps: {
|
||
clearable: false,
|
||
options: computed(() => tenantOptions.value),
|
||
placeholder: '请选择租户',
|
||
},
|
||
},
|
||
{
|
||
field: 'purpose',
|
||
component: 'NSelect',
|
||
label: '用途',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: dict.getOption('ImFilePurposeOptions'),
|
||
placeholder: '请选择用途',
|
||
},
|
||
},
|
||
{
|
||
field: 'autoCleanup',
|
||
component: 'NSelect',
|
||
label: '自动清理',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: dict.getOption('ImFilePolicySwitchOptions'),
|
||
placeholder: '请选择开关',
|
||
},
|
||
},
|
||
{
|
||
field: 'scanEnabled',
|
||
component: 'NSelect',
|
||
label: '病毒扫描',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: dict.getOption('ImFilePolicySwitchOptions'),
|
||
placeholder: '请选择开关',
|
||
},
|
||
},
|
||
]);
|
||
|
||
export const columns = [
|
||
{
|
||
title: '用途',
|
||
key: 'purpose',
|
||
align: 'left',
|
||
width: 130,
|
||
render(row: State) {
|
||
return dict.getLabel('ImFilePurposeOptions', row.purpose) || row.purpose;
|
||
},
|
||
},
|
||
{ title: '大小上限', key: 'maxSize', align: 'left', width: 120 },
|
||
{ title: '保留天数', key: 'retentionDays', align: 'left', width: 100 },
|
||
{
|
||
title: '自动清理',
|
||
key: 'autoCleanup',
|
||
align: 'left',
|
||
width: 100,
|
||
render(row: State) {
|
||
return dict.getLabel('ImFilePolicySwitchOptions', row.autoCleanup);
|
||
},
|
||
},
|
||
{
|
||
title: '病毒扫描',
|
||
key: 'scanEnabled',
|
||
align: 'left',
|
||
width: 100,
|
||
render(row: State) {
|
||
return dict.getLabel('ImFilePolicySwitchOptions', row.scanEnabled);
|
||
},
|
||
},
|
||
{ title: 'MIME白名单', key: 'allowedMimes', align: 'left', width: 260 },
|
||
{ title: '备注', key: 'remark', align: 'left', width: 180 },
|
||
{ title: '更新时间', key: 'updatedAt', align: 'left', width: 180 },
|
||
];
|
||
|
||
export const rules = {
|
||
purpose: { required: true, trigger: ['blur', 'change'], type: 'string', message: '请选择用途' },
|
||
maxSize: {
|
||
required: true,
|
||
trigger: ['blur', 'input'],
|
||
type: 'number',
|
||
message: '请输入大小上限',
|
||
},
|
||
};
|
||
|
||
export function loadOptions() {
|
||
dict.loadOptions(['ImFilePurposeOptions', 'ImFilePolicySwitchOptions']);
|
||
}
|
||
|
||
export async function loadTenantOptions() {
|
||
const res = await TenantList({ page: 1, perPage: 100 });
|
||
tenantOptions.value = (res?.list || []).map((item) => ({
|
||
label: `${item.name}(${item.code})`,
|
||
value: item.id,
|
||
}));
|
||
return tenantOptions.value;
|
||
}
|