save
This commit is contained in:
parent
f764463a1a
commit
e1f5d19ff7
@ -178,149 +178,156 @@
|
|||||||
const UPDATE_URL = "/app/admin/user/update";
|
const UPDATE_URL = "/app/admin/user/update";
|
||||||
|
|
||||||
// 字段 性别 sex
|
// 字段 性别 sex
|
||||||
layui.use(['jquery', 'xmSelect'], function() {
|
layui.use(["jquery", "xmSelect"], function() {
|
||||||
let value = layui.jquery('#sex').attr('value');
|
layui.jquery.ajax({
|
||||||
let initValue = value ? value.split(',') : [];
|
url: "/app/admin/dict/get/sex",
|
||||||
layui.xmSelect.render({
|
dataType: "json",
|
||||||
el: '#sex',
|
success: function (e) {
|
||||||
name: 'sex',
|
let value = layui.jquery("#sex").attr("value");
|
||||||
initValue: initValue,
|
let initValue = value ? value.split(",") : [];
|
||||||
data: [{"value":"男","name":"男"},{"value":"女","name":"女"}],
|
layui.xmSelect.render({
|
||||||
model: {"icon":"hidden","label":{"type":"text"}},
|
el: "#sex",
|
||||||
clickClose: true,
|
name: "sex",
|
||||||
radio: true,
|
initValue: initValue,
|
||||||
})
|
data: e.data,
|
||||||
|
model: {"icon":"hidden","label":{"type":"text"}},
|
||||||
|
clickClose: 'true',
|
||||||
|
radio: 'true',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 生日 birthday
|
// 字段 生日 birthday
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#birthday',
|
elem: "#birthday",
|
||||||
range: ['#birthday-date-start', '#birthday-date-end'],
|
range: ["#birthday-date-start", "#birthday-date-end"],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 登录时间 last_time
|
// 字段 登录时间 last_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#last_time',
|
elem: "#last_time",
|
||||||
range: ['#last_time-date-start', '#last_time-date-end'],
|
range: ["#last_time-date-start", "#last_time-date-end"],
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 注册时间 join_time
|
// 字段 注册时间 join_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#join_time',
|
elem: "#join_time",
|
||||||
range: ['#join_time-date-start', '#join_time-date-end'],
|
range: ["#join_time-date-start", "#join_time-date-end"],
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 表格渲染
|
// 表格渲染
|
||||||
layui.use(['table', 'form', 'jquery', 'common', 'popup'], function() {
|
layui.use(['table', 'form', 'jquery', 'common', 'popup', 'util'], function() {
|
||||||
let table = layui.table;
|
let table = layui.table;
|
||||||
let form = layui.form;
|
let form = layui.form;
|
||||||
let $ = layui.jquery;
|
let $ = layui.jquery;
|
||||||
let common = layui.common;
|
let common = layui.common;
|
||||||
|
let util = layui.util;
|
||||||
|
|
||||||
// 表头参数
|
// 表头参数
|
||||||
let cols = [
|
let cols = [
|
||||||
{
|
{
|
||||||
type: 'checkbox'
|
type: "checkbox"
|
||||||
},{
|
},{
|
||||||
title: '主键',
|
title: "主键",
|
||||||
field: 'id',
|
field: "id",
|
||||||
sort: true,
|
sort: true,
|
||||||
},{
|
},{
|
||||||
title: '用户名',
|
title: "用户名",
|
||||||
field: 'username',
|
field: "username",
|
||||||
},{
|
},{
|
||||||
title: '昵称',
|
title: "昵称",
|
||||||
field: 'nickname',
|
field: "nickname",
|
||||||
},{
|
},{
|
||||||
title: '密码',
|
title: "密码",
|
||||||
field: 'password',
|
field: "password",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '性别',
|
title: "性别",
|
||||||
field: 'sex',
|
field: "sex",
|
||||||
templet: function (d) {
|
templet: function (d) {
|
||||||
let field = 'sex';
|
let field = "sex";
|
||||||
if (typeof d[field] == "undefined") return '';
|
if (typeof d[field] == "undefined") return "";
|
||||||
let items = [];
|
let items = [];
|
||||||
layui.each((d[field] + '').split(','), function (k , v) {
|
layui.each((d[field] + "").split(","), function (k , v) {
|
||||||
items.push(apiResults[field][v] || v);
|
items.push(apiResults[field][v] || v);
|
||||||
});
|
});
|
||||||
return items.join(',');
|
return util.escape(items.join(","));
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
title: '头像',
|
title: "头像",
|
||||||
field: 'avatar',
|
field: "avatar",
|
||||||
templet: function (d) {
|
templet: function (d) {
|
||||||
return '<img src="'+d.avatar+'" style="max-width:32px;max-height:32px;" alt="" />';
|
return '<img src="'+encodeURI(d['avatar'])+'" style="max-width:32px;max-height:32px;" alt="" />'
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
title: '邮箱',
|
title: "邮箱",
|
||||||
field: 'email',
|
field: "email",
|
||||||
},{
|
},{
|
||||||
title: '手机',
|
title: "手机",
|
||||||
field: 'mobile',
|
field: "mobile",
|
||||||
},{
|
},{
|
||||||
title: '等级',
|
title: "等级",
|
||||||
field: 'level',
|
field: "level",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '生日',
|
title: "生日",
|
||||||
field: 'birthday',
|
field: "birthday",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '余额',
|
title: "余额",
|
||||||
field: 'money',
|
field: "money",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '积分',
|
title: "积分",
|
||||||
field: 'score',
|
field: "score",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '登录时间',
|
title: "登录时间",
|
||||||
field: 'last_time',
|
field: "last_time",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '登录ip',
|
title: "登录ip",
|
||||||
field: 'last_ip',
|
field: "last_ip",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '注册时间',
|
title: "注册时间",
|
||||||
field: 'join_time',
|
field: "join_time",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '注册ip',
|
title: "注册ip",
|
||||||
field: 'join_ip',
|
field: "join_ip",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: 'token',
|
title: "token",
|
||||||
field: 'token',
|
field: "token",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '创建时间',
|
title: "创建时间",
|
||||||
field: 'created_at',
|
field: "created_at",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '更新时间',
|
title: "更新时间",
|
||||||
field: 'updated_at',
|
field: "updated_at",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '角色',
|
title: "角色",
|
||||||
field: 'role',
|
field: "role",
|
||||||
hide: true,
|
hide: true,
|
||||||
},{
|
},{
|
||||||
title: '禁用',
|
title: "禁用",
|
||||||
field: 'status',
|
field: "status",
|
||||||
templet: function (d) {
|
templet: function (d) {
|
||||||
let field = 'status';
|
let field = "status";
|
||||||
form.on('switch('+field+')', function (data) {
|
form.on("switch("+field+")", function (data) {
|
||||||
let load = layer.load();
|
let load = layer.load();
|
||||||
let postData = {};
|
let postData = {};
|
||||||
postData[field] = data.elem.checked ? 1 : 0;
|
postData[field] = data.elem.checked ? 1 : 0;
|
||||||
@ -330,11 +337,11 @@
|
|||||||
if (res.code) {
|
if (res.code) {
|
||||||
return layui.popup.failure(res.msg);
|
return layui.popup.failure(res.msg);
|
||||||
}
|
}
|
||||||
return layui.popup.success('操作成功');
|
return layui.popup.success("操作成功");
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let checked = d[field] === 1 ? 'checked' : '';
|
let checked = d[field] === 1 ? "checked" : "";
|
||||||
return '<input type="checkbox" value="'+d[PRIMARY_KEY]+'" lay-filter="'+field+'" lay-skin="switch" lay-text="" '+checked+'/>';
|
return '<input type="checkbox" value="'+util.escape(d[PRIMARY_KEY])+'" lay-filter="'+util.escape(field)+'" lay-skin="switch" lay-text="'+util.escape('')+'" '+checked+'/>';
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
title: "操作",
|
title: "操作",
|
||||||
@ -345,25 +352,58 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 渲染表格
|
// 渲染表格
|
||||||
table.render({
|
function render()
|
||||||
elem: '#data-table',
|
{
|
||||||
url: SELECT_API,
|
table.render({
|
||||||
page: true,
|
elem: "#data-table",
|
||||||
cols: [cols],
|
url: SELECT_API,
|
||||||
skin: 'line',
|
page: true,
|
||||||
size: 'lg',
|
cols: [cols],
|
||||||
toolbar: '#table-toolbar',
|
skin: "line",
|
||||||
autoSort: false,
|
size: "lg",
|
||||||
defaultToolbar: [{
|
toolbar: "#table-toolbar",
|
||||||
title: '刷新',
|
autoSort: false,
|
||||||
layEvent: 'refresh',
|
defaultToolbar: [{
|
||||||
icon: 'layui-icon-refresh',
|
title: "刷新",
|
||||||
}, 'filter', 'print', 'exports']
|
layEvent: "refresh",
|
||||||
});
|
icon: "layui-icon-refresh",
|
||||||
|
}, "filter", "print", "exports"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 获取表格中下拉或树形组件数据
|
// 获取表格中下拉或树形组件数据
|
||||||
|
let apis = [];
|
||||||
|
apis.push(['sex', '/app/admin/dict/get/sex']);
|
||||||
let apiResults = {};
|
let apiResults = {};
|
||||||
apiResults['sex'] = {"男":"男","女":"女"};
|
apiResults['sex'] = [];
|
||||||
|
let count = apis.length;
|
||||||
|
layui.each(apis, function (k, item) {
|
||||||
|
let [field, url] = item;
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
dateType: "json",
|
||||||
|
success: function (res) {
|
||||||
|
function travel(items) {
|
||||||
|
for (let k in items) {
|
||||||
|
let item = items[k];
|
||||||
|
apiResults[field][item.value] = item.name;
|
||||||
|
if (item.children) {
|
||||||
|
travel(item.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
travel(res.data);
|
||||||
|
},
|
||||||
|
complete: function () {
|
||||||
|
if (--count === 0) {
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (!count) {
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
// 编辑或删除行事件
|
// 编辑或删除行事件
|
||||||
table.on('tool(data-table)', function(obj) {
|
table.on('tool(data-table)', function(obj) {
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">性别</label>
|
<label class="layui-form-label">性别</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<div name="sex" id="sex" value="男" ></div>
|
<div name="sex" id="sex" value="1" ></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -155,64 +155,71 @@
|
|||||||
const INSERT_API = "/app/admin/user/insert";
|
const INSERT_API = "/app/admin/user/insert";
|
||||||
|
|
||||||
// 字段 性别 sex
|
// 字段 性别 sex
|
||||||
layui.use(['jquery', 'xmSelect'], function() {
|
layui.use(["jquery", "xmSelect"], function() {
|
||||||
let value = layui.jquery('#sex').attr('value');
|
layui.jquery.ajax({
|
||||||
let initValue = value ? value.split(',') : [];
|
url: "/app/admin/dict/get/sex",
|
||||||
layui.xmSelect.render({
|
dataType: "json",
|
||||||
el: '#sex',
|
success: function (e) {
|
||||||
name: 'sex',
|
let value = layui.jquery("#sex").attr("value");
|
||||||
initValue: initValue,
|
let initValue = value ? value.split(",") : [];
|
||||||
data: [{"value":"男","name":"男"},{"value":"女","name":"女"}],
|
layui.xmSelect.render({
|
||||||
value: '男',
|
el: "#sex",
|
||||||
model: {"icon":"hidden","label":{"type":"text"}},
|
name: "sex",
|
||||||
clickClose: true,
|
initValue: initValue,
|
||||||
radio: true,
|
data: e.data,
|
||||||
})
|
value: '1',
|
||||||
|
model: {"icon":"hidden","label":{"type":"text"}},
|
||||||
|
clickClose: 'true',
|
||||||
|
radio: 'true',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 头像 avatar
|
// 字段 头像 avatar
|
||||||
layui.use(['upload', 'layer', 'jquery'], function() {
|
layui.use(["upload", "layer", "jquery"], function() {
|
||||||
let input = layui.jquery('#avatar').prev();
|
let input = layui.jquery("#avatar").prev();
|
||||||
input.prev().attr('src', input.val());
|
input.prev().attr("src", input.val());
|
||||||
layui.upload.render({
|
layui.upload.render({
|
||||||
elem: '#avatar',
|
elem: "#avatar",
|
||||||
url: '/app/admin/upload/avatar',
|
url: '/app/admin/upload/avatar',
|
||||||
acceptMime: 'image/gif,image/jpeg,image/jpg,image/png',
|
acceptMime: 'image/gif,image/jpeg,image/jpg,image/png',
|
||||||
|
field: '__file__',
|
||||||
done: function (res) {
|
done: function (res) {
|
||||||
if (res.code > 0) return layui.layer.msg(res.msg);
|
if (res.code > 0) return layui.layer.msg(res.msg);
|
||||||
this.item.prev().val(res.data.path).prev().attr('src', res.data.path);
|
this.item.prev().val(res.data.path).prev().attr("src", res.data.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 生日 birthday
|
// 字段 生日 birthday
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#birthday',
|
elem: "#birthday",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 登录时间 last_time
|
// 字段 登录时间 last_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#last_time',
|
elem: "#last_time",
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 注册时间 join_time
|
// 字段 注册时间 join_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#join_time',
|
elem: "#join_time",
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 禁用 status
|
// 字段 禁用 status
|
||||||
layui.use(['form', 'jquery'], function() {
|
layui.use(["form", "jquery"], function() {
|
||||||
layui.jquery('#status').attr('checked', layui.jquery('input[name="status"]').val() != 0);
|
layui.jquery("#status").attr("checked", layui.jquery('input[name="status"]').val() != 0);
|
||||||
layui.form.render();
|
layui.form.render();
|
||||||
layui.form.on('switch(status)', function(data) {
|
layui.form.on("switch(status)", function(data) {
|
||||||
layui.jquery('input[name="status"]').val(this.checked ? 1 : 0);
|
layui.jquery('input[name="status"]').val(this.checked ? 1 : 0);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -172,70 +172,77 @@
|
|||||||
}
|
}
|
||||||
if (typeof obj[0] === 'undefined' || !obj[0].nodeName) return;
|
if (typeof obj[0] === 'undefined' || !obj[0].nodeName) return;
|
||||||
if (obj[0].nodeName.toLowerCase() === 'textarea') {
|
if (obj[0].nodeName.toLowerCase() === 'textarea') {
|
||||||
obj.html(layui.util.escape(value));
|
obj.val(layui.util.escape(value));
|
||||||
} else {
|
} else {
|
||||||
obj.attr('value', value);
|
obj.attr('value', value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 性别 sex
|
// 字段 性别 sex
|
||||||
layui.use(['jquery', 'xmSelect'], function() {
|
layui.use(["jquery", "xmSelect"], function() {
|
||||||
let value = layui.jquery('#sex').attr('value');
|
layui.jquery.ajax({
|
||||||
let initValue = value ? value.split(',') : [];
|
url: "/app/admin/dict/get/sex",
|
||||||
layui.xmSelect.render({
|
dataType: "json",
|
||||||
el: '#sex',
|
success: function (e) {
|
||||||
name: 'sex',
|
let value = layui.jquery("#sex").attr("value");
|
||||||
initValue: initValue,
|
let initValue = value ? value.split(",") : [];
|
||||||
data: [{"value":"男","name":"男"},{"value":"女","name":"女"}],
|
layui.xmSelect.render({
|
||||||
model: {"icon":"hidden","label":{"type":"text"}},
|
el: "#sex",
|
||||||
clickClose: true,
|
name: "sex",
|
||||||
radio: true,
|
initValue: initValue,
|
||||||
})
|
data: e.data,
|
||||||
|
model: {"icon":"hidden","label":{"type":"text"}},
|
||||||
|
clickClose: 'true',
|
||||||
|
radio: 'true',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 头像 avatar
|
// 字段 头像 avatar
|
||||||
layui.use(['upload', 'layer', 'jquery'], function() {
|
layui.use(["upload", "layer", "jquery"], function() {
|
||||||
let input = layui.jquery('#avatar').prev();
|
let input = layui.jquery("#avatar").prev();
|
||||||
input.prev().attr('src', input.val());
|
input.prev().attr("src", input.val());
|
||||||
layui.upload.render({
|
layui.upload.render({
|
||||||
elem: '#avatar',
|
elem: "#avatar",
|
||||||
url: '/app/admin/upload/avatar',
|
url: '/app/admin/upload/avatar',
|
||||||
acceptMime: 'image/gif,image/jpeg,image/jpg,image/png',
|
acceptMime: 'image/gif,image/jpeg,image/jpg,image/png',
|
||||||
|
field: '__file__',
|
||||||
done: function (res) {
|
done: function (res) {
|
||||||
if (res.code > 0) return layui.layer.msg(res.msg);
|
if (res.code > 0) return layui.layer.msg(res.msg);
|
||||||
this.item.prev().val(res.data.path).prev().attr('src', res.data.path);
|
this.item.prev().val(res.data.path).prev().attr("src", res.data.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 字段 生日 birthday
|
// 字段 生日 birthday
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#birthday',
|
elem: "#birthday",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 登录时间 last_time
|
// 字段 登录时间 last_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#last_time',
|
elem: "#last_time",
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 注册时间 join_time
|
// 字段 注册时间 join_time
|
||||||
layui.use(['laydate'], function() {
|
layui.use(["laydate"], function() {
|
||||||
layui.laydate.render({
|
layui.laydate.render({
|
||||||
elem: '#join_time',
|
elem: "#join_time",
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 字段 禁用 status
|
// 字段 禁用 status
|
||||||
layui.use(['form', 'jquery'], function() {
|
layui.use(["form", "jquery"], function() {
|
||||||
layui.jquery('#status').attr('checked', layui.jquery('input[name="status"]').val() != 0);
|
layui.jquery("#status").attr("checked", layui.jquery('input[name="status"]').val() != 0);
|
||||||
layui.form.render();
|
layui.form.render();
|
||||||
layui.form.on('switch(status)', function(data) {
|
layui.form.on("switch(status)", function(data) {
|
||||||
layui.jquery('input[name="status"]').val(this.checked ? 1 : 0);
|
layui.jquery('input[name="status"]').val(this.checked ? 1 : 0);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user