444 lines
19 KiB
HTML
444 lines
19 KiB
HTML
<title>用户等级配置</title>
|
|
|
|
<div class="layui-card layadmin-header">
|
|
<div class="layui-breadcrumb" lay-filter="breadcrumb">
|
|
<a lay-href="">主页</a>
|
|
<a><cite>游戏管理</cite></a>
|
|
<a><cite>用户等级配置</cite></a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-fluid">
|
|
<div class="layui-card">
|
|
<div class="layui-card-body">
|
|
<table id="table-userlevel" lay-filter="table-userlevel"></table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/html" id="toolbar-userlevel">
|
|
<div class="layui-btn-container">
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="init-userlevel"><i class="layui-icon layui-icon-refresh"></i> 初始化配置</button>
|
|
<button class="layui-btn layui-btn-sm" lay-filter="save-userlevel"><i class="layui-icon layui-icon-ok"></i> 保存配置</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-filter="reload-userlevel"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
|
|
<button class="layui-btn layui-btn-sm" lay-filter="add-userlevel">添加</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-filter="batchdel-userlevel">批量删除</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="saveSection('UserLevelConfigs')"><i class="layui-icon layui-icon-export"></i> 保存到初始化文件</button>
|
|
</div>
|
|
</script>
|
|
<script>window.saveSection=function(n){layui.admin.req({method:'get',url:(layui.setter.baseurl||'/')+'adminapi/GameConfig/SaveSection/'+n,done:function(r){layui.layer.msg(r.info||(r.code===0?'保存成功':'保存失败'))}})}</script>
|
|
|
|
<script type="text/html" id="table-operate">
|
|
<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
|
|
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="product"><i class="layui-icon layui-icon-gift"></i>道具</a>
|
|
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
|
|
</script>
|
|
|
|
<script type="text/html" id="product-dialog-tpl">
|
|
<div style="padding:20px;">
|
|
<div class="layui-form">
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">选择道具</label>
|
|
<div class="layui-input-block">
|
|
<select name="productNumber" id="productNumber" lay-search>
|
|
<option value="">请选择道具</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">数量</label>
|
|
<div class="layui-input-block">
|
|
<input type="number" name="productCount" id="productCount" class="layui-input" placeholder="请输入数量" value="1">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</script>
|
|
|
|
<script>
|
|
layui.use(['admin', 'table', 'form', 'layer'], function () {
|
|
var $ = layui.$,
|
|
admin = layui.admin,
|
|
table = layui.table,
|
|
form = layui.form,
|
|
layer = layui.layer,
|
|
setter = layui.setter;
|
|
|
|
var gameConfig = null;
|
|
var currentLevelIndex = -1;
|
|
var currentProductIndex = -1;
|
|
var propList = [];
|
|
var currentDialogData = null;
|
|
|
|
setTimeout(function() {
|
|
if (window.parent && window.parent.$ && window.parent.layer) {
|
|
window.parent.$('.layui-layer-shade').remove();
|
|
window.parent.layer.closeAll();
|
|
}
|
|
$('.layui-layer-shade').remove();
|
|
layer.closeAll();
|
|
}, 100);
|
|
|
|
function loadConfig() {
|
|
admin.req({
|
|
method: "get",
|
|
url: setter.baseurl + "adminapi/GameConfig",
|
|
done: function (res) {
|
|
if (res.code === 0 && res.data) {
|
|
gameConfig = res.data;
|
|
propList = (gameConfig.propConfig || []).map(function(p) {
|
|
return { number: p.number, name: p.name, type: p.type };
|
|
});
|
|
renderTable();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function renderTable() {
|
|
table.render({
|
|
elem: '#table-userlevel',
|
|
data: gameConfig ? gameConfig.userLevelConfigs || [] : [],
|
|
cols: [[
|
|
{ type: 'checkbox', fixed: 'left' },
|
|
{ field: "level", title: "等级", width: 70, edit: 'text' },
|
|
{ field: "expMin", title: "经验下限", width: 100, edit: 'text' },
|
|
{ field: "expMax", title: "经验上限", width: 100, edit: 'text' },
|
|
{ field: "gold", title: "金币", width: 120, edit: 'text' },
|
|
{ field: "diamond", title: "钻石", width: 100, edit: 'text' },
|
|
{ field: "productList", title: "升级道具", width: 100, templet: function(d) {
|
|
return (d.productList && d.productList.length) ? d.productList.length + '项' : '无';
|
|
}},
|
|
{ title: "操作", width: 220, fixed: 'right', toolbar: '#table-operate' }
|
|
]],
|
|
toolbar: '#toolbar-userlevel',
|
|
defaultToolbar: ['filter', 'exports', 'print']
|
|
});
|
|
}
|
|
|
|
function initConfig() {
|
|
layer.confirm('确定要初始化全部配置数据吗?此操作将清空现有数据!', function(idx) {
|
|
layer.close(idx);
|
|
admin.req({
|
|
method: "get",
|
|
url: setter.baseurl + "adminapi/GameConfig/InitSection/UserLevelConfigs",
|
|
done: function (res) {
|
|
if (res.code === 0 || res.code === 200) {
|
|
layer.msg('初始化成功');
|
|
loadConfig();
|
|
} else {
|
|
layer.msg(res.info || '初始化失败');
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
layer.msg(res.info || '初始化失败');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
$(document).on('click', '[lay-filter="init-userlevel"]', function() {
|
|
if (window.parent && window.parent.$ && window.parent.layer) {
|
|
window.parent.$('.layui-layer-shade').remove();
|
|
window.parent.layer.closeAll();
|
|
}
|
|
initConfig();
|
|
});
|
|
|
|
$(document).on('click', '[lay-filter="reload-userlevel"]', function() {
|
|
loadConfig();
|
|
layer.msg('刷新成功');
|
|
});
|
|
|
|
$(document).on('click', '[lay-filter="save-userlevel"]', function() {
|
|
if (window.parent && window.parent.$ && window.parent.layer) {
|
|
window.parent.$('.layui-layer-shade').remove();
|
|
window.parent.layer.closeAll();
|
|
}
|
|
admin.req({
|
|
method: "post",
|
|
contentType: "application/json;charset=UTF-8",
|
|
url: setter.baseurl + "adminapi/GameConfig/Update",
|
|
data: JSON.stringify(gameConfig),
|
|
done: function (res) {
|
|
if (res.code === 0 || res.code === 200) {
|
|
layer.msg('保存成功');
|
|
loadConfig();
|
|
} else {
|
|
layer.msg(res.info || '保存失败');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
function updateDataByTable(obj) {
|
|
var field = obj.field;
|
|
var value = obj.value;
|
|
var data = obj.data;
|
|
|
|
if (!isNaN(value) && value !== '') {
|
|
var num = parseFloat(value);
|
|
data[field] = num;
|
|
}
|
|
}
|
|
|
|
table.on('edit(table-userlevel)', function(obj){
|
|
updateDataByTable(obj);
|
|
});
|
|
|
|
table.on('tool(table-userlevel)', function(obj) {
|
|
var data = obj.data;
|
|
var trIndex = obj.tr.index();
|
|
if (trIndex < 0) trIndex = gameConfig.userLevelConfigs.findIndex(function(x) { return x.level === data.level; });
|
|
|
|
if (obj.event === 'edit') {
|
|
showEditDialog(data, false, trIndex);
|
|
} else if (obj.event === 'del') {
|
|
layer.confirm('确定删除该配置吗?', function(idx) {
|
|
if (trIndex >= 0) gameConfig.userLevelConfigs.splice(trIndex, 1);
|
|
obj.del();
|
|
layer.close(idx);
|
|
});
|
|
} else if (obj.event === 'product') {
|
|
currentLevelIndex = trIndex;
|
|
showProductDialog(data);
|
|
}
|
|
});
|
|
|
|
function showAddDialog() {
|
|
var newData = {
|
|
level: 0,
|
|
expMin: 0,
|
|
expMax: 0,
|
|
gold: 0,
|
|
diamond: 0,
|
|
productList: []
|
|
};
|
|
showEditDialog(newData, true);
|
|
}
|
|
|
|
$(document).on('click', '[lay-filter="add-userlevel"]', function() {
|
|
showAddDialog();
|
|
});
|
|
|
|
function showEditDialog(data, isAdd, rowIndex) {
|
|
var dialogTitle = isAdd ? '添加用户等级' : '编辑用户等级';
|
|
var html = '<div style="padding:20px;">' +
|
|
'<form class="layui-form">' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">等级</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="level" value="' + (data.level || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">经验下限</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="expMin" value="' + (data.expMin || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">经验上限</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="expMax" value="' + (data.expMax || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">金币</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="gold" value="' + (data.gold || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">钻石</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="diamond" value="' + (data.diamond || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</form>' +
|
|
'</div>';
|
|
|
|
layer.open({
|
|
type: 1,
|
|
title: dialogTitle,
|
|
area: ['550px', '450px'],
|
|
content: html,
|
|
btn: ['保存', '取消'],
|
|
shadeClose: true,
|
|
yes: function(index, layero) {
|
|
if (isAdd) {
|
|
var newItem = {
|
|
level: parseInt(layero.find('input[name="level"]').val()) || 0,
|
|
expMin: parseInt(layero.find('input[name="expMin"]').val()) || 0,
|
|
expMax: parseInt(layero.find('input[name="expMax"]').val()) || 0,
|
|
gold: parseInt(layero.find('input[name="gold"]').val()) || 0,
|
|
diamond: parseInt(layero.find('input[name="diamond"]').val()) || 0,
|
|
productList: []
|
|
};
|
|
gameConfig.userLevelConfigs.unshift(newItem);
|
|
} else {
|
|
var original = gameConfig.userLevelConfigs[rowIndex];
|
|
if (!original) {
|
|
original = gameConfig.userLevelConfigs.find(function(x) { return x.level === data.level; });
|
|
}
|
|
if (!original) { layer.msg('数据异常,请刷新后重试'); return; }
|
|
original.level = parseInt(layero.find('input[name="level"]').val()) || 0;
|
|
original.expMin = parseInt(layero.find('input[name="expMin"]').val()) || 0;
|
|
original.expMax = parseInt(layero.find('input[name="expMax"]').val()) || 0;
|
|
original.gold = parseInt(layero.find('input[name="gold"]').val()) || 0;
|
|
original.diamond = parseInt(layero.find('input[name="diamond"]').val()) || 0;
|
|
}
|
|
layer.close(index);
|
|
table.reload('table-userlevel', {
|
|
data: gameConfig.userLevelConfigs
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
$(document).on('click', '[lay-filter="batchdel-userlevel"]', function() {
|
|
var checkStatus = table.checkStatus('table-userlevel');
|
|
var checkData = checkStatus.data;
|
|
if (checkData.length === 0) {
|
|
return layer.msg('请选择要删除的数据');
|
|
}
|
|
layer.confirm('确定删除选中的 ' + checkData.length + ' 条数据吗?', function(idx) {
|
|
var levels = checkData.map(function(item) { return item.level; });
|
|
gameConfig.userLevelConfigs = gameConfig.userLevelConfigs.filter(function(item) {
|
|
return !levels.includes(item.level);
|
|
});
|
|
table.reload('table-userlevel', {
|
|
data: gameConfig.userLevelConfigs
|
|
});
|
|
layer.close(idx);
|
|
});
|
|
});
|
|
|
|
function showProductDialog(data) {
|
|
currentDialogData = data;
|
|
currentProductIndex = -1;
|
|
|
|
var dialogContent = $('#product-dialog-tpl').html();
|
|
|
|
layer.open({
|
|
type: 1,
|
|
title: '等级' + data.level + ' - 升级道具',
|
|
area: ['600px', '400px'],
|
|
content: dialogContent,
|
|
shadeClose: true,
|
|
success: function(layero) {
|
|
var propOptions = '<option value="">请选择道具</option>';
|
|
propList.forEach(function(p) {
|
|
propOptions += '<option value="' + p.number + '">' + p.number + ' - ' + p.name + '</option>';
|
|
});
|
|
layero.find('#productNumber').html(propOptions);
|
|
form.render();
|
|
|
|
renderProductTable(layero);
|
|
|
|
layero.find('#productNumber').on('change', function() {
|
|
var selected = $(this).val();
|
|
if (selected) {
|
|
var prop = propList.find(function(p) { return p.number === selected; });
|
|
if (prop) {
|
|
layero.find('#productCount').val(1);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
btn: ['添加', '关闭'],
|
|
yes: function(index, layero) {
|
|
var number = layero.find('#productNumber').val();
|
|
var count = parseInt(layero.find('#productCount').val()) || 1;
|
|
if (!number) {
|
|
layer.msg('请选择道具');
|
|
return;
|
|
}
|
|
var prop = propList.find(function(p) { return p.number === number; });
|
|
var list = getProductList();
|
|
var existing = list.find(function(p) { return p.number === number; });
|
|
if (existing) {
|
|
existing.count += count;
|
|
} else {
|
|
list.push({
|
|
number: number,
|
|
name: prop ? prop.name : '',
|
|
type: prop ? prop.type : 0,
|
|
count: count
|
|
});
|
|
}
|
|
renderProductTable(layero);
|
|
layer.msg('添加成功');
|
|
}
|
|
});
|
|
}
|
|
|
|
function getProductList() {
|
|
if (!currentDialogData) return [];
|
|
if (!currentDialogData.productList) {
|
|
currentDialogData.productList = [];
|
|
}
|
|
return currentDialogData.productList;
|
|
}
|
|
|
|
function getPropName(number) {
|
|
var prop = propList.find(function(p) { return p.number === number; });
|
|
return prop ? prop.number + ' - ' + prop.name : number || '';
|
|
}
|
|
|
|
function getPropType(number) {
|
|
var prop = propList.find(function(p) { return p.number === number; });
|
|
return prop ? prop.type : 0;
|
|
}
|
|
|
|
function renderProductTable(layero) {
|
|
var list = getProductList();
|
|
|
|
if (layero.find('#table-product-list').length === 0) {
|
|
layero.find('.layui-layer-content').append(
|
|
'<div style="padding:0 20px 20px;"><table id="table-product-list" lay-filter="table-product-list"></table></div>'
|
|
);
|
|
}
|
|
|
|
table.render({
|
|
elem: layero.find('#table-product-list'),
|
|
data: list,
|
|
page: false,
|
|
height: 260,
|
|
cols: [[
|
|
{ type: 'numbers', title: '序号', width: 60 },
|
|
{ field: "number", title: "道具编号", width: 120 },
|
|
{ field: "name", title: "道具名称", width: 120 },
|
|
{ field: "count", title: "数量", width: 80, edit: 'text' },
|
|
{ title: "操作", width: 100, templet: function(d) {
|
|
return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
|
|
}}
|
|
]]
|
|
});
|
|
|
|
layero.off('click', '.layui-btn-danger').on('click', '.layui-btn-danger', function() {
|
|
var tr = $(this).closest('tr[data-index]');
|
|
var index = parseInt(tr.attr('data-index'));
|
|
var list = getProductList();
|
|
if (index >= 0 && index < list.length) {
|
|
list.splice(index, 1);
|
|
renderProductTable(layero);
|
|
}
|
|
});
|
|
|
|
table.on('edit(table-product-list)', function(obj) {
|
|
var list = getProductList();
|
|
var index = layero.find('#table-product-list + .layui-table-view tr[data-index]').index(obj.tr);
|
|
if (index >= 0 && index < list.length) {
|
|
list[index].count = parseInt(obj.value) || 0;
|
|
}
|
|
});
|
|
}
|
|
|
|
loadConfig();
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|