您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
企业版Gitee增强
当前为
// ==UserScript== // @name GiteePlus // @version 1.1.4 // @description 企业版Gitee增强 // @author Kason // @grant GM_addStyle // @grant unsafeWindow // @license MIT // @match https://e.gitee.com/* // @icon https://e.gitee.com/assets/images/favicon.ico // @namespace https://gf.qytechs.cn/users/1186291 // ==/UserScript== (function () { "use strict"; let script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.src = "https://cdn.jsdelivr.net/npm/vue@3"; document.documentElement.appendChild(script); let link = document.createElement("link"); link.setAttribute("rel", "stylesheet"); link.href = "https://cdn.jsdelivr.net/npm/element-plus/dist/index.css"; document.documentElement.appendChild(link); let elscript = document.createElement("script"); elscript.setAttribute("type", "text/javascript"); elscript.src = "https://cdn.jsdelivr.net/npm/element-plus"; document.documentElement.appendChild(elscript); window.onload = () => { // 样式单独抽离管理 let app_styles = `position: absolute; display: flex; justify-content: flex-start; top: 58px; left: 240px; z-index:2; align-items: flex-start; margin-top: 5px;`; let badge_style = `margin-top: 10px;margin-right: 40px;`; let week_time_style = `text-align: center;margin-left: 70px;`; let last_week_time_style = `text-align: center;margin-left: 60px;`; let calendar_style = `position: absolute;top: 53px;width: 500px; right: -160px;text-align: center;`; let calendat_body_style = `margin-top:2px;`; let text = `<div id="app" style="${app_styles};"> <el-tooltip class="box-item" effect="light" content="所有任务/需求/Bug" placement="bottom"> <el-badge :value="sun_count" v-if="show_status" style="${badge_style};"><el-tag>总任务</el-tag></el-badge> </el-tooltip> <el-tooltip class="box-item" effect="light" content="24小时内将超时" placement="bottom"> <el-badge :value="deadline_count" v-if="show_status" style="${badge_style};"><el-tag type="warning">临期任务</el-tag></el-badge> </el-tooltip> <el-badge :value="expired_count" v-if="show_status" style="${badge_style};"><el-tag>延 期</el-tag></el-badge> <el-badge :value="feature_count" v-if="show_status" type="primary" style="${badge_style};"><el-tag >需 求</el-tag></el-badge> <el-badge :value="task_count" v-if="show_status" type="primary" style="${badge_style};"><el-tag>任 务</el-tag></el-badge> <el-badge :value="bug_count" v-if="show_status" type="warning" style="${badge_style};"><el-tag>Bug</el-tag></el-badge> <el-statistic style="${last_week_time_style}" v-if="show_status" title="上周工时(标准:40)" :value="last_work_time"> <template #suffix > <el-icon style="vertical-align: -0.125em"> <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" data-v-ea893728=""><path fill="currentColor" d="M512 896a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm0 64a448 448 0 1 1 0-896 448 448 0 0 1 0 896z"></path><path fill="currentColor" d="M480 256a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V288a32 32 0 0 1 32-32z"></path><path fill="currentColor" d="M480 512h256q32 0 32 32t-32 32H480q-32 0-32-32t32-32z"></path></svg> </el-icon> </template> </el-statistic> <el-statistic style="${week_time_style}" v-if="show_status" title="本周工时(标准:40)" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" :value="work_time"> <template #suffix > <el-icon style="vertical-align: -0.125em" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" > <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" data-v-ea893728=""><path fill="currentColor" d="M512 896a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm0 64a448 448 0 1 1 0-896 448 448 0 0 1 0 896z"></path><path fill="currentColor" d="M480 256a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V288a32 32 0 0 1 32-32z"></path><path fill="currentColor" d="M480 512h256q32 0 32 32t-32 32H480q-32 0-32-32t32-32z"></path></svg> </el-icon> </template> </el-statistic> <el-calendar ref="calendar" style="${calendar_style}" v-model="selectedDate" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" v-show="showCalendar" :range="dateRange"> <template #date-cell="{ data }"> <div v-show="isInAllDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};">{{ data.day.split('-').slice(1).join('-') }}</div> <svg v-if="!isSpecifiedDate( data.day.split('-').slice(0).join('-') )&&isInAllDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};" t="1696519254340" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1893" width="20" height="20"><path d="M666.32 727.28L554.08 944.8a36.24 36.24 0 0 1-48.88 15.6c-7.12-3.68-12.8-9.52-16.16-16.8L384.64 722.24c-5.12-10.8-15.2-18.4-26.96-20.32L116.16 662.4a36.24 36.24 0 0 1-29.92-41.68c1.28-7.84 5.12-15.12 10.96-20.56l178.24-167.68a36.32 36.32 0 0 0 11.04-31.92l-37.12-241.92a36.264 36.264 0 0 1 53.36-37.28l214.56 117.68c10.48 5.76 23.12 5.92 33.76 0.56L769.6 129.6a36.24 36.24 0 0 1 51.92 39.2l-45.68 240.48c-2.24 11.76 1.44 23.84 9.84 32.32l172.16 173.92a36.264 36.264 0 0 1-0.24 51.28c-5.68 5.6-13.04 9.2-20.96 10.16l-242.8 30.88c-11.68 1.6-22.08 8.8-27.52 19.44z" fill="#bfbfbf" p-id="1894"></path><path d="M655.2 709.36l-104.4 202.4a33.8 33.8 0 0 1-45.52 14.56 33.824 33.824 0 0 1-15.04-15.6L393.04 704.72a33.744 33.744 0 0 0-25.12-18.96l-224.8-36.8a33.88 33.88 0 0 1-27.92-38.8c1.2-7.36 4.8-14.08 10.16-19.12l165.92-156.08a33.768 33.768 0 0 0 10.24-29.68l-34.48-225.2a33.784 33.784 0 0 1 28.24-38.48c7.36-1.12 14.88 0.24 21.36 3.76l199.76 109.52c9.76 5.36 21.52 5.52 31.44 0.56l203.44-102.4a33.792 33.792 0 0 1 48.4 36.48l-42.48 223.76c-2.08 10.88 1.36 22.16 9.2 30.08l160.24 161.84a33.752 33.752 0 0 1-0.24 47.76c-5.28 5.2-12.08 8.56-19.44 9.52L680.96 691.2a34.152 34.152 0 0 0-25.76 18.16z" fill="#bfbfbf" p-id="1895"></path><path d="M118.48 631.44l388.16-161.76 5.2 457.6a33.704 33.704 0 0 1-22.96-18.48L391.68 702.72a33.88 33.88 0 0 0-25.12-18.96l-224.8-36.72a33.504 33.504 0 0 1-23.28-15.6z m676.8-465.28c3.36 6.64 4.4 14.16 3.04 21.52l-42.48 223.76c-2.08 10.96 1.36 22.16 9.2 30.08l160.24 161.84c9.6 9.68 12.4 24.08 7.2 36.64L506.64 469.6l278.08-315.84c4.32 3.2 8 7.36 10.56 12.4z" fill="#bfbfbf" p-id="1896"></path></svg> <svg v-if="isSpecifiedDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};" t="1696518710705" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1608" width="20" height="20"><path d="M666.32 727.28L554.08 944.8a36.24 36.24 0 0 1-48.88 15.6c-7.12-3.68-12.8-9.52-16.16-16.8L384.64 722.24c-5.12-10.8-15.2-18.4-26.96-20.32L116.16 662.4a36.24 36.24 0 0 1-29.92-41.68c1.28-7.84 5.12-15.12 10.96-20.56l178.24-167.68a36.32 36.32 0 0 0 11.04-31.92l-37.12-241.92a36.264 36.264 0 0 1 53.36-37.28l214.56 117.68c10.48 5.76 23.12 5.92 33.76 0.56L769.6 129.6a36.24 36.24 0 0 1 51.92 39.2l-45.68 240.48c-2.24 11.76 1.44 23.84 9.84 32.32l172.16 173.92a36.264 36.264 0 0 1-0.24 51.28c-5.68 5.6-13.04 9.2-20.96 10.16l-242.8 30.88c-11.68 1.6-22.08 8.8-27.52 19.44z" fill="#6E6E96" p-id="1609"></path><path d="M655.2 709.36l-104.4 202.4a33.8 33.8 0 0 1-45.52 14.56 33.824 33.824 0 0 1-15.04-15.6L393.04 704.72a33.744 33.744 0 0 0-25.12-18.96l-224.8-36.8a33.88 33.88 0 0 1-27.92-38.8c1.2-7.36 4.8-14.08 10.16-19.12l165.92-156.08a33.768 33.768 0 0 0 10.24-29.68l-34.48-225.2a33.784 33.784 0 0 1 28.24-38.48c7.36-1.12 14.88 0.24 21.36 3.76l199.76 109.52c9.76 5.36 21.52 5.52 31.44 0.56l203.44-102.4a33.792 33.792 0 0 1 48.4 36.48l-42.48 223.76c-2.08 10.88 1.36 22.16 9.2 30.08l160.24 161.84a33.752 33.752 0 0 1-0.24 47.76c-5.28 5.2-12.08 8.56-19.44 9.52L680.96 691.2a34.152 34.152 0 0 0-25.76 18.16z" fill="#FECD34" p-id="1610"></path><path d="M118.48 631.44l388.16-161.76 5.2 457.6a33.704 33.704 0 0 1-22.96-18.48L391.68 702.72a33.88 33.88 0 0 0-25.12-18.96l-224.8-36.72a33.504 33.504 0 0 1-23.28-15.6z m676.8-465.28c3.36 6.64 4.4 14.16 3.04 21.52l-42.48 223.76c-2.08 10.96 1.36 22.16 9.2 30.08l160.24 161.84c9.6 9.68 12.4 24.08 7.2 36.64L506.64 469.6l278.08-315.84c4.32 3.2 8 7.36 10.56 12.4z" fill="#FEA935" p-id="1611"></path></svg> <div v-if="isInAllDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};">{{ registered_map[data.day] || 0 }}</div> </template> </el-calendar> </div>`; var el = document.createElement("div"); el.innerHTML = text; document.body.append(el); // 登录(不可用)人对象 class assignee { constructor() { this.data = { id: null, username: null, name: null, remark: null, pinyin: null, avatar_url: null, is_enterprise_member: null, is_history_member: null, outsourced: null, }; } } // 创建者对象 class author { constructor() { this.data = { id: null, username: null, name: null, remark: null, pinyin: null, avatar_url: null, is_enterprise_member: null, is_history_member: null, outsourced: null, }; } } // 任务类型 class issue_type { constructor() { this.data = { id: null, title: null, template: null, ident: null, color: null, is_system: null, created_at: null, updated_at: null, category: null, description: null, }; } } // 任务状态 class issue_state { constructor() { this.data = { id: null, title: null, color: null, icon: null, command: null, serial: null, issue_types: [new issue_type()], created_at: null, updated_at: null, }; } } // 工作项数据 class issue_data { constructor() { this.total_count = 0; this.data = [ { id: null, root_id: null, parent_id: null, project_id: null, ident: null, title: null, issue_state_id: null, program_id: null, state: null, comments_count: null, priority: null, branch: null, priority_human: null, assignee: new assignee(), duration: null, created_at: null, updated_at: null, collaborators: [], author: new author(), milestone: null, issue_state: new issue_state(), issue_type: new issue_type(), labels: [], issue_extra: [], plan_started_at: null, deadline: null, finished_at: null, started_at: null, security_hole: null, is_star: null, kanban_info: null, estimated_duration: null, // 任务单登记时间 registered_duration: 0, }, ]; } } const App = { data() { return { roult_path: null, message: "Hello Gitee Plus", elements: null, work_time: 0, last_work_time: 0, issurDataTotal: null, show_status: true, sun_count: 0, deadline_count: 0, task_count: 0, feature_count: 0, bug_count: 0, expired_count: 0, calendar: null, dateRange: null, registered_map: {}, selectedDate: new Date(), // 添加选中的日期 showCalendar: false, // 控制日历组件的显示 }; }, mounted() { // 获取当前公司的路由前缀 this.getRoluteStr() .then((result) => { this.roult_path = result.id; }) .catch(function (error) { console.error("Gitee客户端异常,获取公司路由失败"); }); // 设置左侧标题为会员 this.$nextTick(() => { setTimeout(() => { const element = document.querySelector( ".level-label.level-label--standard" ); const avator = document.querySelector(".nav-item.user"); if (element && avator) { element.innerHTML = "Plus"; element.style.background = "linear-gradient(90deg,#c9e7ff,#f3bc4c)"; element.style.fontSize = "16px"; element.style.color = "#093978"; // 创建一个新的<div>元素 const svgContainer = document.createElement("div"); svgContainer.innerHTML = `<svg t="1696521690855" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14197" width="16" height="16"><path d="M308.586 388.462c10.932 6.596 25.134 3.01 31.496-7.902 33.666-57.784 92.488-158.71 131.688-225.968 17.562-30.122 61.848-30.122 79.408 0 39.2 67.26 98.024 168.184 131.712 225.968 6.362 10.912 20.564 14.5 31.472 7.902 57.792-34.924 123.604-78.328 173.824-112.194 32.056-21.624 75.466 2.736 71.568 40.698-12.946 126.192-39.312 349.476-76.764 499.802-5.286 21.168-17.764 39.334-38.864 46.166-40.656 13.126-132.452 30.666-332.64 30.666-195.328 0-287.46-16.688-329.594-29.702-23.206-7.168-36.354-27.306-41.418-50.646-36.69-169.816-62.832-376.206-76.18-495.084-4.28-38.124 39.31-62.924 71.544-41.19 50.086 33.762 115.382 76.804 172.748 111.484z" fill="#FCBF28" p-id="14198"></path><path d="M646.4 602.4c0 33.6-100.8 179.2-134.4 179.2-33.6 0-134.4-145.6-134.4-179.2 0-33.6 100.8-179.2 134.4-179.2 33.6 0 134.4 145.6 134.4 179.2z" fill="#FFFFFF" p-id="14199"></path></svg>`; // 添加SVG容器到目标元素中 avator.appendChild(svgContainer); avator.style.position = "relative"; svgContainer.style.position = "absolute"; svgContainer.style.top = "3px"; svgContainer.style.left = "12px"; } }, 1300); }); // 页面可见性的改变 document.addEventListener("visibilitychange", function () { if (document.visibilityState === "visible") { console.log("当前页面在浏览器打开标签"); // TODO 获取焦点,主动获取一次通知中,是否存在新的任务,如果有新的任务,将和上次离开时间对比,共有多少任务派出 // TODO 计算出任务数量,并显示在页面中 } else { // TODO 页面进入后台,进行新的修改 记录时间 } }); // 路由判定 window.addEventListener("popstate", (event) => { if (window.location.pathname.includes("dashboard")) { this.show_status = true; } else { this.show_status = false; } }); this.$nextTick(() => { setTimeout(() => { this.display_none_btn(); }, 1500); }); this.showNotification("By Kason", "欢迎回来 GiteePlus"); this.$nextTick(() => { setTimeout(() => { this.get_week_reports() .then(function (result) { // 本周 var current_week = result.current_week; // 上一周 var last_week = result.last_week; if ( (last_week.id != null && current_week.id == null) || (last_week.id != undefined && current_week.id == undefined) ) { // 显示为需要写周报 // 创建滚动文本元素 var marquee = document.createElement("marquee"); marquee.setAttribute("behavior", "scroll"); marquee.setAttribute("direction", "left"); // 设置滚动文本内容和样式 marquee.innerText = "您本周周报还没写..."; marquee.style.fontSize = "35px"; marquee.style.fontWeight = "bold"; marquee.style.marginTop = "25px"; marquee.style.color = "crimson"; // 查找指定的 div 元素,并将滚动文本添加到其中 var targetDiv = document.querySelector(".reports-view"); if (targetDiv) { targetDiv.appendChild(marquee); } const el = document.querySelector( ".markdown-body.text-disabled" ); if (el != null) { el.style.display = "none"; } var currentDate = new Date(); var currentDay = currentDate.getDay(); if (currentDay >= 5) { // TODO 对今天是周五的情况下,且周报也未获取到,继续处理 } } else if ( last_week.id == null && current_week.id == null && new Date().getDay() == 1 ) { var two_marquee = document.createElement("marquee"); two_marquee.setAttribute("behavior", "scroll"); two_marquee.setAttribute("direction", "left"); // 设置滚动文本内容和样式 two_marquee.innerText = "您 上周/本周 都没写..."; two_marquee.style.fontSize = "35px"; two_marquee.style.fontWeight = "bold"; two_marquee.style.marginTop = "25px"; two_marquee.style.color = "crimson"; const ele = document.querySelector( ".markdown-body.text-disabled" ); if (ele != null) { ele.style.display = "none"; } // 查找指定的 div 元素,并将滚动文本添加到其中 var two_targetDiv = document.querySelector(".reports-view"); if (two_targetDiv) { two_targetDiv.appendChild(two_marquee); } // TODO 上周周报没写的处理 } else if (last_week.id == null && current_week.id == null) { var thr_marquee = document.createElement("marquee"); thr_marquee.setAttribute("behavior", "scroll"); thr_marquee.setAttribute("direction", "left"); // 设置滚动文本内容和样式 thr_marquee.innerText = "您本周周报还没写..."; thr_marquee.style.fontSize = "35px"; thr_marquee.style.fontWeight = "bold"; thr_marquee.style.marginTop = "25px"; thr_marquee.style.color = "crimson"; const element = document.querySelector( ".markdown-body.text-disabled" ); if (element != null) { element.style.display = "none"; } // 查找指定的 div 元素,并将滚动文本添加到其中 var thr_targetDiv = document.querySelector(".reports-view"); if (thr_targetDiv) { thr_targetDiv.appendChild(thr_marquee); } } }) .catch(function (error) { console.error("Gitee客户端异常,获取周报失败"); }); }, 1000); }); this.send_todo_num_request() .then((issue_str) => { return this.send_issue_data_request(issue_str); }) .then((issue) => { // 处理返回的 issue 数据 this.issurDataTotal = issue; // 获取到的数据 this.sun_count = this.issurDataTotal.total_count; if ( this.issurDataTotal.total_count != 0 && this.issurDataTotal.data.length > 0 ) { for (let info of this.issurDataTotal.data) { // 截止时间 if (info.deadline != null) { var currentTime = new Date(); if (new Date(info.deadline) >= currentTime) { var time = this.get_hour_difference(info.deadline); if (time != null && time <= 24) { this.deadline_count++; } } else { // 逾期任务 this.expired_count++; } } // 将数据分类,摘选出需求/任务/bug if (info.issue_type.id == 626337) { this.bug_count++; } if (info.issue_type.id == 626336) { this.feature_count++; } const validIssueTypeIds = new Set([ 16690, 662615, 757073, 757074, 766555, ]); if (validIssueTypeIds.has(info.issue_type.id)) { this.task_count++; } } // 调用element-plus的通知,可以等待通知消息接收到再处理 if (this.deadline_count>0){ this.$notify({ title: "贴心通知", message: "⚠注意!您有24小时内需完成任务共" + this.deadline_count + "条", type: "info", position: "bottom-right", offset: 30, duration: 1800, }); } } }) .catch((error) => { console.error("Gitee客户端异常", error); }); this.get_week_time() .then((result) => { if (result != null) { var dates = result.dates; var all_registered_duration = result.all_registered_duration; var daily_registered_duration_count = result.daily_registered_duration_count; this.work_time = all_registered_duration; // 设置期限为本周 this.allDate = dates; this.dateRange = [new Date(dates[0]), new Date(dates[6])]; var registered_count = []; for (let i = 0; i < dates.length; i++) { var key = dates[i].replace(/"/g, ""); var value = daily_registered_duration_count[key]; registered_count[key] = value; } this.registered_map = registered_count; } }) .catch(function (error) { console.error("Gitee客户端异常,获取工时失败"); }); this.get_last_week_time() .then((result) => { if (result != null) { var dates = result.dates; var all_registered_duration = result.all_registered_duration; this.last_work_time = all_registered_duration; } }) .catch(function (error) { console.error("Gitee客户端异常,获取工时失败"); }); }, methods: { // 隐藏多余按钮 display_none_btn() { this.elements = document.querySelectorAll( ".ge-app-top-right .ge-app-top-nav" ); for (let i = 0; i < this.elements.length; i++) { if (i === 0 || i === 1 || i === 3) { this.elements[i].style.display = "none"; } } }, // 创建通知并显示 showNotification(title, message) { var notification = new unsafeWindow.Notification(title, { body: message, icon: "https://e.gitee.com/assets/images/favicon.ico", }); setTimeout(function () { notification.close(); }, 3000); }, // 获取周报状态 get_week_reports() { const _this = this; // 保存正确的上下文 // 获取当前年份 const currentYear = new Date().getFullYear(); return new Promise(function (resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/" + _this.roult_path + "/week_reports/my_reports?year=" + currentYear, true ); // 设置XMLHttpRequest 自动获取Cookie xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var respbody = JSON.parse(xhr.responseText); var current_week = respbody.data[0]; var last_week = respbody.data[1]; resolve({ current_week: current_week, last_week: last_week }); } else { reject("Gitee客户端异常"); } } }; xhr.onerror = function (e) { reject("周报获取异常"); }; // 发送请求 xhr.send(null); }); }, // 获取todo_num数量 send_todo_num_request() { const _this = this; return new Promise(async function (resolve, reject) { await _this.getRoluteStr(); var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/" + _this.roult_path + "/issues/stat_count?todo=true&today=true&week=true&overdue=true&star=true&all=true", true ); // 设置XMLHttpRequest 自动获取Cookie xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var respbody = JSON.parse(xhr.responseText); var issue_str = respbody.todo; resolve(issue_str); // 将获取到的值传递给 Promise 的 resolve 方法 } else { reject("Gitee客户端异常"); } } }; xhr.onerror = function (e) { reject("信息获取异常"); }; // 发送请求 xhr.send(null); }); }, // 获取任务总集合 send_issue_data_request(todo_nums) { const _this = this; return new Promise(async function (resolve, reject) { await _this.getRoluteStr(); var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/" + _this.roult_path + "/issues?state=open,progressing&only_related_me=1&page=1&offset=0&per_page=" + todo_nums, true ); // 设置XMLHttpRequest 自动获取Cookie xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var work_json = xhr.responseText; var issueData = new issue_data(); issueData = JSON.parse(work_json); var issue = Object.assign(new issue_data(), issueData); resolve(issue); } else { reject("Gitee客户端异常"); } } }; xhr.onerror = function (e) { reject("信息获取异常"); }; // 发送请求 xhr.send(null); }); }, // 计算时间差 get_hour_difference(deadline) { var currentTime = new Date(); var specifiedTime = new Date(deadline); if (currentTime <= specifiedTime) { var diffMs = specifiedTime - currentTime; var diffHours = Math.floor(diffMs / 1000 / 60 / 60); return diffHours; } return null; }, // 获取工时状态 get_week_time() { // 获取当前日期 var currentDate = new Date(); // 获取当前日期是一周中的第几天(0-6,其中0表示星期日) var currentDay = currentDate.getDay(); // 计算当前一周的第一天和最后一天的日期 var firstDayOfWeek = new Date( currentDate.setDate(currentDate.getDate() - currentDay + 1) ); var lastDayOfWeek = new Date( currentDate.setDate(currentDate.getDate() - currentDay + 7) ); // 创建一个数组来存储一周的日期 var weekDates = []; // 循环获取一周的日期并将其存入数组 for (var i = 0; i <= 6; i++) { var date = new Date(firstDayOfWeek); date.setDate(firstDayOfWeek.getDate() + i); weekDates.push(date); } // 遍历时间,格式化日期为"YYYY-MM-DD"的格式 var formattedDates = weekDates.map(function (date) { var year = date.getFullYear(); var month = ("0" + (date.getMonth() + 1)).slice(-2); var day = ("0" + date.getDate()).slice(-2); return year + "-" + month + "-" + day; }); // 当前一周的日期,传入工时接口 const _this = this; return new Promise(async function (resolve, reject) { await _this.getRoluteStr(); var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/" + _this.roult_path + "/statistics/user_daily_workloads_overview?search=" + JSON.parse(localStorage.getItem("gitee.user")).userInfo .username + "&start_date=" + formattedDates[0] + "&end_date=" + formattedDates[6], true ); xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var respbody = JSON.parse(xhr.responseText); var all_registered_duration = respbody.all_registered_duration; var daily_registered_duration_count = respbody.daily_registered_duration_count; var dates = respbody.dates; resolve({ all_registered_duration: all_registered_duration, daily_registered_duration_count: daily_registered_duration_count, dates: dates, }); } else { reject("Gitee客户端异常"); } } }; xhr.onerror = function (e) { reject("工时获取异常"); }; xhr.send(null); }); }, // 获取上周的工时 get_last_week_time() { // 获取当前日期 var currentDate = new Date(); // 计算上周的第一天和最后一天的日期 var firstDayOfLastWeek = new Date( currentDate.setDate( currentDate.getDate() - currentDate.getDay() - 6 ) ); var lastDayOfLastWeek = new Date( currentDate.setDate(currentDate.getDate() - currentDate.getDay()) ); // 创建一个数组来存储上周的日期 var weekDates = []; // 循环获取上周的日期并将其存入数组 for (var i = 0; i <= 6; i++) { var date = new Date(firstDayOfLastWeek); date.setDate(firstDayOfLastWeek.getDate() + i); weekDates.push(date); } // 遍历时间,格式化日期为"YYYY-MM-DD"的格式 var formattedDates = weekDates.map(function (date) { var year = date.getFullYear(); var month = ("0" + (date.getMonth() + 1)).slice(-2); var day = ("0" + date.getDate()).slice(-2); return year + "-" + month + "-" + day; }); // 当前一周的日期,传入工时接口 const _this = this; return new Promise(async function (resolve, reject) { await _this.getRoluteStr(); var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/" + _this.roult_path + "/statistics/user_daily_workloads_overview?search=" + JSON.parse(localStorage.getItem("gitee.user")).userInfo .username + "&start_date=" + formattedDates[0] + "&end_date=" + formattedDates[6], true ); xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var respbody = JSON.parse(xhr.responseText); var all_registered_duration = respbody.all_registered_duration; var daily_registered_duration_count = respbody.daily_registered_duration_count; var dates = respbody.dates; resolve({ all_registered_duration: all_registered_duration, daily_registered_duration_count: daily_registered_duration_count, dates: dates, }); } else { reject("上周工时获取异常"); } } }; xhr.onerror = function (e) { reject("上周工时获取异常"); }; xhr.send(null); }); }, showCalendarOnMouseover() { this.showCalendar = true; }, isSpecifiedDate(date) { // 根据你的指定日期进行判断逻辑 var current_time = new Date(date); const specifiedDate = new Date(); // 分别获取日期对象的年、月、日 const yearMatched = current_time.getFullYear() === specifiedDate.getFullYear(); const monthMatched = current_time.getMonth() === specifiedDate.getMonth(); const dayMatched = current_time.getDate() === specifiedDate.getDate(); // 判断年、月、日是否都匹配 return yearMatched && monthMatched && dayMatched; }, isInAllDate(dateTime) { // 获取当前日期 var currentDate = new Date(); // 获取当前日期是一周中的第几天(0-6,其中0表示星期日) var currentDay = currentDate.getDay(); // 计算当前一周的第一天和最后一天的日期 var firstDayOfWeek = new Date( currentDate.setDate(currentDate.getDate() - currentDay + 1) ); var lastDayOfWeek = new Date( currentDate.setDate(currentDate.getDate() - currentDay + 7) ); // 创建一个数组来存储一周的日期 var weekDates = []; // 循环获取一周的日期并将其存入数组 for (var i = 0; i <= 6; i++) { var date = new Date(firstDayOfWeek); date.setDate(firstDayOfWeek.getDate() + i); weekDates.push(date); } // 格式化日期为"YYYY-MM-DD"的格式 var formattedDates = weekDates.map(function (date) { var year = date.getFullYear(); var month = ("0" + (date.getMonth() + 1)).slice(-2); var day = ("0" + date.getDate()).slice(-2); return year + "-" + month + "-" + day; }); if (formattedDates.includes(dateTime)) { return true; } else { return false; } }, getRoluteStr() { const _this = this; return new Promise(function (resolve, reject) { var enterprisePath = localStorage.getItem("enterprisePath"); var xhr = new XMLHttpRequest(); xhr.open( "GET", "https://api.gitee.com/enterprises/basic_info?enterprise_path=" + enterprisePath, true ); xhr.withCredentials = true; xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var respbody = JSON.parse(xhr.responseText); var enterprises = respbody.enterprises; const result = enterprises.find( (obj) => obj.path === enterprisePath ); resolve({ id: result.id }); } else { reject("公司id获取异常"); } } }; xhr.onerror = function (e) { reject("上周工时获取异常"); }; xhr.send(null); }); }, }, }; const app = Vue.createApp(App); app.use(ElementPlus); app.mount("#app"); }; })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址