后台优化
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= $lang ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?= $translations['title'] ?? '车辆管理' ?></title>
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
<?php if ($lang === 'ar'): ?>
|
||||
<style>
|
||||
body {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
.layui-table-cell {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<!-- 数据表格 -->
|
||||
<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" permission="app.admin.vehicle.insert">
|
||||
<i class="layui-icon layui-icon-add-1"></i><?= $translations['add'] ?? '新增' ?>
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.vehicle.delete">
|
||||
<i class="layui-icon layui-icon-delete"></i><?= $translations['delete'] ?? '删除' ?>
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.vehicle.update"><?= $translations['edit'] ?? '编辑' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.vehicle.delete"><?= $translations['delete'] ?? '删除' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="detail" permission="app.admin.vehicle.detail"><?= $translations['detail'] ?? '详情' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="updateLogistics" permission="app.admin.vehicle.updateLogistics"><?= $translations['updateLogistics'] ?? '物流修改' ?></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/permission.js"></script>
|
||||
<script src="/app/admin/admin/js/common.js"></script>
|
||||
|
||||
<script>
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
const SELECT_API = "/app/admin/vehicle/select";
|
||||
const UPDATE_API = "/app/admin/vehicle/update";
|
||||
const DELETE_API = "/app/admin/vehicle/delete";
|
||||
const INSERT_URL = "/app/admin/vehicle/insert";
|
||||
const UPDATE_URL = "/app/admin/vehicle/update";
|
||||
const DETAIL_URL = "/app/admin/vehicle/detail";
|
||||
const LOGISTICS_URL = "/app/admin/vehicle/updateLogistics";
|
||||
|
||||
// 翻译文本
|
||||
const translations = <?= json_encode($translations) ?>;
|
||||
|
||||
// 初始化layui
|
||||
layui.use(["table", "form", "common", "popup", "util"], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.$;
|
||||
let common = layui.common;
|
||||
let util = layui.util;
|
||||
|
||||
console.log('Layui initialized');
|
||||
|
||||
// 监听语言更新消息
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.data && event.data.type === 'language_changed') {
|
||||
// 重新获取翻译
|
||||
$.get('/app/admin/vehicle/getTranslations', function(translations) {
|
||||
// 更新标签页标题
|
||||
if (window.parent && window.parent.layui) {
|
||||
window.parent.layui.use(['tab'], function() {
|
||||
let tab = window.parent.layui.tab;
|
||||
if (tab && typeof tab.changeTitle === 'function') {
|
||||
let currentTab = window.parent.document.querySelector('.layui-tab-title .layui-this');
|
||||
if (currentTab) {
|
||||
tab.changeTitle(currentTab.getAttribute('lay-id'), translations.title);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// 重新加载表格
|
||||
table.reload('data-table');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 表头参数
|
||||
let cols = [[
|
||||
{type: "checkbox", align: "center"},
|
||||
{title: translations.id, align: "center", field: "id"},
|
||||
{title: translations.vin, align: "center", field: "vin"},
|
||||
{title: translations.status, align: "center", field: "status_txt"},
|
||||
{title: translations.current_location, align: "center", field: "location_name"},
|
||||
{title: translations.final_location, align: "center", field: "final_location_name"},
|
||||
{title: translations.fbo_location, align: "center", field: "fbo_location_name"},
|
||||
{title: translations.created_at, align: "center", field: "created_at"},
|
||||
{title: translations.updated_at, align: "center", field: "updated_at"},
|
||||
{title: translations.operation, toolbar: "#table-bar", align: "center", fixed: "right", width: 150}
|
||||
]];
|
||||
|
||||
// 渲染表格
|
||||
table.render({
|
||||
elem: "#data-table",
|
||||
url: SELECT_API,
|
||||
page: {
|
||||
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
|
||||
groups: 5,
|
||||
theme: '#FF5722',
|
||||
text: {
|
||||
count: translations.pagination_total,
|
||||
limit: translations.pagination_limit,
|
||||
page: translations.pagination_page,
|
||||
prev: translations.pagination_prev,
|
||||
next: translations.pagination_next,
|
||||
jump: translations.pagination_jump,
|
||||
go: translations.pagination_go
|
||||
}
|
||||
},
|
||||
cols: cols,
|
||||
skin: "line",
|
||||
size: "lg",
|
||||
toolbar: "#table-toolbar",
|
||||
autoSort: false,
|
||||
defaultToolbar: [{
|
||||
title: translations.refresh,
|
||||
layEvent: "refresh",
|
||||
icon: "layui-icon-refresh",
|
||||
}, translations.filter, translations.print, translations.export],
|
||||
text: {
|
||||
none: translations.data_not_found
|
||||
},
|
||||
done: function () {
|
||||
// 更新分页文本
|
||||
$('.layui-laypage a').each(function() {
|
||||
let text = $(this).text();
|
||||
if (text === '上一页') {
|
||||
$(this).text(translations.pagination_prev);
|
||||
} else if (text === '下一页') {
|
||||
$(this).text(translations.pagination_next);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新分页信息
|
||||
let pageInfo = $('.layui-laypage-count').text();
|
||||
let total = pageInfo.match(/\d+/)[0];
|
||||
$('.layui-laypage-count').text(translations.pagination_total.replace('{total}', total));
|
||||
|
||||
// 更新每页条数
|
||||
$('.layui-laypage-limits option').each(function() {
|
||||
let value = $(this).val();
|
||||
$(this).text(translations.pagination_limit.replace('{limit}', value));
|
||||
});
|
||||
|
||||
// 更新跳转文本
|
||||
$('.layui-laypage-skip').prev().text(translations.pagination_jump);
|
||||
$('.layui-laypage-btn').text(translations.pagination_go);
|
||||
|
||||
layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
|
||||
}
|
||||
});
|
||||
|
||||
// 编辑或删除行事件
|
||||
table.on("tool(data-table)", function(obj) {
|
||||
if (obj.event === "remove") {
|
||||
remove(obj);
|
||||
} else if (obj.event === "edit") {
|
||||
edit(obj);
|
||||
} else if (obj.event === "detail") {
|
||||
detail(obj);
|
||||
} else if (obj.event === "updateLogistics") {
|
||||
updateLogistics(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", {
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: data.field
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
// 表格顶部搜索重置事件
|
||||
form.on("submit(table-reset)", function(data) {
|
||||
table.reload("data-table", {
|
||||
where: []
|
||||
})
|
||||
});
|
||||
|
||||
// 字段允许为空
|
||||
form.verify({
|
||||
phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
|
||||
email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
|
||||
url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
|
||||
number: [/(^$)|^\d+$/,'只能填写数字'],
|
||||
date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
|
||||
identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
|
||||
});
|
||||
|
||||
// 表格排序事件
|
||||
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: translations.add,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: INSERT_URL
|
||||
});
|
||||
}
|
||||
|
||||
// 表格编辑数据
|
||||
let edit = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.edit,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
|
||||
// 删除一行
|
||||
let remove = function(obj) {
|
||||
return doRemove(obj.data[PRIMARY_KEY]);
|
||||
}
|
||||
|
||||
// 删除多行
|
||||
let batchRemove = function(obj) {
|
||||
let checkIds = common.checkField(obj, PRIMARY_KEY);
|
||||
if (checkIds === "") {
|
||||
layui.popup.warning(translations.no_data_selected);
|
||||
return false;
|
||||
}
|
||||
doRemove(checkIds.split(","));
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
let doRemove = function (ids) {
|
||||
let data = {};
|
||||
data[PRIMARY_KEY] = ids;
|
||||
layer.confirm(translations.confirm_delete, {
|
||||
icon: 3,
|
||||
title: translations.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(translations.operation_success, refreshTable);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新表格数据
|
||||
window.refreshTable = function() {
|
||||
table.reloadData("data-table", {
|
||||
scrollPos: "fixed",
|
||||
done: function (res, curr) {
|
||||
if (curr > 1 && res.data && !res.data.length) {
|
||||
curr = curr - 1;
|
||||
table.reloadData("data-table", {
|
||||
page: {
|
||||
curr: curr
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 查看数据
|
||||
let detail = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.detail,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: DETAIL_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
|
||||
// 查看数据
|
||||
let updateLogistics = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.edit,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: LOGISTICS_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user