feat: 公账周期账单与合并明细优化,退款弹窗与开方成功页按钮换行
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
周期账单生成与变动记录抽屉;查看合并按账单日 Tabs;退款原因必填;开方成功页操作按钮自动换行。
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
resetPassword,
|
||||
updateAdmin,
|
||||
} from '#/views/system/admin/api';
|
||||
import { getRoleInfo } from '#/views/system/role/api';
|
||||
|
||||
import { normalizeAdminPayload } from './admin-payload';
|
||||
import { createAdminModalFormProps } from './form-schemas';
|
||||
@@ -49,6 +50,20 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const meta = computed(() => getRoleMeta(props.roleId));
|
||||
/** 优先展示接口返回的角色昵称(自定义角色尤为重要) */
|
||||
const roleTitle = ref('');
|
||||
const pageTitle = computed(() => roleTitle.value || meta.value.title);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const info = await getRoleInfo(props.roleId);
|
||||
if (info?.name) {
|
||||
roleTitle.value = String(info.name);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
const isUpdate = ref(false);
|
||||
@@ -217,9 +232,9 @@ const copyToClipboard = async (text: string) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height :title="meta.title">
|
||||
<Page auto-content-height :title="pageTitle">
|
||||
<Modal
|
||||
:title="`${isUpdate ? '编辑' : '新增'}${meta.title}`"
|
||||
:title="`${isUpdate ? '编辑' : '新增'}${pageTitle}`"
|
||||
class="w-[60%]"
|
||||
>
|
||||
<Form />
|
||||
|
||||
@@ -38,8 +38,14 @@ export const ROLE_SALESPERSON = 6;
|
||||
|
||||
export function getRoleMeta(roleId: number): AdminRoleMeta {
|
||||
const meta = ADMIN_ROLE_LIST.find((r) => r.id === roleId);
|
||||
if (!meta) {
|
||||
throw new Error(`Unknown admin role id: ${roleId}`);
|
||||
if (meta) {
|
||||
return meta;
|
||||
}
|
||||
return meta;
|
||||
// 自定义角色:无静态页元数据时回落为通用 basic 表单,避免抛错
|
||||
return {
|
||||
id: roleId,
|
||||
title: `角色${roleId}`,
|
||||
slug: `role-${roleId}`,
|
||||
formType: 'basic',
|
||||
};
|
||||
}
|
||||
|
||||
25
apps/web-antd/src/views/system/admin/dynamic/index.vue
Normal file
25
apps/web-antd/src/views/system/admin/dynamic/index.vue
Normal file
@@ -0,0 +1,25 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 自定义角色通用管理员页:从路由 path 解析 roleId,复用 AdminPage
|
||||
* 菜单 path 约定:/system/admin/role/{roleId}
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
/** 从 path 提取角色 ID,解析失败返回 0 */
|
||||
const roleId = computed(() => {
|
||||
const match = String(route.path).match(/\/system\/admin\/role\/(\d+)/);
|
||||
return match ? Number(match[1]) : 0;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AdminPage v-if="roleId > 0" :role-id="roleId" />
|
||||
<div v-else class="p-6 text-[hsl(var(--muted-foreground))]">
|
||||
无法识别角色 ID,请检查菜单路径是否为 /system/admin/role/{角色ID}
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* 某药品的配送仓绑定列表弹窗(卡片展示)
|
||||
* 展示报价/推广费/平台费/库存;新增/编辑打开仓药绑定表单(药品预填)
|
||||
* 打开时尽量补齐总仓售价,供费用封顶与平台费默认 5%
|
||||
* 打开时尽量补齐总仓售价与平台供货价,供费用封顶与自动算费
|
||||
*/
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
@@ -13,14 +13,19 @@ import { Button, Empty, message, Pagination, Spin, Tag } from 'ant-design-vue';
|
||||
import { getWarehouseDrugManagementList } from '#/views/business/warehouse-drug-management/admin/api';
|
||||
|
||||
import { deleteDeliveryWarehouseDrug, getDeliveryWarehouseDrugList } from '../api';
|
||||
import { resolveCentralPrice } from '../utils/resolve-central-price';
|
||||
import {
|
||||
resolveCentralMarketPrice,
|
||||
resolveCentralPrice,
|
||||
} from '../utils/resolve-central-price';
|
||||
import FormModal from './modal.vue';
|
||||
|
||||
const drugId = ref(0);
|
||||
const drugName = ref('');
|
||||
const drugMeta = ref<Record<string, any>>({});
|
||||
/** 总仓售价,用于绑仓表单默认平台费与封顶 */
|
||||
/** 总仓售价,用于绑仓表单封顶与推广费计算 */
|
||||
const centralPrice = ref<number | null>(null);
|
||||
/** 总仓平台供货价,用于自动算推广费/平台费 */
|
||||
const centralMarketPrice = ref<number | null>(null);
|
||||
const productGridApi = ref();
|
||||
const loading = ref(false);
|
||||
const items = ref<Record<string, any>[]>([]);
|
||||
@@ -41,6 +46,13 @@ const priceText = computed(() => {
|
||||
return '无总仓售价';
|
||||
});
|
||||
|
||||
const marketText = computed(() => {
|
||||
if (centralMarketPrice.value != null && centralMarketPrice.value > 0) {
|
||||
return `¥${Number(centralMarketPrice.value).toFixed(2)}`;
|
||||
}
|
||||
return '无总仓供货价';
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载绑定卡片数据
|
||||
*/
|
||||
@@ -65,10 +77,15 @@ async function loadList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表未带售价时,按 drug_id 查总仓补齐
|
||||
* 列表未带售价/供货价时,按 drug_id 查总仓补齐
|
||||
*/
|
||||
async function ensureCentralPrice() {
|
||||
if (centralPrice.value != null && centralPrice.value > 0) return;
|
||||
const needSale = !(centralPrice.value != null && centralPrice.value > 0);
|
||||
const needMarket = !(
|
||||
centralMarketPrice.value != null &&
|
||||
centralMarketPrice.value > 0
|
||||
);
|
||||
if (!needSale && !needMarket) return;
|
||||
if (!drugId.value) return;
|
||||
try {
|
||||
const res = await getWarehouseDrugManagementList({
|
||||
@@ -78,16 +95,20 @@ async function ensureCentralPrice() {
|
||||
});
|
||||
const row = res?.items?.[0];
|
||||
const price = Number(row?.price ?? 0);
|
||||
if (price > 0) {
|
||||
const market = Number(row?.market_price ?? 0);
|
||||
if (needSale && price > 0) {
|
||||
centralPrice.value = price;
|
||||
}
|
||||
if (needMarket && market > 0) {
|
||||
centralMarketPrice.value = market;
|
||||
}
|
||||
} catch {
|
||||
// 补齐失败不阻断绑仓,表单内仍可手填三费
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增:药品锁定预填 + 带上 number 类型总仓售价
|
||||
* 打开新增:药品锁定预填 + 带上总仓售价与平台供货价
|
||||
*/
|
||||
async function openCreate() {
|
||||
await ensureCentralPrice();
|
||||
@@ -95,6 +116,10 @@ async function openCreate() {
|
||||
centralPrice.value != null && centralPrice.value > 0
|
||||
? Number(centralPrice.value)
|
||||
: null;
|
||||
const market =
|
||||
centralMarketPrice.value != null && centralMarketPrice.value > 0
|
||||
? Number(centralMarketPrice.value)
|
||||
: null;
|
||||
formModalApi.setData({
|
||||
update: false,
|
||||
// 新增成功后刷新业务列表与本卡片列表
|
||||
@@ -110,16 +135,21 @@ async function openCreate() {
|
||||
},
|
||||
lockDrug: true,
|
||||
central_price: price,
|
||||
central_market_price: market,
|
||||
market_price: market,
|
||||
presetDrug: {
|
||||
id: drugId.value,
|
||||
drug_name: drugName.value,
|
||||
specification: drugMeta.value.specification || '',
|
||||
image: drugMeta.value.image || '',
|
||||
central_price: price,
|
||||
central_market_price: market,
|
||||
market_price: market,
|
||||
},
|
||||
values: {
|
||||
drug_id: drugId.value,
|
||||
...(price != null ? { sale_price: price } : {}),
|
||||
...(market != null ? { market_price: market } : {}),
|
||||
},
|
||||
});
|
||||
formModalApi.open();
|
||||
@@ -131,6 +161,10 @@ async function openEdit(row: any) {
|
||||
centralPrice.value != null && centralPrice.value > 0
|
||||
? Number(centralPrice.value)
|
||||
: resolveCentralPrice(row);
|
||||
const market =
|
||||
centralMarketPrice.value != null && centralMarketPrice.value > 0
|
||||
? Number(centralMarketPrice.value)
|
||||
: resolveCentralMarketPrice(row);
|
||||
formModalApi.setData({
|
||||
update: true,
|
||||
gridApi: {
|
||||
@@ -144,9 +178,12 @@ async function openEdit(row: any) {
|
||||
},
|
||||
},
|
||||
central_price: price,
|
||||
central_market_price: market,
|
||||
market_price: market,
|
||||
values: {
|
||||
...row,
|
||||
...(price != null ? { sale_price: price } : {}),
|
||||
...(market != null ? { market_price: market } : {}),
|
||||
},
|
||||
});
|
||||
formModalApi.open();
|
||||
@@ -192,6 +229,11 @@ const [Modal, modalApi] = useVbenModal({
|
||||
resolveCentralPrice(data.values) ??
|
||||
resolveCentralPrice(data.presetDrug) ??
|
||||
null;
|
||||
centralMarketPrice.value =
|
||||
resolveCentralMarketPrice(data) ??
|
||||
resolveCentralMarketPrice(data.values) ??
|
||||
resolveCentralMarketPrice(data.presetDrug) ??
|
||||
null;
|
||||
productGridApi.value = data.gridApi;
|
||||
pendingAutoCreate.value = !!data.autoCreate;
|
||||
page.value = 1;
|
||||
@@ -220,6 +262,17 @@ const [Modal, modalApi] = useVbenModal({
|
||||
>
|
||||
{{ priceText }}
|
||||
</span>
|
||||
<span class="bind-list-header__sep">·</span>
|
||||
<span>平台供货价:</span>
|
||||
<span
|
||||
:class="
|
||||
centralMarketPrice && centralMarketPrice > 0
|
||||
? 'bind-list-header__price'
|
||||
: 'bind-list-header__price--empty'
|
||||
"
|
||||
>
|
||||
{{ marketText }}
|
||||
</span>
|
||||
</div>
|
||||
<Button type="primary" @click="openCreate">新增绑定</Button>
|
||||
</div>
|
||||
@@ -289,6 +342,10 @@ const [Modal, modalApi] = useVbenModal({
|
||||
font-size: 13px;
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
.bind-list-header__sep {
|
||||
margin: 0 6px;
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
.bind-list-header__price {
|
||||
font-weight: 600;
|
||||
color: hsl(var(--foreground));
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
/**
|
||||
* 仓药绑定弹窗
|
||||
* 新增时用 DrugSearchSelect(is-card) 选药;编辑/预填锁定时不可换药
|
||||
* 有总仓售价时:展示、新增默认平台费=售价5%、三费超售价实时提醒并拦截提交
|
||||
* 注意:必须 await setValues,否则异步覆盖会把 sale_price 冲掉
|
||||
* 有总仓售价/供货价时:展示、按公式自动算推广费/平台费、三费超售价实时提醒并拦截提交
|
||||
* 注意:必须 await setValues,否则异步覆盖会把 sale_price/market_price 冲掉
|
||||
*/
|
||||
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
||||
|
||||
@@ -27,7 +27,10 @@ import {
|
||||
seedAutoPromoFeeKey,
|
||||
syncFeeSumDisplay,
|
||||
} from '#/views/system/delivery-warehouse-drug/config/form';
|
||||
import { resolveCentralPrice } from '#/views/system/delivery-warehouse-drug/utils/resolve-central-price';
|
||||
import {
|
||||
resolveCentralMarketPrice,
|
||||
resolveCentralPrice,
|
||||
} from '#/views/system/delivery-warehouse-drug/utils/resolve-central-price';
|
||||
|
||||
/** 非中药品类:西药/保健/中成药/服务包/非药品/医疗器械 */
|
||||
const NON_CHINESE_DRUG_TYPES = [2, 3, 4, 5, 6, 7];
|
||||
@@ -62,31 +65,31 @@ onUnmounted(() => {
|
||||
});
|
||||
|
||||
/**
|
||||
* 写入售价;新增时默认平台费 = 售价 5%,并按差额回填推广费
|
||||
* 编辑仅写售价并锁定依赖 key,不覆盖已有三费
|
||||
* 写入总仓售价与平台供货价
|
||||
* 新增时按公式自动回填推广费/平台费;编辑仅写入价并锁定依赖 key,不覆盖已有三费
|
||||
*/
|
||||
async function applyCentralPrice(
|
||||
async function applyCentralPrices(
|
||||
price: number | string | null | undefined,
|
||||
market: number | string | null | undefined,
|
||||
isCreate: boolean,
|
||||
) {
|
||||
const n = Number(price);
|
||||
if (!(n > 0)) {
|
||||
await formApi.setFieldValue('sale_price', undefined);
|
||||
return;
|
||||
}
|
||||
const sale = Number(n.toFixed(4));
|
||||
const saleN = Number(price);
|
||||
const marketN = Number(market);
|
||||
const sale = saleN > 0 ? Number(saleN.toFixed(4)) : undefined;
|
||||
const marketPrice = marketN > 0 ? Number(marketN.toFixed(4)) : undefined;
|
||||
await formApi.setFieldValue('sale_price', sale);
|
||||
await formApi.setFieldValue('market_price', marketPrice);
|
||||
const values = await formApi.getValues();
|
||||
const merged = {
|
||||
...values,
|
||||
...(sale != null ? { sale_price: sale } : {}),
|
||||
...(marketPrice != null ? { market_price: marketPrice } : {}),
|
||||
};
|
||||
if (isCreate) {
|
||||
const platform = Number((sale * 0.05).toFixed(4));
|
||||
await formApi.setFieldValue('platform_fee', platform);
|
||||
const values = await formApi.getValues();
|
||||
const merged = { ...values, sale_price: sale, platform_fee: platform };
|
||||
applyAutoPromoFee(merged, formApi);
|
||||
syncFeeSumDisplay(merged, formApi);
|
||||
return;
|
||||
}
|
||||
const values = await formApi.getValues();
|
||||
const merged = { ...values, sale_price: sale };
|
||||
seedAutoPromoFeeKey(merged);
|
||||
syncFeeSumDisplay(merged, formApi);
|
||||
}
|
||||
@@ -102,6 +105,17 @@ function pickSalePrice(data: Record<string, any>) {
|
||||
return resolveCentralPrice(data.presetDrug);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从弹窗入参解析平台供货价:优先 data.central_market_price / market_price
|
||||
*/
|
||||
function pickMarketPrice(data: Record<string, any>) {
|
||||
const fromData = resolveCentralMarketPrice(data);
|
||||
if (fromData != null) return fromData;
|
||||
const fromValues = resolveCentralMarketPrice(data.values);
|
||||
if (fromValues != null) return fromValues;
|
||||
return resolveCentralMarketPrice(data.presetDrug);
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
@@ -124,10 +138,13 @@ const [Modal, modalApi] = useVbenModal({
|
||||
const e = await formApi.validate();
|
||||
if (!e.valid) return;
|
||||
const payload = { ...(await formApi.getValues()) };
|
||||
// sale_price 只作封顶校验,不用费用合计覆盖
|
||||
// sale_price / market_price 只作算费与封顶,不落仓药绑定表
|
||||
if (payload.sale_price === undefined || payload.sale_price === '') {
|
||||
delete payload.sale_price;
|
||||
}
|
||||
if (payload.market_price === undefined || payload.market_price === '') {
|
||||
delete payload.market_price;
|
||||
}
|
||||
delete payload._fee_sum;
|
||||
if (Number(calcFeeSum(payload)) <= 0) {
|
||||
message.warning('报价/推广费/平台费合计必须大于0');
|
||||
@@ -160,14 +177,16 @@ const [Modal, modalApi] = useVbenModal({
|
||||
lockDrug.value = !!data.lockDrug && !update;
|
||||
editDrugCard.value = null;
|
||||
feeOverTip.value = '';
|
||||
// 清零自动算费 key,避免沿用上一单的报价/平台费组合
|
||||
// 清零自动算费 key,避免沿用上一单的报价/供货价组合
|
||||
resetAutoPromoFeeKey();
|
||||
const salePrice = pickSalePrice(data);
|
||||
// 先重置,再 await 写入,避免异步 setValues 冲掉 sale_price
|
||||
const marketPrice = pickMarketPrice(data);
|
||||
// 先重置,再 await 写入,避免异步 setValues 冲掉售价/供货价
|
||||
await formApi.resetForm();
|
||||
const nextValues = {
|
||||
...(values || {}),
|
||||
...(salePrice != null ? { sale_price: salePrice } : {}),
|
||||
...(marketPrice != null ? { market_price: marketPrice } : {}),
|
||||
};
|
||||
if (Object.keys(nextValues).length) {
|
||||
await formApi.setValues(nextValues);
|
||||
@@ -182,8 +201,8 @@ const [Modal, modalApi] = useVbenModal({
|
||||
spec: values.drug?.specification || values.specification || '',
|
||||
image: values.drug?.image || values.image || DRUG_PLACEHOLDER_IMAGE,
|
||||
};
|
||||
// 编辑:只写售价,不覆盖已有三费
|
||||
await applyCentralPrice(salePrice, false);
|
||||
// 编辑:只写售价/供货价,不覆盖已有三费
|
||||
await applyCentralPrices(salePrice, marketPrice, false);
|
||||
} else if (lockDrug.value && presetDrug) {
|
||||
const id = Number(presetDrug.id || values?.drug_id || 0);
|
||||
await formApi.setFieldValue('drug_id', id);
|
||||
@@ -193,18 +212,24 @@ const [Modal, modalApi] = useVbenModal({
|
||||
spec: presetDrug.specification || '',
|
||||
image: presetDrug.image || DRUG_PLACEHOLDER_IMAGE,
|
||||
};
|
||||
await applyCentralPrice(salePrice, true);
|
||||
await applyCentralPrices(salePrice, marketPrice, true);
|
||||
} else if (!update) {
|
||||
await applyCentralPrice(salePrice, true);
|
||||
await applyCentralPrices(salePrice, marketPrice, true);
|
||||
}
|
||||
// 再确认一次:部分表单实现会二次回填空值
|
||||
await nextTick();
|
||||
const after = await formApi.getValues();
|
||||
const afterSale = Number(after?.sale_price);
|
||||
if (salePrice != null && (!(afterSale > 0) || afterSale !== salePrice)) {
|
||||
await applyCentralPrice(salePrice, !update);
|
||||
const afterMarket = Number(after?.market_price);
|
||||
const saleMismatch =
|
||||
salePrice != null && (!(afterSale > 0) || afterSale !== salePrice);
|
||||
const marketMismatch =
|
||||
marketPrice != null &&
|
||||
(!(afterMarket > 0) || afterMarket !== marketPrice);
|
||||
if (saleMismatch || marketMismatch) {
|
||||
await applyCentralPrices(salePrice, marketPrice, !update);
|
||||
}
|
||||
// 打开后同步一次上限与提示(售价写入后 dependencies 可能未立刻跑完)
|
||||
// 打开后同步一次上限与提示(价写入后 dependencies 可能未立刻跑完)
|
||||
const latest = await formApi.getValues();
|
||||
feeOverTip.value = syncFeeSumDisplay(latest, formApi);
|
||||
},
|
||||
@@ -222,10 +247,14 @@ async function onSelectDrug(item: any) {
|
||||
return;
|
||||
}
|
||||
await formApi.setFieldValue('drug_id', drugId);
|
||||
// 搜药选中后若带总仓价则预填平台费 5%
|
||||
const price = resolveCentralPrice(item) ?? resolveCentralPrice(item?.drug);
|
||||
if (price != null) {
|
||||
await applyCentralPrice(price, true);
|
||||
// 搜药选中后若带总仓售价/供货价则按新公式自动算费
|
||||
const price =
|
||||
resolveCentralPrice(item) ?? resolveCentralPrice(item?.drug);
|
||||
const market =
|
||||
resolveCentralMarketPrice(item) ??
|
||||
resolveCentralMarketPrice(item?.drug);
|
||||
if (price != null || market != null) {
|
||||
await applyCentralPrices(price, market, true);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -11,15 +11,25 @@ export function calcFeeSum(values: Record<string, any>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店推广费 = 售价 − (报价 + 平台费),不低于 0
|
||||
* 有售价时用于自动回填,保证三费合计贴合售价
|
||||
* 推广费 = 商品售价 − 平台供货价,不低于 0
|
||||
* 有售价与供货价时用于自动回填
|
||||
*/
|
||||
export function calcPromoFee(values: Record<string, any>): number {
|
||||
const sale = Number(values.sale_price) || 0;
|
||||
if (!(sale > 0)) return Number(values.promo_fee) || 0;
|
||||
const market = Number(values.market_price) || 0;
|
||||
if (!(sale > 0) || !(market > 0)) return Number(values.promo_fee) || 0;
|
||||
return Number(Math.max(0, sale - market).toFixed(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台费 = 平台供货价 − 仓库报价,不低于 0
|
||||
* 有供货价时用于自动回填
|
||||
*/
|
||||
export function calcPlatformFee(values: Record<string, any>): number {
|
||||
const market = Number(values.market_price) || 0;
|
||||
if (!(market > 0)) return Number(values.platform_fee) || 0;
|
||||
const quote = Number(values.quote) || 0;
|
||||
const platformFee = Number(values.platform_fee) || 0;
|
||||
return Number(Math.max(0, sale - quote - platformFee).toFixed(4));
|
||||
return Number(Math.max(0, market - quote).toFixed(4));
|
||||
}
|
||||
|
||||
/** 三费是否超过药品售价 */
|
||||
@@ -34,8 +44,8 @@ type FeeOverTipHandler = (tip: string) => void;
|
||||
let feeOverTipHandler: FeeOverTipHandler | null = null;
|
||||
|
||||
/**
|
||||
* 记录上次自动算费依赖(售价|报价|平台费)
|
||||
* 仅依赖变化时覆盖 promo_fee,避免手改推广费被立刻冲掉
|
||||
* 记录上次自动算费依赖(售价|供货价|报价)
|
||||
* 仅依赖变化时覆盖两费,避免手改被立刻冲掉
|
||||
*/
|
||||
let lastAutoPromoKey = '';
|
||||
|
||||
@@ -50,47 +60,55 @@ export function resetAutoPromoFeeKey() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑回填后锁定当前依赖 key,避免一打开就把已有推广费冲掉
|
||||
* 之后只有改报价/平台费/售价才会重新自动算
|
||||
* 编辑回填后锁定当前依赖 key,避免一打开就把已有两费冲掉
|
||||
* 之后只有改售价/供货价/报价才会重新自动算
|
||||
*/
|
||||
export function seedAutoPromoFeeKey(values: Record<string, any>) {
|
||||
const sale = Number(values.sale_price) || 0;
|
||||
if (!(sale > 0)) {
|
||||
const market = Number(values.market_price) || 0;
|
||||
if (!(sale > 0) && !(market > 0)) {
|
||||
lastAutoPromoKey = '';
|
||||
return;
|
||||
}
|
||||
lastAutoPromoKey = `${sale}|${Number(values.quote) || 0}|${Number(values.platform_fee) || 0}`;
|
||||
lastAutoPromoKey = `${sale}|${market}|${Number(values.quote) || 0}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 有售价且 quote/platform/sale 变化时,自动回填门店推广费
|
||||
* @returns 回填后的 values(含最新 promo_fee),供合计展示使用
|
||||
* 有售价/供货价且 sale/market/quote 变化时,自动回填推广费与平台费
|
||||
* @returns 回填后的 values(含最新两费),供合计展示使用
|
||||
*/
|
||||
export function applyAutoPromoFee(
|
||||
values: Record<string, any>,
|
||||
formApi: any,
|
||||
): Record<string, any> {
|
||||
const sale = Number(values.sale_price) || 0;
|
||||
if (!(sale > 0)) {
|
||||
const market = Number(values.market_price) || 0;
|
||||
// 无售价且无供货价时不强算
|
||||
if (!(sale > 0) && !(market > 0)) {
|
||||
return values;
|
||||
}
|
||||
const key = `${sale}|${Number(values.quote) || 0}|${Number(values.platform_fee) || 0}`;
|
||||
const nextPromo = calcPromoFee(values);
|
||||
// 依赖未变:可能是手改推广费触发,不覆盖
|
||||
const key = `${sale}|${market}|${Number(values.quote) || 0}`;
|
||||
// 依赖未变:可能是手改推广费/平台费触发,不覆盖
|
||||
if (key === lastAutoPromoKey) {
|
||||
return values;
|
||||
}
|
||||
lastAutoPromoKey = key;
|
||||
const cur = Number(values.promo_fee);
|
||||
if (!(Math.abs(cur - nextPromo) < 0.00005)) {
|
||||
const nextPromo = calcPromoFee(values);
|
||||
const nextPlatform = calcPlatformFee(values);
|
||||
const curPromo = Number(values.promo_fee);
|
||||
const curPlatform = Number(values.platform_fee);
|
||||
if (!(Math.abs(curPromo - nextPromo) < 0.00005)) {
|
||||
formApi.setFieldValue('promo_fee', nextPromo);
|
||||
}
|
||||
return { ...values, promo_fee: nextPromo };
|
||||
if (!(Math.abs(curPlatform - nextPlatform) < 0.00005)) {
|
||||
formApi.setFieldValue('platform_fee', nextPlatform);
|
||||
}
|
||||
return { ...values, promo_fee: nextPromo, platform_fee: nextPlatform };
|
||||
}
|
||||
|
||||
/**
|
||||
* 费用合计联动:先按差额回填推广费,再刷新合计 / 超售价提示
|
||||
* 为什么放在 trigger:输入报价或平台费即触发,不必等提交
|
||||
* 费用合计联动:先按新公式回填两费,再刷新合计 / 超售价提示
|
||||
* 为什么放在 trigger:输入报价或供货价即触发,不必等提交
|
||||
* @returns 超售价提示文案(无则空串)
|
||||
*/
|
||||
export function syncFeeSumDisplay(
|
||||
@@ -101,14 +119,16 @@ export function syncFeeSumDisplay(
|
||||
const sum = calcFeeSum(merged);
|
||||
formApi.setFieldValue('_fee_sum', sum);
|
||||
const sale = Number(merged.sale_price) || 0;
|
||||
const market = Number(merged.market_price) || 0;
|
||||
const canAuto = sale > 0 && market > 0;
|
||||
const over = sale > 0 && Number(sum) > sale;
|
||||
const tip = over
|
||||
? `三费合计已超过药品售价 ¥${sale.toFixed(4)},请下调报价/推广费/平台费`
|
||||
: '';
|
||||
const feeHelp = over
|
||||
? tip
|
||||
: sale > 0
|
||||
? `推广费自动=售价−(报价+平台费);合计不得超过 ¥${sale.toFixed(4)}`
|
||||
: canAuto
|
||||
? `推广费=售价−供货价,平台费=供货价−报价;合计不得超过 ¥${sale.toFixed(4)}`
|
||||
: '报价+推广费+平台费之和,保存时需大于0';
|
||||
// 单项输入上限:有售价时不得超过售价;同时刷新合计 help
|
||||
const feeInputProps = {
|
||||
@@ -127,17 +147,18 @@ export function syncFeeSumDisplay(
|
||||
},
|
||||
{
|
||||
fieldName: 'promo_fee',
|
||||
help: sale > 0 ? '自动计算:售价 − (报价 + 平台费),可微调' : undefined,
|
||||
help: canAuto ? '自动计算:售价 − 平台供货价,可微调' : undefined,
|
||||
componentProps: {
|
||||
...feeInputProps,
|
||||
placeholder: sale > 0 ? '自动=售价−报价−平台费' : '请输入推广费',
|
||||
placeholder: canAuto ? '自动=售价−供货价' : '请输入推广费',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'platform_fee',
|
||||
help: market > 0 ? '自动计算:平台供货价 − 仓库报价,可微调' : undefined,
|
||||
componentProps: {
|
||||
...feeInputProps,
|
||||
placeholder: '请输入平台费',
|
||||
placeholder: market > 0 ? '自动=供货价−报价' : '请输入平台费',
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -216,6 +237,19 @@ export const modalFormProps: VbenFormProps = {
|
||||
label: '药品售价',
|
||||
help: '来自总仓库建议售价;三费合计不得超过该值',
|
||||
},
|
||||
{
|
||||
// 总仓供货价只读,用于自动算推广费/平台费
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
precision: 4,
|
||||
class: 'w-full',
|
||||
placeholder: '无总仓供货价',
|
||||
},
|
||||
fieldName: 'market_price',
|
||||
label: '平台供货价',
|
||||
help: '来自总仓库供货价;推广费=售价−供货价,平台费=供货价−报价',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
@@ -238,7 +272,7 @@ export const modalFormProps: VbenFormProps = {
|
||||
},
|
||||
fieldName: 'promo_fee',
|
||||
label: '推广费',
|
||||
help: '有售价时自动=售价−(报价+平台费)',
|
||||
help: '有售价与供货价时自动=售价−供货价',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
@@ -251,6 +285,7 @@ export const modalFormProps: VbenFormProps = {
|
||||
},
|
||||
fieldName: 'platform_fee',
|
||||
label: '平台费',
|
||||
help: '有供货价时自动=供货价−报价',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
@@ -266,7 +301,13 @@ export const modalFormProps: VbenFormProps = {
|
||||
trigger(values, formApi) {
|
||||
syncFeeSumDisplay(values, formApi);
|
||||
},
|
||||
triggerFields: ['quote', 'promo_fee', 'platform_fee', 'sale_price'],
|
||||
triggerFields: [
|
||||
'quote',
|
||||
'promo_fee',
|
||||
'platform_fee',
|
||||
'sale_price',
|
||||
'market_price',
|
||||
],
|
||||
},
|
||||
},
|
||||
// 创建时可填初始库存,提交后走入库流水(编辑时不展示)
|
||||
|
||||
@@ -21,3 +21,27 @@ export function resolveCentralPrice(
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从列表行 / 弹窗入参中解析总仓平台供货价(market_price)
|
||||
* 用于三费自动计算:推广费=售价−供货价,平台费=供货价−报价
|
||||
*/
|
||||
export function resolveCentralMarketPrice(
|
||||
source: Record<string, any> | null | undefined,
|
||||
): number | null {
|
||||
if (!source) return null;
|
||||
const nested =
|
||||
source.central_warehouse_drug ?? source.centralWarehouseDrug ?? null;
|
||||
const candidates = [
|
||||
source.central_market_price,
|
||||
source.centralMarketPrice,
|
||||
nested?.market_price,
|
||||
source.market_price,
|
||||
source.marketPrice,
|
||||
];
|
||||
for (const c of candidates) {
|
||||
const n = Number(c);
|
||||
if (n > 0) return Number(n.toFixed(4));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -29,13 +29,12 @@ const gridApi = ref();
|
||||
const detail = ref<Record<string, any> | null>(null);
|
||||
/** 三费超售价红色提示 */
|
||||
const feeOverTip = ref('');
|
||||
/** 记录已按售价自动填过平台费的售价,避免反复覆盖手改 */
|
||||
const lastAutoPlatformSale = ref(0);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
wrapperClass: 'grid-cols-12',
|
||||
// 一行两个:默认半宽,弹窗加宽后排布更紧凑
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-12',
|
||||
formItemClass: 'col-span-6',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
@@ -145,7 +144,7 @@ const [Form, formApi] = useVbenForm({
|
||||
fieldName: 'market_price',
|
||||
label: '仓库供货价',
|
||||
rules: 'required',
|
||||
help: '写入总仓并同步到门店供货价',
|
||||
help: '写入总仓并同步到门店;推广费=售价−本价,平台费=本价−绑仓报价',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
@@ -184,12 +183,12 @@ const [Form, formApi] = useVbenForm({
|
||||
fieldName: 'platform_fee',
|
||||
label: '平台费',
|
||||
rules: 'required',
|
||||
help: '默认售价的 5%,可改',
|
||||
help: '自动=平台供货价−仓库报价,可改',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '自动=售价−报价−平台费',
|
||||
placeholder: '自动=售价−供货价',
|
||||
min: 0,
|
||||
precision: 4,
|
||||
class: 'w-full',
|
||||
@@ -197,7 +196,7 @@ const [Form, formApi] = useVbenForm({
|
||||
fieldName: 'promo_fee',
|
||||
label: '推广费',
|
||||
rules: 'required',
|
||||
help: '有售价时自动计算,可微调',
|
||||
help: '自动=售价−平台供货价,可微调',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
@@ -210,23 +209,22 @@ const [Form, formApi] = useVbenForm({
|
||||
// 把 price 映射为仓药绑定逻辑里的 sale_price,复用三费联动
|
||||
dependencies: {
|
||||
async trigger(values, formApiInst) {
|
||||
const sale = Number(values.price) || 0;
|
||||
// 售价变化时默认平台费 = 售价 * 5%(仅该售价首次自动填)
|
||||
if (sale > 0 && lastAutoPlatformSale.value !== sale) {
|
||||
const platform = Number((sale * 0.05).toFixed(4));
|
||||
await formApiInst.setFieldValue('platform_fee', platform);
|
||||
lastAutoPlatformSale.value = sale;
|
||||
values = { ...values, platform_fee: platform };
|
||||
}
|
||||
syncFeeSumDisplay(
|
||||
{
|
||||
...values,
|
||||
sale_price: sale,
|
||||
sale_price: Number(values.price) || 0,
|
||||
market_price: Number(values.market_price) || 0,
|
||||
},
|
||||
formApiInst,
|
||||
);
|
||||
},
|
||||
triggerFields: ['quote', 'promo_fee', 'platform_fee', 'price'],
|
||||
triggerFields: [
|
||||
'quote',
|
||||
'promo_fee',
|
||||
'platform_fee',
|
||||
'price',
|
||||
'market_price',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -262,60 +260,60 @@ const [Modal, modalApi] = useVbenModal({
|
||||
onConfirm: async () => {
|
||||
const e = await formApi.validate();
|
||||
if (!e.valid) return;
|
||||
const values = await formApi.getValues();
|
||||
const status = Number(values.status);
|
||||
if (status !== 2 && status !== 3) {
|
||||
message.warning('请选择上架或下架');
|
||||
return;
|
||||
}
|
||||
if (!values.zone_id) {
|
||||
message.warning('请选择所属分区');
|
||||
return;
|
||||
}
|
||||
const drugNumber = String(values.drug_number || '').trim();
|
||||
if (!drugNumber) {
|
||||
message.warning('请填写 ERP 编号(无 ERP 可点「非erp」填 -1)');
|
||||
return;
|
||||
}
|
||||
const feeValues = {
|
||||
quote: values.quote,
|
||||
promo_fee: values.promo_fee,
|
||||
platform_fee: values.platform_fee,
|
||||
sale_price: values.price,
|
||||
};
|
||||
if (isFeeOverSalePrice(feeValues)) {
|
||||
message.warning(
|
||||
`三费合计已超过售价 ¥${Number(values.price).toFixed(4)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (Number(calcFeeSum(feeValues)) <= 0) {
|
||||
message.warning('报价/推广费/平台费合计必须大于0');
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
auditDeliveryWarehouseProduct({
|
||||
id: Number(values.id),
|
||||
status: status as 2 | 3,
|
||||
zone_id: Number(values.zone_id),
|
||||
category_id: Number(values.category_id || 0),
|
||||
drug_number: drugNumber,
|
||||
market_price: Number(values.market_price),
|
||||
price: Number(values.price),
|
||||
quote: Number(values.quote),
|
||||
promo_fee: Number(values.promo_fee),
|
||||
platform_fee: Number(values.platform_fee),
|
||||
initial_stock: Number(values.initial_stock || 0),
|
||||
})
|
||||
.then(() => {
|
||||
message.success('审核成功,已完成总仓同步与仓药绑定');
|
||||
gridApi.value?.query?.() ?? gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
});
|
||||
|
||||
const values = await formApi.getValues();
|
||||
const status = Number(values.status);
|
||||
if (status !== 2 && status !== 3) {
|
||||
message.warning('请选择上架或下架');
|
||||
return;
|
||||
}
|
||||
if (!values.zone_id) {
|
||||
message.warning('请选择所属分区');
|
||||
return;
|
||||
}
|
||||
const drugNumber = String(values.drug_number || '').trim();
|
||||
if (!drugNumber) {
|
||||
message.warning('请填写 ERP 编号(无 ERP 可点「非erp」填 -1)');
|
||||
return;
|
||||
}
|
||||
const feeValues = {
|
||||
quote: values.quote,
|
||||
promo_fee: values.promo_fee,
|
||||
platform_fee: values.platform_fee,
|
||||
sale_price: values.price,
|
||||
};
|
||||
if (isFeeOverSalePrice(feeValues)) {
|
||||
message.warning(
|
||||
`三费合计已超过售价 ¥${Number(values.price).toFixed(4)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (Number(calcFeeSum(feeValues)) <= 0) {
|
||||
message.warning('报价/推广费/平台费合计必须大于0');
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await auditDeliveryWarehouseProduct({
|
||||
id: Number(values.id),
|
||||
status: status as 2 | 3,
|
||||
zone_id: Number(values.zone_id),
|
||||
category_id: Number(values.category_id || 0),
|
||||
drug_number: drugNumber,
|
||||
market_price: Number(values.market_price),
|
||||
price: Number(values.price),
|
||||
quote: Number(values.quote),
|
||||
promo_fee: Number(values.promo_fee),
|
||||
platform_fee: Number(values.platform_fee),
|
||||
initial_stock: Number(values.initial_stock || 0),
|
||||
});
|
||||
message.success('审核成功,已完成总仓同步与仓药绑定');
|
||||
gridApi.value?.query?.() ?? gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
@@ -326,7 +324,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||
const data = modalApi.getData<Record<string, any>>() || {};
|
||||
gridApi.value = data.gridApi ?? null;
|
||||
resetAutoPromoFeeKey();
|
||||
lastAutoPlatformSale.value = 0;
|
||||
feeOverTip.value = '';
|
||||
await formApi.resetForm();
|
||||
const id = Number(data.id || data.values?.id || 0);
|
||||
@@ -364,18 +361,25 @@ const [Modal, modalApi] = useVbenModal({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="仓品审核" class="w-[80%] md:w-[560px] lg:w-[520px]">
|
||||
<!-- 加宽弹窗,配合表单一行两列 -->
|
||||
<Modal title="仓品审核" class="w-[92%] md:w-[780px] lg:w-[860px]">
|
||||
<div v-if="detail" class="mb-4">
|
||||
<Descriptions :column="1" size="small" bordered>
|
||||
<Descriptions :column="2" size="small" bordered>
|
||||
<Descriptions.Item label="药品名称">
|
||||
{{ detail.drug_name || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="规格">
|
||||
{{ detail.specification || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="别名">
|
||||
{{ detail.drug_alias || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="类型">
|
||||
{{ detail.type_txt || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="供应商">
|
||||
{{ detail.supplier?.name || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="上传报价">
|
||||
¥{{ detail.upload_quote || '0' }}
|
||||
</Descriptions.Item>
|
||||
|
||||
@@ -6,7 +6,13 @@ interface RowType {
|
||||
id: number;
|
||||
image?: string;
|
||||
drug_name: string;
|
||||
/** 规格、别名等仓侧建品信息,审核列表需一眼可见 */
|
||||
specification?: string;
|
||||
drug_alias?: string;
|
||||
type_txt?: string;
|
||||
/** 仓侧上传报价,审核绑仓时默认带入 */
|
||||
upload_quote?: number | string;
|
||||
supplier?: { id?: number; name?: string };
|
||||
audit_status: number;
|
||||
audit_status_txt?: string;
|
||||
status: number;
|
||||
@@ -39,7 +45,27 @@ export const gridOptions: VxeGridProps<RowType> = {
|
||||
slots: { default: 'image' },
|
||||
},
|
||||
{ field: 'drug_name', title: '药品名称', minWidth: 160 },
|
||||
{ field: 'specification', title: '规格', minWidth: 120 },
|
||||
{ field: 'drug_alias', title: '别名', minWidth: 120 },
|
||||
{ field: 'type_txt', title: '类型', width: 110 },
|
||||
{
|
||||
field: 'supplier.name',
|
||||
title: '供应商',
|
||||
minWidth: 120,
|
||||
formatter: ({ row }) => row?.supplier?.name || '—',
|
||||
},
|
||||
{
|
||||
field: 'upload_quote',
|
||||
title: '上传报价',
|
||||
width: 110,
|
||||
formatter: ({ cellValue }) => {
|
||||
// 与审核弹窗「上传报价」一致,空值显示 —
|
||||
if (cellValue === null || cellValue === undefined || cellValue === '') {
|
||||
return '—';
|
||||
}
|
||||
return `¥${cellValue}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'audit_status_txt',
|
||||
title: '审核状态',
|
||||
|
||||
@@ -96,7 +96,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
{ field: 'status', title: '状态', width: 90, slots: { default: 'status' } },
|
||||
{ field: 'sort', title: '排序', width: 80 },
|
||||
{ field: 'created_at', title: '创建时间', width: 170 },
|
||||
{ title: '操作', slots: { default: 'action' }, width: 220, fixed: 'right' },
|
||||
// 三个操作横排需要约 200+;过窄会挤换行,配合 TableAction :flex=false 避免两列叠字
|
||||
{ title: '操作', slots: { default: 'action' }, width: 240, fixed: 'right' },
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
@@ -334,7 +335,9 @@ async function handleConfirmImport(payload: { rows: any[]; sourceId: number }) {
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<!-- flex=false:超过 2 个按钮时禁止两列 grid,避免行高被裁切叠字 -->
|
||||
<TableAction
|
||||
:flex="false"
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
|
||||
162
apps/web-antd/src/views/system/menu/components/auth-role.vue
Normal file
162
apps/web-antd/src/views/system/menu/components/auth-role.vue
Normal file
@@ -0,0 +1,162 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 菜单反向授权抽屉:勾选角色后全量同步该菜单在 xk_role_menu_relations 中的绑定
|
||||
* 与「角色→授权菜单」共用同一张关系表,入口方向相反
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Checkbox, Empty, Spin, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
getRoleIdsByMenuId,
|
||||
getRoleOption,
|
||||
saveMenuRoles,
|
||||
} from '#/views/system/role/api';
|
||||
|
||||
type RoleOptionItem = { label: string; value: number };
|
||||
|
||||
const record = ref<any>({});
|
||||
const loading = ref(false);
|
||||
const roleOptions = ref<RoleOptionItem[]>([]);
|
||||
const selectedRoleIds = ref<number[]>([]);
|
||||
|
||||
const drawerTitle = computed(() => {
|
||||
const menuName = record.value?.title || record.value?.name || '';
|
||||
return menuName ? `授权角色 - ${menuName}` : '授权角色';
|
||||
});
|
||||
|
||||
/** 是否勾选了超级管理员(role_id=1);登录时超管不依赖关系表,需提示 */
|
||||
const hasSuperAdmin = computed(() => selectedRoleIds.value.includes(1));
|
||||
|
||||
/**
|
||||
* 加载全部角色选项 + 当前菜单已绑定角色,用于回显勾选
|
||||
*/
|
||||
async function loadData() {
|
||||
const menuId = Number(record.value?.id || 0);
|
||||
if (!menuId) {
|
||||
roleOptions.value = [];
|
||||
selectedRoleIds.value = [];
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const [options, boundIds] = await Promise.all([
|
||||
getRoleOption({}),
|
||||
getRoleIdsByMenuId(menuId),
|
||||
]);
|
||||
roleOptions.value = (Array.isArray(options) ? options : [])
|
||||
.map((item: any) => ({
|
||||
label: String(item.label || item.name || ''),
|
||||
value: Number(item.value || item.id),
|
||||
}))
|
||||
.filter((item: RoleOptionItem) => item.value > 0 && item.label);
|
||||
const ids = Array.isArray(boundIds) ? boundIds : [];
|
||||
selectedRoleIds.value = ids
|
||||
.map((id: any) => Number(id))
|
||||
.filter((id) => id > 0);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 全选当前列表中的角色 */
|
||||
function selectAll() {
|
||||
selectedRoleIds.value = roleOptions.value.map((row) => row.value);
|
||||
}
|
||||
|
||||
/** 清空勾选 */
|
||||
function clearAll() {
|
||||
selectedRoleIds.value = [];
|
||||
}
|
||||
|
||||
/** 反选 */
|
||||
function invertAll() {
|
||||
const set = new Set(selectedRoleIds.value);
|
||||
selectedRoleIds.value = roleOptions.value
|
||||
.map((row) => row.value)
|
||||
.filter((id) => !set.has(id));
|
||||
}
|
||||
|
||||
const [Drawer, DrawerApi] = useVbenDrawer({
|
||||
onOpenChange: async (isOpen) => {
|
||||
record.value = isOpen ? DrawerApi.getData()?.record : {};
|
||||
if (isOpen) {
|
||||
await loadData();
|
||||
} else {
|
||||
selectedRoleIds.value = [];
|
||||
roleOptions.value = [];
|
||||
}
|
||||
},
|
||||
onConfirm: async () => {
|
||||
const menuId = Number(record.value?.id || 0);
|
||||
if (!menuId) {
|
||||
message.warning('菜单无效');
|
||||
return;
|
||||
}
|
||||
DrawerApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await saveMenuRoles({
|
||||
menu_id: menuId,
|
||||
role_id: selectedRoleIds.value.slice(),
|
||||
});
|
||||
message.success('授权成功');
|
||||
DrawerApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
DrawerApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose(DrawerApi);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer class="w-[520px]" :title="drawerTitle">
|
||||
<Spin :spinning="loading">
|
||||
<Alert
|
||||
v-if="hasSuperAdmin"
|
||||
class="mb-3"
|
||||
type="info"
|
||||
show-icon
|
||||
message="超级管理员登录时默认拥有全部菜单,不依赖本关系表;勾选仍会写入绑定记录。"
|
||||
/>
|
||||
<div class="mb-3 flex flex-wrap items-center gap-2">
|
||||
<Button size="small" @click="selectAll">全选</Button>
|
||||
<Button size="small" @click="clearAll">清空</Button>
|
||||
<Button size="small" @click="invertAll">反选</Button>
|
||||
<span class="text-muted-foreground text-xs">
|
||||
已选 {{ selectedRoleIds.length }} / {{ roleOptions.length }}
|
||||
</span>
|
||||
</div>
|
||||
<Empty
|
||||
v-if="!loading && roleOptions.length === 0"
|
||||
description="暂无角色可选"
|
||||
/>
|
||||
<Checkbox.Group
|
||||
v-else
|
||||
v-model:value="selectedRoleIds"
|
||||
class="flex w-full flex-col gap-2"
|
||||
>
|
||||
<div
|
||||
v-for="item in roleOptions"
|
||||
:key="item.value"
|
||||
class="border-border hover:bg-muted/40 rounded border px-3 py-2"
|
||||
>
|
||||
<Checkbox :value="item.value">
|
||||
<span>{{ item.label }}</span>
|
||||
<span class="text-muted-foreground ml-2 text-xs">
|
||||
#{{ item.value }}
|
||||
</span>
|
||||
<span v-if="item.value === 1" class="text-primary ml-2 text-xs">
|
||||
(超管默认全菜单)
|
||||
</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
</Checkbox.Group>
|
||||
</Spin>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -4,18 +4,18 @@ import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import AuthMenu from '../role/components/auth-menu.vue';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { Icon } from '#/components/icon';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
|
||||
import { deleteMenu } from './api';
|
||||
import AuthRole from './components/auth-role.vue';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
import {Icon} from "#/components/icon";
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
|
||||
@@ -72,11 +72,19 @@ const expandAll = () => {
|
||||
const collapseAll = () => {
|
||||
gridApi.grid?.setAllTreeExpand(false);
|
||||
};
|
||||
|
||||
/** 菜单反向授权:打开角色勾选抽屉 */
|
||||
const authRoleRef = ref();
|
||||
const handleAuthRole = (record: any) => {
|
||||
authRoleRef.value.setData({ record });
|
||||
authRoleRef.value.open();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="菜单管理">
|
||||
<FormModal />
|
||||
<AuthRole ref="authRoleRef" />
|
||||
<Grid>
|
||||
<template #toolbar-actions>
|
||||
<TableAction
|
||||
@@ -137,6 +145,13 @@ const collapseAll = () => {
|
||||
// auth: ['admin', 'sys:role:detail'],
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '授权角色',
|
||||
type: 'link',
|
||||
icon: 'ant-design:team-outlined',
|
||||
size: 'small',
|
||||
onClick: handleAuthRole.bind(null, row),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
@@ -150,17 +165,6 @@ const collapseAll = () => {
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
// auth: ['admin', 'sys:role:detail'],
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -44,6 +44,25 @@ export async function saveRoleMenu(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}save-role-menu`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按菜单反查已授权的角色 ID(菜单→角色反向授权回显)
|
||||
*/
|
||||
export async function getRoleIdsByMenuId(menuId: number) {
|
||||
return requestClient.get<any>(`${prefix}get-role-ids-by-menu-id`, {
|
||||
params: { menu_id: menuId },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单反向授权:全量同步该菜单绑定的角色
|
||||
*/
|
||||
export async function saveMenuRoles(data: {
|
||||
menu_id: number;
|
||||
role_id: number[];
|
||||
}) {
|
||||
return requestClient.post<any>(`${prefix}save-menu-roles`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
* @param data
|
||||
@@ -68,6 +87,48 @@ export async function deleteRole(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}delete`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计无任何菜单绑定的角色
|
||||
*/
|
||||
export async function countEmptyMenuRoles() {
|
||||
return requestClient.get<any>(`${prefix}count-empty-menu-roles`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按模板角色为「空菜单」角色批量补全菜单
|
||||
*/
|
||||
export async function backfillEmptyMenuRoles(data: { source_role_id: number }) {
|
||||
return requestClient.post<any>(`${prefix}backfill-empty-role-menus`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计缺少管理员管理菜单的预设角色
|
||||
*/
|
||||
export async function countMissingAdminMenus() {
|
||||
return requestClient.get<any>(`${prefix}count-missing-admin-menus`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为预设管理员角色补全「管理员」菜单组
|
||||
*/
|
||||
export async function syncAdminManagementMenus() {
|
||||
return requestClient.post<any>(`${prefix}sync-admin-management-menus`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计缺少管理员管理入口的自定义角色
|
||||
*/
|
||||
export async function countMissingCustomAdminMenus() {
|
||||
return requestClient.get<any>(`${prefix}count-missing-custom-admin-menus`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为历史自定义角色批量补生成管理员管理入口
|
||||
*/
|
||||
export async function backfillCustomRoleAdminMenus() {
|
||||
return requestClient.post<any>(`${prefix}backfill-custom-role-admin-menus`);
|
||||
}
|
||||
|
||||
const workbenchPrefix = 'role-workbench-widget/';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,147 +1,52 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
|
||||
import { Button, message, Tree } from 'ant-design-vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
import { getAllNodeIds, getLeafNodeIds } from '#/util/tool';
|
||||
import { getMenuTreeOption } from '#/views/system/menu/api';
|
||||
import { saveRoleMenu } from '../api';
|
||||
import RoleMenuTree from './role-menu-tree.vue';
|
||||
|
||||
import { getMenuIdsByRoleIds, saveRoleMenu } from '../api';
|
||||
import {Icon} from "#/components/icon";
|
||||
const record = ref<any>({});
|
||||
const menuTreeRef = ref<InstanceType<typeof RoleMenuTree>>();
|
||||
|
||||
const record = ref();
|
||||
const treeRef = ref();
|
||||
const treeData = ref([]);
|
||||
const isExpand = ref(false);
|
||||
|
||||
// 计算标题:授权菜单 - 角色名称
|
||||
const drawerTitle = computed(() => {
|
||||
const roleName = record.value?.name || '';
|
||||
return roleName ? `授权菜单 - ${roleName}` : '授权菜单';
|
||||
});
|
||||
|
||||
// 勾选的key
|
||||
const checkedKeys = ref([]);
|
||||
// 提交的勾选的key,会进行特殊处理,包含半勾状态的父节点halfCheckedKeys
|
||||
const submitCheckedKeys = ref<any>([]);
|
||||
// 所有叶子节点key
|
||||
const leafKeys = ref<any>([]);
|
||||
// 所有节点key
|
||||
const allNodeIds = ref([]);
|
||||
// 当前展开的key
|
||||
const currentExpandedKeys = ref([]);
|
||||
/**
|
||||
* api请求成功回调
|
||||
*/
|
||||
const handleFetchSuccess = () => {
|
||||
getMenuIdsByRoleIds({
|
||||
id: record.value.id,
|
||||
// appCode: props.appCode,
|
||||
}).then((res: any) => {
|
||||
// 设置的勾选节点只能为叶子节点
|
||||
checkedKeys.value = res.filter((item: any) => {
|
||||
return leafKeys.value.includes(item);
|
||||
});
|
||||
submitCheckedKeys.value = res;
|
||||
});
|
||||
};
|
||||
const [Drawer, DrawerApi] = useVbenDrawer({
|
||||
onOpenChange(isOpen) {
|
||||
onOpenChange: async (isOpen) => {
|
||||
record.value = isOpen ? DrawerApi.getData()?.record : {};
|
||||
if (isOpen) {
|
||||
DrawerApi.setState({
|
||||
loading: true,
|
||||
});
|
||||
getMenuTreeOption({
|
||||
filterByUser: 1,
|
||||
})
|
||||
.then((res) => {
|
||||
treeData.value = res;
|
||||
leafKeys.value = getLeafNodeIds(res);
|
||||
allNodeIds.value = getAllNodeIds(res);
|
||||
handleFetchSuccess();
|
||||
})
|
||||
.finally(() => {
|
||||
DrawerApi.setState({
|
||||
loading: false,
|
||||
});
|
||||
});
|
||||
await nextTick();
|
||||
menuTreeRef.value?.reload();
|
||||
}
|
||||
},
|
||||
onConfirm() {
|
||||
const menus = submitCheckedKeys.value.map((item: any) => {
|
||||
return item;
|
||||
});
|
||||
DrawerApi.setState({
|
||||
loading: true,
|
||||
confirmLoading: true,
|
||||
});
|
||||
saveRoleMenu({
|
||||
role_id: record.value.id,
|
||||
menu_id: menus,
|
||||
})
|
||||
.then(() => {
|
||||
message.success('保存成功');
|
||||
DrawerApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
DrawerApi.setState({
|
||||
loading: false,
|
||||
confirmLoading: false,
|
||||
});
|
||||
onConfirm: async () => {
|
||||
const menus = menuTreeRef.value?.getSubmitMenuIds() || [];
|
||||
DrawerApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await saveRoleMenu({
|
||||
role_id: record.value.id,
|
||||
menu_id: menus,
|
||||
});
|
||||
message.success('保存成功');
|
||||
DrawerApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
DrawerApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
/**
|
||||
* 点击复选框触发处理
|
||||
* @param mCheckedKeys
|
||||
*/
|
||||
const handleCheck = (mCheckedKeys: any, e: any) => {
|
||||
checkedKeys.value = mCheckedKeys;
|
||||
// 提交的时候需要将半选的父节点也提交上
|
||||
submitCheckedKeys.value = [...mCheckedKeys, ...e.halfCheckedKeys];
|
||||
};
|
||||
// 展开折叠事件
|
||||
const handleExpand = (expandedKeys: any) => {
|
||||
currentExpandedKeys.value = expandedKeys;
|
||||
};
|
||||
// 展开折叠按钮事件
|
||||
const handleExpandAndCollapse = () => {
|
||||
isExpand.value = !isExpand.value;
|
||||
currentExpandedKeys.value = isExpand.value ? allNodeIds.value : [];
|
||||
};
|
||||
|
||||
defineExpose(DrawerApi);
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<Drawer class="w-[60%]" :title="drawerTitle">
|
||||
<Button type="primary" @click="handleExpandAndCollapse">
|
||||
{{ isExpand ? '折叠' : '展开' }}
|
||||
</Button>
|
||||
<Tree
|
||||
ref="treeRef"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
:expanded-keys="currentExpandedKeys"
|
||||
:field-names="{
|
||||
title: 'title',
|
||||
key: 'id',
|
||||
}"
|
||||
:show-line="true"
|
||||
:tree-data="treeData"
|
||||
checkable
|
||||
style="margin: 20px auto"
|
||||
@check="handleCheck"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
<template #title="{ title, icon }">
|
||||
<Icon :icon="icon" />
|
||||
{{ $t(title) }}
|
||||
</template>
|
||||
</Tree>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template>
|
||||
<Drawer class="w-[60%]" :title="drawerTitle">
|
||||
<RoleMenuTree ref="menuTreeRef" :role-id="record?.id" />
|
||||
</Drawer>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 补生成自定义角色的管理员管理入口:在「管理员」菜单组下创建管理页并授权超管/系统管理员
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
backfillCustomRoleAdminMenus,
|
||||
countMissingCustomAdminMenus,
|
||||
} from '../api';
|
||||
|
||||
const missingCount = ref(0);
|
||||
const missingRoleIds = ref<number[]>([]);
|
||||
const gridApi = ref();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
const res = await backfillCustomRoleAdminMenus();
|
||||
const created = res?.created_count ?? 0;
|
||||
if (created > 0) {
|
||||
message.success(
|
||||
`已为 ${created} 个自定义角色生成管理员管理入口(超管/系统管理员重新登录后可见)`,
|
||||
);
|
||||
} else {
|
||||
message.info('没有需要补生成的自定义角色');
|
||||
}
|
||||
gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
gridApi.value = modalApi.getData()?.gridApi;
|
||||
modalApi.setState({ loading: true });
|
||||
try {
|
||||
const res = await countMissingCustomAdminMenus();
|
||||
missingCount.value = res?.count ?? 0;
|
||||
missingRoleIds.value = res?.role_ids ?? [];
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose(modalApi);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[80%] md:w-[50%]" title="补生成管理员入口">
|
||||
<Alert
|
||||
class="mb-4"
|
||||
show-icon
|
||||
type="info"
|
||||
:message="
|
||||
missingCount > 0
|
||||
? `${missingCount} 个自定义角色缺少管理员管理入口`
|
||||
: '自定义角色的管理员管理入口已齐全'
|
||||
"
|
||||
:description="
|
||||
missingCount > 0
|
||||
? `待补生成角色 ID:${missingRoleIds.join('、')}(将在「管理员」下创建菜单,并授权超管/系统管理员)`
|
||||
: '可点击确定执行一次幂等检查'
|
||||
"
|
||||
/>
|
||||
<div class="text-sm text-[hsl(var(--muted-foreground))]">
|
||||
仅处理非预设自定义角色;每个角色会生成 path=/system/admin/role/{id}
|
||||
的管理页。预设角色(如诊所管理员)已有静态入口,不会重复创建。
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,105 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 补全空角色菜单弹窗:为从未绑定菜单的角色按模板角色批量写入菜单
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, message, Select } from 'ant-design-vue';
|
||||
|
||||
import { backfillEmptyMenuRoles, countEmptyMenuRoles, getRoleOption } from '../api';
|
||||
|
||||
const emptyCount = ref(0);
|
||||
const emptyRoleIds = ref<number[]>([]);
|
||||
const roleOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const sourceRoleId = ref<number>();
|
||||
const gridApi = ref();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
if (!sourceRoleId.value) {
|
||||
message.warning('请选择模板角色');
|
||||
return;
|
||||
}
|
||||
if (emptyCount.value <= 0) {
|
||||
message.info('暂无需要补全的角色');
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
const res = await backfillEmptyMenuRoles({
|
||||
source_role_id: sourceRoleId.value,
|
||||
});
|
||||
const filled = res?.filled_count ?? 0;
|
||||
message.success(`已成功为 ${filled} 个角色补全菜单`);
|
||||
gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
sourceRoleId.value = undefined;
|
||||
return;
|
||||
}
|
||||
gridApi.value = modalApi.getData()?.gridApi;
|
||||
modalApi.setState({ loading: true });
|
||||
try {
|
||||
const [countRes, options] = await Promise.all([
|
||||
countEmptyMenuRoles(),
|
||||
getRoleOption({}),
|
||||
]);
|
||||
emptyCount.value = countRes?.count ?? 0;
|
||||
emptyRoleIds.value = countRes?.role_ids ?? [];
|
||||
roleOptions.value = (options || []).map((item: any) => ({
|
||||
label: item.label || item.name,
|
||||
value: Number(item.value || item.id),
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose(modalApi);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[80%] md:w-[50%]" title="补全空角色菜单">
|
||||
<Alert
|
||||
class="mb-4"
|
||||
show-icon
|
||||
type="info"
|
||||
:message="`待补全 ${emptyCount} 个角色(无任何菜单绑定)`"
|
||||
:description="
|
||||
emptyCount > 0
|
||||
? `角色 ID:${emptyRoleIds.join('、')}`
|
||||
: '当前没有需要补全的角色'
|
||||
"
|
||||
/>
|
||||
<div class="mb-2 text-sm text-[hsl(var(--muted-foreground))]">
|
||||
仅针对「从未绑定过任何菜单」的角色;选择模板角色后复制其全部菜单。已有菜单的角色不会被覆盖。
|
||||
若需补全「管理员管理」菜单组,请使用「同步管理员菜单」。
|
||||
</div>
|
||||
<Select
|
||||
v-model:value="sourceRoleId"
|
||||
allow-clear
|
||||
class="w-full"
|
||||
placeholder="请选择模板角色"
|
||||
:options="roleOptions"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
/>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,96 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 角色列表内「添加管理员」弹窗:按当前行 role_id 动态切换表单 schema 后提交 createAdmin
|
||||
* 复用 admin/_shared 的表单与 payload,避免各角色字段分叉再写一套
|
||||
*/
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createAdmin } from '#/views/system/admin/api';
|
||||
import { normalizeAdminPayload } from '#/views/system/admin/_shared/admin-payload';
|
||||
import { createAdminModalFormProps } from '#/views/system/admin/_shared/form-schemas';
|
||||
import { getRoleMeta } from '#/views/system/admin/_shared/role-meta';
|
||||
|
||||
const DEFAULT_AVATAR =
|
||||
'https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/xk_upload_20251022/20251022104156946505ca86d97626c08882f31797dbcef49c.png';
|
||||
|
||||
/** 当前弹窗绑定的角色 ID(打开时写入,提交时带上) */
|
||||
const currentRoleId = ref(0);
|
||||
/** 当前角色表单类型,提交归一化用 */
|
||||
const currentFormType = ref(getRoleMeta(0).formType);
|
||||
|
||||
const [Form, formApi] = useVbenForm(
|
||||
createAdminModalFormProps(0, currentFormType.value),
|
||||
);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
const e = await formApi.validate();
|
||||
if (!e.valid) return;
|
||||
const roleId = currentRoleId.value;
|
||||
if (!roleId) {
|
||||
message.warning('角色无效');
|
||||
return;
|
||||
}
|
||||
const values = await formApi.getValues();
|
||||
const payload = normalizeAdminPayload(
|
||||
{ ...values, role_id: roleId },
|
||||
currentFormType.value,
|
||||
);
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await createAdmin(payload);
|
||||
message.success('添加管理员成功');
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
currentRoleId.value = 0;
|
||||
return;
|
||||
}
|
||||
const data = modalApi.getData<Record<string, any>>() ?? {};
|
||||
const roleId = Number(data.role_id || data.id || 0);
|
||||
const roleName = String(data.role_name || data.name || '');
|
||||
if (!roleId) {
|
||||
message.warning('角色无效');
|
||||
modalApi.close();
|
||||
return;
|
||||
}
|
||||
const meta = getRoleMeta(roleId);
|
||||
currentRoleId.value = roleId;
|
||||
currentFormType.value = meta.formType;
|
||||
modalApi.setState({
|
||||
title: `添加管理员 - ${roleName || meta.title}`,
|
||||
});
|
||||
// 按角色切换字段(省市区/供应商/诊所等),用 setState 整表替换 schema
|
||||
const formProps = createAdminModalFormProps(roleId, meta.formType);
|
||||
formApi.setState({ schema: formProps.schema });
|
||||
await nextTick();
|
||||
formApi.resetForm();
|
||||
formApi.setValues({
|
||||
role_id: roleId,
|
||||
avatar: DEFAULT_AVATAR,
|
||||
});
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[60%]">
|
||||
<Form />
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -1,21 +1,64 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
/**
|
||||
* 角色新建/编辑弹窗:新建可一并勾选菜单;编辑可同步修改菜单授权
|
||||
*/
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
import { Divider, message, Select } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createRole, updateRole } from '#/views/system/role/api';
|
||||
import {
|
||||
createRole,
|
||||
getMenuIdsByRoleIds,
|
||||
getRoleOption,
|
||||
saveRoleMenu,
|
||||
updateRole,
|
||||
} from '#/views/system/role/api';
|
||||
import { modalFormProps } from '#/views/system/role/config/form';
|
||||
|
||||
|
||||
import RoleMenuTree from './role-menu-tree.vue';
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const gridApi = ref();
|
||||
const menuTreeRef = ref<InstanceType<typeof RoleMenuTree>>();
|
||||
const copyFromRoleId = ref<number>();
|
||||
const roleOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const initialMenuIds = ref<number[]>([]);
|
||||
const currentRoleId = ref<number>();
|
||||
|
||||
const [Form, formApi] = useVbenForm(modalFormProps);
|
||||
|
||||
/** 判断菜单勾选是否相对回显有变更 */
|
||||
const isMenuChanged = (menuIds: number[]) => {
|
||||
const current = [...menuIds].map(Number).sort((a, b) => a - b);
|
||||
const initial = [...initialMenuIds.value].map(Number).sort((a, b) => a - b);
|
||||
if (current.length !== initial.length) {
|
||||
return true;
|
||||
}
|
||||
return current.some((id, index) => id !== initial[index]);
|
||||
};
|
||||
|
||||
/** 加载角色下拉(从角色复制) */
|
||||
const loadRoleOptions = async () => {
|
||||
const options = await getRoleOption({});
|
||||
roleOptions.value = (options || []).map((item: any) => ({
|
||||
label: item.label || item.name,
|
||||
value: Number(item.value || item.id),
|
||||
}));
|
||||
};
|
||||
|
||||
/** 编辑时记录初始菜单,用于判断是否需要 saveRoleMenu */
|
||||
const loadInitialMenus = async (roleId?: number) => {
|
||||
if (!roleId) {
|
||||
initialMenuIds.value = [];
|
||||
return;
|
||||
}
|
||||
const res = await getMenuIdsByRoleIds({ id: roleId });
|
||||
initialMenuIds.value = (res || []).map((item: number) => Number(item));
|
||||
};
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
@@ -26,12 +69,28 @@ const [Modal, modalApi] = useVbenModal({
|
||||
const e = await formApi.validate();
|
||||
if (!e.valid) return;
|
||||
const values = await formApi.getValues();
|
||||
const menuIds = menuTreeRef.value?.getSubmitMenuIds() || [];
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
const submitApi = isUpdate.value ? updateRole : createRole;
|
||||
try {
|
||||
await submitApi(values);
|
||||
message.success('保存成功');
|
||||
gridApi.value?.reload();
|
||||
if (isUpdate.value) {
|
||||
await updateRole(values);
|
||||
if (isMenuChanged(menuIds)) {
|
||||
await saveRoleMenu({
|
||||
role_id: values.id,
|
||||
menu_id: menuIds,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await createRole({
|
||||
...values,
|
||||
menu_id: menuIds,
|
||||
});
|
||||
message.success('创建成功,已自动生成管理员管理入口(超管/系统管理员重新登录后可见)');
|
||||
}
|
||||
if (isUpdate.value) {
|
||||
message.success('保存成功');
|
||||
}
|
||||
gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -39,20 +98,65 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
onOpenChange: async (isOpen: boolean) => {
|
||||
gridApi.value = isOpen ? modalApi.getData()?.gridApi : null;
|
||||
if (isOpen) {
|
||||
const { values, update } = modalApi.getData<Record<string, any>>();
|
||||
if (values) {
|
||||
isUpdate.value = update;
|
||||
formApi.setValues(values);
|
||||
if (!isOpen) {
|
||||
copyFromRoleId.value = undefined;
|
||||
currentRoleId.value = undefined;
|
||||
initialMenuIds.value = [];
|
||||
return;
|
||||
}
|
||||
const { values, update } = modalApi.getData<Record<string, any>>();
|
||||
isUpdate.value = !!update;
|
||||
copyFromRoleId.value = undefined;
|
||||
currentRoleId.value = values?.id ? Number(values.id) : undefined;
|
||||
if (values) {
|
||||
formApi.setValues(values);
|
||||
}
|
||||
modalApi.setState({ loading: true });
|
||||
try {
|
||||
await loadRoleOptions();
|
||||
if (isUpdate.value && currentRoleId.value) {
|
||||
await loadInitialMenus(currentRoleId.value);
|
||||
} else {
|
||||
initialMenuIds.value = [];
|
||||
}
|
||||
await nextTick();
|
||||
await menuTreeRef.value?.reload();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="`${isUpdate === true ? '编辑' : '新增'}角色`" class="w-[80%] md:w-[50%] lg:w-[30%] h-[60%]">
|
||||
<Modal
|
||||
:title="`${isUpdate === true ? '编辑' : '新增'}角色`"
|
||||
class="w-[90%] md:w-[70%] lg:w-[50%]"
|
||||
>
|
||||
<Form />
|
||||
<Divider orientation="left">授权菜单</Divider>
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<span class="shrink-0 text-sm text-[hsl(var(--muted-foreground))]">
|
||||
从角色复制
|
||||
</span>
|
||||
<Select
|
||||
v-model:value="copyFromRoleId"
|
||||
allow-clear
|
||||
class="flex-1"
|
||||
placeholder="选择模板角色预填菜单(可选)"
|
||||
:options="roleOptions"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
/>
|
||||
</div>
|
||||
<RoleMenuTree
|
||||
ref="menuTreeRef"
|
||||
:copy-from-role-id="copyFromRoleId"
|
||||
:role-id="isUpdate ? currentRoleId : undefined"
|
||||
/>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 角色菜单授权树(新建/编辑/授权抽屉复用)
|
||||
* 勾选叶子节点展示,提交时合并半选父节点
|
||||
*/
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Button, Spin, Tree } from 'ant-design-vue';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
import { Icon } from '#/components/icon';
|
||||
import { getAllNodeIds, getLeafNodeIds } from '#/util/tool';
|
||||
import { getMenuTreeOption } from '#/views/system/menu/api';
|
||||
|
||||
import { getMenuIdsByRoleIds } from '../api';
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前角色 ID,有则回显已授权菜单 */
|
||||
roleId?: number;
|
||||
/** 从模板角色复制菜单勾选 */
|
||||
copyFromRoleId?: number;
|
||||
}>();
|
||||
|
||||
const treeRef = ref();
|
||||
const treeData = ref<any[]>([]);
|
||||
const isExpand = ref(false);
|
||||
const loading = ref(false);
|
||||
const checkedKeys = ref<number[]>([]);
|
||||
const submitCheckedKeys = ref<number[]>([]);
|
||||
const leafKeys = ref<number[]>([]);
|
||||
const allNodeIds = ref<number[]>([]);
|
||||
const currentExpandedKeys = ref<number[]>([]);
|
||||
|
||||
/**
|
||||
* 按角色 ID 加载菜单勾选(叶子展示 + 提交含半选父节点)
|
||||
*/
|
||||
const loadMenuIdsByRole = async (roleId?: number) => {
|
||||
if (!roleId) {
|
||||
checkedKeys.value = [];
|
||||
submitCheckedKeys.value = [];
|
||||
return;
|
||||
}
|
||||
const res = await getMenuIdsByRoleIds({ id: roleId });
|
||||
const menuIds = (res || []).map((item: number) => Number(item));
|
||||
checkedKeys.value = menuIds.filter((item: number) => leafKeys.value.includes(item));
|
||||
submitCheckedKeys.value = menuIds;
|
||||
};
|
||||
|
||||
/**
|
||||
* 初始化菜单树数据
|
||||
*/
|
||||
const initTree = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await getMenuTreeOption({ filterByUser: 1 });
|
||||
treeData.value = res;
|
||||
leafKeys.value = getLeafNodeIds(res);
|
||||
allNodeIds.value = getAllNodeIds(res);
|
||||
const sourceRoleId = props.copyFromRoleId || props.roleId;
|
||||
await loadMenuIdsByRole(sourceRoleId);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [props.roleId, props.copyFromRoleId] as const,
|
||||
async () => {
|
||||
if (!treeData.value.length) {
|
||||
return;
|
||||
}
|
||||
const sourceRoleId = props.copyFromRoleId || props.roleId;
|
||||
await loadMenuIdsByRole(sourceRoleId);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 勾选变化:提交需包含半选父节点
|
||||
*/
|
||||
const handleCheck = (mCheckedKeys: number[], e: { halfCheckedKeys?: number[] }) => {
|
||||
checkedKeys.value = mCheckedKeys;
|
||||
submitCheckedKeys.value = [...mCheckedKeys, ...(e.halfCheckedKeys || [])];
|
||||
};
|
||||
|
||||
const handleExpand = (expandedKeys: number[]) => {
|
||||
currentExpandedKeys.value = expandedKeys;
|
||||
};
|
||||
|
||||
const handleExpandAndCollapse = () => {
|
||||
isExpand.value = !isExpand.value;
|
||||
currentExpandedKeys.value = isExpand.value ? allNodeIds.value : [];
|
||||
};
|
||||
|
||||
/** 对外暴露:获取待提交的 menu_id 列表 */
|
||||
const getSubmitMenuIds = () => {
|
||||
return [...submitCheckedKeys.value];
|
||||
};
|
||||
|
||||
/** 对外暴露:重新加载树与勾选 */
|
||||
const reload = async () => {
|
||||
await initTree();
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
getSubmitMenuIds,
|
||||
reload,
|
||||
});
|
||||
|
||||
initTree();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Spin :spinning="loading">
|
||||
<div class="role-menu-tree">
|
||||
<Button type="primary" size="small" @click="handleExpandAndCollapse">
|
||||
{{ isExpand ? '折叠' : '展开' }}
|
||||
</Button>
|
||||
<Tree
|
||||
ref="treeRef"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
:expanded-keys="currentExpandedKeys"
|
||||
:field-names="{
|
||||
title: 'title',
|
||||
key: 'id',
|
||||
}"
|
||||
:show-line="true"
|
||||
:tree-data="treeData"
|
||||
checkable
|
||||
class="role-menu-tree__tree"
|
||||
@check="handleCheck"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
<template #title="{ title, icon }">
|
||||
<Icon :icon="icon" />
|
||||
{{ $t(title) }}
|
||||
</template>
|
||||
</Tree>
|
||||
</div>
|
||||
</Spin>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.role-menu-tree__tree {
|
||||
margin: 12px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 同步管理员管理菜单:为预设管理员角色补全「管理员」菜单组(73 + 对应子页)
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, message } from 'ant-design-vue';
|
||||
|
||||
import { countMissingAdminMenus, syncAdminManagementMenus } from '../api';
|
||||
|
||||
const missingCount = ref(0);
|
||||
const missingRoleIds = ref<number[]>([]);
|
||||
const gridApi = ref();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
const res = await syncAdminManagementMenus();
|
||||
const synced = res?.synced_count ?? 0;
|
||||
if (synced > 0) {
|
||||
message.success(`已为 ${synced} 个角色补全管理员管理菜单(含父级菜单链)`);
|
||||
} else {
|
||||
message.info('未发现需要补全的管理员菜单');
|
||||
}
|
||||
gridApi.value?.reload?.();
|
||||
modalApi.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
gridApi.value = modalApi.getData()?.gridApi;
|
||||
modalApi.setState({ loading: true });
|
||||
try {
|
||||
const res = await countMissingAdminMenus();
|
||||
missingCount.value = res?.count ?? 0;
|
||||
missingRoleIds.value = res?.role_ids ?? [];
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
modalApi.setState({ loading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose(modalApi);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[80%] md:w-[50%]" title="同步管理员管理菜单">
|
||||
<Alert
|
||||
class="mb-4"
|
||||
show-icon
|
||||
type="info"
|
||||
:message="
|
||||
missingCount > 0
|
||||
? `${missingCount} 个预设管理员角色缺少「管理员」菜单组`
|
||||
: '各预设管理员角色的「管理员」菜单已齐全'
|
||||
"
|
||||
:description="
|
||||
missingCount > 0
|
||||
? `待补全角色 ID:${missingRoleIds.join('、')}(将追加菜单 4→21→73 及对应子页)`
|
||||
: '可点击确定执行一次幂等检查;若侧栏仍无「管理员」菜单,请让对应账号重新登录'
|
||||
"
|
||||
/>
|
||||
<div class="text-sm text-[hsl(var(--muted-foreground))]">
|
||||
自动为可识别的管理员角色补全「基础管理 → RBAC管理 → 管理员 → 子页」整条菜单链。
|
||||
预设角色按 ID 匹配;自定义角色按角色代码(value)与菜单路径匹配。仅追加缺失项。
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -30,7 +30,8 @@ export const gridOptions: VxeGridProps<RowType> = {
|
||||
columns: [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 100 },
|
||||
{ field: 'name', align: 'left', title: '名称' },
|
||||
// 名称可点,打开授权菜单抽屉(与操作列「授权菜单」同入口)
|
||||
{ field: 'name', align: 'left', title: '名称', slots: { default: 'name' } },
|
||||
{ field: 'value', title: '角色代码' },
|
||||
{ field: 'desc', title: '备注' },
|
||||
{ field: 'created_at', title: '创建时间' },
|
||||
|
||||
@@ -8,16 +8,21 @@ import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Button, Image, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { Icon } from '#/components/icon';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
|
||||
import { deleteRole } from './api';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
import BackfillMenuModal from './components/backfill-menu-modal.vue';
|
||||
import SyncAdminMenuModalDemo from './components/sync-admin-menu-modal.vue';
|
||||
import BackfillCustomAdminMenuModalDemo from './components/backfill-custom-admin-menu-modal.vue';
|
||||
import CreateAdminModalDemo from './components/create-admin-modal.vue';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
import AuthMenu from "#/views/system/role/components/auth-menu.vue";
|
||||
import MpEntry from "#/views/system/role/components/mp-entry.vue";
|
||||
import QuickNav from "#/views/system/role/components/quick-nav.vue";
|
||||
import WorkbenchWidget from "#/views/system/role/components/workbench-widget.vue";
|
||||
import AuthMenu from '#/views/system/role/components/auth-menu.vue';
|
||||
import MpEntry from '#/views/system/role/components/mp-entry.vue';
|
||||
import QuickNav from '#/views/system/role/components/quick-nav.vue';
|
||||
import WorkbenchWidget from '#/views/system/role/components/workbench-widget.vue';
|
||||
|
||||
// 支持配置小程序工作台入口的角色(1/2平台 3/4/6业务员线 8诊所管理员 14诊所推广员)
|
||||
const MP_ENTRY_ROLE_IDS = [1, 2, 3, 4, 6, 8, 14];
|
||||
@@ -47,6 +52,39 @@ const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: FormModalDemo,
|
||||
});
|
||||
|
||||
const [BackfillModal, backfillModalApi] = useVbenModal({
|
||||
connectedComponent: BackfillMenuModal,
|
||||
});
|
||||
|
||||
const [SyncAdminMenuModal, syncAdminMenuModalApi] = useVbenModal({
|
||||
connectedComponent: SyncAdminMenuModalDemo,
|
||||
});
|
||||
|
||||
const [BackfillCustomAdminMenuModal, backfillCustomAdminMenuModalApi] =
|
||||
useVbenModal({
|
||||
connectedComponent: BackfillCustomAdminMenuModalDemo,
|
||||
});
|
||||
|
||||
/** 角色列表内直接新增该角色管理员(不跳转管理员页) */
|
||||
const [CreateAdminModal, createAdminModalApi] = useVbenModal({
|
||||
connectedComponent: CreateAdminModalDemo,
|
||||
});
|
||||
|
||||
const showBackfillModal = () => {
|
||||
backfillModalApi.setData({ gridApi });
|
||||
backfillModalApi.open();
|
||||
};
|
||||
|
||||
const showSyncAdminMenuModal = () => {
|
||||
syncAdminMenuModalApi.setData({ gridApi });
|
||||
syncAdminMenuModalApi.open();
|
||||
};
|
||||
|
||||
const showBackfillCustomAdminMenuModal = () => {
|
||||
backfillCustomAdminMenuModalApi.setData({ gridApi });
|
||||
backfillCustomAdminMenuModalApi.open();
|
||||
};
|
||||
|
||||
const showModal = (data = {}, isUpdate = false) => {
|
||||
formModalApi.setData({
|
||||
// 表单值
|
||||
@@ -63,7 +101,7 @@ const showModal = (data = {}, isUpdate = false) => {
|
||||
formModalApi.open();
|
||||
};
|
||||
|
||||
// 授权菜单
|
||||
// 授权菜单(操作列 / 点击角色名称共用)
|
||||
const authMenuRef = ref();
|
||||
const handleAuthMenu = (record: any) => {
|
||||
authMenuRef.value.setData({
|
||||
@@ -72,6 +110,23 @@ const handleAuthMenu = (record: any) => {
|
||||
authMenuRef.value.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开「添加管理员」弹窗,role_id 固定为当前行角色
|
||||
* 表单字段按该角色 formType 动态切换(复用 admin/_shared)
|
||||
*/
|
||||
const openCreateAdminModal = (record: any) => {
|
||||
const roleId = Number(record?.id || 0);
|
||||
if (!roleId) {
|
||||
message.warning('角色无效');
|
||||
return;
|
||||
}
|
||||
createAdminModalApi.setData({
|
||||
role_id: roleId,
|
||||
role_name: record?.name,
|
||||
});
|
||||
createAdminModalApi.open();
|
||||
};
|
||||
|
||||
// 快捷导航
|
||||
const quickNavRef = ref();
|
||||
const handleQuickNav = (record: any) => {
|
||||
@@ -121,6 +176,10 @@ const deleteApi = (row: any) => {
|
||||
<template>
|
||||
<Page auto-content-height title="角色管理">
|
||||
<FormModal />
|
||||
<BackfillModal />
|
||||
<SyncAdminMenuModal />
|
||||
<BackfillCustomAdminMenuModal />
|
||||
<CreateAdminModal />
|
||||
<AuthMenu ref="authMenuRef" />
|
||||
<QuickNav ref="quickNavRef" />
|
||||
<WorkbenchWidget ref="workbenchWidgetRef" />
|
||||
@@ -136,6 +195,24 @@ const deleteApi = (row: any) => {
|
||||
// auth: ['超级角色', 'sys:user:save'],
|
||||
onClick: showModal.bind(null),
|
||||
},
|
||||
{
|
||||
label: '补全空角色菜单',
|
||||
type: 'default',
|
||||
icon: 'ant-design:menu-unfold-outlined',
|
||||
onClick: showBackfillModal,
|
||||
},
|
||||
{
|
||||
label: '同步管理员菜单',
|
||||
type: 'default',
|
||||
icon: 'grommet-icons:user-admin',
|
||||
onClick: showSyncAdminMenuModal,
|
||||
},
|
||||
{
|
||||
label: '补生成管理员入口',
|
||||
type: 'default',
|
||||
icon: 'ant-design:appstore-add-outlined',
|
||||
onClick: showBackfillCustomAdminMenuModal,
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
@@ -161,6 +238,12 @@ const deleteApi = (row: any) => {
|
||||
<template #avatar="{ row }">
|
||||
<Image :src="row.avatar" height="30" width="30" />
|
||||
</template>
|
||||
<!-- 点击角色名称打开授权菜单 -->
|
||||
<template #name="{ row }">
|
||||
<Button type="link" class="!px-0" @click="handleAuthMenu(row)">
|
||||
{{ row.name }}
|
||||
</Button>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
@@ -181,6 +264,13 @@ const deleteApi = (row: any) => {
|
||||
// auth: ['admin', 'sys:role:detail'],
|
||||
onClick: handleAuthMenu.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '添加管理员',
|
||||
type: 'link',
|
||||
icon: 'ant-design:user-add-outlined',
|
||||
size: 'small',
|
||||
onClick: openCreateAdminModal.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '快捷导航',
|
||||
type: 'link',
|
||||
|
||||
@@ -108,6 +108,39 @@ export async function getStoreCardStatsApi(params: {
|
||||
return requestClient.get<any>(`${prefix}card-stats`, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店资金账户余额(仅超管/系统管理员)
|
||||
*/
|
||||
export async function getStoreBalanceApi(params: { id: number }) {
|
||||
return requestClient.get<any>(`${prefix}store-balance`, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店资金流水列表(仅超管/系统管理员)
|
||||
*/
|
||||
export async function getStoreFundWaterListApi(params: {
|
||||
id: number;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
search_time?: [string, string];
|
||||
}) {
|
||||
return requestClient.get<any>(`${prefix}store-fund-water-list`, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店账户变动列表(仅超管/系统管理员)
|
||||
*/
|
||||
export async function getStoreAccountChangeLogListApi(params: {
|
||||
id: number;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
search_time?: [string, string];
|
||||
}) {
|
||||
return requestClient.get<any>(`${prefix}store-account-change-log-list`, {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增诊所
|
||||
* @param data
|
||||
|
||||
@@ -25,6 +25,8 @@ defineOptions({ name: 'PublicAccountPayConfigPanel' });
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const billMode = ref<'order' | 'daily'>('order');
|
||||
/** immediate=发方后自动走公账;doctor_confirm=须医生手动申请 */
|
||||
const payTrigger = ref<'immediate' | 'doctor_confirm'>('immediate');
|
||||
const generateTime = ref<Dayjs>(dayjs('22:00', 'HH:mm'));
|
||||
const lockTime = ref<Dayjs>(dayjs('09:00', 'HH:mm'));
|
||||
/** 账单日起算满 N 天后锁店,默认 1=次日 */
|
||||
@@ -65,6 +67,9 @@ async function load() {
|
||||
if (row.config_key === 'public_account_bill_mode') {
|
||||
billMode.value = row.config_value === 'daily' ? 'daily' : 'order';
|
||||
}
|
||||
if (row.config_key === 'public_account_pay_trigger') {
|
||||
payTrigger.value = row.config_value === 'doctor_confirm' ? 'doctor_confirm' : 'immediate';
|
||||
}
|
||||
if (row.config_key === 'public_account_daily_generate_time') {
|
||||
generateTime.value = parseHm(row.config_value, '22:00');
|
||||
}
|
||||
@@ -201,6 +206,14 @@ async function handleSave() {
|
||||
config_group: 'public_account_pay',
|
||||
value_type: 'string',
|
||||
},
|
||||
{
|
||||
config_key: 'public_account_pay_trigger',
|
||||
config_value: payTrigger.value,
|
||||
config_group: 'public_account_pay',
|
||||
value_type: 'string',
|
||||
description: '公账支付触发时机:immediate=发方后自动走公账,doctor_confirm=须医生点申请',
|
||||
sort: 401,
|
||||
},
|
||||
{
|
||||
config_key: 'public_account_daily_generate_time',
|
||||
config_value: generateTime.value.format('HH:mm'),
|
||||
@@ -286,6 +299,16 @@ onMounted(() => {
|
||||
<Radio value="daily">按天先用后付(到点出日汇总)</Radio>
|
||||
</Radio.Group>
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<div class="mb-2 font-medium text-[hsl(var(--foreground))]">支付时机</div>
|
||||
<Radio.Group v-model:value="payTrigger">
|
||||
<Radio value="immediate">立即支付(发方后自动走公账)</Radio>
|
||||
<Radio value="doctor_confirm">医生确认后再支付</Radio>
|
||||
</Radio.Group>
|
||||
<div class="mt-1 text-xs text-[hsl(var(--muted-foreground))]">
|
||||
与出账模式无关:立即支付时诊所已开通则发方后自动申请公账;医生确认时须手动点「申请公账支付」
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="isDaily">
|
||||
<div class="mb-6">
|
||||
<div class="mb-2 font-medium text-[hsl(var(--foreground))]">日汇总生成时刻</div>
|
||||
|
||||
Reference in New Issue
Block a user