|
@@ -64,6 +64,8 @@ interface RowVO {
|
|
|
|
|
|
const xGrid = ref<VxeGridInstance<RowVO>>();
|
|
|
const originalDataMap = new Map();
|
|
|
+let allTasks = []; // 用于存储所有任务数据
|
|
|
+
|
|
|
|
|
|
const gridOptions = reactive<VxeGridProps<RowVO>>({
|
|
|
border: 'inner',
|
|
@@ -95,7 +97,7 @@ const gridOptions = reactive<VxeGridProps<RowVO>>({
|
|
|
pageSizes: [10, 20, 30],
|
|
|
},
|
|
|
editConfig: {
|
|
|
- trigger: 'click',
|
|
|
+ trigger: 'manual',
|
|
|
mode: 'row',
|
|
|
showStatus: true,
|
|
|
},
|
|
@@ -133,7 +135,6 @@ const operationList = ref([]);
|
|
|
|
|
|
const gridEvents: VxeGridListeners<RowVO> = {
|
|
|
pageChange({currentPage, pageSize}) {
|
|
|
- // console.log(currentPage, pageSize)
|
|
|
if (gridOptions.pagerConfig) {
|
|
|
gridOptions.pagerConfig.currentPage = currentPage;
|
|
|
gridOptions.pagerConfig.pageSize = pageSize;
|
|
@@ -142,6 +143,19 @@ const gridEvents: VxeGridListeners<RowVO> = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+async function fetchAllTasks(page = 1, limit = 100) {
|
|
|
+ try {
|
|
|
+ const response = await getTasks({ page, limit });
|
|
|
+ allTasks = allTasks.concat(response.data);
|
|
|
+
|
|
|
+ if (response.data.length === limit) {
|
|
|
+ await fetchAllTasks(page + 1, limit);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error fetching all tasks:', error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function getTaskList(filters = {}) {
|
|
|
try {
|
|
|
gridOptions.loading = true;
|
|
@@ -152,6 +166,9 @@ async function getTaskList(filters = {}) {
|
|
|
});
|
|
|
gridOptions.data = response.data;
|
|
|
gridOptions.pagerConfig.total = response.total;
|
|
|
+
|
|
|
+ allTasks = []; // 重置 allTasks
|
|
|
+ await fetchAllTasks(); // 获取所有任务数据
|
|
|
} catch (error) {
|
|
|
console.error('Error fetching task data:', error);
|
|
|
} finally {
|
|
@@ -159,13 +176,16 @@ async function getTaskList(filters = {}) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
const selectorRef = ref(null);
|
|
|
|
|
|
function filteredDataChange(newList) {
|
|
|
- // console.log('newList:', newList.value);
|
|
|
if (selectorRef.value) {
|
|
|
+ // 重置页码到第一页
|
|
|
+ if (gridOptions.pagerConfig) {
|
|
|
+ gridOptions.pagerConfig.currentPage = 1;
|
|
|
+ }
|
|
|
getTaskList(newList.value);
|
|
|
- // gridOptions.data = newList.value;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -324,54 +344,36 @@ async function createTask() {
|
|
|
};
|
|
|
try {
|
|
|
const resp = await postCreateTask(body);
|
|
|
+ if (resp.code === 2000) {
|
|
|
+ dialogFormVisible.value = false;
|
|
|
+ await getTaskList(); // 重新获取任务列表
|
|
|
+ ElMessage({message: '创建成功', type: 'success',})
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
- console.error('error:', error);
|
|
|
- await VXETable.modal.message({content: '创建失败,请重试', status: 'error'});
|
|
|
+ ElMessage({message: '创建失败', type: 'error',})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const submitEvent = async () => {
|
|
|
- // 创建一个新的行对象,用于保存表单数据
|
|
|
- const newRow: RowVO = {
|
|
|
- platformNumber: taskRuleForm.number,
|
|
|
- platformName: taskRuleForm.name,
|
|
|
- country: taskRuleForm.country,
|
|
|
- brandName: taskRuleForm.brand,
|
|
|
- user_name: taskRuleForm.operation,
|
|
|
- currencyCode: taskRuleForm.currency,
|
|
|
- currencyCodePlatform: taskRuleForm.currencyCodePlatform,
|
|
|
- child_user_number: '',
|
|
|
- };
|
|
|
- // 将新行添加到表格数据中
|
|
|
- gridOptions.data.push(newRow);
|
|
|
- try {
|
|
|
- await createTask();
|
|
|
- dialogFormVisible.value = false;
|
|
|
- //获取更新表格数据
|
|
|
- await getTaskList();
|
|
|
- gridOptions.loading = true;
|
|
|
- setTimeout(() => {
|
|
|
- gridOptions.loading = false;
|
|
|
- }, 300);
|
|
|
- } catch (error) {
|
|
|
- console.error('Failed to save task:', error);
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
const submitForm = async (formEl: FormInstance | undefined) => {
|
|
|
if (!formEl) return;
|
|
|
await formEl.validate(async (valid, fields) => {
|
|
|
if (valid) {
|
|
|
- await submitEvent();
|
|
|
- await nextTick();
|
|
|
+ const isDuplicate = allTasks.some(task => String(task.platformNumber) === String(taskRuleForm.number));
|
|
|
+ if (isDuplicate) {
|
|
|
+ await ElMessage({message: '平台编号已存在,请重新输入', type: 'warning',})
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ await createTask();
|
|
|
taskRuleFormRef.value.resetFields();
|
|
|
- await VXETable.modal.message({content: '创建成功', status: 'success'});
|
|
|
- } else {
|
|
|
- // console.log('error submit!', fields);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+function handleClose(done: Function) {
|
|
|
+ if (taskRuleFormRef.value) taskRuleFormRef.value.resetFields();
|
|
|
+ done();
|
|
|
+}
|
|
|
+
|
|
|
async function fetchOperationSelect() {
|
|
|
try {
|
|
|
const resp = await getOperationSelect();
|
|
@@ -440,7 +442,7 @@ onMounted(() => {
|
|
|
</vxe-grid>
|
|
|
</div>
|
|
|
</el-card>
|
|
|
- <el-dialog v-model="dialogFormVisible" title="新建任务" width="500" style="border-radius: 10px;">
|
|
|
+ <el-dialog v-model="dialogFormVisible" title="新建任务" width="500" style="border-radius: 10px;" :before-close="handleClose">
|
|
|
<el-form
|
|
|
ref="taskRuleFormRef"
|
|
|
:model="taskRuleForm"
|