key policy
This commit is contained in:
parent
ddc568ba39
commit
6a56e9a4d2
32
app/api/controller/UserPolicyController.php
Normal file
32
app/api/controller/UserPolicyController.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\UserPolicy;
|
||||||
|
use app\constant\ResponseCode;
|
||||||
|
use support\Request;
|
||||||
|
use think\Exception;
|
||||||
|
|
||||||
|
class UserPolicyController extends BaseController
|
||||||
|
{
|
||||||
|
protected $noNeedLogin = ['*'];
|
||||||
|
public function getPolicy(Request $e)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$policy = UserPolicy::where('id', 1)->findOrEmpty();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => ResponseCode::SUCCESS,
|
||||||
|
'data' => $policy,
|
||||||
|
'msg' => 'success',
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => ResponseCode::FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
app/common/model/UserPolicy.php
Normal file
12
app/common/model/UserPolicy.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use app\BaseModel;
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class UserPolicy extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
32
plugin/admin/app/model/UserPolicy.php
Normal file
32
plugin/admin/app/model/UserPolicy.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\admin\app\model;
|
||||||
|
|
||||||
|
use plugin\admin\app\model\Base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property integer $id (主键)
|
||||||
|
* @property mixed $policy Key Policies
|
||||||
|
* @property mixed $created_at 创建时间
|
||||||
|
* @property string $updated_at 更新时间
|
||||||
|
* @property string $deleted_at
|
||||||
|
*/
|
||||||
|
class UserPolicy extends Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'wa_user_policy';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -104,14 +104,15 @@
|
|||||||
|
|
||||||
<!-- 表格顶部工具栏 -->
|
<!-- 表格顶部工具栏 -->
|
||||||
<script type="text/html" id="table-toolbar">
|
<script type="text/html" id="table-toolbar">
|
||||||
<!-- <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add"-->
|
|
||||||
<!-- permission="app.admin.teacherscheduletime.insert">-->
|
|
||||||
<!-- <i class="layui-icon layui-icon-add-1"></i>新增-->
|
|
||||||
<!-- </button>-->
|
|
||||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove"
|
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove"
|
||||||
permission="app.admin.teacherscheduletime.delete">
|
permission="app.admin.teacherscheduletime.delete">
|
||||||
<i class="layui-icon layui-icon-delete"></i>删除
|
<i class="layui-icon layui-icon-delete"></i>删除
|
||||||
</button>
|
</button>
|
||||||
|
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="export-schedule"
|
||||||
|
permission="app.admin.teacherscheduletime.insert">
|
||||||
|
<i class="layui-icon layui-icon-add-1"></i>排课汇总导出
|
||||||
|
</button>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- 表格行工具栏 -->
|
<!-- 表格行工具栏 -->
|
||||||
@ -289,6 +290,8 @@
|
|||||||
add();
|
add();
|
||||||
} else if (obj.event === "refresh") {
|
} else if (obj.event === "refresh") {
|
||||||
refreshTable();
|
refreshTable();
|
||||||
|
} else if (obj.event === "export-schedule") {
|
||||||
|
exportSchedule();
|
||||||
} else if (obj.event === "batchRemove") {
|
} else if (obj.event === "batchRemove") {
|
||||||
batchRemove(obj);
|
batchRemove(obj);
|
||||||
}
|
}
|
||||||
@ -346,6 +349,18 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 表格新增数据
|
||||||
|
let exportSchedule = function () {
|
||||||
|
layer.open({
|
||||||
|
type: 2,
|
||||||
|
title: "汇总导出",
|
||||||
|
shade: 0.1,
|
||||||
|
maxmin: true,
|
||||||
|
area: [common.isModile() ? "100%" : "500px", common.isModile() ? "100%" : "450px"],
|
||||||
|
content: INSERT_URL
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 表格编辑数据
|
// 表格编辑数据
|
||||||
let edit = function (obj) {
|
let edit = function (obj) {
|
||||||
let value = obj.data[PRIMARY_KEY];
|
let value = obj.data[PRIMARY_KEY];
|
||||||
|
158
plugin/admin/app/view/user-policy/index.html
Normal file
158
plugin/admin/app/view/user-policy/index.html
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-cn">
|
||||||
|
<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">
|
||||||
|
|
||||||
|
<form class="layui-form">
|
||||||
|
|
||||||
|
<div class="mainBox">
|
||||||
|
<div class="main-container mr-5">
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">Key Policies</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="hidden" id="id" name="id" class="layui-textarea" value="{$user_policy['id']}"></input>
|
||||||
|
<textarea id="policy" name="policy" class="layui-textarea">{$user_policy['policy']}</textarea>
|
||||||
|
</div>
|
||||||
|
</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?v=2.8.12"></script>
|
||||||
|
<script src="/app/admin/component/pear/pear.js"></script>
|
||||||
|
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
|
||||||
|
<script src="/app/admin/admin/js/permission.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// 相关接口
|
||||||
|
const PRIMARY_KEY = "id";
|
||||||
|
const SELECT_API = "/app/admin/user-policy/select" + location.search;
|
||||||
|
const UPDATE_API = "/app/admin/user-policy/update";
|
||||||
|
|
||||||
|
// 获取数据库记录
|
||||||
|
layui.use(["form", "util", "popup"], function () {
|
||||||
|
let $ = layui.$;
|
||||||
|
$.ajax({
|
||||||
|
url: SELECT_API,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (res) {
|
||||||
|
|
||||||
|
// 给表单初始化数据
|
||||||
|
layui.each(res.data[0], function (key, value) {
|
||||||
|
let obj = $('*[name="' + key + '"]');
|
||||||
|
if (key === "password") {
|
||||||
|
obj.attr("placeholder", "不更新密码请留空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof obj[0] === "undefined" || !obj[0].nodeName) return;
|
||||||
|
if (obj[0].nodeName.toLowerCase() === "textarea") {
|
||||||
|
obj.val(value);
|
||||||
|
} else {
|
||||||
|
obj.attr("value", value);
|
||||||
|
obj[0].value = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 字段 Key Policies policy
|
||||||
|
layui.use(["tinymce"], function () {
|
||||||
|
var tinymce = layui.tinymce
|
||||||
|
var edit = tinymce.render({
|
||||||
|
elem: "#policy",
|
||||||
|
height: 650,
|
||||||
|
images_upload_url: "/app/admin/upload/image",
|
||||||
|
});
|
||||||
|
edit.on("blur", function () {
|
||||||
|
layui.$("#policy").val(edit.getContent());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 字段 创建时间 created_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#created_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 更新时间 updated_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#updated_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 deleted_at deleted_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#deleted_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// ajax返回失败
|
||||||
|
if (res.code) {
|
||||||
|
layui.popup.failure(res.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//提交事件
|
||||||
|
layui.use(["form", "popup"], function () {
|
||||||
|
// 字段验证允许为空
|
||||||
|
layui.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)$)/, "请输入正确的身份证号"]
|
||||||
|
});
|
||||||
|
layui.form.on("submit(save)", function (data) {
|
||||||
|
data.field[PRIMARY_KEY] = layui.url().search[PRIMARY_KEY];
|
||||||
|
data.field['id'] = 1;
|
||||||
|
layui.$.ajax({
|
||||||
|
url: UPDATE_API,
|
||||||
|
type: "POST",
|
||||||
|
dateType: "json",
|
||||||
|
data: data.field,
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
142
plugin/admin/app/view/user-policy/insert.html
Normal file
142
plugin/admin/app/view/user-policy/insert.html
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-cn">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>新增页面</title>
|
||||||
|
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||||
|
<link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
|
||||||
|
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form class="layui-form" action="">
|
||||||
|
|
||||||
|
<div class="mainBox">
|
||||||
|
<div class="main-container mr-5">
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">Key Policies</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<textarea id="policy" name="policy" class="layui-textarea"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">创建时间</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="created_at" id="created_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">更新时间</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="updated_at" id="updated_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">deleted_at</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="deleted_at" id="deleted_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</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?v=2.8.12"></script>
|
||||||
|
<script src="/app/admin/component/pear/pear.js"></script>
|
||||||
|
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
|
||||||
|
<script src="/app/admin/admin/js/permission.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// 相关接口
|
||||||
|
const INSERT_API = "/app/admin/user-policy/insert";
|
||||||
|
|
||||||
|
// 字段 Key Policies policy
|
||||||
|
layui.use(["tinymce"], function() {
|
||||||
|
var tinymce = layui.tinymce
|
||||||
|
var edit = tinymce.render({
|
||||||
|
elem: "#policy",
|
||||||
|
images_upload_url: "/app/admin/upload/image",
|
||||||
|
});
|
||||||
|
edit.on("blur", function(){
|
||||||
|
layui.$("#policy").val(edit.getContent());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 字段 创建时间 created_at
|
||||||
|
layui.use(["laydate"], function() {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#created_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 更新时间 updated_at
|
||||||
|
layui.use(["laydate"], function() {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#updated_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 deleted_at deleted_at
|
||||||
|
layui.use(["laydate"], function() {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#deleted_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
//提交事件
|
||||||
|
layui.use(["form", "popup"], function () {
|
||||||
|
// 字段验证允许为空
|
||||||
|
layui.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)$)/, "请输入正确的身份证号"]
|
||||||
|
});
|
||||||
|
layui.form.on("submit(save)", function (data) {
|
||||||
|
layui.$.ajax({
|
||||||
|
url: INSERT_API,
|
||||||
|
type: "POST",
|
||||||
|
dateType: "json",
|
||||||
|
data: data.field,
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
180
plugin/admin/app/view/user-policy/update.html
Normal file
180
plugin/admin/app/view/user-policy/update.html
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-cn">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>更新页面</title>
|
||||||
|
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css"/>
|
||||||
|
<link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css"/>
|
||||||
|
<link rel="stylesheet" href="/app/admin/admin/css/reset.css"/>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form class="layui-form">
|
||||||
|
|
||||||
|
<div class="mainBox">
|
||||||
|
<div class="main-container mr-5">
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">Key Policies</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<textarea id="policy" name="policy" class="layui-textarea"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">创建时间</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="created_at" id="created_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">更新时间</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="updated_at" id="updated_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">deleted_at</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="deleted_at" id="deleted_at" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</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?v=2.8.12"></script>
|
||||||
|
<script src="/app/admin/component/pear/pear.js"></script>
|
||||||
|
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
|
||||||
|
<script src="/app/admin/admin/js/permission.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// 相关接口
|
||||||
|
const PRIMARY_KEY = "id";
|
||||||
|
const SELECT_API = "/app/admin/user-policy/select" + location.search;
|
||||||
|
const UPDATE_API = "/app/admin/user-policy/update";
|
||||||
|
|
||||||
|
// 获取数据库记录
|
||||||
|
layui.use(["form", "util", "popup"], function () {
|
||||||
|
let $ = layui.$;
|
||||||
|
$.ajax({
|
||||||
|
url: SELECT_API,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (res) {
|
||||||
|
|
||||||
|
// 给表单初始化数据
|
||||||
|
layui.each(res.data[0], function (key, value) {
|
||||||
|
let obj = $('*[name="' + key + '"]');
|
||||||
|
if (key === "password") {
|
||||||
|
obj.attr("placeholder", "不更新密码请留空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof obj[0] === "undefined" || !obj[0].nodeName) return;
|
||||||
|
if (obj[0].nodeName.toLowerCase() === "textarea") {
|
||||||
|
obj.val(value);
|
||||||
|
} else {
|
||||||
|
obj.attr("value", value);
|
||||||
|
obj[0].value = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 字段 Key Policies policy
|
||||||
|
layui.use(["tinymce"], function () {
|
||||||
|
var tinymce = layui.tinymce
|
||||||
|
var edit = tinymce.render({
|
||||||
|
elem: "#policy",
|
||||||
|
images_upload_url: "/app/admin/upload/image",
|
||||||
|
});
|
||||||
|
edit.on("blur", function () {
|
||||||
|
layui.$("#policy").val(edit.getContent());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 字段 创建时间 created_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#created_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 更新时间 updated_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#updated_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// 字段 deleted_at deleted_at
|
||||||
|
layui.use(["laydate"], function () {
|
||||||
|
layui.laydate.render({
|
||||||
|
elem: "#deleted_at",
|
||||||
|
type: "datetime",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// ajax返回失败
|
||||||
|
if (res.code) {
|
||||||
|
layui.popup.failure(res.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//提交事件
|
||||||
|
layui.use(["form", "popup"], function () {
|
||||||
|
// 字段验证允许为空
|
||||||
|
layui.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)$)/, "请输入正确的身份证号"]
|
||||||
|
});
|
||||||
|
layui.form.on("submit(save)", function (data) {
|
||||||
|
data.field[PRIMARY_KEY] = layui.url().search[PRIMARY_KEY];
|
||||||
|
layui.$.ajax({
|
||||||
|
url: UPDATE_API,
|
||||||
|
type: "POST",
|
||||||
|
dateType: "json",
|
||||||
|
data: data.field,
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user