123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {
- //去掉特殊字符和转义字符
- function excludeSpecial(s) {
- s = s.replace(/[\\\/\b\f\n\r\t\'\[\]\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/g,'');
- return s;
- };
- $(document).on('keyup','.description',function () {
- var descrp = $(this).val();
- $(this).val(excludeSpecial(descrp));
- });
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'wechat/response/index',
- add_url: 'wechat/response/add',
- edit_url: 'wechat/response/edit',
- del_url: 'wechat/response/del',
- multi_url: 'wechat/response/multi',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- sortName: 'id',
- columns: [
- [
- {field: 'state', checkbox: true, },
- // {field: 'id', title: 'ID'},
- {field: 'type', title: __('Type'),formatter:function(value){
- var ob = {'text':'文本','image':'图片', 'news':'图文'};
- return ob[value];
- }, searchList:{'text':'文本', 'image':'图片', 'news':'图文'}},
- {field: 'title', title: __('Resource title'),operate:'LIKE'},
- // {field: 'eventkey', title: __('Event key')},
- {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate:false},
- {field: 'is_subscribe', title: __('是否支持多图文'), formatter: function (value) {
- var o = {'1':'支持多图文','0':'不支持多图文'};
- return o[value];
- }, searchList: {'1':'支持多图文','0':'不支持多图文'}},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- select: function () {
- //console.log(window.location.search);
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'wechat/response/index',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url + window.location.search,
- sortName: 'id',
- columns: [
- [
- {field: 'state', checkbox: true, },
- //{field: 'id', title: 'ID'},
- {field: 'type', title: __('Type'),formatter:function(value){
- var ob = {'text':'文本','image':'图片', 'news':'图文'};
- return ob[value];
- }, searchList:{'text':'文本', 'image':'图片', 'news':'图文'}},
- {field: 'title', title: __('Resource title'),operate:'LIKE'},
- {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate:false},
- {field: 'is_subscribe', title: __('是否支持多图文'), formatter: function (value) {
- var o = {'1':'支持多图文','0':'不支持多图文'};
- return o[value];
- }, searchList: {'1':'支持多图文','0':'不支持多图文'}},
- {field: 'operate', title: __('Operate'), events: {
- 'click .btn-chooseone': function (e, value, row, index) {
- Fast.api.close(row);
- },
- }, formatter: function () {
- return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
- }}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
-
- //资源管理
- var ore={
- arrma:[
- {
- 'title':'',
- 'image':'',
- 'url':'http://',
- 'description':'',
- }
- ],
- imglis:[],
- titlist:[],
- sli:'<div class="img_txt_li img_txt_main">\
- <div class="img_txt_one_tit">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_one_h3"><input type="text" value="sli_value" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
- </div>\
- <div class="img_txt_one_img img_txt_edit_img"><img src="sli_img" /></div>\
- <div class="form-group group-type-news group-type">\
- <label for="description" class="control-label col-xs-12 col-sm-2">简介:</label>\
- <div class="col-xs-12">\
- <textarea type="text" class="form-control description" rows="4" maxlength="120">sli_description</textarea>\
- </div>\
- </div>\
- <div class="fa img_txt_remvoe"></div>\
- </div>'
- };
-
-
- /**
- * form表单验证
- */
- $("form[role=form]").data("validator-options", {
- ignore: ':hidden',
- beforeSubmit: function (form) {
- if($('input[name="row[type]"]:checked').val() == 'news'){
- var $imgTxtMain = $('.img_txt_main');
- var reg = /^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w/;
- var sList = '';
- ore.arrma = [];
- for(var i=0; i<$imgTxtMain.length; i++){
- ore.arrma.push({});
- //标题
- if($('.img_txt_main:eq('+ i +') input:eq(0)').val().length > 0){
- ore.arrma[i].title = $('.img_txt_main:eq('+ i +') input:eq(0)').val();
- }else{
- Toastr.error("图文标题不能为空");
- return false;
- }
- //链接
- if(reg.test($('.img_txt_main:eq('+ i +') input:eq(1)').val())){
- ore.arrma[i].url = $('.img_txt_main:eq('+ i +') input:eq(1)').val();
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- //图片
- if($('.img_txt_main:eq('+ i +') img').attr('src').length > 0){
- ore.arrma[i].image = $('.img_txt_main:eq('+ i +') img').attr('src');
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- ore.arrma[i].description = $('.img_txt_main:eq('+ i +') textarea').val();
- }
- sList = JSON.stringify(ore.arrma);
- $('.img_txt_hidde_input').val(sList);
- // console.log('验证');
- // return false;
- }
- }
- });
- Form.api.bindevent($("form[role=form]"),
- function (data) {
- Fast.api.close(data);
- },
- function (data) {
- console.log('error', data);
- });
-
-
-
- /**
- * 资源类型管理
- */
- $(document).on('click', "input[name='row[type]']", function () {
- var type = $(this).val();
- $('.group-type').addClass('hide');
- $('.group-type input').attr('disabled');
- $('.group-type-' + type).removeClass('hide');
- $('.group-type-' + type+' input').removeAttr('disabled');
- });
- //是否多图文
- $(document).on('click',"input[name='row[is_subscribe]']",function(){
- var subscribe = $(this).val();
- $('.group-type-subscribe').addClass('hide');
- if(subscribe==1){
- $('.group-type-subscribe').removeClass('hide');
- $('.img_txt_li').removeClass('hide');
- }else{
- $('.img_txt_li').addClass('hide');
- }
- });
-
- /**
- * 插入关注自动回复模板
- */
- $(document).on('click', ".btn_automatic_reply", function () {
- var textarea = $("textarea[name='row[content]']");
- var cursorPos = textarea.prop('selectionStart');
- var v = textarea.val();
- var textBefore = v.substring(0, cursorPos);
- var textAfter = v.substring(cursorPos, v.length);
- var txttar = '欢迎关注,您上次阅读的小说《{$book_name}》\n\n<a href="{$book_url}">【点此继续阅读】</a>\n\n为方便下次阅读,请置顶公众号';
- textarea.val(textBefore + txttar + textAfter);
- });
- /**
- * 插入链接
- */
- $(document).on('click', ".btn-insertlink", function () {
- var textarea = $("textarea[name='row[content]']");
- var cursorPos = textarea.prop('selectionStart');
- var v = textarea.val();
- var textBefore = v.substring(0, cursorPos);
- var textAfter = v.substring(cursorPos, v.length);
- Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
- text = $.trim(text);
- Layer.close(index);
- Layer.prompt({title: '请输入跳转的链接URL(包含http/https)', formType: 3}, function (link, index) {
- link = link.replace(/\s+/g, "");
- link = link.replace(/[\r\n]/g, "");
- text = text == '' ? link : text;
- textarea.val(textBefore + '<a href="' + link + '">' + text + '</a>' + textAfter);
- Layer.close(index);
- });
- });
- });
-
- $.ajax({
- type:'get',
- url:'/admin/manage/cover/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
- cache:false,
- async:false,
- success:function(data){
- // console.log(data)
- ore.imglis = data.rows;
- },
- error:function(err){
- }
- })
- $.ajax({
- type:'get',
- url:'/admin/manage/title/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
- cache:false,
- async:false,
- success:function(data){
- // console.log(data)
- ore.titlist = data.rows;
- ore.arrma[0]['image'] = ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'];
- ore.arrma[0]['title'] = ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'];
- if($('.img_txt_hidde_input').val().length > 0){
- ore.arrma = JSON.parse($('.img_txt_hidde_input').val());
- console.log(ore.arrma);
- for(var i=0; i<$('.img_txt_hidde_input').val().length; i++){
- if(i==0){
- $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
- <div class="img_txt_one_tit">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
- </div>\
- <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
- <div class="form-group group-type-news group-type">\
- <label for="description" class="control-label col-xs-12 col-sm-2">简介:</label>\
- <div class="col-xs-12">\
- <textarea type="text" class="form-control description" rows="4" maxlength="120">' + ore.arrma[0]['description'] + '</textarea>\
- </div>\
- </div>\
- </div>');
- }else{
- var sLiImg=ore.sli.replace(/sli_img/g,ore.arrma[i]['image']);
- sLiImg=sLiImg.replace(/sli_value/g,ore.arrma[i]['title']);
- sLiImg=sLiImg.replace(/click_url/g,ore.arrma[i]['url']);
- sLiImg=sLiImg.replace(/sli_description/g,ore.arrma[i]['description']);
- $('.img_txt_list').append(sLiImg);
- }
- }
- }else{
- $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
- <div class="img_txt_one_tit">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
- </div>\
- <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
- <div class="form-group group-type-news group-type">\
- <label for="description" class="control-label col-xs-12 col-sm-2">简介:</label>\
- <div class="col-xs-12">\
- <textarea type="text" class="form-control description" rows="4" maxlength="120">' + ore.arrma[0]['description'] + '</textarea>\
- </div>\
- </div>\
- </div>');
- }
- },
- error:function(err){
- }
- })
-
-
-
-
- $(document).on('click','.img_txt_add_but',function(){
- var $List=$('.img_txt_main');
- var oNowData = {
- image:ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'],
- title:ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'],
- url:'http://',
- description:''
- }
- var sLiImg=ore.sli.replace(/sli_img/g,oNowData['image']);
- sLiImg=sLiImg.replace(/sli_value/g,oNowData['title']);
- sLiImg=sLiImg.replace(/click_url/g,'http://');
- sLiImg=sLiImg.replace(/sli_description/g,oNowData['description']);
- if($List.length<5){
- $('.img_txt_list').append(sLiImg);
- ore.arrma.push(oNowData);
- }else{
- Toastr.error("不能超过5篇");
- }
- });
-
- $(document).on('click','.img_txt_remvoe',function(){
- var $this=$(this);
- $this.parent().remove();
- });
- //修改title
- $(document).on('click','.img_txt_edit_tit',function(){
- var $this=$(this);
- Fast.api.open('manage/title/select', '选择', {
- callback: function (data) {
- console.log('展示title回调', data);
- $this.parent().find('input').eq(0).val(data.title);
- }
- });
- });
- //修改url
- $(document).on('click','.img_txt_edit_url',function(){
- var $this=$(this);
- Fast.api.open('referral/referral/select?one=1', '选择', {
- callback: function (data) {
- var data = data[0];
- // console.log('展示title回调', data);
- $this.parent().find('textarea').val(data['book']['description']);
- $this.parent().find('input').eq(1).val(data.source_url);
- }
- });
- });
- //修改book
- $(document).on('click','.img_txt_edit_book',function(){
- var $this=$(this);
- Fast.api.open('book.book/select?one=1', '选择', {
- callback: function (data) {
- var data = data[0];
- $this.parent().find('input').eq(1).val(data.current_book_url);
- $this.parent().parent().find('textarea').eq(0).val(data.description);
- }
- });
- });
- //修改图片
- $(document).on('click','.img_txt_edit_img',function(){
- var $this=$(this);
- Fast.api.open('manage/cover/select', '选择', {
- callback: function (data) {
- // console.log('展示image回调', data);
- $this.find('img').attr('src',data.image);
- }
- });
- });
- //修改跳转链接
- $(document).on('click','.img_txt_main a',function(){
- var $this=$(this);
- var nIndex = $this.parents('.img_txt_main').index();
- layer.prompt({
- formType: 2,
- value: ore.arrma[nIndex].url,
- title: '请输入跳转链接地址(http://)',
- area: ['300px', '100px'] //自定义文本域宽高
- }, function(value, index, elem){
- //var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
- var reg=/^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w/;
- if(reg.test(value)){
- layer.close(index);
- ore.arrma[nIndex].url = value;
- $this.html(value);
- }else{
- Toastr.error("请输入正确的跳转地址。");
- }
- });
- });
- }
- }
- };
- return Controller;
- });
-
|