Files
Nsfocus_test_ai_project/static/html/list.html
T
2022-02-13 12:47:30 +08:00

215 lines
8.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>思维导图列表</title>
<link rel="shortcut icon" href="/static/favicon.ico"/>
<link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" media="all">
<script src="/static/layui-v2.6.8/layui/layui.js"></script>
<script src="/static/js/jquery-1.11.3.min.js"></script>
<script>
let layer //弹层
, laypage //分页
, laydate //日期
, table //表格
, carousel //轮播
, upload //上传
, element //元素操作
, slider //滑块
, dropdown //下拉菜单
//加载模块
layui.use(function () { //亦可加载特定模块:layui.use(['layer', 'laydate', function(){
//得到各种内置组件
layer = layui.layer //弹层
, laypage = layui.laypage //分页
, laydate = layui.laydate //日期
, table = layui.table //表格
, carousel = layui.carousel //轮播
, upload = layui.upload //上传
, element = layui.element //元素操作
, slider = layui.slider //滑块
, dropdown = layui.dropdown //下拉菜单
});
// 定义function
const listView = function (options) {
// 当前页
this.current_page = 1
// 每页条数
this.limit = 50
this.options = options
this.opts = {"h": 'oo'}
}
listView.prototype = {
init: function () {
this.merge_obj(this.opts, this.options)
},
// 获取数据
fetch_data: function () {
const get_param = {'page': this.current_page, 'page_size': this.limit}
if (this.get_coop_mind_name()) {
get_param.coop_mind_name = this.get_coop_mind_name()
}
$.get('list', get_param, function (resp) {
console.log(resp)
$('#layui-table tbody').empty()
const results = resp.results
results.forEach(item => {
const tr = `<tr>
<td>${item.coop_mind_name}</td>
<td>${item.creator}</td>
<td>${item.create_time}</td>
<td>${item.update_time}</td>
<td></td>
</tr>`
$('#layui-table tbody').append(tr)
})
})
// 分页组件
this.auto_page_bar()
},
get_coop_mind_name: function () {
return $('#mind_name').val()
},
// 显示分页组件
auto_page_bar: function () {
const me = this
//执行一个laypage实例
laypage.render({
elem: me.opts.page_bar_elem //注意,这里的 test1 是 ID,不用加 # 号
, count: 50 //数据总数,从服务端得到
, limit: me.limit // 每页显示的条数。
});
},
// 合并属性
merge_obj: function (target, src) {
for (let o in src) {
if (o in target) {
if (typeof target[o] === 'object' && Object.prototype.toString.call(target[o]).toLowerCase() === '[object object]' && !target[o].length) {
this.merge(target[o], src[o]);
} else {
target[o] = src[o];
}
} else {
target[o] = src[o];
}
}
return target;
},
json2string: function (json) {
if (!!JSON) {
try {
return JSON.stringify(json);
} catch (e) {
logger.warn(e);
logger.warn('can not convert to string');
return null;
}
}
}
}
$(function () {
// 初始化对象
const view = new listView({'page_bar_elem': 'page_bar'})
view.init()
view.fetch_data()
// 绑定事件
$('#c_').click(function () {
const mind_name = $('#mind_name').val()
if (mind_name) {
const snapshot_data = {
id: 'root',
topic: 'jsMind',
children: [
{
id: 'easy',
topic: 'Easy',
direction: 'left',
expanded: false,
children: [
{id: 'easy1', topic: 'Easy to show'},
{id: 'easy2', topic: 'Easy to edit'},
{id: 'easy3', topic: 'Easy to store'},
{id: 'easy4', topic: 'Easy to embed'}
]
},
{
id: 'open',
topic: 'Open Source',
direction: 'right',
expanded: true,
children: [
{id: 'open1', topic: 'on GitHub'},
{id: 'open2', topic: 'BSD License'}
]
},
{
id: 'powerful',
topic: 'Powerful',
direction: 'right',
children: [
{id: 'powerful1', topic: 'Base on Javascript'},
{id: 'powerful2', topic: 'Base on HTML5'},
{id: 'powerful3', topic: 'Depends on you'}
]
},
{
id: 'other',
topic: 'test node',
direction: 'left',
children: [
{id: 'other1', topic: "I'm from local variable"},
{id: 'other2', topic: 'I can do everything'}
]
}
]
}
$.post('create', {'mind_name': mind_name, 'snapshot_data': view.json2string(snapshot_data)}, function (resp) {
console.log(resp)
view.fetch_data()
})
} else {
layer.msg('请输入导图名称')
}
})
})
</script>
</head>
<body>
<div style="margin-top: 5px;">
<div class="layui-input-inline">
<input name="mind_name" required lay-verify="required" autocomplete="off" class="layui-input" id="mind_name" value="pp">
</div>
<button type="button" class="layui-btn" id="c_">创建导图</button>
<button type="button" class="layui-btn">搜索</button>
</div>
<table class="layui-table" id="layui-table">
<colgroup>
<col width="500">
<col width="100">
<col width="300">
<col width="300">
<col>
</colgroup>
<thead>
<tr>
<th>名称</th>
<th>创建人</th>
<th>创建时间</th>
<th>更新时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="page_bar"></div>
</body>
</html>