### Initialize Layui Modules Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/molds-list.html Initializes necessary Layui modules for UI components like date pickers, pagination, and layers. This setup is required before using these components. ```javascript layui.use(['laydate','element','laypage','layer'], function(){ $ = layui.jquery;//jquery laydate = layui.laydate;//日期插件 lement = layui.element;//面包导航 // laypage = layui.laypage;//分页 layer = layui.layer;//弹出层 //以上模块根据需要引入 }); ``` -------------------------------- ### SQL Query Examples for Content Filtering Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/editcache.html Demonstrates various SQL syntaxes for filtering content based on IDs, categories, and keywords. Ensure strings are enclosed in English single quotes. ```sql id in(1,2,3) ``` ```sql tid in(2,3,4) ``` ```sql title like '%网站建设%' ``` ```sql (title like '%网站建设%' or body like '%网站建设%' ) ``` ```sql title='网站建设' ``` -------------------------------- ### Initialize layui form module Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/collecttype-list.html Initializes the layui form module for use in the page. This is a standard setup for layui-based forms. ```javascript layui.use(['form'], function(){ form = layui.form; }); ``` -------------------------------- ### Plugin Action Handler Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/plugins-list.html Handles the installation, uninstallation, and deletion of plugins via AJAX. Displays confirmation messages and reloads the page upon successful completion. ```JavaScript function actionDo(path,type){ var type = parseInt(type); var msg = ''; if(type==0){ msg = '{fun JZLANG('确定要卸载?')}'; }else if(type==1){ msg = '{fun JZLANG('确定要安装?')}'; }else{ msg = '{fun JZLANG('确定要删除?')}'; } layer.confirm(msg,function(index){ $.ajax({ url:"{fun U('action_do')}", dataType:"json", async:true, data:{path:path,type:type}, type:"POST", beforeSend:function(){ //请求前的处理 if(parseInt(type)==1){ layer.msg('{fun JZLANG('正在安装中,请稍等~')}'); }else if(parseInt(type)==-1){ layer.msg('{fun JZLANG('正在删除中,请稍等~')}'); }else{ layer.msg('{fun JZLANG('正在卸载中,请稍等~')}'); } }, success:function(res){ layer.closeAll(); //请求成功时处理 if(res.code==0){ layer.msg(res.msg,{icon: 1,time:1000},function(){ window.location.reload(); }) }else{ layer.alert(res.msg); } }, complete:function(){ //请求完成的处理 }, error:function(){ //请求出错处理 } }) }) } ``` -------------------------------- ### Plugin List Table Headers Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/plugins-list.html Displays the headers for the plugin list table, including Plugin Name, Version, Author, Platform, Description, Plugin File, Status, Installation Instructions, and Actions. ```HTML {fun JZLANG('插件名')} {fun JZLANG('版本')} {fun JZLANG('作者')} {fun JZLANG('平台')} {fun JZLANG('简介')} {fun JZLANG('插件文件')} {fun JZLANG('开关')} {fun JZLANG('安装说明')} {fun JZLANG('操作')} ``` -------------------------------- ### Displaying Product Details (JizhiCMS Template) Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/showlabel.html Use the $jz variable to access detailed properties of a product item, including SEO fields, price, stock, images, and author information. Includes an example of incrementing hit count. ```JizhiCMS Template 商品标题:{!--$jz['title']--} 当前位置:{!--$positions--} 商品SEO标题:{!--$jz['seo_title']--} 商品关键词:{!--$jz['keywords']--} 商品点击量:{!--$jz['hits']--}自增操作{!--fun incrData('product',$jz['id'],'hits')--} 商品主图:{!--$jz['litpic']--} 商品价格:{!--$jz['price']--} 商品库存:{!--$jz['stock_num']--} 商品简介:{!--$jz['description']--} 商品内容:{!--$jz['body']--} 商品上传管理员:{!--fun adminInfo($jz['userid'],'name')--} 商品更新时间:{!--fun date('Y-m-d',$jz['addtime'])--} 其他字段内容统一输出:{!--$v[字段参数]--} ``` -------------------------------- ### Template List Item Rendering Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/template-list.html Iterates through a list of templates to display their details, including name, author, type, version, and description. Conditional logic handles different template statuses (installed, local, third-party) and update availability. ```html {foreach $lists as $v}* []({$v['web']}) {$v['name']} {fun JZLANG('作者:')}{$v['author']} {if($v['official']==1)}{fun JZLANG('官方')}{else if($v['official']==2)}{fun JZLANG('本地')}{else}{fun JZLANG('第三方')}{/if} 【 {$v['template']} 】 v{$v['version']}{if($v['isupdate'])} {fun JZLANG('有更新')}{/if} {$v['description']} {if($v['install'])} {fun JZLANG('已使用')} {fun JZLANG('备份数据')} {else if($v['official']==2)} {fun JZLANG('安装模板')} {else} {fun JZLANG('下载')} {/if} {/foreach} ``` -------------------------------- ### Template List Filtering and Navigation Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/template-list.html Provides navigation links for filtering templates by 'All', 'Local', and includes a refresh button. The 'All' link navigates to the general template index, while 'Local' filters for locally installed templates. ```html [{fun JZLANG('全部')}]({fun U('Template/index')}) [{fun JZLANG('本地')}]({fun U('Template/index',['isdown'=>1]}) __ __ ``` -------------------------------- ### Plugin List Table Row Data Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/plugins-list.html Populates a row in the plugin list table with plugin details and action buttons. Includes version, author, platform, description, file path, status, and conditional actions for installation, configuration, uninstallation, deletion, and download. ```HTML {$v['name']} v{$v['version']}{if($v['isupdate'])}{fun JZLANG('新')}{/if} {$v['author']} {if($v['official']==1)}{fun JZLANG('官方')}{else if($v['official']==2)}{fun JZLANG('本地')}{else}{fun JZLANG('第三方')}{/if} {$v['description']} {$v['filepath']} {if(checkAction('Plugins/change_status'))} {if($v['isinstall'])} {else} - {/if} {else} - {/if} {if(checkAction('Plugins/desc') && $v['exists'])}{fun JZLANG('安装说明')}{else} - {/if} {if(checkAction('Plugins/action_do'))} {if($v['isinstall'])} {fun JZLANG('配置')} [{fun JZLANG('导出')}]({fun U('plugins/output',['filepath'=>$v['filepath']])}) {fun JZLANG('卸载')} {fun JZLANG('删除')} {else if($v['exists'])} {fun JZLANG('安装')} {fun JZLANG('删除')} {else} {fun JZLANG('下载')} {/if} {else} - {/if} ``` -------------------------------- ### Displaying Article/Content Details (JizhiCMS Template) Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/showlabel.html Use the $jz variable to access detailed properties of an article or general content item, including SEO fields, hits, images, and author information. Includes an example of incrementing hit count. ```JizhiCMS Template 文章标题:{!--$jz['title']--} 当前位置:{!--$positions--} 文章SEO标题:{!--$jz['seo_title']--} 文章关键词:{!--$jz['keywords']--} 文章点击量:{!--$jz['hits']--}自增操作{!--fun incrData('article',$jz['id'],'hits')--} 文章缩略图:{!--$jz['litpic']--} 文章简介:{!--$jz['description']--} 文章内容:{!--$jz['body']--} 文章作者:{!--fun adminInfo($jz['userid'],'name')--} 文章更新时间:{!--fun date('Y-m-d',$jz['addtime'])--} 其他字段内容统一输出:{!--$v[字段参数]--} ``` -------------------------------- ### Initiate Database Backup Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/beifen.html Redirects the user to the backup URL to initiate a database backup process. ```javascript function beifen(){ window.location.href="{fun U('Index/backup')}"; } ``` -------------------------------- ### Get Fields for Ruler Edit Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/ruler-edit.html Retrieves fields for the ruler edit form. This function is called when the page loads. ```javascript get_fields(0,{$data['id']}); ``` -------------------------------- ### Product Add Form Initialization Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/product-add.html Initializes form elements and event listeners for the product add form using Layui framework. Includes submission handling, category selection logic, and local data caching. ```javascript $(function() { get_fields({$tid}); get_fields_ext({$tid}); }) layui.use(['laydate','form','layer','upload'], function(){ var $ = layui.jquery ,form = layui.form ,layer = layui.layer; laydate = layui.laydate; var upload = layui.upload; //监听提交 form.on('submit(save)', function(data){ if($("#tids").length>0){ var tids_str = tids_obj.getValue('valueStr'); if(tids_str!=''){ data.field.tids = ','+tids_str+','; } } $.post("{fun U('addproduct')}",data.field,function(r){ localStorage.setItem('cachedata', ''); var r = JSON.parse(r); if(r.code==0){ layer.confirm(r.msg, { btn: ['{fun JZLANG('返回')}','{fun JZLANG('确定')}'] //按钮 }, function(){ {if($webconf['admintpl']=='tpl')} window.location.href="{fun U('Product/productlist')}"; {else} parent.location.reload(); parent.layer.close(index); {/if} }, function(){ window.location.href=r.url; }); }else{ layer.alert(r.msg, {icon: 5}); } }); return false; }); //监听选择 form.on('select(tid)', function(data){ var alldata = form.val("jizhiform"); localStorage.setItem('cachedata', JSON.stringify(alldata)); get_fields(data.value); get_fields_ext(data.value); }); $("#resetdata").click(function(){ var alldata = localStorage.getItem('cachedata'); if(alldata!=''){ form.val("jizhiform",JSON.parse(alldata)); } }) }); ``` -------------------------------- ### Initialize Rich Text Editor with Image/Video Uploads Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/common/content.html Initializes a wangEditor instance with configurations for image and video uploads, including server settings, file constraints, and custom insert functions. Use this to set up the editor for rich content creation. ```javascript $(document).ready(function (){ var html = document.getElementById("editor-content-textarea-body").value var E_body = window.wangEditor // 切换语言 E_body.i18nChangeLanguage("zh-CN") window.editor = E_body.createEditor({ selector: "#editor-text-area-body", html: html, config: { placeholder: "请输入内容...", MENU_CONF: { uploadImage: { fieldName: "file", server: "{fun U('common/uploads')}", // 单个文件的最大体积限制,默认为 2M maxFileSize: 100 * 1024 * 1024, // 100M // 最多可上传几个文件,默认为 100 maxNumberOfFiles: 100, allowedFileTypes: ["image/*"], // 超时时间,默认为 10 秒 timeout: 10 * 60 * 1000, // 5 秒 // 单个文件上传成功之后 //onSuccess(file: File, res: any) { // TS 语法 onSuccess(file, res) { // JS 语法 console.log(`${file.name} 上传成功`, res) if(res.code!=0){ alert(res.error) } }, // 单个文件上传失败 //onFailed(file: File, res: any) { // TS 语法 onFailed(file, res) { // JS 语法 console.log(`${file.name} 上传失败`, res) }, // 上传错误,或者触发 timeout 超时 //onError(file: File, err: any, res: any) { // TS 语法 onError(file, err, res) { // JS 语法 console.log(`${file.name} 上传出错`, err, res) }, //customInsert(res: any, insertFn: InsertFnType) { // TS 语法 customInsert(res, insertFn) { // JS 语法 // res 即服务端的返回结果 console.log(res,insertFn) // 从 res 中找到 url alt href ,然后插入图片 insertFn(res.url) }, }, uploadVideo: { fieldName: "file", server: "{fun U('common/uploads')}", // 单个文件的最大体积限制,默认为 2M maxFileSize: 10000 * 1024 * 1024 * 1024, // 10000G // 最多可上传几个文件,默认为 100 maxNumberOfFiles: 100, allowedFileTypes: ["video/*"], // 超时时间,默认为 10 秒 timeout: 30 * 60 * 1000, // 30 分钟 // 单个文件上传成功之后 //onSuccess(file: File, res: any) { // TS 语法 onSuccess(file, res) { // JS 语法 console.log(`${file.name} 上传成功`, res) if(res.code!=0){ alert(res.error) } }, // 单个文件上传失败 //onFailed(file: File, res: any) { // TS 语法 onFailed(file, res) { // JS 语法 console.log(`${file.name} 上传失败`, res) }, // 上传错误,或者触发 timeout 超时 //onError(file: File, err: any, res: any) { // TS 语法 onError(file, err, res) { // JS 语法 console.log(`${file.name} 上传出错`, err, res) }, //customInsert(res: any, insertFn: InsertFnType) { // TS 语法 customInsert(res, insertFn) { // JS 语法 // res 即服务端的返回结果 console.log(res,insertFn) // 从 res 中找到 url alt href ,然后插入图片 insertFn(res.url) }, }, }, onChange(editor) { var html = editor.getHtml() var num = 0, reg = /
( | \s+)+<\/p>|
(
)+<\/p>/g;
while (num < html.length && html != "") {
num++;
let k = html.match(reg);
if (k) {
html = html.replace(k[0], "");
}
}
document.getElementById("editor-content-textarea-body").value = html
}
}
})
})
```
--------------------------------
### Delete Permission Confirmation
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/power-list.html
Implements a confirmation dialog for deleting a permission. Upon confirmation, it sends an asynchronous GET request to delete the permission and updates the UI.
```javascript
/*删除*/
function ruler_del(obj,id){
layer.confirm('{fun JZLANG(\'确认要删除吗?\')}',function(index){
$.get("{\}\__APP\_URL\}\/Member/deleterulers/id/"+id,{},function(r){
var r = JSON.parse(r);
if(r.code==0){
//发异步删除数据
$(obj).parents("tr").remove();
layer.msg(r.msg,{icon: 1,time:1000});
window.location.reload();
}else{
layer.msg(r.msg,{icon: 5,time:1000});
}
})
});
}
```
--------------------------------
### Get Current Navigation Array
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/desktop-add.html
Retrieves the appropriate navigation data array (top or left) based on the provided navigation type identifier (1 for left, other for top).
```javascript
function getCurrentNav(n){
var n = parseInt(n);
if(n==1){
return leftNav;
}else{
return topNav;
}
}
```
--------------------------------
### Layui Form Initialization and Event Handling
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/plugins-list.html
Initializes Layui form elements and sets up event listeners for status switches and download submissions. Handles AJAX requests for changing plugin status and initiating plugin downloads.
```JavaScript
layui.use(['laydate','form'], function(){
var laydate = layui.laydate;
var form = layui.form;
form.on('switch(status)', function (data) {
$.post("{fun U('change_status')}",{filepath:data.elem.value},function(r){});
});
form.on('submit(down)', function (data) {
var filepath = $(data.elem).attr('data');
var download_url = $(data.elem).attr('data-'+filepath+'-url');
$("#"+filepath+"-downbutton").hide();
$("#"+filepath+"-down-action").show();
var othis = $("#"+filepath+"-down-action");
var DISABLED = 'layui-btn-disabled';
if(othis.hasClass(DISABLED)) return;
//获取文件大小
$.ajax({
url:"{fun U('plugins/update')}",
data:{action:'prepare-download',filepath:filepath,download_url:download_url},
async : false,
type : "POST",
dataType:'json',
success:function(res){
if(res.code==0){
$(data.elem).attr('data-'+filepath+'-size',res.size);
}else{
layer.alert('{fun JZLANG('获取文件大小失败,请检查网络!')}');
return false;
}
}
});
$.post("{fun U('plugins/update')}",{action:'start-download',filepath:filepath,download_url:download_url},function(res){
//开始下载
console.log(res);
},'json');
//模拟loading
var n = 0, timer = setInterval(function(){
$.post("{fun U('plugins/update')}",{action:'get-file-size',filepath:filepath,download_url:download_url},function(res){
console.log(res);
var cur_size = parseInt(res.size);
console.log(cur_size);
var filesize = parseInt($(data.elem).attr('data-'+filepath+'-size'));
n = Math.round(cur_size/filesize)*100;
if(filesize==cur_size){
n = 90;//只加载到90%,剩下10%解压
//"#down-text".html('插件下载完成');
console.log('插件下载完成,正在解压~');
clearInterval(timer);
othis.removeClass(DISABLED);
element.progress('demo-'+filepath+'-progress', n+'%');
$.post("{fun U('plugins/update')}",{filepath:filepath,download_url:download_url,'filesize':$(data.elem).attr('data-'+filepath+'-size'),'action':'file-upzip'},function(res){
if(res.code==0){
//"#down-text".html('插件已下载完毕!');
console.log('插件已解压完毕!');
element.progress('demo-'+filepath+'-progress', '100%');
window.location.reload();
}else{
layer.msg(res.msg);
return false;
}
},'json');
}
element.progress('demo-'+filepath+'-progress', n+'%');
},'json');
}, 1000);
return false;
});
});
```
--------------------------------
### Initialize Layui Modules and Form Handling
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/cache.html
Initializes necessary layui modules and sets up a form submission listener for cache clearing. This code should be used when interacting with the cache clearing functionality.
```javascript
layui.use(['laydate','form','layer','upload'], function(){
$ = layui.jquery;
var form = layui.form ,
layer = layui.layer;
laydate = layui.laydate;
var upload = layui.upload;
form.render();
//监听提交
form.on('submit(formDemo)', function(data){
if(JSON.stringify(data.field)=="{}"){
layer.msg('{fun JZLANG('请选择清空目标!')}');
}
$.post("{fun U('Index/cleanCache')}",data.field,function(r){
//console.log(r);return false;
var r = JSON.parse(r);
if(r.code==0){
layer.confirm('{fun JZLANG('清理成功!')}', function(){
window.location.reload();
});
}else{
layer.alert(r.msg, {icon: 5});
}
});
return false;
})
})
```
--------------------------------
### Document Ready Initialization
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/static/cms/user/article-add.html
Initializes the category and field fetching logic when the document is ready. It sets up event listeners for changes in the mold and tid select elements.
```javascript
$(document).ready(function(){
getclass($('#molds').val());
"#molds".change(function () {
var molds = $('#molds').val();
if(molds==''){
return false;
}
getclass(molds)
});
"#tid".change(function () {
{if($data)} var id = {$data['id']};
{else} var id = 0;
{/if}
var tid = "#tid".val();
get_fields(tid,id)
});
});
```
--------------------------------
### Initialize Layui Modules
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/beifen.html
Initializes necessary Layui modules for date, element, pagination, and layer components. JQuery is aliased to $.
```javascript
layui.use(['laydate','element','laypage','layer'], function(){
var $ = layui.jquery;//jquery
var laydate = layui.laydate;//日期插件
var element = layui.element;//面包导航
var laypage = layui.laypage;//分页
var layer = layui.layer;//弹出层
});
```
--------------------------------
### Initialize Layui Table for Order List
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/order-list.html
Renders the order list table using Layui. It configures data fetching, pagination, and column definitions. The 'done' callback updates order count summaries.
```javascript
layui.use(['laydate','form','element','laypage','layer','table'], function(){
var $= layui.jquery;//jquery
var laydate = layui.laydate;//日期插件
var lement = layui.element;//面包导航
var layer = layui.layer;//弹出层
var form = layui.form;
var table = layui.table;
//执行一个laydate实例
laydate.render({
elem: '#start' //指定元素
});
//执行一个laydate实例
laydate.render({
elem: '#end' //指定元素
});
table.render({
elem: '#jizhi_table'
,height: 700
,url: window.location.href+'?ajax=1' //数据接口
,page: true //开启分页
,size:'lg'
,count:100
,toolbar:"#toolbar"
,data:{}
,page: {
//支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
//,curr: 5 //设定初始在第 5 页
,groups: 5 //只显示 1 个连续页码
,first: true //显示首页
,last: true //显示尾页
,count:500
,limit:10
,first: '{fun JZLANG(\'首页\')}' //不显示首页
,last: '{fun JZLANG(\'尾页\')}' //不显示尾页
}
,done: function(res, curr, count){
//如果是异步请求数据方式,res即为你接口返回的信息。
//如果是直接赋值的方式,res即为:{data: [], count: 99}
//data为当前页数据、count为数据总长度
console.log(res);
$("#all_num").html(res.all);
$("#overpay_num").html(res.overpay_num);
$("#notpay_num").html(res.notpay_num);
$("#allmoney").html(res.allmoney);
}
,cols: [[
//表头
{type:'checkbox'}
,{field: 'id', title: 'ID', width:60}
,{field: 'isshow', title: '{fun JZLANG(\'状态\')}', width: 100, templet: '#isshow'}
,{field: 'orderno', title: '{fun JZLANG(\'订单号\')}'}
,{field: 'paytype', title: '{fun JZLANG(\'付款方式\')}'}
,{field: 'username', title: '{fun JZLANG(\'用户昵称\')}'}
,{field: 'tel', title: '{fun JZLANG(\'手机号\')}',width:150}
,{field: 'price', title: '{fun JZLANG(\'金额\')}',width:150}
,{field: 'jifen', title: '{fun JZLANG(\'积分\')}',width:150}
{foreach $fields_list as $v},{field: '{$v["field"]}', title: '{$v["fieldname"]}'}{/foreach}
,{field: 'ispay', title: '{fun JZLANG(\'是否付款\')}', width: 100, templet: '#ispay'}
,{field: 'new_paytime', title: '{fun JZLANG(\'付款时间\')}',width:160}
,{field: 'new_addtime', title: '{fun JZLANG(\'提交时间\')}',width:160}
,{field: '', title: '{fun JZLANG(\'操作\')}',width:160, toolbar: '#rightbar', fixed:'right'}
]]
});
table.on('tool(jizhi_table)', function(obj){
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的DOM对象
switch(layEvent){
case 'edit':
//console.log(data);
x_admin_show('{fun JZLANG(\'查看\')}',data.edit_url);
break;
case 'view':
break;
case 'delete':
layer.confirm('{fun JZLANG(\'确认要删除吗?\')}',function(index){
$.post("{fun U('Order/deleteorder')}",{id:data.id},function(r){
var r = JSON.parse(r);
if(r.code==0){
//发异步删除数据
$(tr).remove();
layer.msg(r.msg,{icon: 1,time:1000},function(){
table.reload('jizhi_table', {
url:
});
});
}
});
});
break;
}
});
});
```
--------------------------------
### Layui Initialization and Form Handling
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/member-edit.html
Initializes Layui components including form, layer, upload, and laydate. Sets up image upload functionality and handles form submission for member edits.
```javascript
layui.use(['form','layer','upload','laydate'], function(){
$ = layui.jquery;
var form = layui.form, layer = layui.layer, laydate = layui.laydate, upload = layui.upload;
laydate.render({
elem: '#birthday' //指定元素
});
//图片上传接口
upload.render({
elem: '#litpic_upload',
url: "{fun U('Common/uploads')}" //上传接口
,data:{molds:'member'}
,done: function(res){
//上传成功后的回调
if(res.code==0){
$('#litpic_img').attr('src',res.url);
$('#litpic').val(res.url);
}
else{
layer.alert(res.error, {icon: 5});
}
}
});
//监听提交
form.on('submit(add)', function(data){
console.log(data);
$.post("{fun U('Member/memberedit')}",data.field,function(res){
var r = JSON.parse(res);
if(r.code==0){
//发异步,把数据提交给php
layer.msg("{fun JZLANG('修改成功')}", {icon: 6,time:2000},function () {
{if($webconf['admintpl']=='tpl')}
window.location.href="{fun U('Member/index')}";
{else}
parent.layer.closeAll();
{/if}
});
}
else{
layer.msg(r.msg);
}
})
return false;
});
get_fields(0,{$data['id']});
get_fields_ext(0,{$data['id']});
});
```
--------------------------------
### Initialize Layui Table for Recycle Bin
Source: https://github.com/cherry-toto/jizhicms/blob/2.0/app/admin/t/tpl/recycle-list.html
Renders the data table for the recycle bin using layui. It configures data fetching, pagination, column definitions, and event listeners for row-level operations.
```javascript
layui.use(['laydate','form','element','laypage','layer','table'], function(){
var $ = layui.jquery;//jquery
var laydate = layui.laydate;//日期插件
var lement = layui.element;//面包导航
var layer = layui.layer;//弹出层
var form = layui.form;
var table = layui.table;
table.render({
elem: '#jizhi_table'
,height: 700
,url: window.location.href+'?ajax=1' //数据接口
,page: true //开启分页
,size:'lg'
,count:100
,toolbar:"#toolbar"
,data:{}
,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
//,curr: 5 //设定初始在第 5 页
,groups: 5 //只显示 1 个连续页码
,first: true //显示首页
,last: true //显示尾页
,count:500
,limit:10
}
,cols: [[
{field: 'id', title: 'ID', width:60}
,{type:'checkbox'}
,{field: 'title', title: '{fun JZLANG("标记")}'}
,{field: 'moldsname', title: '{fun JZLANG("模型")}'}
{if(checkAction('Recycle/restore') || checkAction('Recycle/del'))}
,{field: '', title: '{fun JZLANG("操作")}', toolbar: '#rightbar',width:200, fixed:'right'}
{/if}
]]
});
table.on('tool(jizhi_table)', function(obj){
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的DOM对象
switch(layEvent){
case 'restore':
layer.confirm('{fun JZLANG('你确定要还原吗?')}',function(index){
$.post("{fun U('Recycle/restore')}",{id:data.id},function(r){
var r = JSON.parse(r);
if(r.code==0){
//发异步删除数据
$(tr).remove();
layer.msg(r.msg,{icon: 1,time:1000},function(){
table.reload('jizhi_table', {
url: window.location.href+'?ajax=1'
,where: {} //设定异步数据接口的额外参数
});
});
}else{
layer.msg(r.msg,{icon: 5,time:1000});
}
})
});
break;
case 'delete':
layer.confirm('{fun JZLANG('确认要删除吗?删除后就彻底无法恢复了!')}',function(index){
$.post("{fun U('Recycle/del')}",{id:data.id},function(r){
var r = JSON.parse(r);
if(r.code==0){
//发异步删除数据
$(tr).remove();
layer.msg(r.msg,{icon: 1,time:1000},function(){
table.reload('jizhi_table', {
url: window.location.href+'?ajax=1'
,where: {} //设定异步数据接口的额外参数
});
});
}else{
layer.msg(r.msg,{icon: 5,time:1000});
}
})
});
break;
}
});
table.on('checkbox(jizhi_table)', function(obj){
var checkStatus = table.checkStatus('jizhi_table'); //idTest 即为基础参数 id 对应的值
var len = checkStatus.data.length;
var arr=[];
if(len>0){
for(var i=0;i