jQuery MiniUI

 找回密码
 立即注册
查看: 3549|回复: 2
打印 上一主题 下一主题

自定义扩展miniui组件遇到的问题 [复制链接]

Rank: 3Rank: 3

跳转到指定楼层
楼主
发表于 2021-8-10 15:47:01 |只看该作者 |倒序浏览
本帖最后由 Aisin丿Gioro 于 2021-8-11 08:56 编辑
  1. mini.ux.Viewer = function (options) {
  2.     mini.ux.Viewer.superclass.constructor.call(this);
  3.     var defaults = {
  4.         footToolbar: [
  5.             'zoomIn',
  6.             'zoomOut',
  7.             'prev',
  8.             'fullscreen',
  9.             'next',
  10.             'actualSize',
  11.             'rotateRight'
  12.         ],
  13.         icons: {
  14.             maximize: 'fa fa-window-maximize',
  15.             close: 'fa fa-close',
  16.             zoomIn: 'fa fa-search-plus',
  17.             zoomOut: 'fa fa-search-minus',
  18.             prev: 'fa fa-arrow-left',
  19.             next: 'fa fa-arrow-right',
  20.             fullscreen: 'fa fa-photo',
  21.             actualSize: 'fa fa-arrows-alt',
  22.             rotateLeft: 'fa fa-rotate-left',
  23.             rotateRight: 'fa fa-rotate-right'
  24.         },
  25.         ratioThreshold: 0.1,
  26.     };
  27.     this.options = $.extend(true, {}, defaults, options);
  28.     if (options && $.isArray(options.footToolbar)) {
  29.         this.options.footToolbar = options.footToolbar;
  30.     }
  31.     this.imageData = {};
  32.     this.isRotated = false;
  33.     this.rotateAngle = 0;
  34.     this.init();
  35. };
  36. mini.extend(mini.ux.Viewer, mini.Panel, {
  37.     uiCls: "mini-ux-window",
  38.     init: function(){
  39.         this.initComponents();
  40.         this.bindEvents();
  41.         this.resize();
  42.         this.loadImg(rootPath + "static/admin/images/login/bg.jpg");
  43.     },
  44.     initComponents: function () {
  45.         var footer = this.creatDOM();

  46.         this.set({
  47.             style: "width: 100%;height:100%",
  48.             borderStyle: "border: 0",
  49.             bodyStyle: "position: relative;padding:0",
  50.             footerStyle: "text-align: center",
  51.             showHeader: false,
  52.             showToolbar: false,
  53.             showFooter: true,
  54.             allowResize: false,
  55.             footer: footer
  56.         });
  57.     },
  58.     creatDOM: function () {
  59.         var btnsTpl = {
  60.             maximize: '<a name="maximize" class="mini-button m-l-xs m-l-xs m-r-xs" iconCls="' + this.options.icons.maximize + '" tooltip="maximize"></a>',
  61.             close: '<a name="close" class="mini-button m-l-xs m-l-xs m-r-xs" iconCls="' + this.options.icons.close + '" tooltip="close"></a>',
  62.             zoomIn: '<a name="zoomIn" class="mini-button m-l-xs m-l-xs m-r-xs" iconCls="' + this.options.icons.zoomIn + '" tooltip="zoom-in"></a>',
  63.             zoomOut: '<a name="zoomOut" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.zoomOut + '" tooltip="zoom-out"></a>',
  64.             prev: '<a name="prev" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.prev + '" tooltip="prev"></a>',
  65.             next: '<a name="next" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.next + '" tooltip="next"></a>',
  66.             fullscreen: '<a name="fullscreen" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.fullscreen + '" tooltip="fullscreen"></a>',
  67.             actualSize: '<a name="actualSize" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.actualSize + '" tooltip="actual-size"></a>',
  68.             rotateLeft: '<a name="rotateLeft" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.rotateLeft + '" tooltip="rotate-left"></a>',
  69.             rotateRight: '<a name="rotateRight" class="mini-button m-l-xs m-r-xs" iconCls="' + this.options.icons.rotateRight + '" tooltip="rotate-right"></a>'
  70.         };

  71.         var toolbarHtml = this.creatBtns(this.options.footToolbar, btnsTpl);
  72.         return toolbarHtml;
  73.     },
  74.     creatBtns: function (toolbar, btns) {
  75.         var btnsStr = '';

  76.         $.each(toolbar, function (index, item) {
  77.             btnsStr += btns[item];
  78.         });

  79.         return btnsStr;
  80.     },
复制代码
  1. bindEvents: function () {
  2.         var that = this;

  3.         this.maximizeBtn = mini.getbyName('maximize', this);
  4.         this.zoomInBtn = mini.getbyName('zoomIn', this);
  5.         this.zoomOutBtn = mini.getbyName('zoomOut', this);
  6.         this.fullscreenBtn = mini.getbyName('fullscreen', this);
  7.         this.actualSizeBtn = mini.getbyName('actualSize', this);
  8.         this.rotateLeftBtn = mini.getbyName('rotateLeft', this);
  9.         this.rotateRightBtn = mini.getbyName('rotateRight', this);

  10.         this.$stage.off('wheel mousewheel DOMMouseScroll').on('wheel mousewheel DOMMouseScroll', function (e) {
  11.             that.wheel(e);
  12.         });

  13.         this.zoomInBtn.on('click', function (e) {
  14.             that.zoom(that.options.ratioThreshold * 3, {
  15.                 x: that.$stage.width() / 2,
  16.                 y: that.$stage.height() / 2
  17.             }, e);
  18.         });
  19.         this.zoomOutBtn.on('click', function (e) {
  20.             that.zoom(-that.options.ratioThreshold * 3, {
  21.                 x: that.$stage.width() / 2,
  22.                 y: that.$stage.height() / 2
  23.             }, e);
  24.         });
  25.         this.actualSizeBtn.on('click', function (e) {
  26.             that.zoomTo(1, {
  27.                 x: that.$stage.width() / 2,
  28.                 y: that.$stage.height() / 2
  29.             }, e);
  30.         });
  31.         this.fullscreenBtn.on('click', function (e) {
  32.             that.fullscreen();
  33.         });
  34.         this.rotateLeftBtn.on('click', function (e) {
  35.             that.rotate(-90);
  36.         });
  37.         this.rotateRightBtn.on('click', function (e) {
  38.             that.rotate(90);
  39.         });

  40.         $(document).off('keydown').on('keydown', function (e) {
  41.             that.keydown(e);
  42.         });
  43.     },
复制代码

为什么我给按钮绑定点击事件获取不到按钮组件?footer的按钮直接换成字符串拼接的形式就可以获取

Rank: 8Rank: 8

沙发
发表于 2021-8-11 14:39:27 |只看该作者
直接发做好例子,发html上来

Rank: 2

板凳
发表于 2021-8-20 08:58:31 |只看该作者
html没有解析为minui对象,所以get不到的.建用在在init中用new mini.xxxx 创建mini对象

mini.parse();

Archiver|普加软件

GMT+8, 2024-9-29 05:33 , Processed in 1.048095 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部