Browse Source

Merge remote-tracking branch 'origin/master'

master
修宁 6 months ago
parent
commit
06a774497d
  1. 90
      src/components/ErrorDialog.vue
  2. 16
      src/config.ts
  3. 127
      src/views/user/roles.vue
  4. 4
      src/views/user/users.vue

90
src/components/ErrorDialog.vue

@ -0,0 +1,90 @@
<script setup lang="ts">
import { reactive } from "vue";
import { ElIcon, ElSwitch } from "element-plus";
import { CircleCloseFilled } from "@element-plus/icons-vue";
defineOptions({
name: 'ErrorDialog',
});
// Props
interface ErrorDialogProps {
err: AxiosInterceptorError;
}
// props
const props = withDefaults(defineProps<ErrorDialogProps>(), {});
// State
interface ErrorDialogState {
show: boolean;
}
// state
const state = reactive<ErrorDialogState>({
show: false,
});
// Data
interface ErrorDialogData {
}
//
const data: ErrorDialogData = {};
interface ErrorDialogExpose {
state: ErrorDialogState;
data: ErrorDialogData;
}
const expose: ErrorDialogExpose = {
state,
data,
};
//
defineExpose(expose);
export type {
ErrorDialogProps,
ErrorDialogState,
}
</script>
<template>
<div class="error-dialog flex-column-container">
<div class="flex-row-container">
<ElIcon :size="20" style="color: #ff4d4f;">
<CircleCloseFilled/>
</ElIcon>
<div class="flex-item-fill">
{{ props.err?.message }}
</div>
<div v-if="props.err?.data?.error">
<ElSwitch size="small" v-model="state.show"/>
查看详情
</div>
</div>
<div v-if="props.err?.data?.error && state.show" class="show-details flex-item-fill">
<pre class="show-details-pre">{{ props.err?.data?.error }}</pre>
</div>
</div>
</template>
<style scoped>
.show-details-pre {
width: 790px;
height: 470px;
overflow: auto;
padding: 0;
}
</style>
<style>
.el-dialog:has(> .el-dialog__body > .error-dialog) {
min-height: 160px;
}
.el-dialog:has(> .el-dialog__body > .error-dialog > .show-details) {
height: 600px !important;
}
</style>

16
src/config.ts

@ -2,6 +2,8 @@ import type { InternalAxiosRequestConfig } from "axios";
import { Constant, initGlobalConfig } from "@ease-forge/shared"; import { Constant, initGlobalConfig } from "@ease-forge/shared";
import { initGlobalConfigWithRuntime } from "@ease-forge/runtime"; import { initGlobalConfigWithRuntime } from "@ease-forge/runtime";
import router from "@/router"; import router from "@/router";
import { createVNode } from "vue";
import ErrorDialog from "@/components/ErrorDialog.vue";
function globalConfig() { function globalConfig() {
window.globalConfig.customAxios = axiosInstance => { window.globalConfig.customAxios = axiosInstance => {
@ -30,6 +32,7 @@ function globalConfig() {
status: response?.status ?? -1, status: response?.status ?? -1,
title: "系统错误", title: "系统错误",
message: "", message: "",
data: response?.data,
}; };
if (!error || !response) { if (!error || !response) {
err.message = "请求服务端异常"; err.message = "请求服务端异常";
@ -46,7 +49,18 @@ function globalConfig() {
err.message = message ?? Constant.defHttpErrorMsg[response.status] ?? "服务器异常"; err.message = message ?? Constant.defHttpErrorMsg[response.status] ?? "服务器异常";
} }
} }
system.msg(err.message); system.showDialog(createVNode(ErrorDialog, {
err,
}), {
title: '业务异常',
width: 800,
height: 120,
showClose: true,
showMax: false,
showCancelButton: false,
showOkButton: true,
okButtonText: "关闭",
}).finally();
return Promise.reject(err); return Promise.reject(err);
}, },
); );

127
src/views/user/roles.vue

