| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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();
- //搜索条件
- let username = GetQueryString('username') ?? null;
- let nick = GetQueryString('nick') ?? null;
- $('.username').val(username);
- $('.nick').val(nick);
- let cols = [
- [
- {
- title: 'UID',
- field: 'manager_uid',
- align: 'center'
- },
- {
- title: '昵称',
- field: 'nick',
- align: 'center'
- },
- {
- title: '账号',
- field: 'username',
- align: 'center'
- },
- {
- title: '最近登录时间',
- field: 'login_at',
- align: 'center'
- },
- {
- title: '更新时间',
- field: 'updated_at',
- align: 'center'
- },
- {
- title: '操作',
- toolbar: '#users-bar',
- align: 'center'
- }
- ]
- ]
- let search = httpRequestPostData({
- username: username,
- nick: nick,
- });
- table.render({
- elem: '#users-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('/manager/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: '#users-toolbar',
- defaultToolbar: [{
- title: '刷新',
- layEvent: 'refresh',
- icon: 'layui-icon-refresh',
- }, 'filter', 'print', 'exports']
- });
- table.on('toolbar(users-table)', function (obj) {
- if (obj.event === 'add') {
- window.add();
- } else if (obj.event === 'refresh') {
- window.refresh();
- } else if (obj.event === 'batchRemove') {
- window.batchRemove(obj);
- }
- });
- window.add = function () {
- layer.open({
- id: 'users_create',
- type: 2,
- title: '添加',
- shade: 0.1,
- offset: '80px',
- area: ['450px', '400px'],
- maxWidth: 500,
- maxHeight: 500,
- scrollbar: true,
- content: 'users_create.html',
- });
- }
- // 表单内
- table.on('tool(users-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: 'users-edit',
- type: 2,
- title: '修改',
- shade: 0.1,
- offset: '80px',
- area: ['450px', '450px'],
- maxWidth: 500,
- maxHeight: 500,
- scrollbar: true,
- content: 'users_edit.html?manager_uid=' + obj.data.manager_uid,
- });
- }
- // 删除
- window.remove = function (obj) {
- layer.confirm('确定要删除 ID 为:' + obj.data.manager_uid + ' 标签?', {
- icon: 3,
- title: '提示'
- }, function () {
- let deleteLoading = layer.msg('操作数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
- let postData = {
- manager_uid: obj.data.manager_uid
- };
- let ret = mhttp.ajax({
- url: '/manager/delete',
- data: postData,
- });
- ret.then((data) => {
- layer.close(deleteLoading);
- if (data.code === 200) {
- layer.msg(data.message, {icon: 1, time: 1000});
- obj.del();
- } else {
- layer.msg(data.message, {icon: 2, time: 1000});
- }
- });
- });
- }
- window.refresh = function (param) {
- table.reload('users-table');
- }
- })
|