350 lines
16 KiB
HTML
350 lines
16 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-scratchcard" lay-filter="table-scratchcard"></table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/html" id="toolbar-scratchcard">
|
|
<div class="layui-btn-container">
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="init-scratchcard"><i class="layui-icon layui-icon-refresh"></i> 初始化配置</button>
|
|
<button class="layui-btn layui-btn-sm" lay-filter="save-scratchcard"><i class="layui-icon layui-icon-ok"></i> 保存配置</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-filter="reload-scratchcard"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
|
|
<button class="layui-btn layui-btn-sm" lay-filter="add-scratchcard">添加</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-filter="batchdel-scratchcard">批量删除</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="saveSection('ScratchCardConfig')"><i class="layui-icon layui-icon-export"></i> 保存到初始化文件</button>
|
|
</div>
|
|
</script>
|
|
|
|
<script type="text/html" id="tpl-type">
|
|
{{# var typeMap = {1:'金币',2:'钻石',3:'道具'}; }}
|
|
{{= typeMap[d.type] || '金币' }}
|
|
</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-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
|
|
</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;
|
|
|
|
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;
|
|
renderTable();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function renderTable() {
|
|
var data = gameConfig ? gameConfig.scratchCardConfig || [] : [];
|
|
table.render({
|
|
elem: '#table-scratchcard',
|
|
data: data,
|
|
cols: [[
|
|
{ type: 'checkbox', fixed: 'left' },
|
|
{ field: "type", title: "奖励类型", width: 100, templet: '#tpl-type' },
|
|
{ field: "count", title: "奖励数量", width: 100 },
|
|
{ field: "weight", title: "权重", width: 100 },
|
|
{ field: "baseProduct", title: "道具编号", width: 120, templet: function(d) { return d.baseProduct ? d.baseProduct.number : ''; } },
|
|
{ field: "baseProduct", title: "道具名称", width: 120, templet: function(d) { return d.baseProduct ? d.baseProduct.name : ''; } },
|
|
{ title: "操作", width: 150, fixed: 'right', toolbar: '#table-operate' }
|
|
]],
|
|
toolbar: '#toolbar-scratchcard',
|
|
defaultToolbar: ['filter', 'exports', 'print']
|
|
});
|
|
}
|
|
|
|
function initConfig() {
|
|
layer.confirm('确定要初始化全部配置数据吗?此操作将清空现有数据!', function(idx) {
|
|
layer.close(idx);
|
|
admin.req({
|
|
method: "get",
|
|
url: setter.baseurl + "adminapi/GameConfig/InitSection/ScratchCardConfig",
|
|
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-scratchcard"]', 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-scratchcard"]', function() {
|
|
loadConfig();
|
|
layer.msg('刷新成功');
|
|
});
|
|
|
|
$(document).on('click', '[lay-filter="save-scratchcard"]', function() {
|
|
if (window.parent && window.parent.$ && window.parent.layer) {
|
|
window.parent.$('.layui-layer-shade').remove();
|
|
window.parent.layer.closeAll();
|
|
}
|
|
var configs = gameConfig.scratchCardConfig || [];
|
|
if (configs.length === 0) return layer.msg('至少保留一条刮刮卡配置');
|
|
for (var i = 0; i < configs.length; i++) {
|
|
if (configs[i].count <= 0) return layer.msg('第 ' + (i + 1) + ' 项奖励数量必须大于0');
|
|
if (configs[i].weight <= 0) return layer.msg('第 ' + (i + 1) + ' 项权重必须大于0');
|
|
if (configs[i].type === 3 && (!configs[i].baseProduct || !configs[i].baseProduct.number))
|
|
return layer.msg('第 ' + (i + 1) + ' 项道具编号不能为空');
|
|
}
|
|
if (configs.length > 0) {
|
|
configs.forEach(function(item) {
|
|
if (!item.baseProduct) {
|
|
item.baseProduct = { type: 1, number: '', name: '', desc: '', imageUrl: '', level: 0 };
|
|
}
|
|
});
|
|
}
|
|
admin.req({
|
|
method: "post",
|
|
contentType: "application/json;charset=UTF-8",
|
|
url: setter.baseurl + "adminapi/GameConfig/UpdateScratchCard",
|
|
data: JSON.stringify(configs),
|
|
done: function (res) {
|
|
if (res.code === 0 || res.code === 200) {
|
|
layer.msg('保存成功');
|
|
loadConfig();
|
|
} else {
|
|
layer.msg(res.info || '保存失败');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
table.on('tool(table-scratchcard)', function(obj) {
|
|
var data = obj.data;
|
|
var trIndex = gameConfig.scratchCardConfig.findIndex(function(x) {
|
|
return x.type === data.type && x.count === data.count && x.weight === data.weight;
|
|
});
|
|
if (obj.event === 'edit') {
|
|
showEditDialog(trIndex > -1 ? gameConfig.scratchCardConfig[trIndex] : data, false, trIndex);
|
|
} else if (obj.event === 'del') {
|
|
layer.confirm('确定删除该配置吗?', function(idx) {
|
|
if (trIndex > -1) gameConfig.scratchCardConfig.splice(trIndex, 1);
|
|
obj.del();
|
|
layer.close(idx);
|
|
});
|
|
}
|
|
});
|
|
|
|
function showAddDialog() {
|
|
if (!gameConfig.scratchCardConfig) {
|
|
gameConfig.scratchCardConfig = [];
|
|
}
|
|
var newData = {
|
|
type: 1,
|
|
count: 100,
|
|
weight: 10,
|
|
baseProduct: { type: 1, number: '', name: '', desc: '' },
|
|
propNumber: '',
|
|
propName: ''
|
|
};
|
|
showEditDialog(newData, true);
|
|
}
|
|
|
|
$(document).on('click', '[lay-filter="add-scratchcard"]', function() {
|
|
showAddDialog();
|
|
});
|
|
|
|
$(document).on('click', '[lay-filter="batchdel-scratchcard"]', function() {
|
|
var checkStatus = table.checkStatus('table-scratchcard');
|
|
var checkData = checkStatus.data;
|
|
if (checkData.length === 0) {
|
|
return layer.msg('请选择要删除的数据');
|
|
}
|
|
layer.confirm('确定删除选中的 ' + checkData.length + ' 条数据吗?', function(idx) {
|
|
var ids = checkData.map(function(item) { return item.baseProduct ? item.baseProduct.number : ''; });
|
|
gameConfig.scratchCardConfig = gameConfig.scratchCardConfig.filter(function(item) {
|
|
return !ids.includes(item.baseProduct ? item.baseProduct.number : '');
|
|
});
|
|
renderTable();
|
|
layer.close(idx);
|
|
});
|
|
});
|
|
|
|
function showEditDialog(data, isAdd, rowIndex) {
|
|
var dialogTitle = isAdd ? '添加刮刮卡' : '编辑刮刮卡';
|
|
if (!data.baseProduct) {
|
|
data.baseProduct = { type: 1, number: '', name: '', desc: '' };
|
|
}
|
|
var typeOptions = [
|
|
{value: 1, text: '金币'},
|
|
{value: 2, text: '钻石'},
|
|
{value: 3, text: '道具'}
|
|
];
|
|
|
|
var typeHtml = '';
|
|
typeOptions.forEach(function(opt) {
|
|
typeHtml += '<option value="' + opt.value + '"' + (data.type === opt.value ? ' selected' : '') + '>' + opt.text + '</option>';
|
|
});
|
|
|
|
var propTypeOptions = [
|
|
{value: 1, text: '道具'},
|
|
{value: 2, text: '技能'},
|
|
{value: 5, text: '炮台'},
|
|
{value: 6, text: '翅膀'},
|
|
{value: 7, text: '战神'}
|
|
];
|
|
|
|
var propTypeHtml = '';
|
|
var currentPropType = data.baseProduct ? data.baseProduct.type : 1;
|
|
propTypeOptions.forEach(function(opt) {
|
|
propTypeHtml += '<option value="' + opt.value + '"' + (currentPropType === opt.value ? ' selected' : '') + '>' + opt.text + '</option>';
|
|
});
|
|
|
|
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">' +
|
|
'<select name="type">' + typeHtml + '</select>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">奖励数量</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="number" name="count" value="' + (data.count || 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="weight" value="' + (data.weight || 0) + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">道具编号</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="text" name="propNumber" value="' + ((data.baseProduct && data.baseProduct.number) || data.propNumber || '') + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">道具名称</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<input type="text" name="propName" value="' + ((data.baseProduct && data.baseProduct.name) || data.propName || '') + '" class="layui-input">' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="layui-form-item">' +
|
|
'<label class="layui-form-label">道具类型</label>' +
|
|
'<div class="layui-input-block">' +
|
|
'<select name="propType">' + propTypeHtml + '</select>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</form>' +
|
|
'</div>';
|
|
|
|
layer.open({
|
|
type: 1,
|
|
title: dialogTitle,
|
|
area: ['500px', '450px'],
|
|
content: html,
|
|
btn: ['保存', '取消'],
|
|
shadeClose: true,
|
|
success: function(layero) {
|
|
form.render('select');
|
|
},
|
|
yes: function(index, layero) {
|
|
var rewardType = parseInt(layero.find('select[name="type"]').val());
|
|
var rewardCount = parseInt(layero.find('input[name="count"]').val()) || 0;
|
|
var rewardWeight = parseInt(layero.find('input[name="weight"]').val()) || 0;
|
|
var propNumber = layero.find('input[name="propNumber"]').val();
|
|
var propName = layero.find('input[name="propName"]').val();
|
|
var propType = parseInt(layero.find('select[name="propType"]').val());
|
|
|
|
if (rewardCount <= 0) return layer.msg('奖励数量必须大于0');
|
|
if (rewardWeight <= 0) return layer.msg('权重必须大于0');
|
|
if (rewardType === 3 && !propNumber) return layer.msg('道具奖励必须填写道具编号');
|
|
|
|
if (isAdd) {
|
|
var newItem = {
|
|
type: rewardType,
|
|
count: rewardCount,
|
|
weight: rewardWeight,
|
|
propNumber: propNumber,
|
|
propName: propName,
|
|
baseProduct: {
|
|
type: propType,
|
|
number: propNumber,
|
|
name: propName,
|
|
desc: ''
|
|
}
|
|
};
|
|
gameConfig.scratchCardConfig.unshift(newItem);
|
|
} else if (rowIndex > -1) {
|
|
// Layui 行对象是副本,编辑结果必须写回原始数组。
|
|
var original = gameConfig.scratchCardConfig[rowIndex];
|
|
original.type = rewardType;
|
|
original.count = rewardCount;
|
|
original.weight = rewardWeight;
|
|
original.propNumber = propNumber;
|
|
original.propName = propName;
|
|
original.baseProduct = {
|
|
type: propType,
|
|
number: propNumber,
|
|
name: propName,
|
|
desc: original.baseProduct ? (original.baseProduct.desc || '') : ''
|
|
};
|
|
}
|
|
layer.close(index);
|
|
table.reload('table-scratchcard', {
|
|
data: gameConfig.scratchCardConfig
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
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?'保存成功':'保存失败'))}})}
|
|
|
|
loadConfig();
|
|
});
|
|
</script>
|