Skip to content

Commit dc84021

Browse files
committed
【改进】不同数据库的右上角日程按钮对应进去的日程界面应是当前数据库视图 #5
1 parent b5de4ed commit dc84021

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/calendar/calendar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let av_ids: string[] = [];
2929

3030

3131

32-
export async function run(id: string, initialView = 'dayGridMonth') {
32+
export async function run(id: string, initialView = 'dayGridMonth', S_viewID = "") {
3333
const calendarEl = document.getElementById(`calendar-${id}`)!;
3434
const calendar = new Calendar(calendarEl, {
3535
plugins: [
@@ -183,6 +183,7 @@ export async function run(id: string, initialView = 'dayGridMonth') {
183183
// 从思源数据转换事件
184184
events: async function (info, successCallback, failureCallback) {
185185
try {
186+
filterViewId = S_viewID;
186187
steveTools.outlog('Fetching calendar events...::::::::::::::::::::::::::');
187188
// 1. 获取引用ID
188189
av_ids = await moduleInstances['M_calendar'].getAVreferenceid();

src/calendar/module-calendar.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class M_calendar {
121121
const msg = JSON.parse(e.data);
122122
if (msg.cmd === "transactions") {
123123
// console.log(msg);
124-
if(msg.data[0].doOperations[0].action==="updateAttrs"){
124+
if (msg.data[0].doOperations[0].action === "updateAttrs") {
125125
console.log("updateAttrs");
126126
this.avButton();
127127
}
@@ -174,11 +174,33 @@ export class M_calendar {
174174

175175
// 添加按钮点击事件
176176
button.addEventListener('click', async () => {
177-
steveTools.outlog('按钮被点击了');
177+
console.log('按钮被点击了');
178+
// Find the closest element with the specified classes
179+
let dataId = '';
180+
const avBlocks = document.querySelectorAll('div.item.item--focus[data-id]');
181+
if (avBlocks.length > 0) {
182+
// Get the closest AV block relative to the button
183+
let closestBlock = avBlocks[0];
184+
let minDistance = Infinity;
185+
186+
avBlocks.forEach(block => {
187+
const rect = block.getBoundingClientRect();
188+
const distance = Math.abs(rect.top - button.getBoundingClientRect().top);
189+
if (distance < minDistance) {
190+
minDistance = distance;
191+
closestBlock = block;
192+
}
193+
});
194+
195+
dataId = closestBlock.getAttribute('data-id');
196+
console.log('data-id:', dataId);
197+
steveTools.outlog('Selected AV block ID:', dataId);
198+
}
199+
178200
if (front == "browser-mobile" || front == "mobile") {
179-
await this.openRiChengViewDialog(true);
201+
await this.openRiChengViewDialog(true, dataId);
180202
} else {
181-
await this.openRiChengViewDialog();
203+
await this.openRiChengViewDialog(false, dataId);
182204
}
183205
});
184206
// 将按钮插入到目标 <span> 元素的右边
@@ -188,7 +210,7 @@ export class M_calendar {
188210
}, 500); // 延迟 500 毫秒
189211
}
190212

191-
async openRiChengViewDialog(isMobile: boolean = false) {
213+
async openRiChengViewDialog(isMobile: boolean = false, viewID="") {
192214

193215
const id = new Date().getTime().toString();
194216
let calendar: any;
@@ -205,7 +227,7 @@ export class M_calendar {
205227
});
206228

207229
setTimeout(async () => {
208-
calendar = await run(id);
230+
calendar = await run(id,'dayGridMonth',viewID);
209231
}, 100);
210232
}
211233

0 commit comments

Comments
 (0)