chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<div class="uc-wrap">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">任务中心</div>
|
||||
<div class="layui-card-body" pad15>
|
||||
<div class="task-list" id="taskList">
|
||||
<div class="task-empty" id="taskEmpty" style="display:none;color:#999;padding:20px 0;text-align:center;">暂无进行中的任务</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
layui.use(['http', 'layer', 'jquery'], function () {
|
||||
var http = layui.http, layer = layui.layer, $ = layui.jquery;
|
||||
|
||||
function render(list) {
|
||||
var box = $('#taskList'), html = '';
|
||||
if (!list || !list.length) {
|
||||
$('#taskEmpty').show();
|
||||
return;
|
||||
}
|
||||
$('#taskEmpty').hide();
|
||||
list.forEach(function (t) {
|
||||
var reward = '';
|
||||
if (t.reward_type == 1) {
|
||||
reward = '<span class="task-reward score">' + t.reward_num + ' 积分</span>';
|
||||
} else if (t.reward_type == 2) {
|
||||
reward = '<span class="task-reward coin">' + t.reward_num + ' 金币</span>';
|
||||
} else if (t.reward_type == 3) {
|
||||
reward = '<span class="task-reward prop">道具 #' + t.reward_num + '</span>';
|
||||
}
|
||||
var btn = t.claimed
|
||||
? '<button class="layui-btn layui-btn-disabled layui-btn-xs" disabled>已领取</button>'
|
||||
: '<button class="layui-btn layui-btn-xs task-claim" data-id="' + t.id + '">领取奖励</button>';
|
||||
html += ''
|
||||
+ '<div class="task-item">'
|
||||
+ '<div class="task-main">'
|
||||
+ '<div class="task-title">' + t.title + '</div>'
|
||||
+ '<div class="task-desc">' + (t.description || '') + '</div>'
|
||||
+ '</div>'
|
||||
+ '<div class="task-side">'
|
||||
+ '<div class="task-reward-box">' + reward + '</div>'
|
||||
+ btn
|
||||
+ '</div>'
|
||||
+ '</div>';
|
||||
});
|
||||
box.html(html);
|
||||
}
|
||||
|
||||
http.get('list').then(function (res) {
|
||||
if (res.code === 0) {
|
||||
render(res.data || []);
|
||||
} else {
|
||||
layer.msg(res.message || '加载失败', { icon: 2 });
|
||||
}
|
||||
}).catch(function () {
|
||||
layer.msg('加载失败', { icon: 2 });
|
||||
});
|
||||
|
||||
$('#taskList').on('click', '.task-claim', function () {
|
||||
var id = $(this).data('id'), $btn = $(this);
|
||||
$btn.attr('disabled', true);
|
||||
http.post('claim', { task_id: id }).then(function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.message || '领取成功', { icon: 1 });
|
||||
$btn.parent().find('.task-claim').removeClass('task-claim').addClass('layui-btn-disabled').text('已领取');
|
||||
http.get('list').then(function (r) {
|
||||
if (r.code === 0) { render(r.data || []); }
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.message || '领取失败', { icon: 2 });
|
||||
$btn.attr('disabled', false);
|
||||
}
|
||||
}).catch(function () {
|
||||
layer.msg('请求失败', { icon: 2 });
|
||||
$btn.attr('disabled', false);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.task-item { display:flex; align-items:center; justify-content:space-between; padding:14px 4px; border-bottom:1px solid #f0f0f0; }
|
||||
.task-item:last-child { border-bottom:none; }
|
||||
.task-main { flex:1; padding-right:16px; }
|
||||
.task-title { font-size:15px; font-weight:600; color:#333; }
|
||||
.task-desc { font-size:13px; color:#888; margin-top:4px; line-height:1.5; }
|
||||
.task-side { text-align:right; min-width:120px; }
|
||||
.task-reward-box { margin-bottom:8px; }
|
||||
.task-reward { display:inline-block; padding:2px 10px; border-radius:12px; font-size:12px; }
|
||||
.task-reward.score { background:#e6f0ff; color:#1e6fff; }
|
||||
.task-reward.coin { background:#fff3e0; color:#ff8c00; }
|
||||
.task-reward.prop { background:#e8f8ee; color:#1aab5b; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user