JD VMS Integration

Auto fill vms form fields

  1. // ==UserScript==
  2. // @name JD VMS Integration
  3. // @namespace com.jd.vms
  4. // @version 1.0.4
  5. // @description Auto fill vms form fields
  6. // @author tinymins
  7. // @match http://vms.jd.com/Integration/Apply
  8. // @icon http://vms.jd.com/assets/img/favicon.ico
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const getConfig = () => {
  13. let config = {};
  14. try {
  15. config = JSON.parse(window.localStorage['com.derzh.jd.vms.integration.apply.preset']);
  16. } catch (error) {}
  17. if (typeof config !== 'object') {
  18. config = {};
  19. }
  20. return Object.assign({
  21. apply_type: '4',
  22. version_server: '0',
  23. test_content: '无',
  24. module_id: '73',
  25. self_test: '0',
  26. modification_explanation: '无',
  27. affect_range: '无',
  28. interface_name: '无',
  29. test_data: '无',
  30. test_address: 'http://beta-ace.jd.com/launch/',
  31. code_branch: 'prod',
  32. review_result: '1',
  33. request_memo: '无',
  34. code_review_operator: '',
  35. product_operator: '',
  36. test_operator: '',
  37. }, config);
  38. };
  39.  
  40. $('#cancel-apply-request').after('<button type="button" class="btn btn-default pull-right">存为预设</button>').next().click(() => {
  41. window.localStorage['com.derzh.jd.vms.integration.apply.preset'] = JSON.stringify({
  42. apply_type: $('#apply_type').val(),
  43. version_server: $('#version_server').val(),
  44. test_content: $('#test_content').val(),
  45. module_id: $('#module_id').val(),
  46. self_test: $('#self_test').val(),
  47. modification_explanation: $('#modification_explanation').val(),
  48. affect_range: $('#affect_range').val(),
  49. interface_name: $('#interface_name').val(),
  50. test_data: $('#test_data').val(),
  51. test_address: $('#test_address').val(),
  52. code_branch: $('#code_branch').val(),
  53. review_result: $('#review_result').val(),
  54. request_memo: $('#request-memo').val(),
  55. code_review_operator: $('#code-review-operator').val(),
  56. product_operator: $('#product-operator').val(),
  57. test_operator: $('#test-operator').val(),
  58. });
  59. });
  60.  
  61. $('#jacp_card_id').after('<button style="margin: 5px; height: 30px; transform: translateY(2px);">行云</button>').next().click(() => {
  62. if ($('#jacp_card_id').val() === '-1') {
  63. return alert('请先选择卡片');
  64. }
  65. window.open(`http://jagile.jd.com/teamspace/cardlist/tf_project/carddetail?cardId=${$('#jacp_card_id').val()}`);
  66. });
  67.  
  68. $('#jacp_card_id').after('<button style="margin: 5px; height: 30px; transform: translateY(2px);">FILL</button>').next().click(() => {
  69. if ($('#jacp_card_id').val() === '-1') {
  70. return alert('请先选择卡片');
  71. }
  72. const config = getConfig();
  73. $('#apply_type').val(config.apply_type).change();
  74. const dateNextMonth = new Date();
  75. dateNextMonth.setTime(dateNextMonth.getTime() + 86400e3 * 30);
  76. $('#expect_online_date').val(
  77. [dateNextMonth.getFullYear(), dateNextMonth.getMonth() + 1, dateNextMonth.getDate()]
  78. .map(a => (a < 10 ? `0${a}` : a))
  79. .join('-'),
  80. );
  81. $('#version_server').val(config.version_server);
  82. $('#test_content').val(config.test_content);
  83. $('#module_id').val(config.module_id).change();
  84. $('#self_test').val(config.self_test);
  85. $('#modification_explanation').val(config.modification_explanation);
  86. $('#affect_range').val(config.affect_range);
  87. $('[name="degrade_switch_apply"][value="0"]+ins').click();
  88. $('[name="pressure_test"][value="0"]+ins').click();
  89. $('#interface_name').val(config.interface_name);
  90. $('#test_data').val(config.test_data);
  91. $('#test_address').val(config.test_address);
  92. $('#code_branch').val(config.code_branch);
  93. $('#review_result').val(config.review_result).change();
  94. $('#request-memo').val(config.request_memo);
  95. const fetch = (url) => {
  96. const xml = new XMLHttpRequest();
  97. xml.open('GET', url, false);
  98. xml.withCredentials = true;
  99. xml.send();
  100. return xml.responseText;
  101. };
  102. const fill_erp_tags = async (elid, erps) => {
  103. const data = await Promise.all(
  104. erps
  105. .split(',')
  106. .map(s => s.trim())
  107. .filter(_ => _)
  108. .map(
  109. erp => $.ajax(`http://vms.jd.com/user/get_user_base_info?keyword=${erp}`)
  110. .then(res => res.info.data.find(({ user_name }) => user_name === erp)),
  111. )
  112. .filter(_ => _),
  113. );
  114. const jqEl = $(`#${elid}`);
  115. jqEl.tagsinput('removeAll');
  116. data.filter(_ => _).forEach(v => jqEl.tagsinput('add', v));
  117. };
  118. const card = JSON.parse(fetch(`http://jagile.jd.com/jacp/api/v1/bizSpaceCard/cardDetail?id=${jacp_card_dom.val()}`));
  119. const roles = JSON.parse(fetch(`http://jagile.jd.com/jacp/api/v1/bizConfig/space/kv/${card.data.spaceId}`))
  120. .data.reduce((a, b) => {
  121. if (String(b.name + b.group).match(/测试/u)) {
  122. a[b.code] = 1;
  123. }
  124. return a;
  125. }, {});
  126. fill_erp_tags('code-review-operator', config.code_review_operator);
  127. fill_erp_tags('product-operator', card.data.creator.erp || config.product_operator);
  128. fill_erp_tags('test-operator', card.data.personHours.find(a => roles[a.roleCode])?.erp || config.test_operator);
  129. });