@ -1,13 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive } from "vue"; import { createVNode, reactive } from "vue";
import { ElButton } from "element-plus"; import { ElButton } from "element-plus";
import { Delete, Plus, Search } from "@element-plus/icons-vue"; import { Delete, EditPen, Plus, Search } from "@element-plus/icons-vue";
import DataForm from "@/components/data-form/DataForm.vue"; import DataForm from "@/components/data-form/DataForm.vue";
import type { FormField } from "@/components/data-form/DataFormTypes.ts"; import type { FormField } from "@/components/data-form/DataFormTypes.ts";
import { AgGridVue } from "ag-grid-vue3"; import { AgGridVue } from "ag-grid-vue3";
import type { GridOptions } from "ag-grid-enterprise"; import type { GridOptions, IServerSideGetRowsParams } from "ag-grid-enterprise";
import type { GridApi, GridReadyEvent } from "ag-grid-community"; import type { GridApi, GridReadyEvent } from "ag-grid-community";
import { localeText as localeTextCn } from "@/components/yvTable/yv-aggrid-cn.locale"; import { localeText as localeTextCn } from "@/components/yvTable/yv-aggrid-cn.locale";
import { Request } from "@ease-forge/shared";
// Props // Props
interface ComponentProps { interface ComponentProps {
@ -18,12 +19,14 @@ const props = withDefaults(defineProps<ComponentProps>(), {});
// State // State
interface ComponentState { interface ComponentState {
loading: boolean;
queryData: any; queryData: any;
grid1Data: Array<any>; grid1Data: Array<any>;
} }
// state // state
const state = reactive<ComponentState>({ const state = reactive<ComponentState>({
loading: false,
queryData: {}, queryData: {},
grid1Data: [], grid1Data: [],
}); });
@ -63,6 +66,7 @@ const data: ComponentData = {
// suppressLoadingOverlay: true, // suppressLoadingOverlay: true,
// //
rowSelection: "single", rowSelection: "single",
rowModelType: "serverSide",
columnDefs: [ columnDefs: [
{ field: 'id', headerName: 'id', editable: false, hide: true }, { field: 'id', headerName: 'id', editable: false, hide: true },
{ field: 'roleCode', headerName: '角色编号', editable: false }, { field: 'roleCode', headerName: '角色编号', editable: false },
@ -77,19 +81,128 @@ const data: ComponentData = {
paginationPageSize: 50, paginationPageSize: 50,
// suppressPaginationPanel // suppressPaginationPanel
onGridReady(event: GridReadyEvent) { onGridReady(event: GridReadyEvent) {
data.api = event.api data.api = event.api;
data.api.setServerSideDatasource({ getRows: serverSideDatasource });
}, },
}, },
}; };
function reload() {
data.api.paginationGoToPage(0);
data.api.setServerSideDatasource({ getRows: serverSideDatasource });
}
function serverSideDatasource(params: IServerSideGetRowsParams) {
const { startRow, endRow } = params.request;
console.log("startRow, endRow ", params.request);
const pageSize = endRow - startRow;
const pageNo = Math.floor(startRow / pageSize) + 1;
state.loading = true;
Request.request.get<PageData>(
"/api/workbench/UserPermissions@queryRole",
{
params: {
...state.queryData,
pageSize,
pageNo,
},
},
).then(page => {
params.success({ rowData: page.records, rowCount: page.total })
}).finally(() => state.loading = false);
}
function addOrUpdate(add: boolean = true) {
let row = {};
let ref;
if (!add) {
const select = data.api?.getSelectedRows()?.[0];
if (!select) {
system.msg("未选择数据行");
return;
}
row = select;
}
system.showDialog(createVNode(DataForm, {
refCallback: v => ref = v,
data: row,
formFields: [
{
dataPath: 'roleCode', label: '角色编号', input: 'Input',
inputProps: {
placeholder: '角色编号',
disabled: !add,
}
},
{
dataPath: 'roleName', label: '角色名称', input: 'Input',
inputProps: {
placeholder: '角色名称'
}
},
{
dataPath: 'isEnable', label: '启用', input: 'Switch',
inputProps: {
inactiveValue: 0,
activeValue: 1,
inlinePrompt: true,
inactiveText: "禁用",
activeText: "启用",
},
},
],
rules: {
roleCode: [
{ required: true, message: "角色编号必填", trigger: "blur" },
],
roleName: [
{ required: true, message: "角色名称必填", trigger: "blur" },
],
},
showMessage: true,
columnCount: 1,
labelWidth: '90px'
}), {
title: `${add ? "新增" : "编辑"}用户`,
width: 480,
height: 300,
showClose: true,
showMax: false,
showCancelButton: true,
showOkButton: true,
okButtonText: '确定',
cancelButtonText: '取消',
manualClose: async (close) => {
await ref.data.formRef.validate();
Request.request.post(`/api/workbench/UserPermissions@${add ? "addRole" : "updateRole"}`, row).then(() => {
close();
reload();
});
},
}).then().finally()
}
function delRole() {
const select = data.api?.getSelectedRows()?.[0];
if (!select) {
system.msg("未选择数据行");
return;
}
system.confirm(`是否删除用户: ${select.loginName}?`).then(() => {
Request.request.post(`/api/workbench/UserPermissions@delRole?id=${select.id}`).then(() => {
reload();
});
});
}
</script> </script>
<template> <template>
<div class="dashboard flex-column-container"> <div class="dashboard flex-column-container">
<div class="tools flex-item-fixed"> <div class="tools flex-item-fixed">
<ElButton :icon="Search">查询</ElButton> <ElButton :icon="Search" :loading="state.loading" @click="reload">查询</ElButton>
<ElButton :icon="Plus">新增</ElButton> <ElButton :icon="Plus" @click="addOrUpdate(true)">新增</ElButton>
<ElButton :icon="Delete" type="danger" :plain="true">删除</ElButton> <ElButton :icon="EditPen" @click="addOrUpdate(false)">编辑</ElButton>
<ElButton :icon="Delete" type="danger" :plain="true" @click="delRole">删除</ElButton>
</div> </div>
<DataForm <DataForm
class="query-form flex-item-fixed" class="query-form flex-item-fixed"

4
src/views/user/users.vue

@ -80,10 +80,10 @@ const data: ComponentData = {
], ],
pagination: true, pagination: true,
paginationPageSize: 50, paginationPageSize: 50,
cacheBlockSize: 50, // cacheBlockSize: 50,
// suppressPaginationPanel // suppressPaginationPanel
onGridReady(event: GridReadyEvent) { onGridReady(event: GridReadyEvent) {
data.api = event.api data.api = event.api;
data.api.setServerSideDatasource({ getRows: serverSideDatasource }); data.api.setServerSideDatasource({ getRows: serverSideDatasource });
}, },
}, },

Loading…
Cancel
Save