dict
This commit is contained in:
parent
e1f5d19ff7
commit
5424e7d0f0
159
src/plugin/admin/app/controller/DictController.php
Normal file
159
src/plugin/admin/app/controller/DictController.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\Option;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 字典管理
|
||||
*/
|
||||
class DictController extends Base
|
||||
{
|
||||
/**
|
||||
* 不需要授权的方法
|
||||
*/
|
||||
public $noNeedAuth = ['get'];
|
||||
|
||||
/**
|
||||
* 浏览
|
||||
* @return Response
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return view("dict/index");
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function insert(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$option_name = $this->dictNameToOptionName($request->post('name'));
|
||||
if (Option::where('name', $option_name)->first()) {
|
||||
return $this->json(1, '字典已经存在' . $option_name);
|
||||
}
|
||||
$values = (array)$request->post('value', []);
|
||||
$format_values = $this->filterValue($values);
|
||||
$option = new Option;
|
||||
$option->name = $option_name;
|
||||
$option->value = json_encode($format_values, JSON_UNESCAPED_UNICODE);
|
||||
$option->save();
|
||||
return $this->json(0);
|
||||
}
|
||||
return view("dict/insert");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$name = $this->dictNameToOptionName($request->post('name', ''));
|
||||
$option = Option::where('name', $name)->first();
|
||||
if (!$option) {
|
||||
return $this->json(1, '字典不存在');
|
||||
}
|
||||
$format_values = $this->filterValue($request->post('value'));
|
||||
$option->name = $this->dictNameToOptionName($request->post('name'));
|
||||
$option->value = $format_values;
|
||||
$option->save();
|
||||
}
|
||||
return view("dict/update");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$names = (array)$request->post('name');
|
||||
foreach ($names as $index => $name) {
|
||||
$names[$index] = $this->dictNameToOptionName($name);
|
||||
}
|
||||
Option::whereIn('name', $names)->delete();
|
||||
return $this->json(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
$name = $request->get('name', '');
|
||||
if ($name && is_string($name)) {
|
||||
$items = Option::where('name', 'like', "dict_$name%")->get()->toArray();
|
||||
} else {
|
||||
$items = Option::where('name', 'like', 'dict_%')->get()->toArray();
|
||||
}
|
||||
foreach ($items as &$item) {
|
||||
$item['name'] = $this->optionNameTodictName($item['name']);
|
||||
}
|
||||
return $this->json(0, 'ok', $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param Request $request
|
||||
* @param $name
|
||||
* @return Response
|
||||
*/
|
||||
public function get(Request $request, $name): Response
|
||||
{
|
||||
$value = Option::where('name', $this->dictNameToOptionName($name))->value('value');
|
||||
if ($value === null) {
|
||||
return $this->json(1, '字典不存在');
|
||||
}
|
||||
return $this->json(1, 'ok', json_decode($value, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤字典选项
|
||||
* @param array $values
|
||||
* @return array
|
||||
* @throws BusinessException
|
||||
*/
|
||||
protected function filterValue(array $values): array
|
||||
{
|
||||
$format_values = [];
|
||||
foreach ($values as $item) {
|
||||
if (!isset($item['value']) || !isset($item['name'])) {
|
||||
throw new BusinessException('格式错误', 1);
|
||||
}
|
||||
$format_values[] = ['value' => $item['value'], 'name' => $item['name']];
|
||||
}
|
||||
return $format_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function dictNameToOptionName(string $name): string
|
||||
{
|
||||
return "dict_$name";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function optionNameTodictName(string $name): string
|
||||
{
|
||||
return substr($name, 5);
|
||||
}
|
||||
|
||||
}
|
40
src/plugin/admin/app/model/Dict.php
Normal file
40
src/plugin/admin/app/model/Dict.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\model;
|
||||
|
||||
use plugin\admin\app\model\Base;
|
||||
|
||||
/**
|
||||
* @property integer $id 主键(主键)
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property string $bb bb
|
||||
* @property integer $tree1
|
||||
* @property string $tree2
|
||||
* @property string $icon
|
||||
* @property string $file
|
||||
* @property integer $select1
|
||||
* @property string $select2
|
||||
* @property string $img
|
||||
* @property integer $state
|
||||
*/
|
||||
class Dict extends Base
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dict';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
256
src/plugin/admin/app/view/dict/index.html
Normal file
256
src/plugin/admin/app/view/dict/index.html
Normal file
@ -0,0 +1,256 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>浏览页面</title>
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
|
||||
<!-- 顶部查询表单 -->
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<form class="layui-form top-search-from">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" value="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label"></label>
|
||||
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
|
||||
<i class="layui-icon layui-icon-search"></i>查询
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
|
||||
<i class="layui-icon layui-icon-refresh"></i>重置
|
||||
</button>
|
||||
</div>
|
||||
<div class="toggle-btn">
|
||||
<a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
|
||||
<a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table id="data-table" lay-filter="data-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<script type="text/html" id="table-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove">删除</button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script src="/app/admin/admin/js/index.js"></script>
|
||||
<script>
|
||||
|
||||
// 相关接口
|
||||
const SELECT_API = "/app/admin/dict/select";
|
||||
const UPDATE_API = "/app/admin/dict/update";
|
||||
const DELETE_API = "/app/admin/dict/delete";
|
||||
const INSERT_URL = "/app/admin/dict/insert";
|
||||
const UPDATE_URL = "/app/admin/dict/update";
|
||||
|
||||
// 表格渲染
|
||||
layui.use(['table', 'form', 'jquery', 'common', 'popup', 'util'], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let common = layui.common;
|
||||
let util = layui.util;
|
||||
|
||||
// 表头参数
|
||||
let cols = [
|
||||
{
|
||||
type: "checkbox"
|
||||
},{
|
||||
title: "名称",
|
||||
field: "name",
|
||||
width: 160,
|
||||
},{
|
||||
title: "值",
|
||||
field: "value",
|
||||
},{
|
||||
title: "创建时间",
|
||||
field: "created_at",
|
||||
width: 180,
|
||||
hide: true,
|
||||
},{
|
||||
title: "更新时间",
|
||||
field: "updated_at",
|
||||
width: 180,
|
||||
hide: true,
|
||||
},{
|
||||
title: "操作",
|
||||
toolbar: "#table-bar",
|
||||
align: "center",
|
||||
width: 160,
|
||||
fixed: "right",
|
||||
}
|
||||
];
|
||||
|
||||
// 渲染表格
|
||||
function render()
|
||||
{
|
||||
table.render({
|
||||
elem: "#data-table",
|
||||
url: SELECT_API,
|
||||
page: true,
|
||||
cols: [cols],
|
||||
skin: "line",
|
||||
size: "lg",
|
||||
toolbar: "#table-toolbar",
|
||||
autoSort: false,
|
||||
defaultToolbar: [{
|
||||
title: "刷新",
|
||||
layEvent: "refresh",
|
||||
icon: "layui-icon-refresh",
|
||||
}, "filter", "print", "exports"]
|
||||
});
|
||||
}
|
||||
render();
|
||||
|
||||
// 编辑或删除行事件
|
||||
table.on('tool(data-table)', function(obj) {
|
||||
if (obj.event === 'remove') {
|
||||
remove(obj);
|
||||
} else if (obj.event === 'edit') {
|
||||
edit(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// 表格顶部工具栏事件
|
||||
table.on('toolbar(data-table)', function(obj) {
|
||||
if (obj.event === 'add') {
|
||||
add();
|
||||
} else if (obj.event === 'refresh') {
|
||||
refreshTable();
|
||||
} else if (obj.event === 'batchRemove') {
|
||||
batchRemove(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// 表格顶部搜索事件
|
||||
form.on('submit(table-query)', function(data) {
|
||||
table.reload('data-table', {
|
||||
where: data.field
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
// 表格顶部搜索重置事件
|
||||
form.on('submit(table-reset)', function(data) {
|
||||
table.reload('data-table', {
|
||||
where: []
|
||||
})
|
||||
});
|
||||
|
||||
// 表格排序事件
|
||||
table.on('sort(data-table)', function(obj){
|
||||
table.reload('data-table', {
|
||||
initSort: obj,
|
||||
scrollPos: 'fixed',
|
||||
where: {
|
||||
field: obj.field,
|
||||
order: obj.type
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 表格新增数据
|
||||
let add = function() {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shade: 0.1,
|
||||
area: [common.isModile()?'100%':'500px', common.isModile()?'100%':'500px'],
|
||||
content: INSERT_URL
|
||||
});
|
||||
}
|
||||
|
||||
// 表格编辑数据
|
||||
let edit = function(obj) {
|
||||
let value = obj.data['name'];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '修改',
|
||||
shade: 0.1,
|
||||
area: [common.isModile()?'100%':'500px', common.isModile()?'100%':'500px'],
|
||||
content: UPDATE_URL + '?name=' + value
|
||||
});
|
||||
}
|
||||
|
||||
// 删除一行
|
||||
let remove = function(obj) {
|
||||
return doRemove(obj.data['name']);
|
||||
}
|
||||
|
||||
// 删除多行
|
||||
let batchRemove = function(obj) {
|
||||
let checkIds = common.checkField(obj, 'name');
|
||||
if (checkIds === "") {
|
||||
layui.popup.warning('未选中数据');
|
||||
return false;
|
||||
}
|
||||
doRemove(checkIds.split(','));
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
let doRemove = function (ids) {
|
||||
let data = {};
|
||||
data['name'] = ids;
|
||||
layer.confirm('确定删除?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: DELETE_API,
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
type: 'post',
|
||||
success: function(res) {
|
||||
layer.close(loading);
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success('操作成功', refreshTable);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新表格数据
|
||||
window.refreshTable = function(param) {
|
||||
table.reloadData('data-table', {
|
||||
scrollPos: 'fixed'
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
223
src/plugin/admin/app/view/dict/insert.html
Normal file
223
src/plugin/admin/app/view/dict/insert.html
Normal file
@ -0,0 +1,223 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>新增字典</title>
|
||||
<link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
.mainBox {
|
||||
width: auto !important;
|
||||
}
|
||||
.layui-tab .layui-table-cell {
|
||||
overflow:visible !important;
|
||||
}
|
||||
.layui-table-body ,.layui-table-box{
|
||||
overflow:visible !important;
|
||||
}
|
||||
.layui-tab .layui-form-select dl {
|
||||
max-height: 190px;
|
||||
}
|
||||
.layui-table-body .layui-table-col-special:last-child {
|
||||
width: 100% !important;
|
||||
border-right: 1px solid #eee !important;
|
||||
}
|
||||
xm-select {
|
||||
min-height: 38px;
|
||||
line-height: 38px;
|
||||
}
|
||||
xm-select .xm-body .xm-option .xm-option-icon {
|
||||
font-size: 18px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<form class="layui-form" action="" lay-filter="create-dict-form">
|
||||
|
||||
<div class="mainBox">
|
||||
<div class="main-container">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label" style="width:auto">字典名</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入英文字母组合">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<!-- 字段属性 -->
|
||||
<table id="column-table" lay-filter="column-table"></table>
|
||||
|
||||
<script type="text/html" id="column-toolbar">
|
||||
<button type="button" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</button>
|
||||
<button type="button" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-value">
|
||||
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][value]" placeholder="值" autocomplete="off" class="layui-input" value="{{ d.value }}">
|
||||
<input type="hidden" name="value[{{ d.LAY_INDEX-1 }}][_field_id]" value="{{ d._field_id }}">
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-name">
|
||||
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][name]" placeholder="标题" autocomplete="off" class="layui-input" value="{{ d.name }}">
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bottom">
|
||||
<div class="button-container">
|
||||
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
|
||||
lay-filter="save">
|
||||
提交
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md">
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script>
|
||||
|
||||
const INSERT_API = '/app/admin/dict/insert';
|
||||
|
||||
// 字段设置
|
||||
layui.use(['table', 'common', 'popup'], function () {
|
||||
|
||||
let table = layui.table;
|
||||
let common = layui.common;
|
||||
let cols = [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
title: '值',
|
||||
field: 'value',
|
||||
templet: '#col-value'
|
||||
},
|
||||
{
|
||||
title: '标题',
|
||||
field: 'name',
|
||||
templet: '#col-name',
|
||||
}
|
||||
];
|
||||
|
||||
window._field_id = 0;
|
||||
let data = [{
|
||||
_field_id: _field_id++,
|
||||
value : '',
|
||||
name: '',
|
||||
}];
|
||||
|
||||
table.render({
|
||||
elem: '#column-table',
|
||||
cols: [cols],
|
||||
data: data,
|
||||
cellMinWidth: 40,
|
||||
skin: 'line',
|
||||
size: 'lg',
|
||||
limit: 10000,
|
||||
page: false,
|
||||
toolbar: '#column-toolbar',
|
||||
defaultToolbar: [],
|
||||
});
|
||||
|
||||
table.on('toolbar(column-table)', function(obj) {
|
||||
if (obj.event === 'add') {
|
||||
add();
|
||||
} else if (obj.event === 'batchRemove') {
|
||||
batchRemove(obj);
|
||||
}
|
||||
});
|
||||
|
||||
let add = function() {
|
||||
syncTableData();
|
||||
let options = table.getData('column-table');
|
||||
options.push({
|
||||
_field_id: _field_id++,
|
||||
value : '',
|
||||
name: '',
|
||||
});
|
||||
table.reloadData('column-table', {data:options});
|
||||
}
|
||||
|
||||
let batchRemove = function(obj) {
|
||||
var checkIds = common.checkField(obj,'_field_id');
|
||||
if (checkIds === "") return layui.popup.warning('未选中数据');
|
||||
let data = table.getData('column-table');
|
||||
let newData = [];
|
||||
let deleteIds = checkIds.split(',');
|
||||
layui.each(data, function (index, item) {
|
||||
if (deleteIds.indexOf(item._field_id + '') === -1) {
|
||||
newData.push(item);
|
||||
}
|
||||
});
|
||||
table.reloadData('column-table', {data: newData})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
layui.use(['form', 'jquery', 'popup'], function () {
|
||||
//提交事件
|
||||
layui.form.on('submit(save)', function () {
|
||||
let data = layui.form.val('create-dict-form');
|
||||
layui.jquery.ajax({
|
||||
url: INSERT_API,
|
||||
type: 'POST',
|
||||
dateType: 'json',
|
||||
data: data,
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success('操作成功', function () {
|
||||
parent.refreshTable();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
window.syncTableData = function () {
|
||||
let tableData = layui.form.val('create-dict-form');
|
||||
let columnTableData = [];
|
||||
let len = Object.keys(tableData).length;
|
||||
let id = 0;
|
||||
window._key_id = 0;
|
||||
while (id < len) {
|
||||
// column data
|
||||
if (typeof tableData['value[' + id + '][_field_id]'] !== 'undefined') {
|
||||
columnTableData.push({
|
||||
_field_id: tableData['value[' + id + '][_field_id]'],
|
||||
name : tableData['value[' + id + '][name]'],
|
||||
value: tableData['value[' + id + '][value]'],
|
||||
});
|
||||
}
|
||||
_key_id++;
|
||||
id++;
|
||||
}
|
||||
layui.table.reloadData('column-table', {data: columnTableData});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
235
src/plugin/admin/app/view/dict/update.html
Normal file
235
src/plugin/admin/app/view/dict/update.html
Normal file
@ -0,0 +1,235 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>更新字典</title>
|
||||
<link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
.mainBox {
|
||||
width: auto !important;
|
||||
}
|
||||
.layui-tab .layui-table-cell {
|
||||
overflow:visible !important;
|
||||
}
|
||||
.layui-table-body ,.layui-table-box{
|
||||
overflow:visible !important;
|
||||
}
|
||||
.layui-tab .layui-form-select dl {
|
||||
max-height: 190px;
|
||||
}
|
||||
.layui-table-body .layui-table-col-special:last-child {
|
||||
width: 100% !important;
|
||||
border-right: 1px solid #eee !important;
|
||||
}
|
||||
xm-select {
|
||||
min-height: 38px;
|
||||
line-height: 38px;
|
||||
}
|
||||
xm-select .xm-body .xm-option .xm-option-icon {
|
||||
font-size: 18px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<form class="layui-form" action="" lay-filter="create-dict-form">
|
||||
|
||||
<div class="mainBox">
|
||||
<div class="main-container">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label" style="width:auto">字典名</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入英文字母组合">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<!-- 字段属性 -->
|
||||
<table id="column-table" lay-filter="column-table"></table>
|
||||
|
||||
<script type="text/html" id="column-toolbar">
|
||||
<button type="button" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</button>
|
||||
<button type="button" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-value">
|
||||
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][value]" placeholder="值" autocomplete="off" class="layui-input" value="{{ d.value }}">
|
||||
<input type="hidden" name="value[{{ d.LAY_INDEX-1 }}][_field_id]" value="{{ d._field_id }}">
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-name">
|
||||
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][name]" placeholder="标题" autocomplete="off" class="layui-input" value="{{ d.name }}">
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bottom">
|
||||
<div class="button-container">
|
||||
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
|
||||
lay-filter="save">
|
||||
提交
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md">
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script>
|
||||
|
||||
const DICT_NAME = layui.url().search.name;
|
||||
const UPDATE_API = '/app/admin/dict/update';
|
||||
const SELECT_API = '/app/admin/dict/get/' + DICT_NAME;
|
||||
|
||||
// 字段设置
|
||||
layui.use(['table', 'common', 'popup'], function () {
|
||||
|
||||
let table = layui.table;
|
||||
let common = layui.common;
|
||||
let $ = layui.$;
|
||||
let cols = [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
title: '值',
|
||||
field: 'value',
|
||||
templet: '#col-value'
|
||||
},
|
||||
{
|
||||
title: '标题',
|
||||
field: 'name',
|
||||
templet: '#col-name',
|
||||
}
|
||||
];
|
||||
|
||||
$('input[name="name"]').val(DICT_NAME);
|
||||
|
||||
window._field_id = 0;
|
||||
let data = [];
|
||||
$.ajax({
|
||||
url: SELECT_API,
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
success: function (res) {
|
||||
data = res.data;
|
||||
layui.each(data, function (k, v) {
|
||||
data[k]['_field_id'] = _field_id++;
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
table.render({
|
||||
elem: '#column-table',
|
||||
cols: [cols],
|
||||
data: data,
|
||||
cellMinWidth: 40,
|
||||
skin: 'line',
|
||||
size: 'lg',
|
||||
limit: 10000,
|
||||
page: false,
|
||||
toolbar: '#column-toolbar',
|
||||
defaultToolbar: [],
|
||||
});
|
||||
|
||||
table.on('toolbar(column-table)', function(obj) {
|
||||
if (obj.event === 'add') {
|
||||
add();
|
||||
} else if (obj.event === 'batchRemove') {
|
||||
batchRemove(obj);
|
||||
}
|
||||
});
|
||||
|
||||
let add = function() {
|
||||
syncTableData();
|
||||
let options = table.getData('column-table');
|
||||
options.push({
|
||||
_field_id: _field_id++,
|
||||
value : '',
|
||||
name: '',
|
||||
});
|
||||
table.reloadData('column-table', {data:options});
|
||||
}
|
||||
|
||||
let batchRemove = function(obj) {
|
||||
var checkIds = common.checkField(obj,'_field_id');
|
||||
if (checkIds === "") return layui.popup.warning('未选中数据');
|
||||
let data = table.getData('column-table');
|
||||
let newData = [];
|
||||
let deleteIds = checkIds.split(',');
|
||||
layui.each(data, function (index, item) {
|
||||
if (deleteIds.indexOf(item._field_id + '') === -1) {
|
||||
newData.push(item);
|
||||
}
|
||||
});
|
||||
table.reloadData('column-table', {data: newData})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
layui.use(['form', 'jquery', 'popup'], function () {
|
||||
//提交事件
|
||||
layui.form.on('submit(save)', function () {
|
||||
let data = layui.form.val('create-dict-form');
|
||||
layui.jquery.ajax({
|
||||
url: UPDATE_API,
|
||||
type: 'POST',
|
||||
dateType: 'json',
|
||||
data: data,
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success('操作成功', function () {
|
||||
parent.refreshTable();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
window.syncTableData = function () {
|
||||
let tableData = layui.form.val('create-dict-form');
|
||||
let columnTableData = [];
|
||||
let len = Object.keys(tableData).length;
|
||||
let id = 0;
|
||||
window._key_id = 0;
|
||||
while (id < len) {
|
||||
// column data
|
||||
if (typeof tableData['value[' + id + '][_field_id]'] !== 'undefined') {
|
||||
columnTableData.push({
|
||||
_field_id: tableData['value[' + id + '][_field_id]'],
|
||||
name : tableData['value[' + id + '][name]'],
|
||||
value: tableData['value[' + id + '][value]'],
|
||||
});
|
||||
}
|
||||
_key_id++;
|
||||
id++;
|
||||
}
|
||||
layui.table.reloadData('column-table', {data: columnTableData});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user