feat: 完成采购,视频分析模块

This commit is contained in:
fyy
2025-07-27 17:42:43 +08:00
parent 08b738f0f4
commit 3d7ddf3ed8
45 changed files with 5349 additions and 166 deletions

View File

@@ -0,0 +1,59 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'libName',
label: '库名称',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '人员库编码',
field: 'id',
},
{
title: '人员库名称',
field: 'libName',
},
{
title: '人员库描述',
field: 'libDesc',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '库名称',
fieldName: 'libName',
component: 'Input',
rules: 'required',
},
{
label: '描述',
fieldName: 'libDesc',
component: 'Input',
},
];

View File

@@ -0,0 +1,198 @@
<script setup lang="ts">
import type { VbenFormProps } from '@vben/common-ui';
import { Page, useVbenModal } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
import type { PersonLibForm } from '#/api/sis/personLib/model';
import { getVxePopupContainer } from '@vben/utils';
import { Modal, Popconfirm, Space, Tag } from 'ant-design-vue';
import {
personLibExport,
personLibList,
personLibRemove,
} from '#/api/sis/personLib';
import { commonDownloadExcel } from '#/utils/file/download';
import { columns, querySchema } from './data';
import personLibModal from './personLib-modal.vue';
import libAuthModal from '#/views/sis/personLib/libAuth-modal.vue';
const formOptions: VbenFormProps = {
commonConfig: {
labelWidth: 80,
componentProps: {
allowClear: true,
},
},
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
// 处理区间选择器RangePicker时间格式 将一个字段映射为两个字段 搜索/导出会用到
// 不需要直接删除
// fieldMappingTime: [
// [
// 'createTime',
// ['params[beginTime]', 'params[endTime]'],
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
// ],
// ],
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
// trigger: 'row',
},
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await personLibList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'sis-personLib-index',
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [PersonLibModal, modalApi] = useVbenModal({
connectedComponent: personLibModal,
});
const [LibAuthModal, libAuthModalApi] = useVbenModal({
connectedComponent: libAuthModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<PersonLibForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleDelete(row: Required<PersonLibForm>) {
await personLibRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<PersonLibForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await personLibRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(
personLibExport,
'人像库数据',
tableApi.formApi.form.values,
{
fieldMappingTime: formOptions.fieldMappingTime,
},
);
}
function handleAuth(row: Required<PersonLibForm>) {
libAuthModalApi.setData({ id: row.id });
libAuthModalApi.open();
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="人像库列表">
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['sis:personLib:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['sis:personLib:remove']"
@click="handleMultiDelete"
>
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['sis:personLib:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button @click.stop="handleAuth(row)"> 授权</ghost-button>
<ghost-button
v-access:code="['sis:personLib:edit']"
@click.stop="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</ghost-button>
<Popconfirm
:get-popup-container="getVxePopupContainer"
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<ghost-button
danger
v-access:code="['sis:personLib:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
<template #libType="{ row }">
<Tag v-if="row.libType == 1" color="#108ee9">人脸库</Tag>
<Tag v-else color="#2db7f5">工服库</Tag>
</template>
</BasicTable>
<PersonLibModal @reload="tableApi.query()" />
<LibAuthModal @reload="tableApi.query()" />
</Page>
</template>

View File

@@ -0,0 +1,159 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { useBeforeCloseDiff } from '#/utils/popup';
import { message, Tree } from 'ant-design-vue';
import {
authRecordAdd,
queryAuthDevice,
queryTree,
} from '#/api/sis/authRecord';
const emit = defineEmits<{ reload: [] }>();
const title = ref('门禁授权');
const { onBeforeClose } = useBeforeCloseDiff({});
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[700px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (isOpen) {
const { id } = modalApi.getData();
queryAuthDevice(id).then((res = []) => {
const arr: any[] = [];
res.forEach((item) => {
arr.push(item.deviceId);
checkedKeys.value = arr;
});
});
} else {
// 关闭时清除选中
checkedKeys.value = [];
}
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { id } = modalApi.getData();
if (eleIds.value.length === 0 && acIds.value.length === 0) {
message.error('请选择授权设备');
return;
}
// if (eleIds.value.length !== 0 && eleIds.value.length === 0) {
// message.error('请选择授权设备')
// return
// }
if (eleIds.value.length !== 0 && floorIds.value.length === 0) {
message.error('存在电梯未选中授权楼层,请选择!');
return;
}
const params = {
libId: id,
deviceIds: [acIds.value, eleIds.value, floorIds.value],
};
authRecordAdd(params);
// console.log(params)
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
function handleClosed() {
// await formApi.resetForm();
// resetInitialized();
}
const checkedKeys = ref<any[]>([]);
const treeData = ref([]);
const fieldNames = {
title: 'title',
label: 'label',
key: 'code',
children: 'children',
};
onMounted(() => {
loadDeviceTree();
});
function loadDeviceTree() {
queryTree().then((data: any) => {
treeData.value = data;
});
}
type Key = string | number;
const eleIds = ref<any[]>([]);
const acIds = ref<any[]>([]);
const floorIds = ref<any[]>([]);
function handleCheck(
checked: Key[] | { checked: Key[]; halfChecked: Key[] },
info: any,
) {
if (info.checked) {
switch (info.node.label) {
case 'floor':
const floorArr: any[] = [info.node.code];
floorIds.value = floorIds.value.concat(floorArr);
break;
case 'accessControl':
const acArr: any[] = [info.node.code];
acIds.value = acIds.value.concat(acArr);
break;
case 'elevator':
const eleArr: any[] = [info.node.code];
eleIds.value = eleIds.value.concat(eleArr);
break;
}
} else {
switch (info.node.label) {
case 'floor':
floorIds.value = floorIds.value.filter(
(item) => item !== info.node.code,
);
break;
case 'accessControl':
acIds.value = acIds.value.filter((item) => item !== info.node.code);
break;
case 'elevator':
eleIds.value = eleIds.value.filter((item) => item !== info.node.code);
break;
}
}
console.log('floorIds', floorIds.value);
console.log('acIds', acIds.value);
console.log('eleIds', eleIds.value);
// checkData.handlfChecked = [0, 1, 2]
// checkedKeys.value = { checked: checkData.checked, halfChecked: checkData.handlfChecked }
// console.log("checked---", checked)
// console.log("halfChecked---", info)
}
</script>
<template>
<BasicModal :title="title">
<div class="p-4">
<Tree
checkable
checkStrictly
:tree-data="treeData"
:fieldNames="fieldNames"
v-model:checkedKeys="checkedKeys"
:onCheck="handleCheck"
>
</Tree>
</div>
</BasicModal>
</template>

View File

@@ -0,0 +1,104 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import {
personLibAdd,
personLibInfo,
personLibUpdate,
} from '#/api/sis/personLib';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } from './data';
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满两列
formItemClass: 'col-span-2',
// 默认label宽度 px
labelWidth: 80,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
},
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[550px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await personLibInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? personLibUpdate(data) : personLibAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>

View File

@@ -0,0 +1,175 @@
import { type FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';
import { getDictOptions } from '#/utils/dict';
import { personLibList } from '#/api/sis/personLib';
import type { PersonLibQuery, PersonLibVO } from '#/api/sis/personLib/model';
let libArr: PersonLibVO[] = [];
export const querySchema: FormSchemaGetter = () => [
{
label: '图片库',
fieldName: 'libId',
component: 'ApiSelect',
componentProps: {
resultField: 'list', // 根据API返回结构调整
labelField: 'libName',
valueField: 'id',
// immediate: true,
api: async () => {
if (!libArr || libArr.length == 0) {
const params: PersonLibQuery = {
pageNum: 1,
pageSize: 500,
};
const res = await personLibList(params);
libArr = res.rows;
}
return libArr;
},
},
},
{
component: 'Input',
fieldName: 'imgName',
label: '人像名称',
},
{
component: 'Select',
componentProps: {
getPopupContainer,
options: getDictOptions(DictEnum.SYS_USER_SEX),
},
fieldName: 'sex',
label: '性别',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
/* {
title: '人员库编码',
field: 'libCode',
},*/
{
title: '人像名称',
field: 'imgName',
},
{
title: '性别',
field: 'sex',
},
{
title: '邮箱',
field: 'email',
},
{
title: '联系方式',
field: 'tel',
},
{
title: '证件类型',
field: 'certificateType',
},
{
title: '证件号码',
field: 'certificateNo',
},
{
title: '出生日期',
field: 'birthDate',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '图片库',
fieldName: 'libIds',
component: 'ApiSelect',
rules: 'required',
componentProps: {
resultField: 'list', // 根据API返回结构调整
labelField: 'libName',
valueField: 'id',
mode: 'multiple',
// immediate: true,
api: async () => {
if (!libArr || libArr.length == 0) {
const params: PersonLibQuery = {
pageNum: 1,
pageSize: 500,
};
const res = await personLibList(params);
libArr = res.rows;
}
return libArr;
},
},
},
{
label: '人像名称',
fieldName: 'imgName',
component: 'Input',
rules: 'required',
},
{
label: '性别',
fieldName: 'sex',
component: 'Select',
componentProps: {
getPopupContainer,
options: getDictOptions(DictEnum.SYS_USER_SEX),
},
},
{
label: '邮箱',
fieldName: 'email',
component: 'Input',
},
{
label: '联系方式',
fieldName: 'tel',
component: 'Input',
},
{
label: '证件类型',
fieldName: 'certificateType',
component: 'Select',
componentProps: {
getPopupContainer,
options: getDictOptions(DictEnum.SYS_CERTIFICATE_TYPE),
},
},
{
label: '证件号码',
fieldName: 'certificateNo',
component: 'Input',
},
{
label: '出生日期',
fieldName: 'birthDate',
component: 'Input',
},
{
label: '人像图片',
fieldName: 'imgOssId',
component: 'ImageUpload',
componentProps: {
// accept: 'image/*', // 可选拓展名或者mime类型 ,拼接
maxCount: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
},
formItemClass: 'col-span-2',
},
];

View File

@@ -0,0 +1,156 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { useBeforeCloseDiff } from '#/utils/popup';
import { Switch, Transfer, Tree } from 'ant-design-vue';
import { queryTree } from '#/api/sis/accessControl';
import { authRecordAdd } from '#/api/sis/authRecord';
import type { TreeNode } from '#/api/common';
import type { AuthRecordForm } from '#/api/sis/authRecord/model';
const emit = defineEmits<{ reload: [] }>();
const title = ref('门禁授权');
const { onBeforeClose } = useBeforeCloseDiff({});
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[700px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
checked.value = false;
targetKeys.value = []
}
}
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { ids, libId } = modalApi.getData() as {
ids?: number[] | string[];
libId: number | string;
};
const params: AuthRecordForm = {
libId,
imgIds: ids,
acIds: targetKeys.value,
issue: checked.value
};
const res = await authRecordAdd(params);
console.log(res);
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
// await formApi.resetForm();
// resetInitialized();
}
const checked = ref(false);
const targetKeys = ref<string[]>([]);
const dataSource = ref<TreeNode[]>([]);
const treeData = ref<any[]>([]);
onMounted(() => {
queryAcTree();
});
function handleTreeData(treeData: TreeNode[] | any[], datasource: TreeNode[]) {
treeData.forEach((item) => {
item.title = item.label;
item.key = item.code;
// 如果不是门禁,则
if (item.level != 5) {
item.disabled = true;
}
datasource.push(item);
if (item.children) {
handleTreeData(item.children, datasource);
}
});
}
function queryAcTree() {
queryTree().then((res = []) => {
const datasource: TreeNode[] = [];
handleTreeData(res, datasource);
dataSource.value = datasource;
treeData.value = res;
});
}
const onChecked = (
e: any,
checkedKeys: string[],
onItemSelect: (n: any, c: boolean) => void,
) => {
const { eventKey } = e.node;
onItemSelect(eventKey, !isChecked(checkedKeys, eventKey));
};
function isChecked(
selectedKeys: (string | number)[],
eventKey: string | number,
) {
return selectedKeys.indexOf(eventKey) !== -1;
}
</script>
<template>
<BasicModal :title="title">
<div class="p-4">
<span>AI盒子授权: </span>
<Switch v-model:checked="checked" />
</div>
<div class="p-4">
<Transfer
v-model:target-keys="targetKeys"
class="tree-transfer h-[400px] overflow-auto"
:data-source="dataSource"
:render="(item) => item.title"
>
<template #children="{ direction, selectedKeys, onItemSelect }">
<Tree
v-if="direction === 'left'"
block-node
checkable
check-strictly
:show-line="true"
default-expand-all
:checked-keys="[...selectedKeys, ...targetKeys]"
:tree-data="treeData"
@check="
(_, props) => {
onChecked(
props,
[...selectedKeys, ...targetKeys],
onItemSelect,
);
}
"
@select="
(_, props) => {
onChecked(
props,
[...selectedKeys, ...targetKeys],
onItemSelect,
);
}
"
/>
</template>
</Transfer>
</div>
</BasicModal>
</template>

View File

@@ -0,0 +1,205 @@
<script setup lang="ts">
import type { VbenFormProps } from '@vben/common-ui';
import { Page, useVbenModal } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
import type { PersonLibImgForm } from '#/api/sis/personLibImg/model';
import { getVxePopupContainer } from '@vben/utils';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import {
personLibImgExport,
personLibImgList,
personLibImgRemove,
} from '#/api/sis/personLibImg';
import { commonDownloadExcel } from '#/utils/file/download';
import { columns, querySchema } from './data';
import personLibImgModal from './personLibImg-modal.vue';
import imgAuthModal from './imgAuth-modal.vue';
const formOptions: VbenFormProps = {
commonConfig: {
labelWidth: 80,
componentProps: {
allowClear: true,
},
},
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
// 处理区间选择器RangePicker时间格式 将一个字段映射为两个字段 搜索/导出会用到
// 不需要直接删除
// fieldMappingTime: [
// [
// 'createTime',
// ['params[beginTime]', 'params[endTime]'],
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
// ],
// ],
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
// trigger: 'row',
},
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await personLibImgList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'system-personLibImg-index',
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [PersonLibImgModal, modalApi] = useVbenModal({
connectedComponent: personLibImgModal,
});
const [ImgAuthModal, authModalApi] = useVbenModal({
connectedComponent: imgAuthModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<PersonLibImgForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleDelete(row: Required<PersonLibImgForm>) {
await personLibImgRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<PersonLibImgForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await personLibImgRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(
personLibImgExport,
'人像信息数据',
tableApi.formApi.form.values,
{
fieldMappingTime: formOptions.fieldMappingTime,
},
);
}
/**
* 对图像进行门禁授权
*/
function accessControlAuth() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<PersonLibImgForm>) => row.id);
authModalApi.setData({ ids, libId: rows[0].libId });
authModalApi.open();
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="人像信息列表">
<template #toolbar-tools>
<Space>
<!-- <a-button
type="primary"
:disabled="!vxeCheckboxChecked(tableApi)"
v-access:code="['system:personLibImg:add']"
@click="accessControlAuth"
>
门禁授权
</a-button> -->
<a-button
v-access:code="['system:personLibImg:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['system:personLibImg:remove']"
@click="handleMultiDelete"
>
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['system:personLibImg:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['system:personLibImg:edit']"
@click.stop="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</ghost-button>
<Popconfirm
:get-popup-container="getVxePopupContainer"
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<ghost-button
danger
v-access:code="['system:personLibImg:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<PersonLibImgModal @reload="tableApi.query()" />
<ImgAuthModal @reload="tableApi.query()" />
</Page>
</template>

View File

@@ -0,0 +1,105 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import {
personLibImgAdd,
personLibImgInfo,
personLibImgUpdate,
} from '#/api/sis/personLibImg';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } from './data';
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满两列
formItemClass: 'col-span-1',
// 默认label宽度 px
labelWidth: 100,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
allowClear: true,
},
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[700px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await personLibImgInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? personLibImgUpdate(data) : personLibImgAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>