433 lines
23 KiB
HTML
433 lines
23 KiB
HTML
|
|||
|
|
<title>排行榜奖励配置</title>
|
||
|
|
|
||
|
|
<style>
|
||
|
|
.layui-form-label { width: 200px; }
|
||
|
|
.rank-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
|
||
|
|
.rank-table th, .rank-table td { border: 1px solid #e6e6e6; padding: 6px 8px; text-align: center; font-size: 13px; }
|
||
|
|
.rank-table th { background: #f2f2f2; font-weight: bold; }
|
||
|
|
.rank-table input { text-align: center; height: 32px; }
|
||
|
|
.rank-table .del-row { color: #ff5722; cursor: pointer; }
|
||
|
|
.item-btn { cursor: pointer; color: #1e9fff; text-decoration: underline; }
|
||
|
|
.prop-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
|
||
|
|
.prop-row select { flex: 1; }
|
||
|
|
.prop-row input { width: 60px; }
|
||
|
|
</style>
|
||
|
|
|
||
|
|
<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-header">
|
||
|
|
<div class="layui-btn-container">
|
||
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="save-ranking"><i class="layui-icon layui-icon-ok"></i> 保存配置</button>
|
||
|
|
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-filter="reload-ranking"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
|
||
|
|
<button class="layui-btn layui-btn-sm" lay-filter="init-ranking"><i class="layui-icon layui-icon-refresh-3"></i> 初始化</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="layui-card-body">
|
||
|
|
<form class="layui-form" id="form-ranking" style="padding: 20px;">
|
||
|
|
<div class="layui-form-item">
|
||
|
|
<label class="layui-form-label">总开关</label>
|
||
|
|
<div class="layui-input-inline">
|
||
|
|
<input type="checkbox" name="isEnabled" lay-skin="switch" lay-text="开启|关闭">
|
||
|
|
</div>
|
||
|
|
<div class="layui-form-mid">关闭后所有排行榜奖励将不发放</div>
|
||
|
|
</div>
|
||
|
|
<div class="layui-form-item">
|
||
|
|
<label class="layui-form-label">维护中</label>
|
||
|
|
<div class="layui-input-inline">
|
||
|
|
<input type="checkbox" name="isMaintaining" lay-skin="switch" lay-text="开启|关闭">
|
||
|
|
</div>
|
||
|
|
<div class="layui-form-mid">开启后前端请求排行榜将提示维护中</div>
|
||
|
|
</div>
|
||
|
|
<div class="layui-form-item">
|
||
|
|
<label class="layui-form-label">维护提示文案</label>
|
||
|
|
<div class="layui-input-inline" style="width: 400px;">
|
||
|
|
<input type="text" name="maintainingMessage" class="layui-input" placeholder="当前排行榜正在维护中,请稍后再试">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div id="groups-container"></div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
layui.use(['admin', 'form', 'layer'], function () {
|
||
|
|
var $ = layui.$,
|
||
|
|
admin = layui.admin,
|
||
|
|
form = layui.form,
|
||
|
|
layer = layui.layer,
|
||
|
|
setter = layui.setter;
|
||
|
|
|
||
|
|
var activityConfig = null;
|
||
|
|
var propList = [];
|
||
|
|
var RANKING_NAMES = { 1: '金币达人榜', 2: '等级达人榜', 3: '当日积分榜' };
|
||
|
|
var ITEMS_CTX = null; // { gi, ri } 当前编辑的单元格
|
||
|
|
|
||
|
|
function loadPropList() {
|
||
|
|
admin.req({
|
||
|
|
method: "get",
|
||
|
|
url: setter.baseurl + "adminapi/GameConfig/PropList",
|
||
|
|
async: false,
|
||
|
|
done: function (res) {
|
||
|
|
if (res.code === 0 && res.data) propList = res.data;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPropInfo(otherId) {
|
||
|
|
return propList.find(function(p) { return p.number === otherId; });
|
||
|
|
}
|
||
|
|
|
||
|
|
function getTypeName(type) {
|
||
|
|
var typeNames = {
|
||
|
|
1: '炮台', 2: '翅膀', 3: '炮塔碎片', 4: '翅膀碎片', 5: '战神',
|
||
|
|
6: '战神碎片', 7: '刮刮卡', 8: '改名卡', 9: '大喇叭', 10: '技能',
|
||
|
|
11: '召唤卡', 12: 'VIP经验', 13: '鱼雷'
|
||
|
|
};
|
||
|
|
return typeNames[type] || '其他';
|
||
|
|
}
|
||
|
|
|
||
|
|
function loadConfig() {
|
||
|
|
admin.req({
|
||
|
|
method: "get",
|
||
|
|
url: setter.baseurl + "adminapi/ActivityConfig",
|
||
|
|
done: function (res) {
|
||
|
|
activityConfig = (res.code === 0 && res.data) ? res.data : {};
|
||
|
|
renderGroups();
|
||
|
|
},
|
||
|
|
fail: function () { activityConfig = {}; renderGroups(); }
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderGroups() {
|
||
|
|
if (!activityConfig) activityConfig = {};
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { isEnabled: false, isMaintaining: false, maintainingMessage: '', groups: [] };
|
||
|
|
$('#form-ranking input[name="isEnabled"]').prop('checked', cfg.isEnabled);
|
||
|
|
$('#form-ranking input[name="isMaintaining"]').prop('checked', cfg.isMaintaining);
|
||
|
|
$('#form-ranking input[name="maintainingMessage"]').val(cfg.maintainingMessage || '当前排行榜正在维护中,请稍后再试');
|
||
|
|
form.render();
|
||
|
|
|
||
|
|
var html = '';
|
||
|
|
var groups = cfg.groups && cfg.groups.length > 0 ? cfg.groups : getDefaultGroups();
|
||
|
|
for (var gi = 0; gi < groups.length; gi++) {
|
||
|
|
var g = groups[gi];
|
||
|
|
html += '<fieldset class="layui-elem-field"><legend>' + (g.name || RANKING_NAMES[g.rankingType] || '排行榜') + '</legend>';
|
||
|
|
html += '<div class="layui-field-box">';
|
||
|
|
html += '<table class="rank-table"><thead><tr>';
|
||
|
|
html += '<th style="width:40px">启用</th><th>排名</th><th>金币</th><th>钻石</th><th>道具</th><th style="width:40px">操作</th>';
|
||
|
|
html += '</tr></thead><tbody id="tbody-' + gi + '">';
|
||
|
|
var rewards = g.rewards && g.rewards.length > 0 ? g.rewards : [];
|
||
|
|
for (var ri = 0; ri < rewards.length; ri++) {
|
||
|
|
html += renderRow(gi, ri, rewards[ri]);
|
||
|
|
}
|
||
|
|
html += '</tbody></table>';
|
||
|
|
html += '<button class="layui-btn layui-btn-xs layui-btn-normal" onclick="addRow(' + gi + ')"><i class="layui-icon layui-icon-add-1"></i> 新增排名</button>';
|
||
|
|
html += '</div></fieldset><br>';
|
||
|
|
}
|
||
|
|
$('#groups-container').html(html);
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderRow(gi, ri, r) {
|
||
|
|
if (!r) r = { rankMin: ri + 1, rankMax: ri + 1, gold: 0, diamond: 0, items: [], enabled: true };
|
||
|
|
var rankLabel = r.rankMin === r.rankMax ? '第' + r.rankMin + '名' : '第' + r.rankMin + '-' + r.rankMax + '名';
|
||
|
|
var itemsStr = '';
|
||
|
|
if (r.items) {
|
||
|
|
itemsStr = r.items.map(function (it) {
|
||
|
|
var prop = getPropInfo(it.otherId);
|
||
|
|
var imgHtml = prop ? '<img src="' + (prop.imageUrl || '/uploads/' + prop.number + '.png') + '" style="width:20px;height:20px;vertical-align:middle;margin-right:3px;">' : '';
|
||
|
|
var name = prop ? prop.name : (it.otherId || '');
|
||
|
|
return imgHtml + name + 'x' + (it.count || 0);
|
||
|
|
}).join(' ');
|
||
|
|
}
|
||
|
|
var checked = r.enabled !== false ? 'checked' : '';
|
||
|
|
return '<tr>' +
|
||
|
|
'<td><input type="checkbox" lay-filter="row-switch" data-gi="' + gi + '" data-ri="' + ri + '" ' + checked + ' lay-skin="switch" lay-text="开|关"></td>' +
|
||
|
|
'<td><input type="text" class="layui-input" style="width:70px" data-gi="' + gi + '" data-ri="' + ri + '" data-field="rankLabel" value="' + rankLabel + '"></td>' +
|
||
|
|
'<td><input type="number" class="layui-input" style="width:80px" data-gi="' + gi + '" data-ri="' + ri + '" data-field="gold" value="' + (r.gold || 0) + '"></td>' +
|
||
|
|
'<td><input type="number" class="layui-input" style="width:80px" data-gi="' + gi + '" data-ri="' + ri + '" data-field="diamond" value="' + (r.diamond || 0) + '"></td>' +
|
||
|
|
'<td><span class="item-btn" onclick="openItemsDialog(' + gi + ',' + ri + ')">' + (itemsStr || '点击设置') + '</span></td>' +
|
||
|
|
'<td><span class="del-row" onclick="removeRow(' + gi + ',' + ri + ')"><i class="layui-icon layui-icon-delete"></i></span></td>' +
|
||
|
|
'</tr>';
|
||
|
|
}
|
||
|
|
|
||
|
|
// 每次操作前, 将 DOM 中的 gold/diamond/rankLabel 同步回 config 缓存
|
||
|
|
function syncDomToConfig() {
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { groups: [] };
|
||
|
|
$('#groups-container fieldset').each(function (gi) {
|
||
|
|
if (!cfg.groups[gi]) return;
|
||
|
|
$(this).find('table tbody tr').each(function (ri) {
|
||
|
|
if (!cfg.groups[gi].rewards[ri]) return;
|
||
|
|
var rankLabel = $(this).find('input[data-field="rankLabel"]').val() || ('第' + (ri + 1) + '名');
|
||
|
|
var parsed = parseRankLabel(rankLabel);
|
||
|
|
cfg.groups[gi].rewards[ri].rankMin = parsed.rankMin;
|
||
|
|
cfg.groups[gi].rewards[ri].rankMax = parsed.rankMax;
|
||
|
|
cfg.groups[gi].rewards[ri].gold = parseInt($(this).find('input[data-field="gold"]').val()) || 0;
|
||
|
|
cfg.groups[gi].rewards[ri].diamond = parseInt($(this).find('input[data-field="diamond"]').val()) || 0;
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
window.addRow = function (gi) {
|
||
|
|
syncDomToConfig();
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { groups: [] };
|
||
|
|
if (!cfg.groups[gi]) cfg.groups[gi] = { rankingType: gi + 1, name: RANKING_NAMES[gi + 1] || '', rewards: [] };
|
||
|
|
var ri = cfg.groups[gi].rewards.length;
|
||
|
|
cfg.groups[gi].rewards.push({ rankMin: ri + 1, rankMax: ri + 1, gold: 0, diamond: 0, items: [], enabled: true });
|
||
|
|
renderGroups();
|
||
|
|
};
|
||
|
|
|
||
|
|
window.removeRow = function (gi, ri) {
|
||
|
|
layer.confirm('确定删除该排名奖励?', function (idx) {
|
||
|
|
layer.close(idx);
|
||
|
|
syncDomToConfig();
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { groups: [] };
|
||
|
|
if (cfg.groups[gi] && cfg.groups[gi].rewards) {
|
||
|
|
cfg.groups[gi].rewards.splice(ri, 1);
|
||
|
|
renderGroups();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
|
||
|
|
window.openItemsDialog = function (gi, ri) {
|
||
|
|
ITEMS_CTX = { gi: gi, ri: ri };
|
||
|
|
var tr = document.querySelector('#tbody-' + gi + ' tr:nth-child(' + (ri + 1) + ')');
|
||
|
|
var rewards = getGroupRewards(gi);
|
||
|
|
var items = (rewards[ri] && rewards[ri].items) ? JSON.parse(JSON.stringify(rewards[ri].items)) : [];
|
||
|
|
|
||
|
|
var html = '<div style="padding:15px;max-height:400px;overflow-y:auto;">';
|
||
|
|
html += '<div id="items-list">';
|
||
|
|
if (items.length === 0) {
|
||
|
|
html += '<div class="items-empty" style="color:#999;">暂无道具,点击下方按钮添加</div>';
|
||
|
|
} else {
|
||
|
|
for (var i = 0; i < items.length; i++) {
|
||
|
|
html += renderItemRow(i, items[i]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
html += '</div>';
|
||
|
|
html += '<button type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-add-item-row" style="margin-top:10px;"><i class="layui-icon layui-icon-add-1"></i> 添加道具</button>';
|
||
|
|
html += '</div>';
|
||
|
|
|
||
|
|
layer.open({
|
||
|
|
type: 1,
|
||
|
|
title: '编辑道具',
|
||
|
|
area: ['500px', '450px'],
|
||
|
|
content: html,
|
||
|
|
btn: ['确定', '取消'],
|
||
|
|
success: function (layero) {
|
||
|
|
layero.on('click', '.btn-add-item-row', function () {
|
||
|
|
addItemRow(layero);
|
||
|
|
});
|
||
|
|
layero.on('click', '.btn-remove-item-row', function () {
|
||
|
|
$(this).closest('.prop-row').remove();
|
||
|
|
if (layero.find('#items-list .prop-row').length === 0) {
|
||
|
|
layero.find('#items-list').html('<div class="items-empty" style="color:#999;">暂无道具,点击下方按钮添加</div>');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
form.render('select');
|
||
|
|
},
|
||
|
|
yes: function (idx, layero) {
|
||
|
|
var newItems = collectItems(layero);
|
||
|
|
saveItemsToReward(gi, ri, newItems);
|
||
|
|
layer.close(idx);
|
||
|
|
renderGroups();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
|
||
|
|
function renderItemRow(i, item) {
|
||
|
|
var selectHtml = '<select class="layui-input item-prop" style="width:140px;height:32px;">';
|
||
|
|
selectHtml += '<option value="">无</option>';
|
||
|
|
var groups = {};
|
||
|
|
propList.forEach(function(p) {
|
||
|
|
var typeName = getTypeName(p.type);
|
||
|
|
if (!groups[typeName]) groups[typeName] = [];
|
||
|
|
groups[typeName].push(p);
|
||
|
|
});
|
||
|
|
for (var typeName in groups) {
|
||
|
|
selectHtml += '<optgroup label="' + typeName + '">';
|
||
|
|
groups[typeName].forEach(function(p) {
|
||
|
|
var selected = p.number === item.otherId ? ' selected' : '';
|
||
|
|
selectHtml += '<option value="' + p.number + '"' + selected + '>' + p.name + '</option>';
|
||
|
|
});
|
||
|
|
selectHtml += '</optgroup>';
|
||
|
|
}
|
||
|
|
selectHtml += '</select>';
|
||
|
|
var prop = getPropInfo(item.otherId);
|
||
|
|
var imgSrc = prop ? (prop.imageUrl || '/uploads/' + prop.number + '.png') : '';
|
||
|
|
var imgHtml = '<img class="prop-preview" src="' + imgSrc + '" style="width:32px;height:32px;vertical-align:middle;margin:0 4px;' + (prop ? '' : 'display:none;') + '">';
|
||
|
|
return '<div class="prop-row">' +
|
||
|
|
selectHtml +
|
||
|
|
imgHtml +
|
||
|
|
'<span>x</span>' +
|
||
|
|
'<input class="layui-input item-count" type="number" value="' + (item.count || 1) + '" style="width:60px;height:32px;">' +
|
||
|
|
'<span class="del-row btn-remove-item-row" style="margin-left:6px;"><i class="layui-icon layui-icon-delete"></i></span>' +
|
||
|
|
'</div>';
|
||
|
|
}
|
||
|
|
|
||
|
|
function addItemRow(layero) {
|
||
|
|
var list = layero.find('#items-list')[0];
|
||
|
|
layero.find('#items-list .items-empty').remove();
|
||
|
|
var i = layero.find('#items-list .prop-row').length;
|
||
|
|
var div = document.createElement('div');
|
||
|
|
div.innerHTML = renderItemRow(i, { otherId: '', count: 1 });
|
||
|
|
list.appendChild(div.firstElementChild);
|
||
|
|
form.render('select');
|
||
|
|
}
|
||
|
|
|
||
|
|
function collectItems(layero) {
|
||
|
|
var items = [];
|
||
|
|
layero.find('#items-list .prop-row').each(function () {
|
||
|
|
var row = this;
|
||
|
|
var otherId = row.querySelector('.item-prop').value.trim();
|
||
|
|
var count = parseInt(row.querySelector('.item-count').value) || 1;
|
||
|
|
if (otherId) items.push({ otherId: otherId, count: count });
|
||
|
|
});
|
||
|
|
return items;
|
||
|
|
}
|
||
|
|
|
||
|
|
function saveItemsToReward(gi, ri, items) {
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { groups: [] };
|
||
|
|
if (!cfg.groups[gi]) cfg.groups[gi] = { rankingType: gi + 1, name: RANKING_NAMES[gi + 1] || '', rewards: [] };
|
||
|
|
if (!cfg.groups[gi].rewards[ri]) cfg.groups[gi].rewards[ri] = { rankMin: ri + 1, rankMax: ri + 1, gold: 0, diamond: 0, items: [] };
|
||
|
|
cfg.groups[gi].rewards[ri].items = items;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 道具选择变更时更新图片预览
|
||
|
|
$(document).on('change', '.item-prop', function() {
|
||
|
|
var val = $(this).val();
|
||
|
|
var $img = $(this).next('.prop-preview');
|
||
|
|
if (val) {
|
||
|
|
var prop = getPropInfo(val);
|
||
|
|
if (prop) {
|
||
|
|
$img.attr('src', prop.imageUrl || '/uploads/' + prop.number + '.png').show();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$img.hide();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
function getGroupRewards(gi) {
|
||
|
|
var cfg = activityConfig.rankingRewardConfig || { groups: [] };
|
||
|
|
if (!cfg.groups[gi]) cfg.groups[gi] = { rankingType: gi + 1, name: RANKING_NAMES[gi + 1] || '', rewards: [] };
|
||
|
|
return cfg.groups[gi].rewards;
|
||
|
|
}
|
||
|
|
|
||
|
|
function parseRankLabel(str) {
|
||
|
|
// "第1名" / "第1-3名" / "第1名" → { rankMin, rankMax }
|
||
|
|
str = str.replace(/[第名\s]/g, '');
|
||
|
|
var parts = str.split('-');
|
||
|
|
return { rankMin: parseInt(parts[0]) || 1, rankMax: parseInt(parts[1]) || parseInt(parts[0]) || 1 };
|
||
|
|
}
|
||
|
|
|
||
|
|
function getDefaultGroups() {
|
||
|
|
return [
|
||
|
|
{ rankingType: 1, name: '金币达人榜', rewards: getDefaultRewards() },
|
||
|
|
{ rankingType: 2, name: '等级达人榜', rewards: getDefaultRewards() },
|
||
|
|
{ rankingType: 3, name: '当日积分榜', rewards: getDefaultRewards() }
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
function getDefaultRewards() {
|
||
|
|
return [
|
||
|
|
{ rankMin: 1, rankMax: 1, gold: 65000, diamond: 50, items: [{ otherId: '40004', count: 10 }, { otherId: '40003', count: 10 }], enabled: true },
|
||
|
|
{ rankMin: 2, rankMax: 2, gold: 45000, diamond: 50, items: [{ otherId: '40004', count: 10 }, { otherId: '40003', count: 10 }], enabled: true },
|
||
|
|
{ rankMin: 3, rankMax: 3, gold: 30000, diamond: 50, items: [{ otherId: '40004', count: 10 }, { otherId: '40003', count: 10 }], enabled: true },
|
||
|
|
{ rankMin: 4, rankMax: 4, gold: 20000, diamond: 50, items: [{ otherId: '40004', count: 8 }, { otherId: '40003', count: 8 }], enabled: true },
|
||
|
|
{ rankMin: 5, rankMax: 5, gold: 15000, diamond: 50, items: [{ otherId: '40004', count: 8 }, { otherId: '40003', count: 8 }], enabled: true },
|
||
|
|
{ rankMin: 6, rankMax: 6, gold: 12000, diamond: 30, items: [{ otherId: '40004', count: 8 }, { otherId: '40003', count: 8 }], enabled: true },
|
||
|
|
{ rankMin: 7, rankMax: 7, gold: 10000, diamond: 30, items: [{ otherId: '40004', count: 6 }, { otherId: '40003', count: 6 }], enabled: true },
|
||
|
|
{ rankMin: 8, rankMax: 8, gold: 8000, diamond: 30, items: [{ otherId: '40004', count: 6 }, { otherId: '40003', count: 6 }], enabled: true },
|
||
|
|
{ rankMin: 9, rankMax: 9, gold: 6000, diamond: 30, items: [{ otherId: '40004', count: 6 }, { otherId: '40003', count: 6 }], enabled: true },
|
||
|
|
{ rankMin: 10, rankMax: 10, gold: 5000, diamond: 30, items: [{ otherId: '40004', count: 5 }, { otherId: '40003', count: 5 }], enabled: true },
|
||
|
|
{ rankMin: 11, rankMax: 11, gold: 3000, diamond: 20, items: [{ otherId: '40004', count: 5 }, { otherId: '40003', count: 5 }], enabled: true },
|
||
|
|
{ rankMin: 12, rankMax: 12, gold: 2000, diamond: 20, items: [{ otherId: '40004', count: 5 }, { otherId: '40003', count: 5 }], enabled: true },
|
||
|
|
{ rankMin: 13, rankMax: 13, gold: 1500, diamond: 20, items: [{ otherId: '40004', count: 3 }, { otherId: '40003', count: 3 }], enabled: true },
|
||
|
|
{ rankMin: 14, rankMax: 14, gold: 1200, diamond: 20, items: [{ otherId: '40004', count: 3 }, { otherId: '40003', count: 3 }], enabled: true },
|
||
|
|
{ rankMin: 15, rankMax: 15, gold: 1000, diamond: 20, items: [{ otherId: '40004', count: 3 }, { otherId: '40003', count: 3 }], enabled: true }
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
$(document).on('click', '[lay-filter="reload-ranking"]', function () { loadConfig(); layer.msg('刷新成功'); });
|
||
|
|
|
||
|
|
$(document).on('click', '[lay-filter="init-ranking"]', function () {
|
||
|
|
layer.confirm('确定要初始化排行榜奖励配置吗?', function (idx) {
|
||
|
|
layer.close(idx);
|
||
|
|
if (!activityConfig.rankingRewardConfig) activityConfig.rankingRewardConfig = {};
|
||
|
|
var cfg = activityConfig.rankingRewardConfig;
|
||
|
|
cfg.isEnabled = true;
|
||
|
|
cfg.isMaintaining = false;
|
||
|
|
cfg.maintainingMessage = '当前排行榜正在维护中,请稍后再试';
|
||
|
|
cfg.groups = [
|
||
|
|
{ rankingType: 1, name: '金币达人榜', rewards: getDefaultRewards() },
|
||
|
|
{ rankingType: 2, name: '等级达人榜', rewards: getDefaultRewards() },
|
||
|
|
{ rankingType: 3, name: '当日积分榜', rewards: getDefaultRewards() }
|
||
|
|
];
|
||
|
|
admin.req({
|
||
|
|
method: "post",
|
||
|
|
contentType: "application/json;charset=UTF-8",
|
||
|
|
url: setter.baseurl + "adminapi/ActivityConfig/Update",
|
||
|
|
data: JSON.stringify(activityConfig),
|
||
|
|
done: function (res) {
|
||
|
|
if (res.code === 0 || res.code === 200) { layer.msg('初始化成功'); loadConfig(); }
|
||
|
|
else { layer.msg(res.info || '初始化失败'); }
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
$(document).on('click', '[lay-filter="save-ranking"]', function () {
|
||
|
|
if (!activityConfig.rankingRewardConfig) activityConfig.rankingRewardConfig = {};
|
||
|
|
var cfg = activityConfig.rankingRewardConfig;
|
||
|
|
cfg.isEnabled = $('#form-ranking input[name="isEnabled"]').prop('checked');
|
||
|
|
cfg.isMaintaining = $('#form-ranking input[name="isMaintaining"]').prop('checked');
|
||
|
|
cfg.maintainingMessage = $('#form-ranking input[name="maintainingMessage"]').val() || '当前排行榜正在维护中,请稍后再试';
|
||
|
|
|
||
|
|
var groups = [];
|
||
|
|
$('#groups-container fieldset').each(function (gi) {
|
||
|
|
var name = $(this).find('legend').text();
|
||
|
|
var rewards = [];
|
||
|
|
$(this).find('table tbody tr').each(function (ri) {
|
||
|
|
var enabled = $(this).find('input[type="checkbox"]').first().prop('checked');
|
||
|
|
if (!enabled) return;
|
||
|
|
|
||
|
|
var rankLabel = $(this).find('input[data-field="rankLabel"]').val() || ('第' + (ri + 1) + '名');
|
||
|
|
var parsed = parseRankLabel(rankLabel);
|
||
|
|
var gold = parseInt($(this).find('input[data-field="gold"]').val()) || 0;
|
||
|
|
var diamond = parseInt($(this).find('input[data-field="diamond"]').val()) || 0;
|
||
|
|
// 从 config 缓存取道具数据
|
||
|
|
var items = [];
|
||
|
|
if (cfg.groups && cfg.groups[gi] && cfg.groups[gi].rewards && cfg.groups[gi].rewards[ri]) {
|
||
|
|
items = cfg.groups[gi].rewards[ri].items || [];
|
||
|
|
}
|
||
|
|
rewards.push({ rankMin: parsed.rankMin, rankMax: parsed.rankMax, gold: gold, diamond: diamond, items: items, enabled: true });
|
||
|
|
});
|
||
|
|
groups.push({ rankingType: gi + 1, name: name, rewards: rewards });
|
||
|
|
});
|
||
|
|
cfg.groups = groups;
|
||
|
|
|
||
|
|
admin.req({
|
||
|
|
method: "post",
|
||
|
|
contentType: "application/json;charset=UTF-8",
|
||
|
|
url: setter.baseurl + "adminapi/ActivityConfig/Update",
|
||
|
|
data: JSON.stringify(activityConfig),
|
||
|
|
done: function (res) {
|
||
|
|
if (res.code === 0 || res.code === 200) { layer.msg('保存成功'); loadConfig(); }
|
||
|
|
else { layer.msg(res.info || '保存失败'); }
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
loadPropList();
|
||
|
|
loadConfig();
|
||
|
|
});
|
||
|
|
</script>
|