wupengfei 3 سال پیش
والد
کامیت
8d14a1b8e6
2فایلهای تغییر یافته به همراه282 افزوده شده و 52 حذف شده
  1. 15 0
      application/extra/addons.php
  2. 267 52
      public/assets/js/addons.js

+ 15 - 0
application/extra/addons.php

@@ -3,12 +3,27 @@
 return [
     'autoload' => false,
     'hooks' => [
+        'sms_send' => [
+            'alisms',
+        ],
+        'sms_notice' => [
+            'alisms',
+        ],
+        'sms_check' => [
+            'alisms',
+        ],
         'upgrade' => [
             'shopro',
         ],
         'app_init' => [
             'shopro',
         ],
+        'wipecache_after' => [
+            'tinymce',
+        ],
+        'set_tinymce' => [
+            'tinymce',
+        ],
     ],
     'route' => [],
     'priority' => [],

+ 267 - 52
public/assets/js/addons.js

@@ -1,69 +1,284 @@
 define([], function () {
     if (Config.modulename == 'admin' && Config.controllername == 'index' && Config.actionname == 'index') {
+        require.config({
+            paths: {
+                'vue': "../addons/shopro/libs/vue",
+                'moment': "../addons/shopro/libs/moment",
+                'text': "../addons/shopro/libs/require-text",
+                'chat': '../addons/shopro/libs/chat',
+                'ELEMENT': '../addons/shopro/libs/element/element',
+            },
+            shim: {
+                'ELEMENT': {
+                    deps: ['css!../addons/shopro/libs/element/element.css']
+                },
+            },
+        });
+        require(['vue', 'jquery', 'chat', 'text!../addons/shopro/chat.html', 'ELEMENT', 'moment'], function (Vue, $, Chat, ChatTemp, ELEMENT, Moment) {
+
+            Vue.use(ELEMENT);
+
+            var wsUri;
+            Fast.api.ajax({
+                url: 'shopro/chat/index/init',
+                loading: false,
+                type: 'GET'
+            }, function (ret, res) {
+                if (res.data.config.type == 'shopro') {
+
+                    let wg = 'ws';
+                    if (res.data.config.system.is_ssl == 1) {
+                        wg = 'wss';
+                    }
+                    wsUri = wg + '://' + window.location.hostname + ':' + res.data.config.system.gateway_port;
+                    // 反向代理
+                    if (res.data.config.system.is_ssl == 1 && res.data.config.system.ssl_type == 'reverse_proxy') {
+                        wsUri = wg + '://' + window.location.hostname + '/websocket/';
+                    }
+                    $("body").append(`<div id="chatTemplateContainer" style="display:none"></div>
+                    <div id="chatService"><Chat :passvalue="obj"></Chat></div>`);
+
+                    $("#chatTemplateContainer").append(ChatTemp);
+
+                    new Vue({
+                        el: "#chatService",
+                        data() {
+                            return {
+                                obj: {
+                                    commonWordsList: res.data.fast_reply,
+                                    token: res.data.token,
+                                    wsUri: wsUri,
+                                    expire_time: res.data.expire_time,
+                                    customer_service_id: res.data.customer_service.id,
+                                    adminData: res.data,
+                                    emoji_list: res.data.emoji
+                                }
+                            }
+                        }
+                    });
+
+                }
+                return false;
+            }, function (ret, res) {
+                if (res.msg == '') {
+                    return false;
+                }
+            })
+        });
+    }
     require.config({
         paths: {
-            'vue': "../addons/shopro/libs/vue",
-            'moment': "../addons/shopro/libs/moment",
-            'text': "../addons/shopro/libs/require-text",
-            'chat': '../addons/shopro/libs/chat',
-            'ELEMENT': '../addons/shopro/libs/element/element',
+            'summernote': '../addons/summernote/lang/summernote-zh-CN.min'
         },
         shim: {
-            'ELEMENT': {
-                deps: ['css!../addons/shopro/libs/element/element.css']
-            },
-        },
+            'summernote': ['../addons/summernote/js/summernote.min', 'css!../addons/summernote/css/summernote.css'],
+        }
     });
-    require(['vue', 'jquery', 'chat', 'text!../addons/shopro/chat.html', 'ELEMENT', 'moment'], function (Vue, $, Chat, ChatTemp, ELEMENT, Moment) {
-
-        Vue.use(ELEMENT);
+    require(['form', 'upload'], function (Form, Upload) {
+        var _bindevent = Form.events.bindevent;
+        Form.events.bindevent = function (form) {
+            _bindevent.apply(this, [form]);
+            try {
+                //绑定summernote事件
+                if ($(".summernote,.editor", form).size() > 0) {
+                    require(['summernote'], function () {
+                        var imageButton = function (context) {
+                            var ui = $.summernote.ui;
+                            var button = ui.button({
+                                contents: '<i class="fa fa-file-image-o"/>',
+                                tooltip: __('Choose'),
+                                click: function () {
+                                    parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=image/*", __('Choose'), {
+                                        callback: function (data) {
+                                            var urlArr = data.url.split(/\,/);
+                                            $.each(urlArr, function () {
+                                                var url = Fast.api.cdnurl(this);
+                                                context.invoke('editor.insertImage', url);
+                                            });
+                                        }
+                                    });
+                                    return false;
+                                }
+                            });
+                            return button.render();
+                        };
+                        var attachmentButton = function (context) {
+                            var ui = $.summernote.ui;
+                            var button = ui.button({
+                                contents: '<i class="fa fa-file"/>',
+                                tooltip: __('Choose'),
+                                click: function () {
+                                    parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=*", __('Choose'), {
+                                        callback: function (data) {
+                                            var urlArr = data.url.split(/\,/);
+                                            $.each(urlArr, function () {
+                                                var url = Fast.api.cdnurl(this);
+                                                var node = $("<a href='" + url + "'>" + url + "</a>");
+                                                context.invoke('insertNode', node[0]);
+                                            });
+                                        }
+                                    });
+                                    return false;
+                                }
+                            });
+                            return button.render();
+                        };
 
-        var wsUri;
-        Fast.api.ajax({
-            url: 'shopro/chat/index/init',
-            loading: false,
-            type: 'GET'
-        }, function (ret, res) {
-            if (res.data.config.type == 'shopro') {
-
-                let wg = 'ws';
-                if (res.data.config.system.is_ssl == 1) {
-                    wg = 'wss';
-                }
-                wsUri = wg + '://' + window.location.hostname + ':' + res.data.config.system.gateway_port;
-                // 反向代理
-                if (res.data.config.system.is_ssl == 1 && res.data.config.system.ssl_type == 'reverse_proxy') {
-                    wsUri = wg + '://' + window.location.hostname + '/websocket/';
+                        $(".summernote,.editor", form).summernote({
+                            height: 250,
+                            lang: 'zh-CN',
+                            fontNames: [
+                                'Arial', 'Arial Black', 'Serif', 'Sans', 'Courier',
+                                'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande',
+                                "Open Sans", "Hiragino Sans GB", "Microsoft YaHei",
+                                '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆',
+                            ],
+                            fontNamesIgnoreCheck: [
+                                "Open Sans", "Microsoft YaHei",
+                                '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆'
+                            ],
+                            toolbar: [
+                                ['style', ['style', 'undo', 'redo']],
+                                ['font', ['bold', 'underline', 'strikethrough', 'clear']],
+                                ['fontname', ['color', 'fontname', 'fontsize']],
+                                ['para', ['ul', 'ol', 'paragraph', 'height']],
+                                ['table', ['table', 'hr']],
+                                ['insert', ['link', 'picture', 'video']],
+                                ['select', ['image', 'attachment']],
+                                ['view', ['fullscreen', 'codeview', 'help']],
+                            ],
+                            buttons: {
+                                image: imageButton,
+                                attachment: attachmentButton,
+                            },
+                            dialogsInBody: true,
+                            followingToolbar: false,
+                            callbacks: {
+                                onChange: function (contents) {
+                                    $(this).val(contents);
+                                    $(this).trigger('change');
+                                },
+                                onInit: function () {
+                                },
+                                onImageUpload: function (files) {
+                                    var that = this;
+                                    //依次上传图片
+                                    for (var i = 0; i < files.length; i++) {
+                                        Upload.api.send(files[i], function (data) {
+                                            var url = Fast.api.cdnurl(data.url);
+                                            $(that).summernote("insertImage", url, 'filename');
+                                        });
+                                    }
+                                }
+                            }
+                        });
+                    });
                 }
-                $("body").append(`<div id="chatTemplateContainer" style="display:none"></div>
-                    <div id="chatService"><Chat :passvalue="obj"></Chat></div>`);
+            } catch (e) {
 
-                $("#chatTemplateContainer").append(ChatTemp);
+            }
 
-                new Vue({
-                    el: "#chatService",
-                    data() {
-                        return {
-                            obj: {
-                                commonWordsList: res.data.fast_reply,
-                                token: res.data.token,
-                                wsUri: wsUri,
-                                expire_time: res.data.expire_time,
-                                customer_service_id: res.data.customer_service.id,
-                                adminData: res.data,
-                                emoji_list: res.data.emoji
+        };
+    });
+
+    require.config({
+        paths: {
+            'tinymce': '../addons/tinymce/js/tinymce/tinymce.min'
+        },
+    });
+    require(['form', 'upload'], function (Form, Upload) {
+        var _bindevent = Form.events.bindevent;
+        Form.events.bindevent = function (form) {
+            _bindevent.apply(this, [form]);
+            try {
+                //绑定summernote事件
+                if ($(".tinymce,.editor", form).size() > 0) {
+                    require(['tinymce'], function () {
+                        var init = {
+                            selector: ".tinymce,.editor",//容器可以是id也可以是class
+                            language: 'zh_CN',//语言
+                            theme: 'silver',//主体默认主题
+                            plugins: ['advlist link image lists charmap hr anchor pagebreak searchreplace wordcount visualblocks visualchars code insertdatetime nonbreaking save table contextmenu directionality help autolink autosave print preview spellchecker fullscreen media emoticons template paste textcolor'],//所含插件
+                            content_style : '',//编辑器样式只对编辑器试图有效不会提交到html中
+                            toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | spellchecker help',//工具栏
+                            file_picker_types: 'image,media',//文件上传支持类型:file,image,media
+                            //图像上传处理
+                            convert_urls:false,//关闭url自动检测
+                            images_upload_handler: function (blobInfo, success, failure) {
+                                Upload.api.send(blobInfo.blob(), function (data) {
+                                    var url = Fast.api.cdnurl(data.url);
+                                    success( url);
+                                    return;
+                                },function (data,ret) {
+                                    Layer && Layer.closeAll('dialog');
+                                    failure(ret.msg);
+                                    return;
+                                });
+                            },
+                            image_default_size:{width:'100%',height:''},//图片添加成功后的默认宽高 格式:{width:"",height:''} 允许是百分比或像素
+                            media_default_size:{width:'100%',height:''},//音/视频添加成功后的默认宽高 格式:{width:"",height:''} 允许是百分比或像素
+                            browser_spellcheck: true,//浏览器检查拼写
+                            spellchecker_callback: function(method, text, success, failure) {
+                                var words = text.match(this.getWordCharPattern());
+                                if (method == "spellcheck") {
+                                    var suggestions = {};
+                                    for (var i = 0; i < words.length; i++) {
+                                        suggestions[words[i]] = ["First", "Second"];
+                                    }
+                                    success(suggestions);
+                                }
+                            },
+                            setup:function (editor) {
+                                editor.on('change',function () {
+                                    editor.save();
+                                    $(editor.getElement()).trigger("input");
+                                });
                             }
+                        };
+                        if(false){
+                            //文件上传处理
+                            init.file_picker_callback = function(callback, value, meta) {
+                                //为不同插件指定文件类型
+                                switch(meta.filetype){
+                                    case 'image':
+                                        filetype='image/*';
+                                        break;
+                                    case 'media':
+                                        filetype='audio/*,video/*';
+                                        break;
+                                    case 'file':
+                                    default:
+                                }
+
+                                //模拟出一个input用于添加本地文件
+                                var input = document.createElement('input');
+                                input.setAttribute('type', 'file');
+                                input.setAttribute('accept', filetype);
+                                input.click();
+                                input.onchange = function() {
+                                    Upload.api.send(this.files[0], function (data) {
+                                        var url = Fast.api.cdnurl(data.url);
+                                        callback(url);
+                                        return;
+                                    },function (data,ret) {
+                                        Layer && Layer.closeAll('dialog');
+                                        alert(ret.msg);
+                                        return;
+                                    });
+                                };
+                            };
                         }
-                    }
-                });
+                        tinymce.init(init);
+                        $(document).on("click", ":button[type=submit],input[type=submit]", function () {
+                            tinymce.triggerSave();
+                        });
+                    });
+                }
+            } catch (e) {
 
             }
-            return false;
-        }, function (ret, res) {
-            if (res.msg == '') {
-                return false;
-            }
-        })
+
+        };
     });
-}
+
 });