|
|
@@ -1,9 +1,10 @@
|
|
|
import * as api from './api';
|
|
|
import { dict, useCompute, PageQuery, AddReq, DelReq, EditReq, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
|
|
|
import tableSelector from '/@/components/tableSelector/index.vue';
|
|
|
-import { shallowRef, computed } from 'vue';
|
|
|
+import { shallowRef, computed, ref } from 'vue';
|
|
|
import manyToMany from '/@/components/manyToMany/index.vue';
|
|
|
import { auth } from '/@/utils/authFunction';
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
const { compute } = useCompute();
|
|
|
|
|
|
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
|
|
@@ -34,6 +35,56 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|
|
return tabActivted.value === 'receive';
|
|
|
});
|
|
|
|
|
|
+ // 选中行的状态管理
|
|
|
+ const selectedIds = ref<any[]>([]);
|
|
|
+
|
|
|
+ // 选择变化处理
|
|
|
+ const onSelectionChange = (changed: any[]) => {
|
|
|
+ console.log("selection", changed);
|
|
|
+ selectedIds.value = changed.map((item: any) => item.id);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 将selectedIds暴露给crudExpose
|
|
|
+ (crudExpose as any).selectedIds = selectedIds;
|
|
|
+
|
|
|
+ // 批量已读功能
|
|
|
+ const handleBatchRead = async () => {
|
|
|
+ try {
|
|
|
+ if (selectedIds.value.length === 0) {
|
|
|
+ ElMessage.warning('请先选择要标记为已读的消息');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确认对话框
|
|
|
+ await ElMessageBox.confirm(
|
|
|
+ `确定要将选中的 ${selectedIds.value.length} 条消息标记为已读吗?`,
|
|
|
+ '批量已读确认',
|
|
|
+ {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ // 调用批量已读API
|
|
|
+ await api.MarkMessagesRead(selectedIds.value);
|
|
|
+
|
|
|
+ ElMessage.success('批量已读操作成功');
|
|
|
+
|
|
|
+ // 清空选中状态
|
|
|
+ selectedIds.value = [];
|
|
|
+
|
|
|
+ // 刷新表格
|
|
|
+ crudExpose.doRefresh();
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ if (error !== 'cancel') {
|
|
|
+ console.error('批量已读失败:', error);
|
|
|
+ ElMessage.error('批量已读操作失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return {
|
|
|
crudOptions: {
|
|
|
toolbar:{
|
|
|
@@ -45,18 +96,20 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|
|
// 紧凑模式
|
|
|
compact:{show:false},
|
|
|
// 导出按钮
|
|
|
- /* export:{
|
|
|
+ export:{
|
|
|
text: '导出',
|
|
|
type: 'primary',
|
|
|
size: 'small',
|
|
|
icon: 'upload',
|
|
|
circle: false,
|
|
|
- display: true
|
|
|
- }, */
|
|
|
+ display: true,
|
|
|
+ show:false
|
|
|
+ },
|
|
|
// 列设置按钮
|
|
|
columns:{
|
|
|
show:false
|
|
|
},
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
request: {
|
|
|
@@ -65,6 +118,14 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|
|
editRequest,
|
|
|
delRequest,
|
|
|
},
|
|
|
+ table: {
|
|
|
+ rowKey: 'id',
|
|
|
+ selection: {
|
|
|
+ enabled: true,
|
|
|
+ multiple: true,
|
|
|
+ },
|
|
|
+ onSelectionChange,
|
|
|
+ },
|
|
|
actionbar: {
|
|
|
buttons: {
|
|
|
add: {
|
|
|
@@ -73,6 +134,15 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|
|
// return tabActivted.value !== 'receive' && auth('messageCenter:Create');
|
|
|
// }),
|
|
|
},
|
|
|
+ // 全部已读按钮
|
|
|
+ batchRead: {
|
|
|
+ text: '全部已读',
|
|
|
+ circle: false,
|
|
|
+ type: 'primary',
|
|
|
+ display: true,
|
|
|
+ show: computed(() => tabActivted.value === 'receive'),
|
|
|
+ click: handleBatchRead,
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
form:{
|
|
|
@@ -121,6 +191,20 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|
|
show: false,
|
|
|
},
|
|
|
}, */
|
|
|
+ $checked: {
|
|
|
+ title: "选择",
|
|
|
+ form: { show: false },
|
|
|
+ column: {
|
|
|
+ type: "selection",
|
|
|
+ align: "center",
|
|
|
+ width: "55px",
|
|
|
+ columnSetDisabled: true, //禁止在列设置中选择
|
|
|
+ show: computed(() => tabActivted.value === 'receive'),
|
|
|
+ selectable(row: any, index: any) {
|
|
|
+ return row.id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
_index: {
|
|
|
title: '序号',
|
|
|
form: { show: false },
|