GitLab Assistant

GitLab Viewer Publish and Deploy Project!

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

  1. // ==UserScript==
  2. // @name GitLab Assistant
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.09998
  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 = 'https://gitassest.oss-cn-shanghai.aliyuncs.com/base/element-icons.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. debugger;
  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. const placeholder = document.createElement('div');
  809.  
  810. // 创建 Vue 实例并挂载到页面
  811. const vueInstance = new Vue({
  812. el: placeholder,
  813. components: {
  814. MyComponent
  815. },
  816. methods: {
  817. },
  818. template: `<my-component></my-component>`
  819. });
  820.  
  821. // 开始在项目仓库页添加搜索设计门户按钮 start
  822. const panel = document.querySelector('.project-home-panel');
  823. let vueInstance2;
  824. const description = document.querySelector('.read-more-container');
  825. const descriptionText = description && description.innerText;
  826. let haveDesignBackupUrl = /platesdetail\?guid=(?!$)/.test(descriptionText);
  827.  
  828. if(panel && !haveDesignBackupUrl) {
  829. const btnPlaceholder = document.createElement('div');
  830. btnPlaceholder.setAttribute('class', 'epoint-portal-search');
  831. // 创建 Vue 实例并挂载到页面
  832. vueInstance2 = new Vue({
  833. el: btnPlaceholder,
  834. data: function() {
  835. return {
  836. proName: document.querySelector('.home-panel-title').innerText.trim().substring(0, 4)
  837. };
  838. },
  839. methods: {
  840. manage() {
  841. 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)
  842. }
  843. },
  844. template: `<div style="margin-top:4px;">
  845. <el-tooltip content="新点设计门户中查找此项目" placement="top" effect="light">
  846. <el-button type="primary" icon="el-icon-search" size="small" @click="manage">查找UI备份地址</el-button>
  847. </el-tooltip>
  848. </div>`
  849. });
  850. // 开始在项目仓库页添加搜索设计门户按钮 end
  851. }
  852.  
  853.  
  854. // 等待页面加载完成
  855. window.addEventListener('load', function() {
  856. // 将占位元素追加到 body 元素中
  857. document.body.appendChild(vueInstance.$el);
  858.  
  859. panel && !haveDesignBackupUrl && panel.appendChild(vueInstance2.$el);
  860.  
  861. // 克隆按钮下增加sourcetree 快捷打开方式
  862. const dropMenu = document.querySelector('.clone-options-dropdown');
  863.  
  864. if(dropMenu) {
  865. // 协议的方式 sourcetree://cloneRepo?type=stash&cloneUrl=http://192.168.0.200/fe3project/taicang-vue-website.git
  866. let sourceTreeHtml = '<li class="pt-2 gl-new-dropdown-item">\
  867. <label class="label-bold gl-px-4!" xt-marked="ok">在您的Sourcetree中打开</label>\
  868. <a class="dropdown-item open-with-link" href="sourcetree://cloneRepo?type=stash&cloneUrl='+ document.getElementById('http_project_clone').value +'">\
  869. <div class="gl-new-dropdown-item-text-wrapper" xt-marked="ok">Sourcetree (HTTPS)</div></a></li>';
  870.  
  871. jQuery(dropMenu).append(sourceTreeHtml);
  872. }
  873. });
  874.  
  875. // 将文件条目组织成嵌套结构
  876. function organizeFileEntries(fileEntries) {
  877. const root = {
  878. label: document.querySelector('.home-panel-title').innerText || document.getElementById('project_name_edit').value,
  879. type: 'folder',
  880. children: []
  881. };
  882.  
  883. // 创建嵌套结构
  884. fileEntries.forEach(entry => {
  885. const pathSegments = entry.name.split('/');
  886. let currentFolder = root;
  887.  
  888. // 遍历路径中的每个部分,创建相应的文件夹节点
  889. for (let i = 0; i < pathSegments.length - 1; i++) {
  890. const folderName = pathSegments[i];
  891. let folder = currentFolder.children.find(child => child.label === folderName);
  892.  
  893. if(isExcludeFolder(entry.name)) {
  894. continue;
  895. }
  896.  
  897. if (!folder) {
  898. folder = {
  899. label: folderName,
  900. type: 'folder',
  901. children: []
  902. };
  903. currentFolder.children.push(folder);
  904. }
  905.  
  906. currentFolder = folder;
  907. }
  908.  
  909. // 创建文件节点并添加到相应的文件夹中
  910. const fileName = pathSegments[pathSegments.length - 1];
  911.  
  912. if(fileName && fileName.length && isIncludeFile(fileName) && !isExcludeFolder(entry.name)) {
  913. const fileNode = {
  914. label: fileName,
  915. type: 'file',
  916. entry: entry.name
  917. };
  918. currentFolder.children.push(fileNode);
  919. }
  920. });
  921.  
  922. return [root];
  923. }
  924. // 是否排除的文件夹
  925. function isExcludeFolder(entry) {
  926. if(entry.indexOf('css') > -1 ||
  927. entry.indexOf('scss') > -1 ||
  928. entry.indexOf('js') > -1 ||
  929. entry.indexOf('images') > -1 ||
  930. entry.indexOf('fui') > -1 ||
  931. entry.indexOf('lib') > -1 ||
  932. entry.indexOf('test') > -1 ||
  933. entry.indexOf('font') > -1 ||
  934. entry.indexOf('frame/fui') > -1) {
  935. return true;
  936. } else {
  937. return false;
  938. }
  939. }
  940. // 是否包含的文件
  941. function isIncludeFile(fileName) {
  942. if(fileName.indexOf('.html') > -1) {
  943. return true;
  944. } else {
  945. return false;
  946. }
  947. }
  948.  
  949. function getZipResource(callback) {
  950. const downloadUrl = window.location.origin + document.querySelector('.gl-button.btn-sm.btn-confirm').getAttribute('href');
  951.  
  952. fetch(downloadUrl)
  953. .then(response => response.arrayBuffer())
  954. .then(data => {
  955. // 将 ZIP 文件的二进制数据传递给 JSZip 进行解析
  956. return JSZip.loadAsync(data);
  957. })
  958. .then(zip => {
  959. // 获取 ZIP 文件中的所有条目(文件和目录)
  960. const zipEntries = Object.values(zip.files);
  961. const treeData = organizeFileEntries(zipEntries)
  962.  
  963. callback && callback(treeData);
  964.  
  965. })
  966. .catch(error => {
  967. console.error(error);
  968. });
  969. }
  970.  
  971. // 树结构第一个节点数据
  972. function findFirstFileNode(tree) {
  973. // 遍历树的节点
  974. for (let i = 0; i < tree.length; i++) {
  975. const node = tree[i];
  976.  
  977. // 如果节点的类型为 file,则返回该节点
  978. if (node.type === 'file') {
  979. return node;
  980. }
  981.  
  982. // 如果节点有子节点,则递归调用该函数查找子节点中的第一个 file 节点
  983. if (node.children && node.children.length > 0) {
  984. const fileNode = findFirstFileNode(node.children);
  985. if (fileNode) {
  986. return fileNode;
  987. }
  988. }
  989. }
  990.  
  991. // 如果没有找到 file 节点,则返回 null
  992. return null;
  993. }
  994. })();
  995.  
  996. // 修改项目描述的长度
  997. (function() {
  998. 'use strict';
  999. let regs = [/^http:\/\/192\.168\.0\.200\/fe3project\//,
  1000. /^http:\/\/192\.168\.0\.200\/frontend_pc\/project\//];
  1001. let match = false;
  1002.  
  1003. for(let r = 0, lr = regs.length; r < lr; r++) {
  1004. if(regs[r].test(location.href)) {
  1005. match = true;
  1006. break;
  1007. }
  1008. }
  1009.  
  1010. if(!match) {
  1011. return;
  1012. }
  1013.  
  1014. let tryTimes = 6;
  1015. let changed = false;
  1016.  
  1017. // 增加项目描述的输入长度
  1018. function modifyTextareaLen() {
  1019. if(tryTimes > 0 && !changed) {
  1020. setTimeout(() => {
  1021. const textarea = document.getElementById('project_description');
  1022. tryTimes--;
  1023. if(textarea) {
  1024. textarea.setAttribute("maxlength", "1000");
  1025.  
  1026. jQuery(textarea).blur(function(event) {
  1027. this.value = this.value.replace(/,/g, ',').replace(/&isfwqfb=1/g, '');
  1028. this.value = convertDateFormat(this.value);
  1029. jQuery(this).trigger('change');
  1030. });
  1031. changed = true;
  1032. } else {
  1033. modifyTextareaLen();
  1034. }
  1035. }, 1000);
  1036. }
  1037. }
  1038.  
  1039. window.onload = function() {
  1040. modifyTextareaLen();
  1041. }
  1042. })();
  1043.  
  1044. // 设计门户增加通往前端仓库的跳板
  1045. (function() {
  1046. 'use strict';
  1047.  
  1048. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/casestemplates\/casetemplatesdetail/,
  1049. /^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/generalpagetemplates\/generalpagetemplatesdetail/,
  1050. /^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/dynamiceffecttemplates\/dynamiceffecttemplatesdetail/];
  1051. let match = false;
  1052.  
  1053. for(let r = 0, lr = regs.length; r < lr; r++) {
  1054. if(regs[r].test(location.href)) {
  1055. match = true;
  1056. break;
  1057. }
  1058. }
  1059.  
  1060. if(!match) {
  1061. return;
  1062. }
  1063.  
  1064. function addStyle() {
  1065. // 注入样式:增加按钮
  1066. 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}";
  1067.  
  1068.  
  1069. // 添加注入样式
  1070. let extraStyleElement = document.createElement("style");
  1071. extraStyleElement.innerHTML = injectStyle;
  1072. document.head.appendChild(extraStyleElement);
  1073. }
  1074.  
  1075. function getUrlParameters() {
  1076. var params = {};
  1077. var search = window.location.search.substring(1);
  1078. var urlParams = search.split('&');
  1079.  
  1080. for (var i = 0; i < urlParams.length; i++) {
  1081. var param = urlParams[i].split('=');
  1082. var paramName = decodeURIComponent(param[0]);
  1083. var paramValue = decodeURIComponent(param[1] || '');
  1084. params[paramName] = paramValue;
  1085. }
  1086.  
  1087. return params;
  1088. }
  1089.  
  1090. window.onload = ()=> {
  1091. addStyle();
  1092. const $content = jQuery('.content');
  1093.  
  1094. $content.append('<div class="front-proto">前端原型</div>');
  1095.  
  1096. const $frontBtn = jQuery('.front-proto', $content);
  1097.  
  1098. $frontBtn.on('click', ()=> {
  1099. window.open('http://192.168.0.200/?name=' + getUrlParameters().guid);
  1100. });
  1101. };
  1102. })();
  1103.  
  1104. // 前端项目案例库增加获取参数的能力
  1105. // 前端项目案例库增加部署能力
  1106. (function() {
  1107. 'use strict';
  1108.  
  1109. let regs = [/^http:\/\/192\.168\.118\.60:9999\/webapp\/pages\/caselib\/create\.html/,
  1110. /^http:\/\/192\.168\.201\.159:9999\/webapp\/pages\/default\/onlinecase.html/];
  1111. let match = false;
  1112.  
  1113. for(let r = 0, lr = regs.length; r < lr; r++) {
  1114. if(regs[r].test(location.href)) {
  1115. match = true;
  1116. break;
  1117. }
  1118. }
  1119.  
  1120. if(!match) {
  1121. return;
  1122. }
  1123.  
  1124. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  1125.  
  1126. // 添加样式规则,将字体应用到指定元素上
  1127. GM_addStyle(`
  1128. @font-face {
  1129. font-family: element-icons;
  1130. src: url(${fontUrl}) format("woff");
  1131. }
  1132. `);
  1133.  
  1134. GM_addStyle(GM_getResourceText('ElementCSS'));
  1135.  
  1136. const businessType = [
  1137. { Value: '7a20e23c-30b8-47e2-8d8d-f2691c9c63c4', Text: '政务服务' },
  1138. { Value: 'c12150bb-b358-452f-87f0-8a2254df87cb', Text: '政务协同' },
  1139. { Value: '3845804e-de68-421c-9402-7b238cfb5a70', Text: '大数据' },
  1140. { Value: '3c28ee56-f24d-4843-b9a2-93e6b96264f4', Text: '电子交易' },
  1141. { Value: '673b5918-51bc-4f1a-ab73-fca86e54d7d1', Text: '数字建设' },
  1142. { Value: '6d9e7d84-7de3-4e0f-bd4f-ed4722ed25b5', Text: '建筑企业' },
  1143. { Value: 'c22f8d2f-518d-4381-b88c-1da68536ed3a', Text: '公共安全' },
  1144. { Value: 'c5810829-1b21-4b22-85cd-390b1edd9614', Text: '智能设备' },
  1145. { Value: '080c7560-c261-428b-a45d-b86b57b47ffb', Text: '中央研究院' }
  1146. ];
  1147.  
  1148. const projectType = [
  1149. { Value: 'dca44f63-be3f-4e9c-b78f-d786571c22c9', Text: '网站' },
  1150. { Value: 'c7861460-163b-4060-80ec-d60604c50435', Text: '业务系统' },
  1151. { Value: '49accc71-6f7d-43f3-b726-58decf58b6fa', Text: '智能设备' },
  1152. { Value: '90209c65-1a55-4d8c-a836-2e5c6b834ada', Text: '大屏可视化' },
  1153. { Value: 'fb0415fb-65ee-42c1-895a-dca042c2568e', Text: '中屏可视化' },
  1154. { Value: '2b83f9b1-ec78-4819-a400-d7d49ea1ecc5', Text: '其他' }
  1155. ];
  1156.  
  1157. let $businesstype;
  1158. let $projecttype;
  1159.  
  1160. function getUrlParameters() {
  1161. var params = {};
  1162. var search = window.location.search.substring(1);
  1163. var urlParams = search.split('&');
  1164.  
  1165. for (var i = 0; i < urlParams.length; i++) {
  1166. var param = urlParams[i].split('=');
  1167. var paramName = decodeURIComponent(param[0]);
  1168. var paramValue = decodeURIComponent(param[1] || '');
  1169. if(paramName) {
  1170. params[paramName] = paramValue;
  1171. }
  1172. }
  1173.  
  1174. return params;
  1175. }
  1176.  
  1177. function initForm (params) {
  1178. if(typeof params === 'object') {
  1179. document.getElementsByName('Title')[0].value = params.projectName ? params.projectName : '';
  1180. document.getElementsByName('KeyWords')[0].value = params.projectKeys ? params.projectKeys : '';
  1181. document.getElementsByName('Entry')[0].value = params.entryUrl ? params.entryUrl : '';
  1182. document.getElementsByName('SourceCode')[0].value = params.git ? params.git : '';
  1183. }
  1184. }
  1185.  
  1186. let setSuccess = false;
  1187. let setTimes = 5;
  1188.  
  1189. function initSelect(params) {
  1190. if(typeof params !== 'object') {
  1191. return;
  1192. }
  1193.  
  1194. if(setTimes > 0 && !setSuccess) {
  1195. setTimeout(()=> {
  1196. setTimes--;
  1197.  
  1198. businessType.forEach((item)=> {
  1199. if(params.projectBU) {
  1200. if(item.Text === params.projectBU.trim()) {
  1201. $businesstype.val(item.Value);
  1202. } else if( params.projectBU.trim() == '一网统管' || params.projectBU.trim() == '一网协同' || params.projectBU.trim() == '一网通办' ) {
  1203. $businesstype.val('7a20e23c-30b8-47e2-8d8d-f2691c9c63c4');
  1204. }
  1205. $businesstype.trigger("chosen:updated");
  1206. }
  1207. });
  1208.  
  1209. projectType.forEach((item)=> {
  1210. if(params.projectType && item.Text === params.projectType.trim()) {
  1211. $projecttype.val(item.Value);
  1212. $projecttype.trigger("chosen:updated");
  1213. }
  1214. });
  1215.  
  1216. setSuccess = true;
  1217.  
  1218. }, 1000);
  1219. } else {
  1220. initSelect(params);
  1221. }
  1222. }
  1223.  
  1224. function addRelatedDom() {
  1225. const sourceInput = document.getElementsByName('SourceCode')[0];
  1226. const $sourceInput = jQuery(sourceInput);
  1227.  
  1228. $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>')
  1229. }
  1230.  
  1231. function addStyle() {
  1232. let epointCss = ".el-loading-spinner {margin-top: -50px;} .el-button--primary:focus {outline: 0 !important;}";
  1233. // 添加注入样式
  1234. let extraStyleElement = document.createElement("style");
  1235. extraStyleElement.innerHTML = epointCss;
  1236. document.head.appendChild(extraStyleElement);
  1237. }
  1238.  
  1239. window.onload = ()=> {
  1240. const params = getUrlParameters();
  1241.  
  1242. // 有参数,进行填充表单
  1243. if(params && params.git) {
  1244. $businesstype = jQuery('#businesstype');
  1245. $projecttype = jQuery('#projecttype');
  1246.  
  1247. initForm(params);
  1248. initSelect(params);
  1249.  
  1250. return false;
  1251. }
  1252.  
  1253. // 没有url参数填充,则做部署功能展示
  1254. addRelatedDom();
  1255. addStyle();
  1256.  
  1257. const placeholder = document.createElement('div');
  1258.  
  1259. // 创建 Vue 实例并挂载到页面
  1260. const vueInstance = new Vue({
  1261. el: placeholder,
  1262. data() {
  1263. return {
  1264. framework: [
  1265. {label: '重构模板', value: 1},
  1266. {label: 'f9x1.0', value: 2},
  1267. {label: 'f9x2.0', value: 3},
  1268. {label: 'f950', value: 4},
  1269. {label: 'f950sp1', value: 5},
  1270. {label: 'f950sp2', value: 6},
  1271. {label: 'f950sp3', value: 7},
  1272. {label: 'f951', value: 18},
  1273. {label: 'f940', value: 8},
  1274. {label: 'f941', value: 10},
  1275. {label: 'f942', value: 9},
  1276. {label: 'f934', value: 11},
  1277. {label: 'f933', value: 12},
  1278. {label: 'f932', value: 13},
  1279. {label: 'f9211', value: 14},
  1280. {label: '骨架', value: 15},
  1281. {label: 'Vue', value: 16},
  1282. {label: 'React', value: 17}
  1283. ],
  1284. data: [], // 目录结构树
  1285. defaultProps: {
  1286. children: 'children',
  1287. label: 'label'
  1288. },
  1289. loadingTree: false,
  1290. dialogVisible: false,
  1291. dialogDeployVisible: false,
  1292. showDeployPath: false,
  1293. depDialogVisible: false,
  1294. loading: false,
  1295. formLabelWidth: '120px',
  1296. supportDeploy: false,
  1297. form: {
  1298. frame: '',
  1299. deployPath: ''
  1300. },
  1301. rules: {
  1302. frame: [
  1303. { required: true, message: '请选择框架类型', trigger: 'change' }
  1304. ],
  1305. deployPath: [
  1306. { required: true, message: '请输入部署到 170/showcase 下的目标路径名称', trigger: 'change' }
  1307. ]
  1308. }
  1309. }
  1310. },
  1311. methods: {
  1312. // 部署
  1313. doDeploy() {
  1314. let self = this;
  1315.  
  1316. this.$refs['form'].validate((valid) => {
  1317. if (valid) {
  1318. this.dialogDeployVisible = false;
  1319. this.depDialogVisible = true;
  1320. this.loading = true;
  1321. // 部署
  1322. this.getDeployInfo({ type: '1', frame: this.form.frame, deployPath: this.form.deployPath }, (data)=> {
  1323. this.loading = false;
  1324. this.depDialogVisible = false;
  1325.  
  1326. if(!data.custom.text){
  1327.  
  1328. this.data = data.custom.pageTreeData;
  1329. this.projectFtpUrl = data.custom.projectRootPath;
  1330. this.supportDeploy = data.custom.supportDeploy;
  1331.  
  1332. this.$message({
  1333. type: 'success',
  1334. message: '部署成功!'
  1335. });
  1336. // 打开查看弹窗
  1337. this.viewProject();
  1338. this.toggleViewButton(true);
  1339.  
  1340. } else {
  1341. this.$message({
  1342. type: 'error',
  1343. message: data.custom.text
  1344. });
  1345. }
  1346. });
  1347. } else {
  1348. console.log('error submit!!');
  1349. return false;
  1350. }
  1351. });
  1352. },
  1353. // 项目部署
  1354. getDeployInfo(params, callback) {
  1355. const author = document.querySelector('#account a').innerText.trim().substring(4);
  1356. const projectName = document.getElementsByName('Title')[0].value.trim();
  1357. const projectGitUrl = document.getElementsByName('SourceCode')[0].value.trim();
  1358.  
  1359. if(typeof params == 'function') {
  1360. callback = params;
  1361. params = null;
  1362. }
  1363. if(author && author.length && projectGitUrl) {
  1364. fetch('http://192.168.219.170:3008/api/getDeployInfo', {
  1365. method: 'POST',
  1366. // 允许跨域请求
  1367. mode: 'cors',
  1368. headers: {
  1369. 'Accept': 'application/json',
  1370. 'Content-Type': 'application/json'
  1371. },
  1372. body: JSON.stringify({//post请求参数
  1373. params: {
  1374. "type": (params && params.type !== undefined) ? params.type : '0',// 0 代表查看, 1代表部署
  1375. "deployMan": author, // 部署人姓名
  1376. "projectName": projectName, // 项目名称
  1377. "projectGitUrl": projectGitUrl,
  1378. "frame": (params && params.frame) ? params.frame : undefined,
  1379. "deployPath": (params && params.deployPath) ? params.deployPath : undefined // 部署的目标目录
  1380. }
  1381. })
  1382. })
  1383. .then(response => response.text())
  1384. .then((result) => {
  1385. var data = JSON.parse(result);
  1386. callback && callback(data);
  1387. })
  1388. .catch(error => {
  1389. this.depDialogVisible = false;
  1390. this.dialogVisible = false;
  1391. this.$message({
  1392. type: 'error',
  1393. message: '系统故障,请联系管理员。'
  1394. });
  1395. console.error(error);
  1396. });
  1397. } else {
  1398. this.$message({
  1399. type: 'error',
  1400. message: '本页面不支持查看和部署,请先登录。'
  1401. });
  1402. console.error('部署信息请求参数error');
  1403. }
  1404. },
  1405. // 查看项目
  1406. viewProject () {
  1407. this.dialogVisible = true;
  1408. let self = this;
  1409.  
  1410. if(this.data) {
  1411. this.loadingTree = false;
  1412. } else {
  1413. this.loadingTree = true;
  1414. // 发送ajax请求,查看是否进行过部署
  1415. this.getDeployInfo((data)=> {
  1416. // 有部署信息,直接赋值,
  1417. if(data) {
  1418. self.projectIsDeployed = true;
  1419. self.data = data.custom.pageTreeData;
  1420. self.projectFtpUrl = data.custom.projectRootPath;
  1421. self.supportDeploy = data.custom.supportDeploy;
  1422. self.loadingTree = false;
  1423.  
  1424. self.toggleViewButton(true);
  1425.  
  1426. }
  1427. });
  1428. }
  1429. },
  1430. handleNodeClick(data) {
  1431. console.log(data);
  1432. if(data.type === 'folder') {
  1433. return false;
  1434. }
  1435. var self = this;
  1436. var entry = data.entry;
  1437. self.clickNodeEntry = entry;
  1438. if(self.projectFtpUrl) {
  1439. window.open('http://192.168.219.170' + self.projectFtpUrl + data.entry);
  1440. self.clickNodeEntry = null;
  1441. } else {
  1442. if(this.supportDeploy === false) {
  1443. this.$message({
  1444. type: 'error',
  1445. message: '当前项目暂时只支持查看,请耐心等待功能升级。'
  1446. });
  1447. self.clickNodeEntry = null;
  1448. return false;
  1449. }
  1450.  
  1451. this.$confirm('资源未部署,部署至 170 服务器后可查看,是否部署?')
  1452. .then(_ => {
  1453.  
  1454. this.dialogDeployVisible = true;
  1455. })
  1456. .catch(_ => {});
  1457. }
  1458. },
  1459. // svn 需要制定目录名称,showDeployPath
  1460. showDialog(showDeployPath) {
  1461. this.showDeployPath = showDeployPath;
  1462. this.dialogDeployVisible = true;
  1463. },
  1464. // 查看按钮显影控制
  1465. toggleViewButton(show) {
  1466. const $viewBtn = jQuery('#view');
  1467.  
  1468. if(!$viewBtn.length) {
  1469. return;
  1470. }
  1471.  
  1472. if(show) {
  1473. $viewBtn.removeClass('hidden');
  1474. } else {
  1475. $viewBtn.addClass('hidden');
  1476. }
  1477. }
  1478. },
  1479. mounted() {
  1480. const $btnDeloy = jQuery('#deploy');
  1481. const $btnView = jQuery('#view');
  1482.  
  1483. // 绑定vue组件外的事件
  1484. $btnDeloy.on('click', function() {
  1485. // 源码地址和项目名称判断
  1486. const sourceInput = document.getElementsByName('SourceCode');
  1487. const projectNameInput = document.getElementsByName('Title');
  1488.  
  1489. let sourceInputVal = sourceInput[0].value.trim(),
  1490. projectNameInputVal = projectNameInput[0].value.trim();
  1491.  
  1492. const gitpattern = /^http:\/\/192\.168/;
  1493. const svnpattern = /^svn:\/\/192\.168/;
  1494. const sourcepattern = /^(svn:\/\/192\.168|http:\/\/192\.168)/;
  1495.  
  1496. if (!sourceInputVal) {
  1497. vueInstance.$message({
  1498. type: 'error',
  1499. message: '请输入源码地址!'
  1500. });
  1501. return
  1502. }
  1503.  
  1504. if (!sourcepattern.test(sourceInputVal)) {
  1505. vueInstance.$message({
  1506. type: 'error',
  1507. message: '请输入准确的源码 gitlab 或 svn 地址!'
  1508. });
  1509. return
  1510. }
  1511.  
  1512. if (svnpattern.test(sourceInputVal) && !projectNameInputVal) {
  1513. vueInstance.$message({
  1514. type: 'error',
  1515. message: ' svn 仓库地址部署需要填写项目(案例)名称!'
  1516. });
  1517. return
  1518. }
  1519.  
  1520. vueInstance.showDialog(svnpattern.test(sourceInputVal));
  1521. });
  1522. // 查看项目
  1523. $btnView.on('click', function() {
  1524. vueInstance.viewProject();
  1525. });
  1526.  
  1527. },
  1528. template: `<div id="my-form">
  1529. <el-dialog title="部署提示" width="640px" :visible.sync="dialogDeployVisible">
  1530. <el-alert
  1531. title="此操作将把 GitLab / SVN 资源打包部署至 170 服务器,已部署过的项目会进行覆盖部署,是否继续?"
  1532. type="warning" :closable="false" style="margin-bottom: 20px;">
  1533. </el-alert>
  1534. <el-form :model="form" ref="form" :rules="rules">
  1535. <el-form-item label="框架类型" :label-width="formLabelWidth" prop="frame">
  1536. <el-select v-model="form.frame" placeholder="请框架类型" style="width:380px;">
  1537. <el-option v-for="item in framework" :key="item.value" :label="item.label" :value="item.value"></el-option>
  1538. </el-select>
  1539. </el-form-item>
  1540. <el-form-item label="部署路径" :label-width="formLabelWidth" prop="deployPath" v-if="showDeployPath">
  1541. <el-input v-model="form.deployPath" placeholder="请输入部署至服务器 170/showcase 下的目标路径名称" style="width:380px;"></el-input>
  1542. </el-form-item>
  1543. </el-form>
  1544. <div slot="footer" class="dialog-footer">
  1545. <el-button @click="dialogDeployVisible = false">取 消</el-button>
  1546. <el-button type="primary" @click="doDeploy">确 定</el-button>
  1547. </div>
  1548. </el-dialog>
  1549. <el-dialog
  1550. title="部署"
  1551. width="420px"
  1552. :visible.sync="depDialogVisible">
  1553. <div class="deploy-body"
  1554. style="height: 306px;"
  1555. v-loading="loading"
  1556. element-loading-text="正在打包部署至 170 服务器,请耐心等待"
  1557. element-loading-spinner="el-icon-loading">
  1558. </div>
  1559. </el-dialog>
  1560. <el-dialog
  1561. title="目录结构"
  1562. width="900px"
  1563. :append-to-body="true"
  1564. :visible.sync="dialogVisible">
  1565. <el-tree
  1566. class="filter-tree"
  1567. :data="data"
  1568. :props="defaultProps"
  1569. node-key="id"
  1570. default-expand-all
  1571. @node-click="handleNodeClick"
  1572. v-loading="loadingTree"
  1573. element-loading-background="rgba(255, 255, 255, 1)"
  1574. element-loading-text="拼命加载中......"
  1575. ref="tree">
  1576. </el-tree>
  1577. </el-dialog>
  1578. </div>`
  1579. });
  1580.  
  1581. // 将占位元素追加到 body 元素中
  1582. jQuery('.form-container').after(vueInstance.$el);
  1583. };
  1584. })();
  1585.  
  1586. // 新建项目提示
  1587. // 新建项目查找重复项目
  1588. (function() {
  1589. 'use strict';
  1590. let regs = [/^http:\/\/192\.168\.0\.200\/projects\/new/];
  1591. let match = false;
  1592.  
  1593. for(let r = 0, lr = regs.length; r < lr; r++) {
  1594. if(regs[r].test(location.href)) {
  1595. match = true;
  1596. break;
  1597. }
  1598. }
  1599.  
  1600. if(!match) {
  1601. return;
  1602. }
  1603.  
  1604. // 等待页面加载完成
  1605. window.addEventListener('load', function() {
  1606. const $projectName = jQuery('#project_name');
  1607. const $projectDescription = jQuery('#project_description');
  1608. const $check = jQuery('#project_visibility_level_10');
  1609. const $projectPath = jQuery('#project_path');
  1610.  
  1611. // 页面参数
  1612. const p = gitlabUtil.getUrlParameters();
  1613. const projectName = p.projectName;
  1614. const projectBu = p.bu;
  1615. const projectType = p.projectType;
  1616. const frame = p.frame;
  1617. let vueInstance;
  1618. let uiUrl = p.uiUrl;
  1619. if(uiUrl && uiUrl !== '后补' && uiUrl.indexOf('interaction-design-portal') > -1 ) {
  1620. uiUrl += '=' + location.href.substr(location.href.length - 50, 36);
  1621. }
  1622.  
  1623. if($projectName && $projectName.length) {
  1624. $projectName.attr('placeholder', '以需求或项目管理系统中的项目名称为准');
  1625. if(projectName) {
  1626. $projectName.val(projectName);
  1627. $projectName.trigger('change');
  1628. // 防止项目名称中有英文单词时,会自动填充项目标识串。
  1629. $projectPath.val('');
  1630. }
  1631.  
  1632. // 添加检索重复项目按钮
  1633. const btnPlaceholder = document.createElement('div');
  1634.  
  1635. // 创建 Vue 实例并挂载到页面
  1636. vueInstance = new Vue({
  1637. el: btnPlaceholder,
  1638. data: function() {
  1639. return {
  1640. showBtn: false
  1641. };
  1642. },
  1643. methods: {
  1644. // 打开检索弹窗
  1645. check: function() {
  1646. let name = $projectName.val().trim();
  1647. // 去除临时
  1648. name = name.replace('(临时)', '').replace('临时', '');
  1649. // 去除项目
  1650. // name = name.replace('项目', '');
  1651. // 去除子系统,即第一个 - 后面的字符串
  1652. name = name.split('-')[0];
  1653. name = name.split('——')[0];
  1654. if(name.length > 20) {
  1655. name = name.substring(0, 20);
  1656. }
  1657. window.open('http://192.168.0.200/?name=' + name);
  1658.  
  1659. },
  1660. // 同步输入框和按钮状态
  1661. checkInput: function() {
  1662. if($projectName.val().trim() != '') {
  1663. this.showBtn = true;
  1664. } else {
  1665. this.showBtn = false;
  1666. }
  1667. }
  1668. },
  1669. mounted: function() {
  1670. let self = this;
  1671. self.checkInput();
  1672.  
  1673. $projectName.on('change', function() {
  1674. self.checkInput();
  1675. });
  1676. },
  1677. template: `<div>
  1678. <div style="position:absolute; top: 29px; left: 343px;" v-show="showBtn">
  1679. <el-tooltip content="检索已创建的项目,避免重复创建" placement="top" effect="light">
  1680. <el-button type="primary" style="vertical-align: top;" icon="el-icon-search" size="small" id="create-project" @click="check">检索</el-button>
  1681. </el-tooltip>
  1682. </div>
  1683. </div>`
  1684. });
  1685.  
  1686. // 将占位元素追加到 项目名称输入框 后面
  1687. $projectName.parent('.form-group')[0].appendChild(vueInstance.$el);
  1688. }
  1689.  
  1690. if($projectDescription && $projectDescription.length) {
  1691. let date = new Date();
  1692. const imgEl = document.querySelector('.header-user-avatar');
  1693. let name = imgEl ? imgEl.getAttribute('alt') : '张三';
  1694. name = name.replace('(前端研发3部)', '');
  1695. $projectDescription.attr('placeholder', 'YYYY-M-D,张三,UI:https://oa.epoint.com.cn/interaction-design-portal/portal/pages/casestemplates/casetemplatesdetail?guid=');
  1696. $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='));
  1697. $projectDescription.prev('.label-bold').find('span').text(' (UI备份地址完善后会自动获取项目名称、业务条线和项目类型)')
  1698.  
  1699. $projectDescription[0].setAttribute("maxlength", "1000");
  1700. // 增加主题表单
  1701. var themeHtml = '<div class="row">\
  1702. <div class="form-group col-md-9">\
  1703. <label class="label-bold" for="project_topics">主题<i style="color:red; font-style:normal; font-weight: 400; padding-left: 5px;">业务系统类型关键字添加框架版本</i></label>\
  1704. <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="">\
  1705. <p class="form-text text-muted">用逗号分隔主题。</p>\
  1706. <p class="form-text text-muted">业务条线:政务服务、大数据、一网统管、一网协同、智能设备、电子交易、数字建设、公共安全、支撑产品;</p>\
  1707. <p class="form-text text-muted">项目类型:网站、业务系统、智能设备、大屏可视化、中屏可视化、在线表单;</p>\
  1708. <p class="form-text text-muted">关键字:f942f951f950sp2f9x2.0f9x1.0、骨架、vuereact、单页、gojselementAntDesign、全景、关系图、流程图、响应式、svg、视频、miniuiegisegis3d、高德、百度、超图、three、主题、瀑布流、上传、自定义用户控件等;</p>\
  1709. </div></div>';
  1710.  
  1711. $projectDescription.closest('.form-group').after(themeHtml);
  1712.  
  1713. var $theme = jQuery('#project_topics');
  1714.  
  1715. // 规避中文,
  1716. $projectDescription.blur(function(event) {
  1717. this.value = this.value.replace(/,/g, ',').replace(/&isfwqfb=1/g, '');
  1718. // 日期转换
  1719. this.value = convertDateFormat(this.value);
  1720.  
  1721. // 检测主题是否为空,且是否已输入uiUrl
  1722. if ($theme.val().trim() == '') {
  1723. var regex = /guid=([0-9a-fA-F-]{36})/; // 匹配整个URL字符串中的guid后的36位字符
  1724.  
  1725. var match = this.value.match(regex);
  1726.  
  1727. if (match) {
  1728. var extractedGuid = match[1];
  1729. // console.log(extractedGuid);
  1730. // 通过 guid 请求数据
  1731. var apiUrl = 'https://oa.epoint.com.cn/interaction-design-portal/rest/portal/pages/casestemplates/casestemplatesdetailaction/page_load'
  1732. if(this.value.indexOf('dynamiceffecttemplates') > -1) {
  1733. apiUrl = 'https://oa.epoint.com.cn/interaction-design-portal/rest/portal/pages/dynamiceffecttemplates/dynamiceffecttemplatesdetailaction/page_load';
  1734. }
  1735.  
  1736. // 获取项目信息
  1737. GM_xmlhttpRequest({
  1738. method: 'GET',
  1739. url: apiUrl + '?guid='+ extractedGuid +'&isCommondto=true',
  1740. headers: {
  1741. 'Content-Type': 'application/json; charset=utf-8'
  1742. },
  1743. onload: function(res) {
  1744. const data = JSON.parse(res.response);
  1745. let pData = data.custom.casetemplatedata || data.custom.dynamiceffecttemplatesdata;
  1746. let proBu = pData.stripline || pData.line;
  1747. const proType = pData.type;
  1748. const proName = pData.project || pData.title;
  1749. switch(proBu) {
  1750. case '政务BG':
  1751. proBu = '政务服务';
  1752. break;
  1753. case '建设BG':
  1754. proBu = '数字建设';
  1755. break;
  1756. case '交易BG':
  1757. proBu = '电子交易';
  1758. break;
  1759. case '智能设备BU':
  1760. proBu = '智能设备';
  1761. break;
  1762. }
  1763. proName && $projectName.val(proName);
  1764. proBu && proType && $theme.val(proBu + ', ' + proType);
  1765. $projectName.trigger('change');
  1766. }
  1767. });
  1768. }
  1769. }
  1770. });
  1771.  
  1772.  
  1773. if(projectBu) {
  1774. $theme.val(projectBu);
  1775. }
  1776.  
  1777. if(projectType && projectType !== '智能化设备') {
  1778. $theme.val($theme.val() + ', ' + projectType);
  1779. }
  1780.  
  1781. if(frame) {
  1782. $theme.val($theme.val() + ', ' + frame);
  1783. }
  1784.  
  1785. $theme.blur(function(event) {
  1786. this.value = this.value.replaceAll(',', ',');
  1787.  
  1788. });
  1789. }
  1790.  
  1791. if($check && $check.length) {
  1792. $check.trigger('click');
  1793. }
  1794. });
  1795.  
  1796. })();
  1797.  
  1798. // 通过 oa 首页中转,跳过跨站访问的限制
  1799. (function(){
  1800. 'use strict';
  1801. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/epointoa9\/frame\/fui\/pages\/themes\/aide/];
  1802. let match = false;
  1803.  
  1804. for(let r = 0, lr = regs.length; r < lr; r++) {
  1805. if(regs[r].test(location.href)) {
  1806. match = true;
  1807. break;
  1808. }
  1809. }
  1810.  
  1811. if(!match) {
  1812. return;
  1813. }
  1814.  
  1815. let redirectUlr = gitlabUtil.getUrlParameters().redirect;
  1816.  
  1817. if(redirectUlr) {
  1818. window.location.href = redirectUlr;
  1819. }
  1820. })();
  1821.  
  1822. // 设计门户瀑布流页面,查找对应项目
  1823. (function(){
  1824. 'use strict';
  1825. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/interaction-design-portal\/portal\/pages\/casestemplates\/casetemplateslist/];
  1826. let match = false;
  1827.  
  1828. for(let r = 0, lr = regs.length; r < lr; r++) {
  1829. if(regs[r].test(location.href)) {
  1830. match = true;
  1831. break;
  1832. }
  1833. }
  1834.  
  1835. if(!match) {
  1836. return;
  1837. }
  1838.  
  1839. let projectName = location.href.split('projectname');
  1840.  
  1841. window.addEventListener('load', function() {
  1842. if(projectName[1]) {
  1843. projectName = decodeURIComponent(projectName[1]);
  1844.  
  1845. const $input = jQuery('#search-input');
  1846. const $searchBtn = jQuery('.search-icon');
  1847.  
  1848. setTimeout(() => {
  1849. $input.val(projectName);
  1850. $searchBtn.trigger('click');
  1851. }, 1000);
  1852. }
  1853. });
  1854. })();
  1855.  
  1856. // 邮件详情页可以创建项目
  1857. (function() {
  1858. 'use strict';
  1859. let regs = [/^https:\/\/oa\.epoint\.com\.cn\:8080\/OA9\/oa9\/mail\/mailreceivedetail/,
  1860. /^https:\/\/oa\.epoint\.com\.cn\/OA9\/oa9\/mail\/mailreceivedetail/];
  1861. let match = false;
  1862.  
  1863. for(let r = 0, lr = regs.length; r < lr; r++) {
  1864. if(regs[r].test(location.href)) {
  1865. match = true;
  1866. break;
  1867. }
  1868. }
  1869.  
  1870. if(!match) {
  1871. return;
  1872. }
  1873.  
  1874. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  1875.  
  1876. // 添加样式规则,将字体应用到指定元素上
  1877. GM_addStyle(`
  1878. @font-face {
  1879. font-family: element-icons;
  1880. src: url(${fontUrl}) format("woff");
  1881. }
  1882. `);
  1883.  
  1884. GM_addStyle(GM_getResourceText('ElementCSS'));
  1885.  
  1886. // 在邮件签收情况后添加按钮-新建项目
  1887. function initCreate() {
  1888. const title = document.querySelector('#mail-detail-container .dtt');
  1889. let vueInstance;
  1890. let gitUrl = 'http://192.168.0.200/projects/new?namespace_id=4817';
  1891.  
  1892. if(title) {
  1893. const btnPlaceholder = document.createElement('div');
  1894. let tds = jQuery('#mailcontent table').find("td[colspan='3']");
  1895. tds = tds.length ? tds : jQuery('#mailcontent table').find("td:nth-child(2)");
  1896. const projectName = tds.eq(0).text().trim().replace('(临时)', '').replace('(临时)', '');
  1897. const firstTdtext = jQuery('#mailcontent table').find("th,td").eq(0).text().trim();
  1898. const isFrontEndEmail = jQuery('#mailcontent table').length && firstTdtext && (firstTdtext == '项目名称' || firstTdtext == '产品名称');
  1899. let bu = '政务服务';
  1900. let projectType = '';
  1901. let frame = '';
  1902. const demandUrl = tds.eq(1).text();
  1903. let uiUrl = '';
  1904.  
  1905. // 由于表格格式不固定,重新遍历一遍获取 uiUrl 和 frame
  1906. tds.each(function(i, el) {
  1907. if(jQuery(el).prev().text().trim() == '备份地址') {
  1908. uiUrl = jQuery(el).text().trim();
  1909. }
  1910. if(jQuery(el).prev().text().trim() == '框架版本') {
  1911. frame = jQuery(el).text().trim();
  1912. }
  1913. if(jQuery(el).prev().text().trim() == '设计类型') {
  1914. projectType = jQuery(el).text().trim();
  1915. }
  1916. });
  1917.  
  1918. uiUrl = uiUrl ? removeQueryStringParameter(uiUrl, 'isfwqfb') : '';
  1919. const backGuid = extractGuidFromUrl(uiUrl);
  1920.  
  1921. if(!isFrontEndEmail) {
  1922. return;
  1923. }
  1924.  
  1925. // 请求项目信息地址
  1926. let apiUrl = '';
  1927.  
  1928. apiUrl = uiUrl.split('?')[0];
  1929. apiUrl = apiUrl.split('interaction-design-portal')[0] + 'interaction-design-portal/rest' + apiUrl.split('interaction-design-portal')[1] + 'action/page_load';
  1930.  
  1931. if(apiUrl.indexOf('casetemplatesdetailaction') > -1) {
  1932. apiUrl = apiUrl.replace('casetemplatesdetailaction', 'casestemplatesdetailaction');
  1933. }
  1934.  
  1935. // 创建 Vue 实例并挂载到页面
  1936. vueInstance = new Vue({
  1937. el: btnPlaceholder,
  1938. data: function() {
  1939. return {
  1940. proBu: bu,
  1941. proType: projectType
  1942. };
  1943. },
  1944. methods: {
  1945. create: function() {
  1946. window.open(gitUrl + '&projectName=' + projectName + '&bu=' + this.proBu + '&projectType=' + this.proType + '&frame=' + frame + '&uiUrl=' + uiUrl + '#blank_project');
  1947. },
  1948. search: function() {
  1949. window.open('http://192.168.0.200/?name=' + projectName);
  1950. }
  1951. },
  1952. mounted: function() {
  1953. let self = this;
  1954. // 获取项目信息
  1955. GM_xmlhttpRequest({
  1956. method: 'GET',
  1957. url: apiUrl + '?guid='+ backGuid +'&isfwqfb=1&isCommondto=true',
  1958. headers: {
  1959. 'Content-Type': 'application/json; charset=utf-8'
  1960. },
  1961. onload: function(res) {
  1962. const data = JSON.parse(res.response);
  1963. let pData = data.custom.casetemplatedata || data.custom.dynamiceffecttemplatesdata;
  1964. self.proBu = pData.stripline || pData.line;
  1965. self.proType = pData.type;
  1966. switch(self.proBu) {
  1967. case '政务BG':
  1968. self.proBu = '政务服务';
  1969. break;
  1970. case '建设BG':
  1971. self.proBu = '数字建设';
  1972. break;
  1973. case '交易BG':
  1974. self.proBu = '电子交易';
  1975. break;
  1976. case '智能设备BU':
  1977. self.proBu = '智能设备';
  1978. break;
  1979. }
  1980. }
  1981. });
  1982. },
  1983. template: `<div style="display:inline-block; margin-left: 5px; vertical-align: top;">
  1984. <el-tooltip content="去 GitLab 创建项目" placement="top" effect="light">
  1985. <el-button type="primary" style="vertical-align: top;" icon="el-icon-folder-add" circle size="mini" id="create-project" @click="create"></el-button>
  1986. </el-tooltip>
  1987. <el-tooltip content="去 GitLab 查找项目" placement="top" effect="light">
  1988. <el-button type="primary" style="vertical-align: top;" icon="el-icon-search" circle size="mini" @click="search"></el-button>
  1989. </el-tooltip>
  1990. </div>`
  1991. });
  1992.  
  1993. // 将占位元素追加到 邮件标题后 元素中
  1994. // f9 框架会冲突
  1995. title.appendChild(vueInstance.$el);
  1996. // jQuery(title).append(vueInstance.$el.outerHTML);
  1997.  
  1998. /*
  1999. jQuery('#create-project').on('click', function() {
  2000. window.open(gitUrl);
  2001. });*/
  2002. }
  2003. }
  2004.  
  2005. function extractGuidFromUrl(url) {
  2006. const regex = /[?&]guid=([^&]+)/;
  2007. const match = url.match(regex);
  2008.  
  2009. if (match) {
  2010. return match[1]; // 第一个捕获组中的值即为 guid
  2011. } else {
  2012. return null; // 如果没有匹配到 guid,则返回 null
  2013. }
  2014. }
  2015.  
  2016. function removeQueryStringParameter(url, parameterName) {
  2017. const urlParts = url.split('?');
  2018.  
  2019. if (urlParts.length === 2) {
  2020. const baseUrl = urlParts[0];
  2021. const queryString = urlParts[1];
  2022.  
  2023. const parameters = queryString.split('&').filter(param => {
  2024. const paramName = param.split('=')[0];
  2025. return paramName !== parameterName;
  2026. });
  2027.  
  2028. if (parameters.length > 0) {
  2029. return baseUrl + '?' + parameters.join('&');
  2030. } else {
  2031. return baseUrl;
  2032. }
  2033. }
  2034.  
  2035. return url;
  2036. }
  2037.  
  2038. window.addEventListener('load', function() {
  2039. setTimeout(function() {
  2040. initCreate();
  2041. }, 500);
  2042. });
  2043.  
  2044. })();
  2045.  
  2046. // 需求详情页,增加设为待办功能
  2047. (function() {
  2048. 'use strict';
  2049. let regs = [/^https:\/\/oa\.epoint\.com\.cn\/productrelease\/cpzt\/demandmanageznsb\/demandbasicinfo_detail/];
  2050. let match = false;
  2051.  
  2052. for(let r = 0, lr = regs.length; r < lr; r++) {
  2053. if(regs[r].test(location.href)) {
  2054. match = true;
  2055. break;
  2056. }
  2057. }
  2058.  
  2059. if(!match) {
  2060. return;
  2061. }
  2062.  
  2063. window.addEventListener('load', function() {
  2064. const $toolbar = jQuery('.fui-toolbar');
  2065.  
  2066. $toolbar.find('.btn-group').eq(0).after('<div class="fe-add"><span class="mini-button mini-btn-danger" state="danger" id="mark">在飞书中标记待办</span></div>');
  2067.  
  2068. mini.parse($toolbar);
  2069.  
  2070. const markbtn = mini.get('mark');
  2071. const guid = gitlabUtil.getUrlParameters().ProcessVersionInstanceGuid;
  2072.  
  2073. markbtn.on('click', function(e) {
  2074. window.open('https://k7n084n7rx.feishu.cn/base/bascnxklVJQ9VqGGkc4bmu3YJPb?table=tblJhJ9dr4N3AKDr&view=vewNNJTfJp&demandGuid=' + guid );
  2075. });
  2076. });
  2077.  
  2078. })();
  2079.  
  2080. // 更新脚本同步版本信息
  2081. (function() {
  2082. 'use strict';
  2083. let regs = [/^https:\/\/greasyfork\.org\/zh-CN\/scripts\/466808\/versions\/new/];
  2084. let match = false;
  2085.  
  2086. for(let r = 0, lr = regs.length; r < lr; r++) {
  2087. if(regs[r].test(location.href)) {
  2088. match = true;
  2089. break;
  2090. }
  2091. }
  2092.  
  2093. if(!match) {
  2094. return;
  2095. }
  2096.  
  2097. const p = document.getElementById('script-description');
  2098. const href = 'http://192.168.0.200/-/ide/project/fe3group/gitlabassistant-web/edit/main/-/version.json';
  2099.  
  2100. const linkElement = document.createElement("a");
  2101.  
  2102. linkElement.href = href; // 设置超链接的URL
  2103. linkElement.textContent = "去同步脚本版本"; // 设置超链接的文本内容
  2104. linkElement.target = '_blank';
  2105.  
  2106. // 将超链接元素插入到目标元素的后面
  2107. p.parentNode.insertBefore(linkElement, p.nextSibling);
  2108. })();