修改添加题目功能
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
{include file="public/header" /}
|
||||
<div class="config-container">
|
||||
<!-- 页面头部样式 -->
|
||||
<div class="config-header" style="display: flex;flex-direction: column;flex-wrap: wrap;align-items: flex-start;">
|
||||
<div class="maintitle">
|
||||
<i class="layui-icon layui-icon-form"></i>
|
||||
<span>题目列表</span>
|
||||
</div>
|
||||
<div style="display: flex;align-items: flex-start;flex-direction: column;gap: 15px;margin-bottom: 10px;">
|
||||
<div class="shaixuan">
|
||||
<label>筛选:</label>
|
||||
<div class="layui-form" style="display: flex; gap: 10px;">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="nameSearch" placeholder="搜索题目内容" class="layui-input">
|
||||
</div>
|
||||
<button type="button" class="layui-btn layui-btn-normal" onclick="doSearch()">
|
||||
<i class="layui-icon layui-icon-search"></i>搜索
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="doRefresh()">
|
||||
<i class="layui-icon layui-icon-refresh"></i>重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-normal" onclick="add()">
|
||||
<i class="layui-icon layui-icon-add-1"></i>添加题目
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="refresh()">
|
||||
<i class="layui-icon layui-icon-refresh"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="topicTable" lay-filter="topicTable"></table>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="questionTypeTemplate">
|
||||
{{#
|
||||
var typeText = '';
|
||||
switch(d.question_type){
|
||||
case 1: typeText = '单选'; break;
|
||||
case 2: typeText = '多选'; break;
|
||||
case 3: typeText = '判断'; break;
|
||||
case 4: typeText = '填空'; break;
|
||||
case 5: typeText = '简答'; break;
|
||||
case 6: typeText = '编程'; break;
|
||||
default: typeText = '未知';
|
||||
}
|
||||
}}
|
||||
{{ typeText }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="difficultyTemplate">
|
||||
{{#
|
||||
var stars = '';
|
||||
for(var i=1; i<=5; i++){
|
||||
stars += i <= d.difficulty ? '★' : '☆';
|
||||
}
|
||||
}}
|
||||
{{ stars }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="operationBar">
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
|
||||
<i class="layui-icon layui-icon-edit"></i>编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'form', 'table'], function () {
|
||||
var layer = layui.layer;
|
||||
var $ = layui.jquery;
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
|
||||
// 初始化表格
|
||||
table.render({
|
||||
elem: '#resourceTable',
|
||||
url: '/admin/resources/lists',
|
||||
method: 'get',
|
||||
cols: [[
|
||||
{ field: 'id', title: 'ID' },
|
||||
{ field: 'question_type', title: '题型' },
|
||||
{ field: 'subject_id', title: '科目' },
|
||||
{ field: 'knowledge_point_id', title: '知识点' },
|
||||
{ field: 'difficulty', title: '难度' },
|
||||
{ field: 'is_deleted', title: '状态' },
|
||||
{ title: '操作', toolbar: '#operationBar' }
|
||||
]],
|
||||
page: true,
|
||||
limit: 10,
|
||||
limits: [10, 50, 100],
|
||||
//height: 'full-220'
|
||||
});
|
||||
|
||||
// 监听工具条事件
|
||||
table.on('tool(topicTable)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') {
|
||||
edit(data.id);
|
||||
} else if (obj.event === 'del') {
|
||||
del(data.id);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听分类筛选变化
|
||||
form.on('select(categoryFilter)', function (data) {
|
||||
filterByCategory(data.value);
|
||||
});
|
||||
});
|
||||
|
||||
function filterByCategory(categoryId) {
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function doSearch() {
|
||||
var nameKeyword = $('#nameSearch').val().trim();
|
||||
|
||||
if (!nameKeyword && !$('#categoryFilter').val()) {
|
||||
layer.msg('请输入搜索条件', { icon: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function doRefresh() {
|
||||
// 清空搜索条件
|
||||
$('#nameSearch').val('');
|
||||
$('#categoryFilter').val('');
|
||||
layui.form.render('select'); // 重新渲染select
|
||||
|
||||
// 重新加载表格,不带任何筛选条件
|
||||
layui.table.reload('topicTable', {
|
||||
where: {},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
|
||||
layer.msg('已重置', { icon: 1 });
|
||||
}
|
||||
|
||||
function reloadTable() {
|
||||
var categoryId = $('#categoryFilter').val();
|
||||
var categoryName = '';
|
||||
if (categoryId) {
|
||||
var selectedOption = $('#categoryFilter option[value="' + categoryId + '"]');
|
||||
if (selectedOption.length > 0) {
|
||||
categoryName = selectedOption.text().trim();
|
||||
}
|
||||
}
|
||||
var nameKeyword = $('#nameSearch').val().trim();
|
||||
|
||||
layui.table.reload('topicTable', {
|
||||
where: {
|
||||
category: categoryName,
|
||||
name: nameKeyword
|
||||
},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function add() {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '添加题目',
|
||||
area: ['800px', '700px'], // 宽度800px,高度100%
|
||||
shadeClose: true, // 点击遮罩关闭
|
||||
content: '/admin/tk/topicadd'
|
||||
});
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '/admin/tk/topicedit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该题目吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('/admin/tk/topicdelete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
layui.table.reload('topicTable');
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
layui.table.reload('topicTable');
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user