当前位置 : 主页 > 网络编程 > JavaScript >

yada项目微信菜单管理 controller 页面angularjs.txt

来源:互联网 收集:自由互联 发布时间:2021-06-30
yada项目微信菜单管理 controller 页面angularjs.txt (function () { 'use strict'; angular .module('hmapFront') .controller('CustomMenusController', CustomMenusController); CustomMenusController.$inject = ['CustomMenus', 'toastr', '$s
yada项目微信菜单管理 controller 页面angularjs.txt
(function () {
  'use strict';

  angular
    .module('hmapFront')
    .controller('CustomMenusController', CustomMenusController);
  CustomMenusController.$inject = ['CustomMenus', 'toastr', '$state', '$scope', '$rootScope'];
  function CustomMenusController( CustomMenus,toastr, $state, $scope, $rootScope)  {
    var vm = this;

    vm.cars = [] ;
    vm.saveMenu = saveMenu;
    vm.edit = false;
    vm.allModification = true ;
    vm.newEdit =  true ;
    vm.submitMenu = false ;
    vm.index = "" ;
    vm.fname = [];
    vm.loadAll = loadAll;
    vm.editUser = editUser ;
    vm.loadAll();
    vm.leftMove  = leftMove ;
    vm.rightMove = rightMove ;

    vm.upMove   =  upMove ;
    vm.delMenu  = delMenu ;
    vm.newMenu = newMenu ;
    vm.changervar =  changervar ;
    vm.beforeJudge = beforeJudge ;
    vm.upBelowJudge = upBelowJudge;
    vm.upBelow = upBelow;
    vm.whetherUrl = "";
    vm.affirm = affirm ; //确认保存
    vm.newMu  = {"name":"" ,"url":"" };

    function editUser(index) {

      vm.index  =  index  ;
      vm.edit = false;
      vm.allModification = false ;
      vm.newEdit = true ;
      $("input[type='radio']").removeAttr('checked');//清空选中
      vm.upone =  true ;



      vm.fname =   vm.cars.rows[0].button[index] ;//给修改页面一级菜单赋值

      if(vm.cars.rows[0].button.length == 1 || vm.cars.rows[0].button.length == 0 ){
        vm.leftone = true ;
        vm.rightone =  true ;
      }else if(index == 0 ){      /*如果选中的一级菜单是第0 个 或者 是最后一个  隐藏 按钮*/
        vm.leftone = true ;
        vm.rightone =  false ;

      }else if (index == vm.cars.rows[0].button.length-1 ){
        vm.rightone =  true ;
        vm.leftone = false;

      }else{
        vm.rightone =  false ;
        vm.leftone = false;
      }

      toastr.success('生成成功!', '提示信息');
    }

    function saveMenu() {
      vm.allModification = true ;
      CustomMenus.saveMenu().update(vm.cars.rows[0]);
      if( vm.cars.rows[0].button.length >= 3){  //显示的时候 如果选择的是二级菜单  ,,并且选择上级菜单  等于空 二级菜单不能为空
           alert("一级菜单不能选择");
      }
      toastr.success('已提交!', '提示信息');

    }

    function affirm(){
      vm.submitMenu = false ;
      vm.newEdit = true ;
      $("#oneMenu").find("button")
        .removeAttr("disabled");
      vm.whetherUrl = {"type":"view","name":vm.newMu.name ,"url":vm.newMu.url };
      if(vm.data == "一级" ){
        if( vm.newMu.url == "" ){
          vm.whetherUrl =  {"name": vm.newMu.name ,"sub_button":[] };
        }
        vm.cars.rows[0].button.push(vm.whetherUrl);
      }else {
        //  添加二级菜单
        var option =  $("#superiorMenu option:selected").text();
        for(var i = 0 ; i <= vm.cars.rows[0].button.length ; i++){
          if(vm.cars.rows[0].button[i].name  == option ){
            vm.cars.rows[0].button[i].sub_button.push(vm.whetherUrl);
          }
        }
      }
      toastr.success('保存成功!', '提示信息');
    }
    function beforeJudge(){


    }

    function onSuccess(data, headers) {
      toastr.success('生成成功!', '提示信息');
      vm.cars = data;

    }
    function loadAll() {
      CustomMenus.getCustomMenuAll().query({}, onSuccess);// 调用service 不要少括号
    }
    function rightMove(){   //向左右移动
      var index =  vm.index ;
      vm.temporary  =  vm.cars.rows[0].button[index];
      vm.cars.rows[0].button[vm.index] =  vm.cars.rows[0].button[index+1];
      vm.cars.rows[0].button[index+1] =  vm.temporary;
      vm.index =  vm.index + 1 ;
      editUser(vm.index);
    }
    function leftMove() {
      var index =  vm.index ;
      vm.temporary  =  vm.cars.rows[0].button[index];
      vm.cars.rows[0].button[vm.index] =  vm.cars.rows[0].button[index-1];
      vm.cars.rows[0].button[index-1] =  vm.temporary;
      vm.index =  vm.index - 1 ;
      editUser(vm.index);
    }

    function upMove() {  //向上移动
      var redioUp =  $("input[type='radio']:checked").val();

      vm.temporary  =  vm.cars.rows[0].button[vm.index].sub_button[redioUp];
      vm.cars.rows[0].button[vm.index].sub_button[redioUp] =  vm.cars.rows[0].button[vm.index].sub_button[redioUp-1];
      vm.cars.rows[0].button[vm.index].sub_button[redioUp-1] =  vm.temporary;


    }
    function upBelow(){
      var index =  $("input[type='radio']:checked").val();
      if(index == 0 ){
        vm.upone =  true ;
      }
    }
    function upBelowJudge(){
     var index =  $("input[type='radio']:checked").val();
      //隐藏上下按钮
      console.log(index);
      if(index == undefined){
        vm.upone =  true ;
      } else if(vm.cars.rows[0].button[vm.index].sub_button.length == 1 || vm.cars.rows[0].button[vm.index].sub_button.length == 0 ){
        vm.upone =  true ;
      }else if(index == 0 ){      /*如果选中的一级菜单是第0 个 或者 是最后一个  隐藏 按钮*/
        vm.upone =  true ;
      }else if (index == vm.cars.rows[0].button[vm.index].sub_button.length-1 ){
        vm.upone =  false ;
      }else{
          vm.upone =  false ;
      }
    }
    function delMenu(twoIndex) {

      if(twoIndex == null){    //一级
        vm.cars.rows[0].button.splice(vm.index,1) ;
      }else if (twoIndex != null){
        vm.cars.rows[0].button[vm.index].sub_button.splice(twoIndex,1) ;
      }
      editUser(0);
    }
    function newMenu() {
      vm.newEdit = false ;
      vm.edit =  true ;
      vm.allModification = false ;
      vm.submitMenu = true ;
      $("#oneMenu").find("button")
        .attr("disabled","disabled");
    }

    function changervar() {
      vm.data =  $("#ddlRegType").val();
      if( vm.cars.rows[0].button.length >= 3){
        $("option[value='一级']").remove();
      }

      if(vm.data == "一级"){
        $("#superiorMenu")
          .attr("disabled","disabled")
          .empty();
      }else{

        $("#superiorMenu").removeAttr("disabled");
        for(var i = 0 ; i <= vm.cars.rows[0].button.length ; i++){
          var menu = vm.cars.rows[0].button[i];
          if(!menu.sub_button.length == 0 ){
            $("#superiorMenu").append("");
           }
        }
      }
    }

         console.log(vm.cars);

  }
})();
网友评论