1751 lines
69 KiB
JavaScript
1751 lines
69 KiB
JavaScript
/**
|
||
*ZMP
|
||
*加载之外的扩展
|
||
*/
|
||
var _token = $('#token').attr('content');
|
||
|
||
layui.config({
|
||
base: '/static/manager/extend/'
|
||
}).extend({
|
||
iconPicker: 'iconPicker'
|
||
});
|
||
|
||
layui.use(['element','form','carousel','layer','laydate'], function(){
|
||
var element = layui.element,//导航的hover效果、二级菜单等功能,需要依赖element模块
|
||
form = layui.form,iconPicker = layui.iconPicker,layer=layui.layer,laydate=layui.laydate,carousel = layui.carousel;
|
||
element.render();
|
||
form.render();
|
||
/**
|
||
* ZMP
|
||
* @desc 权限列表的全选与不全选
|
||
*/
|
||
|
||
$('.perm-read-only').each(function(){
|
||
$(this).prop("checked", true);
|
||
form.render();
|
||
})
|
||
|
||
form.on('checkbox(parents)', function(data){
|
||
if($(this).hasClass('perm-read-only')){
|
||
data.elem.checked=true;
|
||
}
|
||
var a = data.elem.checked,
|
||
$childCheck=$(this).parents(".rules-group").children(".layui-card-body").find('input[type="checkbox"]'); //所有子复选框
|
||
if (a) {
|
||
$($childCheck).prop("checked", true);
|
||
} else {
|
||
$($childCheck).each(function(){
|
||
if(!$(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", false);
|
||
}
|
||
})
|
||
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
form.on('checkbox(childrens)', function (data) {
|
||
var $parentCheck = $(this).parents(".rules-group").find(".layui-card-header").find('input[type="checkbox"]'), //所属父复选框
|
||
$brotherCheck = $(this).parent(".layui-card-body").find('input[type="checkbox"]');//同级子复选框
|
||
var status = true;
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
//只要存在一个子选项被选中则复选项状态修改为选中
|
||
$brotherCheck.each(function () {
|
||
if (this.checked && !$(this).hasClass('perm-read-only')) {
|
||
status = true;
|
||
}
|
||
});
|
||
if (status) {
|
||
$($parentCheck).prop('checked', true);
|
||
} else {
|
||
$($parentCheck).prop('checked', false);
|
||
}
|
||
form.render('checkbox');
|
||
|
||
});
|
||
|
||
// layui-table 全选操作(默认选中的用perm-read-only类标识,默认禁选用disabled="disabled"标识)
|
||
form.on('checkbox(select_all)', function(data){
|
||
var parentTableCheck = $(this).parents(".layui-table").find('input[lay-filter="select_all"]'); //所属全选复选框
|
||
var childrenCheck = $(this).parents(".layui-table").find('input[lay-filter="select_item"]'); //所属子同复选框
|
||
if(data.elem.checked) {
|
||
$(childrenCheck).each(function(){
|
||
if (!$(this).prop('disabled')) {
|
||
$(this).prop("checked", true);
|
||
}
|
||
});
|
||
} else {
|
||
$(childrenCheck).each(function(){
|
||
if(!$(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", false);
|
||
}
|
||
});
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
// layui-table 单个选择操作
|
||
form.on('checkbox(select_item)', function(data){
|
||
var parentTableCheck = $(this).parents(".layui-table").find('input[lay-filter="select_all"]'); //所属全选复选框
|
||
var brotherCheck = $(this).parents(".layui-table").find('input[lay-filter="select_item"]'); //所属同级复选框
|
||
var allChecked = true;
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
brotherCheck.each(function () {
|
||
if (!$(this).prop("disabled") && !$(this).hasClass('perm-read-only')) {
|
||
if (!$(this).prop("checked")) {
|
||
allChecked = false;
|
||
}
|
||
}
|
||
});
|
||
if(allChecked) {
|
||
parentTableCheck.prop('checked', true);
|
||
} else {
|
||
parentTableCheck.prop('checked', false);
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
|
||
|
||
//栏目分类 编辑页面 模型修改事件
|
||
form.on('select(cate-model)', function (data) {
|
||
//获取原始选中value
|
||
var select_value = $('.cate-model').data('selected');
|
||
// 获取文本
|
||
// console.log($(data.elem).find("option:selected").text());
|
||
//当前选中value
|
||
var curr_value = data.value;
|
||
if (select_value != curr_value) { // 斗笔layui.form 实现一个onchange都这么麻烦
|
||
//提示
|
||
layer.alert('更改栏目类型提交后,将清空旧有栏目下所有数据,请谨慎操作', {
|
||
skin: 'layui-layer-molv'
|
||
,closeBtn: 0
|
||
});
|
||
}
|
||
});
|
||
|
||
var answerCount = $('#answer-count').data('count');
|
||
$('.add-answer').click(function () {
|
||
var html = '<div class="layui-form-item">';
|
||
html += '<label class="layui-form-label"></label>';
|
||
html += '<div class="layui-col-md8">';
|
||
html += '<div class="layui-col-md8">';
|
||
html += '<textarea class="layui-textarea" name="answer['+ answerCount +'][content]" rows="5"></textarea>';
|
||
html += '</div>';
|
||
html += '<div class="layui-col-md2">';
|
||
html += '<input type="checkbox" name="answer['+ answerCount +'][right]" title="正确答案" lay-skin="primary">';
|
||
html += '</div>';
|
||
html += '<div class="layui-col-md2">';
|
||
html += '<a class="close-answer" href="javascript:;"><i class="layui-icon">ဆ</i></a>';
|
||
html += '</div></div></div>';
|
||
$('.add-answer-btn').before(html);
|
||
answerCount ++;
|
||
form.render('checkbox');
|
||
});
|
||
$('body').on('click', '.close-answer', function () {
|
||
$(this).parent().parent().remove();
|
||
});
|
||
|
||
|
||
/**
|
||
* ZMP
|
||
* @desc 表格复选框操作(每个页面仅限一个input[lay-filter="childrens-table"]表格表单)
|
||
*/
|
||
var values=[];
|
||
form.on('checkbox(parents-table)', function(data){
|
||
var a = data.elem.checked,
|
||
$childCheck=$(this).parents(".layui-table").find('input[lay-filter="childrens-table"]');//所有子复选框
|
||
values = [];
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
if (a) {
|
||
$($childCheck).each(function(){
|
||
if (!$(this).prop('disabled')) {
|
||
$(this).prop("checked", true);
|
||
values.push($(this).val());
|
||
}
|
||
})
|
||
} else {
|
||
$($childCheck).each(function(){
|
||
if($(this).hasClass('perm-read-only')) {
|
||
$(this).prop("checked", true);
|
||
values.push($(this).val());
|
||
} else {
|
||
$(this).prop("checked", false);
|
||
}
|
||
})
|
||
values=[];
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
form.on('checkbox(childrens-table)', function (data) {
|
||
var $parentCheck = $(this).parents(".layui-table").find('input[lay-filter="parents-table"]'), //所属父复选框
|
||
$brotherCheck = $(this).parents(".layui-table").find('input[lay-filter="childrens-table"]');//同级子复选框
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
var status = false;
|
||
if(data.elem.checked){
|
||
values.push(data.value)
|
||
}else{
|
||
var index = values.indexOf(data.value);
|
||
values.splice(index, 1);
|
||
}
|
||
$brotherCheck.each(function () {
|
||
if (!this.checked) {
|
||
status = true;
|
||
}
|
||
});
|
||
if($($parentCheck).hasClass('perm-read-only')) {
|
||
$($parentCheck).prop('checked', true);
|
||
} else if (status) {
|
||
$($parentCheck).prop('checked', false);
|
||
} else {
|
||
$($parentCheck).prop('checked', true);
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
|
||
// 角色分配权限
|
||
form.on('checkbox(parent-rule)', function(data){
|
||
var a = data.elem.checked,
|
||
$childCheck=$(this).parents(".layui-table").find('input[lay-filter="children-rule"]');//所有子集
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
if (a) {
|
||
$($childCheck).each(function(){
|
||
if (!$(this).prop('disabled')) {
|
||
$(this).prop("checked", true);
|
||
}
|
||
})
|
||
} else {
|
||
$($childCheck).each(function(){
|
||
if($(this).hasClass('perm-read-only')) {
|
||
$(this).prop("checked", true);
|
||
} else {
|
||
$(this).prop("checked", false);
|
||
}
|
||
})
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
form.on('checkbox(children-rule)', function (data) {
|
||
var $parentCheck = $(this).parents(".layui-table").find('input[lay-filter="parent-rule"]'), // 父级
|
||
$brotherCheck = $(this).parents(".layui-table").find('input[lay-filter="children-rule"]');// 子级
|
||
if($(this).hasClass('perm-read-only')){
|
||
$(this).prop("checked", true);
|
||
}
|
||
var allChecked = false;
|
||
$brotherCheck.each(function () {
|
||
var isShow = $(this).data('show');
|
||
var name = $(this).data('name');
|
||
var nameSplit = name.split('/');
|
||
if (this.checked && ((parseInt(isShow) > 0 || (nameSplit.length > 0 && nameSplit[nameSplit.length - 1] == 'index')) || $($parentCheck).prop('checked'))) {
|
||
allChecked = true;
|
||
}
|
||
});
|
||
if($($parentCheck).hasClass('perm-read-only')) {
|
||
$($parentCheck).prop('checked', true);
|
||
} else if (allChecked) {
|
||
$($parentCheck).prop('checked', true);
|
||
} else {
|
||
$($parentCheck).prop('checked', false);
|
||
}
|
||
form.render('checkbox');
|
||
});
|
||
|
||
|
||
// 批量删除(单页仅限一个input[lay-filter="parents-table"] 表格表单)
|
||
if($('.delAll').length > 0){
|
||
$('.delAll').click(function(){
|
||
if (values.length > 0){
|
||
var url = $(this).data('url');
|
||
layerConfirm('primary','确定删除?',url,{"ids":values})
|
||
} else {
|
||
layer.msg('请选择需要操作的数据')
|
||
}
|
||
});
|
||
}
|
||
// 批量设置(单页仅限一个checkTable设置类表格表单)
|
||
if($('.setAll').length > 0){
|
||
$('.setAll').click(function(){
|
||
var result = [];
|
||
var setCheck = $(".checkTable").find('input[lay-filter="childrens-table"]');
|
||
setCheck.each(function () {
|
||
if ($(this).prop('checked')) {
|
||
result.push($(this).val());
|
||
}
|
||
});
|
||
if (result.length > 0){
|
||
var url = $(this).data('url');
|
||
layerConfirm('primary','确定需要对选中的数据进行设置吗?',url,{"ids":result})
|
||
} else {
|
||
layer.msg('请选择需要操作的数据')
|
||
}
|
||
});
|
||
}
|
||
// 文章批量操作
|
||
if($('.batch_all').length > 0){
|
||
$('.batch_all').click(function(){
|
||
if (values.length > 0){
|
||
var url = $(this).data('url');
|
||
var title = $(this).attr('title')
|
||
batch_box_show(url,values,'','','',title);
|
||
} else {
|
||
layer.msg('请选择需要操作的数据')
|
||
}
|
||
})
|
||
}
|
||
// 单文章属性批量操作
|
||
if($('.batch_btn').length > 0){
|
||
$('.batch_btn').click(function(){
|
||
var url = $(this).data('url');
|
||
var id = $(this).data('id');
|
||
var top = $(this).data('top');
|
||
var hot = $(this).data('hot');
|
||
var recommend = $(this).data('recommend');
|
||
var title = $(this).attr('title')
|
||
batch_box_show(url,id,top,hot,recommend,title);
|
||
})
|
||
}
|
||
// 耗时操作
|
||
if($('.btn-long-time').length > 0) {
|
||
$('.btn-long-time').click(function () {
|
||
layer.msg('这是一个耗时操作!请耐心等待...', {time: 1500});
|
||
var loading = layer.load(2, {shade: false});
|
||
var url = $(this).data('url');
|
||
var refresh = parseInt($(this).data('refresh'));
|
||
$.ajax({
|
||
url: url,
|
||
data: {_token:_token},
|
||
type: 'POST',
|
||
dataType: 'json',
|
||
timeout: 10000,
|
||
success: function(data){
|
||
layer.close(loading);
|
||
if (data.code == 0){
|
||
if($('.operate-result').length > 0) {
|
||
$('.operate-result').text(data.msg);
|
||
}
|
||
layer.msg('操作成功!', {time: 1500});
|
||
if (refresh > 0) {
|
||
setTimeout(function () {
|
||
location.reload();
|
||
}, 3000);
|
||
}
|
||
} else {
|
||
layer.msg(data.msg);
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
layer.close(loading);
|
||
layer.msg('操作失败!', {time: 1500});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
// 文件批量删除(按路径)
|
||
if($('.file-del').length > 0) {
|
||
$('.file-del').click(function () {
|
||
var vals = new Array();
|
||
var tableId = $(this).data('filter');
|
||
var url = $(this).data('url');
|
||
$('#'+tableId).find('.select_item').each(function () {
|
||
if($(this).prop('checked')) {
|
||
vals.push($(this).val());
|
||
}
|
||
});
|
||
if (vals.length > 0){
|
||
layerConfirm('primary','确定删除?',url,{"paths":vals})
|
||
} else {
|
||
layer.msg('请选择需要操作的数据')
|
||
}
|
||
});
|
||
}
|
||
|
||
//获取hash来切换选项卡,假设当前地址的hash为lay-id对应的值
|
||
var layid = location.hash.replace(/^#site=/, '');
|
||
element.tabChange('site', layid); //假设当前地址为:http://a.com#site=222,那么选项卡会自动切换到“发送消息”这一项
|
||
//监听Tab切换,以改变地址hash值
|
||
element.on('tab(site)', function(){
|
||
location.hash = 'site='+ this.getAttribute('lay-id');
|
||
});
|
||
form.on('submit(submitAll)', function(data){
|
||
var url=$(data.elem).parents('form').data('action')
|
||
|
||
if(typeof(editor)!=='undefined'){
|
||
|
||
//data.field.content=editor.getData()
|
||
}
|
||
formSubmit(url,data.field)
|
||
return false
|
||
});
|
||
form.verify({
|
||
require: function(value, item){ //value:表单的值、item:表单的DOM对象
|
||
if(!value){
|
||
var masg= $(item).attr('placeholder');
|
||
return masg;
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
//属性功能
|
||
function batch_box_show(url,values,top,hot,recommend,title){
|
||
var html = '<div class="batch_box" style="overflow: hidden;"><div class="between-center layui-col-md12 layui-form" style="padding:30px 20px 15px;">'+
|
||
'<div class="layui-form-item">'+
|
||
'<label class="layui-form-label" style="width: auto;">置顶:</label>'+
|
||
'<div class="layui-input-block" style="margin-left: 45px;">'+
|
||
'<select name="top" class="layui-select">'
|
||
if(top != undefined && top != '' || title != '批量属性'){
|
||
if(top == 'top'){
|
||
html += '<option value="1" selected>是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}else{
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2" selected>否</option>'
|
||
}
|
||
}else{
|
||
html += '<option value="0">请选择</option>'
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}
|
||
html += '</select>'+
|
||
'</div>'+
|
||
'</div>'+
|
||
'<div class="layui-form-item" style="margin-left:10px;">'+
|
||
'<label class="layui-form-label" style="width: auto;">热门:</label>'+
|
||
'<div class="layui-input-block" style="margin-left: 45px;">'+
|
||
'<select name="hot" class="layui-select">'
|
||
if(hot != undefined && hot != '' || title != '批量属性'){
|
||
if(hot == 'hot'){
|
||
html += '<option value="1" selected>是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}else{
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2" selected>否</option>'
|
||
}
|
||
}else{
|
||
html += '<option value="0">请选择</option>'
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}
|
||
html += '</select>'+
|
||
'</div>'+
|
||
'</div>'+
|
||
'<div class="layui-form-item" style="margin-left:10px;">'+
|
||
'<label class="layui-form-label" style="width: auto;">推荐:</label>'+
|
||
'<div class="layui-input-block" style="margin-left: 45px;">'+
|
||
'<select name="recommend" class="layui-select">'
|
||
if(recommend != undefined && recommend != '' || title != '批量属性'){
|
||
if(recommend == 'recommend'){
|
||
html += '<option value="1" selected>是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}else{
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2" selected>否</option>'
|
||
}
|
||
}else{
|
||
html += '<option value="0">请选择</option>'
|
||
html += '<option value="1">是</option>'
|
||
html += '<option value="2">否</option>'
|
||
}
|
||
html += '</select>'+
|
||
'</div>'+
|
||
'</div>'+
|
||
'</div>'+
|
||
'<div class="layui-clear"></div>'+
|
||
'<hr style="margin: 0 0 30px;">'+
|
||
'<div class="layui-form-item" style="margin:0 0 30px;">'+
|
||
'<div class="text-center">'+
|
||
'<button type="button" class="layui-btn layui-btn-normal" data-url="'+url+'" data-id="'+values+'" onclick="betch_form(this)">保存</button>'+
|
||
'</div>'+
|
||
'</div></div>';
|
||
layer.open({
|
||
type: 1,
|
||
title: title,
|
||
shadeClose: true,
|
||
area: ['480px',''], //宽高
|
||
move: false,
|
||
content: html,
|
||
success:function(layero, index) {
|
||
alertRender()
|
||
}
|
||
});
|
||
}
|
||
function betch_form(obj){
|
||
var id = $(obj).attr('data-id');
|
||
var url = $(obj).attr('data-url');
|
||
var top = $(".batch_box select[name='top']").val();
|
||
var hot = $(".batch_box select[name='hot']").val();
|
||
var recommend = $(".batch_box select[name='recommend']").val();
|
||
var arr = new Array();
|
||
$.each(id.split(','),function(i,item){
|
||
arr.push(item)
|
||
})
|
||
$.ajax(url,{
|
||
data:{
|
||
id:arr,
|
||
top:top,
|
||
hot:hot,
|
||
recommend:recommend,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if (data.code == 0){
|
||
layer.msg('操作成功!');
|
||
location.reload();
|
||
} else {
|
||
layer.msg(data.msg);
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 推荐、置顶、热门操作
|
||
*/
|
||
if ($('.recommend').length > 0) {
|
||
$('.recommend').click(function () {
|
||
var id = $(this).data('id');
|
||
var param = $(this).data('param');
|
||
var url = $(this).data('url');
|
||
$.post(url,{id:id,param:param,_token:_token},function(data){
|
||
if(data.code == 0){
|
||
layer.msg('操作成功', {time:1000}, function (index) {
|
||
layer.close(index);
|
||
location.reload();
|
||
});
|
||
}else{
|
||
layer.msg(data.msg, {time:1500});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 删除操作
|
||
*/
|
||
if($('.del').length > 0){
|
||
$('.del').click(function(){
|
||
var that = $(this);
|
||
var tip = '';
|
||
if(that.data('tip') != '' && that.data('tip') != undefined){
|
||
tip = that.data('tip')
|
||
}
|
||
layerConfirm('primary','确定删除'+tip+'?',that.data('url'),{id:that.data('id')})
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 日期插件
|
||
* milo
|
||
* 2018-01-30
|
||
*/
|
||
if($('.layui-date').length) {
|
||
$('.layui-date').each(function(){
|
||
id = '#' + $(this).attr('id');
|
||
layui.use('laydate',function(){
|
||
var laydate = layui.laydate;
|
||
laydate.render({
|
||
elem: id
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
//排序操作
|
||
if($('.sort').length > 0){
|
||
$('.sort').click(function(){
|
||
var url = $(this).data('url');
|
||
var id = $(this).data('id');
|
||
var sort = $(this).data('sort');
|
||
$.post(url,{id:id,sort:sort,_token:_token},function(data){
|
||
if(data.code == 0){
|
||
layer.msg('排序成功', {time:1000}, function (index) {
|
||
location.reload();
|
||
});
|
||
}else{
|
||
layer.msg(data.msg, {time:1500});
|
||
}
|
||
});
|
||
});
|
||
var timeout;
|
||
$(".sort").mousedown(function() {
|
||
var title = '信息';
|
||
var id = $(this).attr('data-id');
|
||
var url = $(this).data('url');
|
||
var sort = $(this).attr('data-sort');
|
||
if($(this).attr('data-sort') == 'up'){
|
||
title = '向上'
|
||
}
|
||
if($(this).attr('data-sort') == 'down'){
|
||
title = '向下'
|
||
}
|
||
timeout = setTimeout(function() {
|
||
layer.prompt({
|
||
formType: 0,
|
||
value: '',
|
||
placeholder:'请输入位数',
|
||
title: title
|
||
}, function(value, index, elem){
|
||
$.ajax(url,{
|
||
data:{
|
||
id:id,
|
||
sort:sort,
|
||
num:value,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
layer.msg('排序成功');
|
||
location.reload();
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
layer.close(index);
|
||
});
|
||
}, 1000);
|
||
});
|
||
$(".sort").mouseup(function() {
|
||
clearTimeout(timeout);
|
||
});
|
||
$(".sort").mouseout(function() {
|
||
clearTimeout(timeout);
|
||
});
|
||
}
|
||
//图片点击放大
|
||
layer.photos({
|
||
photos: '.layer-photos'
|
||
,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
|
||
});
|
||
//视频弹出
|
||
$('.layer-video').click(function(){
|
||
var that = $(this);
|
||
var videoUrl = that.find('video').attr('src');
|
||
layer.open({
|
||
type:2,
|
||
title:false,
|
||
area:['640px','340px'],
|
||
shade:0.8,
|
||
closeBtn:0,
|
||
shadeClose:true,
|
||
content:videoUrl
|
||
})
|
||
})
|
||
/**
|
||
* 弹出层调用方法
|
||
* 20158-1-6 赵虹
|
||
*/
|
||
// if (!$('.modleOpen').size()) {
|
||
$('.modleOpen').click(function(event) {
|
||
var content = $(this).data('href');//需要弹出的层的名字
|
||
var title = $(this).data('title');//需要显示的title名称
|
||
modleOpen(content,title);
|
||
|
||
});
|
||
// }
|
||
/**
|
||
* 弹出层调用方法
|
||
* 20158-1-6 赵虹
|
||
* @param {[type]} title [需要弹出的层的名字]
|
||
* @return {[type]} [需要显示的title名称]
|
||
*/
|
||
function modleOpen(content,title){
|
||
// console.log($('.' + content).html());
|
||
layer.open({
|
||
type: 1,
|
||
skin: 'layui-layer-demo', //样式类名
|
||
anim: 5,
|
||
area: ['500px', 'auto'],
|
||
shadeClose: true, //开启遮罩关闭
|
||
title: title,
|
||
content: $('.' + content).html()
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 侧边栏折叠效果
|
||
* ZMP
|
||
* @param {isMenufold} 判断导航栏是否打开
|
||
*
|
||
*/
|
||
var _isMenufold=false,_t;
|
||
$('.layui-side').on('click','li',function(){
|
||
$('#tip-menu').remove()
|
||
var str='<div id="tip-menu" style="top:'+$(this).offset().top+'px;">'+
|
||
'<ul class="layui-nav layui-nav-tree">'+$(this).find('ul').first().html()+'</ul></div>'
|
||
if(_isMenufold){
|
||
$(this).removeClass('layui-nav-itemed')
|
||
$('body').append(str)
|
||
layui.element.render('nav');
|
||
time(3000)
|
||
}
|
||
})
|
||
function time(tim){
|
||
_t= setTimeout(function(){
|
||
if($('#tip-menu').length > 0) {
|
||
$('#tip-menu').remove()
|
||
}
|
||
},tim)
|
||
}
|
||
$('html').on('mouseenter mouseleave','#tip-menu',function(e){
|
||
if(e.type=='mouseenter' ){
|
||
clearTimeout(_t)
|
||
}else{
|
||
time(200)
|
||
}
|
||
})
|
||
$('#menu-fold').click(function(){
|
||
_isMenufold=!_isMenufold
|
||
if(_isMenufold){
|
||
$('body').attr('id','menu-salce')
|
||
$('.layui-nav-tree .layui-this,.layui-nav .layui-nav-item').removeClass('layui-nav-itemed')
|
||
$(this).css('left','0px')
|
||
}else{
|
||
$("body").removeAttr("id");
|
||
$(this).css('left','180px')
|
||
$('.layui-side li.layui-this').addClass('layui-nav-itemed')
|
||
$('li.layui-this').parents('li .layui-nav-item').addClass('layui-nav-itemed')
|
||
}
|
||
})
|
||
|
||
$('.layui-lv2').find('a.one .layui-nav-more').click(function(){
|
||
// $('.layui-nav-item.layui-lv2').removeClass('layui-nav-itemed')
|
||
// if($(this).attr('class') != 'layui-nav-item layui-lv2 layui-nav-itemed'){
|
||
// $(this).addClass('layui-nav-itemed')
|
||
// }else{
|
||
// $(this).removeClass('layui-nav-itemed')
|
||
// }
|
||
if($(this).parent().attr('class') != 'one active'){
|
||
$(this).parent().addClass('active')
|
||
$(this).parent().parent().addClass('layui-nav-itemed')
|
||
$(this).parent().parent().find('.layui-nav-child').eq(0).show()
|
||
}else{
|
||
$(this).parent().removeClass('active')
|
||
$(this).parent().parent().removeClass('layui-nav-itemed')
|
||
$(this).parent().parent().find('.layui-nav-child').eq(0).hide()
|
||
}
|
||
return false;
|
||
})
|
||
|
||
/**
|
||
*高亮rgba(0,150,136,.2)
|
||
*ZMP
|
||
*/
|
||
$('.layui-side li.layui-this').addClass('layui-nav-itemed layui-this')
|
||
$('li.layui-this').parents('li .layui-nav-item').addClass('layui-nav-itemed layui-this')
|
||
$('#refresh').click(function(){
|
||
window.location.reload()
|
||
})
|
||
var leftMenu=$('.layui-nav-tree .layui-this'),opticy=4;
|
||
// function LightColor(menu,num){
|
||
// let that=this;
|
||
// menu.find('a:first').css('background-color','rgba(0,150,136,.'+num+')')
|
||
// menu.each(function(){
|
||
// if($(this).children('ul').length>0){
|
||
// let child=$(this).find('li.layui-this')
|
||
// num=num-1
|
||
// LightColor(child,num)
|
||
// }else{
|
||
// $(this).find('a:first').css('background-color','rgba(0,150,136,.'+num+')')
|
||
// }
|
||
// })
|
||
// }
|
||
// LightColor(leftMenu,opticy)
|
||
|
||
// 弹窗表单刷新
|
||
//编辑或者添加按钮
|
||
$('a.layui-btn').click(function() {
|
||
var text=$(this).attr('title')
|
||
var $href=$(this).data('href')
|
||
var width=$(this).data('width')
|
||
var state=$(this).data('state')
|
||
var that = $(this)
|
||
if($href && text){
|
||
layerAlert('get',text,$href,'',width,state,that)
|
||
}
|
||
})
|
||
/**
|
||
* 弹窗重新渲染的内容
|
||
* @param filter lay-filter
|
||
* @param iconName 图标名称,自动识别fontClass/unicode
|
||
*/
|
||
function alertRender(){
|
||
layui.use(['form','iconPicker'], function(){
|
||
var form=layui.form,iconPicker=layui.iconPicker
|
||
form.render();
|
||
iconPicker.render({
|
||
// 选择器,推荐使用input
|
||
elem: '#iconPicker',
|
||
// 数据类型:fontClass/unicode,推荐使用fontClass
|
||
type: 'fontClass',
|
||
// 是否开启搜索:true/false
|
||
search: true,
|
||
// 是否开启分页
|
||
page: true,
|
||
// 每页显示数量,默认12
|
||
limit: 12,
|
||
// 点击回调
|
||
click: function (data) {
|
||
},
|
||
// 渲染成功后的回调
|
||
success: function(d) {
|
||
$('#iconPicker').val('iconpicker');
|
||
}
|
||
});
|
||
var iconStr = $('#iconPicker').val();
|
||
if (iconStr) {
|
||
iconPicker.checkIcon('iconPicker', iconStr);
|
||
} else {
|
||
iconPicker.checkIcon('iconPicker', 'layui-icon-star-fill');
|
||
}
|
||
})
|
||
setTimeout(function(){
|
||
$(window).trigger("resize");
|
||
},100)
|
||
}
|
||
// alert弹窗方法
|
||
function layerAlert(type,text,href,parms,width,state,that){
|
||
if(width == undefined || width == ''){
|
||
width = 900
|
||
}
|
||
var load = layer.load(2);
|
||
$.ajax({
|
||
type: type,
|
||
url: href,
|
||
data: {_token:_token},
|
||
success: function(data){
|
||
if (data.code !== undefined && !isNaN(data.code) && data.code != 0) {
|
||
layer.close(load);
|
||
layer.msg(data.msg, {time: 2000})
|
||
} else {
|
||
layer.open({
|
||
type: 1,
|
||
title: text,
|
||
shadeClose: true,
|
||
area: ''+width+'px', //宽高
|
||
maxmin: true,
|
||
move: false,
|
||
content: data,
|
||
success:function(layero, index) {
|
||
layer.close(load);
|
||
alertRender()
|
||
editor();
|
||
codeEditor()
|
||
layui_select_show();
|
||
//判断弹框内容高度
|
||
if($(window).height()-180 < $('.layui-layer-content .layui-card-body').height()){
|
||
layer.style(index,{
|
||
height:$(window).height() - 80,
|
||
top:40
|
||
})
|
||
$('.layui-layer-content').height($(window).height()-123)
|
||
$('.layui-layer-content').css('max-height','85vh');
|
||
$('.eject-layuiBox').height($(window).height()-123)
|
||
$('.eject-layuiBox').css('max-height','85vh');
|
||
}else{
|
||
$('.layui-layer-content').css('max-height','79vh');
|
||
$('.eject-layuiBox').css('max-height','79vh');
|
||
}
|
||
if(state == 'edit'){
|
||
var syg = 0;
|
||
var xyg = 0;
|
||
if(that.attr('class') == 'layui-btn layui-btn-warm layui-btn-xs' || that.attr('class') == 'layui-btn layui-btn-title'){
|
||
syg = that.closest('tr').index()-1;
|
||
xyg = that.closest('tr').index()+1;
|
||
}else{
|
||
syg = parseInt(that.attr('data-xyg'))-1;
|
||
xyg = parseInt(that.attr('data-xyg'))+1;
|
||
}
|
||
var sygurl;
|
||
var xygurl;
|
||
if(syg >= 0){
|
||
$('table tbody tr').eq(syg).find('.layui-btn').each(function(i){
|
||
if($(this).attr('data-state') == 'edit'){
|
||
sygurl = $(this).attr('data-href')
|
||
}
|
||
})
|
||
}
|
||
$('table tbody tr').eq(xyg).find('.layui-btn').each(function(i){
|
||
if($(this).attr('data-state') == 'edit'){
|
||
xygurl = $(this).attr('data-href')
|
||
}
|
||
})
|
||
$('body').append('<div class="layui-edit-btn center-center" style="z-index:'+$('.layui-layer-shade').css("z-index")+'"><div class="between-center" style="width:'+(parseInt(width)+300)+'px">'+
|
||
'<div class="prev" title="编辑" data-xyg="'+syg+'" data-href="'+sygurl+'" data-state="edit" onclick="edit_page(this)"></div>'+
|
||
'<div class="next" title="编辑" data-xyg="'+xyg+'" data-href="'+xygurl+'" data-state="edit" onclick="edit_page(this)"></div>'+
|
||
'</div></div>');
|
||
if(syg < 0){
|
||
$('.layui-edit-btn .between-center .prev').css({'opacity':'0','pointer-events':'none'})
|
||
}
|
||
if(xyg == $('table tbody tr').length){
|
||
$('.layui-edit-btn .between-center .next').css({'opacity':'0','pointer-events':'none'})
|
||
}
|
||
}
|
||
},
|
||
end:function(){
|
||
if(state == 'edit'){
|
||
$('.layui-edit-btn').remove();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
// $.get(href,parms,function(data){
|
||
// console.log(data)
|
||
|
||
// });
|
||
|
||
}
|
||
//编辑左右翻页
|
||
function edit_page(obj){
|
||
layer.closeAll();
|
||
var text=$(obj).attr('title')
|
||
var $href=$(obj).data('href')
|
||
var width=$(obj).data('width')
|
||
var state=$(obj).data('state')
|
||
var that = $(obj)
|
||
if($href && text){
|
||
layerAlert('get',text,$href,'',width,state,that)
|
||
}
|
||
}
|
||
|
||
//ajax确认弹窗方法
|
||
/**
|
||
* type {table,primary} 使用在layuitable里面还是外面
|
||
* title 弹窗标题
|
||
* url ajax链接
|
||
*/
|
||
function layerConfirm(type,title,url,usedata) {
|
||
layer.confirm(title, {
|
||
btn: ['确定','取消'] //按钮
|
||
}, function(){
|
||
usedata._token=_token;
|
||
$.post(url,usedata,function(data){
|
||
if (data.code == 0){
|
||
layer.msg('操作成功!');
|
||
if(type=='table'){
|
||
location.reload();
|
||
}else{
|
||
location.reload();
|
||
}
|
||
} else {
|
||
layer.msg(data.msg);
|
||
}
|
||
})
|
||
}, function(){
|
||
layer.msg('已取消!');
|
||
});
|
||
}
|
||
|
||
//表单ajax提交
|
||
function formSubmit(url,fromdata) {
|
||
if(fromdata._token != ''){
|
||
fromdata._token = _token;
|
||
}
|
||
$.post(url,fromdata,function(data) {
|
||
if(data.code==0){
|
||
layer.msg('提交成功!')
|
||
setTimeout(function(){
|
||
//var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
|
||
//parent.layer.close(index); //再执行关闭
|
||
parent.layer.closeAll();
|
||
parent.location.reload()
|
||
},500)
|
||
}else {
|
||
layer.msg(data.msg)
|
||
}
|
||
})
|
||
}
|
||
|
||
$('.upload-single').on('change',function(e){
|
||
var files=e.currentTarget.files;
|
||
var fileName = files[0].name;
|
||
if(fileName.split('.')[1].toLowerCase()!=='zip'){
|
||
layer.msg('文件格式错误!请上传ZIP格式文件', {icon: 5})
|
||
}else{
|
||
$(this).parents('.layui-form-item').find('.layui-form-mid').html(fileName)
|
||
}
|
||
})
|
||
$('button[form-submit]').on('click',function(e) {
|
||
var required=$(this).parents('form').find('[lay-verify="required"]'),isSubmit=true
|
||
required.each(function(index,item){
|
||
var name=$(item).parents('.layui-form-item').find('label').html()
|
||
if(!$(item).val()){
|
||
isSubmit=false
|
||
layer.msg(name+'不能为空!', {icon: 5})
|
||
return false
|
||
}
|
||
})
|
||
if(isSubmit){
|
||
$(this).parents('form').submit()
|
||
// var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
|
||
// parent.layer.close(index); //再执行关闭
|
||
// parent.location.reload()
|
||
}
|
||
})
|
||
$('.three-list li').each(function(index,item){
|
||
if($(item).find('ul').length>0){
|
||
$(item).children('a').addClass('has-c')
|
||
}
|
||
})
|
||
$('.three-list li a').click(function(){
|
||
if($(this).find('ul').eq(0).length>0){
|
||
if($(this).hasClass('active')){
|
||
$(this).removeClass('active')
|
||
}else{
|
||
$(this).addClass('active')
|
||
}
|
||
}
|
||
})
|
||
//图片删除
|
||
$('.upload.more').on('click','.multi_del',function(){
|
||
var that=this;
|
||
layer.confirm('是否删除?', {
|
||
btn: ['确认','取消'] //按钮
|
||
}, function(){
|
||
$(that).parents('div.img-item').remove();
|
||
layer.msg('删除成功');
|
||
}, function(){
|
||
layer.msg('已取消')
|
||
});
|
||
});
|
||
// 向前后调序
|
||
$('.upload.more').on('click','.operate a',function(e){
|
||
var curBtnClass=e.currentTarget.classList.value
|
||
var img=$(this).parents('.img-item').find('.item-src'),
|
||
curInput=$(this).parents('.img-item').find('input,textarea'), //当前所有inuput
|
||
$currentImg=img.attr('src'),
|
||
$curphoto=img.attr('photo-src'),
|
||
input=''//所有上一个或者下一个input
|
||
if(curBtnClass=='multi_up'){
|
||
var $prevDom=$(this).parents('.img-item').prev() //上一个图组
|
||
if($prevDom.length==0){
|
||
layer.msg('已到第一个了')
|
||
return false
|
||
}
|
||
var prevImg=$prevDom.find('.item-src'),//获取上一个
|
||
prev1=prevImg .attr('src'),
|
||
prevp=prevImg.attr('photo-src')
|
||
input=$prevDom.find('input,textarea') //上一个所有的input
|
||
img.attr({'src':prev1, //当前
|
||
'photo-src':prevp
|
||
})
|
||
prevImg.attr({'src':$currentImg, //上一张图
|
||
'photo-src':$curphoto
|
||
})
|
||
}else if(curBtnClass=='multi_down'){
|
||
var $nextDom=$(this).parents('.img-item').next()
|
||
if($nextDom.length==0){
|
||
layer.msg('已到最后一个了')
|
||
return false
|
||
}
|
||
var nextImg=$nextDom.find('.item-src')
|
||
next=nextImg .attr('src'), //获取下一个
|
||
nextp=nextImg.attr('photo-src')
|
||
input=$nextDom.find('input,textarea')
|
||
img.attr({'src':next, //当前
|
||
'photo-src':nextp
|
||
})
|
||
nextImg.attr({'src':$currentImg, //下一张图
|
||
'photo-src':$curphoto
|
||
})
|
||
}
|
||
curInput.each(function(index1,item1) {
|
||
var temp=$(item1).val();
|
||
$(item1).val($(input[index1]).val())
|
||
$(input[index1]).val(temp)
|
||
})
|
||
})
|
||
|
||
//富文本编辑器ckeditor,单页面可以添加多个,需要使用不同的ID
|
||
function editor(){
|
||
if($('.editor').length){
|
||
$.each($('.editor'),function(i){
|
||
var E = window.wangEditor;
|
||
var id = $(this).attr('id');
|
||
var wang = new E(this);
|
||
var $text1 = $(this).parent().find('textarea');
|
||
wang.customConfig.onchange = function (html) {
|
||
// 监控变化,同步更新到 textarea
|
||
$text1.val(html)
|
||
}
|
||
wang.customConfig.menus = [
|
||
'head', // 标题
|
||
'bold', // 粗体
|
||
'fontSize', // 字号
|
||
'fontName', // 字体
|
||
'italic', // 斜体
|
||
'underline', // 下划线
|
||
'strikeThrough', // 删除线
|
||
'foreColor', // 文字颜色
|
||
'backColor', // 背景颜色
|
||
'link', // 插入链接
|
||
'list', // 列表
|
||
'justify', // 对齐方式
|
||
'quote', // 引用
|
||
'emoticon', // 表情
|
||
'image', // 插入图片
|
||
'table', // 表格
|
||
'video', // 插入视频
|
||
'code', // 插入代码
|
||
'undo', // 撤销
|
||
'redo', // 重复
|
||
]
|
||
// 隐藏“网络图片”tab
|
||
wang.customConfig.showLinkImg = true
|
||
wang.customConfig.uploadFileName = 'wang_img[]'
|
||
wang.customConfig.showLinkVideo = true
|
||
|
||
wang.customConfig.uploadImgHooks = {
|
||
before: function (xhr, editor, files) {
|
||
// 图片上传之前触发
|
||
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,files 是选择的图片文件
|
||
// 如果返回的结果是 {prevent: true, msg: 'xxxx'} 则表示用户放弃上传
|
||
},
|
||
success: function (xhr, editor, result) {
|
||
// 图片上传并返回结果,图片插入成功之后触发
|
||
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
|
||
},
|
||
fail: function (xhr, editor, result) {
|
||
// 图片上传并返回结果,但图片插入错误时触发
|
||
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
|
||
},
|
||
error: function (xhr, editor) {
|
||
// 图片上传出错时触发
|
||
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
|
||
},
|
||
timeout: function (xhr, editor) {
|
||
// 图片上传超时时触发
|
||
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
|
||
},
|
||
// 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
|
||
// (但是,服务器端返回的必须是一个 JSON 格式字符串!!!否则会报错)
|
||
customInsert: function (insertImg, result, editor) {
|
||
// 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)
|
||
// insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果
|
||
console.log(result);
|
||
if(result.errno == 0) {
|
||
if(result.data.length > 0) {
|
||
$.each(result.data,function(i,val){
|
||
insertImg(val);
|
||
})
|
||
}
|
||
} else {
|
||
// 错误提示
|
||
layer.msg(result.data[0])
|
||
}
|
||
}
|
||
}
|
||
wang.customConfig.uploadImgParams = {_token:_token}
|
||
wang.customConfig.uploadVideoParams = {_token:_token}
|
||
|
||
//上传视频
|
||
wang.customConfig.uploadVideoServer = "/manager/upload/video.html"
|
||
|
||
wang.customConfig.uploadVideoHooks = {
|
||
customInsert: function (insertImg, result, editor) {
|
||
var url =result.data.src;//获取后台返回的url
|
||
insertImg(url);
|
||
}
|
||
};
|
||
|
||
wang.customConfig.uploadImgServer = '/manager/upload/wangImage.html'
|
||
wang.customConfig.customAlert = function (info) {
|
||
// info 是需要提示的内容
|
||
layer.msg(info)
|
||
}
|
||
wang.create();
|
||
wang.txt.html($text1.val())
|
||
$text1.val(wang.txt.html())
|
||
|
||
editorSelector = '.editor';
|
||
$(editorSelector + " .w-e-toolbar").eq(i).append('<div class="w-e-menu"><a class="_wangEditor_btn_fullscreen" onclick="window.wangEditor.fullscreen.toggleFullscreen(this)">全屏</a></div>');
|
||
window.wangEditor.fullscreen = {
|
||
// editor create之后调用
|
||
toggleFullscreen: function(editorSelector){
|
||
$(editorSelector).closest('.editor-text').toggleClass('fullscreen-editor')
|
||
if($(editorSelector).text() == '全屏'){
|
||
$(editorSelector).text('退出全屏');
|
||
}else{
|
||
$(editorSelector).text('全屏');
|
||
}
|
||
},
|
||
charu:function(obj){
|
||
insertHtmlAtCaret('<img src="'+$(obj).attr('src')+'">',$(obj).closest('.editor').find('.w-e-text'))
|
||
$(obj).closest('.editor').find('.w-e-panel-container').remove();
|
||
}
|
||
};
|
||
$(editorSelector + " .w-e-toolbar").eq(i).append('<div class="w-e-menu"><a class="_wangEditor_btn_viewsource'+i+'" data-id="'+i+'" onclick="window.wangEditor.viewsource.toggleViewsource(this)">源码</a></div>');
|
||
window.wangEditor.viewsource = {
|
||
toggleViewsource: function(editorSelector) {
|
||
$('.editor').each(function(i){
|
||
if($(editorSelector).attr('data-id') == i){
|
||
if($(editorSelector).text() == '源码'){
|
||
$(editorSelector).text('返回');
|
||
$(this).addClass('active')
|
||
$(this).parent().find('textarea.layui-textarea').removeClass('layui-hide')
|
||
}else{
|
||
$(editorSelector).text('源码');
|
||
$(this).removeClass('active')
|
||
$(this).parent().find('textarea.layui-textarea').addClass('layui-hide')
|
||
}
|
||
}
|
||
})
|
||
},recovery:function(editorSelector){
|
||
$('.editor').each(function(i){
|
||
if($(editorSelector).text() == '返回'){
|
||
editorHtml = $(editorSelector).closest('.editor').find('.w-e-text').html().replace(/</ig, "<").replace(/>/ig, ">").replace(/ /ig, " ");
|
||
$(editorSelector).text('源码');
|
||
$(editorSelector).closest('.editor').find('.w-e-text').html(editorHtml);
|
||
$(editorSelector).closest('.editor').parent().find('textarea').val(editorHtml)
|
||
}
|
||
})
|
||
}
|
||
};
|
||
$(editorSelector + " .w-e-toolbar").eq(i).append('<div class="w-e-menu"><a class="_wangEditor_btn_eliminate'+i+'" data-id="'+i+'" onclick="window.wangEditor.eliminate.toggleViewsource(this)">清除格式</a></div>');
|
||
window.wangEditor.eliminate = {
|
||
toggleViewsource: function(editorSelector) {
|
||
$('.editor').each(function(i){
|
||
if($(editorSelector).attr('data-id') == i){
|
||
var str = $(editorSelector).closest('.editor').find('.w-e-text').html();
|
||
str = str.replace(/<xml>[\s\S]*?<\/xml>/ig, '');
|
||
str = str.replace(/<style>[\s\S]*?<\/style>/ig, '');
|
||
str = str.replace(/<\/?[^>]*>/g, '');
|
||
str = str.replace(/[ | ]*\n/g, '\n');
|
||
str = str.replace(/ /ig, '');
|
||
$(editorSelector).closest('.editor').find('.w-e-text').html(str);
|
||
}
|
||
})
|
||
}
|
||
};
|
||
var that = $(this)
|
||
that.removeClass('active');
|
||
that.parent().find('textarea').addClass('layui-hide')
|
||
that.parent().find('textarea').on('input propertychange', function () {
|
||
that.find('.w-e-text').html($(this).val())
|
||
})
|
||
});
|
||
}
|
||
getblur();
|
||
}
|
||
//页面加载时,根据需要加载富文本编辑器
|
||
if($('.editor').length){
|
||
editor();
|
||
}
|
||
if($('.codeEditor').length){
|
||
codeEditor();
|
||
}
|
||
|
||
//代码编辑器
|
||
function codeEditor(){
|
||
$('.codeEditor').each(function(){
|
||
var myTextarea = $(this);
|
||
if($(this).parent().find('.CodeMirror').length == 0){
|
||
var CodeMirrorEditor = CodeMirror.fromTextArea(myTextarea[0], {
|
||
lineNumbers: true,
|
||
mode: "text/html",
|
||
matchBrackets: true
|
||
});
|
||
$('form.layui-form').find('button.layui-btn').hover(function(){
|
||
myTextarea.val(CodeMirrorEditor.getValue())
|
||
})
|
||
}
|
||
})
|
||
//弹框内容改变时自动居中
|
||
$(window).trigger("resize");
|
||
}
|
||
|
||
//自定义筛选功能
|
||
function layui_select_show(){
|
||
$('.layui-select.newStyle.eject').each(function(a){
|
||
var arr = new Array();
|
||
var html = ''
|
||
var that = $(this);
|
||
$.each(that.find('input.parameter').val().split(','),function(i,item){
|
||
if(item != ''){
|
||
html = '<span>'+item+'<i data-id="'+i+'" onclick="layui_select_del(this)"></i></span>'
|
||
that.find('.top_box').append(html)
|
||
arr.push(item);
|
||
that.find('.lower_box ul li').each(function(a){
|
||
if($(this).text() == item){
|
||
$(this).addClass('active')
|
||
}
|
||
});
|
||
}
|
||
})
|
||
that.hover(function(i){
|
||
that.find('.top_box span').each(function(i){
|
||
var that2 = $(this);
|
||
$(this).find('i').attr('data-id',i)
|
||
})
|
||
that.find('.top_box').attr('data-arr',that.find('input.parameter').val());
|
||
if(that.find('.top_box').attr('data-arr').split(',').length > 0){
|
||
arr.splice(0)
|
||
$.each(that.find('.top_box').attr('data-arr').split(','),function(i,item){
|
||
if(item != ''){
|
||
arr.push(item)
|
||
}
|
||
})
|
||
}
|
||
})
|
||
that.find('.lower_box ul li').click(function(b){
|
||
if($(this).attr('class') != 'active'){
|
||
$(this).addClass('active');
|
||
arr.push($(this).text())
|
||
$(this).closest('.layui-select.newStyle').find('input.parameter').val(arr);
|
||
html = '<span>'+$(this).text()+'<i data-id="" onclick="layui_select_del(this)"></i></span>'
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').attr('data-arr',arr)
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').append(html)
|
||
that.find('.top_box span').each(function(i){
|
||
$(this).find('i').attr('data-id',i)
|
||
})
|
||
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').eq($(this).index()).val($(this).attr('data-checkbox'));
|
||
}
|
||
|
||
}else{
|
||
$(this).removeClass('active');
|
||
var cs = $(this).attr('data-val');
|
||
$.each(arr,function(i,item){
|
||
if(cs == item){
|
||
arr.splice(i,1);
|
||
that.find('.top_box span').eq(i).remove();
|
||
}
|
||
})
|
||
$(this).closest('.layui-select.newStyle').find('input.parameter').val(arr);
|
||
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').eq($(this).index()).val('');
|
||
}
|
||
}
|
||
})
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').each(function(){
|
||
var that2 = $(this);
|
||
if($(this).val() != ''){
|
||
html = '<span>'+$(this).attr('data-val')+'<i data-id="'+$(this).index()+'" onclick="layui_select_del(this)"></i></span>'
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').append(html)
|
||
arr.push($(this).attr('data-val'));
|
||
that.find('.lower_box ul li').each(function(a){
|
||
if($(this).attr('data-val') == that2.attr('data-val')){
|
||
$(this).addClass('active')
|
||
}
|
||
});
|
||
}
|
||
})
|
||
that.find('input.parameter').val(arr);
|
||
}
|
||
})
|
||
}
|
||
$('.layui-select.newStyle').each(function(a){
|
||
var arr = new Array();
|
||
var html = ''
|
||
var that = $(this);
|
||
$.each(that.find('input.parameter').val().split(','),function(i,item){
|
||
if(item != ''){
|
||
html = '<span>'+item+'<i data-id="'+i+'" onclick="layui_select_del(this)"></i></span>'
|
||
that.find('.top_box').append(html)
|
||
arr.push(item);
|
||
that.find('.lower_box ul li').each(function(a){
|
||
if($(this).text() == item){
|
||
$(this).addClass('active')
|
||
}
|
||
});
|
||
}
|
||
})
|
||
that.hover(function(i){
|
||
that.find('.top_box span').each(function(i){
|
||
var that2 = $(this);
|
||
$(this).find('i').attr('data-id',i)
|
||
})
|
||
that.find('.top_box').attr('data-arr',that.find('input.parameter').val());
|
||
if(that.find('.top_box').attr('data-arr').split(',').length > 0){
|
||
arr.splice(0)
|
||
$.each(that.find('.top_box').attr('data-arr').split(','),function(i,item){
|
||
if(item != ''){
|
||
arr.push(item)
|
||
}
|
||
})
|
||
}
|
||
})
|
||
that.find('.lower_box ul li').click(function(b){
|
||
console.log($(this).attr('class'))
|
||
if($(this).attr('class') != 'active'){
|
||
$(this).addClass('active');
|
||
arr.push($(this).text())
|
||
$(this).closest('.layui-select.newStyle').find('input.parameter').val(arr);
|
||
html = '<span>'+$(this).text()+'<i data-id="" onclick="layui_select_del(this)"></i></span>'
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').attr('data-arr',arr)
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').append(html)
|
||
that.find('.top_box span').each(function(i){
|
||
$(this).find('i').attr('data-id',i)
|
||
})
|
||
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').eq($(this).index()).val($(this).attr('data-checkbox'));
|
||
}
|
||
|
||
}else{
|
||
$(this).removeClass('active');
|
||
var cs = $(this).attr('data-val');
|
||
$.each(arr,function(i,item){
|
||
if(cs == item){
|
||
arr.splice(i,1);
|
||
that.find('.top_box span').eq(i).remove();
|
||
}
|
||
})
|
||
$(this).closest('.layui-select.newStyle').find('input.parameter').val(arr);
|
||
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').eq($(this).index()).val('');
|
||
}
|
||
}
|
||
})
|
||
if(that.find('.checkbox_list').length > 0){
|
||
that.find('.checkbox_list input').each(function(){
|
||
var that2 = $(this);
|
||
if($(this).val() != ''){
|
||
html = '<span>'+$(this).attr('data-val')+'<i data-id="'+$(this).index()+'" onclick="layui_select_del(this)"></i></span>'
|
||
$(this).closest('.layui-select.newStyle').find('.top_box').append(html)
|
||
arr.push($(this).attr('data-val'));
|
||
that.find('.lower_box ul li').each(function(a){
|
||
if($(this).attr('data-val') == that2.attr('data-val')){
|
||
$(this).addClass('active')
|
||
}
|
||
});
|
||
}
|
||
})
|
||
that.find('input.parameter').val(arr);
|
||
}
|
||
})
|
||
function layui_select_del(obj){
|
||
var arr = new Array();
|
||
$.each($(obj).closest('.layui-select.newStyle').find('.top_box').attr('data-arr').split(','),function(i,item){
|
||
arr.push(item)
|
||
})
|
||
var cs = $(obj).parent().text();
|
||
arr.splice($(obj).attr('data-id'),1);
|
||
var string;
|
||
$.each(arr,function(i,item){
|
||
if(i == 0){
|
||
string = item
|
||
}else{
|
||
string += ','+item
|
||
}
|
||
})
|
||
$(obj).closest('.layui-select.newStyle').find('input.parameter').val(string);
|
||
$(obj).closest('.layui-select.newStyle').find('.lower_box ul li').each(function(i){
|
||
if($(this).text() == cs){
|
||
$(this).removeClass('active');
|
||
if($(obj).closest('.layui-select.newStyle').find('.checkbox_list').length > 0){
|
||
$(obj).closest('.layui-select.newStyle').find('.checkbox_list input').eq(i).val('');
|
||
}
|
||
}
|
||
});
|
||
$(obj).parent().remove();
|
||
}
|
||
|
||
//导航选中样式
|
||
$('.layui-lv2').each(function(){
|
||
if($(this).attr('class') == 'layui-nav-item layui-lv2 layui-this layui-nav-itemed'){
|
||
$(this).closest('.layui-lv1').removeClass('layui-this')
|
||
}
|
||
})
|
||
$('.layui-lv3').each(function(){
|
||
if($(this).attr('class') == 'layui-nav-item layui-lv3 layui-this layui-nav-itemed'){
|
||
$(this).closest('.layui-lv2').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv1').removeClass('layui-this')
|
||
$(this).closest('.layui-lv2').removeClass('layui-this')
|
||
}
|
||
})
|
||
$('.layui-lv4').each(function(){
|
||
if($(this).attr('class') == 'layui-nav-item layui-lv4 layui-this layui-nav-itemed'){
|
||
$(this).closest('.layui-lv2').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv3').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv1').removeClass('layui-this')
|
||
$(this).closest('.layui-lv2').removeClass('layui-this')
|
||
$(this).closest('.layui-lv3').removeClass('layui-this')
|
||
}
|
||
})
|
||
$('.layui-lv5').each(function(){
|
||
if($(this).attr('class') == 'layui-nav-item layui-lv5 layui-this layui-nav-itemed'){
|
||
$(this).closest('.layui-lv2').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv3').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv4').find('a.one').eq(0).addClass('active');
|
||
$(this).closest('.layui-lv1').removeClass('layui-this');
|
||
$(this).closest('.layui-lv2').removeClass('layui-this');
|
||
$(this).closest('.layui-lv3').removeClass('layui-this');
|
||
$(this).closest('.layui-lv4').removeClass('layui-this');
|
||
}
|
||
})
|
||
|
||
// 表格拖动功能
|
||
var curIndex = 0;
|
||
var newIndex = 0;
|
||
var sort;
|
||
$("table").sortable({
|
||
cursor: "move",
|
||
items: ".table-lv1", //只是li可以拖动
|
||
opacity: 0.6, //拖动时,透明度为0.6
|
||
revert: true, //释放时,增加动画
|
||
cancel:'.editor,a.layui-btn,input,.CodeMirror,textarea',
|
||
start: function(e,ui) {
|
||
curIndex = ui.item.index();
|
||
},
|
||
update: function(event, ui) { //更新排序之后
|
||
newIndex = ui.item.index();
|
||
if(curIndex > newIndex){
|
||
sort = 'up';
|
||
newIndex = curIndex - newIndex;
|
||
}else{
|
||
sort = 'down';
|
||
newIndex = newIndex - curIndex;
|
||
}
|
||
$.ajax(ui.item[0].dataset.url,{
|
||
data:{
|
||
id:ui.item[0].dataset.id,
|
||
sort:sort,
|
||
num:newIndex,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
layer.msg('排序成功');
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
$("tbody.table-lv1").sortable({
|
||
cursor: "move",
|
||
items: ".table-lv2", //只是li可以拖动
|
||
opacity: 0.6, //拖动时,透明度为0.6
|
||
revert: true, //释放时,增加动画
|
||
cancel:'.editor,a.layui-btn,input,.CodeMirror,textarea',
|
||
start: function(e,ui) {
|
||
curIndex = ui.item.index();
|
||
},
|
||
update: function(event, ui) { //更新排序之后
|
||
newIndex = ui.item.index();
|
||
if(curIndex > newIndex){
|
||
sort = 'up';
|
||
newIndex = curIndex - newIndex;
|
||
}else{
|
||
sort = 'down';
|
||
newIndex = newIndex - curIndex;
|
||
}
|
||
$.ajax(ui.item[0].dataset.url,{
|
||
data:{
|
||
id:ui.item[0].dataset.id,
|
||
sort:sort,
|
||
num:newIndex,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
layer.msg('排序成功');
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
$("tbody.table-lv2").sortable({
|
||
cursor: "move",
|
||
items: ".table-lv3", //只是li可以拖动
|
||
opacity: 0.6, //拖动时,透明度为0.6
|
||
revert: true, //释放时,增加动画
|
||
cancel:'.editor,a.layui-btn,input,.CodeMirror,textarea',
|
||
start: function(e,ui) {
|
||
curIndex = ui.item.index();
|
||
},
|
||
update: function(event, ui) { //更新排序之后
|
||
newIndex = ui.item.index();
|
||
if(curIndex > newIndex){
|
||
sort = 'up';
|
||
newIndex = curIndex - newIndex;
|
||
}else{
|
||
sort = 'down';
|
||
newIndex = newIndex - curIndex;
|
||
}
|
||
$.ajax(ui.item[0].dataset.url,{
|
||
data:{
|
||
id:ui.item[0].dataset.id,
|
||
sort:sort,
|
||
num:newIndex,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
layer.msg('排序成功');
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
var fwqpage = 2;
|
||
function getImgList(id){
|
||
var html = '';
|
||
var pageBtn = '';
|
||
fwqpage = 1;
|
||
$.ajax('/manager/file/list',{
|
||
data:{
|
||
type:'img',
|
||
page:fwqpage,
|
||
size:20,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
if(data.data.length > 0){
|
||
$.each(data.data,function(i,item){
|
||
html += '<span><img src="'+item.src+'" onclick="window.wangEditor.fullscreen.charu(this)"></span>'
|
||
})
|
||
$('#'+id).closest('.editor').find('.w-e-serverImgs .top-box').append(html)
|
||
if(data.data.length >= 20){
|
||
pageBtn = '<a href="javascript:;" data-id="'+id+'" onclick="getImgMore(this)">加载更多</a>';
|
||
$('#'+id).closest('.editor').find('.w-e-serverImgs .lower-box').append(pageBtn)
|
||
}
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
function getImgMore(obj){
|
||
var html = '';
|
||
var pageBtn = '';
|
||
var id = $(obj).attr('data-id');
|
||
$.ajax('/manager/file/list',{
|
||
data:{
|
||
type:'img',
|
||
page:fwqpage,
|
||
size:20,
|
||
_token:_token
|
||
},
|
||
dataType:'json',//服务器返回json格式数据
|
||
type:'post',//HTTP请求类型
|
||
timeout:10000,//超时时间设置为10秒;
|
||
success:function(data){
|
||
if(data.code == 0){
|
||
if(data.data.length > 0){
|
||
$.each(data.data,function(i,item){
|
||
html += '<span><img src="'+item.src+'" onclick="window.wangEditor.fullscreen.charu(this)"></span>'
|
||
})
|
||
$('#'+id).closest('.editor').find('.w-e-serverImgs .top-box').append(html)
|
||
if(data.data.length < 20){
|
||
pageBtn = '没有了';
|
||
$('#'+id).closest('.editor').find('.w-e-serverImgs .lower-box').html(pageBtn)
|
||
}else{
|
||
fwqpage++
|
||
}
|
||
}else{
|
||
layer.msg(data.msg)
|
||
}
|
||
}
|
||
},
|
||
error:function(xhr,type,errorThrown){
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
var sel,range;
|
||
var textContent;
|
||
function getblur(){
|
||
$('.editor .w-e-text').click(function(){
|
||
sel = window.getSelection();
|
||
range = sel.getRangeAt(0);
|
||
//range.deleteContents();
|
||
})
|
||
}
|
||
function insertHtmlAtCaret(html,obj){
|
||
if (window.getSelection) {
|
||
// IE9 and non-IE
|
||
if(sel != undefined){
|
||
if (sel.getRangeAt && sel.rangeCount) {
|
||
var el = document.createElement("div");
|
||
el.innerHTML = html;
|
||
var frag = document.createDocumentFragment(), node, lastNode;
|
||
while ((node = el.firstChild)) {
|
||
lastNode = frag.appendChild(node);
|
||
}
|
||
range.insertNode(frag);
|
||
// Preserve the selection
|
||
if (lastNode) {
|
||
range = range.cloneRange();
|
||
range.setStartAfter(lastNode);
|
||
range.collapse(true);
|
||
sel.removeAllRanges();
|
||
sel.addRange(range);
|
||
}
|
||
}
|
||
}else{
|
||
$(obj).append(html)
|
||
}
|
||
} else if (document.selection && document.selection.type != "Control") {
|
||
// IE < 9
|
||
document.selection.createRange().pasteHTML(html);
|
||
}
|
||
textContent=$(obj).html();//这个也很重要。因为如果不写可能就会覆盖了原来内容替换成你添加的。或者是干脆不显示了。textContent是全局变量是你输入的内容。
|
||
$(obj).closest('.editor').parent().find('textarea').val(textContent)
|
||
}
|
||
|
||
function limitContentLength(elm, len)
|
||
{
|
||
var newString = $(elm).val().slice(0, len);
|
||
$(elm).val(newString);
|
||
} |