348 lines
16 KiB
Vue
348 lines
16 KiB
Vue
<template>
|
||
<section class="content">
|
||
<div class="box box-primary">
|
||
<div class="box-body">
|
||
<!-- Content Header (Page header) -->
|
||
<section class="content-header">
|
||
<h1 id="itemTitle"></h1>
|
||
</section>
|
||
<!-- .content -->
|
||
<section class="content">
|
||
<div id="table"></div>
|
||
<div id="toolbar">
|
||
<button id="sysConf-add" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-plus"></i>增加
|
||
</button>
|
||
|
||
<button id="sysConf-multiDel" class="btn btn-default">
|
||
<i class="glyphicon glyphicon-wrench"></i>批量删除
|
||
</button>
|
||
</div>
|
||
</section><!-- .content -->
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<div class="modal fade" id="sysConfModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
||
<div class="modal-dialog" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
||
aria-hidden="true">×</span></button>
|
||
<h4 class="modal-title" id="modalLabel">字典信息</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-horizontal" id="sysConfForm">
|
||
<div class="form-group">
|
||
<label for="configId" class="col-sm-2 control-label">id</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="configId" id="configId">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="configName" class="col-sm-2 control-label">名称</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="configName"
|
||
id="configName">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="col-sm-2 control-label">状态</label>
|
||
<div class="col-sm-10">
|
||
<label class="radio-inline"><input type="radio" name="configStatus" value="1"
|
||
checked>有效</label>
|
||
<label class="radio-inline"><input type="radio" name="configStatus" value="2">无效</label>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="configValue" class="col-sm-2 control-label">值</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control" name="configValue" id="configValue">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="nameSpace" class="col-sm-2 control-label">命名空间</label>
|
||
<div class="col-sm-10">
|
||
<input type="text" class="form-control validate[required]" name="nameSpace" id="nameSpace">
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
|
||
<button type="button" class="btn btn-primary" id="save">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="modal fade" id="tipModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
|
||
<div class="modal-dialog" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title">提示信息</h4>
|
||
</div>
|
||
<div class="modal-body" id="tipMsg"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import TableHelper from '@/utils/bootstrap-table-helper';
|
||
import { getSysConfList } from '@/api/system/sysconf';
|
||
|
||
export default {
|
||
name: "SysconfAdminView",
|
||
setup() {
|
||
function showText(obj) {
|
||
let text = unescape($(obj).prop('title'));
|
||
$("#tipMsg").text(text);
|
||
$("#tipModal").modal('show');
|
||
}
|
||
window.showText = showText;
|
||
return {
|
||
showText
|
||
};
|
||
},
|
||
created() {
|
||
this.$nextTick(function () {
|
||
this.initData();
|
||
this.getSysConf();
|
||
});
|
||
},
|
||
methods: {
|
||
getSysConf() {
|
||
getSysConfList().then(res => {
|
||
$('#table').bootstrapTable('load', res.rows);
|
||
});
|
||
},
|
||
initData() {
|
||
$(function () {
|
||
$('#table').bootstrapTable('destroy');
|
||
$('#table').bootstrapTable({
|
||
columns: [
|
||
{field: 'tmp', title: 'ID', align: 'center', width: '5%', checkbox: true},
|
||
{
|
||
field: 'configId',
|
||
title: 'id',
|
||
align: 'center',
|
||
width: '5%',
|
||
},
|
||
{
|
||
field: 'configName',
|
||
title: '名称',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
return '<div style="text-align: center; width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="' + escape(val) + '" onclick="showText(this);">' + val + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'configValue',
|
||
title: '值',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
return '<div style="text-align: center; width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="' + escape(val) + '" onclick="showText(this);">' + val + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'configStatus',
|
||
title: '状态',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
if (val == 1) {
|
||
return '有效';
|
||
}
|
||
else if (val == 2) {
|
||
return '无效';
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: 'nameSpace',
|
||
title: '命名空间',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
return '<div style="text-align: center; width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="' + escape(val) + '" onclick="showText(this);">' + val + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'configId',
|
||
title: '操作',
|
||
align: 'center',
|
||
width: '5%',
|
||
formatter: function (val, row, index) {
|
||
return '<button class="btn btn-sm btn-success opt-edit" data-id=' + val + '>' +
|
||
'<i class="glyphicon glyphicon-edit"></i>编辑</button>' +
|
||
' <button class="btn btn-sm btn-danger opt-remove" data-id=' + val +
|
||
'><i class="glyphicon glyphicon-remove"></i>删除</button>';
|
||
}
|
||
}
|
||
],
|
||
cache: false,
|
||
striped: true,
|
||
showRefresh: true,
|
||
pageNumber: 1,
|
||
pageSize: 10,
|
||
pagination: true,
|
||
pageList: [10, 25, 50, 100],
|
||
search: true,
|
||
sidePagination: "client",
|
||
toolbar: '#toolbar'
|
||
});
|
||
|
||
$("#table").on("click", '.opt-remove', function () {
|
||
var id = $(this).attr("data-id");
|
||
if (id == 'undefined') {
|
||
$("#tipMsg").text("id参数有误");
|
||
$("#tipModal").modal('show');
|
||
return;
|
||
}
|
||
if (confirm("你确认删除该记录吗?" +
|
||
"\r\n删除后再也不能找回,请谨慎操作!")) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: "/admin/sysConf/del.action",
|
||
data: { 'ids': JSON.stringify([id]) },
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#tipMsg").text("删除成功");
|
||
$("#tipModal").modal('show');
|
||
getSysConfList().then(res => {
|
||
$('#table').bootstrapTable('load', res.rows);
|
||
});
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("删除失败");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
$("#sysConf-add").click(function () {
|
||
// 打开编辑弹窗
|
||
$("#sysConfModal").modal('show');
|
||
$("#sysConfForm")[0].reset();
|
||
$("#configId").val('');
|
||
$("#configId").attr('readonly', false);
|
||
});
|
||
|
||
$("#sysConf-multiDel").click(function () {
|
||
var rows = $("#table").bootstrapTable("getSelections");
|
||
if (rows.length == 0) {
|
||
alert("请先选择要删除的记录");
|
||
return;
|
||
}
|
||
console.log("rows: " + rows.length);
|
||
var idArr = [];
|
||
for (var i = 0; i < rows.length; i++) {
|
||
idArr.push(rows[i]['configId']);
|
||
}
|
||
console.log(idArr);
|
||
if (confirm("你确认批量删除该记录吗?" +
|
||
"\r\n删除后再也不能找回,请谨慎操作!")) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: "/admin/sysConf/del.action",
|
||
data: { 'ids': JSON.stringify(idArr) },
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#tipMsg").text("删除成功");
|
||
$("#tipModal").modal('show');
|
||
getSysConfList().then(res => {
|
||
$('#table').bootstrapTable('load', res.rows);
|
||
});
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("删除失败");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
$("#cancel").click(function () {
|
||
TableHelper.unCheckAll("#table");
|
||
});
|
||
|
||
$("#table").on("click", '.opt-edit', function () {
|
||
$("#configId").attr('readonly', true);
|
||
var id = $(this).attr("data-id");
|
||
$.ajax({
|
||
type: "get",
|
||
url: "/admin/sysConf/get.action",
|
||
data: { id: id },
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.entity) {
|
||
$("#configId").val(json.entity.configId);
|
||
$("#configName").val(json.entity.configName);
|
||
$("#configValue").val(json.entity.configValue);
|
||
$("#nameSpace").val(json.entity.nameSpace);
|
||
var status = json.entity.configStatus - 1;
|
||
$("input:radio[name='configStatus']")[status].checked = true;
|
||
// 打开编辑弹窗
|
||
$("#sysConfModal").modal('show');
|
||
} else {
|
||
$("#tipMsg").text("获取菜单信息出错");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#save").click(function () {
|
||
if ($("#sysConfForm").validationEngine('validate')) {
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/admin/sysConf/save.action",
|
||
data: $('#sysConfForm').serialize(),
|
||
dataType: "json",
|
||
success: function (json) {
|
||
if (json.success == 'true') {
|
||
$("#sysConfModal").modal('hide');
|
||
$("#tipMsg").text("保存成功");
|
||
$("#tipModal").modal('show');
|
||
getSysConfList().then(res => {
|
||
$('#table').bootstrapTable('load', res.rows);
|
||
});
|
||
TableHelper.doRefresh("#table");
|
||
} else {
|
||
$("#tipMsg").text("保存失败");
|
||
$("#tipModal").modal('show');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.table_line {
|
||
word-break: break-all;
|
||
}
|
||
|
||
.td_center {
|
||
vertical-align: middle !important;
|
||
}
|
||
|
||
.table_line {
|
||
word-break: break-all;
|
||
}
|
||
|
||
.td_center {
|
||
vertical-align: middle !important;
|
||
}
|
||
</style>
|