GitLab Assistant

GitLab Viewer Publish and Deploy Project!

当前为 2023-10-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitLab Assistant
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.09999
  5. // @description GitLab Viewer Publish and Deploy Project!
  6. // @author Sean
  7. // @match http://192.168.0.200*
  8. // @match http://192.168.0.200/*
  9. // @match http://192.168.0.200/fe3project/*
  10. // @match http://192.168.0.200/frontend_pc/project/*
  11. // @match https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplatesdetail*
  12. // @match https://oa.epoint.com.cn/interaction-design-portal/portal/pages/generalpagetemplates/generalpagetemplatesdetail*
  13. // @match https://oa.epoint.com.cn/interaction-design-portal/portal/pages/dynamiceffecttemplates/dynamiceffecttemplatesdetail*
  14. // @match http://192.168.201.159:9999/webapp/pages/default/onlinecase.html*
  15. // @match http://192.168.118.60:9999/webapp/pages/caselib/create.html*
  16. // @match https://oa.epoint.com.cn/epointoa9/frame/fui/pages/themes/aide/aide*
  17. // @match https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplateslist*
  18. // @match https://oa.epoint.com.cn:8080/OA9/oa9/mail/mailreceivedetail*
  19. // @match https://oa.epoint.com.cn/productrelease/cpzt/demandmanageznsb/demandbasicinfo_detail*
  20. // @match https://greasyfork.org/zh-CN/scripts/466808/versions/new*
  21. // @icon http://192.168.0.200/assets/favicon-7901bd695fb93edb07975966062049829afb56cf11511236e61bcf425070e36e.png
  22. // @require https://cdn.bootcdn.net/ajax/libs/jszip/3.7.1/jszip.min.js
  23. // @grant GM_getResourceURL
  24. // @grant GM_addStyle
  25. // @grant GM_getResourceText
  26. // @resource ElementCSS https://gitassest.oss-cn-shanghai.aliyuncs.com/base/element-ui.css
  27. // @grant GM_xmlhttpRequest
  28. // @license MIT
  29. // @run-at document-end
  30. // ==/UserScript==
  31.  
  32. (function() {
  33. 'use strict';
  34. // @require 不允许加入,改成动态插入
  35. const script = document.createElement('script');
  36. script.src = 'https://gitassest.oss-cn-shanghai.aliyuncs.com/base/vue_2.7.14.min.js';
  37. document.body.appendChild(script);
  38. const script2 = document.createElement('script');
  39. script2.src = 'https://gitassest.oss-cn-shanghai.aliyuncs.com/base/element-ui.js';
  40. document.body.appendChild(script2);
  41. })();
  42.  
  43. // 个性化 gitlab 样式,
  44. // 满足项目详情多行显示,
  45. // 项目列表中的链接新窗口打开,
  46. // 搜索框 placeholder 个性化提示
  47. // 增加CodePipeline 入口等
  48. /*
  49. @require https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js
  50. @require https://unpkg.com/element-ui/lib/index.js
  51. @resource ElementCSS https://unpkg.com/element-ui/lib/theme-chalk/index.css
  52. */
  53. (function() {
  54. 'use strict';
  55.  
  56. let regs = [/^http:\/\/192\.168\.0\.200\/fe3project\//,
  57. /^http:\/\/192\.168\.0\.200\/frontend_pc\/project\//,
  58. /^http:\/\/192\.168\.0\.200/,
  59. /^http:\/\/192\.168\.0\.200\//];
  60. let match = false;
  61.  
  62. for(let r = 0, lr = regs.length; r < lr; r++) {
  63. if(regs[r].test(location.href)) {
  64. match = true;
  65. break;
  66. }
  67. }
  68.  
  69. if(!match) {
  70. return;
  71. }
  72.  
  73. // 注入样式:改变容器宽度,项目描述多行展示
  74. let injectStyle = ".group-list-tree .group-row-contents .description p { white-space: normal; } .container-limited.limit-container-width { max-width: 1400px } .limit-container-width .info-well {max-width: none;}";
  75.  
  76. injectStyle += ".container-fluid.container-limited.limit-container-width .file-holder.readme-holder.limited-width-container .file-content {max-width: none;}"
  77. injectStyle += 'button:focus {outline-color: transparent !important;}'
  78. injectStyle += '.has-description .description {word-break: break-all;}'
  79. // 添加注入样式
  80. let extraStyleElement = document.createElement("style");
  81. extraStyleElement.innerHTML = injectStyle;
  82. document.head.appendChild(extraStyleElement);
  83.  
  84. //const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  85. const fontUrl = 'http://s2cr8jvei.hd-bkt.clouddn.com/gitlabassest/element-icons.535877f.woff';
  86.  
  87. // 添加样式规则,将字体应用到指定元素上
  88. GM_addStyle(`
  89. @font-face {
  90. font-family: element-icons;
  91. src: url(${fontUrl}) format("woff");
  92. }
  93. `);
  94.  
  95. GM_addStyle(GM_getResourceText('ElementCSS'));
  96.  
  97. // 改变列表打开链接方式,改为新窗口打开
  98. let change = false;
  99. let tryTimes = 3;
  100.  
  101. function changeOpenType() {
  102. if(!change){
  103. setTimeout(()=> {
  104. let links = document.querySelectorAll('.description a');
  105. if(links.length) {
  106. for(let i = 0, l = links.length; i < l; i++) {
  107. links[i].target = "_blank";
  108. if(i === l - 1) {
  109. change = true;
  110. }
  111. }
  112. } else {
  113. changeOpenType();
  114. }
  115. }, 1000);
  116. }
  117. }
  118.  
  119. function stopLinkProp() {
  120. setTimeout(()=> {
  121. const links = document.querySelectorAll('.description a');
  122. for(let i = 0, l = links.length; i < l; i++) {
  123. links[i].addEventListener('click', ()=> {
  124. event.stopPropagation();
  125. });
  126. }
  127. }, 1000);
  128. }
  129.  
  130. // 等待页面加载完成
  131. window.addEventListener('load', function() {
  132.  
  133. var targetDiv = document.querySelector('section');
  134.  
  135. if(targetDiv) {
  136. // 创建一个 Mutation Observer 实例
  137. var observer = new MutationObserver(function(mutations) {
  138. // 在这里处理 div 子元素的变化
  139. mutations.forEach(function(mutation) {
  140. if(mutation.addedNodes && mutation.addedNodes.length) {
  141. change = false;
  142. changeOpenType();
  143.  
  144. stopLinkProp();
  145. }
  146. });
  147. });
  148.  
  149. // 配置 Mutation Observer
  150. var config = { childList: true, subtree: true };
  151.  
  152. // 开始观察目标 div 元素
  153. observer.observe(targetDiv, config);
  154. }
  155.  
  156. const placeholder = document.createElement('div');
  157.  
  158. // 创建 Vue 实例并挂载到页面
  159. const vueInstance = new Vue({
  160. el: placeholder,
  161. methods: {
  162. // 进入管理平台 code pipeline
  163. manage() {
  164. window.open('http://192.168.219.170/code-pipeline')
  165. }
  166. },
  167. template: `<div id="my-ext" style="margin-top:4px;">
  168. <el-tooltip content="进入 Code Pipeline 管理平台" placement="top" effect="light">
  169. <el-button type="primary" icon="el-icon-attract" size="small" circle @click="manage"></el-button>
  170. </el-tooltip>
  171. </div>`
  172. });
  173.  
  174. // 将占位元素追加到 body 元素中
  175. document.querySelector('.title-container').appendChild(vueInstance.$el);
  176.  
  177. // 修改 placehodler
  178. const listInput = document.getElementById('group-filter-form-field');
  179. const listInput2 = document.getElementById('project-filter-form-field');
  180.  
  181. if(listInput) {
  182. listInput.setAttribute("placeholder", "按项目名称、日期、开发者搜索,关键字≥3");
  183. listInput.style.width = '305px';
  184. }
  185. if(listInput2) {
  186. listInput2.setAttribute("placeholder", "按项目名称、日期、开发者搜索,关键字≥3");
  187. listInput2.style.width = '305px';
  188. }
  189. });
  190.  
  191.  
  192. })();
  193.  
  194. // 公共方法
  195. (function(){
  196. function convertDateFormat(inputString) {
  197. // 匹配日期格式为yyyy-mm-dd或yyyy-m-dd或yyyy-mm-d或yyyy-m-d的正则表达式
  198. const dateRegex = /\d{4}-\d{1,2}-\d{1,2}/g;
  199.  
  200. // 找到所有匹配的日期格式
  201. const dates = inputString.match(dateRegex);
  202.  
  203. // 如果没有匹配到日期,则直接返回原始字符串
  204. if (!dates || dates.length === 0) {
  205. return inputString;
  206. }
  207.  
  208. // 遍历所有匹配到的日期,进行转换
  209. dates.forEach((date) => {
  210. const [year, month, day] = date.split('-');
  211. const formattedDate = `${parseInt(year, 10)}-${parseInt(month, 10)}-${parseInt(day, 10)}`;
  212. inputString = inputString.replace(date, formattedDate);
  213. });
  214.  
  215. return inputString;
  216. }
  217.  
  218. function getUrlParameters() {
  219. var params = {};
  220. var search = window.location.search.substring(1);
  221. var urlParams = search.split('&');
  222.  
  223. for (var i = 0; i < urlParams.length; i++) {
  224. var param = urlParams[i].split('=');
  225. var paramName = decodeURIComponent(param[0]);
  226. var paramValue = decodeURIComponent(param[1] || '');
  227. if(paramName) {
  228. params[paramName] = paramValue;
  229. }
  230. }
  231.  
  232. return params;
  233. }
  234.  
  235. // 检查脚本更新
  236. GM_xmlhttpRequest({
  237. method: 'GET',
  238. url: 'http://192.168.0.200/fe3group/gitlabassistant-web/-/raw/main/version.json',
  239. headers: {
  240. 'Content-Type': 'application/json; charset=utf-8'
  241. },
  242. onload: function(res) {
  243. const data = JSON.parse(res.response);
  244.  
  245. const version = GM_info.script.version;
  246. // 有新版本
  247. if(parseInt(version.replace(/\./g, '')) < parseInt(data.version.replace(/\./g, ''))) {
  248. const updateConfirm = confirm("Gitlab Assistant 脚本有更新,建议更新!");
  249. if (updateConfirm == true){
  250. window.open('https://greasyfork.org/zh-CN/scripts/466808-gitlab-assistant')
  251. }
  252. }
  253. }
  254. });
  255.  
  256. /*
  257. * 获取分支列表
  258. */
  259. function getBranches (fn) {
  260. GM_xmlhttpRequest({
  261. method: 'GET',
  262. url: location.href.split('/-/')[0] + '/refs',
  263. headers: {
  264. 'Content-Type': 'application/json; charset=utf-8'
  265. },
  266. onload: function(res) {
  267. const data = JSON.parse(res.response);
  268. const branches = data.Branches;
  269.  
  270. if(branches) {
  271. fn && fn(branches);
  272. }
  273. }
  274. });
  275. }
  276.  
  277. window.convertDateFormat = convertDateFormat;
  278.  
  279. window.gitlabUtil = {
  280. getUrlParameters: getUrlParameters,
  281. getBranches: getBranches
  282. }
  283. })();
  284.  
  285. // GitLab Viewer Publish and Deploy Project
  286. // 查看项目、部署项目、发布项目功能
  287. // 添加搜索设计门户资源功能
  288. (function() {
  289. 'use strict';
  290. let regs = [/^http:\/\/192\.168\.0\.200\/fe3project\//,
  291. /^http:\/\/192\.168\.0\.200\/frontend_pc\/project\//,
  292. /^http:\/\/192\.168\.0\.200\/fepublic\//];
  293. let match = false;
  294.  
  295. for(let r = 0, lr = regs.length; r < lr; r++) {
  296. if(regs[r].test(location.href)) {
  297. match = true;
  298. break;
  299. }
  300. }
  301.  
  302. if(!match) {
  303. return;
  304. }
  305. /*
  306. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  307.  
  308. // 添加样式规则,将字体应用到指定元素上
  309. GM_addStyle(`
  310. @font-face {
  311. font-family: element-icons;
  312. src: url(${fontUrl}) format("woff");
  313. }
  314. `);
  315.  
  316. GM_addStyle(GM_getResourceText('ElementCSS'));
  317. */
  318.  
  319. let epointCss = ".epoint-tool {position: fixed; bottom: 0%; right:10px; transform: translateY(-40%);}";
  320. epointCss += ".el-row { padding: 6px 0;} .el-dialog__body .el-tree{min-height: 420px; max-height: 500px;overflow: auto;}";
  321. epointCss += ".view-toolbar {padding-bottom: 10px;}";
  322. epointCss += ".deploy-body {height: 306px;}"
  323. epointCss += ".el-loading-spinner {margin-top: -60px;} .el-button--primary:focus {outline: 0 !important;}";
  324.  
  325. // 添加注入样式
  326. let extraStyleElement = document.createElement("style");
  327. extraStyleElement.innerHTML = epointCss;
  328. document.head.appendChild(extraStyleElement);
  329.  
  330. const MyComponent = {
  331. template: `<div class="epoint-wrap">
  332. <div class="epoint-tool">
  333. <el-row>
  334. <el-tooltip content="查看项目页面和模块结构" placement="left" effect="light">
  335. <el-button type="primary" icon="el-icon-search" round @click="viewProject">查看</el-button>
  336. </el-tooltip>
  337. </el-row>
  338. <el-row>
  339. <el-tooltip content="一键部署到170服务器" placement="left" effect="light">
  340. <el-button type="primary" icon="el-icon-s-unfold" round @click="doDeploy">部署</el-button>
  341. </el-tooltip>
  342. </el-row>
  343. <el-row>
  344. <el-tooltip content="一键发布到项目案例库" placement="left" effect="light">
  345. <el-button type="primary" icon="el-icon-upload" round @click="publish">发布</el-button>
  346. </el-tooltip>
  347. </el-row>
  348. <el-row>
  349. <el-tooltip content="进入 Code Pipeline 管理平台进行更多操作" placement="left" effect="light">
  350. <el-button type="primary" icon="el-icon-attract" round @click="manage">管理</el-button>
  351. </el-tooltip>
  352. </el-row>
  353. </div>
  354. <el-dialog
  355. title="目录结构"
  356. width="900px"
  357. :append-to-body="true"
  358. :visible.sync="dialogVisible"
  359. :before-close="handleClose">
  360. <div class="view-body">
  361. <div class="view-toolbar" v-if="projectFtpUrl"><el-button type="primary" size="small" @click="viewAll">查看全部</el-button></div>
  362. <div class="view-content">
  363. <el-tree
  364. class="filter-tree"
  365. :data="data"
  366. :props="defaultProps"
  367. node-key="id"
  368. default-expand-all
  369. @node-click="handleNodeClick"
  370. v-loading="loadingTree"
  371. element-loading-background="rgba(255, 255, 255, 1)"
  372. element-loading-text="拼命加载中......"
  373. ref="tree">
  374. </el-tree>
  375. </div>
  376. </div>
  377. </el-dialog>
  378. <el-dialog
  379. title="部署"
  380. width="420px"
  381. :visible.sync="depDialogVisible">
  382. <div class="deploy-body"
  383. v-loading="loading"
  384. element-loading-text="正在打包部署至 170 服务器,请耐心等待"
  385. element-loading-spinner="el-icon-loading">
  386. </div>
  387. </el-dialog>
  388. <el-dialog title="部署提示" width="640px" :visible.sync="dialogDeployVisible">
  389. <el-alert
  390. title="此操作将把 GitLab 资源打包部署至 170 服务器,已部署过的项目会进行覆盖部署,是否继续?"
  391. type="warning" :closable="false" style="margin-bottom: 20px;">
  392. </el-alert>
  393. <el-form :model="form" ref="form" :rules="rules">
  394. <el-form-item label="框架类型" :label-width="formLabelWidth" prop="frame">
  395. <el-select v-model="form.frame" placeholder="请框架类型">
  396. <el-option v-for="item in framework" :key="item.value" :label="item.label" :value="item.value"></el-option>
  397. </el-select>
  398. </el-form-item>
  399. <el-form-item label="分支" :label-width="formLabelWidth" prop="branch">
  400. <el-select v-model="form.branch" placeholder="请选择分支">
  401. <el-option v-for="item in branches" :key="item.value" :label="item.label" :value="item.value"></el-option>
  402. </el-select>
  403. </el-form-item>
  404. </el-form>
  405. <div slot="footer" class="dialog-footer">
  406. <el-button @click="dialogDeployVisible = false">取 消</el-button>
  407. <el-button type="primary" @click="doDeploy">确 定</el-button>
  408. </div>
  409. </el-dialog>
  410. </div>`,
  411. data() {
  412. return {
  413. dialogVisible: false, // 查看目录结构弹窗
  414. data: [], // 目录结构树的数据结构
  415. defaultProps: {
  416. children: 'children',
  417. label: 'label'
  418. },
  419. loadingTree: false,
  420. depDialogVisible: false, // 部署中弹窗
  421. loading: false,
  422. projectLibUrl: 'http://192.168.118.60:9999/webapp/pages/caselib/create.html', // 项目案例库地址
  423. projectIsDeployed: false, // 项目是否部署过
  424. projectFtpUrl: '', // ftp路径
  425. projectEntryUrl: '', // 项目案例库发布表单的入口页面
  426. supportDeploy: true, // 项目是否支持部署
  427. dialogDeployVisible: false,
  428. formLabelWidth: '120px',
  429. form: {
  430. frame: '',
  431. branch: ''
  432. },
  433. framework: [
  434. {label: '重构模板', value: 1},
  435. {label: 'f9x1.0', value: 2},
  436. {label: 'f9x2.0', value: 3},
  437. {label: 'f950', value: 4},
  438. {label: 'f950sp1', value: 5},
  439. {label: 'f950sp2', value: 6},
  440. {label: 'f950sp3', value: 7},
  441. {label: 'f951', value: 18},
  442. {label: 'f940', value: 8},
  443. {label: 'f941', value: 10},
  444. {label: 'f942', value: 9},
  445. {label: 'f934', value: 11},
  446. {label: 'f933', value: 12},
  447. {label: 'f932', value: 13},
  448. {label: 'f9211', value: 14},
  449. {label: '骨架', value: 15},
  450. {label: 'Vue', value: 16},
  451. {label: 'React', value: 17}
  452. ],
  453. rules: {
  454. frame: [
  455. { required: true, message: '请选择框架类型', trigger: 'change' }
  456. ],
  457. branch: [
  458. { required: true, message: '请选择分支', trigger: 'change' }
  459. ]
  460. },
  461. clickNodeEntry: null,
  462. branches: []
  463. };
  464. },
  465. methods: {
  466. handleClose(done) {
  467. done();
  468. /*
  469. this.$confirm('确认关闭?')
  470. .then(_ => {
  471. done();
  472. })
  473. .catch(_ => {});*/
  474. },
  475. handleNodeClick(data) {
  476. console.log(data);
  477. if(data.type === 'folder') {
  478. return false;
  479. }
  480. var self = this;
  481. var entry = data.entry;
  482. self.clickNodeEntry = entry;
  483. if(self.projectFtpUrl) {
  484. window.open('http://192.168.219.170' + self.projectFtpUrl + data.entry);
  485. self.clickNodeEntry = null;
  486. } else {
  487. if(this.supportDeploy === false) {
  488. this.$message({
  489. type: 'error',
  490. message: '当前项目暂时只支持查看,请耐心等待功能升级。'
  491. });
  492. self.clickNodeEntry = null;
  493. return false;
  494. }
  495.  
  496. this.$confirm('资源未部署,部署至 170 服务器后可查看,是否部署?')
  497. .then(_ => {
  498.  
  499. this.dialogDeployVisible = true;
  500. /*
  501. this.depDialogVisible = true;
  502. this.loading = true;
  503. // 部署
  504. this.getDeployInfo({ type: '1' }, (data)=> {
  505. this.loading = false;
  506. this.depDialogVisible = false;
  507.  
  508. this.data = data.custom.detail;
  509. this.projectFtpUrl = data.custom.ftpUrl;
  510.  
  511. this.$alert('部署成功!', '提示', {
  512. confirmButtonText: '确定',
  513. callback: action => {
  514. window.open('http://192.168.219.170' + self.projectFtpUrl + entry)
  515. }
  516. });
  517.  
  518. });*/
  519. })
  520. .catch(_ => {});
  521. }
  522. },
  523. // 部署
  524. doDeploy () {
  525. if(!this.isDownLoadPage()) {
  526. return;
  527. }
  528. if(!this.dialogDeployVisible) {
  529. this.dialogDeployVisible = true;
  530. return;
  531. }
  532.  
  533. let self = this;
  534.  
  535. this.$refs['form'].validate((valid) => {
  536. if (valid) {
  537. this.dialogDeployVisible = false;
  538. this.depDialogVisible = true;
  539. this.loading = true;
  540. // 部署
  541. this.getDeployInfo({ type: '1', frame: this.form.frame, branch: this.form.branch }, (data)=> {
  542. this.loading = false;
  543. this.depDialogVisible = false;
  544.  
  545. if(!data.custom.text){
  546.  
  547. this.data = data.custom.pageTreeData;
  548. this.projectFtpUrl = data.custom.projectRootPath;
  549. this.supportDeploy = data.custom.supportDeploy;
  550.  
  551. this.setProjectEntry();
  552. // 从部署按钮直接过来的
  553. if(!this.clickNodeEntry) {
  554. this.$message({
  555. type: 'success',
  556. message: '部署成功!'
  557. });
  558. // 打开查看弹窗
  559. this.viewProject();
  560. } else {// 从点击目录结构过来的,可以调整点击的树节点页面
  561. this.$alert('部署成功!', '提示', {
  562. confirmButtonText: '确定',
  563. callback: action => {
  564. window.open('http://192.168.219.170' + self.projectFtpUrl + self.clickNodeEntry);
  565. self.clickNodeEntry = null;
  566. }
  567. });
  568. }
  569.  
  570. } else {
  571. this.$message({
  572. type: 'error',
  573. message: data.custom.text
  574. });
  575. }
  576. });
  577. } else {
  578. console.log('error submit!!');
  579. return false;
  580. }
  581. });
  582.  
  583. /*
  584. this.$confirm('此操作将把 GitLab 资源打包部署至 170 服务器,已部署过的项目会进行覆盖部署,是否继续?', '提示', {
  585. confirmButtonText: '确定',
  586. cancelButtonText: '取消',
  587. type: 'warning'
  588. }).then(() => {
  589. }).catch(() => {
  590. this.$message({
  591. type: 'info',
  592. message: '已取消部署'
  593. });
  594. });*/
  595. },
  596. // 发布项目案例库
  597. publish () {
  598. this.$confirm('此操作将把项目发布至 <a href="'+ this.projectLibUrl +'" target="_blank">项目案例库</a>,已发布过的项目案例库会有重复项,是否继续?', '提示', {
  599. confirmButtonText: '确定',
  600. cancelButtonText: '取消',
  601. dangerouslyUseHTMLString: true,
  602. type: 'warning'
  603. }).then(() => {
  604. const themes = document.querySelectorAll('.badge-secondary');
  605. let keys = [];
  606.  
  607. for(let i = 0, l = themes.length; i < l; i++) {
  608. if(themes[0].innerText == '智能设备' && i > 0) {
  609. keys.push(themes[i].innerText);
  610. } else if (themes[0].innerText !== '智能设备' && i > 1) {
  611. keys.push(themes[i].innerText);
  612. }
  613. }
  614. // 存在更多主题的情况
  615. const moreKeyEl = document.querySelector('.gl-w-full .text-nowrap');
  616. if(moreKeyEl) {
  617. const moreKeyElContent = moreKeyEl.getAttribute('data-content');
  618. const regex = />([^<]+)</g;
  619. const matches = moreKeyElContent.match(regex);
  620. const results = matches.filter(function(match) {
  621. return match.length > 3;
  622. });
  623. const moreKeyData = results.map(function(match) {
  624. return match.substring(2, match.length - 2);
  625. });
  626.  
  627. if(moreKeyData && moreKeyData.length) {
  628. keys = keys.concat(moreKeyData);
  629. }
  630. }
  631.  
  632. // 组织项目案例库所需参数
  633. const projectName = document.querySelector('.home-panel-title').innerText;
  634. const projectBU = themes[0] ? themes[0].innerText : null;
  635. const projectKeys = keys.join(' ');
  636. const entryUrl = this.projectEntryUrl;
  637. let projectType = themes[1] ? themes[1].innerText : null;
  638.  
  639. if(themes[0]) {
  640. if(themes[0].innerText == '智能设备') {
  641. projectType = themes[1] ? themes[0].innerText : null;
  642. } else {
  643. projectType = themes[1] ? themes[1].innerText : null;
  644. }
  645. }
  646.  
  647. const destUrl = this.projectLibUrl + '?projectName=' + projectName + '&projectBU=' + projectBU + '&projectType=' + projectType + '&projectKeys=' + projectKeys + '&entryUrl=' + entryUrl + '&git=' + window.location.href;
  648.  
  649. this.$message({
  650. type: 'success',
  651. message: destUrl
  652. });
  653.  
  654. window.open(destUrl);
  655.  
  656. }).catch(() => {
  657. this.$message({
  658. type: 'info',
  659. message: '已取消发布'
  660. });
  661. });
  662. },
  663. // 查看项目
  664. viewProject () {
  665. if(!this.isDownLoadPage()) {
  666. return;
  667. }
  668. this.dialogVisible = true;
  669. this.loadingTree = true;
  670. let self = this;
  671.  
  672. // 发送ajax请求,查看是否进行过部署
  673. this.getDeployInfo((data)=> {
  674. // 有部署信息,直接赋值,
  675. if(data) {
  676. self.projectIsDeployed = true;
  677. self.data = data.custom.pageTreeData;
  678. self.projectFtpUrl = data.custom.projectRootPath;
  679. self.supportDeploy = data.custom.supportDeploy;
  680. self.loadingTree = false;
  681.  
  682. self.setProjectEntry();
  683.  
  684. } else {
  685. // 无部署信息,仅查看文件目录
  686. getZipResource((data)=> {
  687. self.data = data;
  688. self.loadingTree = false;
  689. });
  690. }
  691. });
  692.  
  693. },
  694. // 查看项目的所有页面
  695. viewAll() {
  696. window.open('http://192.168.219.170/code-pipeline/#/project/deploy-preview?rowguid=' + document.body.getAttribute('data-project-id'));
  697. },
  698. // 项目部署信息
  699. getDeployInfo(params, callback) {
  700. const projectId = document.body.getAttribute('data-project-id');
  701. const downloadBtn = document.querySelector('.gl-button.btn-sm.btn-confirm');
  702.  
  703. const sourceUrl = downloadBtn.getAttribute('href');
  704. const downloadUrl = window.location.origin + sourceUrl;
  705. const files = document.body.getAttribute('data-find-file').split('/');
  706. const name = document.body.getAttribute('data-project') + '-' + files[files.length - 1];
  707. const author = document.querySelector('.current-user .gl-font-weight-bold').innerText.trim();
  708. const projectName = document.querySelector('.sidebar-context-title').innerText.trim();
  709. const deployManOA = document.querySelector('.current-user>a').getAttribute('data-user');
  710. const projectGitUrl = 'http://192.168.0.200' + document.body.getAttribute('data-find-file').split('/-/')[0];
  711.  
  712. if(typeof params == 'function') {
  713. callback = params;
  714. params = null;
  715. }
  716.  
  717. if(projectId && projectId.length && sourceUrl) {
  718. fetch('http://192.168.219.170:3008/api/getDeployInfo', {
  719. method: 'POST',
  720. // 允许跨域请求
  721. mode: 'cors',
  722. headers: {
  723. 'Accept': 'application/json',
  724. 'Content-Type': 'application/json'
  725. },
  726. body: JSON.stringify({//post请求参数
  727. params: {
  728. "type": (params && params.type !== undefined) ? params.type : '0',// 0 代表查看, 1代表部署
  729. "name": name, // 项目路径英文名
  730. "deployMan": author, // 部署人姓名
  731. "deployManOA": deployManOA, // 部署人账号
  732. "projectName": projectName, // 项目名称
  733. "downloadUrl": downloadUrl, // 下载地址
  734. "projectId": projectId, // 主键,gitlab上的项目id
  735. "projectGitUrl": projectGitUrl,
  736. "frame": (params && params.frame) ? params.frame : undefined
  737. }
  738. })
  739. })
  740. .then(response => response.text())
  741. .then((result) => {
  742. var data = JSON.parse(result);
  743. callback && callback(data);
  744. })
  745. .catch(error => {
  746. this.depDialogVisible = false;
  747. this.dialogVisible = false;
  748. this.$message({
  749. type: 'error',
  750. message: '系统故障,请联系管理员。'
  751. });
  752. console.error(error);
  753. });
  754. } else {
  755. this.$message({
  756. type: 'error',
  757. message: '本页不支持查看和部署,请至仓库页。'
  758. });
  759. console.error('部署信息请求参数error');
  760. }
  761. },
  762. // 进入管理平台 code pipeline
  763. manage() {
  764. window.open('http://192.168.219.170/code-pipeline')
  765. },
  766. // 设置入口
  767. setProjectEntry(){
  768. const firstNode = findFirstFileNode(this.data);
  769. if(firstNode) {
  770. this.projectEntryUrl = 'http://192.168.219.170' + this.projectFtpUrl + firstNode.entry;
  771. }else {
  772. this.projectEntryUrl = null;
  773. }
  774. },
  775. isDownLoadPage() {
  776. const downloadBtn = document.querySelector('.gl-button.btn-sm.btn-confirm');
  777. const sourceUrl = downloadBtn && downloadBtn.getAttribute('href');
  778.  
  779. if(downloadBtn && sourceUrl) {
  780. return true;
  781. } else {
  782. this.$message({
  783. type: 'error',
  784. message: '本页面不支持查看和部署,请移至仓库页。'
  785. });
  786. return false;
  787. }
  788. }
  789. },
  790. mounted() {
  791. gitlabUtil.getBranches((branches) => {
  792. let tempArr = [];
  793. branches.forEach((item, index)=> {
  794. tempArr.push({
  795. label: item,
  796. value: item
  797. });
  798. });
  799. this.branches = tempArr;
  800. });
  801.  
  802. const selectBranch = document.querySelector('.qa-branches-select').getAttribute('data-selected') || 'main';
  803.  
  804. this.form.branch = selectBranch;
  805. }
  806. };
  807.  
  808.  
  809. // 等待页面加载完成
  810. window.addEventListener('load', function() {
  811.  
  812.  
  813. const placeholder = document.createElement('div');
  814.  
  815. // 创建 Vue 实例并挂载到页面
  816. const vueInstance = new Vue({
  817. el: placeholder,
  818. components: {
  819. MyComponent
  820. },
  821. methods: {
  822. },
  823. template: `<my-component></my-component>`
  824. });
  825.  
  826. // 开始在项目仓库页添加搜索设计门户按钮 start
  827. const panel = document.querySelector('.project-home-panel');
  828. let vueInstance2;
  829. const description = document.querySelector('.read-more-container');
  830. const descriptionText = description && description.innerText;
  831. let haveDesignBackupUrl = /platesdetail\?guid=(?!$)/.test(descriptionText);
  832.  
  833. if(panel && !haveDesignBackupUrl) {
  834. const btnPlaceholder = document.createElement('div');
  835. btnPlaceholder.setAttribute('class', 'epoint-portal-search');
  836. // 创建 Vue 实例并挂载到页面
  837. vueInstance2 = new Vue({
  838. el: btnPlaceholder,
  839. data: function() {
  840. return {
  841. proName: document.querySelector('.home-panel-title').innerText.trim().substring(0, 4)
  842. };
  843. },
  844. methods: {
  845. manage() {
  846. window.open('https://oa.epoint.com.cn/epointoa9/frame/fui/pages/themes/aide/aide?pageId=aide&redirect=https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplateslist?projectname' + this.proName)
  847. }
  848. },
  849. template: `<div style="margin-top:4px;">
  850. <el-tooltip content="新点设计门户中查找此项目" placement="top" effect="light">
  851. <el-button type="primary" icon="el-icon-search" size="small" @click="manage">查找UI备份地址</el-button>
  852. </el-tooltip>
  853. </div>`
  854. });
  855. // 开始在项目仓库页添加搜索设计门户按钮 end
  856. }
  857.  
  858. // 将占位元素追加到 body 元素中
  859. document.body.appendChild(vueInstance.$el);
  860.  
  861. panel && !haveDesignBackupUrl && panel.appendChild(vueInstance2.$el);
  862.  
  863. // 克隆按钮下增加sourcetree 快捷打开方式
  864. const dropMenu = document.querySelector('.clone-options-dropdown');
  865.  
  866. if(dropMenu) {
  867. // 协议的方式 sourcetree://cloneRepo?type=stash&cloneUrl=http://192.168.0.200/fe3project/taicang-vue-website.git
  868. let sourceTreeHtml = '<li class="pt-2 gl-new-dropdown-item">\
  869. <label class="label-bold gl-px-4!" xt-marked="ok">在您的Sourcetree中打开</label>\
  870. <a class="dropdown-item open-with-link" href="sourcetree://cloneRepo?type=stash&cloneUrl='+ document.getElementById('http_project_clone').value +'">\
  871. <div class="gl-new-dropdown-item-text-wrapper" xt-marked="ok">Sourcetree (HTTPS)</div></a></li>';
  872.  
  873. jQuery(dropMenu).append(sourceTreeHtml);
  874. }
  875. });
  876.  
  877. // 将文件条目组织成嵌套结构
  878. function organizeFileEntries(fileEntries) {
  879. const root = {
  880. label: document.querySelector('.home-panel-title').innerText || document.getElementById('project_name_edit').value,
  881. type: 'folder',
  882. children: []
  883. };
  884.  
  885. // 创建嵌套结构
  886. fileEntries.forEach(entry => {
  887. const pathSegments = entry.name.split('/');
  888. let currentFolder = root;
  889.  
  890. // 遍历路径中的每个部分,创建相应的文件夹节点
  891. for (let i = 0; i < pathSegments.length - 1; i++) {
  892. const folderName = pathSegments[i];
  893. let folder = currentFolder.children.find(child => child.label === folderName);
  894.  
  895. if(isExcludeFolder(entry.name)) {
  896. continue;
  897. }
  898.  
  899. if (!folder) {
  900. folder = {
  901. label: folderName,
  902. type: 'folder',
  903. children: []
  904. };
  905. currentFolder.children.push(folder);
  906. }
  907.  
  908. currentFolder = folder;
  909. }
  910.  
  911. // 创建文件节点并添加到相应的文件夹中
  912. const fileName = pathSegments[pathSegments.length - 1];
  913.  
  914. if(fileName && fileName.length && isIncludeFile(fileName) && !isExcludeFolder(entry.name)) {
  915. const fileNode = {
  916. label: fileName,
  917. type: 'file',
  918. entry: entry.name
  919. };
  920. currentFolder.children.push(fileNode);
  921. }
  922. });
  923.  
  924. return [root];
  925. }
  926. // 是否排除的文件夹
  927. function isExcludeFolder(entry) {
  928. if(entry.indexOf('css') > -1 ||
  929. entry.indexOf('scss') > -1 ||
  930. entry.indexOf('js') > -1 ||
  931. entry.indexOf('images') > -1 ||
  932. entry.indexOf('fui') > -1 ||
  933. entry.indexOf('lib') > -1 ||
  934. entry.indexOf('test') > -1 ||
  935. entry.indexOf('font') > -1 ||
  936. entry.indexOf('frame/fui') > -1) {
  937. return true;
  938. } else {
  939. return false;
  940. }
  941. }
  942. // 是否包含的文件
  943. function isIncludeFile(fileName) {
  944. if(fileName.indexOf('.html') > -1) {
  945. return true;
  946. } else {
  947. return false;
  948. }
  949. }
  950.  
  951. function getZipResource(callback) {
  952. const downloadUrl = window.location.origin + document.querySelector('.gl-button.btn-sm.btn-confirm').getAttribute('href');
  953.  
  954. fetch(downloadUrl)
  955. .then(response => response.arrayBuffer())
  956. .then(data => {
  957. // 将 ZIP 文件的二进制数据传递给 JSZip 进行解析
  958. return JSZip.loadAsync(data);
  959. })
  960. .then(zip => {
  961. // 获取 ZIP 文件中的所有条目(文件和目录)
  962. const zipEntries = Object.values(zip.files);
  963. const treeData = organizeFileEntries(zipEntries)
  964.  
  965. callback && callback(treeData);
  966.  
  967. })
  968. .catch(error => {
  969. console.error(error);
  970. });
  971. }
  972.  
  973. // 树结构第一个节点数据
  974. function findFirstFileNode(tree) {
  975. // 遍历树的节点
  976. for (let i = 0; i < tree.length; i++) {
  977. const node = tree[i];
  978.  
  979. // 如果节点的类型为 file,则返回该节点
  980. if (node.type === 'file') {
  981. return node;
  982. }
  983.  
  984. // 如果节点有子节点,则递归调用该函数查找子节点中的第一个 file 节点
  985. if (node.children && node.children.length > 0) {
  986. const fileNode = findFirstFileNode(node.children);
  987. if (fileNode) {
  988. return fileNode;
  989. }
  990. }
  991. }
  992.  
  993. // 如果没有找到 file 节点,则返回 null
  994. return null;
  995. }
  996. })();
  997.  
  998. // 修改项目描述的长度
  999. (function() {
  1000. 'use strict';
  1001. let regs = [/^http:\/\/192\.168\.0\.200\/fe3project\//,
  1002. /^http:\/\/192\.168\.0\.200\/frontend_pc\/project\//];
  1003. let match = false;
  1004.  
  1005. for(let r = 0, lr = regs.length; r < lr; r++) {
  1006. if(regs[r].test(location.href)) {
  1007. match = true;
  1008. break;
  1009. }
  1010. }
  1011.  
  1012. if(!match) {
  1013. return;
  1014. }
  1015.  
  1016. let tryTimes = 6;
  1017. let changed = false;
  1018.  
  1019. // 增加项目描述的输入长度
  1020. function modifyTextareaLen() {
  1021. if(tryTimes > 0 && !changed) {
  1022. setTimeout(() => {
  1023. const textarea = document.getElementById('project_description');
  1024. tryTimes--;
  1025. if(textarea) {
  1026. textarea.setAttribute("maxlength", "1000");
  1027.  
  1028. jQuery(textarea).blur(function(event) {
  1029. this.value = this.value.replace(/,/g, ',').replace(/&isfwqfb=1/g, '');
  1030. this.value = convertDateFormat(this.value);
  1031. jQuery(this).trigger('change');
  1032. });
  1033. changed = true;
  1034. } else {
  1035. modifyTextareaLen();
  1036. }
  1037. }, 1000);
  1038. }
  1039. }
  1040.  
  1041. window.onload = function() {
  1042. modifyTextareaLen();
  1043. }
  1044. })();
  1045.  
  1046. // 设计门户增加通往前端仓库的跳板
  1047. (function() {
  1048. 'use strict';
  1049.  
  1050. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/casestemplates\/casetemplatesdetail/,
  1051. /^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/generalpagetemplates\/generalpagetemplatesdetail/,
  1052. /^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/dynamiceffecttemplates\/dynamiceffecttemplatesdetail/];
  1053. let match = false;
  1054.  
  1055. for(let r = 0, lr = regs.length; r < lr; r++) {
  1056. if(regs[r].test(location.href)) {
  1057. match = true;
  1058. break;
  1059. }
  1060. }
  1061.  
  1062. if(!match) {
  1063. return;
  1064. }
  1065.  
  1066. function addStyle() {
  1067. // 注入样式:增加按钮
  1068. let injectStyle = ".content { position: relative; } .front-proto { position: absolute; top: 20px; right: 20px; width: 106px; height: 36px; border-radius: 4px; cursor: pointer; line-height: 36px; background: #25c2c9; color: #fff; text-align: center; font-size: 14px}";
  1069.  
  1070.  
  1071. // 添加注入样式
  1072. let extraStyleElement = document.createElement("style");
  1073. extraStyleElement.innerHTML = injectStyle;
  1074. document.head.appendChild(extraStyleElement);
  1075. }
  1076.  
  1077. function getUrlParameters() {
  1078. var params = {};
  1079. var search = window.location.search.substring(1);
  1080. var urlParams = search.split('&');
  1081.  
  1082. for (var i = 0; i < urlParams.length; i++) {
  1083. var param = urlParams[i].split('=');
  1084. var paramName = decodeURIComponent(param[0]);
  1085. var paramValue = decodeURIComponent(param[1] || '');
  1086. params[paramName] = paramValue;
  1087. }
  1088.  
  1089. return params;
  1090. }
  1091.  
  1092. window.onload = ()=> {
  1093. addStyle();
  1094. const $content = jQuery('.content');
  1095.  
  1096. $content.append('<div class="front-proto">前端原型</div>');
  1097.  
  1098. const $frontBtn = jQuery('.front-proto', $content);
  1099.  
  1100. $frontBtn.on('click', ()=> {
  1101. window.open('http://192.168.0.200/?name=' + getUrlParameters().guid);
  1102. });
  1103. };
  1104. })();
  1105.  
  1106. // 前端项目案例库增加获取参数的能力
  1107. // 前端项目案例库增加部署能力
  1108. (function() {
  1109. 'use strict';
  1110.  
  1111. let regs = [/^http:\/\/192\.168\.118\.60:9999\/webapp\/pages\/caselib\/create\.html/,
  1112. /^http:\/\/192\.168\.201\.159:9999\/webapp\/pages\/default\/onlinecase.html/];
  1113. let match = false;
  1114.  
  1115. for(let r = 0, lr = regs.length; r < lr; r++) {
  1116. if(regs[r].test(location.href)) {
  1117. match = true;
  1118. break;
  1119. }
  1120. }
  1121.  
  1122. if(!match) {
  1123. return;
  1124. }
  1125.  
  1126. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  1127.  
  1128. // 添加样式规则,将字体应用到指定元素上
  1129. GM_addStyle(`
  1130. @font-face {
  1131. font-family: element-icons;
  1132. src: url(${fontUrl}) format("woff");
  1133. }
  1134. `);
  1135.  
  1136. GM_addStyle(GM_getResourceText('ElementCSS'));
  1137.  
  1138. const businessType = [
  1139. { Value: '7a20e23c-30b8-47e2-8d8d-f2691c9c63c4', Text: '政务服务' },
  1140. { Value: 'c12150bb-b358-452f-87f0-8a2254df87cb', Text: '政务协同' },
  1141. { Value: '3845804e-de68-421c-9402-7b238cfb5a70', Text: '大数据' },
  1142. { Value: '3c28ee56-f24d-4843-b9a2-93e6b96264f4', Text: '电子交易' },
  1143. { Value: '673b5918-51bc-4f1a-ab73-fca86e54d7d1', Text: '数字建设' },
  1144. { Value: '6d9e7d84-7de3-4e0f-bd4f-ed4722ed25b5', Text: '建筑企业' },
  1145. { Value: 'c22f8d2f-518d-4381-b88c-1da68536ed3a', Text: '公共安全' },
  1146. { Value: 'c5810829-1b21-4b22-85cd-390b1edd9614', Text: '智能设备' },
  1147. { Value: '080c7560-c261-428b-a45d-b86b57b47ffb', Text: '中央研究院' }
  1148. ];
  1149.  
  1150. const projectType = [
  1151. { Value: 'dca44f63-be3f-4e9c-b78f-d786571c22c9', Text: '网站' },
  1152. { Value: 'c7861460-163b-4060-80ec-d60604c50435', Text: '业务系统' },
  1153. { Value: '49accc71-6f7d-43f3-b726-58decf58b6fa', Text: '智能设备' },
  1154. { Value: '90209c65-1a55-4d8c-a836-2e5c6b834ada', Text: '大屏可视化' },
  1155. { Value: 'fb0415fb-65ee-42c1-895a-dca042c2568e', Text: '中屏可视化' },
  1156. { Value: '2b83f9b1-ec78-4819-a400-d7d49ea1ecc5', Text: '其他' }
  1157. ];
  1158.  
  1159. let $businesstype;
  1160. let $projecttype;
  1161.  
  1162. function getUrlParameters() {
  1163. var params = {};
  1164. var search = window.location.search.substring(1);
  1165. var urlParams = search.split('&');
  1166.  
  1167. for (var i = 0; i < urlParams.length; i++) {
  1168. var param = urlParams[i].split('=');
  1169. var paramName = decodeURIComponent(param[0]);
  1170. var paramValue = decodeURIComponent(param[1] || '');
  1171. if(paramName) {
  1172. params[paramName] = paramValue;
  1173. }
  1174. }
  1175.  
  1176. return params;
  1177. }
  1178.  
  1179. function initForm (params) {
  1180. if(typeof params === 'object') {
  1181. document.getElementsByName('Title')[0].value = params.projectName ? params.projectName : '';
  1182. document.getElementsByName('KeyWords')[0].value = params.projectKeys ? params.projectKeys : '';
  1183. document.getElementsByName('Entry')[0].value = params.entryUrl ? params.entryUrl : '';
  1184. document.getElementsByName('SourceCode')[0].value = params.git ? params.git : '';
  1185. }
  1186. }
  1187.  
  1188. let setSuccess = false;
  1189. let setTimes = 5;
  1190.  
  1191. function initSelect(params) {
  1192. if(typeof params !== 'object') {
  1193. return;
  1194. }
  1195.  
  1196. if(setTimes > 0 && !setSuccess) {
  1197. setTimeout(()=> {
  1198. setTimes--;
  1199.  
  1200. businessType.forEach((item)=> {
  1201. if(params.projectBU) {
  1202. if(item.Text === params.projectBU.trim()) {
  1203. $businesstype.val(item.Value);
  1204. } else if( params.projectBU.trim() == '一网统管' || params.projectBU.trim() == '一网协同' || params.projectBU.trim() == '一网通办' ) {
  1205. $businesstype.val('7a20e23c-30b8-47e2-8d8d-f2691c9c63c4');
  1206. }
  1207. $businesstype.trigger("chosen:updated");
  1208. }
  1209. });
  1210.  
  1211. projectType.forEach((item)=> {
  1212. if(params.projectType && item.Text === params.projectType.trim()) {
  1213. $projecttype.val(item.Value);
  1214. $projecttype.trigger("chosen:updated");
  1215. }
  1216. });
  1217.  
  1218. setSuccess = true;
  1219.  
  1220. }, 1000);
  1221. } else {
  1222. initSelect(params);
  1223. }
  1224. }
  1225.  
  1226. function addRelatedDom() {
  1227. const sourceInput = document.getElementsByName('SourceCode')[0];
  1228. const $sourceInput = jQuery(sourceInput);
  1229.  
  1230. $sourceInput.after('<a class="btn" style="cursor: pointer;margin-left:10px;" id="deploy">部署</a><a class="btn hidden" style="cursor: pointer;margin-left:10px" id="view">查看</a>')
  1231. }
  1232.  
  1233. function addStyle() {
  1234. let epointCss = ".el-loading-spinner {margin-top: -50px;} .el-button--primary:focus {outline: 0 !important;}";
  1235. // 添加注入样式
  1236. let extraStyleElement = document.createElement("style");
  1237. extraStyleElement.innerHTML = epointCss;
  1238. document.head.appendChild(extraStyleElement);
  1239. }
  1240.  
  1241. window.onload = ()=> {
  1242. const params = getUrlParameters();
  1243.  
  1244. // 有参数,进行填充表单
  1245. if(params && params.git) {
  1246. $businesstype = jQuery('#businesstype');
  1247. $projecttype = jQuery('#projecttype');
  1248.  
  1249. initForm(params);
  1250. initSelect(params);
  1251.  
  1252. return false;
  1253. }
  1254.  
  1255. // 没有url参数填充,则做部署功能展示
  1256. addRelatedDom();
  1257. addStyle();
  1258.  
  1259. const placeholder = document.createElement('div');
  1260.  
  1261. // 创建 Vue 实例并挂载到页面
  1262. const vueInstance = new Vue({
  1263. el: placeholder,
  1264. data() {
  1265. return {
  1266. framework: [
  1267. {label: '重构模板', value: 1},
  1268. {label: 'f9x1.0', value: 2},
  1269. {label: 'f9x2.0', value: 3},
  1270. {label: 'f950', value: 4},
  1271. {label: 'f950sp1', value: 5},
  1272. {label: 'f950sp2', value: 6},
  1273. {label: 'f950sp3', value: 7},
  1274. {label: 'f951', value: 18},
  1275. {label: 'f940', value: 8},
  1276. {label: 'f941', value: 10},
  1277. {label: 'f942', value: 9},
  1278. {label: 'f934', value: 11},
  1279. {label: 'f933', value: 12},
  1280. {label: 'f932', value: 13},
  1281. {label: 'f9211', value: 14},
  1282. {label: '骨架', value: 15},
  1283. {label: 'Vue', value: 16},
  1284. {label: 'React', value: 17}
  1285. ],
  1286. data: [], // 目录结构树
  1287. defaultProps: {
  1288. children: 'children',
  1289. label: 'label'
  1290. },
  1291. loadingTree: false,
  1292. dialogVisible: false,
  1293. dialogDeployVisible: false,
  1294. showDeployPath: false,
  1295. depDialogVisible: false,
  1296. loading: false,
  1297. formLabelWidth: '120px',
  1298. supportDeploy: false,
  1299. form: {
  1300. frame: '',
  1301. deployPath: ''
  1302. },
  1303. rules: {
  1304. frame: [
  1305. { required: true, message: '请选择框架类型', trigger: 'change' }
  1306. ],
  1307. deployPath: [
  1308. { required: true, message: '请输入部署到 170/showcase 下的目标路径名称', trigger: 'change' }
  1309. ]
  1310. }
  1311. }
  1312. },
  1313. methods: {
  1314. // 部署
  1315. doDeploy() {
  1316. let self = this;
  1317.  
  1318. this.$refs['form'].validate((valid) => {
  1319. if (valid) {
  1320. this.dialogDeployVisible = false;
  1321. this.depDialogVisible = true;
  1322. this.loading = true;
  1323. // 部署
  1324. this.getDeployInfo({ type: '1', frame: this.form.frame, deployPath: this.form.deployPath }, (data)=> {
  1325. this.loading = false;
  1326. this.depDialogVisible = false;
  1327.  
  1328. if(!data.custom.text){
  1329.  
  1330. this.data = data.custom.pageTreeData;
  1331. this.projectFtpUrl = data.custom.projectRootPath;
  1332. this.supportDeploy = data.custom.supportDeploy;
  1333.  
  1334. this.$message({
  1335. type: 'success',
  1336. message: '部署成功!'
  1337. });
  1338. // 打开查看弹窗
  1339. this.viewProject();
  1340. this.toggleViewButton(true);
  1341.  
  1342. } else {
  1343. this.$message({
  1344. type: 'error',
  1345. message: data.custom.text
  1346. });
  1347. }
  1348. });
  1349. } else {
  1350. console.log('error submit!!');
  1351. return false;
  1352. }
  1353. });
  1354. },
  1355. // 项目部署
  1356. getDeployInfo(params, callback) {
  1357. const author = document.querySelector('#account a').innerText.trim().substring(4);
  1358. const projectName = document.getElementsByName('Title')[0].value.trim();
  1359. const projectGitUrl = document.getElementsByName('SourceCode')[0].value.trim();
  1360.  
  1361. if(typeof params == 'function') {
  1362. callback = params;
  1363. params = null;
  1364. }
  1365. if(author && author.length && projectGitUrl) {
  1366. fetch('http://192.168.219.170:3008/api/getDeployInfo', {
  1367. method: 'POST',
  1368. // 允许跨域请求
  1369. mode: 'cors',
  1370. headers: {
  1371. 'Accept': 'application/json',
  1372. 'Content-Type': 'application/json'
  1373. },
  1374. body: JSON.stringify({//post请求参数
  1375. params: {
  1376. "type": (params && params.type !== undefined) ? params.type : '0',// 0 代表查看, 1代表部署
  1377. "deployMan": author, // 部署人姓名
  1378. "projectName": projectName, // 项目名称
  1379. "projectGitUrl": projectGitUrl,
  1380. "frame": (params && params.frame) ? params.frame : undefined,
  1381. "deployPath": (params && params.deployPath) ? params.deployPath : undefined // 部署的目标目录
  1382. }
  1383. })
  1384. })
  1385. .then(response => response.text())
  1386. .then((result) => {
  1387. var data = JSON.parse(result);
  1388. callback && callback(data);
  1389. })
  1390. .catch(error => {
  1391. this.depDialogVisible = false;
  1392. this.dialogVisible = false;
  1393. this.$message({
  1394. type: 'error',
  1395. message: '系统故障,请联系管理员。'
  1396. });
  1397. console.error(error);
  1398. });
  1399. } else {
  1400. this.$message({
  1401. type: 'error',
  1402. message: '本页面不支持查看和部署,请先登录。'
  1403. });
  1404. console.error('部署信息请求参数error');
  1405. }
  1406. },
  1407. // 查看项目
  1408. viewProject () {
  1409. this.dialogVisible = true;
  1410. let self = this;
  1411.  
  1412. if(this.data) {
  1413. this.loadingTree = false;
  1414. } else {
  1415. this.loadingTree = true;
  1416. // 发送ajax请求,查看是否进行过部署
  1417. this.getDeployInfo((data)=> {
  1418. // 有部署信息,直接赋值,
  1419. if(data) {
  1420. self.projectIsDeployed = true;
  1421. self.data = data.custom.pageTreeData;
  1422. self.projectFtpUrl = data.custom.projectRootPath;
  1423. self.supportDeploy = data.custom.supportDeploy;
  1424. self.loadingTree = false;
  1425.  
  1426. self.toggleViewButton(true);
  1427.  
  1428. }
  1429. });
  1430. }
  1431. },
  1432. handleNodeClick(data) {
  1433. console.log(data);
  1434. if(data.type === 'folder') {
  1435. return false;
  1436. }
  1437. var self = this;
  1438. var entry = data.entry;
  1439. self.clickNodeEntry = entry;
  1440. if(self.projectFtpUrl) {
  1441. window.open('http://192.168.219.170' + self.projectFtpUrl + data.entry);
  1442. self.clickNodeEntry = null;
  1443. } else {
  1444. if(this.supportDeploy === false) {
  1445. this.$message({
  1446. type: 'error',
  1447. message: '当前项目暂时只支持查看,请耐心等待功能升级。'
  1448. });
  1449. self.clickNodeEntry = null;
  1450. return false;
  1451. }
  1452.  
  1453. this.$confirm('资源未部署,部署至 170 服务器后可查看,是否部署?')
  1454. .then(_ => {
  1455.  
  1456. this.dialogDeployVisible = true;
  1457. })
  1458. .catch(_ => {});
  1459. }
  1460. },
  1461. // svn 需要制定目录名称,showDeployPath
  1462. showDialog(showDeployPath) {
  1463. this.showDeployPath = showDeployPath;
  1464. this.dialogDeployVisible = true;
  1465. },
  1466. // 查看按钮显影控制
  1467. toggleViewButton(show) {
  1468. const $viewBtn = jQuery('#view');
  1469.  
  1470. if(!$viewBtn.length) {
  1471. return;
  1472. }
  1473.  
  1474. if(show) {
  1475. $viewBtn.removeClass('hidden');
  1476. } else {
  1477. $viewBtn.addClass('hidden');
  1478. }
  1479. }
  1480. },
  1481. mounted() {
  1482. const $btnDeloy = jQuery('#deploy');
  1483. const $btnView = jQuery('#view');
  1484.  
  1485. // 绑定vue组件外的事件
  1486. $btnDeloy.on('click', function() {
  1487. // 源码地址和项目名称判断
  1488. const sourceInput = document.getElementsByName('SourceCode');
  1489. const projectNameInput = document.getElementsByName('Title');
  1490.  
  1491. let sourceInputVal = sourceInput[0].value.trim(),
  1492. projectNameInputVal = projectNameInput[0].value.trim();
  1493.  
  1494. const gitpattern = /^http:\/\/192\.168/;
  1495. const svnpattern = /^svn:\/\/192\.168/;
  1496. const sourcepattern = /^(svn:\/\/192\.168|http:\/\/192\.168)/;
  1497.  
  1498. if (!sourceInputVal) {
  1499. vueInstance.$message({
  1500. type: 'error',
  1501. message: '请输入源码地址!'
  1502. });
  1503. return
  1504. }
  1505.  
  1506. if (!sourcepattern.test(sourceInputVal)) {
  1507. vueInstance.$message({
  1508. type: 'error',
  1509. message: '请输入准确的源码 gitlab 或 svn 地址!'
  1510. });
  1511. return
  1512. }
  1513.  
  1514. if (svnpattern.test(sourceInputVal) && !projectNameInputVal) {
  1515. vueInstance.$message({
  1516. type: 'error',
  1517. message: ' svn 仓库地址部署需要填写项目(案例)名称!'
  1518. });
  1519. return
  1520. }
  1521.  
  1522. vueInstance.showDialog(svnpattern.test(sourceInputVal));
  1523. });
  1524. // 查看项目
  1525. $btnView.on('click', function() {
  1526. vueInstance.viewProject();
  1527. });
  1528.  
  1529. },
  1530. template: `<div id="my-form">
  1531. <el-dialog title="部署提示" width="640px" :visible.sync="dialogDeployVisible">
  1532. <el-alert
  1533. title="此操作将把 GitLab / SVN 资源打包部署至 170 服务器,已部署过的项目会进行覆盖部署,是否继续?"
  1534. type="warning" :closable="false" style="margin-bottom: 20px;">
  1535. </el-alert>
  1536. <el-form :model="form" ref="form" :rules="rules">
  1537. <el-form-item label="框架类型" :label-width="formLabelWidth" prop="frame">
  1538. <el-select v-model="form.frame" placeholder="请框架类型" style="width:380px;">
  1539. <el-option v-for="item in framework" :key="item.value" :label="item.label" :value="item.value"></el-option>
  1540. </el-select>
  1541. </el-form-item>
  1542. <el-form-item label="部署路径" :label-width="formLabelWidth" prop="deployPath" v-if="showDeployPath">
  1543. <el-input v-model="form.deployPath" placeholder="请输入部署至服务器 170/showcase 下的目标路径名称" style="width:380px;"></el-input>
  1544. </el-form-item>
  1545. </el-form>
  1546. <div slot="footer" class="dialog-footer">
  1547. <el-button @click="dialogDeployVisible = false">取 消</el-button>
  1548. <el-button type="primary" @click="doDeploy">确 定</el-button>
  1549. </div>
  1550. </el-dialog>
  1551. <el-dialog
  1552. title="部署"
  1553. width="420px"
  1554. :visible.sync="depDialogVisible">
  1555. <div class="deploy-body"
  1556. style="height: 306px;"
  1557. v-loading="loading"
  1558. element-loading-text="正在打包部署至 170 服务器,请耐心等待"
  1559. element-loading-spinner="el-icon-loading">
  1560. </div>
  1561. </el-dialog>
  1562. <el-dialog
  1563. title="目录结构"
  1564. width="900px"
  1565. :append-to-body="true"
  1566. :visible.sync="dialogVisible">
  1567. <el-tree
  1568. class="filter-tree"
  1569. :data="data"
  1570. :props="defaultProps"
  1571. node-key="id"
  1572. default-expand-all
  1573. @node-click="handleNodeClick"
  1574. v-loading="loadingTree"
  1575. element-loading-background="rgba(255, 255, 255, 1)"
  1576. element-loading-text="拼命加载中......"
  1577. ref="tree">
  1578. </el-tree>
  1579. </el-dialog>
  1580. </div>`
  1581. });
  1582.  
  1583. // 将占位元素追加到 body 元素中
  1584. jQuery('.form-container').after(vueInstance.$el);
  1585. };
  1586. })();
  1587.  
  1588. // 新建项目提示
  1589. // 新建项目查找重复项目
  1590. (function() {
  1591. 'use strict';
  1592. let regs = [/^http:\/\/192\.168\.0\.200\/projects\/new/];
  1593. let match = false;
  1594.  
  1595. for(let r = 0, lr = regs.length; r < lr; r++) {
  1596. if(regs[r].test(location.href)) {
  1597. match = true;
  1598. break;
  1599. }
  1600. }
  1601.  
  1602. if(!match) {
  1603. return;
  1604. }
  1605.  
  1606. // 等待页面加载完成
  1607. window.addEventListener('load', function() {
  1608. const $projectName = jQuery('#project_name');
  1609. const $projectDescription = jQuery('#project_description');
  1610. const $check = jQuery('#project_visibility_level_10');
  1611. const $projectPath = jQuery('#project_path');
  1612.  
  1613. // 页面参数
  1614. const p = gitlabUtil.getUrlParameters();
  1615. const projectName = p.projectName;
  1616. const projectBu = p.bu;
  1617. const projectType = p.projectType;
  1618. const frame = p.frame;
  1619. let vueInstance;
  1620. let uiUrl = p.uiUrl;
  1621. if(uiUrl && uiUrl !== '后补' && uiUrl.indexOf('interaction-design-portal') > -1 ) {
  1622. uiUrl += '=' + location.href.substr(location.href.length - 50, 36);
  1623. }
  1624.  
  1625. if($projectName && $projectName.length) {
  1626. $projectName.attr('placeholder', '以需求或项目管理系统中的项目名称为准');
  1627. if(projectName) {
  1628. $projectName.val(projectName);
  1629. $projectName.trigger('change');
  1630. // 防止项目名称中有英文单词时,会自动填充项目标识串。
  1631. $projectPath.val('');
  1632. }
  1633.  
  1634. // 添加检索重复项目按钮
  1635. const btnPlaceholder = document.createElement('div');
  1636.  
  1637. // 创建 Vue 实例并挂载到页面
  1638. vueInstance = new Vue({
  1639. el: btnPlaceholder,
  1640. data: function() {
  1641. return {
  1642. showBtn: false
  1643. };
  1644. },
  1645. methods: {
  1646. // 打开检索弹窗
  1647. check: function() {
  1648. let name = $projectName.val().trim();
  1649. // 去除临时
  1650. name = name.replace('(临时)', '').replace('临时', '');
  1651. // 去除项目
  1652. // name = name.replace('项目', '');
  1653. // 去除子系统,即第一个 - 后面的字符串
  1654. name = name.split('-')[0];
  1655. name = name.split('——')[0];
  1656. if(name.length > 20) {
  1657. name = name.substring(0, 20);
  1658. }
  1659. window.open('http://192.168.0.200/?name=' + name);
  1660.  
  1661. },
  1662. // 同步输入框和按钮状态
  1663. checkInput: function() {
  1664. if($projectName.val().trim() != '') {
  1665. this.showBtn = true;
  1666. } else {
  1667. this.showBtn = false;
  1668. }
  1669. }
  1670. },
  1671. mounted: function() {
  1672. let self = this;
  1673. self.checkInput();
  1674.  
  1675. $projectName.on('change', function() {
  1676. self.checkInput();
  1677. });
  1678. },
  1679. template: `<div>
  1680. <div style="position:absolute; top: 29px; left: 343px;" v-show="showBtn">
  1681. <el-tooltip content="检索已创建的项目,避免重复创建" placement="top" effect="light">
  1682. <el-button type="primary" style="vertical-align: top;" icon="el-icon-search" size="small" id="create-project" @click="check">检索</el-button>
  1683. </el-tooltip>
  1684. </div>
  1685. </div>`
  1686. });
  1687.  
  1688. // 将占位元素追加到 项目名称输入框 后面
  1689. $projectName.parent('.form-group')[0].appendChild(vueInstance.$el);
  1690. }
  1691.  
  1692. if($projectDescription && $projectDescription.length) {
  1693. let date = new Date();
  1694. const imgEl = document.querySelector('.header-user-avatar');
  1695. let name = imgEl ? imgEl.getAttribute('alt') : '张三';
  1696. name = name.replace('(前端研发3部)', '');
  1697. $projectDescription.attr('placeholder', 'YYYY-M-D,张三,UI:https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplatesdetail?guid=');
  1698. $projectDescription.val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ','+ name +',UI:' + (uiUrl ? uiUrl : 'https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplatesdetail?guid='));
  1699. $projectDescription.prev('.label-bold').find('span').text(' (UI备份地址完善后会自动获取项目名称、业务条线和项目类型)')
  1700.  
  1701. $projectDescription[0].setAttribute("maxlength", "1000");
  1702. // 增加主题表单
  1703. var themeHtml = '<div class="row">\
  1704. <div class="form-group col-md-9">\
  1705. <label class="label-bold" for="project_topics">主题<i style="color:red; font-style:normal; font-weight: 400; padding-left: 5px;">业务系统类型关键字添加框架版本</i></label>\
  1706. <input value="" maxlength="2000" class="form-control gl-form-input" placeholder="业务条线(政务服务|一网协同...),项目类型(网站|业务系统|中屏可视化...),关键字(f950sp2|gojs|vue...)" size="2000" type="text" name="project[topics]" id="project_topics" data-is-dirty-submit-input="true" data-dirty-submit-original-value="">\
  1707. <p class="form-text text-muted">用逗号分隔主题。</p>\
  1708. <p class="form-text text-muted">业务条线:政务服务、大数据、一网统管、一网协同、智能设备、电子交易、数字建设、公共安全、支撑产品;</p>\
  1709. <p class="form-text text-muted">项目类型:网站、业务系统、智能设备、大屏可视化、中屏可视化、在线表单;</p>\
  1710. <p class="form-text text-muted">关键字:f942f951f950sp2f9x2.0f9x1.0、骨架、vuereact、单页、gojselementAntDesign、全景、关系图、流程图、响应式、svg、视频、miniuiegisegis3d、高德、百度、超图、three、主题、瀑布流、上传、自定义用户控件等;</p>\
  1711. </div></div>';
  1712.  
  1713. $projectDescription.closest('.form-group').after(themeHtml);
  1714.  
  1715. var $theme = jQuery('#project_topics');
  1716.  
  1717. // 规避中文,
  1718. $projectDescription.blur(function(event) {
  1719. this.value = this.value.replace(/,/g, ',').replace(/&isfwqfb=1/g, '');
  1720. // 日期转换
  1721. this.value = convertDateFormat(this.value);
  1722.  
  1723. // 检测主题是否为空,且是否已输入uiUrl
  1724. if ($theme.val().trim() == '') {
  1725. var regex = /guid=([0-9a-fA-F-]{36})/; // 匹配整个URL字符串中的guid后的36位字符
  1726.  
  1727. var match = this.value.match(regex);
  1728.  
  1729. if (match) {
  1730. var extractedGuid = match[1];
  1731. // console.log(extractedGuid);
  1732. // 通过 guid 请求数据
  1733. var apiUrl = 'https://oa.epoint.com.cn/interaction-design-portal/rest/portal/pages/casestemplates/casestemplatesdetailaction/page_load'
  1734. if(this.value.indexOf('dynamiceffecttemplates') > -1) {
  1735. apiUrl = 'https://oa.epoint.com.cn/interaction-design-portal/rest/portal/pages/dynamiceffecttemplates/dynamiceffecttemplatesdetailaction/page_load';
  1736. }
  1737.  
  1738. // 获取项目信息
  1739. GM_xmlhttpRequest({
  1740. method: 'GET',
  1741. url: apiUrl + '?guid='+ extractedGuid +'&isCommondto=true',
  1742. headers: {
  1743. 'Content-Type': 'application/json; charset=utf-8'
  1744. },
  1745. onload: function(res) {
  1746. const data = JSON.parse(res.response);
  1747. let pData = data.custom.casetemplatedata || data.custom.dynamiceffecttemplatesdata;
  1748. let proBu = pData.stripline || pData.line;
  1749. const proType = pData.type;
  1750. const proName = pData.project || pData.title;
  1751. switch(proBu) {
  1752. case '政务BG':
  1753. proBu = '政务服务';
  1754. break;
  1755. case '建设BG':
  1756. proBu = '数字建设';
  1757. break;
  1758. case '交易BG':
  1759. proBu = '电子交易';
  1760. break;
  1761. case '智能设备BU':
  1762. proBu = '智能设备';
  1763. break;
  1764. }
  1765. proName && $projectName.val(proName);
  1766. proBu && proType && $theme.val(proBu + ', ' + proType);
  1767. $projectName.trigger('change');
  1768. }
  1769. });
  1770. }
  1771. }
  1772. });
  1773.  
  1774.  
  1775. if(projectBu) {
  1776. $theme.val(projectBu);
  1777. }
  1778.  
  1779. if(projectType && projectType !== '智能化设备') {
  1780. $theme.val($theme.val() + ', ' + projectType);
  1781. }
  1782.  
  1783. if(frame) {
  1784. $theme.val($theme.val() + ', ' + frame);
  1785. }
  1786.  
  1787. $theme.blur(function(event) {
  1788. this.value = this.value.replaceAll(',', ',');
  1789.  
  1790. });
  1791. }
  1792.  
  1793. if($check && $check.length) {
  1794. $check.trigger('click');
  1795. }
  1796. });
  1797.  
  1798. })();
  1799.  
  1800. // 通过 oa 首页中转,跳过跨站访问的限制
  1801. (function(){
  1802. 'use strict';
  1803. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/epointoa9\/frame\/fui\/pages\/themes\/aide/];
  1804. let match = false;
  1805.  
  1806. for(let r = 0, lr = regs.length; r < lr; r++) {
  1807. if(regs[r].test(location.href)) {
  1808. match = true;
  1809. break;
  1810. }
  1811. }
  1812.  
  1813. if(!match) {
  1814. return;
  1815. }
  1816.  
  1817. let redirectUlr = gitlabUtil.getUrlParameters().redirect;
  1818.  
  1819. if(redirectUlr) {
  1820. window.location.href = redirectUlr;
  1821. }
  1822. })();
  1823.  
  1824. // 设计门户瀑布流页面,查找对应项目
  1825. (function(){
  1826. 'use strict';
  1827. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/casestemplates\/casetemplateslist/];
  1828. let match = false;
  1829.  
  1830. for(let r = 0, lr = regs.length; r < lr; r++) {
  1831. if(regs[r].test(location.href)) {
  1832. match = true;
  1833. break;
  1834. }
  1835. }
  1836.  
  1837. if(!match) {
  1838. return;
  1839. }
  1840.  
  1841. let projectName = location.href.split('projectname');
  1842.  
  1843. window.addEventListener('load', function() {
  1844. if(projectName[1]) {
  1845. projectName = decodeURIComponent(projectName[1]);
  1846.  
  1847. const $input = jQuery('#search-input');
  1848. const $searchBtn = jQuery('.search-icon');
  1849.  
  1850. setTimeout(() => {
  1851. $input.val(projectName);
  1852. $searchBtn.trigger('click');
  1853. }, 1000);
  1854. }
  1855. });
  1856. })();
  1857.  
  1858. // 邮件详情页可以创建项目
  1859. (function() {
  1860. 'use strict';
  1861. let regs = [/^https:\/\/oa\.epoint\.com\.cn\:8080\/OA9\/oa9\/mail\/mailreceivedetail/,
  1862. /^https:\/\/oa\.epoint\.com\.cn\/OA9\/oa9\/mail\/mailreceivedetail/];
  1863. let match = false;
  1864.  
  1865. for(let r = 0, lr = regs.length; r < lr; r++) {
  1866. if(regs[r].test(location.href)) {
  1867. match = true;
  1868. break;
  1869. }
  1870. }
  1871.  
  1872. if(!match) {
  1873. return;
  1874. }
  1875.  
  1876. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  1877.  
  1878. // 添加样式规则,将字体应用到指定元素上
  1879. GM_addStyle(`
  1880. @font-face {
  1881. font-family: element-icons;
  1882. src: url(${fontUrl}) format("woff");
  1883. }
  1884. `);
  1885.  
  1886. GM_addStyle(GM_getResourceText('ElementCSS'));
  1887.  
  1888. // 在邮件签收情况后添加按钮-新建项目
  1889. function initCreate() {
  1890. const title = document.querySelector('#mail-detail-container .dtt');
  1891. let vueInstance;
  1892. let gitUrl = 'http://192.168.0.200/projects/new?namespace_id=4817';
  1893.  
  1894. if(title) {
  1895. const btnPlaceholder = document.createElement('div');
  1896. let tds = jQuery('#mailcontent table').find("td[colspan='3']");
  1897. tds = tds.length ? tds : jQuery('#mailcontent table').find("td:nth-child(2)");
  1898. const projectName = tds.eq(0).text().trim().replace('(临时)', '').replace('(临时)', '');
  1899. const firstTdtext = jQuery('#mailcontent table').find("th,td").eq(0).text().trim();
  1900. const isFrontEndEmail = jQuery('#mailcontent table').length && firstTdtext && (firstTdtext == '项目名称' || firstTdtext == '产品名称');
  1901. let bu = '政务服务';
  1902. let projectType = '';
  1903. let frame = '';
  1904. const demandUrl = tds.eq(1).text();
  1905. let uiUrl = '';
  1906.  
  1907. // 由于表格格式不固定,重新遍历一遍获取 uiUrl 和 frame
  1908. tds.each(function(i, el) {
  1909. if(jQuery(el).prev().text().trim() == '备份地址') {
  1910. uiUrl = jQuery(el).text().trim();
  1911. }
  1912. if(jQuery(el).prev().text().trim() == '框架版本') {
  1913. frame = jQuery(el).text().trim();
  1914. }
  1915. if(jQuery(el).prev().text().trim() == '设计类型') {
  1916. projectType = jQuery(el).text().trim();
  1917. }
  1918. });
  1919.  
  1920. uiUrl = uiUrl ? removeQueryStringParameter(uiUrl, 'isfwqfb') : '';
  1921. const backGuid = extractGuidFromUrl(uiUrl);
  1922.  
  1923. if(!isFrontEndEmail) {
  1924. return;
  1925. }
  1926.  
  1927. // 请求项目信息地址
  1928. let apiUrl = '';
  1929.  
  1930. apiUrl = uiUrl.split('?')[0];
  1931. apiUrl = apiUrl.split('interaction-design-portal')[0] + 'interaction-design-portal/rest' + apiUrl.split('interaction-design-portal')[1] + 'action/page_load';
  1932.  
  1933. if(apiUrl.indexOf('casetemplatesdetailaction') > -1) {
  1934. apiUrl = apiUrl.replace('casetemplatesdetailaction', 'casestemplatesdetailaction');
  1935. }
  1936.  
  1937. // 创建 Vue 实例并挂载到页面
  1938. vueInstance = new Vue({
  1939. el: btnPlaceholder,
  1940. data: function() {
  1941. return {
  1942. proBu: bu,
  1943. proType: projectType
  1944. };
  1945. },
  1946. methods: {
  1947. create: function() {
  1948. window.open(gitUrl + '&projectName=' + projectName + '&bu=' + this.proBu + '&projectType=' + this.proType + '&frame=' + frame + '&uiUrl=' + uiUrl + '#blank_project');
  1949. },
  1950. search: function() {
  1951. window.open('http://192.168.0.200/?name=' + projectName);
  1952. }
  1953. },
  1954. mounted: function() {
  1955. let self = this;
  1956. // 获取项目信息
  1957. GM_xmlhttpRequest({
  1958. method: 'GET',
  1959. url: apiUrl + '?guid='+ backGuid +'&isfwqfb=1&isCommondto=true',
  1960. headers: {
  1961. 'Content-Type': 'application/json; charset=utf-8'
  1962. },
  1963. onload: function(res) {
  1964. const data = JSON.parse(res.response);
  1965. let pData = data.custom.casetemplatedata || data.custom.dynamiceffecttemplatesdata;
  1966. self.proBu = pData.stripline || pData.line;
  1967. self.proType = pData.type;
  1968. switch(self.proBu) {
  1969. case '政务BG':
  1970. self.proBu = '政务服务';
  1971. break;
  1972. case '建设BG':
  1973. self.proBu = '数字建设';
  1974. break;
  1975. case '交易BG':
  1976. self.proBu = '电子交易';
  1977. break;
  1978. case '智能设备BU':
  1979. self.proBu = '智能设备';
  1980. break;
  1981. }
  1982. }
  1983. });
  1984. },
  1985. template: `<div style="display:inline-block; margin-left: 5px; vertical-align: top;">
  1986. <el-tooltip content="去 GitLab 创建项目" placement="top" effect="light">
  1987. <el-button type="primary" style="vertical-align: top;" icon="el-icon-folder-add" circle size="mini" id="create-project" @click="create"></el-button>
  1988. </el-tooltip>
  1989. <el-tooltip content="去 GitLab 查找项目" placement="top" effect="light">
  1990. <el-button type="primary" style="vertical-align: top;" icon="el-icon-search" circle size="mini" @click="search"></el-button>
  1991. </el-tooltip>
  1992. </div>`
  1993. });
  1994.  
  1995. // 将占位元素追加到 邮件标题后 元素中
  1996. // f9 框架会冲突
  1997. title.appendChild(vueInstance.$el);
  1998. // jQuery(title).append(vueInstance.$el.outerHTML);
  1999.  
  2000. /*
  2001. jQuery('#create-project').on('click', function() {
  2002. window.open(gitUrl);
  2003. });*/
  2004. }
  2005. }
  2006.  
  2007. function extractGuidFromUrl(url) {
  2008. const regex = /[?&]guid=([^&]+)/;
  2009. const match = url.match(regex);
  2010.  
  2011. if (match) {
  2012. return match[1]; // 第一个捕获组中的值即为 guid
  2013. } else {
  2014. return null; // 如果没有匹配到 guid,则返回 null
  2015. }
  2016. }
  2017.  
  2018. function removeQueryStringParameter(url, parameterName) {
  2019. const urlParts = url.split('?');
  2020.  
  2021. if (urlParts.length === 2) {
  2022. const baseUrl = urlParts[0];
  2023. const queryString = urlParts[1];
  2024.  
  2025. const parameters = queryString.split('&').filter(param => {
  2026. const paramName = param.split('=')[0];
  2027. return paramName !== parameterName;
  2028. });
  2029.  
  2030. if (parameters.length > 0) {
  2031. return baseUrl + '?' + parameters.join('&');
  2032. } else {
  2033. return baseUrl;
  2034. }
  2035. }
  2036.  
  2037. return url;
  2038. }
  2039.  
  2040. window.addEventListener('load', function() {
  2041. setTimeout(function() {
  2042. initCreate();
  2043. }, 500);
  2044. });
  2045.  
  2046. })();
  2047.  
  2048. // 需求详情页,增加设为待办功能
  2049. (function() {
  2050. 'use strict';
  2051. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/productrelease\/cpzt\/demandmanageznsb\/demandbasicinfo_detail/];
  2052. let match = false;
  2053.  
  2054. for(let r = 0, lr = regs.length; r < lr; r++) {
  2055. if(regs[r].test(location.href)) {
  2056. match = true;
  2057. break;
  2058. }
  2059. }
  2060.  
  2061. if(!match) {
  2062. return;
  2063. }
  2064.  
  2065. window.addEventListener('load', function() {
  2066. const $toolbar = jQuery('.fui-toolbar');
  2067.  
  2068. $toolbar.find('.btn-group').eq(0).after('<div class="fe-add"><span class="mini-button mini-btn-danger" state="danger" id="mark">在飞书中标记待办</span></div>');
  2069.  
  2070. mini.parse($toolbar);
  2071.  
  2072. const markbtn = mini.get('mark');
  2073. const guid = gitlabUtil.getUrlParameters().ProcessVersionInstanceGuid;
  2074.  
  2075. markbtn.on('click', function(e) {
  2076. window.open('https://k7n084n7rx.feishu.cn/base/bascnxklVJQ9VqGGkc4bmu3YJPb?table=tblJhJ9dr4N3AKDr&view=vewNNJTfJp&demandGuid=' + guid );
  2077. });
  2078. });
  2079.  
  2080. })();
  2081.  
  2082. // 更新脚本同步版本信息
  2083. (function() {
  2084. 'use strict';
  2085. let regs = [/^https:\/\/greasyfork\.org\/zh-CN\/scripts\/466808\/versions\/new/];
  2086. let match = false;
  2087.  
  2088. for(let r = 0, lr = regs.length; r < lr; r++) {
  2089. if(regs[r].test(location.href)) {
  2090. match = true;
  2091. break;
  2092. }
  2093. }
  2094.  
  2095. if(!match) {
  2096. return;
  2097. }
  2098.  
  2099. const p = document.getElementById('script-description');
  2100. const href = 'http://192.168.0.200/-/ide/project/fe3group/gitlabassistant-web/edit/main/-/version.json';
  2101.  
  2102. const linkElement = document.createElement("a");
  2103.  
  2104. linkElement.href = href; // 设置超链接的URL
  2105. linkElement.textContent = "去同步脚本版本"; // 设置超链接的文本内容
  2106. linkElement.target = '_blank';
  2107.  
  2108. // 将超链接元素插入到目标元素的后面
  2109. p.parentNode.insertBefore(linkElement, p.nextSibling);
  2110. })();