channel_list.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () {
  2. let table = layui.table;
  3. let $ = layui.jquery;
  4. let admin = layui.madmin;
  5. let layer = layui.layer;
  6. let form = layui.form;
  7. let common = layui.common;
  8. let mhttp = layui.mhttp;
  9. admin.getConfig();
  10. getStorageServersConfig();
  11. //搜索条件
  12. let uid = GetQueryString('uid') ?? null;
  13. let agent_uid = GetQueryString('agent_uid') ?? null;
  14. let mom_app_uid = GetQueryString('mom_app_uid') ?? null;
  15. let agent_username = GetQueryString('agent_username') ?? null;
  16. $('.uid').val(uid);
  17. $('.agent_uid').val(agent_uid);
  18. $('.mom_app_uid').val(mom_app_uid);
  19. $('.agent_username').val(agent_username);
  20. let appArray = {};
  21. let appArrayInfo = {};
  22. // 获取app
  23. let ret = mhttp.ajax({
  24. url: '/app/all'
  25. });
  26. ret.then((data) => {
  27. if (data.code === 200) {
  28. let html = '<option value=""></option>';
  29. for (var i in data.data) {
  30. appArray[data.data[i].uid] = data.data[i].name;
  31. appArrayInfo[data.data[i].uid] = data.data[i];
  32. html += '<option class="se_' + data.data[i].uid + '" value="' + data.data[i].uid + '">' + data.data[i].name + '</option>';
  33. }
  34. $('.mom_app_uid').append(html);
  35. $('.mom_app_uid .se_' + mom_app_uid).attr('selected', 'selected');
  36. form.render();
  37. let cols = [
  38. [
  39. {
  40. title: 'UID',
  41. field: 'uid',
  42. align: 'center',
  43. },
  44. {
  45. title: '渠道名字',
  46. field: 'name',
  47. align: 'center'
  48. },
  49. {
  50. title: '代理UID',
  51. field: 'agent_uid',
  52. align: 'center',
  53. },
  54. {
  55. title: '代理名称',
  56. field: 'nick',
  57. align: 'center',
  58. templet: function (d) {
  59. if (!d.agent_name) {
  60. return '未知';
  61. }
  62. return d.agent_name.nick;
  63. }
  64. },
  65. {
  66. title: '渠道链接',
  67. field: 'share_url',
  68. align: 'center',
  69. templet: function (d) {
  70. if (d.share_url) {
  71. return '<button class="pear-btn pear-btn-sm" lay-event="cp_link">推广链接</button>';
  72. } else {
  73. return '';
  74. }
  75. }
  76. },
  77. {
  78. title: '应用名称',
  79. field: 'mom_app_uid',
  80. align: 'center',
  81. templet: function (d) {
  82. return appArray[d.mom_app_uid];
  83. }
  84. },
  85. {
  86. title: '更新时间',
  87. field: 'updated_at',
  88. align: 'center'
  89. },
  90. {
  91. title: '操作',
  92. field: 'updated_at',
  93. align: 'center',
  94. width: '200',
  95. templet(d) {
  96. if (d.channel_row) {
  97. // 判断版本号是否相同
  98. if (appArrayInfo[d.mom_app_uid].android_version === d.channel_row.mom_app_version) {
  99. if (d.channel_row.status === 1) {
  100. return '<div class="pack_btn-box_uid_' + d.uid + '"><button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="pack">重新打包</button><button class="pear-btn pear-btn-sm" lay-event="cp">查看地址</button></div>';
  101. } else if ((d.channel_row.status === 2)) {
  102. return '<div class="pack_btn-box_uid_' + d.uid + '"><button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="pack">重新打包(失败)</button></div>';
  103. } else if ((d.channel_row.status === 3)) {
  104. return '<div class="pack_btn-box_uid_' + d.uid + '"><button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="pack">重新打包(打包中)</button></div>';
  105. }
  106. } else {
  107. return '<div class="pack_btn-box_uid_' + d.uid + '"><button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="pack">重新打包(版本过低)</button></div>';
  108. }
  109. } else {
  110. return '<div class="pack_btn-box_uid_' + d.uid + '"><button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="pack">渠道打包</button></div>';
  111. }
  112. }
  113. },
  114. ]
  115. ];
  116. let search = httpRequestPostData({
  117. uid: uid,
  118. agent_uid: agent_uid,
  119. mom_app_uid: mom_app_uid,
  120. agent_username: agent_username
  121. });
  122. table.render({
  123. elem: '#channel-table',
  124. method: 'POST',
  125. request: {
  126. pageName: 'page',
  127. limitName: 'page_size'
  128. },
  129. async: false,
  130. headers: {
  131. "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? ''
  132. },
  133. contentType: 'application/json',
  134. where: search,
  135. url: getMyApiUrl('/agent/channel/list'),
  136. limit: 20,
  137. limits: [20, 30, 40, 50, 80, 100],
  138. parseData: function (res) {
  139. return httpRequestPagesParseData(res);
  140. },
  141. response: {
  142. "statusCode": 200,
  143. },
  144. done: function (data, page, total) {
  145. var intCode = parseInt(data.code);
  146. if (intCode === 403) {
  147. cbRespnseRedirectLogin(data);
  148. } else if (intCode === 401) {
  149. // 仅仅是过期了,这里可以有其他逻辑补偿.
  150. // 暂时跳到登陆页面
  151. cbRespnse401(data);
  152. }
  153. onloadRender();
  154. },
  155. error: function (obj, message) {
  156. cbRespnseReloadPage(obj, message);
  157. },
  158. page: true,
  159. cols: cols,
  160. skin: 'line',
  161. defaultToolbar: [{
  162. title: '刷新',
  163. layEvent: 'refresh',
  164. icon: 'layui-icon-refresh',
  165. }, 'filter', 'print', 'exports']
  166. });
  167. } else {
  168. layer.msg(data.message, {icon: 2, time: 1000});
  169. }
  170. });
  171. form.render();
  172. // 表单内
  173. table.on('tool(channel-table)', function (obj) {
  174. if (obj.event === 'pack') {
  175. let createLoading = layer.load();
  176. // 打包
  177. let ret = mhttp.ajax({
  178. url: '/agent/channel/pack',
  179. data: {uid: obj.data.uid}
  180. });
  181. ret.then((data) => {
  182. layer.close(createLoading);
  183. if (data.code === 200) {
  184. layer.msg(data.message, {icon: 1, time: 1000}, function () {
  185. // 成功刷父页面
  186. // window.parent.location.reload();
  187. // 成功关闭父窗口
  188. // let index = parent.layer.getFrameIndex(window.name);
  189. // parent.layer.close(index);
  190. // parent.layui.table.reload("channel-table");
  191. // table.reload('channel-table');
  192. let p_uid = obj.data.uid;
  193. let pack_bth = $('.pack_btn-box_uid_' + p_uid);
  194. pack_bth.html('<div class="pack_btn-box_uid_' + p_uid + '"><button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="pack">重新打包(打包中)</button></div>');
  195. });
  196. } else {
  197. layer.msg(data.message, {icon: 2, time: 1000});
  198. }
  199. });
  200. return false;
  201. } else if (obj.event === 'cp') {
  202. // 复制
  203. layer.open({
  204. id: 'qrcode',
  205. type: 2,
  206. title: '获取链接',
  207. shade: 0.1,
  208. offset: '200px',
  209. area: ['400px', '200px'],
  210. maxWidth: 500,
  211. maxHeight: 500,
  212. scrollbar: true,
  213. content: 'copy_link.html?|||' + obj.data.channel_row.app_download,
  214. });
  215. } else if (obj.event === 'cp_link') {
  216. console.debug(obj.data)
  217. // 复制
  218. layer.open({
  219. id: 'qrcode',
  220. type: 2,
  221. title: '获取链接',
  222. shade: 0.1,
  223. offset: '200px',
  224. area: ['400px', '200px'],
  225. maxWidth: 500,
  226. maxHeight: 500,
  227. scrollbar: true,
  228. content: 'copy_link.html?|||' + obj.data.share_url,
  229. });
  230. }
  231. });
  232. $('#reset').click(function () {
  233. window.location.href = './channel_list.html';
  234. });
  235. window.refresh = function (param) {
  236. table.reload('channel-table');
  237. }
  238. })