layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () { let table = layui.table; let $ = layui.jquery; let admin = layui.madmin; let layer = layui.layer; let form = layui.form; let common = layui.common; let mhttp = layui.mhttp; admin.getConfig(); getStorageServersConfig(); //搜索条件 let name = GetQueryString('name') ?? null; let app_uid = GetQueryString('app_uid') ?? null; $('.name').val(name); $('.app_uid').val(app_uid); let cols = [ [ { title: 'UID', field: 'uid', align: 'center', }, { title: 'ICON', field: 'icon_url', align: 'center', toolbar: '#app-icon' }, { title: '应用名称', field: 'name', align: 'center', }, { title: '隐藏状态', field: 'status', align: 'center', toolbar: '#app-status' }, { title: '排序', field: 'squad', align: 'center' }, { title: '版本(A|I)', align: 'center', toolbar: '#app-version-android-ios' }, { title: '打包开关(A|I)', align: 'center', toolbar: '#app-enable-android-ios' }, { title: '地址(安卓|苹果)', align: 'center', toolbar: '#app-dow-url-android-ios' }, { title: '更新时间', field: 'updated_at', align: 'center' }, { title: '操作', align: 'center', fixed: 'right', toolbar: '#app-bar' } ] ]; let search = httpRequestPostData({ name: name, uid: app_uid, }); table.render({ elem: '#app-table', method: 'POST', request: { pageName: 'page', limitName: 'page_size' }, async: false, headers: { "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? '' }, contentType: 'application/json', where: search, url: getMyApiUrl('/app/lists'), limit: 20, limits: [20, 30, 40, 50, 80, 100], parseData: function (res) { return httpRequestPagesParseData(res); }, response: { "statusCode": 200, }, done: function (data, page, total) { var intCode = parseInt(data.code); if (intCode === 403) { cbRespnseRedirectLogin(data); } else if (intCode === 401) { // 仅仅是过期了,这里可以有其他逻辑补偿. // 暂时跳到登陆页面 cbRespnse401(data); } onloadRender(); }, error: function (obj, message) { cbRespnseReloadPage(obj, message); }, page: true, cols: cols, skin: 'line', toolbar: '#app-toolbar', defaultToolbar: [{ title: '刷新', layEvent: 'refresh', icon: 'layui-icon-refresh', }, 'filter', 'print', 'exports'] }); table.on('toolbar(app-table)', function (obj) { if (obj.event === 'add') { window.add(); } else if (obj.event === 'refresh') { window.refresh(); } }); window.add = function () { layer.open({ id: 'app_create', type: 2, title: '添加', shade: 0.1, offset: '20px', area: ['410px', '600px'], maxWidth: 500, maxHeight: 600, scrollbar: true, content: 'app_create.html', }); } // 表单内 table.on('tool(app-table)', function (obj) { if (obj.event === 'remove') { window.remove(obj); } else if (obj.event === 'edit') { window.edit(obj); } }); window.edit = function (obj) { layer.open({ id: 'app-edit', type: 2, title: '修改', shade: 0.1, offset: '20px', area: ['410px', '600px'], maxWidth: 500, maxHeight: 600, scrollbar: true, content: 'app_edit.html?app_uid=' + obj.data.uid, }); } // 状态修改 form.on('switch(app-status-edit)', function (obj) { let status = layer.load(); let postData = { uid: this.value }; let ret = mhttp.ajax({ url: '/app/edit/status', data: postData, }); ret.then((data) => { layer.close(status); if (data.code === 200) { layer.msg(data.message, {icon: 1, time: 1000}); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); }); form.on('switch(android-enable-edit)', function (obj) { let android = layer.load(); let postData = { uid: this.value }; let ret = mhttp.ajax({ url: '/app/edit/android/enable', data: postData, }); ret.then((data) => { layer.close(android); if (data.code === 200) { layer.msg(data.message, {icon: 1, time: 1000}); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); }); form.on('switch(ios-enable-edit)', function (obj) { let ios = layer.load(); let postData = { uid: this.value }; let ret = mhttp.ajax({ url: '/app/edit/ios/enable', data: postData, }); ret.then((data) => { layer.close(ios); if (data.code === 200) { layer.msg(data.message, {icon: 1, time: 1000}); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); }); window.refresh = function (param) { table.reload('app-table'); } })