feat: add IM file policy and org exports

This commit is contained in:
richjohnrambo
2026-08-21 23:07:06 +08:00
parent 204f96e07a
commit 5c3f6ae58d
19 changed files with 912 additions and 3 deletions
+9
View File
@@ -0,0 +1,9 @@
import { http } from '@/utils/http/axios';
export function List(params) {
return http.request({ url: '/imFilePolicy/list', method: 'GET', params });
}
export function Update(params) {
return http.request({ url: '/imFilePolicy/update', method: 'POST', params });
}
+9 -1
View File
@@ -1,9 +1,13 @@
import { http } from '@/utils/http/axios';
import { http, jumpExport } from '@/utils/http/axios';
export function DepartmentList(params) {
return http.request({ url: '/imOrg/departmentList', method: 'GET', params });
}
export function DepartmentExport(params) {
jumpExport('/imOrg/departmentExport', params);
}
export function DepartmentEdit(params) {
return http.request({ url: '/imOrg/departmentEdit', method: 'POST', params });
}
@@ -16,6 +20,10 @@ export function MemberList(params) {
return http.request({ url: '/imOrg/memberList', method: 'GET', params });
}
export function MemberExport(params) {
jumpExport('/imOrg/memberExport', params);
}
export function MemberEdit(params) {
return http.request({ url: '/imOrg/memberEdit', method: 'POST', params });
}
+225
View File
@@ -0,0 +1,225 @@
<template>
<div>
<div class="n-layout-page-header">
<n-card :bordered="false" title="IM文件策略" />
</div>
<n-card :bordered="false" class="proCard">
<BasicForm
ref="searchFormRef"
@register="register"
@submit="reloadTable"
@reset="handleReset"
@keyup.enter="reloadTable"
/>
<BasicTable
ref="actionRef"
:columns="columns"
:request="loadDataTable"
:row-key="(row) => row.tenantId + '-' + row.purpose"
:actionColumn="actionColumn"
:scroll-x="scrollX"
:resizeHeightOffset="-10000"
/>
</n-card>
<n-modal
v-model:show="showModal"
preset="dialog"
:show-icon="false"
:title="'文件策略 - ' + purposeLabel"
:style="{ width: dialogWidth }"
>
<n-form
ref="formRef"
:model="formValue"
:rules="rules"
label-placement="left"
label-width="100"
>
<n-form-item label="用途" path="purpose">
<n-select
v-model:value="formValue.purpose"
:disabled="true"
:options="purposeOptions"
placeholder="请选择用途"
/>
</n-form-item>
<n-form-item label="大小上限" path="maxSize">
<n-input-number v-model:value="formValue.maxSize" :min="1" />
</n-form-item>
<n-form-item label="保留天数">
<n-input-number v-model:value="formValue.retentionDays" :min="0" />
</n-form-item>
<n-form-item label="自动清理">
<n-switch v-model:value="autoCleanupEnabled" />
</n-form-item>
<n-form-item label="病毒扫描">
<n-switch v-model:value="scanEnabledValue" />
</n-form-item>
<n-form-item label="MIME白名单">
<n-input
v-model:value="formValue.allowedMimes"
type="textarea"
:autosize="{ minRows: 4, maxRows: 8 }"
placeholder="请输入JSON数组,空数组表示不限"
/>
</n-form-item>
<n-form-item label="备注">
<n-input v-model:value="formValue.remark" placeholder="请输入备注" />
</n-form-item>
</n-form>
<template #action>
<n-space>
<n-button @click="showModal = false">取消</n-button>
<n-button type="primary" :loading="submitLoading" @click="handleSubmit">保存</n-button>
</n-space>
</template>
</n-modal>
</div>
</template>
<script lang="ts" setup>
import { computed, h, onMounted, reactive, ref } from 'vue';
import { useMessage } from 'naive-ui';
import { useDictStore } from '@/store/modules/dict';
import { BasicForm, useForm } from '@/components/Form/index';
import { BasicTable, TableAction } from '@/components/Table';
import { usePermission } from '@/hooks/web/usePermission';
import { useUserStore } from '@/store/modules/user';
import { List, Update } from '@/api/imFilePolicy';
import { adaModalWidth, adaTableScrollX } from '@/utils/hotgo';
import {
columns,
loadOptions,
loadTenantOptions,
newState,
rules,
schemas,
State,
tenantOptions,
} from './model';
const dict = useDictStore();
const message = useMessage();
const { hasPermission } = usePermission();
const userStore = useUserStore();
const isPlatformAdmin = computed(() => userStore.isCompanyDept);
const actionRef = ref();
const searchFormRef = ref<any>({});
const formRef = ref();
const showModal = ref(false);
const submitLoading = ref(false);
const formValue = ref<State>(newState(null));
const dialogWidth = computed(() => adaModalWidth(720));
const purposeOptions = computed(() =>
dict
.getOptions('ImFilePurposeOptions')
.filter((item) => item.value !== 'unknown' && item.value !== 'orphan')
);
const purposeLabel = computed(
() => dict.getLabel('ImFilePurposeOptions', formValue.value.purpose) || formValue.value.purpose
);
const tenantSchema = schemas.value.find((item) => item.field === 'tenantId');
if (tenantSchema) {
tenantSchema.ifShow = () => isPlatformAdmin.value;
}
const autoCleanupEnabled = computed({
get: () => formValue.value.autoCleanup === 1,
set: (value: boolean) => {
formValue.value.autoCleanup = value ? 1 : 0;
},
});
const scanEnabledValue = computed({
get: () => formValue.value.scanEnabled === 1,
set: (value: boolean) => {
formValue.value.scanEnabled = value ? 1 : 0;
},
});
const actionColumn = reactive({
width: 100,
title: '操作',
key: 'action',
fixed: 'right',
render(record: State) {
return h(TableAction as any, {
style: 'button',
actions: [
{
label: '编辑',
auth: ['/imFilePolicy/update'],
onClick: () => handleEdit(record),
},
],
});
},
});
const scrollX = computed(() => adaTableScrollX(columns, actionColumn.width));
const [register, { setFieldsValue }] = useForm({
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
labelWidth: 90,
schemas,
});
const loadDataTable = async (res) => {
const params = { ...searchFormRef.value?.formModel, ...res };
if (isPlatformAdmin.value && !params.tenantId)
return { list: [], page: 1, pageCount: 0, totalCount: 0 };
return await List(params);
};
function reloadTable() {
actionRef.value?.reload();
}
async function handleReset() {
const defaults: Recordable = {};
if (isPlatformAdmin.value && tenantOptions.value.length > 0)
defaults.tenantId = tenantOptions.value[0].value;
await setFieldsValue(defaults);
reloadTable();
}
function handleEdit(record: State) {
formValue.value = newState(record);
if (!formValue.value.allowedMimes) formValue.value.allowedMimes = '[]';
showModal.value = true;
}
async function handleSubmit() {
submitLoading.value = true;
try {
await formRef.value?.validate();
let allowedMimes: any[] = [];
const text = (formValue.value.allowedMimes || '').trim();
if (text) {
allowedMimes = JSON.parse(text);
if (!Array.isArray(allowedMimes)) throw new Error('MIME白名单必须是JSON数组');
}
await Update({ ...formValue.value, allowedMimes });
message.success('操作成功');
showModal.value = false;
reloadTable();
} catch (e: any) {
message.error(e.message || '操作失败');
} finally {
submitLoading.value = false;
}
}
onMounted(async () => {
loadOptions();
if (isPlatformAdmin.value) {
await loadTenantOptions();
if (tenantOptions.value.length > 0) {
await setFieldsValue({ tenantId: tenantOptions.value[0].value });
} else {
message.warning('暂无可用租户');
}
}
reloadTable();
});
</script>
+136
View File
@@ -0,0 +1,136 @@
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: computed(() => dict.getOptions('ImFilePurposeOptions')),
placeholder: '请选择用途',
},
},
{
field: 'autoCleanup',
component: 'NSelect',
label: '自动清理',
componentProps: {
clearable: true,
options: computed(() => dict.getOptions('ImFilePolicySwitchOptions')),
placeholder: '请选择开关',
},
},
{
field: 'scanEnabled',
component: 'NSelect',
label: '病毒扫描',
componentProps: {
clearable: true,
options: computed(() => dict.getOptions('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;
}
+38
View File
@@ -21,6 +21,13 @@
>
新增部门
</n-button>
<n-button
v-if="hasPermission(['/imOrg/departmentExport'])"
type="primary"
@click="handleDepartmentExport"
>
导出部门
</n-button>
</n-space>
<BasicTable
ref="departmentTableRef"
@@ -50,6 +57,14 @@
>
添加成员
</n-button>
<n-button
v-if="hasPermission(['/imOrg/memberExport'])"
type="primary"
:disabled="!selectedDepartment.departmentId"
@click="handleMemberExport"
>
导出成员
</n-button>
</n-space>
<BasicTable
ref="memberTableRef"
@@ -190,9 +205,11 @@
import {
DepartmentDelete,
DepartmentEdit,
DepartmentExport,
DepartmentList,
MemberDelete,
MemberEdit,
MemberExport,
MemberList,
} from '@/api/imOrg';
import {
@@ -364,6 +381,27 @@
memberTableRef.value?.reload();
}
function handleDepartmentExport() {
const params = { ...departmentSearchRef.value?.formModel };
if (isPlatformAdmin.value && !params.tenantId) {
message.warning('请先选择租户');
return;
}
DepartmentExport(params);
}
function handleMemberExport() {
if (!selectedDepartment.value.departmentId) {
message.warning('请先选择部门');
return;
}
MemberExport({
...memberSearchRef.value?.formModel,
tenantId: currentTenantId.value,
departmentId: selectedDepartment.value.departmentId,
});
}
async function handleDepartmentReset() {
const defaults: Recordable = {};
if (isPlatformAdmin.value && tenantOptions.value.length > 0)