Customize user account exports
This commit is contained in:
1 parent
1f48660d49
commit
bce04b768c
2 files changed
+25
-3
No files matched your search
@@ -42,6 +42,11 @@ public sealed class UsersExcelController(
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType, DownloadFileName.Template("用户与权限", ".xlsx"));
|
||||
}
|
||||
|
||||
private static readonly string[] ExportHeaders = ["登录账号", "姓名", "工号/学号", "学院编码", "角色", "状态"];
|
||||
|
||||
[HttpGet("export-columns")]
|
||||
public IActionResult ExportColumns() => Ok(ExportHeaders);
|
||||
|
||||
[HttpGet("export")]
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<IActionResult> Export(
|
||||
@@ -50,7 +55,8 @@ public sealed class UsersExcelController(
|
||||
Guid? collegeId = null,
|
||||
bool? isEnabled = null,
|
||||
bool? hasLoggedIn = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
CancellationToken cancellationToken = default,
|
||||
string? columns = null, string? format = null)
|
||||
{
|
||||
var colleges = await db.Colleges.AsNoTracking()
|
||||
.ToDictionaryAsync(x => x.Id, x => x.Code, cancellationToken);
|
||||
@@ -87,6 +93,11 @@ public sealed class UsersExcelController(
|
||||
string.Join("、", roles),
|
||||
user.IsEnabled ? "启用" : "停用"));
|
||||
}
|
||||
if (columns is not null || format is not null)
|
||||
{
|
||||
var exportRows = rows.Select(row => (IReadOnlyList<object?>)[row[0], row[1], row[3], row[4], row[5], row[6]]).ToList();
|
||||
return TabularExport.Create(this, "用户与权限", ExportHeaders, exportRows, columns, format);
|
||||
}
|
||||
var bytes = ExcelWorkbookHelper.Create("用户与权限", Headers, rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export("用户与权限", ".xlsx"));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import CustomExportDialog from "../components/CustomExportDialog.vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { getDisplayLocale } from "../i18n";
|
||||
const { t, te } = useI18n();
|
||||
@@ -202,7 +203,14 @@ async function downloadTemplate() {
|
||||
}
|
||||
}
|
||||
|
||||
async function exportRows() {
|
||||
const exportDialog = ref<InstanceType<typeof CustomExportDialog>>();
|
||||
async function openExportDialog() {
|
||||
try {
|
||||
const { data } = await http.get<string[]>("/users/export-columns");
|
||||
exportDialog.value?.open(data, t("usersBatch.usersAndPermissionsXlsx"));
|
||||
} catch (error) { ElMessage.error(apiErrorMessage(error)); }
|
||||
}
|
||||
async function exportRows(columns: number[], filename: string, format: string) {
|
||||
try {
|
||||
await downloadApiFile(
|
||||
"/users/export",
|
||||
@@ -214,8 +222,10 @@ async function exportRows() {
|
||||
collegeId: collegeFilter.value,
|
||||
isEnabled: enabledFilter.value,
|
||||
hasLoggedIn: loginFilter.value,
|
||||
columns: columns.join(","), format,
|
||||
},
|
||||
},
|
||||
filename,
|
||||
);
|
||||
ElMessage.success(t("usersBatch.usersAndPermissionsExported"));
|
||||
} catch (error) {
|
||||
@@ -646,7 +656,7 @@ onMounted(load);
|
||||
@click="chooseImportFile"
|
||||
>{{ t("courses.excelImport") }}</el-button
|
||||
>
|
||||
<el-button :icon="Download" @click="exportRows">{{
|
||||
<el-button :icon="Download" @click="openExportDialog">{{
|
||||
t("businessLabels.exportAll")
|
||||
}}</el-button>
|
||||
<input
|
||||
@@ -1044,6 +1054,7 @@ onMounted(load);
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
<CustomExportDialog ref="exportDialog" @export="exportRows" />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in new issue
Block a user