服务商中心_团队管理

云图扩展工具

  1. // ==UserScript==
  2. // @name 服务商中心_团队管理
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 云图扩展工具
  6. // @author siji-Xian
  7. // @match *://yuntu.oceanengine.com/service_provider/team/all_brand_members
  8. // @icon https://lf3-static.bytednsdoc.com/obj/eden-cn/prhaeh7pxvhn/yuntu/yuntu-logo_default.svg
  9. // @grant none
  10. // @license MIT
  11. // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
  12. // @require https://cdn.bootcss.com/moment.js/2.20.1/moment.min.js
  13. // @require https://greasyfork.org/scripts/404478-jsonexportexcel-min/code/JsonExportExcelmin.js?version=811266
  14. // @require https://greasyfork.org/scripts/455576-qmsg/code/Qmsg.js?version=1122361
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. "use strict";
  19. var new_element = document.createElement("link");
  20. new_element.setAttribute("rel", "stylesheet");
  21. new_element.setAttribute("href", "https://qmsg.refrain.xyz/message.min.css");
  22. document.body.appendChild(new_element);
  23.  
  24. const button = document.createElement("div");
  25. button.textContent = "导出数据";
  26. Object.assign(button.style, {
  27. height: "34px",
  28. lineHeight: "var(--line-height, 34px)",
  29. alignItems: "center",
  30. color: "white",
  31. background: "linear-gradient(90deg, rgba(0, 239, 253), rgba(64, 166, 254))",
  32. borderRadius: "5px",
  33. marginLeft: "10px",
  34. fontSize: "13px",
  35. padding: "0 10px",
  36. cursor: "pointer",
  37. fontWeight: "500",
  38. });
  39. button.addEventListener("click", urlClick);
  40.  
  41. //获取brand信息
  42. let brand = localStorage.getItem("__Garfish__platform__yuntu_user") || "";
  43. let brands = JSON.parse(brand);
  44.  
  45. //获取service_provider_id
  46. let service_provider_id = null;
  47.  
  48. (function listen() {
  49. var origin = {
  50. open: XMLHttpRequest.prototype.open,
  51. send: XMLHttpRequest.prototype.send,
  52. };
  53. XMLHttpRequest.prototype.open = function (a, b) {
  54. this.addEventListener("load", replaceFn);
  55. origin.open.apply(this, arguments);
  56. };
  57. XMLHttpRequest.prototype.send = function (a, b) {
  58. origin.send.apply(this, arguments);
  59. };
  60. function replaceFn(obj) {
  61. if (
  62. this?._url?.slice(0, 59) ==
  63. "/service_provider/api/v1/team/query_service_provider_member"
  64. ) {
  65. service_provider_id = JSON.parse(
  66. obj?.target?.response
  67. ).data_list[0].service_provider_id;
  68. }
  69. }
  70. })();
  71.  
  72. //默认GET请求
  73. const getRequestOptions = {
  74. method: "GET",
  75. redirect: "follow",
  76. };
  77.  
  78. //message.js
  79. let loadingMsg = null;
  80.  
  81. function appendDoc() {
  82. const likeComment = document.querySelector(".left_YEVa");
  83. if (likeComment) {
  84. likeComment.append(button);
  85. return;
  86. }
  87. setTimeout(appendDoc, 1000);
  88. }
  89. appendDoc();
  90.  
  91. async function fetchFun(url, data, requestOptions = getRequestOptions) {
  92. const params = new URLSearchParams(data).toString();
  93. try {
  94. const response = await fetch(`${url}?${params}`, requestOptions);
  95. if (response.ok) {
  96. const result = await response.json();
  97. return result;
  98. } else {
  99. throw new Error(`Fetch failed: ${response.status}`);
  100. }
  101. } catch (error) {
  102. loadingMsg.close();
  103. Qmsg.error({
  104. content: `网络请求错误: ${error.message}`,
  105. timeout: 5000,
  106. });
  107. throw error;
  108. }
  109. }
  110.  
  111. async function brandsRequest(e) {
  112. let bodyData = {
  113. service_provider_id: service_provider_id,
  114. page: e,
  115. fuzzy_word: ""
  116. };
  117. let result = await fetchFun(
  118. "https://yuntu.oceanengine.com/service_provider/api/v1/team/query_service_provider_member",
  119. bodyData
  120. );
  121. return result.data_list
  122. }
  123.  
  124. function getRecordCount(text) {
  125. const recordCount = text.match(/\d+/)[0];
  126. const count = parseInt(recordCount)
  127. const pages = Math.ceil(count/10)
  128. return pages;
  129. }
  130.  
  131. function createNumberList(end) {
  132. const result = [];
  133. for (let i = 1; i <= end; i++) {
  134. result.push(i);
  135. }
  136. return result;
  137. }
  138.  
  139. async function task_list() {
  140. loadingMsg = Qmsg.loading("正在导出,请勿重复点击!");
  141. let countText = document.querySelector('.team-pager-record').innerHTML
  142. let count = 0
  143. if (countText) {
  144. count = getRecordCount(countText);
  145. } else {
  146. count = 0;
  147. }
  148. let pages = createNumberList(count)
  149.  
  150. let res = await Promise.all(pages.map(async v=>{
  151. let result = await brandsRequest(v);
  152. return result;
  153. }))
  154.  
  155. let flatResult = res.flat()
  156.  
  157. expExcel(flatResult)
  158. }
  159.  
  160. function expExcel(e) {
  161. let res = e.map(v=>{
  162. return {...v, brinds:v.auth_brand_list.map(v=>v.brand_name)}
  163. })
  164. let contrast = {
  165. 成员姓名: "user_name",
  166. 邮箱: "email",
  167. 手机号: "phone",
  168. 服务品牌: "brinds"
  169. };
  170.  
  171. let datas = {
  172. sheetName: '',
  173. sheetData: res,
  174. sheetHeader: Object.keys(contrast),
  175. sheetFilter: Object.values(contrast),
  176. columnWidths: [], // 列宽
  177. };
  178.  
  179. let option = {};
  180. option.fileName = "团队管理-所有成员"; //文件名
  181. option.datas = [datas];
  182. var toExcel = new ExportJsonExcel(option);
  183. toExcel.saveExcel();
  184. loadingMsg.close();
  185. }
  186.  
  187. function urlClick() {
  188. task_list();
  189. }
  190. })();