From b4ae9c8745d61cc3266bfa1c645c298cee79e211 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sat, 19 Aug 2023 17:32:41 +0800 Subject: [PATCH] update --- .../wwwroot/components/form/form-input.js | 1 - .../wwwroot/components/list/index.js | 132 ++++++++++-------- .../wwwroot/models/base-data/role.js | 1 + .../wwwroot/models/base-data/user.js | 6 +- .../{centralized-control.js => version.js} | 0 .../wwwroot/models/input/fa-yun.js | 4 +- .../wwwroot/request/index.js | 46 +++--- .../wwwroot/router/base-data.js | 2 +- .../wwwroot/views/base-data/user.js | 6 +- .../{centralized-control.js => version.js} | 3 +- 10 files changed, 110 insertions(+), 91 deletions(-) rename code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/{centralized-control.js => version.js} (100%) rename code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/{centralized-control.js => version.js} (91%) diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/form/form-input.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/form/form-input.js index 31f75c58..a3d0a522 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/form/form-input.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/form/form-input.js @@ -29,7 +29,6 @@ export default { -
- + @@ -399,6 +399,39 @@ export default { const defaultImportModel = schemaToModel(config.import.schema); const importModel = ref(null); const versions = ref([]); + const onClick = async (method, confirMmessage = "确认操作吗?", reload = true) => { + try { + if (confirMmessage) { + await ElMessageBox.confirm(confirMmessage, "提示", { + type: "warning", + }); + } + tableLoading.value = true; + let result = null; + if (method.constructor.name == "AsyncFunction") { + result = await method(); + } else { + result = method(); + } + if (!result.errors) { + if (!result.data?.code || result.data.code === 200) { + if (reload) { + pageModel.pageIndex = 1; + await load(); + } + } + } + } catch (error) { + if (error === "cancel") { + ElMessage({ + type: "info", + message: "操作取消", + }); + } + } finally { + tableLoading.value = false; + } + }; const getSortModel = (model) => { (model.sorting ?? "") .split(",") @@ -469,11 +502,14 @@ export default { tableLoading.value = false; } }; - const onPageIndexChange = async () => await load(); - const onPageSizeChange = async () => { + const reload = async () => { pageModel.pageIndex = 1; await load(); }; + const onPageIndexChange = async () => await load(); + const onPageSizeChange = async () => { + await reload(); + }; const click = async (item, rows) => { editFormloading.value = true; editFormMode.value = item.path ?? item; @@ -504,11 +540,16 @@ export default { type: "warning", }); tableLoading.value = true; - const response = await request( + const result = await request( url, rows.map((o) => o.id), - { method: config.edit.deleteMethod } + { method: config.edit.deleteMethod }, + true ); + if (!result.data?.code || result.data.code === 200) { + pageModel.pageIndex = 1; + await reload(); + } } catch (error) { if (error === "cancel") { ElMessage({ @@ -525,7 +566,8 @@ export default { await ElMessageBox.confirm(format("确认删除当前行数据吗?", rows[0]), "提示", { type: "warning", }); - await request(url, null, { method: config.edit.deleteMethod }); + await request(url, null, { method: config.edit.deleteMethod }, true); + await reload(); } catch (error) { if (error === "cancel") { ElMessage({ @@ -541,10 +583,12 @@ export default { const url = config.edit.exportUrl; const method = config.edit.exportMethod; const postData = buildQuery(); - const response = await request(url, postData, { method }); - if (!response.errors) { - window.open(getUrl(`settleaccount/getblobfile/download/${response.data}`)); - } + await onClick(async () => { + const response = await request(url, postData, { method }); + if (!response.errors) { + window.open(getUrl(`settleaccount/getblobfile/download/${response.data}`)); + } + }, "确认导出?"); } else if (item.meta.pattern === "file") { window.open(getUrl(`settleaccount/getblobfile/download/${rows[0]["downFileName"]}`)); } else if ((item.meta.pattern = "row")) { @@ -585,21 +629,23 @@ export default { try { const valid = await editFormRef.value.validate(); if (valid) { - editFormloading.value = true; - let url = (editFormMode.value === "create" ? config.edit.createUrl : config.edit.updateUrl) ?? config.query.url; - if (editFormMode.value === "update") { - url = format(url, editFormModel.value.id); - } - const method = editFormMode.value === "create" ? config.edit.createMethod : config.edit.updateMethod; - const response = await request(url, editFormModel.value, { method }); - if (response.errors) { - ElMessageBox.alert(`错误:${response.errors?.error?.message}`, `代码:${response.errors?.error?.code}`); - //model.errors = response.errors; //?? - } else { - await load(); - editFormMode.value = null; - dialogVisible.value = false; - } + await onClick( + async () => { + let url = (editFormMode.value === "create" ? config.edit.createUrl : config.edit.updateUrl) ?? config.query.url; + if (editFormMode.value === "update") { + url = format(url, editFormModel.value.id); + } + const method = editFormMode.value === "create" ? config.edit.createMethod : config.edit.updateMethod; + const result = await request(url, editFormModel.value, { method }, true); + if (!result.errors) { + dialogVisible.value = false; + editFormMode.value = null; + await reload(); + } + }, + null, + true + ); } } catch (error) { console.log(error); @@ -783,37 +829,6 @@ export default { } return postData; } - const action = async (method, confirMmessage = "确认操作吗?", successMessage = "操作成功", reload = true) => { - try { - await ElMessageBox.confirm(confirMmessage, "提示", { - type: "warning", - }); - tableLoading.value = true; - let result = null; - if (method.constructor.name == "AsyncFunction") { - result = await method(); - } else { - result = method(); - } - if (!result.errors) { - if (!result.data?.code || result.data.code === 200) { - if (reload) { - pageModel.pageIndex = 1; - await load(); - } - } - } - } catch (error) { - if (error === "cancel") { - ElMessage({ - type: "info", - message: "操作取消", - }); - } - } finally { - tableLoading.value = false; - } - }; onMounted(async () => { if (route.meta.children?.length) { for (const item of route.meta.children) { @@ -836,7 +851,8 @@ export default { return { listScrollbarRef, load, - action, + reload, + onClick, config, queryModel, buildQuery, diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/role.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/role.js index c9e249f0..f87db634 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/role.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/role.js @@ -1,6 +1,7 @@ const schema = { title: "角色", type: "object", + disableSelection: true, properties: { name: { title: "角色名", diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/user.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/user.js index 812c413d..1dcc9e16 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/user.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/user.js @@ -1,6 +1,7 @@ const schema = { title: "用户", type: "object", + disableSelection: true, properties: { userName: { title: "用户名", @@ -59,10 +60,7 @@ const schema = { title: "邮箱", type: "string", showForList: true, - rules: [ - { required: true }, - { pattern: "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z]{2,4})+$", message: "%s必须是正确的格式" }, - ], + rules: [{ required: true }, { pattern: "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z]{2,4})+$", message: "%s必须是正确的格式" }], }, roleNames: { title: "角色", diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/centralized-control.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/version.js similarity index 100% rename from code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/centralized-control.js rename to code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/base-data/version.js diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/input/fa-yun.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/input/fa-yun.js index a7cea341..be0f29f1 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/input/fa-yun.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/input/fa-yun.js @@ -313,10 +313,10 @@ export default function (businessType) { let schema = null; let service = null; const syncService = "hand-se-sync/sync"; - if (businessType === "JisBBAC") { + if (businessType === "JisBBAC" || businessType === "MaiDanJianBBAC") { schema = schema1; service = "bbac_se_detail_service"; - } else if (businessType === "JisHBPO") { + } else if (businessType === "JisHBPO" || businessType === "MaiDanJianHBPO") { schema = schema1; service = "hbpo_se_detail_service"; } else { diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/request/index.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/request/index.js index 2e134bc4..5d577589 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/request/index.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/request/index.js @@ -9,23 +9,23 @@ import { ElMessage, ElMessageBox } from "element-plus"; // baseURL: "/api", // }; -const addToken = async (options) => { +async function addToken(options) { if (await isLogin()) { const appStore = useAppStore(); options.headers ??= {}; options.headers.Authorization = `Bearer ${appStore.token}`; } -}; +} -const getUrl = (url) => { +function getUrl(url) { if (url.startsWith("http")) { return url; } let result = settings.baseURL; return (result += `/${url}`); -}; +} -const getResult = async (response) => { +async function getResult(response) { const messages = new Map([ [200, "操作成功"], [201, "已创建"], @@ -59,9 +59,9 @@ const getResult = async (response) => { ElMessageBox.alert(`${result.errors?.error?.message ?? messages.get(response.status) ?? result.status}`, `${result.errors?.error?.code ?? "错误"}`); } return result; -}; +} -async function request(url, data, options, withoutToken = false) { +async function request(url, data, options, notify = false) { url = getUrl(url); let defaultOptions = { method: "POST", @@ -87,18 +87,28 @@ async function request(url, data, options, withoutToken = false) { defaultOptions.body = JSON.stringify(data); } } - if (!withoutToken) { - await addToken(defaultOptions); - } + await addToken(defaultOptions); const response = await fetch(url, defaultOptions); - // if (!result.data?.code || result.data.code === 200) { - // ElMessage({ - // type: "success", - // message: "操作成功", - // }); - // } - return getResult(response); + const result = await getResult(response); + if (!result.errors && notify && (!result.data?.code || result.data.code === 200)) { + ElMessage({ + type: "success", + message: "操作成功", + }); + } + if (result.data?.code && result.data.code !== 200) { + result.errors = result.data.message; + } + return result; +} + +async function get(url, data, notify = false) { + return await request(url, data, { method: "GET" }, notify); +} + +async function post(url, data, notify = false) { + return await request(url, data, { method: "POST" }, notify); } export default request; -export { getUrl }; +export { getUrl, get, post }; diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js index bf68968d..66603861 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js @@ -23,7 +23,7 @@ export default [ children: [createButton("query", "title=查询&isTop=true"), createButton("export", "title=导出&isTop=true&pattern=paged")], }, { - ...createPage("centralized-control", "title=期间设置"), + ...createPage("version", "title=期间设置"), children: [ createButton("query", "title=查询&isTop=true"), createButton("create", "title=新建&isTop=true"), diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/user.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/user.js index 58525a07..48b9a3c9 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/user.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/user.js @@ -13,11 +13,7 @@ export default { const onCommand = async (item, rows) => { if (item.path === "reset-password") { const url = `base/user/${rows[0].id}/${item.path}`; - await appListRef.value.action( - async () => await request(url, null, { method: item.meta.method }), - `是否重置用户${rows[0].userName}密码?`, - `${rows[0].userName}密码已经重置为123456` - ); + await appListRef.value.onClick(async () => await request(url, null, { method: item.meta.method }, true), `是否重置用户${rows[0].userName}密码?`, false); } }; return { appListRef, config, onCommand }; diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/centralized-control.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/version.js similarity index 91% rename from code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/centralized-control.js rename to code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/version.js index 9b3b4f4d..01217efd 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/centralized-control.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/views/base-data/version.js @@ -2,9 +2,8 @@ import html from "html"; import { ref } from "vue"; import request from "../../request/index.js"; import AppList from "../../components/list/index.js"; -import useConfig from "../../models/base-data/centralized-control.js"; +import useConfig from "../../models/base-data/version.js"; import { ElMessage, ElMessageBox } from "element-plus"; -import { format } from "../../utils/index.js"; export default { components: { AppList },