GiteePlus

企业版Gitee增强

当前为 2024-03-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GiteePlus
  3. // @version 1.2.0
  4. // @description 企业版Gitee增强
  5. // @author Kason
  6. // @grant GM_addStyle
  7. // @grant unsafeWindow
  8. // @grant GM_notification
  9. // @grant GM_xmlhttpRequest
  10. // @license MIT
  11. // @match https://e.gitee.com/*
  12. // @icon https://e.gitee.com/assets/images/favicon.ico
  13. // @namespace https://greasyfork.org/users/1186291
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. "use strict";
  18. let script = document.createElement("script");
  19. script.setAttribute("type", "text/javascript");
  20. script.src = "https://cdn.jsdelivr.net/npm/vue@3";
  21. document.documentElement.appendChild(script);
  22. let link = document.createElement("link");
  23. link.setAttribute("rel", "stylesheet");
  24. link.href = "https://cdn.jsdelivr.net/npm/element-plus/dist/index.css";
  25. document.documentElement.appendChild(link);
  26. let fontAwesome = document.createElement("link");
  27. fontAwesome.setAttribute("rel", "stylesheet");
  28. fontAwesome.href =
  29. "https://cdn.bootcdn.net/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css";
  30. document.documentElement.appendChild(fontAwesome);
  31. let elscript = document.createElement("script");
  32. elscript.setAttribute("type", "text/javascript");
  33. elscript.src = "https://cdn.jsdelivr.net/npm/element-plus";
  34. document.documentElement.appendChild(elscript);
  35. let sortableScript = document.createElement("script");
  36. sortableScript.setAttribute("type", "text/javascript");
  37. sortableScript.src =
  38. "https://cdn.bootcdn.net/ajax/libs/Sortable/1.15.0/Sortable.min.js";
  39. sortableScript.async = true;
  40. document.documentElement.appendChild(sortableScript);
  41. window.onload = () => {
  42. // 样式单独抽离管理
  43. let app_styles = `position: absolute;
  44. display: flex;
  45. justify-content: flex-start;
  46. top: 58px;
  47. left: 240px;
  48. z-index:2;
  49. align-items: flex-start;
  50. margin-top: 5px;`;
  51. let badge_style = `margin-top: 10px;margin-right: 40px;`;
  52. let week_time_style = `text-align: center;margin-left: 70px;`;
  53. let last_week_time_style = `text-align: center;margin-left: 60px;`;
  54. let calendar_style = `position: absolute;top: 53px;width: 500px; right: -160px;text-align: center;`;
  55. let calendat_body_style = `margin-top:2px;`;
  56. let text = `<div id="app" style="${app_styles};">
  57. <el-tooltip class="box-item" effect="light" content="所有任务/需求/Bug" placement="bottom">
  58. <el-badge :value="sun_count" v-if="show_status" style="${badge_style};"><el-tag>总任务</el-tag></el-badge>
  59. </el-tooltip>
  60. <el-tooltip class="box-item" effect="light" content="24小时内将超时" placement="bottom">
  61. <el-badge :value="deadline_count" v-if="show_status" style="${badge_style};"><el-tag type="warning">临期任务</el-tag></el-badge>
  62. </el-tooltip>
  63. <el-tooltip class="box-item" effect="light" content="已延期" placement="bottom">
  64. <el-badge :value="expired_count" v-if="show_status" style="${badge_style};"><el-tag>延 期</el-tag></el-badge>
  65. </el-tooltip>
  66. <el-badge :value="feature_count" v-if="show_status" type="primary" style="${badge_style};"><el-tag >需 求</el-tag></el-badge>
  67. <el-badge :value="task_count" v-if="show_status" type="primary" style="${badge_style};"><el-tag>任 务</el-tag></el-badge>
  68. <el-badge :value="bug_count" v-if="show_status" type="warning" style="${badge_style};"><el-tag>Bug</el-tag></el-badge>
  69. <el-statistic style="${last_week_time_style}" v-if="show_status" title="上周工时(标准:40)" :value="last_work_time">
  70. <template #suffix >
  71. <el-icon style="vertical-align: -0.125em">
  72. <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>
  73. </el-icon>
  74. </template>
  75. </el-statistic>
  76. <el-statistic style="${week_time_style}" v-if="show_status" title="本周工时(标准:40)" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" :value="work_time">
  77. <template #suffix >
  78. <el-icon style="vertical-align: -0.125em" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" >
  79. <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>
  80. </el-icon>
  81. </template>
  82. </el-statistic>
  83. <el-calendar ref="calendar" style="${calendar_style}" v-model="selectedDate" @mouseover="showCalendar = true" @mouseleave="showCalendar = false" v-show="showCalendar" :range="dateRange">
  84. <template #date-cell="{ data }">
  85. <div v-show="isInAllDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};">{{ data.day.split('-').slice(1).join('-') }}</div>
  86. <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>
  87. <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>
  88. <div v-if="isInAllDate( data.day.split('-').slice(0).join('-') )" style="${calendat_body_style};">{{ registered_map[data.day] || 0 }}</div>
  89. </template>
  90. </el-calendar>
  91. <el-dialog v-model="showTable" width="800" draggable :show-close="false" :style="{ 'border-radius': '15px' }">
  92. <div slot="title" style="margin-top: -10px;font-size: 17px;font-weight: 800;margin-bottom: 10px; display: flex;align-items: center;flex-direction: row;justify-content: space-between;">任务选择|刷新任务状态<span><el-tooltip class="box-item" effect="dark" content="选中后,将周报直接推送请求" placement="left"><el-checkbox v-model="push">直接推送</el-checkbox></el-tooltip><span></div>
  93. <el-table border stripe max-height="250" ref="tableRef" @selection-change="handleSelectionChange" :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}" :data="tableData" :table-layout="tableLayout">
  94. <el-table-column type="selection" label="序号" width="35"></el-table-column>
  95. <el-table-column prop="title" label="任务名称" width="555" show-overflow-tooltip></el-table-column>
  96. <el-table-column prop="assignee" label="任务负责人" width="95">
  97. <template #default="scope">
  98. <el-avatar :src="scope.row.assignee.avatar_url" style="background: white; width:20px; height:20px"></el-avatar>
  99. </template>
  100. </el-table-column>
  101. <el-table-column prop="issue_state.title" label="状态"></el-table-column>
  102. </el-table>
  103. <el-input
  104. v-model="textarea"
  105. style="width: 100%"
  106. :rows="4"
  107. type="textarea"
  108. placeholder="稍等,我有话要说!\n例如:在xxx任务中,虽然完成了,但是遇到了xxx困难,请求大佬支援...\n例如:在本周任务中,我学会了xxx技能,并在飞书分享相关文档\n例如:我遇到了些问题:1.新的技术;2.服务器问题"></el-input>
  109. <el-button :loading="pushLoading" type="primary" style="display: block; margin: 0 auto; margin-top: 15px;" @click="chatAI"><i class="fa fa-paper-plane"></i>&nbsp;&nbsp;GO GPT!</el-button>
  110. </el-dialog>
  111. </div>`;
  112. var el = document.createElement("div");
  113. el.innerHTML = text;
  114. document.body.append(el);
  115.  
  116. // 登录人对象
  117. class assignee {
  118. constructor() {
  119. this.data = {
  120. id: null,
  121. username: null,
  122. name: null,
  123. remark: null,
  124. pinyin: null,
  125. avatar_url: null,
  126. is_enterprise_member: null,
  127. is_history_member: null,
  128. outsourced: null,
  129. };
  130. }
  131. }
  132. // 创建者对象
  133. class author {
  134. constructor() {
  135. this.data = {
  136. id: null,
  137. username: null,
  138. name: null,
  139. remark: null,
  140. pinyin: null,
  141. avatar_url: null,
  142. is_enterprise_member: null,
  143. is_history_member: null,
  144. outsourced: null,
  145. };
  146. }
  147. }
  148. // 任务类型
  149. class issue_type {
  150. constructor() {
  151. this.data = {
  152. id: null,
  153. title: null,
  154. template: null,
  155. ident: null,
  156. color: null,
  157. is_system: null,
  158. created_at: null,
  159. updated_at: null,
  160. category: null,
  161. description: null,
  162. };
  163. }
  164. }
  165. // 任务状态
  166. class issue_state {
  167. constructor() {
  168. this.data = {
  169. id: null,
  170. title: null,
  171. color: null,
  172. icon: null,
  173. command: null,
  174. serial: null,
  175. issue_types: [new issue_type()],
  176. created_at: null,
  177. updated_at: null,
  178. };
  179. }
  180. }
  181. // 工作项数据
  182. class issue_data {
  183. constructor() {
  184. this.total_count = 0;
  185. this.data = [
  186. {
  187. id: null,
  188. root_id: null,
  189. parent_id: null,
  190. project_id: null,
  191. ident: null,
  192. title: null,
  193. issue_state_id: null,
  194. program_id: null,
  195. state: null,
  196. comments_count: null,
  197. priority: null,
  198. branch: null,
  199. priority_human: null,
  200. assignee: new assignee(),
  201. duration: null,
  202. created_at: null,
  203. updated_at: null,
  204. collaborators: [],
  205. author: new author(),
  206. milestone: null,
  207. issue_state: new issue_state(),
  208. issue_type: new issue_type(),
  209. labels: [],
  210. issue_extra: [],
  211. plan_started_at: null,
  212. deadline: null,
  213. finished_at: null,
  214. started_at: null,
  215. security_hole: null,
  216. is_star: null,
  217. kanban_info: null,
  218. estimated_duration: null,
  219. // 任务单登记时间
  220. registered_duration: 0,
  221. },
  222. ];
  223. }
  224. }
  225.  
  226. const App = {
  227. data() {
  228. return {
  229. roult_path: null,
  230. message: "Hello Gitee Plus",
  231. elements: null,
  232. work_time: 0,
  233. last_work_time: 0,
  234. issurDataTotal: null,
  235. show_status: true,
  236. sun_count: 0,
  237. deadline_count: 0,
  238. task_count: 0,
  239. feature_count: 0,
  240. bug_count: 0,
  241. expired_count: 0,
  242. calendar: null,
  243. dateRange: null,
  244. registered_map: {},
  245. selectedDate: new Date(), // 添加选中的日期
  246. showCalendar: false, // 控制日历组件的显示
  247. tableData: [],
  248. showTable: false,
  249. dialogTableVisible: true,
  250. tableLayout: "fixed",
  251. selectionDatas: [],
  252. textarea: "",
  253. push: true,
  254. pushLoading: false
  255. };
  256. },
  257. mounted() {
  258. // 获取当前公司的路由前缀
  259. this.getRoluteStr()
  260. .then((result) => {
  261. this.roult_path = result.id;
  262. })
  263. .catch(function (error) {
  264. console.error("Gitee客户端异常,获取公司路由失败");
  265. });
  266. // 设置左侧标题为会员,右侧多余按钮
  267. this.hideComp();
  268. // 页面可见性的改变
  269. document.addEventListener("visibilitychange", () => {
  270. if (document.visibilityState === "visible") {
  271. this.showNotification(
  272. "Hi " +
  273. JSON.parse(localStorage.getItem("gitee.user")).userInfo.name,
  274. "欢迎回来 GiteePlus"
  275. );
  276. console.log("当前页面在浏览器打开标签");
  277. // TODO 获取焦点,主动获取一次通知中,是否存在新的任务,如果有新的任务,将和上次离开时间对比,共有多少任务派出
  278. // TODO 计算出任务数量,并显示在页面中
  279. } else {
  280. // TODO 页面进入后台,进行新的修改 记录时间
  281. }
  282. });
  283. // 路由判定
  284. window.addEventListener("popstate", (event) => {
  285. if (window.location.pathname.includes("dashboard")) {
  286. this.show_status = true;
  287. } else {
  288. this.show_status = false;
  289. }
  290. });
  291. // 周报滚动条显示
  292. this.$nextTick(async () => {
  293. try {
  294. const { current_week, last_week } = await this.get_week_reports();
  295. await this.send_todo_num_request();
  296. if (
  297. (last_week.id != null && current_week.id == null) ||
  298. (last_week.id != undefined && current_week.id == undefined)
  299. ) {
  300. const article = document.createElement("div");
  301. article.setAttribute("id", "team-members");
  302. article.innerHTML =
  303. `
  304. <article class="team-member">
  305. <img
  306. class="team-member-avatar"
  307. src="` +
  308. JSON.parse(localStorage.getItem("gitee.user")).userInfo
  309. .avatar_url +
  310. `"
  311. alt="Team Member"
  312. />
  313. <div class="team-member-name">
  314. <h3>周报汇报</h3>
  315. <p>本周周报还没写</p>
  316. </div>
  317. <ul class="social-links">
  318. <a class="zb" href="#"><i class="fa-solid fa-calendar"></i></a>
  319. </ul>
  320. </article>
  321. <article class="team-member">
  322. <div class="team-member-name">
  323. <h3>贴心通知</h3>
  324. <p>24h内需完成任务, ` +
  325. this.deadline_count +
  326. ` 条</p>
  327. </div>
  328. <ul class="social-links">
  329. <li>
  330. <a href="#"><i class="fa-solid fa-ellipsis" style="color: #f3de53;"></i></a>
  331. </li>
  332. </ul>
  333. </article>
  334. <article class="team-member">
  335. <div class="team-member-name">
  336. <h3>超时提醒</h3>
  337. <p>当前累计超时单, ` +
  338. this.expired_count +
  339. ` 条</p>
  340. </div>
  341. <ul class="social-links">
  342. <li>
  343. <a href="#"><i class="fa-solid fa-bell" style="color: #de7cc9;"></i></a>
  344. </li>
  345. </ul>
  346. </article>
  347. `;
  348. let style = document.createElement("style");
  349. style.innerHTML = `
  350. h3{
  351. margin: 0;
  352. }
  353. #team-members {
  354. display: flex;
  355. font-size: 1rem;
  356. background-position: center center;
  357. background-size: cover;
  358. display: flex;
  359. flex-direction: column;
  360. gap: 16px;
  361. width: 100%;
  362. max-width: 550px;
  363. margin: auto;
  364. padding: 50px;
  365. background: rgba(255, 255, 255, 0.25);
  366. backdrop-filter: blur(10px);
  367. border-radius: 10px;
  368. border: 1px solid rgba(255, 255, 255, 0.08);
  369. filter: drop-shadow(0px 20px 10px rgba(0, 0, 0, 0.3));
  370. }
  371. .team-member {
  372. position: relative;
  373. display: flex;
  374. align-items: center;
  375. flex-wrap: wrap;
  376. gap: 5px;
  377. min-height: 60px;
  378. padding-top: 4px;
  379. padding-bottom: 4px;
  380. padding-left: 15px;
  381. padding-right: 15px;
  382. background-color: #ffffff;
  383. border-radius: 25px;
  384. font-size: large;
  385. z-index: 1;
  386. }
  387. .team-member:hover {
  388. cursor: grab;
  389. }
  390. .team-member-avatar {
  391. width: 3.75rem;
  392. height: 3.75rem;
  393. object-fit: cover;
  394. border-radius: 50%;
  395. }
  396. .team-member-name {
  397. display: grid;
  398. gap: 0.125rem;
  399. }
  400. .team-member-name h3 {
  401. color: #2a70dc;
  402. font-size: large;
  403. }
  404. .team-member-name p {
  405. font-size: smaller;
  406. }
  407. .team-member-chosen {
  408. box-shadow: 8px 8px 32px rgba(0, 0, 0, 0.3);
  409. }
  410. .team-member-drag {
  411. opacity: 0;
  412. }
  413. .social-links {
  414. display: flex;
  415. flex-direction: row;
  416. gap: 6px;
  417. margin-left: auto;
  418. padding: 0;
  419. list-style-type: none;
  420. }
  421. .social-links i {
  422. width: 1.25rem;
  423. height: 1.25rem;
  424. font-size: 1.25rem;
  425. }
  426. `;
  427. document.head.appendChild(style);
  428. this.addWeekReportTips(article);
  429. new Sortable(article, {
  430. animation: 350,
  431. chosenClass: "team-member-chosen",
  432. dragClass: "team-member-drag",
  433. });
  434. const currentDate = new Date();
  435. const currentDay = currentDate.getDay();
  436. if (currentDay >= 5) {
  437. // TODO 对今天是周五的情况下,且周报也未获取到,继续处理
  438. }
  439. }
  440. // 去除不写周报的提示
  441. } catch (error) {
  442. console.error("Gitee客户端异常,获取周报失败");
  443. }
  444. this.$nextTick(() => {
  445. const img = document.querySelector(".zb");
  446. if (img) {
  447. img.addEventListener("click", this.showTableData);
  448. }
  449. });
  450. });
  451. this.send_todo_num_request()
  452. .then((issue_str) => {
  453. return this.send_issue_data_request(issue_str);
  454. })
  455. .then((issue) => {
  456. // 处理返回的 issue 数据
  457. this.issurDataTotal = issue;
  458. // 获取到的数据
  459. this.sun_count = this.issurDataTotal.total_count;
  460. if (
  461. this.issurDataTotal.total_count != 0 &&
  462. this.issurDataTotal.data.length > 0
  463. ) {
  464. for (let info of this.issurDataTotal.data) {
  465. // 截止时间
  466. if (info.deadline != null) {
  467. var currentTime = new Date();
  468. if (new Date(info.deadline) >= currentTime) {
  469. var time = this.get_hour_difference(info.deadline);
  470. if (time != null && time <= 24) {
  471. this.deadline_count++;
  472. }
  473. } else {
  474. // 逾期任务
  475. this.expired_count++;
  476. }
  477. }
  478. // 将数据分类,摘选出需求/任务/bug
  479. if (info.issue_type.id == 626337) {
  480. this.bug_count++;
  481. }
  482. if (info.issue_type.id == 626336) {
  483. this.feature_count++;
  484. }
  485. const validIssueTypeIds = new Set([
  486. 16690, 662615, 757073, 757074, 766555,
  487. ]);
  488. if (validIssueTypeIds.has(info.issue_type.id)) {
  489. this.task_count++;
  490. }
  491. }
  492. // 调用element-plus的通知,可以等待通知消息接收到再处理
  493. if (this.deadline_count > 0) {
  494. this.$notify({
  495. title: "贴心通知",
  496. type: "warning",
  497. message:
  498. "注意!您有24小时内需完成的任务,共 " +
  499. this.deadline_count +
  500. " 条",
  501. position: "bottom-right",
  502. showClose: false,
  503. offset: 50,
  504. duration: 3000,
  505. });
  506. }
  507. }
  508. })
  509. .catch((error) => {
  510. console.error("Gitee客户端异常", error);
  511. });
  512. // 工时获取,本周工时,上周工时
  513. this.get_week_time()
  514. .then((result) => {
  515. if (result != null) {
  516. var dates = result.dates;
  517. var all_registered_duration = result.all_registered_duration;
  518. var daily_registered_duration_count =
  519. result.daily_registered_duration_count;
  520. this.work_time = all_registered_duration;
  521. // 设置期限为本周
  522. this.allDate = dates;
  523. this.dateRange = [new Date(dates[0]), new Date(dates[6])];
  524. var registered_count = [];
  525. for (let i = 0; i < dates.length; i++) {
  526. var key = dates[i].replace(/"/g, "");
  527. var value = daily_registered_duration_count[key];
  528. registered_count[key] = value;
  529. }
  530. this.registered_map = registered_count;
  531. }
  532. })
  533. .catch(function (error) {
  534. console.error("Gitee客户端异常,获取工时失败");
  535. });
  536. this.get_last_week_time()
  537. .then((result) => {
  538. if (result != null) {
  539. var dates = result.dates;
  540. var all_registered_duration = result.all_registered_duration;
  541. this.last_work_time = all_registered_duration;
  542. }
  543. })
  544. .catch(function (error) {
  545. console.error("Gitee客户端异常,获取工时失败");
  546. });
  547. // 获取截止到本周日的所有工作任务,排除需求,并赋值给talbeData
  548. this.send_issue_week_data_request();
  549. },
  550. methods: {
  551. // 获取当前选中的选项
  552. handleSelectionChange(selection) {
  553. // 此处能够获取到当前选中的数据,我们可以通过将数据保存在一个新的数组中
  554. this.selectionDatas = selection;
  555. for (let index = 0; index < this.selectionDatas.length; index++) {
  556. const element = this.selectionDatas[index];
  557. console.log(element);
  558. }
  559. },
  560. // 显示任务清单表格
  561. showTableData() {
  562. this.showTable = !this.showTable;
  563. },
  564. // 隐藏多余按钮
  565. display_none_btn() {
  566. this.elements = document.querySelectorAll(
  567. ".ge-app-top-right .ge-app-top-nav"
  568. );
  569. for (let i = 0; i < this.elements.length; i++) {
  570. if (i === 0 || i === 1 || i === 3) {
  571. this.elements[i].style.display = "none";
  572. }
  573. }
  574. },
  575. // 创建GoogleChrome软件系统通知显示,需要开通GoogleChrome的通知权限
  576. showNotification(title, message) {
  577. var notification = new unsafeWindow.Notification(title, {
  578. body: message,
  579. icon: "https://e.gitee.com/assets/images/favicon.ico",
  580. });
  581. setTimeout(function () {
  582. notification.close();
  583. }, 4000);
  584. },
  585. // 获取周报状态
  586. get_week_reports() {
  587. const _this = this; // 保存正确的上下文
  588. const currentYear = new Date().getFullYear();
  589. return new Promise(function (resolve, reject) {
  590. _this
  591. .getRoluteStr()
  592. .then(function () {
  593. const xhr = new XMLHttpRequest();
  594. xhr.open(
  595. "GET",
  596. "https://api.gitee.com/enterprises/" +
  597. _this.roult_path +
  598. "/week_reports/my_reports?year=" +
  599. currentYear,
  600. true
  601. );
  602. // 设置XMLHttpRequest自动获取Cookie
  603. xhr.withCredentials = true;
  604.  
  605. xhr.onload = function () {
  606. if (xhr.readyState === 4) {
  607. if (xhr.status === 200) {
  608. const respbody = JSON.parse(xhr.responseText);
  609. const current_week = respbody.data[0];
  610. const last_week = respbody.data[1];
  611. resolve({
  612. current_week: current_week,
  613. last_week: last_week,
  614. });
  615. } else {
  616. reject("Gitee客户端异常");
  617. }
  618. }
  619. };
  620.  
  621. xhr.onerror = function () {
  622. reject("周报获取异常");
  623. };
  624.  
  625. // 发送请求
  626. xhr.send(null);
  627. })
  628. .catch(function (error) {
  629. reject(error);
  630. });
  631. });
  632. },
  633. // 获取todo_num数量
  634. send_todo_num_request() {
  635. const _this = this;
  636. return new Promise(async function (resolve, reject) {
  637. await _this.getRoluteStr();
  638. var xhr = new XMLHttpRequest();
  639. xhr.open(
  640. "GET",
  641. "https://api.gitee.com/enterprises/" +
  642. _this.roult_path +
  643. "/issues/stat_count?todo=true&today=true&week=true&overdue=true&star=true&all=true",
  644. true
  645. );
  646. // 设置XMLHttpRequest 自动获取Cookie
  647. xhr.withCredentials = true;
  648. xhr.onload = function (e) {
  649. if (xhr.readyState === 4) {
  650. if (xhr.status === 200) {
  651. var respbody = JSON.parse(xhr.responseText);
  652. var issue_str = respbody.todo;
  653. resolve(issue_str); // 将获取到的值传递给 Promise 的 resolve 方法
  654. } else {
  655. reject("Gitee客户端异常");
  656. }
  657. }
  658. };
  659. xhr.onerror = function (e) {
  660. reject("信息获取异常");
  661. };
  662. // 发送请求
  663. xhr.send(null);
  664. });
  665. },
  666. // 获取任务总集合
  667. send_issue_data_request(todo_nums) {
  668. const _this = this;
  669. return new Promise(async function (resolve, reject) {
  670. await _this.getRoluteStr();
  671. var xhr = new XMLHttpRequest();
  672. xhr.open(
  673. "GET",
  674. "https://api.gitee.com/enterprises/" +
  675. _this.roult_path +
  676. "/issues?state=open,progressing&only_related_me=1&page=1&offset=0&per_page=" +
  677. todo_nums,
  678. true
  679. );
  680. // 设置XMLHttpRequest 自动获取Cookie
  681. xhr.withCredentials = true;
  682. xhr.onload = function (e) {
  683. if (xhr.readyState === 4) {
  684. if (xhr.status === 200) {
  685. var work_json = xhr.responseText;
  686. var issueData = new issue_data();
  687. issueData = JSON.parse(work_json);
  688. var issue = Object.assign(new issue_data(), issueData);
  689. resolve(issue);
  690. } else {
  691. reject("Gitee客户端异常");
  692. }
  693. }
  694. };
  695. xhr.onerror = function (e) {
  696. reject("信息获取异常");
  697. };
  698. // 发送请求
  699. xhr.send(null);
  700. });
  701. },
  702. // 获取本周任务总集合
  703. send_issue_week_data_request() {
  704. const _this = this;
  705. return new Promise(async function (resolve, reject) {
  706. await _this.getRoluteStr();
  707. var xhr = new XMLHttpRequest();
  708. xhr.open(
  709. "GET",
  710. "https://api.gitee.com/enterprises/" +
  711. _this.roult_path +
  712. "/issues?deadline_type=week&only_related_me=1",
  713. true
  714. );
  715. // 设置XMLHttpRequest 自动获取Cookie
  716. xhr.withCredentials = true;
  717. xhr.onload = function (e) {
  718. if (xhr.readyState === 4) {
  719. if (xhr.status === 200) {
  720. var work_json = xhr.responseText;
  721. var issueData = new issue_data();
  722. issueData = JSON.parse(work_json);
  723. for (let index = 0; index < issueData.data.length; index++) {
  724. const element = issueData.data[index];
  725. // 需要是自己的任务
  726. if (
  727. element.assignee.id ==
  728. JSON.parse(localStorage.getItem("gitee.user")).userInfo.id
  729. ) {
  730. // 不需要计算需求类型
  731. if (element.issue_type.id != 626336) {
  732. _this.tableData.push(element);
  733. }
  734. }
  735. }
  736. var issue = Object.assign(new issue_data(), issueData);
  737. resolve(issue);
  738. } else {
  739. reject("Gitee客户端异常");
  740. }
  741. }
  742. };
  743. xhr.onerror = function (e) {
  744. reject("信息获取异常");
  745. };
  746. // 发送请求
  747. xhr.send(null);
  748. });
  749. },
  750. // 计算时间差
  751. get_hour_difference(deadline) {
  752. var currentTime = new Date();
  753. var specifiedTime = new Date(deadline);
  754. if (currentTime <= specifiedTime) {
  755. var diffMs = specifiedTime - currentTime;
  756. var diffHours = Math.floor(diffMs / 1000 / 60 / 60);
  757. return diffHours;
  758. }
  759. return null;
  760. },
  761. // 获取工时状态
  762. get_week_time() {
  763. // 获取当前日期
  764. var currentDate = new Date();
  765. // 获取当前日期是一周中的第几天(0-6,其中0表示星期日)
  766. var currentDay = currentDate.getDay();
  767. // 计算当前一周的第一天和最后一天的日期
  768. var firstDayOfWeek = new Date(
  769. currentDate.setDate(currentDate.getDate() - currentDay + 1)
  770. );
  771. var lastDayOfWeek = new Date(
  772. currentDate.setDate(currentDate.getDate() - currentDay + 7)
  773. );
  774. // 创建一个数组来存储一周的日期
  775. var weekDates = [];
  776. // 循环获取一周的日期并将其存入数组
  777. for (var i = 0; i <= 6; i++) {
  778. var date = new Date(firstDayOfWeek);
  779. date.setDate(firstDayOfWeek.getDate() + i);
  780. weekDates.push(date);
  781. }
  782. // 遍历时间,格式化日期为"YYYY-MM-DD"的格式
  783. var formattedDates = weekDates.map(function (date) {
  784. var year = date.getFullYear();
  785. var month = ("0" + (date.getMonth() + 1)).slice(-2);
  786. var day = ("0" + date.getDate()).slice(-2);
  787. return year + "-" + month + "-" + day;
  788. });
  789. // 当前一周的日期,传入工时接口
  790. const _this = this;
  791. return new Promise(async function (resolve, reject) {
  792. await _this.getRoluteStr();
  793. var xhr = new XMLHttpRequest();
  794. xhr.open(
  795. "GET",
  796. "https://api.gitee.com/enterprises/" +
  797. _this.roult_path +
  798. "/statistics/user_daily_workloads_overview?search=" +
  799. JSON.parse(localStorage.getItem("gitee.user")).userInfo
  800. .username +
  801. "&start_date=" +
  802. formattedDates[0] +
  803. "&end_date=" +
  804. formattedDates[6],
  805. true
  806. );
  807. xhr.withCredentials = true;
  808. xhr.onload = function (e) {
  809. if (xhr.readyState === 4) {
  810. if (xhr.status === 200) {
  811. var respbody = JSON.parse(xhr.responseText);
  812. var all_registered_duration =
  813. respbody.all_registered_duration;
  814. var daily_registered_duration_count =
  815. respbody.daily_registered_duration_count;
  816. var dates = respbody.dates;
  817. resolve({
  818. all_registered_duration: all_registered_duration,
  819. daily_registered_duration_count:
  820. daily_registered_duration_count,
  821. dates: dates,
  822. });
  823. } else {
  824. reject("Gitee客户端异常");
  825. }
  826. }
  827. };
  828. xhr.onerror = function (e) {
  829. reject("工时获取异常");
  830. };
  831. xhr.send(null);
  832. });
  833. },
  834. // 获取上周的工时
  835. get_last_week_time() {
  836. // 获取当前日期
  837. var currentDate = new Date();
  838. // 计算上周的第一天和最后一天的日期
  839. var firstDayOfLastWeek = new Date(
  840. currentDate.setDate(
  841. currentDate.getDate() - currentDate.getDay() - 6
  842. )
  843. );
  844. var lastDayOfLastWeek = new Date(
  845. currentDate.setDate(currentDate.getDate() - currentDate.getDay())
  846. );
  847. // 创建一个数组来存储上周的日期
  848. var weekDates = [];
  849. // 循环获取上周的日期并将其存入数组
  850. for (var i = 0; i <= 6; i++) {
  851. var date = new Date(firstDayOfLastWeek);
  852. date.setDate(firstDayOfLastWeek.getDate() + i);
  853. weekDates.push(date);
  854. }
  855. // 遍历时间,格式化日期为"YYYY-MM-DD"的格式
  856. var formattedDates = weekDates.map(function (date) {
  857. var year = date.getFullYear();
  858. var month = ("0" + (date.getMonth() + 1)).slice(-2);
  859. var day = ("0" + date.getDate()).slice(-2);
  860. return year + "-" + month + "-" + day;
  861. });
  862. // 当前一周的日期,传入工时接口
  863. const _this = this;
  864. return new Promise(async function (resolve, reject) {
  865. await _this.getRoluteStr();
  866. var xhr = new XMLHttpRequest();
  867. xhr.open(
  868. "GET",
  869. "https://api.gitee.com/enterprises/" +
  870. _this.roult_path +
  871. "/statistics/user_daily_workloads_overview?search=" +
  872. JSON.parse(localStorage.getItem("gitee.user")).userInfo
  873. .username +
  874. "&start_date=" +
  875. formattedDates[0] +
  876. "&end_date=" +
  877. formattedDates[6],
  878. true
  879. );
  880. xhr.withCredentials = true;
  881. xhr.onload = function (e) {
  882. if (xhr.readyState === 4) {
  883. if (xhr.status === 200) {
  884. var respbody = JSON.parse(xhr.responseText);
  885. var all_registered_duration =
  886. respbody.all_registered_duration;
  887. var daily_registered_duration_count =
  888. respbody.daily_registered_duration_count;
  889. var dates = respbody.dates;
  890. resolve({
  891. all_registered_duration: all_registered_duration,
  892. daily_registered_duration_count:
  893. daily_registered_duration_count,
  894. dates: dates,
  895. });
  896. } else {
  897. reject("上周工时获取异常");
  898. }
  899. }
  900. };
  901. xhr.onerror = function (e) {
  902. reject("上周工时获取异常");
  903. };
  904. xhr.send(null);
  905. });
  906. },
  907. showCalendarOnMouseover() {
  908. this.showCalendar = true;
  909. },
  910. isSpecifiedDate(date) {
  911. // 根据你的指定日期进行判断逻辑
  912. var current_time = new Date(date);
  913. const specifiedDate = new Date();
  914. // 分别获取日期对象的年、月、日
  915. const yearMatched =
  916. current_time.getFullYear() === specifiedDate.getFullYear();
  917. const monthMatched =
  918. current_time.getMonth() === specifiedDate.getMonth();
  919. const dayMatched = current_time.getDate() === specifiedDate.getDate();
  920. // 判断年、月、日是否都匹配
  921. return yearMatched && monthMatched && dayMatched;
  922. },
  923. isInAllDate(dateTime) {
  924. // 获取当前日期
  925. var currentDate = new Date();
  926.  
  927. // 获取当前日期是一周中的第几天(0-6,其中0表示星期日)
  928. var currentDay = currentDate.getDay();
  929.  
  930. // 计算当前一周的第一天和最后一天的日期
  931. var firstDayOfWeek = new Date(
  932. currentDate.setDate(currentDate.getDate() - currentDay + 1)
  933. );
  934. var lastDayOfWeek = new Date(
  935. currentDate.setDate(currentDate.getDate() - currentDay + 7)
  936. );
  937.  
  938. // 创建一个数组来存储一周的日期
  939. var weekDates = [];
  940.  
  941. // 循环获取一周的日期并将其存入数组
  942. for (var i = 0; i <= 6; i++) {
  943. var date = new Date(firstDayOfWeek);
  944. date.setDate(firstDayOfWeek.getDate() + i);
  945. weekDates.push(date);
  946. }
  947.  
  948. // 格式化日期为"YYYY-MM-DD"的格式
  949. var formattedDates = weekDates.map(function (date) {
  950. var year = date.getFullYear();
  951. var month = ("0" + (date.getMonth() + 1)).slice(-2);
  952. var day = ("0" + date.getDate()).slice(-2);
  953. return year + "-" + month + "-" + day;
  954. });
  955. if (formattedDates.includes(dateTime)) {
  956. return true;
  957. } else {
  958. return false;
  959. }
  960. },
  961. getRoluteStr() {
  962. const _this = this;
  963. return new Promise(function (resolve, reject) {
  964. var enterprisePath = localStorage.getItem("enterprisePath");
  965. var xhr = new XMLHttpRequest();
  966. xhr.open(
  967. "GET",
  968. "https://api.gitee.com/enterprises/basic_info?enterprise_path=" +
  969. enterprisePath,
  970. true
  971. );
  972. xhr.withCredentials = true;
  973. xhr.onload = function (e) {
  974. if (xhr.readyState === 4) {
  975. if (xhr.status === 200) {
  976. var respbody = JSON.parse(xhr.responseText);
  977. var enterprises = respbody.enterprises;
  978. const result = enterprises.find(
  979. (obj) => obj.path === enterprisePath
  980. );
  981. resolve({ id: result.id });
  982. } else {
  983. reject("公司id获取异常");
  984. }
  985. }
  986. };
  987. xhr.onerror = function (e) {
  988. reject("上周工时获取异常");
  989. };
  990. xhr.send(null);
  991. });
  992. },
  993. getNoUseElement() {
  994. return new Promise((resolve, reject) => {
  995. const observer = new MutationObserver((mutationsList, observer) => {
  996. const element = document.querySelector(
  997. ".level-label.level-label--standard"
  998. );
  999. const avator = document.querySelector(".nav-item.user");
  1000. const reportView = document.querySelector(".reports-view");
  1001. const topNav = document.querySelectorAll(
  1002. ".ge-app-top-right .ge-app-top-nav"
  1003. );
  1004. if (element && avator && topNav && reportView) {
  1005. observer.disconnect(); // 停止观察DOM变化
  1006. resolve({ element, avator, topNav, reportView });
  1007. }
  1008. });
  1009. observer.observe(document.body, {
  1010. attributes: true,
  1011. childList: true,
  1012. subtree: true,
  1013. });
  1014. setTimeout(() => {
  1015. observer.disconnect();
  1016. reject(new Error("超时,未找到组件"));
  1017. }, 5000);
  1018. });
  1019. },
  1020. async hideComp() {
  1021. try {
  1022. const { element, avator, topNav, reportView } =
  1023. await this.getNoUseElement();
  1024. element.innerHTML = "Plus";
  1025. element.style.background = "linear-gradient(90deg,#c9e7ff,#f3bc4c)";
  1026. element.style.fontSize = "16px";
  1027. element.style.color = "#093978";
  1028. const svgContainer = document.createElement("div");
  1029. 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>`;
  1030. avator.appendChild(svgContainer);
  1031. avator.style.position = "relative";
  1032. svgContainer.style.position = "absolute";
  1033. svgContainer.style.top = "3px";
  1034. svgContainer.style.left = "12px";
  1035. for (let i = 0; i < topNav.length; i++) {
  1036. if (i === 0 || i === 1 || i === 3) {
  1037. topNav[i].style.display = "none";
  1038. }
  1039. }
  1040. reportView.style.display = "flex";
  1041. } catch (error) {
  1042. console.error(error);
  1043. }
  1044. },
  1045. getWeekReportElement() {
  1046. return new Promise((resolve, reject) => {
  1047. const element = document.querySelector(".reports-view");
  1048. const ele = document.querySelector(".markdown-body.text-disabled");
  1049.  
  1050. if (element && ele) {
  1051. resolve({ element, ele });
  1052. } else {
  1053. const observer = new MutationObserver(
  1054. (mutationsList, observer) => {
  1055. const element = document.querySelector(".reports-view");
  1056. const ele = document.querySelector(
  1057. ".markdown-body.text-disabled"
  1058. );
  1059.  
  1060. if (element && ele) {
  1061. observer.disconnect();
  1062. resolve({ element, ele });
  1063. }
  1064. }
  1065. );
  1066.  
  1067. observer.observe(document.body, {
  1068. attributes: true,
  1069. childList: true,
  1070. subtree: true,
  1071. });
  1072.  
  1073. setTimeout(() => {
  1074. observer.disconnect();
  1075. reject(new Error("超时,未找到组件"));
  1076. }, 10000);
  1077. }
  1078. });
  1079. },
  1080. // api信息
  1081. chatAI() {
  1082. const _this = this; // 保存正确的上下文
  1083. _this.pushLoading = true;
  1084. var datas = _this.selectionDatas //选中的数据
  1085. var sendStr = "";
  1086. var respHtml = "";
  1087. _this.textarea // 文本域数据
  1088. _this.push // 直接推送开关
  1089. // 根据上面条件,进行逻辑处理
  1090. if (datas) {
  1091. for (let index = 0; index < datas.length; index++) {
  1092. const element = datas[index];
  1093. sendStr = sendStr + "完成了" + element.title + ";\n"
  1094. }
  1095. }
  1096. // 追加文本域内容
  1097. sendStr += _this.textarea + "\n下面,请按照我给的周报模版,根据上面的信息,给我生成一份精美的周报,丰富我的语句,语言表达清楚,你要表达的完美,老板能够理解我上面的语句\n### 本周工作总结\n1.\n#### 存在问题\n1.\n### 下周工作计划\n1.\n#### 需要支持\n1.";
  1098. var dataToSend = {
  1099. prompt: sendStr,
  1100. options: {
  1101. parentMessageId: ""
  1102. },
  1103. systemMessage: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
  1104. temperature: 0.8,
  1105. top_p: 1
  1106. };
  1107. GM_xmlhttpRequest({
  1108. method: 'POST',
  1109. url: 'http://w9.xjai.cc/api/chat-process',
  1110. data: JSON.stringify(dataToSend),
  1111. headers: {
  1112. 'Content-Type': 'application/json'
  1113. },
  1114. onload: function (response) {
  1115. if (response.status === 200) {
  1116. const resp = response.responseText;
  1117. let splittedText = resp.split("&KFw6loC9Qvy&");
  1118. respHtml = splittedText[1]
  1119. if (_this.push) {
  1120. // 获取今天的日期
  1121. let now = new Date();
  1122. // 获取当前年份
  1123. let currentYear = now.getFullYear();
  1124. // 获取今年的第一天
  1125. let startOfYear = new Date(now.getFullYear(), 0, 1);
  1126. // 计算今天是今年的第几天
  1127. let diff = now.getTime() - startOfYear.getTime();
  1128. let oneDay = 1000 * 60 * 60 * 24;
  1129. let dayOfYear = Math.floor(diff / oneDay) + 1;
  1130. // 计算今天是第几周
  1131. let weekNumber = Math.ceil(dayOfYear / 7);
  1132.  
  1133. var xhr = new XMLHttpRequest();
  1134. const contentText = {
  1135. content: respHtml,
  1136. pull_request_ids: [],
  1137. issue_ids: [],
  1138. event_ids: []
  1139. }
  1140. xhr.open(
  1141. "PUT",
  1142. "https://api.gitee.com/enterprises/" + _this.roult_path + "/week_reports/" + JSON.parse(localStorage.getItem("gitee.user")).userInfo.username + "/" + currentYear + "/" + weekNumber,
  1143. true
  1144. );
  1145. xhr.setRequestHeader('Content-Type', 'application/json');
  1146. xhr.withCredentials = true;
  1147. xhr.onload = function (e) {
  1148. debugger;
  1149. if (xhr.readyState === 4) {
  1150. if (xhr.status === 200) {
  1151. _this.pushLoading = false;
  1152. _this.showTable = !_this.showTable;
  1153. _this.$message({
  1154. type: "success",
  1155. message: "直接推送成功"
  1156. });
  1157. } else {
  1158. _this.pushLoading = false;
  1159. _this.$message({
  1160. type: "error",
  1161. message: "直接推送失败"
  1162. });
  1163. }
  1164. }
  1165. };
  1166. xhr.onerror = function (e) {
  1167. };
  1168. xhr.send(JSON.stringify(contentText));
  1169. } else {
  1170. _this.pushLoading = false;
  1171. this.$message({
  1172. type: "success",
  1173. message: "直接推送成功"
  1174. });
  1175. _this.showTable = !_this.showTable;
  1176. }
  1177. } else {
  1178. // _this.pushLoading = false;
  1179. console.error('GPT网络异常:', response.status);
  1180. }
  1181. },
  1182. onerror: function (err) {
  1183. // _this.pushLoading = false;
  1184. console.error('发送错误,请重试', err);
  1185. }
  1186. });
  1187. },
  1188. async addWeekReportTips(marquee) {
  1189. try {
  1190. const { element, ele } = await this.getWeekReportElement();
  1191. element.appendChild(marquee);
  1192. ele.style.display = "none";
  1193. } catch (error) {
  1194. console.error(error);
  1195. }
  1196. },
  1197. },
  1198. };
  1199. const app = Vue.createApp(App);
  1200. app.use(ElementPlus);
  1201. app.mount("#app");
  1202. };
  1203. })();