app_list.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 name = GetQueryString('name') ?? null;
  13. let app_uid = GetQueryString('app_uid') ?? null;
  14. $('.name').val(name);
  15. $('.app_uid').val(app_uid);
  16. let cols = [
  17. [
  18. {
  19. title: 'UID',
  20. field: 'uid',
  21. align: 'center',
  22. },
  23. {
  24. title: 'ICON',
  25. field: 'icon_url',
  26. align: 'center',
  27. toolbar: '#app-icon'
  28. },
  29. {
  30. title: '应用名称',
  31. field: 'name',
  32. align: 'center',
  33. },
  34. {
  35. title: '隐藏状态',
  36. field: 'status',
  37. align: 'center',
  38. toolbar: '#app-status'
  39. },
  40. {
  41. title: '排序',
  42. field: 'squad',
  43. align: 'center'
  44. },
  45. {
  46. title: '版本(A|I)',
  47. align: 'center',
  48. toolbar: '#app-version-android-ios'
  49. },
  50. {
  51. title: '打包开关(A|I)',
  52. align: 'center',
  53. toolbar: '#app-enable-android-ios'
  54. },
  55. {
  56. title: '地址(安卓|苹果)',
  57. align: 'center',
  58. toolbar: '#app-dow-url-android-ios'
  59. },
  60. {
  61. title: '更新时间',
  62. field: 'updated_at',
  63. align: 'center'
  64. },
  65. {
  66. title: '操作',
  67. align: 'center',
  68. fixed: 'right',
  69. toolbar: '#app-bar'
  70. }
  71. ]
  72. ];
  73. let search = httpRequestPostData({
  74. name: name,
  75. uid: app_uid,
  76. });
  77. table.render({
  78. elem: '#app-table',
  79. method: 'POST',
  80. request: {
  81. pageName: 'page',
  82. limitName: 'page_size'
  83. },
  84. async: false,
  85. headers: {
  86. "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? ''
  87. },
  88. contentType: 'application/json',
  89. where: search,
  90. url: getMyApiUrl('/app/lists'),
  91. limit: 20,
  92. limits: [20, 30, 40, 50, 80, 100],
  93. parseData: function (res) {
  94. return httpRequestPagesParseData(res);
  95. },
  96. response: {
  97. "statusCode": 200,
  98. },
  99. done: function (data, page, total) {
  100. var intCode = parseInt(data.code);
  101. if (intCode === 403) {
  102. cbRespnseRedirectLogin(data);
  103. } else if (intCode === 401) {
  104. // 仅仅是过期了,这里可以有其他逻辑补偿.
  105. // 暂时跳到登陆页面
  106. cbRespnse401(data);
  107. }
  108. onloadRender();
  109. },
  110. error: function (obj, message) {
  111. cbRespnseReloadPage(obj, message);
  112. },
  113. page: true,
  114. cols: cols,
  115. skin: 'line',
  116. toolbar: '#app-toolbar',
  117. defaultToolbar: [{
  118. title: '刷新',
  119. layEvent: 'refresh',
  120. icon: 'layui-icon-refresh',
  121. }, 'filter', 'print', 'exports']
  122. });
  123. table.on('toolbar(app-table)', function (obj) {
  124. if (obj.event === 'add') {
  125. window.add();
  126. } else if (obj.event === 'refresh') {
  127. window.refresh();
  128. }
  129. });
  130. window.add = function () {
  131. layer.open({
  132. id: 'app_create',
  133. type: 2,
  134. title: '添加',
  135. shade: 0.1,
  136. offset: '20px',
  137. area: ['410px', '600px'],
  138. maxWidth: 500,
  139. maxHeight: 600,
  140. scrollbar: true,
  141. content: 'app_create.html',
  142. });
  143. }
  144. // 表单内
  145. table.on('tool(app-table)', function (obj) {
  146. if (obj.event === 'remove') {
  147. window.remove(obj);
  148. } else if (obj.event === 'edit') {
  149. window.edit(obj);
  150. }
  151. });
  152. window.edit = function (obj) {
  153. layer.open({
  154. id: 'app-edit',
  155. type: 2,
  156. title: '修改',
  157. shade: 0.1,
  158. offset: '20px',
  159. area: ['410px', '600px'],
  160. maxWidth: 500,
  161. maxHeight: 600,
  162. scrollbar: true,
  163. content: 'app_edit.html?app_uid=' + obj.data.uid,
  164. });
  165. }
  166. // 状态修改
  167. form.on('switch(app-status-edit)', function (obj) {
  168. let status = layer.load();
  169. let postData = {
  170. uid: this.value
  171. };
  172. let ret = mhttp.ajax({
  173. url: '/app/edit/status',
  174. data: postData,
  175. });
  176. ret.then((data) => {
  177. layer.close(status);
  178. if (data.code === 200) {
  179. layer.msg(data.message, {icon: 1, time: 1000});
  180. } else {
  181. layer.msg(data.message, {icon: 2, time: 1000});
  182. }
  183. });
  184. });
  185. form.on('switch(android-enable-edit)', function (obj) {
  186. let android = layer.load();
  187. let postData = {
  188. uid: this.value
  189. };
  190. let ret = mhttp.ajax({
  191. url: '/app/edit/android/enable',
  192. data: postData,
  193. });
  194. ret.then((data) => {
  195. layer.close(android);
  196. if (data.code === 200) {
  197. layer.msg(data.message, {icon: 1, time: 1000});
  198. } else {
  199. layer.msg(data.message, {icon: 2, time: 1000});
  200. }
  201. });
  202. });
  203. form.on('switch(ios-enable-edit)', function (obj) {
  204. let ios = layer.load();
  205. let postData = {
  206. uid: this.value
  207. };
  208. let ret = mhttp.ajax({
  209. url: '/app/edit/ios/enable',
  210. data: postData,
  211. });
  212. ret.then((data) => {
  213. layer.close(ios);
  214. if (data.code === 200) {
  215. layer.msg(data.message, {icon: 1, time: 1000});
  216. } else {
  217. layer.msg(data.message, {icon: 2, time: 1000});
  218. }
  219. });
  220. });
  221. window.refresh = function (param) {
  222. table.reload('app-table');
  223. }
  224. })