diff --git a/src/api/tenant/index.ts b/src/api/tenant/index.ts index 07ef128..35c4285 100644 --- a/src/api/tenant/index.ts +++ b/src/api/tenant/index.ts @@ -7,7 +7,7 @@ import request from '/@/utils/request'; type TenantListDTO = { accountType: number; // 账号类型 companyType: number; // 企业类型 - status: number; // 状态 + status: number; // 状态 0: 启用 1: 禁用 accountName: string; // 账号名称 page: number; // 页码 size: number; // 页数 @@ -72,15 +72,16 @@ export const exportTenant = (params: Partial) => { url: '/tenant/export', method: 'get', params, + responseType: 'blob', }); }; // 获取子账号列表参数 type TenantUserListDTO = { - phone: string; // 手机号 + mobile: string; // 手机号 companyName: string; // 企业名称 accountType: number; // 账号类型 - active: number; // 状态 + status: number; // 状态 0: 启用 1: 禁用 page: number; // 页码 size: number; // 页数 orderBy: string; // 排序字段 @@ -135,12 +136,13 @@ export const exportTenantUser = (params: Partial) => { url: '/tenant/user/export', method: 'get', params, + responseType: 'blob', }); }; // 租户子账号禁用 export const disableTenantUser = (data: { id: number }) => { return request({ - url: '/tenant/disable', + url: '/tenant/user/disable', method: 'post', data, }); diff --git a/src/views/pages/tenant/add.vue b/src/views/pages/tenant/add.vue index d2fe092..37bc3e8 100644 --- a/src/views/pages/tenant/add.vue +++ b/src/views/pages/tenant/add.vue @@ -23,9 +23,9 @@ - - - + + + @@ -57,7 +57,7 @@ import { onMounted, reactive, ref } from 'vue'; import { NextLoading } from '/@/utils/loading'; import { ElMessage, ElMessageBox, FormInstance } from 'element-plus'; import { createTenant, updateTenant } from '/@/api/tenant'; -import { COMPANYTYPE_CONST, ACCOUNTTYPE_CONST } from './constant'; +import { COMPANYTYPE_CONST, ACCOUNTTYPE_CONST, PERMISSIONS } from './constant'; const emit = defineEmits(['close']); const formRef = ref(); @@ -70,36 +70,9 @@ const formData = reactive({ accountLimit: 0, accountType: '', daterange: [], - menu: ['1','2','3','4','5','6'], + permissions: [...PERMISSIONS.map(() => 1)], }); -const menu = ref([ - { - label: '海外独家', - value: '1', - }, - { - label: '编辑精选', - value: '2', - }, - { - label: '宏观知微', - value: '3', - }, - { - label: '智能资讯榜', - value: '4', - }, - { - label: '热门行业', - value: '5', - }, - { - label: '风口概念', - value: '6', - }, -]); - const validatePhone = (rule: any, value: any, callback: any) => { const phoneRegex = /^1[3456789]\d{9}$/; if (!value) { @@ -125,7 +98,7 @@ const dialogTableVisible = ref(false); function open(data) { dialogTableVisible.value = true; if (data) { - Object.assign(formData, data); + Object.assign(formData, { ...data, daterange: [data.validStart, data.validEnd], permissions: data.permissions.map((item) => item.enabled) }); } } function close() { @@ -143,6 +116,10 @@ function close() { async function submit() { console.log('output >>>>> formData', formData); await formRef.value?.validate(); + const permissions = formData.permissions.map((item, index) => ({ + name: PERMISSIONS[index].label, + enabled: item, + })); const params = { id: formData?.id || undefined, companyType: formData.companyType, @@ -153,8 +130,9 @@ async function submit() { validStart: formData.daterange[0], validEnd: formData.daterange[1], accountLimit: formData.accountLimit, + permissions: permissions, }; - console.log('output >>>>> params',params); + console.log('output >>>>> params', params); if (formData.id) { updateTenant(params).then((res) => { if (res.code === 200) { @@ -176,6 +154,9 @@ async function submit() { }); } } +const onSwitchChange = ({ key, value, model }) => { + console.log(`开关 ${key} 变为 ${value},当前状态:`, model); +}; // 页面加载时 onMounted(() => { diff --git a/src/views/pages/tenant/constant.ts b/src/views/pages/tenant/constant.ts index 124370b..d1dedbf 100644 --- a/src/views/pages/tenant/constant.ts +++ b/src/views/pages/tenant/constant.ts @@ -47,3 +47,30 @@ export const STATUS_CONST: Record = { value: 1, }, }; + +export const PERMISSIONS = [ + { + label: '海外独家', + value: 1, // 0:不可见;1:可见 + }, + { + label: '编辑精选', + value: 1, + }, + { + label: '宏观知微', + value: 1, + }, + { + label: '智能资讯榜', + value: 1, + }, + { + label: '热门行业', + value: 1, + }, + { + label: '风口概念', + value: 1, + }, +]; diff --git a/src/views/pages/tenant/index.vue b/src/views/pages/tenant/index.vue index b54d4af..c1b3d6a 100644 --- a/src/views/pages/tenant/index.vue +++ b/src/views/pages/tenant/index.vue @@ -185,16 +185,28 @@ function exportExcel() { ElMessageBox.confirm('确定导出吗?', '提示', { type: 'warning', }).then(async () => { - // 导出 - let { code, data } = await exportTenant({ - page: tableData.page, - size: tableData.size, - ...formData, - }); - console.log('output >>>>> data', data); + try { + // 导出 + const response = await exportTenant({ + page: tableData.page, + size: tableData.size, + ...formData, + }); - if (code == 200) { - ElMessage.success('导出成功'); + const filename = '租户导出.xlsx'; // 默认文件名 + // 创建 Blob URL + const blob = new Blob([response]); // response 已经是 Blob 对象 + const downloadUrl = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = downloadUrl; + link.download = filename; // 设置下载文件名 + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + // 释放 Blob URL + window.URL.revokeObjectURL(downloadUrl); + } catch (error) { + ElMessage.error('导出失败'); } }); } diff --git a/src/views/pages/tenantUser/add.vue b/src/views/pages/tenantUser/add.vue index 9c72578..ef93aeb 100644 --- a/src/views/pages/tenantUser/add.vue +++ b/src/views/pages/tenantUser/add.vue @@ -93,7 +93,7 @@ async function submit() { id: form?.id || undefined, name: form.name, mobile: form.mobile, - companyName: form.companyName?.companyName, + companyName: form.companyName?.id, department: form.department, accountType: form.accountType, }; diff --git a/src/views/pages/tenantUser/index.vue b/src/views/pages/tenantUser/index.vue index b7729ee..830f933 100644 --- a/src/views/pages/tenantUser/index.vue +++ b/src/views/pages/tenantUser/index.vue @@ -9,7 +9,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -36,7 +36,7 @@ - +