mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
#70 fix 新建按钮
This commit is contained in:
parent
771f273546
commit
e580345063
@ -119,7 +119,7 @@
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form();
|
||||
form.on('submit(save)', function (data) {
|
||||
let field = data.field;
|
||||
var field = data.field;
|
||||
|
||||
var submitFinish = function (err, bot) {
|
||||
if (err) {
|
||||
|
@ -35,95 +35,92 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form()
|
||||
function request(path, data) {
|
||||
var postfix = '/api/';
|
||||
var payload = {
|
||||
url: postfix + path,
|
||||
method: 'POST',
|
||||
contentType: 'application/json;charset=UTF-8',
|
||||
headers: {
|
||||
authorization: $.cookie('authorization')
|
||||
},
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(data)
|
||||
};
|
||||
return new Promise(function (resolve, reject) {
|
||||
$.ajax(payload)
|
||||
.done(function (data) {
|
||||
console.log('Rest api 返回的值:', data);
|
||||
if (data.rc == 0) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
reject(data.error);
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR, textStatus) {
|
||||
console.error('Rest api 返回error:', jqXHR);
|
||||
reject(textStatus)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function request(path, data) {
|
||||
var postfix = '/api/';
|
||||
var payload = {
|
||||
url: postfix + path,
|
||||
method: 'POST',
|
||||
contentType: 'application/json;charset=UTF-8',
|
||||
headers: {
|
||||
authorization: $.cookie('authorization')
|
||||
},
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(data)
|
||||
};
|
||||
return new Promise(function (resolve, reject) {
|
||||
$.ajax(payload)
|
||||
.done(function (data) {
|
||||
console.log('Rest api 返回的值:', data);
|
||||
if (data.rc == 0) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
reject(data.error);
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR, textStatus) {
|
||||
console.error('Rest api 返回error:', jqXHR);
|
||||
reject(textStatus)
|
||||
function query(p, ps) {
|
||||
request('chatbot?p=' + (p || 1) + '&ps=' + (ps || 10), { ops: 'fetch' }).then(function (rows) {
|
||||
var tds = $.map(rows, function (r) {
|
||||
var edit = $('<a href="edit.html?id=' + r.id + '" data-width="550" data-height="300"><i class="layui-icon"></i>编辑</a>');
|
||||
|
||||
var remove = $('<a style="margin-left:10px;"><i class="layui-icon" style="color:red;">ဆ</i>删除</a>').click(function () {
|
||||
var lindex = layer.confirm('请确认是否删除?', {
|
||||
btn: ['确认', '删除']
|
||||
}, function () {
|
||||
console.log('ok', r.id)
|
||||
window.remove(r.id);
|
||||
window.init();
|
||||
layer.close(lindex);
|
||||
}, function () {
|
||||
console.log('cancel', r.id)
|
||||
layer.close(lindex);
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
function query(p, ps) {
|
||||
request('chatbot?p=' + (p || 1) + '&ps=' + (ps || 10), { ops: 'fetch' }).then(function (rows) {
|
||||
var tds = $.map(rows, function (r) {
|
||||
var edit = $('<a href="edit.html?id=' + r.id + '" data-width="550" data-height="300"><i class="layui-icon"></i>编辑</a>');
|
||||
|
||||
var remove = $('<a style="margin-left:10px;"><i class="layui-icon" style="color:red;">ဆ</i>删除</a>').click(function () {
|
||||
var lindex = layer.confirm('请确认是否删除?', {
|
||||
btn: ['确认', '删除']
|
||||
}, function () {
|
||||
console.log('ok', r.id)
|
||||
window.remove(r.id);
|
||||
window.init();
|
||||
layer.close(lindex);
|
||||
}, function () {
|
||||
console.log('cancel', r.id)
|
||||
layer.close(lindex);
|
||||
});
|
||||
});
|
||||
|
||||
var isEnabled = $('<td><input type="checkbox" lay-skin="switch" lay-text="开启|关闭" ' + (r.enabled ? 'checked' : '') + '></td>');
|
||||
isEnabled.change(function () {
|
||||
change(r.id, $(this).find('input').prop('checked'));
|
||||
})
|
||||
|
||||
var rows = [
|
||||
$('<td>' + r.name + '</td>'),
|
||||
$('<td>' + r.snsurl + '</td>'),
|
||||
isEnabled,
|
||||
$('<td style="white-space:nowrap;" nowrap="nowrap"></td>').html([edit, remove])
|
||||
];
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tr.html(rows);
|
||||
return tr;
|
||||
var isEnabled = $('<td><input type="checkbox" lay-skin="switch" lay-text="开启|关闭" ' + (r.enabled ? 'checked' : '') + '></td>');
|
||||
isEnabled.change(function () {
|
||||
change(r.id, $(this).find('input').prop('checked'));
|
||||
})
|
||||
|
||||
$('#bots').html(tds);
|
||||
form.render();
|
||||
var rows = [
|
||||
$('<td>' + r.name + '</td>'),
|
||||
$('<td>' + r.snsurl + '</td>'),
|
||||
isEnabled,
|
||||
$('<td style="white-space:nowrap;" nowrap="nowrap"></td>').html([edit, remove])
|
||||
];
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tr.html(rows);
|
||||
return tr;
|
||||
})
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
return request('chatbot', { ops: 'delete', id: id })
|
||||
}
|
||||
$('#bots').html(tds);
|
||||
})
|
||||
}
|
||||
|
||||
function change(id, isEnabled) {
|
||||
return request('chatbot', { ops: isEnabled ? 'enable' : 'disable', id: id })
|
||||
}
|
||||
function remove(id) {
|
||||
return request('chatbot', { ops: 'delete', id: id })
|
||||
}
|
||||
|
||||
function showCreate() {
|
||||
location.href = '/apps/chatbot/edit.html';
|
||||
}
|
||||
function change(id, isEnabled) {
|
||||
return request('chatbot', { ops: isEnabled ? 'enable' : 'disable', id: id })
|
||||
}
|
||||
|
||||
function init() {
|
||||
query(1, 10);
|
||||
}
|
||||
function showCreate() {
|
||||
location.href = '/apps/chatbot/edit.html';
|
||||
}
|
||||
|
||||
function init() {
|
||||
query(1, 10);
|
||||
}
|
||||
|
||||
layui.use(['form'], function () {
|
||||
init();
|
||||
})
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user